| 1 |
# deps-sort |
| 2 |
|
| 3 |
sort [module-deps](https://npmjs.org/package/module-deps) output for deterministic |
| 4 |
browserify bundles |
| 5 |
|
| 6 |
[](http://travis-ci.org/browserify/deps-sort) |
| 7 |
|
| 8 |
# example |
| 9 |
|
| 10 |
## command-line |
| 11 |
|
| 12 |
``` |
| 13 |
$ for((i=0;i<5;i++)); do module-deps main.js | deps-sort | browser-pack | md5sum; done |
| 14 |
e9e630de2c62953140357db0444c3c3a - |
| 15 |
e9e630de2c62953140357db0444c3c3a - |
| 16 |
e9e630de2c62953140357db0444c3c3a - |
| 17 |
e9e630de2c62953140357db0444c3c3a - |
| 18 |
e9e630de2c62953140357db0444c3c3a - |
| 19 |
``` |
| 20 |
|
| 21 |
or using `browserify --deps` on a [voxeljs](http://voxeljs.com/) project: |
| 22 |
|
| 23 |
``` |
| 24 |
$ for((i=0;i<5;i++)); do browserify --deps browser.js | deps-sort | browser-pack | md5sum; done |
| 25 |
fb418c74b53ba2e4cef7d01808b848e6 - |
| 26 |
fb418c74b53ba2e4cef7d01808b848e6 - |
| 27 |
fb418c74b53ba2e4cef7d01808b848e6 - |
| 28 |
fb418c74b53ba2e4cef7d01808b848e6 - |
| 29 |
fb418c74b53ba2e4cef7d01808b848e6 - |
| 30 |
``` |
| 31 |
|
| 32 |
## api |
| 33 |
|
| 34 |
To use this module programmatically, write streaming object data and read |
| 35 |
streaming object data: |
| 36 |
|
| 37 |
``` js |
| 38 |
var sort = require('../')(); |
| 39 |
var JSONStream = require('JSONStream'); |
| 40 |
var parse = JSONStream.parse([ true ]); |
| 41 |
var stringify = JSONStream.stringify(); |
| 42 |
|
| 43 |
process.stdin.pipe(parse).pipe(sort).pipe(stringify).pipe(process.stdout); |
| 44 |
``` |
| 45 |
|
| 46 |
# methods |
| 47 |
|
| 48 |
``` js |
| 49 |
var depsSort = require('deps-sort'); |
| 50 |
``` |
| 51 |
|
| 52 |
## var stream = depsSort(opts) |
| 53 |
|
| 54 |
Return a new through `stream` that should get written |
| 55 |
[module-deps](https://npmjs.org/package/module-deps) objects and will output |
| 56 |
sorted objects. |
| 57 |
|
| 58 |
`opts` can be: |
| 59 |
|
| 60 |
* `opts.index` - when true, for each module-deps row, insert `row.index` with |
| 61 |
the numeric index and `row.indexDeps` like `row.deps` but mapping require |
| 62 |
strings to row indices |
| 63 |
|
| 64 |
* `opts.expose` - array of names or object mapping names to `true` not to mangle |
| 65 |
with integer indexes when `opts.index` is turned on. If `opts.expose` maps names |
| 66 |
to strings, those strings will be used to resolve the indexed references. |
| 67 |
|
| 68 |
* `opts.dedupe` - set `row.dedupe` for files that match existing contents. Sets |
| 69 |
`row.dedupeIndex` when `opts.index` is enabled. When `row.dedupe` is set, |
| 70 |
`row.sameDeps` will be set to a boolean of whether the dependencies at the |
| 71 |
dedupe target match (true) or just the source content (false). |
| 72 |
|
| 73 |
# input objects |
| 74 |
|
| 75 |
Input objects are file objects in the [module-deps][] shape. They must at least |
| 76 |
have these properties: |
| 77 |
|
| 78 |
* `row.id` - a unique identifier for the file |
| 79 |
* `row.source` - the file contents |
| 80 |
* `row.deps` - dependencies for this file, mapping strings as used in |
| 81 |
`require()` to row IDs. |
| 82 |
|
| 83 |
# output objects |
| 84 |
|
| 85 |
All the input properties, and: |
| 86 |
|
| 87 |
* `row.index` - when `opts.index` is true, the sorted numeric index of the row |
| 88 |
* `row.indexDeps` - like `row.deps`, but mapping to `row.index` instead of |
| 89 |
`row.id` |
| 90 |
* `row.dedupe` - when `opts.dedupe` is true, contains the row ID of a file with |
| 91 |
identical contents |
| 92 |
* `row.dedupeIndex` - like `row.dedupe`, but contains the `row.index` instead |
| 93 |
of `row.id` |
| 94 |
|
| 95 |
# install |
| 96 |
|
| 97 |
With [npm](https://npmjs.org) do: |
| 98 |
|
| 99 |
``` |
| 100 |
npm install deps-sort |
| 101 |
``` |
| 102 |
|
| 103 |
# license |
| 104 |
|
| 105 |
MIT |
| 106 |
|
| 107 |
[module-deps]: https://github.com/browserify/module-deps#output-objects |