├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin.js ├── index.js ├── lib ├── cli.js ├── cycle.js └── npm-graph.js ├── package.json └── test ├── bad-refs ├── index.js └── package.json ├── cli.test.js ├── cycle.detection.test.js ├── fake-package ├── index.js ├── loc1.js ├── loc2.js ├── loc3.js ├── node_modules │ ├── fake2 │ │ ├── index.js │ │ └── package.json │ └── readable-stream │ │ ├── .npmignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── duplex.js │ │ ├── lib │ │ ├── _stream_duplex.js │ │ ├── _stream_passthrough.js │ │ ├── _stream_readable.js │ │ ├── _stream_transform.js │ │ └── _stream_writable.js │ │ ├── node_modules │ │ ├── core-util-is │ │ │ ├── README.md │ │ │ ├── float.patch │ │ │ ├── lib │ │ │ │ └── util.js │ │ │ ├── package.json │ │ │ └── util.js │ │ ├── inherits │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── inherits.js │ │ │ ├── inherits_browser.js │ │ │ ├── package.json │ │ │ └── test.js │ │ ├── isarray │ │ │ ├── README.md │ │ │ ├── build │ │ │ │ └── build.js │ │ │ ├── component.json │ │ │ ├── index.js │ │ │ └── package.json │ │ └── string_decoder │ │ │ ├── .npmignore │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── index.js │ │ │ └── package.json │ │ ├── package.json │ │ ├── passthrough.js │ │ ├── readable.js │ │ ├── transform.js │ │ └── writable.js └── package.json ├── json-includes ├── data.json ├── empty.json └── index.js └── self.graph.test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | lib-cov/ 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - 0.1 5 | - 4 6 | - node 7 | notifications: 8 | email: 9 | on_success: change 10 | on_failure: always 11 | after_script: 12 | - npm install coveralls 13 | - 'npm run coverage | coveralls' 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 0.5.0 / 2014-05-15 2 | ================== 3 | * Change CLI library to yargs and unit test the cli bits better 4 | * Remove colored output from cycle output (-c) 5 | * module-deps upgraded to `3.7.12` (big change) 6 | * Can now ignore missing dependencies with `--skip` #6 7 | - note that `-cov` requires are (still) ignored regardless 8 | - without `--skip`, first missing entry will halt the process 9 | * Can now ignore traversing the tree of specific modules with `--ignore` #8 10 | - will avoid populating huge dependency trees from specific modules 11 | - currently slightly inconsistent #9 12 | 13 | 0.4.0 / 2014-07-18 14 | ================== 15 | * do cycle analysis on the digraph given by module-deps 16 | * cyclical dependencies now detected and highlighted in the output tree 17 | * `-c` flag for raw cycles from Tarjan's algorithm 18 | * bump dependencies 19 | 20 | 0.3.3 / 2014-02-09 21 | ================== 22 | * module-deps upgraded to `1.5.0` 23 | 24 | 0.3.2 / 2014-02-09 25 | ================== 26 | * module-deps upgraded to `1.4.2` 27 | 28 | 0.3.1 / 2013-12-26 29 | ================== 30 | * `argv.b` can be used to additionally show builtins 31 | * `argv.l` can be used to additionally show locally required files (always parsed anyway) 32 | * library usage can set new options with `showBuiltins` and `showLocal` as keys 33 | 34 | 0.3.0 / 2013-12-25 35 | ================== 36 | * output now deterministic (#5) 37 | * module can now be used as a library as well 38 | 39 | 0.2.0 / 2013-12-25 40 | ================== 41 | * filter out builtins from the tree 42 | * fixed missing module dependencies from locally required files (#1) 43 | 44 | 0.1.0 / 2013-12-24 45 | ================== 46 | * package.json `bin` property now used properly as a fallback to directory entry 47 | 48 | 0.0.1 / 2013-12-24 49 | ================== 50 | * first release 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2013 Eirik Albrigtsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # npm graph 2 | [![npm status](http://img.shields.io/npm/v/npm-graph.svg)](https://www.npmjs.org/package/npm-graph) 3 | [![build status](https://secure.travis-ci.org/clux/npm-graph.svg)](http://travis-ci.org/clux/npm-graph) 4 | [![dependency status](https://david-dm.org/clux/npm-graph.svg)](https://david-dm.org/clux/npm-graph) 5 | [![coverage status](http://img.shields.io/coveralls/clux/npm-graph.svg)](https://coveralls.io/r/clux/npm-graph) 6 | 7 | Essentially `npm ls` with two modifications: 8 | 9 | - only explicitly required dependencies 10 | - finds cyclical requires 11 | 12 | Dependencies are analyzed using parts of the browserify toolchain. 13 | 14 | ## Usage 15 | Install globally and give it a path to a _local_ package or a file: 16 | 17 | ```bash 18 | $ npm install -g npm-graph 19 | ``` 20 | 21 | ### no arguments - npm modules only 22 | 23 | ``` 24 | $ npm-graph node_modules/irc-stream/ 25 | irc-stream 26 | └───irc 27 | ``` 28 | 29 | If all modules in "dependencies" are used, then this should look like `npm ls`. 30 | 31 | ### show builtins 32 | 33 | ``` 34 | $ npm-graph node_modules/irc-stream/ -b 35 | irc-stream 36 | ├──┬irc 37 | │ ├───net 38 | │ ├───tls 39 | │ └───util 40 | └───stream 41 | ``` 42 | 43 | This can give some at a glance information about how browserifiable the module is. 44 | 45 | ### show local files 46 | File by file inclusion: 47 | 48 | ``` 49 | $ npm-graph node_modules/irc-stream/ -l 50 | irc-stream 51 | └──┬irc 52 | ├───./codes 53 | └───./colors 54 | ``` 55 | 56 | ### cycle detection 57 | Cycles are detected and shown in the tree with a `↪` after an offender. As an example, readable-stream (tsk tsk) closes a cyclical loop by having Duplex depend on Writable and vice versa (albeit lightly). 58 | 59 | ``` 60 | $ npm install readable-stream@1.0.27-1 61 | $ npm-graph node_modules/readable-stream/writable.js -l 62 | writable.js 63 | └─┬./lib/_stream_writable.js 64 | ├─┬./_stream_duplex ↪ ./_stream_writable 65 | │ ├─┬./_stream_readable 66 | │ │ ├──core-util-is 67 | │ │ ├──inherits 68 | │ │ ├──isarray 69 | │ │ └──string_decoder/ 70 | │ ├──core-util-is 71 | │ └──inherits 72 | ├──core-util-is 73 | └──inherits 74 | ``` 75 | 76 | The mutual file inclusions would normally cause a recursion overflow when generating the tree if we hadn't first found the [strongly connected components](https://npmjs.org/package/strongly-connected-components) in the inclusion digraph and manually broken the cycle. 77 | 78 | ``` 79 | ( •_•) 80 | ( •_•)>⌐■-■ 81 | (⌐■_■) 82 | ``` 83 | 84 | The cyclical components from Tarjan's algorithm are also available with `-c`: 85 | 86 | ``` 87 | $ npm-graph node_modules/readable-stream/writable.js -l -c 88 | [ [ './node_modules/readable-stream/lib/_stream_writable.js', 89 | './node_modules/readable-stream/lib/_stream_duplex.js' ] ] 90 | ``` 91 | 92 | In this case, a 2-cycle. 93 | 94 | ## License 95 | MIT-Licensed. See LICENSE file for details. 96 | -------------------------------------------------------------------------------- /bin.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var argv = require('yargs') 3 | .usage('Usage: npm-graph [entryPoint] [options]') 4 | .example('npm-graph') 5 | .example('npm-graph node_modules/yargs --locals') 6 | .example('npm-graph cli.js') 7 | .example('npm-graph --cycles') 8 | .alias('l', 'locals') 9 | .describe('l', 'Show local file requires') 10 | .boolean('l') 11 | .alias('b', 'builtins') 12 | .describe('b', 'Show built in modules') 13 | .boolean('b') 14 | .alias('c', 'cycles') 15 | .describe('c', 'Show cycles only') 16 | .boolean('c') 17 | .alias('s', 'skip') 18 | .describe('s', 'Skip missing dependencies') 19 | .boolean('s') 20 | .alias('i', 'ignore') 21 | .describe('i', 'List of dependencies to ignore') 22 | .array('i') 23 | .help('h', 'help') 24 | .help('h') 25 | .argv; 26 | 27 | require('./').cli(argv, function (err, result) { 28 | if (err) { 29 | console.error(err.message); 30 | process.exit(1); 31 | } 32 | console.log(result); 33 | process.exit(0); 34 | }); 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = process.env.NPM_GRAPH_COV ? 2 | require('./lib-cov/npm-graph.js'): 3 | require('./lib/npm-graph.js'); 4 | 5 | module.exports.cli = process.env.NPM_GRAPH_COV ? 6 | require('./lib-cov/cli.js'): 7 | require('./lib/cli.js'); 8 | -------------------------------------------------------------------------------- /lib/cli.js: -------------------------------------------------------------------------------- 1 | var graph = require('./npm-graph').analyze 2 | , path = require('path') 3 | , fs = require('fs') 4 | ; 5 | 6 | module.exports = function (argv, cb) { 7 | var dir = path.join(process.cwd(), argv._[0] || '.'); 8 | var opts = { 9 | showLocal: Boolean(argv.l), 10 | showBuiltins: Boolean(argv.b), 11 | showCycles: Boolean(argv.c), 12 | ignoreMissing: Boolean(argv.s), 13 | ignored: argv.i || [] 14 | }; 15 | 16 | var name, file; 17 | // resolve entry point dynamically 18 | if (path.extname(dir) === '.js') { // either we got the specific entry point 19 | file = dir; 20 | name = path.basename(dir); 21 | } 22 | else { // or we got a directory which we try to infer the entry point of 23 | var pkg = require(path.join(dir, 'package.json')); 24 | name = pkg.name; 25 | var entry = pkg.main || 'index.js'; 26 | 27 | if (!fs.existsSync(path.join(dir, entry))) { 28 | var reason = "Failed to find the entry point of " + name; 29 | reason += " - try specifying it directly"; 30 | return cb(new Error(reason)); 31 | } 32 | file = path.join(dir, entry); 33 | } 34 | 35 | graph(file, name, cb, opts); 36 | }; 37 | -------------------------------------------------------------------------------- /lib/cycle.js: -------------------------------------------------------------------------------- 1 | var ssc = require('strongly-connected-components'); 2 | 3 | var createAdjacencyArrays = function (ms) { 4 | var indexed = []; // index -> unique id map 5 | Object.keys(ms).forEach(function (key, i) { 6 | indexed[i] = key; // what's the unique id of index i 7 | }); 8 | var adjacency = []; // index -> [adjacent indexes] 9 | Object.keys(ms).forEach(function (key, i) { 10 | adjacency[i] = ms[key].filter(function (o) { 11 | return o.path; // only care about cyclicals in code we can scan (not builtins) 12 | }).map(function (o) { 13 | // now leave only a map o 14 | var idx = indexed.indexOf(o.path); 15 | if (idx < 0) { 16 | throw new Error("logic fail"); 17 | } 18 | return idx; 19 | }); 20 | }); 21 | 22 | return { indexes: indexed, adjacency: adjacency }; 23 | }; 24 | 25 | exports.detect = function (ms) { 26 | var arys = createAdjacencyArrays(ms); 27 | var comps = ssc(arys.adjacency).components; 28 | arys.cycles = comps.filter(function (c) { 29 | return c.length > 1; // length 1 components have nothing referring back to it :] 30 | }).map(function (c) { 31 | return c.map(function (i) { 32 | return arys.indexes[i]; // convert back to unique ids 33 | }); 34 | }); 35 | return arys; 36 | }; 37 | 38 | // given a modules array with cycles - trim dependencies in each cycle 39 | var trimList = function (ms, cycles) { 40 | var removed = {}; 41 | 42 | cycles.forEach(function (c) { 43 | var last = c[c.length-1]; // last id in cycle 44 | //console.log('will try to trim from', last, ms[last]); 45 | 46 | // need to find a dependency in the cycle 47 | var depsInCycle = ms[last].filter(function (deps) { 48 | return deps.path && c.indexOf(deps.path) >= 0; 49 | }); 50 | if (!depsInCycle.length) { 51 | throw new Error("logic fail2"); // last thing in a cycle should have deps 52 | } 53 | var depToRemove = depsInCycle[0].path; 54 | //console.log('deps in cycle', depsInCycle); 55 | 56 | for (var i = 0; i < ms[last].length; i += 1) { 57 | var dep = ms[last][i]; 58 | if (dep.path && dep.path === depToRemove) { 59 | //console.log('removing', depToRemove); 60 | removed[last] = dep.name; 61 | ms[last].splice(i, 1); 62 | } 63 | } 64 | //console.log('after remove', ms[last]); 65 | }); 66 | 67 | return removed; 68 | }; 69 | 70 | // modifies input array 71 | exports.trimWhileCycles = function (ms) { 72 | var output = exports.detect(ms); 73 | var cycleData = { 74 | cycles: output.cycles.slice(), // original cycles found 75 | removed: {} 76 | }; 77 | 78 | var appendToRemoved = function (rm) { 79 | Object.keys(rm).forEach(function (key) { 80 | cycleData.removed[key] = rm[key]; 81 | }); 82 | }; 83 | 84 | output = exports.detect(ms); 85 | while (output.cycles.length) { 86 | var removed = trimList(ms, output.cycles); 87 | output = exports.detect(ms); // recompute cycles 88 | appendToRemoved(removed); 89 | } 90 | 91 | return cycleData; 92 | }; 93 | -------------------------------------------------------------------------------- /lib/npm-graph.js: -------------------------------------------------------------------------------- 1 | var mdeps = require('module-deps') 2 | , cycle = require('./cycle') 3 | , inspect = require('util').inspect 4 | , topiary = require('topiary'); 5 | 6 | // resolve non-core dependencies 7 | var coreModules = ['assert', 'buffer', 'child_process', 'cluster', 8 | 'console', 'crypto', 'dgram', 'dns', 'events', 'fs', 'http', 'https', 'net', 9 | 'os', 'path', 'punycode', 'querystring', 'readline', 'repl', 'stream', 10 | 'string_decoder', 'tls', 'tty', 'url', 'util', 'vm', 'zlib']; 11 | 12 | var isNotBuiltin = function (id) { 13 | return coreModules.indexOf(id) < 0; 14 | }; 15 | var isNotCoverage = function (id) { 16 | return !(/\/\w*\-cov\//).test(id); 17 | }; 18 | 19 | var isScannedForDeps = function (id) { 20 | return isNotBuiltin(id) && isNotCoverage(id); 21 | }; 22 | 23 | var notCoveredInArray = function (ary, name) { 24 | return ary.every(function (d) { 25 | return d.name !== name; 26 | }); 27 | }; 28 | 29 | exports.analyze = function (file, name, cb, opts) { 30 | opts = opts || {}; 31 | 32 | var showInTree = function (o) { 33 | return (opts.showBuiltins || isNotBuiltin(o.name)) && isNotCoverage(o.name); 34 | }; 35 | var isActuallyScanned = function (id) { 36 | return isScannedForDeps(id) && (opts.ignored || []).indexOf(id) < 0; 37 | }; 38 | 39 | var failed = false; 40 | var lookup = {}; 41 | var md = mdeps({ 42 | filter: isActuallyScanned, 43 | ignoreMissing: opts.ignoreMissing 44 | }); 45 | md.on('error', function (err) { 46 | if (!failed) { 47 | failed = true; 48 | cb(err); 49 | } 50 | }); 51 | md.on('data', function (o) { 52 | // o is object with `id` and `deps` = { relReq : id } 53 | lookup[o.id] = Object.keys(o.deps).map(function (key) { 54 | return { name: key, path: o.deps[key] }; 55 | }); 56 | }); 57 | md.on('end', function () { 58 | if (failed) { 59 | return; 60 | } 61 | var cycleData = cycle.trimWhileCycles(lookup); 62 | if (opts.showCycles) { 63 | return cb(null, inspect(cycleData.cycles)); 64 | } 65 | 66 | var labeler = function (o) { 67 | if (o.path && cycleData.removed[o.path]) { 68 | return o.name + " ↪ " + cycleData.removed[o.path]; 69 | } 70 | return o.name; 71 | }; 72 | 73 | // build a dependency tree from the flat mdeps list by recursing 74 | var traverse = function (currDeps, loc) { 75 | loc.deps = loc.deps || []; 76 | var covered = []; // only cover unique paths once to avoid stack overflow 77 | currDeps.forEach(function (obj) { 78 | if (covered.indexOf(obj.path) < 0) { 79 | covered.push(obj.path); // cover unique paths only once per level 80 | 81 | var key = obj.name 82 | , isRelative = (['\\', '/', '.'].indexOf(key[0]) >= 0) 83 | , notCovered = notCoveredInArray(loc.deps, key) 84 | , isRecorded = (!isRelative || opts.showLocal) && notCovered 85 | , res = isRecorded ? { name: key } : loc; 86 | 87 | if (isRecorded) { 88 | // NB: !isRecorded => only inspect the file for recorded deps 89 | res.path = obj.path; 90 | loc.deps.push(res); 91 | } 92 | 93 | // recurse (!isRecorded => keep adding to previous location) 94 | traverse(lookup[obj.path] || [], res); 95 | } 96 | }); 97 | }; 98 | var tree = { name: name, path: file }; 99 | traverse(lookup[file], tree); 100 | 101 | cb(null, topiary(tree, 'deps', { 102 | filter: showInTree, 103 | sort: true, 104 | name: labeler 105 | })); 106 | }); 107 | md.end(file); 108 | }; 109 | 110 | exports.cycle = cycle; 111 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "npm-graph", 3 | "description": "Prints a dependency graph of modules that is actually required", 4 | "author": "Eirik Albrigtsen ", 5 | "version": "0.5.0", 6 | "repository": { 7 | "type": "git", 8 | "url": "clux/npm-graph" 9 | }, 10 | "keywords": [ 11 | "npm ls", 12 | "browserify", 13 | "dependencies", 14 | "analysis" 15 | ], 16 | "main": "index.js", 17 | "bin": "bin.js", 18 | "scripts": { 19 | "test": "nodeunit --reporter=verbose test/*.js", 20 | "coverage": "jscoverage lib && NPM_GRAPH_COV=1 nodeunit --reporter=lcov test" 21 | }, 22 | "dependencies": { 23 | "module-deps": "^4.0.5", 24 | "strongly-connected-components": "^1.0.1", 25 | "topiary": "^1.1.1", 26 | "yargs": "^3.9.0" 27 | }, 28 | "devDependencies": { 29 | "nodeunit": "~0.9.0", 30 | "jscoverage": "~0.5.4" 31 | }, 32 | "bugs": { 33 | "url": "http://github.com/clux/npm-graph/issues" 34 | }, 35 | "license": "MIT" 36 | } 37 | -------------------------------------------------------------------------------- /test/bad-refs/index.js: -------------------------------------------------------------------------------- 1 | var d = require('uninstalled-dep'); 2 | -------------------------------------------------------------------------------- /test/bad-refs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bad-refs", 3 | "version": "0.0.0", 4 | "description": "A fake package with missing local references", 5 | "main": "index.js", 6 | "private": true, 7 | "optionalDependencies": { 8 | "uninstalled-dep": "latest" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/cli.test.js: -------------------------------------------------------------------------------- 1 | var cli = require('../').cli; 2 | //var fs = require('fs'); 3 | var join = require('path').join; 4 | 5 | exports.blankarg = function (t) { 6 | var argv = { _ : [] }; 7 | 8 | cli(argv, function (err, str) { 9 | t.ok(!err, "no error"); 10 | t.ok(str, 'got result'); 11 | t.ok(str.indexOf('./') < 0, 'no locals'); 12 | t.ok(str.indexOf('─path') < 0, 'no builtins'); 13 | t.equal(str.split('\n')[0], 'npm-graph', "of cwd"); 14 | t.done(); 15 | }); 16 | }; 17 | 18 | exports.blankarg = function (t) { 19 | var argv = { _ : [], l: true, b: true }; 20 | 21 | cli(argv, function (err, str) { 22 | t.ok(!err, "no error"); 23 | t.ok(str, 'got result'); 24 | t.equal(str.split('\n')[0], 'npm-graph', "of cwd"); 25 | t.ok(str.indexOf('─path') >= 0, 'goto builtins'); 26 | t.ok(str.indexOf('./cycle') >= 0, 'got locals'); 27 | t.done(); 28 | }); 29 | }; 30 | 31 | var writableEntry = join( 32 | 'test', 33 | 'fake-package', 34 | 'node_modules', 35 | 'readable-stream', 36 | 'writable.js' 37 | ); 38 | exports.cycle = function (t) { 39 | var argv = { _ : [writableEntry], l: true }; 40 | 41 | cli(argv, function (err, str) { 42 | t.ok(!err, "no error"); 43 | t.ok(str, 'got result'); 44 | t.equal(str.split('\n')[0], 'writable.js', "of entrypoint"); 45 | t.ok(str.indexOf('↪') >= 0, 'got cycle symbol'); 46 | t.done(); 47 | }); 48 | }; 49 | 50 | exports.cycle = function (t) { 51 | var argv = { _ : [writableEntry], c: true }; 52 | cli(argv, function (err, res) { 53 | t.ok(!err, "no error"); 54 | t.ok(res, 'got result'); 55 | t.equal(res.slice(0, 5), "[ [ '", "got at least one cycle"); 56 | t.equal(res.split('\n').length, 2, 'of size 2'); 57 | t.done(); 58 | }); 59 | }; 60 | 61 | exports.missing = function (t) { 62 | var argv = { _ : [ join('test', 'bad-refs') ], s: true }; 63 | cli(argv, function (err, str) { 64 | t.ok(!err, "no error"); 65 | t.ok(str, "got result"); 66 | t.equal(str.split('\n').join(''), 'bad-refs └──uninstalled-dep', 'result'); 67 | t.done(); 68 | }); 69 | }; 70 | 71 | exports.missingFailed = function (t) { 72 | var argv = { _ : [ join('test', 'bad-refs') ] }; 73 | cli(argv, function (err, str) { 74 | t.ok(err, 'should fail'); 75 | t.ok(err.message.indexOf('uninstalled-dep') >= 0, 'missing dep'); 76 | t.ok(!str, 'no result'); 77 | t.done(); 78 | }); 79 | }; 80 | 81 | exports.missingIgnored = function (t) { 82 | var argv = { _ : [ join('test', 'bad-refs') ], 'i': ['uninstalled-dep'] }; 83 | cli(argv, function (err, str) { 84 | t.ok(!err, "no error"); 85 | t.ok(str, "got result"); 86 | t.equal(str.split('\n').join(''), 'bad-refs └──uninstalled-dep', 'result'); 87 | t.done(); 88 | }); 89 | }; 90 | -------------------------------------------------------------------------------- /test/cycle.detection.test.js: -------------------------------------------------------------------------------- 1 | var cycle = require('../').cycle; 2 | 3 | var modules = { 4 | 'md/__nm__/through2/__nm__/xtend/has-keys.js': [], 5 | 'md/__nm__/readable-stream/__nm__/core-util-is/lib/util.js': [], 6 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/foreach.js': [], 7 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/isArguments.js': [], 8 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/shim.js': [ 9 | { name: './foreach', path: 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/foreach.js' }, 10 | { name: './isArguments', path: 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/isArguments.js' } 11 | ], 12 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/index.js': [ 13 | { name: './shim', path: 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/shim.js' } 14 | ], 15 | 'md/__nm__/through2/__nm__/xtend/index.js': [ 16 | { name: './has-keys', path: 'md/__nm__/through2/__nm__/xtend/has-keys.js' }, 17 | { name: 'object-keys', path: 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/index.js' } 18 | ], 19 | 'md/__nm__/inherits/inherits_browser.js': [], 20 | 'md/__nm__/readable-stream/lib/_stream_writable.js': [ 21 | { name: 'buffer', path: false }, 22 | { name: 'stream', path: false }, 23 | { name: './_stream_duplex', path: 'md/__nm__/readable-stream/lib/_stream_duplex.js' }, 24 | { name: 'core-util-is', path: 'md/__nm__/readable-stream/__nm__/core-util-is/lib/util.js' }, 25 | { name: 'inherits', path: 'md/__nm__/inherits/inherits_browser.js' } 26 | ], 27 | 'md/__nm__/readable-stream/__nm__/string_decoder/index.js': [ { name: 'buffer', path: false } ], 28 | 'md/__nm__/readable-stream/__nm__/isarray/index.js': [], 29 | 'md/__nm__/readable-stream/lib/_stream_readable.js': [ 30 | { name: 'buffer', path: false }, 31 | { name: 'events', path: false }, 32 | { name: 'stream', path: false }, 33 | { name: 'core-util-is', path: 'md/__nm__/readable-stream/__nm__/core-util-is/lib/util.js' }, 34 | { name: 'string_decoder/', path: 'md/__nm__/readable-stream/__nm__/string_decoder/index.js' }, 35 | { name: 'inherits', path: 'md/__nm__/inherits/inherits_browser.js' }, 36 | { name: 'isarray', path: 'md/__nm__/readable-stream/__nm__/isarray/index.js' } 37 | ], 38 | 'md/__nm__/readable-stream/lib/_stream_duplex.js': [ 39 | { name: 'core-util-is', path: 'md/__nm__/readable-stream/__nm__/core-util-is/lib/util.js' }, 40 | { name: 'inherits', path: 'md/__nm__/inherits/inherits_browser.js' }, 41 | { name: './_stream_writable', path: 'md/__nm__/readable-stream/lib/_stream_writable.js' }, 42 | { name: './_stream_readable', path: 'md/__nm__/readable-stream/lib/_stream_readable.js' } 43 | ], 44 | 'md/__nm__/readable-stream/lib/_stream_transform.js': [ 45 | { name: 'core-util-is', path: 'md/__nm__/readable-stream/__nm__/core-util-is/lib/util.js' }, 46 | { name: 'inherits', path: 'md/__nm__/inherits/inherits_browser.js' }, 47 | { name: './_stream_duplex', path: 'md/__nm__/readable-stream/lib/_stream_duplex.js' } 48 | ], 49 | 'md/__nm__/readable-stream/transform.js': [ 50 | { name: './lib/_stream_transform.js', path: 'md/__nm__/readable-stream/lib/_stream_transform.js' } 51 | ], 52 | 'md/__nm__/through2/through2.js': [ 53 | { name: 'util', path: false }, 54 | { name: 'xtend', path: 'md/__nm__/through2/__nm__/xtend/index.js' }, 55 | { name: 'readable-stream/transform', path: 'md/__nm__/readable-stream/transform.js' } 56 | ] 57 | }; 58 | 59 | var expected = { 60 | indexes: [ 61 | 'md/__nm__/through2/__nm__/xtend/has-keys.js', // 0 62 | 'md/__nm__/readable-stream/__nm__/core-util-is/lib/util.js', // 1 63 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/foreach.js', // 2 64 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/isArguments.js', // 3 65 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/shim.js', // 4 66 | 'md/__nm__/through2/__nm__/xtend/__nm__/object-keys/index.js', // 5 67 | 'md/__nm__/through2/__nm__/xtend/index.js', // 6 68 | 'md/__nm__/inherits/inherits_browser.js', // 7 69 | 'md/__nm__/readable-stream/lib/_stream_writable.js', // 8 70 | 'md/__nm__/readable-stream/__nm__/string_decoder/index.js', // 9 71 | 'md/__nm__/readable-stream/__nm__/isarray/index.js', // 10 72 | 'md/__nm__/readable-stream/lib/_stream_readable.js', // 11 73 | 'md/__nm__/readable-stream/lib/_stream_duplex.js', // 12 74 | 'md/__nm__/readable-stream/lib/_stream_transform.js', // 13 75 | 'md/__nm__/readable-stream/transform.js', // 14 76 | 'md/__nm__/through2/through2.js' // 15 77 | ], 78 | adjacency: [ 79 | [], // 0 has-keys 80 | [], // 1 core utils lib util 81 | [], // 2 foreach 82 | [], // 3 isarguments 83 | [ 2, 3 ], // 4 object keys shim 84 | [ 4 ], // 5 object keys index 85 | [ 0, 5 ], // 6 xtend index 86 | [], // 7 inherits browser 87 | [ 12, 1, 7 ], // 8 _stream_writable 88 | [], // 9 string decoder index 89 | [], // 10 isarray index 90 | [ 1, 9, 7, 10 ], // 11 _stream_readable 91 | [ 1, 7, 8, 11 ], // 12 _stream_duplex 92 | [ 1, 7, 12 ], // 13 _stream_transform 93 | [ 13 ], // 14 transform 94 | [ 6, 14 ] // 15 through2 95 | ], 96 | cycles: [ 97 | [ 98 | 'md/__nm__/readable-stream/lib/_stream_duplex.js', 99 | 'md/__nm__/readable-stream/lib/_stream_writable.js' 100 | ] 101 | ] 102 | }; 103 | 104 | exports.cycle = function (t) { 105 | var output = cycle.detect(modules); 106 | t.deepEqual(output.indexes, expected.indexes, "it indexed correctly"); 107 | t.deepEqual(output.adjacency, expected.adjacency, "it created adjacency list"); 108 | t.deepEqual(output.cycles, expected.cycles, "it found one cycle"); 109 | 110 | // how we expect cycle breaking to happen 111 | var offender = 'md/__nm__/readable-stream/lib/_stream_writable.js'; 112 | var cut = 'md/__nm__/readable-stream/lib/_stream_duplex.js'; 113 | t.equal(modules[offender].length, 5, 'originally 5 deps for offender'); 114 | var offendersDepsCut = modules[offender].filter(function (dep) { 115 | return dep.path !== cut; 116 | }); 117 | 118 | // break cycles 119 | var trimOutput = cycle.trimWhileCycles(modules); 120 | var trimmed = cycle.detect(modules); 121 | t.deepEqual(trimOutput.cycles, expected.cycles, "trimWhileCycles returns original cycles"); 122 | 123 | // verify that we only removed one element from the cycle (and this was sufficient) 124 | t.deepEqual(trimmed.cycles, [], "no cycles anymore"); 125 | t.equal(modules[offender].length, 4, 'should be one less now'); 126 | t.deepEqual(offendersDepsCut, modules[offender], 'one less dep now'); 127 | 128 | t.done(); 129 | }; 130 | -------------------------------------------------------------------------------- /test/fake-package/index.js: -------------------------------------------------------------------------------- 1 | var stream = require('stream'); 2 | var util = require('util'); 3 | 4 | var loc1 = require('./loc1'); 5 | var loc2 = require('./loc2'); 6 | var loc3 = require('./loc3'); 7 | -------------------------------------------------------------------------------- /test/fake-package/loc1.js: -------------------------------------------------------------------------------- 1 | var stream = require('stream'); 2 | 3 | var loc3 = require('./loc3'); 4 | -------------------------------------------------------------------------------- /test/fake-package/loc2.js: -------------------------------------------------------------------------------- 1 | var l1 = require('./loc1') 2 | 3 | module.exports = require('fake2'); 4 | -------------------------------------------------------------------------------- /test/fake-package/loc3.js: -------------------------------------------------------------------------------- 1 | var fake2 = require('fake2'); 2 | 3 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/fake2/index.js: -------------------------------------------------------------------------------- 1 | var stream = require('stream') 2 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/fake2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fake2", 3 | "version": "0.0.0", 4 | "description": "Another fake package", 5 | "main": "index.js", 6 | "private": true, 7 | "dependencies": {} 8 | } 9 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/.npmignore: -------------------------------------------------------------------------------- 1 | build/ 2 | test/ 3 | examples/ 4 | fs.js 5 | zlib.js -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Isaac Z. Schlueter ("Author") 2 | All rights reserved. 3 | 4 | The BSD License 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 21 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/README.md: -------------------------------------------------------------------------------- 1 | # readable-stream 2 | 3 | ***Node-core streams for userland*** 4 | 5 | [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true)](https://nodei.co/npm/readable-stream/) 6 | [![NPM](https://nodei.co/npm-dl/readable-stream.png)](https://nodei.co/npm/readable-stream/) 7 | 8 | This package is a mirror of the Streams2 and Streams3 implementations in Node-core. 9 | 10 | If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core. 11 | 12 | **readable-stream** comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12. 13 | 14 | **readable-stream** uses proper patch-level versioning so if you pin to `"~1.0.0"` you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the **1.0.x** releases for now and when you’re ready to start using Streams3, pin to `"~1.1.0"` 15 | 16 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/duplex.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_duplex.js") 2 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/lib/_stream_duplex.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // a duplex stream is just a stream that is both readable and writable. 23 | // Since JS doesn't have multiple prototypal inheritance, this class 24 | // prototypally inherits from Readable, and then parasitically from 25 | // Writable. 26 | 27 | module.exports = Duplex; 28 | 29 | /**/ 30 | var objectKeys = Object.keys || function (obj) { 31 | var keys = []; 32 | for (var key in obj) keys.push(key); 33 | return keys; 34 | } 35 | /**/ 36 | 37 | 38 | /**/ 39 | var util = require('core-util-is'); 40 | util.inherits = require('inherits'); 41 | /**/ 42 | 43 | var Readable = require('./_stream_readable'); 44 | var Writable = require('./_stream_writable'); 45 | 46 | util.inherits(Duplex, Readable); 47 | 48 | forEach(objectKeys(Writable.prototype), function(method) { 49 | if (!Duplex.prototype[method]) 50 | Duplex.prototype[method] = Writable.prototype[method]; 51 | }); 52 | 53 | function Duplex(options) { 54 | if (!(this instanceof Duplex)) 55 | return new Duplex(options); 56 | 57 | Readable.call(this, options); 58 | Writable.call(this, options); 59 | 60 | if (options && options.readable === false) 61 | this.readable = false; 62 | 63 | if (options && options.writable === false) 64 | this.writable = false; 65 | 66 | this.allowHalfOpen = true; 67 | if (options && options.allowHalfOpen === false) 68 | this.allowHalfOpen = false; 69 | 70 | this.once('end', onend); 71 | } 72 | 73 | // the no-half-open enforcer 74 | function onend() { 75 | // if we allow half-open state, or if the writable side ended, 76 | // then we're ok. 77 | if (this.allowHalfOpen || this._writableState.ended) 78 | return; 79 | 80 | // no more data can be written. 81 | // But allow more writes to happen in this tick. 82 | process.nextTick(this.end.bind(this)); 83 | } 84 | 85 | function forEach (xs, f) { 86 | for (var i = 0, l = xs.length; i < l; i++) { 87 | f(xs[i], i); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/lib/_stream_passthrough.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // a passthrough stream. 23 | // basically just the most minimal sort of Transform stream. 24 | // Every written chunk gets output as-is. 25 | 26 | module.exports = PassThrough; 27 | 28 | var Transform = require('./_stream_transform'); 29 | 30 | /**/ 31 | var util = require('core-util-is'); 32 | util.inherits = require('inherits'); 33 | /**/ 34 | 35 | util.inherits(PassThrough, Transform); 36 | 37 | function PassThrough(options) { 38 | if (!(this instanceof PassThrough)) 39 | return new PassThrough(options); 40 | 41 | Transform.call(this, options); 42 | } 43 | 44 | PassThrough.prototype._transform = function(chunk, encoding, cb) { 45 | cb(null, chunk); 46 | }; 47 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/lib/_stream_readable.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | module.exports = Readable; 23 | 24 | /**/ 25 | var isArray = require('isarray'); 26 | /**/ 27 | 28 | 29 | /**/ 30 | var Buffer = require('buffer').Buffer; 31 | /**/ 32 | 33 | Readable.ReadableState = ReadableState; 34 | 35 | var EE = require('events').EventEmitter; 36 | 37 | /**/ 38 | if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { 39 | return emitter.listeners(type).length; 40 | }; 41 | /**/ 42 | 43 | var Stream = require('stream'); 44 | 45 | /**/ 46 | var util = require('core-util-is'); 47 | util.inherits = require('inherits'); 48 | /**/ 49 | 50 | var StringDecoder; 51 | 52 | util.inherits(Readable, Stream); 53 | 54 | function ReadableState(options, stream) { 55 | options = options || {}; 56 | 57 | // the point at which it stops calling _read() to fill the buffer 58 | // Note: 0 is a valid value, means "don't call _read preemptively ever" 59 | var hwm = options.highWaterMark; 60 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024; 61 | 62 | // cast to ints. 63 | this.highWaterMark = ~~this.highWaterMark; 64 | 65 | this.buffer = []; 66 | this.length = 0; 67 | this.pipes = null; 68 | this.pipesCount = 0; 69 | this.flowing = false; 70 | this.ended = false; 71 | this.endEmitted = false; 72 | this.reading = false; 73 | 74 | // In streams that never have any data, and do push(null) right away, 75 | // the consumer can miss the 'end' event if they do some I/O before 76 | // consuming the stream. So, we don't emit('end') until some reading 77 | // happens. 78 | this.calledRead = false; 79 | 80 | // a flag to be able to tell if the onwrite cb is called immediately, 81 | // or on a later tick. We set this to true at first, becuase any 82 | // actions that shouldn't happen until "later" should generally also 83 | // not happen before the first write call. 84 | this.sync = true; 85 | 86 | // whenever we return null, then we set a flag to say 87 | // that we're awaiting a 'readable' event emission. 88 | this.needReadable = false; 89 | this.emittedReadable = false; 90 | this.readableListening = false; 91 | 92 | 93 | // object stream flag. Used to make read(n) ignore n and to 94 | // make all the buffer merging and length checks go away 95 | this.objectMode = !!options.objectMode; 96 | 97 | // Crypto is kind of old and crusty. Historically, its default string 98 | // encoding is 'binary' so we have to make this configurable. 99 | // Everything else in the universe uses 'utf8', though. 100 | this.defaultEncoding = options.defaultEncoding || 'utf8'; 101 | 102 | // when piping, we only care about 'readable' events that happen 103 | // after read()ing all the bytes and not getting any pushback. 104 | this.ranOut = false; 105 | 106 | // the number of writers that are awaiting a drain event in .pipe()s 107 | this.awaitDrain = 0; 108 | 109 | // if true, a maybeReadMore has been scheduled 110 | this.readingMore = false; 111 | 112 | this.decoder = null; 113 | this.encoding = null; 114 | if (options.encoding) { 115 | if (!StringDecoder) 116 | StringDecoder = require('string_decoder/').StringDecoder; 117 | this.decoder = new StringDecoder(options.encoding); 118 | this.encoding = options.encoding; 119 | } 120 | } 121 | 122 | function Readable(options) { 123 | if (!(this instanceof Readable)) 124 | return new Readable(options); 125 | 126 | this._readableState = new ReadableState(options, this); 127 | 128 | // legacy 129 | this.readable = true; 130 | 131 | Stream.call(this); 132 | } 133 | 134 | // Manually shove something into the read() buffer. 135 | // This returns true if the highWaterMark has not been hit yet, 136 | // similar to how Writable.write() returns true if you should 137 | // write() some more. 138 | Readable.prototype.push = function(chunk, encoding) { 139 | var state = this._readableState; 140 | 141 | if (typeof chunk === 'string' && !state.objectMode) { 142 | encoding = encoding || state.defaultEncoding; 143 | if (encoding !== state.encoding) { 144 | chunk = new Buffer(chunk, encoding); 145 | encoding = ''; 146 | } 147 | } 148 | 149 | return readableAddChunk(this, state, chunk, encoding, false); 150 | }; 151 | 152 | // Unshift should *always* be something directly out of read() 153 | Readable.prototype.unshift = function(chunk) { 154 | var state = this._readableState; 155 | return readableAddChunk(this, state, chunk, '', true); 156 | }; 157 | 158 | function readableAddChunk(stream, state, chunk, encoding, addToFront) { 159 | var er = chunkInvalid(state, chunk); 160 | if (er) { 161 | stream.emit('error', er); 162 | } else if (chunk === null || chunk === undefined) { 163 | state.reading = false; 164 | if (!state.ended) 165 | onEofChunk(stream, state); 166 | } else if (state.objectMode || chunk && chunk.length > 0) { 167 | if (state.ended && !addToFront) { 168 | var e = new Error('stream.push() after EOF'); 169 | stream.emit('error', e); 170 | } else if (state.endEmitted && addToFront) { 171 | var e = new Error('stream.unshift() after end event'); 172 | stream.emit('error', e); 173 | } else { 174 | if (state.decoder && !addToFront && !encoding) 175 | chunk = state.decoder.write(chunk); 176 | 177 | // update the buffer info. 178 | state.length += state.objectMode ? 1 : chunk.length; 179 | if (addToFront) { 180 | state.buffer.unshift(chunk); 181 | } else { 182 | state.reading = false; 183 | state.buffer.push(chunk); 184 | } 185 | 186 | if (state.needReadable) 187 | emitReadable(stream); 188 | 189 | maybeReadMore(stream, state); 190 | } 191 | } else if (!addToFront) { 192 | state.reading = false; 193 | } 194 | 195 | return needMoreData(state); 196 | } 197 | 198 | 199 | 200 | // if it's past the high water mark, we can push in some more. 201 | // Also, if we have no data yet, we can stand some 202 | // more bytes. This is to work around cases where hwm=0, 203 | // such as the repl. Also, if the push() triggered a 204 | // readable event, and the user called read(largeNumber) such that 205 | // needReadable was set, then we ought to push more, so that another 206 | // 'readable' event will be triggered. 207 | function needMoreData(state) { 208 | return !state.ended && 209 | (state.needReadable || 210 | state.length < state.highWaterMark || 211 | state.length === 0); 212 | } 213 | 214 | // backwards compatibility. 215 | Readable.prototype.setEncoding = function(enc) { 216 | if (!StringDecoder) 217 | StringDecoder = require('string_decoder/').StringDecoder; 218 | this._readableState.decoder = new StringDecoder(enc); 219 | this._readableState.encoding = enc; 220 | }; 221 | 222 | // Don't raise the hwm > 128MB 223 | var MAX_HWM = 0x800000; 224 | function roundUpToNextPowerOf2(n) { 225 | if (n >= MAX_HWM) { 226 | n = MAX_HWM; 227 | } else { 228 | // Get the next highest power of 2 229 | n--; 230 | for (var p = 1; p < 32; p <<= 1) n |= n >> p; 231 | n++; 232 | } 233 | return n; 234 | } 235 | 236 | function howMuchToRead(n, state) { 237 | if (state.length === 0 && state.ended) 238 | return 0; 239 | 240 | if (state.objectMode) 241 | return n === 0 ? 0 : 1; 242 | 243 | if (isNaN(n) || n === null) { 244 | // only flow one buffer at a time 245 | if (state.flowing && state.buffer.length) 246 | return state.buffer[0].length; 247 | else 248 | return state.length; 249 | } 250 | 251 | if (n <= 0) 252 | return 0; 253 | 254 | // If we're asking for more than the target buffer level, 255 | // then raise the water mark. Bump up to the next highest 256 | // power of 2, to prevent increasing it excessively in tiny 257 | // amounts. 258 | if (n > state.highWaterMark) 259 | state.highWaterMark = roundUpToNextPowerOf2(n); 260 | 261 | // don't have that much. return null, unless we've ended. 262 | if (n > state.length) { 263 | if (!state.ended) { 264 | state.needReadable = true; 265 | return 0; 266 | } else 267 | return state.length; 268 | } 269 | 270 | return n; 271 | } 272 | 273 | // you can override either this method, or the async _read(n) below. 274 | Readable.prototype.read = function(n) { 275 | var state = this._readableState; 276 | state.calledRead = true; 277 | var nOrig = n; 278 | 279 | if (typeof n !== 'number' || n > 0) 280 | state.emittedReadable = false; 281 | 282 | // if we're doing read(0) to trigger a readable event, but we 283 | // already have a bunch of data in the buffer, then just trigger 284 | // the 'readable' event and move on. 285 | if (n === 0 && 286 | state.needReadable && 287 | (state.length >= state.highWaterMark || state.ended)) { 288 | emitReadable(this); 289 | return null; 290 | } 291 | 292 | n = howMuchToRead(n, state); 293 | 294 | // if we've ended, and we're now clear, then finish it up. 295 | if (n === 0 && state.ended) { 296 | if (state.length === 0) 297 | endReadable(this); 298 | return null; 299 | } 300 | 301 | // All the actual chunk generation logic needs to be 302 | // *below* the call to _read. The reason is that in certain 303 | // synthetic stream cases, such as passthrough streams, _read 304 | // may be a completely synchronous operation which may change 305 | // the state of the read buffer, providing enough data when 306 | // before there was *not* enough. 307 | // 308 | // So, the steps are: 309 | // 1. Figure out what the state of things will be after we do 310 | // a read from the buffer. 311 | // 312 | // 2. If that resulting state will trigger a _read, then call _read. 313 | // Note that this may be asynchronous, or synchronous. Yes, it is 314 | // deeply ugly to write APIs this way, but that still doesn't mean 315 | // that the Readable class should behave improperly, as streams are 316 | // designed to be sync/async agnostic. 317 | // Take note if the _read call is sync or async (ie, if the read call 318 | // has returned yet), so that we know whether or not it's safe to emit 319 | // 'readable' etc. 320 | // 321 | // 3. Actually pull the requested chunks out of the buffer and return. 322 | 323 | // if we need a readable event, then we need to do some reading. 324 | var doRead = state.needReadable; 325 | 326 | // if we currently have less than the highWaterMark, then also read some 327 | if (state.length - n <= state.highWaterMark) 328 | doRead = true; 329 | 330 | // however, if we've ended, then there's no point, and if we're already 331 | // reading, then it's unnecessary. 332 | if (state.ended || state.reading) 333 | doRead = false; 334 | 335 | if (doRead) { 336 | state.reading = true; 337 | state.sync = true; 338 | // if the length is currently zero, then we *need* a readable event. 339 | if (state.length === 0) 340 | state.needReadable = true; 341 | // call internal read method 342 | this._read(state.highWaterMark); 343 | state.sync = false; 344 | } 345 | 346 | // If _read called its callback synchronously, then `reading` 347 | // will be false, and we need to re-evaluate how much data we 348 | // can return to the user. 349 | if (doRead && !state.reading) 350 | n = howMuchToRead(nOrig, state); 351 | 352 | var ret; 353 | if (n > 0) 354 | ret = fromList(n, state); 355 | else 356 | ret = null; 357 | 358 | if (ret === null) { 359 | state.needReadable = true; 360 | n = 0; 361 | } 362 | 363 | state.length -= n; 364 | 365 | // If we have nothing in the buffer, then we want to know 366 | // as soon as we *do* get something into the buffer. 367 | if (state.length === 0 && !state.ended) 368 | state.needReadable = true; 369 | 370 | // If we happened to read() exactly the remaining amount in the 371 | // buffer, and the EOF has been seen at this point, then make sure 372 | // that we emit 'end' on the very next tick. 373 | if (state.ended && !state.endEmitted && state.length === 0) 374 | endReadable(this); 375 | 376 | return ret; 377 | }; 378 | 379 | function chunkInvalid(state, chunk) { 380 | var er = null; 381 | if (!Buffer.isBuffer(chunk) && 382 | 'string' !== typeof chunk && 383 | chunk !== null && 384 | chunk !== undefined && 385 | !state.objectMode && 386 | !er) { 387 | er = new TypeError('Invalid non-string/buffer chunk'); 388 | } 389 | return er; 390 | } 391 | 392 | 393 | function onEofChunk(stream, state) { 394 | if (state.decoder && !state.ended) { 395 | var chunk = state.decoder.end(); 396 | if (chunk && chunk.length) { 397 | state.buffer.push(chunk); 398 | state.length += state.objectMode ? 1 : chunk.length; 399 | } 400 | } 401 | state.ended = true; 402 | 403 | // if we've ended and we have some data left, then emit 404 | // 'readable' now to make sure it gets picked up. 405 | if (state.length > 0) 406 | emitReadable(stream); 407 | else 408 | endReadable(stream); 409 | } 410 | 411 | // Don't emit readable right away in sync mode, because this can trigger 412 | // another read() call => stack overflow. This way, it might trigger 413 | // a nextTick recursion warning, but that's not so bad. 414 | function emitReadable(stream) { 415 | var state = stream._readableState; 416 | state.needReadable = false; 417 | if (state.emittedReadable) 418 | return; 419 | 420 | state.emittedReadable = true; 421 | if (state.sync) 422 | process.nextTick(function() { 423 | emitReadable_(stream); 424 | }); 425 | else 426 | emitReadable_(stream); 427 | } 428 | 429 | function emitReadable_(stream) { 430 | stream.emit('readable'); 431 | } 432 | 433 | 434 | // at this point, the user has presumably seen the 'readable' event, 435 | // and called read() to consume some data. that may have triggered 436 | // in turn another _read(n) call, in which case reading = true if 437 | // it's in progress. 438 | // However, if we're not ended, or reading, and the length < hwm, 439 | // then go ahead and try to read some more preemptively. 440 | function maybeReadMore(stream, state) { 441 | if (!state.readingMore) { 442 | state.readingMore = true; 443 | process.nextTick(function() { 444 | maybeReadMore_(stream, state); 445 | }); 446 | } 447 | } 448 | 449 | function maybeReadMore_(stream, state) { 450 | var len = state.length; 451 | while (!state.reading && !state.flowing && !state.ended && 452 | state.length < state.highWaterMark) { 453 | stream.read(0); 454 | if (len === state.length) 455 | // didn't get any data, stop spinning. 456 | break; 457 | else 458 | len = state.length; 459 | } 460 | state.readingMore = false; 461 | } 462 | 463 | // abstract method. to be overridden in specific implementation classes. 464 | // call cb(er, data) where data is <= n in length. 465 | // for virtual (non-string, non-buffer) streams, "length" is somewhat 466 | // arbitrary, and perhaps not very meaningful. 467 | Readable.prototype._read = function(n) { 468 | this.emit('error', new Error('not implemented')); 469 | }; 470 | 471 | Readable.prototype.pipe = function(dest, pipeOpts) { 472 | var src = this; 473 | var state = this._readableState; 474 | 475 | switch (state.pipesCount) { 476 | case 0: 477 | state.pipes = dest; 478 | break; 479 | case 1: 480 | state.pipes = [state.pipes, dest]; 481 | break; 482 | default: 483 | state.pipes.push(dest); 484 | break; 485 | } 486 | state.pipesCount += 1; 487 | 488 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && 489 | dest !== process.stdout && 490 | dest !== process.stderr; 491 | 492 | var endFn = doEnd ? onend : cleanup; 493 | if (state.endEmitted) 494 | process.nextTick(endFn); 495 | else 496 | src.once('end', endFn); 497 | 498 | dest.on('unpipe', onunpipe); 499 | function onunpipe(readable) { 500 | if (readable !== src) return; 501 | cleanup(); 502 | } 503 | 504 | function onend() { 505 | dest.end(); 506 | } 507 | 508 | // when the dest drains, it reduces the awaitDrain counter 509 | // on the source. This would be more elegant with a .once() 510 | // handler in flow(), but adding and removing repeatedly is 511 | // too slow. 512 | var ondrain = pipeOnDrain(src); 513 | dest.on('drain', ondrain); 514 | 515 | function cleanup() { 516 | // cleanup event handlers once the pipe is broken 517 | dest.removeListener('close', onclose); 518 | dest.removeListener('finish', onfinish); 519 | dest.removeListener('drain', ondrain); 520 | dest.removeListener('error', onerror); 521 | dest.removeListener('unpipe', onunpipe); 522 | src.removeListener('end', onend); 523 | src.removeListener('end', cleanup); 524 | 525 | // if the reader is waiting for a drain event from this 526 | // specific writer, then it would cause it to never start 527 | // flowing again. 528 | // So, if this is awaiting a drain, then we just call it now. 529 | // If we don't know, then assume that we are waiting for one. 530 | if (!dest._writableState || dest._writableState.needDrain) 531 | ondrain(); 532 | } 533 | 534 | // if the dest has an error, then stop piping into it. 535 | // however, don't suppress the throwing behavior for this. 536 | function onerror(er) { 537 | unpipe(); 538 | dest.removeListener('error', onerror); 539 | if (EE.listenerCount(dest, 'error') === 0) 540 | dest.emit('error', er); 541 | } 542 | // This is a brutally ugly hack to make sure that our error handler 543 | // is attached before any userland ones. NEVER DO THIS. 544 | if (!dest._events || !dest._events.error) 545 | dest.on('error', onerror); 546 | else if (isArray(dest._events.error)) 547 | dest._events.error.unshift(onerror); 548 | else 549 | dest._events.error = [onerror, dest._events.error]; 550 | 551 | 552 | 553 | // Both close and finish should trigger unpipe, but only once. 554 | function onclose() { 555 | dest.removeListener('finish', onfinish); 556 | unpipe(); 557 | } 558 | dest.once('close', onclose); 559 | function onfinish() { 560 | dest.removeListener('close', onclose); 561 | unpipe(); 562 | } 563 | dest.once('finish', onfinish); 564 | 565 | function unpipe() { 566 | src.unpipe(dest); 567 | } 568 | 569 | // tell the dest that it's being piped to 570 | dest.emit('pipe', src); 571 | 572 | // start the flow if it hasn't been started already. 573 | if (!state.flowing) { 574 | // the handler that waits for readable events after all 575 | // the data gets sucked out in flow. 576 | // This would be easier to follow with a .once() handler 577 | // in flow(), but that is too slow. 578 | this.on('readable', pipeOnReadable); 579 | 580 | state.flowing = true; 581 | process.nextTick(function() { 582 | flow(src); 583 | }); 584 | } 585 | 586 | return dest; 587 | }; 588 | 589 | function pipeOnDrain(src) { 590 | return function() { 591 | var dest = this; 592 | var state = src._readableState; 593 | state.awaitDrain--; 594 | if (state.awaitDrain === 0) 595 | flow(src); 596 | }; 597 | } 598 | 599 | function flow(src) { 600 | var state = src._readableState; 601 | var chunk; 602 | state.awaitDrain = 0; 603 | 604 | function write(dest, i, list) { 605 | var written = dest.write(chunk); 606 | if (false === written) { 607 | state.awaitDrain++; 608 | } 609 | } 610 | 611 | while (state.pipesCount && null !== (chunk = src.read())) { 612 | 613 | if (state.pipesCount === 1) 614 | write(state.pipes, 0, null); 615 | else 616 | forEach(state.pipes, write); 617 | 618 | src.emit('data', chunk); 619 | 620 | // if anyone needs a drain, then we have to wait for that. 621 | if (state.awaitDrain > 0) 622 | return; 623 | } 624 | 625 | // if every destination was unpiped, either before entering this 626 | // function, or in the while loop, then stop flowing. 627 | // 628 | // NB: This is a pretty rare edge case. 629 | if (state.pipesCount === 0) { 630 | state.flowing = false; 631 | 632 | // if there were data event listeners added, then switch to old mode. 633 | if (EE.listenerCount(src, 'data') > 0) 634 | emitDataEvents(src); 635 | return; 636 | } 637 | 638 | // at this point, no one needed a drain, so we just ran out of data 639 | // on the next readable event, start it over again. 640 | state.ranOut = true; 641 | } 642 | 643 | function pipeOnReadable() { 644 | if (this._readableState.ranOut) { 645 | this._readableState.ranOut = false; 646 | flow(this); 647 | } 648 | } 649 | 650 | 651 | Readable.prototype.unpipe = function(dest) { 652 | var state = this._readableState; 653 | 654 | // if we're not piping anywhere, then do nothing. 655 | if (state.pipesCount === 0) 656 | return this; 657 | 658 | // just one destination. most common case. 659 | if (state.pipesCount === 1) { 660 | // passed in one, but it's not the right one. 661 | if (dest && dest !== state.pipes) 662 | return this; 663 | 664 | if (!dest) 665 | dest = state.pipes; 666 | 667 | // got a match. 668 | state.pipes = null; 669 | state.pipesCount = 0; 670 | this.removeListener('readable', pipeOnReadable); 671 | state.flowing = false; 672 | if (dest) 673 | dest.emit('unpipe', this); 674 | return this; 675 | } 676 | 677 | // slow case. multiple pipe destinations. 678 | 679 | if (!dest) { 680 | // remove all. 681 | var dests = state.pipes; 682 | var len = state.pipesCount; 683 | state.pipes = null; 684 | state.pipesCount = 0; 685 | this.removeListener('readable', pipeOnReadable); 686 | state.flowing = false; 687 | 688 | for (var i = 0; i < len; i++) 689 | dests[i].emit('unpipe', this); 690 | return this; 691 | } 692 | 693 | // try to find the right one. 694 | var i = indexOf(state.pipes, dest); 695 | if (i === -1) 696 | return this; 697 | 698 | state.pipes.splice(i, 1); 699 | state.pipesCount -= 1; 700 | if (state.pipesCount === 1) 701 | state.pipes = state.pipes[0]; 702 | 703 | dest.emit('unpipe', this); 704 | 705 | return this; 706 | }; 707 | 708 | // set up data events if they are asked for 709 | // Ensure readable listeners eventually get something 710 | Readable.prototype.on = function(ev, fn) { 711 | var res = Stream.prototype.on.call(this, ev, fn); 712 | 713 | if (ev === 'data' && !this._readableState.flowing) 714 | emitDataEvents(this); 715 | 716 | if (ev === 'readable' && this.readable) { 717 | var state = this._readableState; 718 | if (!state.readableListening) { 719 | state.readableListening = true; 720 | state.emittedReadable = false; 721 | state.needReadable = true; 722 | if (!state.reading) { 723 | this.read(0); 724 | } else if (state.length) { 725 | emitReadable(this, state); 726 | } 727 | } 728 | } 729 | 730 | return res; 731 | }; 732 | Readable.prototype.addListener = Readable.prototype.on; 733 | 734 | // pause() and resume() are remnants of the legacy readable stream API 735 | // If the user uses them, then switch into old mode. 736 | Readable.prototype.resume = function() { 737 | emitDataEvents(this); 738 | this.read(0); 739 | this.emit('resume'); 740 | }; 741 | 742 | Readable.prototype.pause = function() { 743 | emitDataEvents(this, true); 744 | this.emit('pause'); 745 | }; 746 | 747 | function emitDataEvents(stream, startPaused) { 748 | var state = stream._readableState; 749 | 750 | if (state.flowing) { 751 | // https://github.com/isaacs/readable-stream/issues/16 752 | throw new Error('Cannot switch to old mode now.'); 753 | } 754 | 755 | var paused = startPaused || false; 756 | var readable = false; 757 | 758 | // convert to an old-style stream. 759 | stream.readable = true; 760 | stream.pipe = Stream.prototype.pipe; 761 | stream.on = stream.addListener = Stream.prototype.on; 762 | 763 | stream.on('readable', function() { 764 | readable = true; 765 | 766 | var c; 767 | while (!paused && (null !== (c = stream.read()))) 768 | stream.emit('data', c); 769 | 770 | if (c === null) { 771 | readable = false; 772 | stream._readableState.needReadable = true; 773 | } 774 | }); 775 | 776 | stream.pause = function() { 777 | paused = true; 778 | this.emit('pause'); 779 | }; 780 | 781 | stream.resume = function() { 782 | paused = false; 783 | if (readable) 784 | process.nextTick(function() { 785 | stream.emit('readable'); 786 | }); 787 | else 788 | this.read(0); 789 | this.emit('resume'); 790 | }; 791 | 792 | // now make it start, just in case it hadn't already. 793 | stream.emit('readable'); 794 | } 795 | 796 | // wrap an old-style stream as the async data source. 797 | // This is *not* part of the readable stream interface. 798 | // It is an ugly unfortunate mess of history. 799 | Readable.prototype.wrap = function(stream) { 800 | var state = this._readableState; 801 | var paused = false; 802 | 803 | var self = this; 804 | stream.on('end', function() { 805 | if (state.decoder && !state.ended) { 806 | var chunk = state.decoder.end(); 807 | if (chunk && chunk.length) 808 | self.push(chunk); 809 | } 810 | 811 | self.push(null); 812 | }); 813 | 814 | stream.on('data', function(chunk) { 815 | if (state.decoder) 816 | chunk = state.decoder.write(chunk); 817 | if (!chunk || !state.objectMode && !chunk.length) 818 | return; 819 | 820 | var ret = self.push(chunk); 821 | if (!ret) { 822 | paused = true; 823 | stream.pause(); 824 | } 825 | }); 826 | 827 | // proxy all the other methods. 828 | // important when wrapping filters and duplexes. 829 | for (var i in stream) { 830 | if (typeof stream[i] === 'function' && 831 | typeof this[i] === 'undefined') { 832 | this[i] = function(method) { return function() { 833 | return stream[method].apply(stream, arguments); 834 | }}(i); 835 | } 836 | } 837 | 838 | // proxy certain important events. 839 | var events = ['error', 'close', 'destroy', 'pause', 'resume']; 840 | forEach(events, function(ev) { 841 | stream.on(ev, self.emit.bind(self, ev)); 842 | }); 843 | 844 | // when we try to consume some more bytes, simply unpause the 845 | // underlying stream. 846 | self._read = function(n) { 847 | if (paused) { 848 | paused = false; 849 | stream.resume(); 850 | } 851 | }; 852 | 853 | return self; 854 | }; 855 | 856 | 857 | 858 | // exposed for testing purposes only. 859 | Readable._fromList = fromList; 860 | 861 | // Pluck off n bytes from an array of buffers. 862 | // Length is the combined lengths of all the buffers in the list. 863 | function fromList(n, state) { 864 | var list = state.buffer; 865 | var length = state.length; 866 | var stringMode = !!state.decoder; 867 | var objectMode = !!state.objectMode; 868 | var ret; 869 | 870 | // nothing in the list, definitely empty. 871 | if (list.length === 0) 872 | return null; 873 | 874 | if (length === 0) 875 | ret = null; 876 | else if (objectMode) 877 | ret = list.shift(); 878 | else if (!n || n >= length) { 879 | // read it all, truncate the array. 880 | if (stringMode) 881 | ret = list.join(''); 882 | else 883 | ret = Buffer.concat(list, length); 884 | list.length = 0; 885 | } else { 886 | // read just some of it. 887 | if (n < list[0].length) { 888 | // just take a part of the first list item. 889 | // slice is the same for buffers and strings. 890 | var buf = list[0]; 891 | ret = buf.slice(0, n); 892 | list[0] = buf.slice(n); 893 | } else if (n === list[0].length) { 894 | // first list is a perfect match 895 | ret = list.shift(); 896 | } else { 897 | // complex case. 898 | // we have enough to cover it, but it spans past the first buffer. 899 | if (stringMode) 900 | ret = ''; 901 | else 902 | ret = new Buffer(n); 903 | 904 | var c = 0; 905 | for (var i = 0, l = list.length; i < l && c < n; i++) { 906 | var buf = list[0]; 907 | var cpy = Math.min(n - c, buf.length); 908 | 909 | if (stringMode) 910 | ret += buf.slice(0, cpy); 911 | else 912 | buf.copy(ret, c, 0, cpy); 913 | 914 | if (cpy < buf.length) 915 | list[0] = buf.slice(cpy); 916 | else 917 | list.shift(); 918 | 919 | c += cpy; 920 | } 921 | } 922 | } 923 | 924 | return ret; 925 | } 926 | 927 | function endReadable(stream) { 928 | var state = stream._readableState; 929 | 930 | // If we get here before consuming all the bytes, then that is a 931 | // bug in node. Should never happen. 932 | if (state.length > 0) 933 | throw new Error('endReadable called on non-empty stream'); 934 | 935 | if (!state.endEmitted && state.calledRead) { 936 | state.ended = true; 937 | process.nextTick(function() { 938 | // Check that we didn't get one last unshift. 939 | if (!state.endEmitted && state.length === 0) { 940 | state.endEmitted = true; 941 | stream.readable = false; 942 | stream.emit('end'); 943 | } 944 | }); 945 | } 946 | } 947 | 948 | function forEach (xs, f) { 949 | for (var i = 0, l = xs.length; i < l; i++) { 950 | f(xs[i], i); 951 | } 952 | } 953 | 954 | function indexOf (xs, x) { 955 | for (var i = 0, l = xs.length; i < l; i++) { 956 | if (xs[i] === x) return i; 957 | } 958 | return -1; 959 | } 960 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/lib/_stream_transform.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | // a transform stream is a readable/writable stream where you do 24 | // something with the data. Sometimes it's called a "filter", 25 | // but that's not a great name for it, since that implies a thing where 26 | // some bits pass through, and others are simply ignored. (That would 27 | // be a valid example of a transform, of course.) 28 | // 29 | // While the output is causally related to the input, it's not a 30 | // necessarily symmetric or synchronous transformation. For example, 31 | // a zlib stream might take multiple plain-text writes(), and then 32 | // emit a single compressed chunk some time in the future. 33 | // 34 | // Here's how this works: 35 | // 36 | // The Transform stream has all the aspects of the readable and writable 37 | // stream classes. When you write(chunk), that calls _write(chunk,cb) 38 | // internally, and returns false if there's a lot of pending writes 39 | // buffered up. When you call read(), that calls _read(n) until 40 | // there's enough pending readable data buffered up. 41 | // 42 | // In a transform stream, the written data is placed in a buffer. When 43 | // _read(n) is called, it transforms the queued up data, calling the 44 | // buffered _write cb's as it consumes chunks. If consuming a single 45 | // written chunk would result in multiple output chunks, then the first 46 | // outputted bit calls the readcb, and subsequent chunks just go into 47 | // the read buffer, and will cause it to emit 'readable' if necessary. 48 | // 49 | // This way, back-pressure is actually determined by the reading side, 50 | // since _read has to be called to start processing a new chunk. However, 51 | // a pathological inflate type of transform can cause excessive buffering 52 | // here. For example, imagine a stream where every byte of input is 53 | // interpreted as an integer from 0-255, and then results in that many 54 | // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in 55 | // 1kb of data being output. In this case, you could write a very small 56 | // amount of input, and end up with a very large amount of output. In 57 | // such a pathological inflating mechanism, there'd be no way to tell 58 | // the system to stop doing the transform. A single 4MB write could 59 | // cause the system to run out of memory. 60 | // 61 | // However, even in such a pathological case, only a single written chunk 62 | // would be consumed, and then the rest would wait (un-transformed) until 63 | // the results of the previous transformed chunk were consumed. 64 | 65 | module.exports = Transform; 66 | 67 | var Duplex = require('./_stream_duplex'); 68 | 69 | /**/ 70 | var util = require('core-util-is'); 71 | util.inherits = require('inherits'); 72 | /**/ 73 | 74 | util.inherits(Transform, Duplex); 75 | 76 | 77 | function TransformState(options, stream) { 78 | this.afterTransform = function(er, data) { 79 | return afterTransform(stream, er, data); 80 | }; 81 | 82 | this.needTransform = false; 83 | this.transforming = false; 84 | this.writecb = null; 85 | this.writechunk = null; 86 | } 87 | 88 | function afterTransform(stream, er, data) { 89 | var ts = stream._transformState; 90 | ts.transforming = false; 91 | 92 | var cb = ts.writecb; 93 | 94 | if (!cb) 95 | return stream.emit('error', new Error('no writecb in Transform class')); 96 | 97 | ts.writechunk = null; 98 | ts.writecb = null; 99 | 100 | if (data !== null && data !== undefined) 101 | stream.push(data); 102 | 103 | if (cb) 104 | cb(er); 105 | 106 | var rs = stream._readableState; 107 | rs.reading = false; 108 | if (rs.needReadable || rs.length < rs.highWaterMark) { 109 | stream._read(rs.highWaterMark); 110 | } 111 | } 112 | 113 | 114 | function Transform(options) { 115 | if (!(this instanceof Transform)) 116 | return new Transform(options); 117 | 118 | Duplex.call(this, options); 119 | 120 | var ts = this._transformState = new TransformState(options, this); 121 | 122 | // when the writable side finishes, then flush out anything remaining. 123 | var stream = this; 124 | 125 | // start out asking for a readable event once data is transformed. 126 | this._readableState.needReadable = true; 127 | 128 | // we have implemented the _read method, and done the other things 129 | // that Readable wants before the first _read call, so unset the 130 | // sync guard flag. 131 | this._readableState.sync = false; 132 | 133 | this.once('finish', function() { 134 | if ('function' === typeof this._flush) 135 | this._flush(function(er) { 136 | done(stream, er); 137 | }); 138 | else 139 | done(stream); 140 | }); 141 | } 142 | 143 | Transform.prototype.push = function(chunk, encoding) { 144 | this._transformState.needTransform = false; 145 | return Duplex.prototype.push.call(this, chunk, encoding); 146 | }; 147 | 148 | // This is the part where you do stuff! 149 | // override this function in implementation classes. 150 | // 'chunk' is an input chunk. 151 | // 152 | // Call `push(newChunk)` to pass along transformed output 153 | // to the readable side. You may call 'push' zero or more times. 154 | // 155 | // Call `cb(err)` when you are done with this chunk. If you pass 156 | // an error, then that'll put the hurt on the whole operation. If you 157 | // never call cb(), then you'll never get another chunk. 158 | Transform.prototype._transform = function(chunk, encoding, cb) { 159 | throw new Error('not implemented'); 160 | }; 161 | 162 | Transform.prototype._write = function(chunk, encoding, cb) { 163 | var ts = this._transformState; 164 | ts.writecb = cb; 165 | ts.writechunk = chunk; 166 | ts.writeencoding = encoding; 167 | if (!ts.transforming) { 168 | var rs = this._readableState; 169 | if (ts.needTransform || 170 | rs.needReadable || 171 | rs.length < rs.highWaterMark) 172 | this._read(rs.highWaterMark); 173 | } 174 | }; 175 | 176 | // Doesn't matter what the args are here. 177 | // _transform does all the work. 178 | // That we got here means that the readable side wants more data. 179 | Transform.prototype._read = function(n) { 180 | var ts = this._transformState; 181 | 182 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) { 183 | ts.transforming = true; 184 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); 185 | } else { 186 | // mark that we need a transform, so that any data that comes in 187 | // will get processed, now that we've asked for it. 188 | ts.needTransform = true; 189 | } 190 | }; 191 | 192 | 193 | function done(stream, er) { 194 | if (er) 195 | return stream.emit('error', er); 196 | 197 | // if there's nothing in the write buffer, then that means 198 | // that nothing more will ever be provided 199 | var ws = stream._writableState; 200 | var rs = stream._readableState; 201 | var ts = stream._transformState; 202 | 203 | if (ws.length) 204 | throw new Error('calling transform done when ws.length != 0'); 205 | 206 | if (ts.transforming) 207 | throw new Error('calling transform done when still transforming'); 208 | 209 | return stream.push(null); 210 | } 211 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/lib/_stream_writable.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // A bit simpler than readable streams. 23 | // Implement an async ._write(chunk, cb), and it'll handle all 24 | // the drain event emission and buffering. 25 | 26 | module.exports = Writable; 27 | 28 | /**/ 29 | var Buffer = require('buffer').Buffer; 30 | /**/ 31 | 32 | Writable.WritableState = WritableState; 33 | 34 | 35 | /**/ 36 | var util = require('core-util-is'); 37 | util.inherits = require('inherits'); 38 | /**/ 39 | 40 | 41 | var Stream = require('stream'); 42 | 43 | util.inherits(Writable, Stream); 44 | 45 | function WriteReq(chunk, encoding, cb) { 46 | this.chunk = chunk; 47 | this.encoding = encoding; 48 | this.callback = cb; 49 | } 50 | 51 | function WritableState(options, stream) { 52 | options = options || {}; 53 | 54 | // the point at which write() starts returning false 55 | // Note: 0 is a valid value, means that we always return false if 56 | // the entire buffer is not flushed immediately on write() 57 | var hwm = options.highWaterMark; 58 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024; 59 | 60 | // object stream flag to indicate whether or not this stream 61 | // contains buffers or objects. 62 | this.objectMode = !!options.objectMode; 63 | 64 | // cast to ints. 65 | this.highWaterMark = ~~this.highWaterMark; 66 | 67 | this.needDrain = false; 68 | // at the start of calling end() 69 | this.ending = false; 70 | // when end() has been called, and returned 71 | this.ended = false; 72 | // when 'finish' is emitted 73 | this.finished = false; 74 | 75 | // should we decode strings into buffers before passing to _write? 76 | // this is here so that some node-core streams can optimize string 77 | // handling at a lower level. 78 | var noDecode = options.decodeStrings === false; 79 | this.decodeStrings = !noDecode; 80 | 81 | // Crypto is kind of old and crusty. Historically, its default string 82 | // encoding is 'binary' so we have to make this configurable. 83 | // Everything else in the universe uses 'utf8', though. 84 | this.defaultEncoding = options.defaultEncoding || 'utf8'; 85 | 86 | // not an actual buffer we keep track of, but a measurement 87 | // of how much we're waiting to get pushed to some underlying 88 | // socket or file. 89 | this.length = 0; 90 | 91 | // a flag to see when we're in the middle of a write. 92 | this.writing = false; 93 | 94 | // a flag to be able to tell if the onwrite cb is called immediately, 95 | // or on a later tick. We set this to true at first, becuase any 96 | // actions that shouldn't happen until "later" should generally also 97 | // not happen before the first write call. 98 | this.sync = true; 99 | 100 | // a flag to know if we're processing previously buffered items, which 101 | // may call the _write() callback in the same tick, so that we don't 102 | // end up in an overlapped onwrite situation. 103 | this.bufferProcessing = false; 104 | 105 | // the callback that's passed to _write(chunk,cb) 106 | this.onwrite = function(er) { 107 | onwrite(stream, er); 108 | }; 109 | 110 | // the callback that the user supplies to write(chunk,encoding,cb) 111 | this.writecb = null; 112 | 113 | // the amount that is being written when _write is called. 114 | this.writelen = 0; 115 | 116 | this.buffer = []; 117 | 118 | // True if the error was already emitted and should not be thrown again 119 | this.errorEmitted = false; 120 | } 121 | 122 | function Writable(options) { 123 | var Duplex = require('./_stream_duplex'); 124 | 125 | // Writable ctor is applied to Duplexes, though they're not 126 | // instanceof Writable, they're instanceof Readable. 127 | if (!(this instanceof Writable) && !(this instanceof Duplex)) 128 | return new Writable(options); 129 | 130 | this._writableState = new WritableState(options, this); 131 | 132 | // legacy. 133 | this.writable = true; 134 | 135 | Stream.call(this); 136 | } 137 | 138 | // Otherwise people can pipe Writable streams, which is just wrong. 139 | Writable.prototype.pipe = function() { 140 | this.emit('error', new Error('Cannot pipe. Not readable.')); 141 | }; 142 | 143 | 144 | function writeAfterEnd(stream, state, cb) { 145 | var er = new Error('write after end'); 146 | // TODO: defer error events consistently everywhere, not just the cb 147 | stream.emit('error', er); 148 | process.nextTick(function() { 149 | cb(er); 150 | }); 151 | } 152 | 153 | // If we get something that is not a buffer, string, null, or undefined, 154 | // and we're not in objectMode, then that's an error. 155 | // Otherwise stream chunks are all considered to be of length=1, and the 156 | // watermarks determine how many objects to keep in the buffer, rather than 157 | // how many bytes or characters. 158 | function validChunk(stream, state, chunk, cb) { 159 | var valid = true; 160 | if (!Buffer.isBuffer(chunk) && 161 | 'string' !== typeof chunk && 162 | chunk !== null && 163 | chunk !== undefined && 164 | !state.objectMode) { 165 | var er = new TypeError('Invalid non-string/buffer chunk'); 166 | stream.emit('error', er); 167 | process.nextTick(function() { 168 | cb(er); 169 | }); 170 | valid = false; 171 | } 172 | return valid; 173 | } 174 | 175 | Writable.prototype.write = function(chunk, encoding, cb) { 176 | var state = this._writableState; 177 | var ret = false; 178 | 179 | if (typeof encoding === 'function') { 180 | cb = encoding; 181 | encoding = null; 182 | } 183 | 184 | if (Buffer.isBuffer(chunk)) 185 | encoding = 'buffer'; 186 | else if (!encoding) 187 | encoding = state.defaultEncoding; 188 | 189 | if (typeof cb !== 'function') 190 | cb = function() {}; 191 | 192 | if (state.ended) 193 | writeAfterEnd(this, state, cb); 194 | else if (validChunk(this, state, chunk, cb)) 195 | ret = writeOrBuffer(this, state, chunk, encoding, cb); 196 | 197 | return ret; 198 | }; 199 | 200 | function decodeChunk(state, chunk, encoding) { 201 | if (!state.objectMode && 202 | state.decodeStrings !== false && 203 | typeof chunk === 'string') { 204 | chunk = new Buffer(chunk, encoding); 205 | } 206 | return chunk; 207 | } 208 | 209 | // if we're already writing something, then just put this 210 | // in the queue, and wait our turn. Otherwise, call _write 211 | // If we return false, then we need a drain event, so set that flag. 212 | function writeOrBuffer(stream, state, chunk, encoding, cb) { 213 | chunk = decodeChunk(state, chunk, encoding); 214 | if (Buffer.isBuffer(chunk)) 215 | encoding = 'buffer'; 216 | var len = state.objectMode ? 1 : chunk.length; 217 | 218 | state.length += len; 219 | 220 | var ret = state.length < state.highWaterMark; 221 | // we must ensure that previous needDrain will not be reset to false. 222 | if (!ret) 223 | state.needDrain = true; 224 | 225 | if (state.writing) 226 | state.buffer.push(new WriteReq(chunk, encoding, cb)); 227 | else 228 | doWrite(stream, state, len, chunk, encoding, cb); 229 | 230 | return ret; 231 | } 232 | 233 | function doWrite(stream, state, len, chunk, encoding, cb) { 234 | state.writelen = len; 235 | state.writecb = cb; 236 | state.writing = true; 237 | state.sync = true; 238 | stream._write(chunk, encoding, state.onwrite); 239 | state.sync = false; 240 | } 241 | 242 | function onwriteError(stream, state, sync, er, cb) { 243 | if (sync) 244 | process.nextTick(function() { 245 | cb(er); 246 | }); 247 | else 248 | cb(er); 249 | 250 | stream._writableState.errorEmitted = true; 251 | stream.emit('error', er); 252 | } 253 | 254 | function onwriteStateUpdate(state) { 255 | state.writing = false; 256 | state.writecb = null; 257 | state.length -= state.writelen; 258 | state.writelen = 0; 259 | } 260 | 261 | function onwrite(stream, er) { 262 | var state = stream._writableState; 263 | var sync = state.sync; 264 | var cb = state.writecb; 265 | 266 | onwriteStateUpdate(state); 267 | 268 | if (er) 269 | onwriteError(stream, state, sync, er, cb); 270 | else { 271 | // Check if we're actually ready to finish, but don't emit yet 272 | var finished = needFinish(stream, state); 273 | 274 | if (!finished && !state.bufferProcessing && state.buffer.length) 275 | clearBuffer(stream, state); 276 | 277 | if (sync) { 278 | process.nextTick(function() { 279 | afterWrite(stream, state, finished, cb); 280 | }); 281 | } else { 282 | afterWrite(stream, state, finished, cb); 283 | } 284 | } 285 | } 286 | 287 | function afterWrite(stream, state, finished, cb) { 288 | if (!finished) 289 | onwriteDrain(stream, state); 290 | cb(); 291 | if (finished) 292 | finishMaybe(stream, state); 293 | } 294 | 295 | // Must force callback to be called on nextTick, so that we don't 296 | // emit 'drain' before the write() consumer gets the 'false' return 297 | // value, and has a chance to attach a 'drain' listener. 298 | function onwriteDrain(stream, state) { 299 | if (state.length === 0 && state.needDrain) { 300 | state.needDrain = false; 301 | stream.emit('drain'); 302 | } 303 | } 304 | 305 | 306 | // if there's something in the buffer waiting, then process it 307 | function clearBuffer(stream, state) { 308 | state.bufferProcessing = true; 309 | 310 | for (var c = 0; c < state.buffer.length; c++) { 311 | var entry = state.buffer[c]; 312 | var chunk = entry.chunk; 313 | var encoding = entry.encoding; 314 | var cb = entry.callback; 315 | var len = state.objectMode ? 1 : chunk.length; 316 | 317 | doWrite(stream, state, len, chunk, encoding, cb); 318 | 319 | // if we didn't call the onwrite immediately, then 320 | // it means that we need to wait until it does. 321 | // also, that means that the chunk and cb are currently 322 | // being processed, so move the buffer counter past them. 323 | if (state.writing) { 324 | c++; 325 | break; 326 | } 327 | } 328 | 329 | state.bufferProcessing = false; 330 | if (c < state.buffer.length) 331 | state.buffer = state.buffer.slice(c); 332 | else 333 | state.buffer.length = 0; 334 | } 335 | 336 | Writable.prototype._write = function(chunk, encoding, cb) { 337 | cb(new Error('not implemented')); 338 | }; 339 | 340 | Writable.prototype.end = function(chunk, encoding, cb) { 341 | var state = this._writableState; 342 | 343 | if (typeof chunk === 'function') { 344 | cb = chunk; 345 | chunk = null; 346 | encoding = null; 347 | } else if (typeof encoding === 'function') { 348 | cb = encoding; 349 | encoding = null; 350 | } 351 | 352 | if (typeof chunk !== 'undefined' && chunk !== null) 353 | this.write(chunk, encoding); 354 | 355 | // ignore unnecessary end() calls. 356 | if (!state.ending && !state.finished) 357 | endWritable(this, state, cb); 358 | }; 359 | 360 | 361 | function needFinish(stream, state) { 362 | return (state.ending && 363 | state.length === 0 && 364 | !state.finished && 365 | !state.writing); 366 | } 367 | 368 | function finishMaybe(stream, state) { 369 | var need = needFinish(stream, state); 370 | if (need) { 371 | state.finished = true; 372 | stream.emit('finish'); 373 | } 374 | return need; 375 | } 376 | 377 | function endWritable(stream, state, cb) { 378 | state.ending = true; 379 | finishMaybe(stream, state); 380 | if (cb) { 381 | if (state.finished) 382 | process.nextTick(cb); 383 | else 384 | stream.once('finish', cb); 385 | } 386 | state.ended = true; 387 | } 388 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/core-util-is/README.md: -------------------------------------------------------------------------------- 1 | # core-util-is 2 | 3 | The `util.is*` functions introduced in Node v0.12. 4 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/core-util-is/float.patch: -------------------------------------------------------------------------------- 1 | diff --git a/lib/util.js b/lib/util.js 2 | index a03e874..9074e8e 100644 3 | --- a/lib/util.js 4 | +++ b/lib/util.js 5 | @@ -19,430 +19,6 @@ 6 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 7 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -var formatRegExp = /%[sdj%]/g; 10 | -exports.format = function(f) { 11 | - if (!isString(f)) { 12 | - var objects = []; 13 | - for (var i = 0; i < arguments.length; i++) { 14 | - objects.push(inspect(arguments[i])); 15 | - } 16 | - return objects.join(' '); 17 | - } 18 | - 19 | - var i = 1; 20 | - var args = arguments; 21 | - var len = args.length; 22 | - var str = String(f).replace(formatRegExp, function(x) { 23 | - if (x === '%%') return '%'; 24 | - if (i >= len) return x; 25 | - switch (x) { 26 | - case '%s': return String(args[i++]); 27 | - case '%d': return Number(args[i++]); 28 | - case '%j': 29 | - try { 30 | - return JSON.stringify(args[i++]); 31 | - } catch (_) { 32 | - return '[Circular]'; 33 | - } 34 | - default: 35 | - return x; 36 | - } 37 | - }); 38 | - for (var x = args[i]; i < len; x = args[++i]) { 39 | - if (isNull(x) || !isObject(x)) { 40 | - str += ' ' + x; 41 | - } else { 42 | - str += ' ' + inspect(x); 43 | - } 44 | - } 45 | - return str; 46 | -}; 47 | - 48 | - 49 | -// Mark that a method should not be used. 50 | -// Returns a modified function which warns once by default. 51 | -// If --no-deprecation is set, then it is a no-op. 52 | -exports.deprecate = function(fn, msg) { 53 | - // Allow for deprecating things in the process of starting up. 54 | - if (isUndefined(global.process)) { 55 | - return function() { 56 | - return exports.deprecate(fn, msg).apply(this, arguments); 57 | - }; 58 | - } 59 | - 60 | - if (process.noDeprecation === true) { 61 | - return fn; 62 | - } 63 | - 64 | - var warned = false; 65 | - function deprecated() { 66 | - if (!warned) { 67 | - if (process.throwDeprecation) { 68 | - throw new Error(msg); 69 | - } else if (process.traceDeprecation) { 70 | - console.trace(msg); 71 | - } else { 72 | - console.error(msg); 73 | - } 74 | - warned = true; 75 | - } 76 | - return fn.apply(this, arguments); 77 | - } 78 | - 79 | - return deprecated; 80 | -}; 81 | - 82 | - 83 | -var debugs = {}; 84 | -var debugEnviron; 85 | -exports.debuglog = function(set) { 86 | - if (isUndefined(debugEnviron)) 87 | - debugEnviron = process.env.NODE_DEBUG || ''; 88 | - set = set.toUpperCase(); 89 | - if (!debugs[set]) { 90 | - if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { 91 | - var pid = process.pid; 92 | - debugs[set] = function() { 93 | - var msg = exports.format.apply(exports, arguments); 94 | - console.error('%s %d: %s', set, pid, msg); 95 | - }; 96 | - } else { 97 | - debugs[set] = function() {}; 98 | - } 99 | - } 100 | - return debugs[set]; 101 | -}; 102 | - 103 | - 104 | -/** 105 | - * Echos the value of a value. Trys to print the value out 106 | - * in the best way possible given the different types. 107 | - * 108 | - * @param {Object} obj The object to print out. 109 | - * @param {Object} opts Optional options object that alters the output. 110 | - */ 111 | -/* legacy: obj, showHidden, depth, colors*/ 112 | -function inspect(obj, opts) { 113 | - // default options 114 | - var ctx = { 115 | - seen: [], 116 | - stylize: stylizeNoColor 117 | - }; 118 | - // legacy... 119 | - if (arguments.length >= 3) ctx.depth = arguments[2]; 120 | - if (arguments.length >= 4) ctx.colors = arguments[3]; 121 | - if (isBoolean(opts)) { 122 | - // legacy... 123 | - ctx.showHidden = opts; 124 | - } else if (opts) { 125 | - // got an "options" object 126 | - exports._extend(ctx, opts); 127 | - } 128 | - // set default options 129 | - if (isUndefined(ctx.showHidden)) ctx.showHidden = false; 130 | - if (isUndefined(ctx.depth)) ctx.depth = 2; 131 | - if (isUndefined(ctx.colors)) ctx.colors = false; 132 | - if (isUndefined(ctx.customInspect)) ctx.customInspect = true; 133 | - if (ctx.colors) ctx.stylize = stylizeWithColor; 134 | - return formatValue(ctx, obj, ctx.depth); 135 | -} 136 | -exports.inspect = inspect; 137 | - 138 | - 139 | -// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics 140 | -inspect.colors = { 141 | - 'bold' : [1, 22], 142 | - 'italic' : [3, 23], 143 | - 'underline' : [4, 24], 144 | - 'inverse' : [7, 27], 145 | - 'white' : [37, 39], 146 | - 'grey' : [90, 39], 147 | - 'black' : [30, 39], 148 | - 'blue' : [34, 39], 149 | - 'cyan' : [36, 39], 150 | - 'green' : [32, 39], 151 | - 'magenta' : [35, 39], 152 | - 'red' : [31, 39], 153 | - 'yellow' : [33, 39] 154 | -}; 155 | - 156 | -// Don't use 'blue' not visible on cmd.exe 157 | -inspect.styles = { 158 | - 'special': 'cyan', 159 | - 'number': 'yellow', 160 | - 'boolean': 'yellow', 161 | - 'undefined': 'grey', 162 | - 'null': 'bold', 163 | - 'string': 'green', 164 | - 'date': 'magenta', 165 | - // "name": intentionally not styling 166 | - 'regexp': 'red' 167 | -}; 168 | - 169 | - 170 | -function stylizeWithColor(str, styleType) { 171 | - var style = inspect.styles[styleType]; 172 | - 173 | - if (style) { 174 | - return '\u001b[' + inspect.colors[style][0] + 'm' + str + 175 | - '\u001b[' + inspect.colors[style][1] + 'm'; 176 | - } else { 177 | - return str; 178 | - } 179 | -} 180 | - 181 | - 182 | -function stylizeNoColor(str, styleType) { 183 | - return str; 184 | -} 185 | - 186 | - 187 | -function arrayToHash(array) { 188 | - var hash = {}; 189 | - 190 | - array.forEach(function(val, idx) { 191 | - hash[val] = true; 192 | - }); 193 | - 194 | - return hash; 195 | -} 196 | - 197 | - 198 | -function formatValue(ctx, value, recurseTimes) { 199 | - // Provide a hook for user-specified inspect functions. 200 | - // Check that value is an object with an inspect function on it 201 | - if (ctx.customInspect && 202 | - value && 203 | - isFunction(value.inspect) && 204 | - // Filter out the util module, it's inspect function is special 205 | - value.inspect !== exports.inspect && 206 | - // Also filter out any prototype objects using the circular check. 207 | - !(value.constructor && value.constructor.prototype === value)) { 208 | - var ret = value.inspect(recurseTimes, ctx); 209 | - if (!isString(ret)) { 210 | - ret = formatValue(ctx, ret, recurseTimes); 211 | - } 212 | - return ret; 213 | - } 214 | - 215 | - // Primitive types cannot have properties 216 | - var primitive = formatPrimitive(ctx, value); 217 | - if (primitive) { 218 | - return primitive; 219 | - } 220 | - 221 | - // Look up the keys of the object. 222 | - var keys = Object.keys(value); 223 | - var visibleKeys = arrayToHash(keys); 224 | - 225 | - if (ctx.showHidden) { 226 | - keys = Object.getOwnPropertyNames(value); 227 | - } 228 | - 229 | - // Some type of object without properties can be shortcutted. 230 | - if (keys.length === 0) { 231 | - if (isFunction(value)) { 232 | - var name = value.name ? ': ' + value.name : ''; 233 | - return ctx.stylize('[Function' + name + ']', 'special'); 234 | - } 235 | - if (isRegExp(value)) { 236 | - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); 237 | - } 238 | - if (isDate(value)) { 239 | - return ctx.stylize(Date.prototype.toString.call(value), 'date'); 240 | - } 241 | - if (isError(value)) { 242 | - return formatError(value); 243 | - } 244 | - } 245 | - 246 | - var base = '', array = false, braces = ['{', '}']; 247 | - 248 | - // Make Array say that they are Array 249 | - if (isArray(value)) { 250 | - array = true; 251 | - braces = ['[', ']']; 252 | - } 253 | - 254 | - // Make functions say that they are functions 255 | - if (isFunction(value)) { 256 | - var n = value.name ? ': ' + value.name : ''; 257 | - base = ' [Function' + n + ']'; 258 | - } 259 | - 260 | - // Make RegExps say that they are RegExps 261 | - if (isRegExp(value)) { 262 | - base = ' ' + RegExp.prototype.toString.call(value); 263 | - } 264 | - 265 | - // Make dates with properties first say the date 266 | - if (isDate(value)) { 267 | - base = ' ' + Date.prototype.toUTCString.call(value); 268 | - } 269 | - 270 | - // Make error with message first say the error 271 | - if (isError(value)) { 272 | - base = ' ' + formatError(value); 273 | - } 274 | - 275 | - if (keys.length === 0 && (!array || value.length == 0)) { 276 | - return braces[0] + base + braces[1]; 277 | - } 278 | - 279 | - if (recurseTimes < 0) { 280 | - if (isRegExp(value)) { 281 | - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); 282 | - } else { 283 | - return ctx.stylize('[Object]', 'special'); 284 | - } 285 | - } 286 | - 287 | - ctx.seen.push(value); 288 | - 289 | - var output; 290 | - if (array) { 291 | - output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); 292 | - } else { 293 | - output = keys.map(function(key) { 294 | - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); 295 | - }); 296 | - } 297 | - 298 | - ctx.seen.pop(); 299 | - 300 | - return reduceToSingleString(output, base, braces); 301 | -} 302 | - 303 | - 304 | -function formatPrimitive(ctx, value) { 305 | - if (isUndefined(value)) 306 | - return ctx.stylize('undefined', 'undefined'); 307 | - if (isString(value)) { 308 | - var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') 309 | - .replace(/'/g, "\\'") 310 | - .replace(/\\"/g, '"') + '\''; 311 | - return ctx.stylize(simple, 'string'); 312 | - } 313 | - if (isNumber(value)) { 314 | - // Format -0 as '-0'. Strict equality won't distinguish 0 from -0, 315 | - // so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 . 316 | - if (value === 0 && 1 / value < 0) 317 | - return ctx.stylize('-0', 'number'); 318 | - return ctx.stylize('' + value, 'number'); 319 | - } 320 | - if (isBoolean(value)) 321 | - return ctx.stylize('' + value, 'boolean'); 322 | - // For some reason typeof null is "object", so special case here. 323 | - if (isNull(value)) 324 | - return ctx.stylize('null', 'null'); 325 | -} 326 | - 327 | - 328 | -function formatError(value) { 329 | - return '[' + Error.prototype.toString.call(value) + ']'; 330 | -} 331 | - 332 | - 333 | -function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { 334 | - var output = []; 335 | - for (var i = 0, l = value.length; i < l; ++i) { 336 | - if (hasOwnProperty(value, String(i))) { 337 | - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, 338 | - String(i), true)); 339 | - } else { 340 | - output.push(''); 341 | - } 342 | - } 343 | - keys.forEach(function(key) { 344 | - if (!key.match(/^\d+$/)) { 345 | - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, 346 | - key, true)); 347 | - } 348 | - }); 349 | - return output; 350 | -} 351 | - 352 | - 353 | -function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { 354 | - var name, str, desc; 355 | - desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; 356 | - if (desc.get) { 357 | - if (desc.set) { 358 | - str = ctx.stylize('[Getter/Setter]', 'special'); 359 | - } else { 360 | - str = ctx.stylize('[Getter]', 'special'); 361 | - } 362 | - } else { 363 | - if (desc.set) { 364 | - str = ctx.stylize('[Setter]', 'special'); 365 | - } 366 | - } 367 | - if (!hasOwnProperty(visibleKeys, key)) { 368 | - name = '[' + key + ']'; 369 | - } 370 | - if (!str) { 371 | - if (ctx.seen.indexOf(desc.value) < 0) { 372 | - if (isNull(recurseTimes)) { 373 | - str = formatValue(ctx, desc.value, null); 374 | - } else { 375 | - str = formatValue(ctx, desc.value, recurseTimes - 1); 376 | - } 377 | - if (str.indexOf('\n') > -1) { 378 | - if (array) { 379 | - str = str.split('\n').map(function(line) { 380 | - return ' ' + line; 381 | - }).join('\n').substr(2); 382 | - } else { 383 | - str = '\n' + str.split('\n').map(function(line) { 384 | - return ' ' + line; 385 | - }).join('\n'); 386 | - } 387 | - } 388 | - } else { 389 | - str = ctx.stylize('[Circular]', 'special'); 390 | - } 391 | - } 392 | - if (isUndefined(name)) { 393 | - if (array && key.match(/^\d+$/)) { 394 | - return str; 395 | - } 396 | - name = JSON.stringify('' + key); 397 | - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { 398 | - name = name.substr(1, name.length - 2); 399 | - name = ctx.stylize(name, 'name'); 400 | - } else { 401 | - name = name.replace(/'/g, "\\'") 402 | - .replace(/\\"/g, '"') 403 | - .replace(/(^"|"$)/g, "'"); 404 | - name = ctx.stylize(name, 'string'); 405 | - } 406 | - } 407 | - 408 | - return name + ': ' + str; 409 | -} 410 | - 411 | - 412 | -function reduceToSingleString(output, base, braces) { 413 | - var numLinesEst = 0; 414 | - var length = output.reduce(function(prev, cur) { 415 | - numLinesEst++; 416 | - if (cur.indexOf('\n') >= 0) numLinesEst++; 417 | - return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; 418 | - }, 0); 419 | - 420 | - if (length > 60) { 421 | - return braces[0] + 422 | - (base === '' ? '' : base + '\n ') + 423 | - ' ' + 424 | - output.join(',\n ') + 425 | - ' ' + 426 | - braces[1]; 427 | - } 428 | - 429 | - return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; 430 | -} 431 | - 432 | - 433 | // NOTE: These type checking functions intentionally don't use `instanceof` 434 | // because it is fragile and can be easily faked with `Object.create()`. 435 | function isArray(ar) { 436 | @@ -522,166 +98,10 @@ function isPrimitive(arg) { 437 | exports.isPrimitive = isPrimitive; 438 | 439 | function isBuffer(arg) { 440 | - return arg instanceof Buffer; 441 | + return Buffer.isBuffer(arg); 442 | } 443 | exports.isBuffer = isBuffer; 444 | 445 | function objectToString(o) { 446 | return Object.prototype.toString.call(o); 447 | -} 448 | - 449 | - 450 | -function pad(n) { 451 | - return n < 10 ? '0' + n.toString(10) : n.toString(10); 452 | -} 453 | - 454 | - 455 | -var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 456 | - 'Oct', 'Nov', 'Dec']; 457 | - 458 | -// 26 Feb 16:19:34 459 | -function timestamp() { 460 | - var d = new Date(); 461 | - var time = [pad(d.getHours()), 462 | - pad(d.getMinutes()), 463 | - pad(d.getSeconds())].join(':'); 464 | - return [d.getDate(), months[d.getMonth()], time].join(' '); 465 | -} 466 | - 467 | - 468 | -// log is just a thin wrapper to console.log that prepends a timestamp 469 | -exports.log = function() { 470 | - console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); 471 | -}; 472 | - 473 | - 474 | -/** 475 | - * Inherit the prototype methods from one constructor into another. 476 | - * 477 | - * The Function.prototype.inherits from lang.js rewritten as a standalone 478 | - * function (not on Function.prototype). NOTE: If this file is to be loaded 479 | - * during bootstrapping this function needs to be rewritten using some native 480 | - * functions as prototype setup using normal JavaScript does not work as 481 | - * expected during bootstrapping (see mirror.js in r114903). 482 | - * 483 | - * @param {function} ctor Constructor function which needs to inherit the 484 | - * prototype. 485 | - * @param {function} superCtor Constructor function to inherit prototype from. 486 | - */ 487 | -exports.inherits = function(ctor, superCtor) { 488 | - ctor.super_ = superCtor; 489 | - ctor.prototype = Object.create(superCtor.prototype, { 490 | - constructor: { 491 | - value: ctor, 492 | - enumerable: false, 493 | - writable: true, 494 | - configurable: true 495 | - } 496 | - }); 497 | -}; 498 | - 499 | -exports._extend = function(origin, add) { 500 | - // Don't do anything if add isn't an object 501 | - if (!add || !isObject(add)) return origin; 502 | - 503 | - var keys = Object.keys(add); 504 | - var i = keys.length; 505 | - while (i--) { 506 | - origin[keys[i]] = add[keys[i]]; 507 | - } 508 | - return origin; 509 | -}; 510 | - 511 | -function hasOwnProperty(obj, prop) { 512 | - return Object.prototype.hasOwnProperty.call(obj, prop); 513 | -} 514 | - 515 | - 516 | -// Deprecated old stuff. 517 | - 518 | -exports.p = exports.deprecate(function() { 519 | - for (var i = 0, len = arguments.length; i < len; ++i) { 520 | - console.error(exports.inspect(arguments[i])); 521 | - } 522 | -}, 'util.p: Use console.error() instead'); 523 | - 524 | - 525 | -exports.exec = exports.deprecate(function() { 526 | - return require('child_process').exec.apply(this, arguments); 527 | -}, 'util.exec is now called `child_process.exec`.'); 528 | - 529 | - 530 | -exports.print = exports.deprecate(function() { 531 | - for (var i = 0, len = arguments.length; i < len; ++i) { 532 | - process.stdout.write(String(arguments[i])); 533 | - } 534 | -}, 'util.print: Use console.log instead'); 535 | - 536 | - 537 | -exports.puts = exports.deprecate(function() { 538 | - for (var i = 0, len = arguments.length; i < len; ++i) { 539 | - process.stdout.write(arguments[i] + '\n'); 540 | - } 541 | -}, 'util.puts: Use console.log instead'); 542 | - 543 | - 544 | -exports.debug = exports.deprecate(function(x) { 545 | - process.stderr.write('DEBUG: ' + x + '\n'); 546 | -}, 'util.debug: Use console.error instead'); 547 | - 548 | - 549 | -exports.error = exports.deprecate(function(x) { 550 | - for (var i = 0, len = arguments.length; i < len; ++i) { 551 | - process.stderr.write(arguments[i] + '\n'); 552 | - } 553 | -}, 'util.error: Use console.error instead'); 554 | - 555 | - 556 | -exports.pump = exports.deprecate(function(readStream, writeStream, callback) { 557 | - var callbackCalled = false; 558 | - 559 | - function call(a, b, c) { 560 | - if (callback && !callbackCalled) { 561 | - callback(a, b, c); 562 | - callbackCalled = true; 563 | - } 564 | - } 565 | - 566 | - readStream.addListener('data', function(chunk) { 567 | - if (writeStream.write(chunk) === false) readStream.pause(); 568 | - }); 569 | - 570 | - writeStream.addListener('drain', function() { 571 | - readStream.resume(); 572 | - }); 573 | - 574 | - readStream.addListener('end', function() { 575 | - writeStream.end(); 576 | - }); 577 | - 578 | - readStream.addListener('close', function() { 579 | - call(); 580 | - }); 581 | - 582 | - readStream.addListener('error', function(err) { 583 | - writeStream.end(); 584 | - call(err); 585 | - }); 586 | - 587 | - writeStream.addListener('error', function(err) { 588 | - readStream.destroy(); 589 | - call(err); 590 | - }); 591 | -}, 'util.pump(): Use readableStream.pipe() instead'); 592 | - 593 | - 594 | -var uv; 595 | -exports._errnoException = function(err, syscall) { 596 | - if (isUndefined(uv)) uv = process.binding('uv'); 597 | - var errname = uv.errname(err); 598 | - var e = new Error(syscall + ' ' + errname); 599 | - e.code = errname; 600 | - e.errno = errname; 601 | - e.syscall = syscall; 602 | - return e; 603 | -}; 604 | +} -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/core-util-is/lib/util.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // NOTE: These type checking functions intentionally don't use `instanceof` 23 | // because it is fragile and can be easily faked with `Object.create()`. 24 | function isArray(ar) { 25 | return Array.isArray(ar); 26 | } 27 | exports.isArray = isArray; 28 | 29 | function isBoolean(arg) { 30 | return typeof arg === 'boolean'; 31 | } 32 | exports.isBoolean = isBoolean; 33 | 34 | function isNull(arg) { 35 | return arg === null; 36 | } 37 | exports.isNull = isNull; 38 | 39 | function isNullOrUndefined(arg) { 40 | return arg == null; 41 | } 42 | exports.isNullOrUndefined = isNullOrUndefined; 43 | 44 | function isNumber(arg) { 45 | return typeof arg === 'number'; 46 | } 47 | exports.isNumber = isNumber; 48 | 49 | function isString(arg) { 50 | return typeof arg === 'string'; 51 | } 52 | exports.isString = isString; 53 | 54 | function isSymbol(arg) { 55 | return typeof arg === 'symbol'; 56 | } 57 | exports.isSymbol = isSymbol; 58 | 59 | function isUndefined(arg) { 60 | return arg === void 0; 61 | } 62 | exports.isUndefined = isUndefined; 63 | 64 | function isRegExp(re) { 65 | return isObject(re) && objectToString(re) === '[object RegExp]'; 66 | } 67 | exports.isRegExp = isRegExp; 68 | 69 | function isObject(arg) { 70 | return typeof arg === 'object' && arg !== null; 71 | } 72 | exports.isObject = isObject; 73 | 74 | function isDate(d) { 75 | return isObject(d) && objectToString(d) === '[object Date]'; 76 | } 77 | exports.isDate = isDate; 78 | 79 | function isError(e) { 80 | return isObject(e) && 81 | (objectToString(e) === '[object Error]' || e instanceof Error); 82 | } 83 | exports.isError = isError; 84 | 85 | function isFunction(arg) { 86 | return typeof arg === 'function'; 87 | } 88 | exports.isFunction = isFunction; 89 | 90 | function isPrimitive(arg) { 91 | return arg === null || 92 | typeof arg === 'boolean' || 93 | typeof arg === 'number' || 94 | typeof arg === 'string' || 95 | typeof arg === 'symbol' || // ES6 symbol 96 | typeof arg === 'undefined'; 97 | } 98 | exports.isPrimitive = isPrimitive; 99 | 100 | function isBuffer(arg) { 101 | return Buffer.isBuffer(arg); 102 | } 103 | exports.isBuffer = isBuffer; 104 | 105 | function objectToString(o) { 106 | return Object.prototype.toString.call(o); 107 | } -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/core-util-is/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "core-util-is", 3 | "version": "1.0.1", 4 | "description": "The `util.is*` functions introduced in Node v0.12.", 5 | "main": "lib/util.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/isaacs/core-util-is" 9 | }, 10 | "keywords": [ 11 | "util", 12 | "isBuffer", 13 | "isArray", 14 | "isNumber", 15 | "isString", 16 | "isRegExp", 17 | "isThis", 18 | "isThat", 19 | "polyfill" 20 | ], 21 | "author": { 22 | "name": "Isaac Z. Schlueter", 23 | "email": "i@izs.me", 24 | "url": "http://blog.izs.me/" 25 | }, 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/isaacs/core-util-is/issues" 29 | }, 30 | "readme": "# core-util-is\n\nThe `util.is*` functions introduced in Node v0.12.\n", 31 | "readmeFilename": "README.md", 32 | "homepage": "https://github.com/isaacs/core-util-is", 33 | "_id": "core-util-is@1.0.1", 34 | "_from": "core-util-is@~1.0.0" 35 | } 36 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/core-util-is/util.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // NOTE: These type checking functions intentionally don't use `instanceof` 23 | // because it is fragile and can be easily faked with `Object.create()`. 24 | function isArray(ar) { 25 | return Array.isArray(ar); 26 | } 27 | exports.isArray = isArray; 28 | 29 | function isBoolean(arg) { 30 | return typeof arg === 'boolean'; 31 | } 32 | exports.isBoolean = isBoolean; 33 | 34 | function isNull(arg) { 35 | return arg === null; 36 | } 37 | exports.isNull = isNull; 38 | 39 | function isNullOrUndefined(arg) { 40 | return arg == null; 41 | } 42 | exports.isNullOrUndefined = isNullOrUndefined; 43 | 44 | function isNumber(arg) { 45 | return typeof arg === 'number'; 46 | } 47 | exports.isNumber = isNumber; 48 | 49 | function isString(arg) { 50 | return typeof arg === 'string'; 51 | } 52 | exports.isString = isString; 53 | 54 | function isSymbol(arg) { 55 | return typeof arg === 'symbol'; 56 | } 57 | exports.isSymbol = isSymbol; 58 | 59 | function isUndefined(arg) { 60 | return arg === void 0; 61 | } 62 | exports.isUndefined = isUndefined; 63 | 64 | function isRegExp(re) { 65 | return isObject(re) && objectToString(re) === '[object RegExp]'; 66 | } 67 | exports.isRegExp = isRegExp; 68 | 69 | function isObject(arg) { 70 | return typeof arg === 'object' && arg !== null; 71 | } 72 | exports.isObject = isObject; 73 | 74 | function isDate(d) { 75 | return isObject(d) && objectToString(d) === '[object Date]'; 76 | } 77 | exports.isDate = isDate; 78 | 79 | function isError(e) { 80 | return isObject(e) && objectToString(e) === '[object Error]'; 81 | } 82 | exports.isError = isError; 83 | 84 | function isFunction(arg) { 85 | return typeof arg === 'function'; 86 | } 87 | exports.isFunction = isFunction; 88 | 89 | function isPrimitive(arg) { 90 | return arg === null || 91 | typeof arg === 'boolean' || 92 | typeof arg === 'number' || 93 | typeof arg === 'string' || 94 | typeof arg === 'symbol' || // ES6 symbol 95 | typeof arg === 'undefined'; 96 | } 97 | exports.isPrimitive = isPrimitive; 98 | 99 | function isBuffer(arg) { 100 | return arg instanceof Buffer; 101 | } 102 | exports.isBuffer = isBuffer; 103 | 104 | function objectToString(o) { 105 | return Object.prototype.toString.call(o); 106 | } 107 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/inherits/LICENSE: -------------------------------------------------------------------------------- 1 | The ISC License 2 | 3 | Copyright (c) Isaac Z. Schlueter 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 11 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 14 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | PERFORMANCE OF THIS SOFTWARE. 16 | 17 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/inherits/README.md: -------------------------------------------------------------------------------- 1 | Browser-friendly inheritance fully compatible with standard node.js 2 | [inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor). 3 | 4 | This package exports standard `inherits` from node.js `util` module in 5 | node environment, but also provides alternative browser-friendly 6 | implementation through [browser 7 | field](https://gist.github.com/shtylman/4339901). Alternative 8 | implementation is a literal copy of standard one located in standalone 9 | module to avoid requiring of `util`. It also has a shim for old 10 | browsers with no `Object.create` support. 11 | 12 | While keeping you sure you are using standard `inherits` 13 | implementation in node.js environment, it allows bundlers such as 14 | [browserify](https://github.com/substack/node-browserify) to not 15 | include full `util` package to your client code if all you need is 16 | just `inherits` function. It worth, because browser shim for `util` 17 | package is large and `inherits` is often the single function you need 18 | from it. 19 | 20 | It's recommended to use this package instead of 21 | `require('util').inherits` for any code that has chances to be used 22 | not only in node.js but in browser too. 23 | 24 | ## usage 25 | 26 | ```js 27 | var inherits = require('inherits'); 28 | // then use exactly as the standard one 29 | ``` 30 | 31 | ## note on version ~1.0 32 | 33 | Version ~1.0 had completely different motivation and is not compatible 34 | neither with 2.0 nor with standard node.js `inherits`. 35 | 36 | If you are using version ~1.0 and planning to switch to ~2.0, be 37 | careful: 38 | 39 | * new version uses `super_` instead of `super` for referencing 40 | superclass 41 | * new version overwrites current prototype while old one preserves any 42 | existing fields on it 43 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/inherits/inherits.js: -------------------------------------------------------------------------------- 1 | module.exports = require('util').inherits 2 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/inherits/inherits_browser.js: -------------------------------------------------------------------------------- 1 | if (typeof Object.create === 'function') { 2 | // implementation from standard node.js 'util' module 3 | module.exports = function inherits(ctor, superCtor) { 4 | ctor.super_ = superCtor 5 | ctor.prototype = Object.create(superCtor.prototype, { 6 | constructor: { 7 | value: ctor, 8 | enumerable: false, 9 | writable: true, 10 | configurable: true 11 | } 12 | }); 13 | }; 14 | } else { 15 | // old school shim for old browsers 16 | module.exports = function inherits(ctor, superCtor) { 17 | ctor.super_ = superCtor 18 | var TempCtor = function () {} 19 | TempCtor.prototype = superCtor.prototype 20 | ctor.prototype = new TempCtor() 21 | ctor.prototype.constructor = ctor 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/inherits/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inherits", 3 | "description": "Browser-friendly inheritance fully compatible with standard node.js inherits()", 4 | "version": "2.0.1", 5 | "keywords": [ 6 | "inheritance", 7 | "class", 8 | "klass", 9 | "oop", 10 | "object-oriented", 11 | "inherits", 12 | "browser", 13 | "browserify" 14 | ], 15 | "main": "./inherits.js", 16 | "browser": "./inherits_browser.js", 17 | "repository": { 18 | "type": "git", 19 | "url": "git://github.com/isaacs/inherits" 20 | }, 21 | "license": "ISC", 22 | "scripts": { 23 | "test": "node test" 24 | }, 25 | "readme": "Browser-friendly inheritance fully compatible with standard node.js\n[inherits](http://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor).\n\nThis package exports standard `inherits` from node.js `util` module in\nnode environment, but also provides alternative browser-friendly\nimplementation through [browser\nfield](https://gist.github.com/shtylman/4339901). Alternative\nimplementation is a literal copy of standard one located in standalone\nmodule to avoid requiring of `util`. It also has a shim for old\nbrowsers with no `Object.create` support.\n\nWhile keeping you sure you are using standard `inherits`\nimplementation in node.js environment, it allows bundlers such as\n[browserify](https://github.com/substack/node-browserify) to not\ninclude full `util` package to your client code if all you need is\njust `inherits` function. It worth, because browser shim for `util`\npackage is large and `inherits` is often the single function you need\nfrom it.\n\nIt's recommended to use this package instead of\n`require('util').inherits` for any code that has chances to be used\nnot only in node.js but in browser too.\n\n## usage\n\n```js\nvar inherits = require('inherits');\n// then use exactly as the standard one\n```\n\n## note on version ~1.0\n\nVersion ~1.0 had completely different motivation and is not compatible\nneither with 2.0 nor with standard node.js `inherits`.\n\nIf you are using version ~1.0 and planning to switch to ~2.0, be\ncareful:\n\n* new version uses `super_` instead of `super` for referencing\n superclass\n* new version overwrites current prototype while old one preserves any\n existing fields on it\n", 26 | "readmeFilename": "README.md", 27 | "bugs": { 28 | "url": "https://github.com/isaacs/inherits/issues" 29 | }, 30 | "homepage": "https://github.com/isaacs/inherits", 31 | "_id": "inherits@2.0.1", 32 | "_from": "inherits@~2.0.1" 33 | } 34 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/inherits/test.js: -------------------------------------------------------------------------------- 1 | var inherits = require('./inherits.js') 2 | var assert = require('assert') 3 | 4 | function test(c) { 5 | assert(c.constructor === Child) 6 | assert(c.constructor.super_ === Parent) 7 | assert(Object.getPrototypeOf(c) === Child.prototype) 8 | assert(Object.getPrototypeOf(Object.getPrototypeOf(c)) === Parent.prototype) 9 | assert(c instanceof Child) 10 | assert(c instanceof Parent) 11 | } 12 | 13 | function Child() { 14 | Parent.call(this) 15 | test(this) 16 | } 17 | 18 | function Parent() {} 19 | 20 | inherits(Child, Parent) 21 | 22 | var c = new Child 23 | test(c) 24 | 25 | console.log('ok') 26 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/isarray/README.md: -------------------------------------------------------------------------------- 1 | 2 | # isarray 3 | 4 | `Array#isArray` for older browsers. 5 | 6 | ## Usage 7 | 8 | ```js 9 | var isArray = require('isarray'); 10 | 11 | console.log(isArray([])); // => true 12 | console.log(isArray({})); // => false 13 | ``` 14 | 15 | ## Installation 16 | 17 | With [npm](http://npmjs.org) do 18 | 19 | ```bash 20 | $ npm install isarray 21 | ``` 22 | 23 | Then bundle for the browser with 24 | [browserify](https://github.com/substack/browserify). 25 | 26 | With [component](http://component.io) do 27 | 28 | ```bash 29 | $ component install juliangruber/isarray 30 | ``` 31 | 32 | ## License 33 | 34 | (MIT) 35 | 36 | Copyright (c) 2013 Julian Gruber <julian@juliangruber.com> 37 | 38 | Permission is hereby granted, free of charge, to any person obtaining a copy of 39 | this software and associated documentation files (the "Software"), to deal in 40 | the Software without restriction, including without limitation the rights to 41 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 42 | of the Software, and to permit persons to whom the Software is furnished to do 43 | so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be included in all 46 | copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 54 | SOFTWARE. 55 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/isarray/build/build.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Require the given path. 4 | * 5 | * @param {String} path 6 | * @return {Object} exports 7 | * @api public 8 | */ 9 | 10 | function require(path, parent, orig) { 11 | var resolved = require.resolve(path); 12 | 13 | // lookup failed 14 | if (null == resolved) { 15 | orig = orig || path; 16 | parent = parent || 'root'; 17 | var err = new Error('Failed to require "' + orig + '" from "' + parent + '"'); 18 | err.path = orig; 19 | err.parent = parent; 20 | err.require = true; 21 | throw err; 22 | } 23 | 24 | var module = require.modules[resolved]; 25 | 26 | // perform real require() 27 | // by invoking the module's 28 | // registered function 29 | if (!module.exports) { 30 | module.exports = {}; 31 | module.client = module.component = true; 32 | module.call(this, module.exports, require.relative(resolved), module); 33 | } 34 | 35 | return module.exports; 36 | } 37 | 38 | /** 39 | * Registered modules. 40 | */ 41 | 42 | require.modules = {}; 43 | 44 | /** 45 | * Registered aliases. 46 | */ 47 | 48 | require.aliases = {}; 49 | 50 | /** 51 | * Resolve `path`. 52 | * 53 | * Lookup: 54 | * 55 | * - PATH/index.js 56 | * - PATH.js 57 | * - PATH 58 | * 59 | * @param {String} path 60 | * @return {String} path or null 61 | * @api private 62 | */ 63 | 64 | require.resolve = function(path) { 65 | if (path.charAt(0) === '/') path = path.slice(1); 66 | var index = path + '/index.js'; 67 | 68 | var paths = [ 69 | path, 70 | path + '.js', 71 | path + '.json', 72 | path + '/index.js', 73 | path + '/index.json' 74 | ]; 75 | 76 | for (var i = 0; i < paths.length; i++) { 77 | var path = paths[i]; 78 | if (require.modules.hasOwnProperty(path)) return path; 79 | } 80 | 81 | if (require.aliases.hasOwnProperty(index)) { 82 | return require.aliases[index]; 83 | } 84 | }; 85 | 86 | /** 87 | * Normalize `path` relative to the current path. 88 | * 89 | * @param {String} curr 90 | * @param {String} path 91 | * @return {String} 92 | * @api private 93 | */ 94 | 95 | require.normalize = function(curr, path) { 96 | var segs = []; 97 | 98 | if ('.' != path.charAt(0)) return path; 99 | 100 | curr = curr.split('/'); 101 | path = path.split('/'); 102 | 103 | for (var i = 0; i < path.length; ++i) { 104 | if ('..' == path[i]) { 105 | curr.pop(); 106 | } else if ('.' != path[i] && '' != path[i]) { 107 | segs.push(path[i]); 108 | } 109 | } 110 | 111 | return curr.concat(segs).join('/'); 112 | }; 113 | 114 | /** 115 | * Register module at `path` with callback `definition`. 116 | * 117 | * @param {String} path 118 | * @param {Function} definition 119 | * @api private 120 | */ 121 | 122 | require.register = function(path, definition) { 123 | require.modules[path] = definition; 124 | }; 125 | 126 | /** 127 | * Alias a module definition. 128 | * 129 | * @param {String} from 130 | * @param {String} to 131 | * @api private 132 | */ 133 | 134 | require.alias = function(from, to) { 135 | if (!require.modules.hasOwnProperty(from)) { 136 | throw new Error('Failed to alias "' + from + '", it does not exist'); 137 | } 138 | require.aliases[to] = from; 139 | }; 140 | 141 | /** 142 | * Return a require function relative to the `parent` path. 143 | * 144 | * @param {String} parent 145 | * @return {Function} 146 | * @api private 147 | */ 148 | 149 | require.relative = function(parent) { 150 | var p = require.normalize(parent, '..'); 151 | 152 | /** 153 | * lastIndexOf helper. 154 | */ 155 | 156 | function lastIndexOf(arr, obj) { 157 | var i = arr.length; 158 | while (i--) { 159 | if (arr[i] === obj) return i; 160 | } 161 | return -1; 162 | } 163 | 164 | /** 165 | * The relative require() itself. 166 | */ 167 | 168 | function localRequire(path) { 169 | var resolved = localRequire.resolve(path); 170 | return require(resolved, parent, path); 171 | } 172 | 173 | /** 174 | * Resolve relative to the parent. 175 | */ 176 | 177 | localRequire.resolve = function(path) { 178 | var c = path.charAt(0); 179 | if ('/' == c) return path.slice(1); 180 | if ('.' == c) return require.normalize(p, path); 181 | 182 | // resolve deps by returning 183 | // the dep in the nearest "deps" 184 | // directory 185 | var segs = parent.split('/'); 186 | var i = lastIndexOf(segs, 'deps') + 1; 187 | if (!i) i = 0; 188 | path = segs.slice(0, i + 1).join('/') + '/deps/' + path; 189 | return path; 190 | }; 191 | 192 | /** 193 | * Check if module is defined at `path`. 194 | */ 195 | 196 | localRequire.exists = function(path) { 197 | return require.modules.hasOwnProperty(localRequire.resolve(path)); 198 | }; 199 | 200 | return localRequire; 201 | }; 202 | require.register("isarray/index.js", function(exports, require, module){ 203 | module.exports = Array.isArray || function (arr) { 204 | return Object.prototype.toString.call(arr) == '[object Array]'; 205 | }; 206 | 207 | }); 208 | require.alias("isarray/index.js", "isarray/index.js"); 209 | 210 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/isarray/component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "isarray", 3 | "description" : "Array#isArray for older browsers", 4 | "version" : "0.0.1", 5 | "repository" : "juliangruber/isarray", 6 | "homepage": "https://github.com/juliangruber/isarray", 7 | "main" : "index.js", 8 | "scripts" : [ 9 | "index.js" 10 | ], 11 | "dependencies" : {}, 12 | "keywords": ["browser","isarray","array"], 13 | "author": { 14 | "name": "Julian Gruber", 15 | "email": "mail@juliangruber.com", 16 | "url": "http://juliangruber.com" 17 | }, 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/isarray/index.js: -------------------------------------------------------------------------------- 1 | module.exports = Array.isArray || function (arr) { 2 | return Object.prototype.toString.call(arr) == '[object Array]'; 3 | }; 4 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/isarray/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "isarray", 3 | "description": "Array#isArray for older browsers", 4 | "version": "0.0.1", 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/juliangruber/isarray.git" 8 | }, 9 | "homepage": "https://github.com/juliangruber/isarray", 10 | "main": "index.js", 11 | "scripts": { 12 | "test": "tap test/*.js" 13 | }, 14 | "dependencies": {}, 15 | "devDependencies": { 16 | "tap": "*" 17 | }, 18 | "keywords": [ 19 | "browser", 20 | "isarray", 21 | "array" 22 | ], 23 | "author": { 24 | "name": "Julian Gruber", 25 | "email": "mail@juliangruber.com", 26 | "url": "http://juliangruber.com" 27 | }, 28 | "license": "MIT", 29 | "readme": "\n# isarray\n\n`Array#isArray` for older browsers.\n\n## Usage\n\n```js\nvar isArray = require('isarray');\n\nconsole.log(isArray([])); // => true\nconsole.log(isArray({})); // => false\n```\n\n## Installation\n\nWith [npm](http://npmjs.org) do\n\n```bash\n$ npm install isarray\n```\n\nThen bundle for the browser with\n[browserify](https://github.com/substack/browserify).\n\nWith [component](http://component.io) do\n\n```bash\n$ component install juliangruber/isarray\n```\n\n## License\n\n(MIT)\n\nCopyright (c) 2013 Julian Gruber <julian@juliangruber.com>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n", 30 | "readmeFilename": "README.md", 31 | "_id": "isarray@0.0.1", 32 | "dist": { 33 | "shasum": "8a18acfca9a8f4177e09abfc6038939b05d1eedf", 34 | "tarball": "http://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz" 35 | }, 36 | "_from": "isarray@0.0.1", 37 | "_npmVersion": "1.2.18", 38 | "_npmUser": { 39 | "name": "juliangruber", 40 | "email": "julian@juliangruber.com" 41 | }, 42 | "maintainers": [ 43 | { 44 | "name": "juliangruber", 45 | "email": "julian@juliangruber.com" 46 | } 47 | ], 48 | "directories": {}, 49 | "_shasum": "8a18acfca9a8f4177e09abfc6038939b05d1eedf", 50 | "_resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", 51 | "bugs": { 52 | "url": "https://github.com/juliangruber/isarray/issues" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/string_decoder/.npmignore: -------------------------------------------------------------------------------- 1 | build 2 | test 3 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/string_decoder/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Joyent, Inc. and other Node contributors. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to permit 8 | persons to whom the Software is furnished to do so, subject to the 9 | following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/string_decoder/README.md: -------------------------------------------------------------------------------- 1 | **string_decoder.js** (`require('string_decoder')`) from Node.js core 2 | 3 | Copyright Joyent, Inc. and other Node contributors. See LICENCE file for details. 4 | 5 | Version numbers match the versions found in Node core, e.g. 0.10.24 matches Node 0.10.24, likewise 0.11.10 matches Node 0.11.10. **Prefer the stable version over the unstable.** 6 | 7 | The *build/* directory contains a build script that will scrape the source from the [joyent/node](https://github.com/joyent/node) repo given a specific Node version. -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/string_decoder/index.js: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | var Buffer = require('buffer').Buffer; 23 | 24 | var isBufferEncoding = Buffer.isEncoding 25 | || function(encoding) { 26 | switch (encoding && encoding.toLowerCase()) { 27 | case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; 28 | default: return false; 29 | } 30 | } 31 | 32 | 33 | function assertEncoding(encoding) { 34 | if (encoding && !isBufferEncoding(encoding)) { 35 | throw new Error('Unknown encoding: ' + encoding); 36 | } 37 | } 38 | 39 | var StringDecoder = exports.StringDecoder = function(encoding) { 40 | this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, ''); 41 | assertEncoding(encoding); 42 | switch (this.encoding) { 43 | case 'utf8': 44 | // CESU-8 represents each of Surrogate Pair by 3-bytes 45 | this.surrogateSize = 3; 46 | break; 47 | case 'ucs2': 48 | case 'utf16le': 49 | // UTF-16 represents each of Surrogate Pair by 2-bytes 50 | this.surrogateSize = 2; 51 | this.detectIncompleteChar = utf16DetectIncompleteChar; 52 | break; 53 | case 'base64': 54 | // Base-64 stores 3 bytes in 4 chars, and pads the remainder. 55 | this.surrogateSize = 3; 56 | this.detectIncompleteChar = base64DetectIncompleteChar; 57 | break; 58 | default: 59 | this.write = passThroughWrite; 60 | return; 61 | } 62 | 63 | this.charBuffer = new Buffer(6); 64 | this.charReceived = 0; 65 | this.charLength = 0; 66 | }; 67 | 68 | 69 | StringDecoder.prototype.write = function(buffer) { 70 | var charStr = ''; 71 | var offset = 0; 72 | 73 | // if our last write ended with an incomplete multibyte character 74 | while (this.charLength) { 75 | // determine how many remaining bytes this buffer has to offer for this char 76 | var i = (buffer.length >= this.charLength - this.charReceived) ? 77 | this.charLength - this.charReceived : 78 | buffer.length; 79 | 80 | // add the new bytes to the char buffer 81 | buffer.copy(this.charBuffer, this.charReceived, offset, i); 82 | this.charReceived += (i - offset); 83 | offset = i; 84 | 85 | if (this.charReceived < this.charLength) { 86 | // still not enough chars in this buffer? wait for more ... 87 | return ''; 88 | } 89 | 90 | // get the character that was split 91 | charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); 92 | 93 | // lead surrogate (D800-DBFF) is also the incomplete character 94 | var charCode = charStr.charCodeAt(charStr.length - 1); 95 | if (charCode >= 0xD800 && charCode <= 0xDBFF) { 96 | this.charLength += this.surrogateSize; 97 | charStr = ''; 98 | continue; 99 | } 100 | this.charReceived = this.charLength = 0; 101 | 102 | // if there are no more bytes in this buffer, just emit our char 103 | if (i == buffer.length) return charStr; 104 | 105 | // otherwise cut off the characters end from the beginning of this buffer 106 | buffer = buffer.slice(i, buffer.length); 107 | break; 108 | } 109 | 110 | var lenIncomplete = this.detectIncompleteChar(buffer); 111 | 112 | var end = buffer.length; 113 | if (this.charLength) { 114 | // buffer the incomplete character bytes we got 115 | buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end); 116 | this.charReceived = lenIncomplete; 117 | end -= lenIncomplete; 118 | } 119 | 120 | charStr += buffer.toString(this.encoding, 0, end); 121 | 122 | var end = charStr.length - 1; 123 | var charCode = charStr.charCodeAt(end); 124 | // lead surrogate (D800-DBFF) is also the incomplete character 125 | if (charCode >= 0xD800 && charCode <= 0xDBFF) { 126 | var size = this.surrogateSize; 127 | this.charLength += size; 128 | this.charReceived += size; 129 | this.charBuffer.copy(this.charBuffer, size, 0, size); 130 | this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding); 131 | return charStr.substring(0, end); 132 | } 133 | 134 | // or just emit the charStr 135 | return charStr; 136 | }; 137 | 138 | StringDecoder.prototype.detectIncompleteChar = function(buffer) { 139 | // determine how many bytes we have to check at the end of this buffer 140 | var i = (buffer.length >= 3) ? 3 : buffer.length; 141 | 142 | // Figure out if one of the last i bytes of our buffer announces an 143 | // incomplete char. 144 | for (; i > 0; i--) { 145 | var c = buffer[buffer.length - i]; 146 | 147 | // See http://en.wikipedia.org/wiki/UTF-8#Description 148 | 149 | // 110XXXXX 150 | if (i == 1 && c >> 5 == 0x06) { 151 | this.charLength = 2; 152 | break; 153 | } 154 | 155 | // 1110XXXX 156 | if (i <= 2 && c >> 4 == 0x0E) { 157 | this.charLength = 3; 158 | break; 159 | } 160 | 161 | // 11110XXX 162 | if (i <= 3 && c >> 3 == 0x1E) { 163 | this.charLength = 4; 164 | break; 165 | } 166 | } 167 | 168 | return i; 169 | }; 170 | 171 | StringDecoder.prototype.end = function(buffer) { 172 | var res = ''; 173 | if (buffer && buffer.length) 174 | res = this.write(buffer); 175 | 176 | if (this.charReceived) { 177 | var cr = this.charReceived; 178 | var buf = this.charBuffer; 179 | var enc = this.encoding; 180 | res += buf.slice(0, cr).toString(enc); 181 | } 182 | 183 | return res; 184 | }; 185 | 186 | function passThroughWrite(buffer) { 187 | return buffer.toString(this.encoding); 188 | } 189 | 190 | function utf16DetectIncompleteChar(buffer) { 191 | var incomplete = this.charReceived = buffer.length % 2; 192 | this.charLength = incomplete ? 2 : 0; 193 | return incomplete; 194 | } 195 | 196 | function base64DetectIncompleteChar(buffer) { 197 | var incomplete = this.charReceived = buffer.length % 3; 198 | this.charLength = incomplete ? 3 : 0; 199 | return incomplete; 200 | } 201 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/node_modules/string_decoder/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "string_decoder", 3 | "version": "0.10.25-1", 4 | "description": "The string_decoder module from Node core", 5 | "main": "index.js", 6 | "dependencies": {}, 7 | "devDependencies": { 8 | "tap": "~0.4.8" 9 | }, 10 | "scripts": { 11 | "test": "tap test/simple/*.js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git://github.com/rvagg/string_decoder.git" 16 | }, 17 | "homepage": "https://github.com/rvagg/string_decoder", 18 | "keywords": [ 19 | "string", 20 | "decoder", 21 | "browser", 22 | "browserify" 23 | ], 24 | "license": "MIT", 25 | "readme": "**string_decoder.js** (`require('string_decoder')`) from Node.js core\n\nCopyright Joyent, Inc. and other Node contributors. See LICENCE file for details.\n\nVersion numbers match the versions found in Node core, e.g. 0.10.24 matches Node 0.10.24, likewise 0.11.10 matches Node 0.11.10. **Prefer the stable version over the unstable.**\n\nThe *build/* directory contains a build script that will scrape the source from the [joyent/node](https://github.com/joyent/node) repo given a specific Node version.", 26 | "readmeFilename": "README.md", 27 | "bugs": { 28 | "url": "https://github.com/rvagg/string_decoder/issues" 29 | }, 30 | "_id": "string_decoder@0.10.25-1", 31 | "_from": "string_decoder@~0.10.x" 32 | } 33 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "readable-stream", 3 | "version": "1.0.27-1", 4 | "description": "Streams2, a user-land copy of the stream library from Node.js v0.10.x", 5 | "main": "readable.js", 6 | "dependencies": { 7 | "core-util-is": "~1.0.0", 8 | "isarray": "0.0.1", 9 | "string_decoder": "~0.10.x", 10 | "inherits": "~2.0.1" 11 | }, 12 | "devDependencies": { 13 | "tap": "~0.2.6" 14 | }, 15 | "scripts": { 16 | "test": "tap test/simple/*.js" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git://github.com/isaacs/readable-stream" 21 | }, 22 | "keywords": [ 23 | "readable", 24 | "stream", 25 | "pipe" 26 | ], 27 | "browser": { 28 | "util": false 29 | }, 30 | "author": { 31 | "name": "Isaac Z. Schlueter", 32 | "email": "i@izs.me", 33 | "url": "http://blog.izs.me/" 34 | }, 35 | "license": "MIT", 36 | "readme": "# readable-stream\n\n***Node-core streams for userland***\n\n[![NPM](https://nodei.co/npm/readable-stream.png?downloads=true)](https://nodei.co/npm/readable-stream/)\n[![NPM](https://nodei.co/npm-dl/readable-stream.png)](https://nodei.co/npm/readable-stream/)\n\nThis package is a mirror of the Streams2 and Streams3 implementations in Node-core.\n\nIf you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *\"stream\"* module in Node-core.\n\n**readable-stream** comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12.\n\n**readable-stream** uses proper patch-level versioning so if you pin to `\"~1.0.0\"` you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the **1.0.x** releases for now and when you’re ready to start using Streams3, pin to `\"~1.1.0\"`\n\n", 37 | "readmeFilename": "README.md", 38 | "bugs": { 39 | "url": "https://github.com/isaacs/readable-stream/issues" 40 | }, 41 | "homepage": "https://github.com/isaacs/readable-stream", 42 | "_id": "readable-stream@1.0.27-1", 43 | "_from": "readable-stream@" 44 | } 45 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/passthrough.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_passthrough.js") 2 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/readable.js: -------------------------------------------------------------------------------- 1 | exports = module.exports = require('./lib/_stream_readable.js'); 2 | exports.Readable = exports; 3 | exports.Writable = require('./lib/_stream_writable.js'); 4 | exports.Duplex = require('./lib/_stream_duplex.js'); 5 | exports.Transform = require('./lib/_stream_transform.js'); 6 | exports.PassThrough = require('./lib/_stream_passthrough.js'); 7 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/transform.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_transform.js") 2 | -------------------------------------------------------------------------------- /test/fake-package/node_modules/readable-stream/writable.js: -------------------------------------------------------------------------------- 1 | module.exports = require("./lib/_stream_writable.js") 2 | -------------------------------------------------------------------------------- /test/fake-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fake-package", 3 | "version": "0.0.0", 4 | "description": "A fake package", 5 | "main": "index.js", 6 | "private": true, 7 | "dependencies": { 8 | "fake2": "latest", 9 | "readable-stream": "^1.0.27-1" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/json-includes/data.json: -------------------------------------------------------------------------------- 1 | [ 2 | "a", 3 | "b", 4 | "c" 5 | ] 6 | -------------------------------------------------------------------------------- /test/json-includes/empty.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /test/json-includes/index.js: -------------------------------------------------------------------------------- 1 | var data = require('./data.json'); // standard json include 2 | console.log(data); 3 | 4 | var empty = require('./empty'); // shortcut syntax 5 | console.log(empty); 6 | -------------------------------------------------------------------------------- /test/self.graph.test.js: -------------------------------------------------------------------------------- 1 | var graph = require('../').analyze; 2 | var join = require('path').join; 3 | 4 | exports.packages = function (t) { 5 | graph(join(__dirname, 'fake-package', 'index.js'), 'fp', function (err, str) { 6 | t.ok(!err, 'worked'); 7 | t.deepEqual(str.split('\n'), [ 8 | "fp", 9 | " └──fake2" 10 | ], 11 | "fake-package deps" 12 | ); 13 | t.done(); 14 | }); 15 | }; 16 | 17 | exports.showLocal = function (t) { 18 | graph(join(__dirname, 'fake-package', 'index.js'), 'fake', function (err, str) { 19 | t.ok(!err, 'worked'); 20 | t.deepEqual(str.split('\n'), [ 21 | "fake", 22 | " ├─┬./loc1", 23 | " │ └─┬./loc3", 24 | " │ └──fake2", 25 | " ├─┬./loc2", 26 | " │ ├─┬./loc1", 27 | " │ │ └─┬./loc3", 28 | " │ │ └──fake2", 29 | " │ └──fake2", 30 | " └─┬./loc3", 31 | " └──fake2" 32 | ], 33 | "local dependencies of fake-package" 34 | ); 35 | t.done(); 36 | }, { showLocal: true }); 37 | }; 38 | 39 | exports.entryPoint = function (t) { 40 | graph(join(__dirname, 'fake-package', 'loc2.js'), 'loc2.js', function (err, str) { 41 | t.ok(!err, 'worked'); 42 | t.deepEqual(str.split('\n'), [ 43 | "loc2.js", 44 | " ├─┬./loc1", 45 | " │ └─┬./loc3", 46 | " │ └──fake2", 47 | " └──fake2" 48 | ], 49 | "local dependencies of fake-package" 50 | ); 51 | t.done(); 52 | }, { showLocal: true }); 53 | }; 54 | 55 | exports.cycleModule = function (t) { 56 | var writableEntry = join( 57 | __dirname, 58 | 'fake-package', 59 | 'node_modules', 60 | 'readable-stream', 61 | 'writable.js' 62 | ); 63 | graph(writableEntry, 'writable.js', function (err, str) { 64 | t.ok(!err, 'worked'); 65 | t.deepEqual(str.split('\n'), [ 66 | "writable.js", 67 | " └─┬./lib/_stream_writable.js", 68 | " ├─┬./_stream_duplex ↪ ./_stream_writable", 69 | " │ ├─┬./_stream_readable", 70 | " │ │ ├──core-util-is", 71 | " │ │ ├──inherits", 72 | " │ │ ├──isarray", 73 | " │ │ └──string_decoder/", 74 | " │ ├──core-util-is", 75 | " │ └──inherits", 76 | " ├──core-util-is", 77 | " └──inherits" 78 | ], "cycle indicated"); 79 | t.done(); 80 | }, { showLocal: true }); 81 | }; 82 | 83 | exports.cycleModuleCycles = function (t) { 84 | var writableEntry = join( 85 | __dirname, 86 | 'fake-package', 87 | 'node_modules', 88 | 'readable-stream', 89 | 'writable.js' 90 | ); 91 | graph(writableEntry, 'writable.js', function (err, str) { 92 | t.ok(!err, 'worked'); 93 | var out = str.split('\n').map(function (s) { 94 | // remove start of that absolute path string 95 | return s.match(/\/readable\-stream\/(.*)/)[1]; 96 | }); 97 | t.deepEqual(out, [ 98 | "lib/_stream_writable.js',", 99 | "lib/_stream_duplex.js' ] ]" 100 | ], "cycle indicated"); 101 | t.done(); 102 | }, { showLocal: true, showCycles: true }); 103 | }; 104 | 105 | exports.jsonIncludes = function (t) { 106 | // TODO: this SHOULD work without ignoreMissing 107 | // but currently the default module-deps resolver (browser-resolve) 108 | // does not handle json includes without the extension in the require 109 | // the same goes for the resolve package which is the nodey thing 110 | graph(join(__dirname, 'json-includes', 'index.js'), 'ji', function (err, str) { 111 | t.ok(!err, 'worked'); 112 | t.deepEqual(str.split('\n'), ["ji"], "json-includes deps"); 113 | t.done(); 114 | }, { ignoreMissing: true }); 115 | }; 116 | --------------------------------------------------------------------------------