pax_global_header00006660000000000000000000000064135560307760014526gustar00rootroot0000000000000052 comment=80b3ed883c1413fac8314b4766945bfbf3f7be8f deps-sort-2.0.1/000077500000000000000000000000001355603077600134465ustar00rootroot00000000000000deps-sort-2.0.1/.npmrc000066400000000000000000000000231355603077600145610ustar00rootroot00000000000000package-lock=false deps-sort-2.0.1/.travis.yml000066400000000000000000000005711355603077600155620ustar00rootroot00000000000000language: node_js node_js: - "13" - "12" - "10" - "9" - "8" - "6" - "4" - "iojs" - "0.12" - "0.10" - "0.8" before_install: # Old npm certs are untrusted https://github.com/npm/npm/issues/20191 - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.8" ]; then export NPM_CONFIG_STRICT_SSL=false; fi' - 'nvm install-latest-npm' deps-sort-2.0.1/LICENSE000066400000000000000000000021201355603077600144460ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) James Halliday and browserify contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. deps-sort-2.0.1/bin/000077500000000000000000000000001355603077600142165ustar00rootroot00000000000000deps-sort-2.0.1/bin/cmd.js000077500000000000000000000004601355603077600153220ustar00rootroot00000000000000#!/usr/bin/env node var argv = require('subarg')(process.argv.slice(2)); var JSONStream = require('JSONStream'); var sort = require('../')(argv); var parse = JSONStream.parse([ true ]); var stringify = JSONStream.stringify(); process.stdin.pipe(parse).pipe(sort).pipe(stringify).pipe(process.stdout); deps-sort-2.0.1/example/000077500000000000000000000000001355603077600151015ustar00rootroot00000000000000deps-sort-2.0.1/example/sort.js000066400000000000000000000003411355603077600164240ustar00rootroot00000000000000var sort = require('../')(); var JSONStream = require('JSONStream'); var parse = JSONStream.parse([ true ]); var stringify = JSONStream.stringify(); process.stdin.pipe(parse).pipe(sort).pipe(stringify).pipe(process.stdout); deps-sort-2.0.1/index.js000066400000000000000000000062521355603077600151200ustar00rootroot00000000000000var through = require('through2'); var shasum = require('shasum-object'); module.exports = function (opts) { if (!opts) opts = {}; var rows = []; return through.obj(write, end); function write (row, enc, next) { rows.push(row); next() } function end () { var tr = this; rows.sort(cmp); sorter(rows, tr, opts); } }; function sorter (rows, tr, opts) { var expose = opts.expose || {}; if (Array.isArray(expose)) { expose = expose.reduce(function (acc, key) { acc[key] = true; return acc; }, {}); } var hashes = {}, deduped = {}; var sameDeps = depCmp(); if (opts.dedupe) { rows.forEach(function (row) { var h = shasum(row.source); sameDeps.add(row, h); if (hashes[h]) { hashes[h].push(row); } else { hashes[h] = [row]; } }); Object.keys(hashes).forEach(function (h) { var rows = hashes[h]; while (rows.length > 1) { var row = rows.pop(); row.dedupe = rows[0].id; row.sameDeps = sameDeps.cmp(rows[0].deps, row.deps); deduped[row.id] = rows[0].id; } }); } if (opts.index) { var index = {}; var offset = 0; rows.forEach(function (row, ix) { if (has(expose, row.id)) { row.index = row.id; offset ++; if (expose[row.id] !== true) { index[expose[row.id]] = row.index; } } else { row.index = ix + 1 - offset; } index[row.id] = row.index; }); rows.forEach(function (row) { row.indexDeps = {}; Object.keys(row.deps).forEach(function (key) { var id = row.deps[key]; row.indexDeps[key] = index[id]; }); if (row.dedupe) { row.dedupeIndex = index[row.dedupe]; } tr.push(row); }); } else { rows.forEach(function (row) { tr.push(row) }); } tr.push(null); } function cmp (a, b) { return a.id + a.hash < b.id + b.hash ? -1 : 1; } function has (obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } function depCmp () { var deps = {}, hashes = {}; return { add: add, cmp: cmp } function add (row, hash) { deps[row.id] = row.deps; hashes[row.id] = hash; } function cmp (a, b, limit) { if (!a && !b) return true; if (!a || !b) return false; var keys = Object.keys(a); if (keys.length !== Object.keys(b).length) return false; for (var i = 0; i < keys.length; i++) { var k = keys[i], ka = a[k], kb = b[k]; var ha = hashes[ka]; var hb = hashes[kb]; var da = deps[ka]; var db = deps[kb]; if (ka === kb) continue; if (ha !== hb || (!limit && !cmp(da, db, 1))) { return false; } } return true; } } deps-sort-2.0.1/package.json000066400000000000000000000015441355603077600157400ustar00rootroot00000000000000{ "name": "deps-sort", "version": "2.0.1", "description": "sort module-deps output for deterministic browserify bundles", "main": "index.js", "bin": { "deps-sort": "bin/cmd.js" }, "dependencies": { "JSONStream": "^1.0.3", "shasum-object": "^1.0.0", "subarg": "^1.0.0", "through2": "^2.0.0" }, "devDependencies": { "tap": "^2.2.0" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/substack/deps-sort.git" }, "homepage": "https://github.com/substack/deps-sort", "keywords": [ "dependency", "graph", "browser", "browserify", "module-deps", "browser-pack", "sorted", "determinism" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT" } deps-sort-2.0.1/readme.markdown000066400000000000000000000060031355603077600164460ustar00rootroot00000000000000# deps-sort sort [module-deps](https://npmjs.org/package/module-deps) output for deterministic browserify bundles [![build status](https://secure.travis-ci.org/browserify/deps-sort.png)](http://travis-ci.org/browserify/deps-sort) # example ## command-line ``` $ for((i=0;i<5;i++)); do module-deps main.js | deps-sort | browser-pack | md5sum; done e9e630de2c62953140357db0444c3c3a - e9e630de2c62953140357db0444c3c3a - e9e630de2c62953140357db0444c3c3a - e9e630de2c62953140357db0444c3c3a - e9e630de2c62953140357db0444c3c3a - ``` or using `browserify --deps` on a [voxeljs](http://voxeljs.com/) project: ``` $ for((i=0;i<5;i++)); do browserify --deps browser.js | deps-sort | browser-pack | md5sum; done fb418c74b53ba2e4cef7d01808b848e6 - fb418c74b53ba2e4cef7d01808b848e6 - fb418c74b53ba2e4cef7d01808b848e6 - fb418c74b53ba2e4cef7d01808b848e6 - fb418c74b53ba2e4cef7d01808b848e6 - ``` ## api To use this module programmatically, write streaming object data and read streaming object data: ``` js var sort = require('../')(); var JSONStream = require('JSONStream'); var parse = JSONStream.parse([ true ]); var stringify = JSONStream.stringify(); process.stdin.pipe(parse).pipe(sort).pipe(stringify).pipe(process.stdout); ``` # methods ``` js var depsSort = require('deps-sort'); ``` ## var stream = depsSort(opts) Return a new through `stream` that should get written [module-deps](https://npmjs.org/package/module-deps) objects and will output sorted objects. `opts` can be: * `opts.index` - when true, for each module-deps row, insert `row.index` with the numeric index and `row.indexDeps` like `row.deps` but mapping require strings to row indices * `opts.expose` - array of names or object mapping names to `true` not to mangle with integer indexes when `opts.index` is turned on. If `opts.expose` maps names to strings, those strings will be used to resolve the indexed references. * `opts.dedupe` - set `row.dedupe` for files that match existing contents. Sets `row.dedupeIndex` when `opts.index` is enabled. When `row.dedupe` is set, `row.sameDeps` will be set to a boolean of whether the dependencies at the dedupe target match (true) or just the source content (false). # input objects Input objects are file objects in the [module-deps][] shape. They must at least have these properties: * `row.id` - a unique identifier for the file * `row.source` - the file contents * `row.deps` - dependencies for this file, mapping strings as used in `require()` to row IDs. # output objects All the input properties, and: * `row.index` - when `opts.index` is true, the sorted numeric index of the row * `row.indexDeps` - like `row.deps`, but mapping to `row.index` instead of `row.id` * `row.dedupe` - when `opts.dedupe` is true, contains the row ID of a file with identical contents * `row.dedupeIndex` - like `row.dedupe`, but contains the `row.index` instead of `row.id` # install With [npm](https://npmjs.org) do: ``` npm install deps-sort ``` # license MIT [module-deps]: https://github.com/browserify/module-deps#output-objects deps-sort-2.0.1/test/000077500000000000000000000000001355603077600144255ustar00rootroot00000000000000deps-sort-2.0.1/test/dedupe-deps-of-deps.js000066400000000000000000000033001355603077600205110ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('dedupe-deps-of-deps', function (t) { t.plan(1); var s = sort({ dedupe: true }); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/bar.js', deps: { baz: '/bar/baz.js' }, source: 'TWO' }, { id: '/bar/baz.js', deps: {}, source: 'THREE' }, { id: '/foo.js', deps: { baz: '/foo/baz.js' }, source: 'TWO', dedupe: '/bar.js', sameDeps: true }, { id: '/foo/baz.js', deps: {}, source: 'THREE', dedupe: '/bar/baz.js', sameDeps: true }, { id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE' } ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE' }); s.write({ id: '/foo.js', deps: { baz : '/foo/baz.js' }, source: 'TWO' }); s.write({ id: '/bar.js', deps: { baz : '/bar/baz.js' }, source: 'TWO' }); s.write({ id: '/foo/baz.js', deps: {}, source: 'THREE' }); s.write({ id: '/bar/baz.js', deps: {}, source: 'THREE' }); s.end(); }); deps-sort-2.0.1/test/dedupe.js000066400000000000000000000017301355603077600162320ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('dedupe', function (t) { t.plan(1); var s = sort({ dedupe: true }); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/bar.js', deps: {}, source: 'TWO' }, { id: '/foo.js', deps: {}, source: 'TWO', dedupe: '/bar.js', sameDeps: true }, { id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE' } ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE' }); s.write({ id: '/foo.js', deps: {}, source: 'TWO' }); s.write({ id: '/bar.js', deps: {}, source: 'TWO' }); s.end(); }); deps-sort-2.0.1/test/dedupe_index.js000066400000000000000000000025471355603077600174300ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('dedupe index', function (t) { t.plan(1); var s = sort({ dedupe: true, index: true }); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/bar.js', deps: {}, source: 'TWO', index: 1, indexDeps: {} }, { id: '/foo.js', deps: {}, source: 'TWO', dedupe: '/bar.js', index: 2, indexDeps: {}, dedupeIndex: 1, sameDeps: true }, { id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE', index: 3, indexDeps: { './foo': 2, './bar': 1 }, } ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE' }); s.write({ id: '/foo.js', deps: {}, source: 'TWO' }); s.write({ id: '/bar.js', deps: {}, source: 'TWO' }); s.end(); }); deps-sort-2.0.1/test/dedupe_undef.js000066400000000000000000000016461355603077600174210ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('dedupe undef', function (t) { t.plan(1); var s = sort({ dedupe: true }); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/bar.js', source: 'TWO' }, { id: '/foo.js', source: 'TWO', dedupe: '/bar.js', sameDeps: true }, { id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE' } ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js', './bar': '/bar.js' }, source: 'ONE' }); s.write({ id: '/foo.js', source: 'TWO' }); s.write({ id: '/bar.js', source: 'TWO' }); s.end(); }); deps-sort-2.0.1/test/expose.js000066400000000000000000000021311355603077600162630ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('expose true', function (t) { t.plan(1); var s = sort({ index: true, expose: [ '/foo.js', '/bar.js' ] }); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/bar.js', deps: {}, index: '/bar.js', indexDeps: {} }, { id: '/foo.js', deps: { './bar': '/bar.js' }, index: '/foo.js', indexDeps: { './bar': '/bar.js' } }, { id: '/main.js', deps: { './foo': '/foo.js' }, index: 1, indexDeps: { './foo': '/foo.js' } }, ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js' } }); s.write({ id: '/foo.js', deps: { './bar': '/bar.js' } }); s.write({ id: '/bar.js', deps: {} }); s.end(); }); deps-sort-2.0.1/test/expose_str.js000066400000000000000000000021501355603077600171540ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('expose string', function (t) { t.plan(1); var s = sort({ index: true, expose: { 'f': '/foo.js', 'b': '/bar.js' } }); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/main.js', deps: { './foo': '/foo.js' }, index: 1, indexDeps: { './foo': 'f' } }, { id: 'b', deps: {}, index: 'b', indexDeps: {} }, { id: 'f', deps: { './bar': '/bar.js' }, index: 'f', indexDeps: { './bar': 'b' } } ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js' } }); s.write({ id: 'f', deps: { './bar': '/bar.js' } }); s.write({ id: 'b', deps: {} }); s.end(); }); deps-sort-2.0.1/test/indexed.js000066400000000000000000000020231355603077600164000ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('indexed', function (t) { t.plan(1); var s = sort({ index: true }); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/bar.js', deps: {}, index: 1, indexDeps: {} }, { id: '/foo.js', deps: { './bar': '/bar.js' }, index: 2, indexDeps: { './bar': 1 } }, { id: '/main.js', deps: { './foo': '/foo.js' }, index: 3, indexDeps: { './foo': 2 } }, ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js' } }); s.write({ id: '/foo.js', deps: { './bar': '/bar.js' } }); s.write({ id: '/bar.js', deps: {} }); s.end(); }); deps-sort-2.0.1/test/sort.js000066400000000000000000000012711355603077600157530ustar00rootroot00000000000000var sort = require('../'); var test = require('tap').test; var through = require('through2'); test('sort', function (t) { t.plan(1); var s = sort(); var rows = []; function write (row, enc, next) { rows.push(row); next() } function end () { t.deepEqual(rows, [ { id: '/bar.js', deps: {} }, { id: '/foo.js', deps: { './bar': '/bar.js' } }, { id: '/main.js', deps: { './foo': '/foo.js' } } ]); } s.pipe(through.obj(write, end)); s.write({ id: '/main.js', deps: { './foo': '/foo.js' } }); s.write({ id: '/foo.js', deps: { './bar': '/bar.js' } }); s.write({ id: '/bar.js', deps: {} }); s.end(); });