pax_global_header00006660000000000000000000000064137117657440014531gustar00rootroot0000000000000052 comment=ac7e85e330d636b87674fbf33ac537395e2f296e module-deps-6.2.3/000077500000000000000000000000001371176574400137575ustar00rootroot00000000000000module-deps-6.2.3/.gitignore000066400000000000000000000000141371176574400157420ustar00rootroot00000000000000node_modulesmodule-deps-6.2.3/.npmrc000066400000000000000000000000231371176574400150720ustar00rootroot00000000000000package-lock=false module-deps-6.2.3/.travis.yml000066400000000000000000000006311371176574400160700ustar00rootroot00000000000000language: node_js node_js: - "12" - "11" - "10" - "8" - "6" - "4" - "iojs" - "0.12" - "0.10" - "0.8" sudo: false before_install: # Old npm certs are untrusted https://github.com/npm/npm/issues/20191 - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.8" ]; then export NPM_CONFIG_STRICT_SSL=false; fi' - 'nvm install-latest-npm' matrix: fast_finish: true module-deps-6.2.3/CHANGELOG.md000066400000000000000000000043071371176574400155740ustar00rootroot00000000000000# module-deps Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## 6.2.3 - 2020-08-03 * Improve error message when dependencies cannot be found [#123](https://github.com/browserify/module-deps/pull/123) * Upgrade `browser-resolve` to 2.0 [#164](https://github.com/browserify/module-deps/pull/164) ## 6.2.2 - 2019-12-13 * Update minimum required version of `detective` [#161](https://github.com/browserify/module-deps/pull/161) ## 6.2.1 - 2019-05-24 * Update minimum required version of `cached-path-relative` [#155](https://github.com/browserify/module-deps/pull/155) * Add CI testing on Windows [#152](https://github.com/browserify/module-deps/pull/152) * Add CI testing on recent Node.js versions (10, 11, 12) [#157](https://github.com/browserify/module-deps/pull/157) ## 6.2.0 - 2018-11-13 * Add `.dirname` property to the object given to `opts.resolve` [#154](https://github.com/browserify/module-deps/pull/154) ## 6.1.0 - 2018-05-16 * Add a `detect` option for custom dependency detection [#63](https://github.com/browserify/module-deps/pull/63), [2dcc339](https://github.com/browserify/module-deps/commit/2dcc3399ee67ba51ed26d9a0605a8ccdc70c9db7) ## 6.0.2 - 2018-03-28 * Fix missing 'file' event when file has a syntax error [#146](https://github.com/browserify/module-deps/pull/146) ## 6.0.1 - 2018-03-27 * Fix crash when file has a transform and a syntax error [#145](https://github.com/browserify/module-deps/pull/145) ## 6.0.0 - 2018-02-07 * Ignore package.json files that do not contain JSON objects [#142](https://github.com/browserify/module-deps/pull/142) * Don't preserve symlinks when resolving transforms, matching Node resolution behaviour [#133](https://github.com/browserify/module-deps/pull/133) * Fix 'file' events with `persistentCache` [#127](https://github.com/browserify/module-deps/pull/127) * Add dependencies to a file when transforms emit 'dep' event [#141](https://github.com/browserify/module-deps/pull/141) ## 5.0.1 - 2018-01-06 * Restore support for node < 4.0.0. ## 5.0.0 - 2018-01-02 * Update deps * Drop support for node < 0.12 due due to detective dropping support * Add engines field set to `>=4.0.0` module-deps-6.2.3/LICENSE000066400000000000000000000020611371176574400147630ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. module-deps-6.2.3/appveyor.yml000066400000000000000000000012151371176574400163460ustar00rootroot00000000000000environment: matrix: # not yet available on appveyor # - nodejs_version: "12" - nodejs_version: "11" - nodejs_version: "10" - nodejs_version: "8" - nodejs_version: "6" - nodejs_version: "4" - nodejs_version: "0.12" - nodejs_version: "0.10" # Install scripts. (runs after repo cloning) install: # Get the latest stable version of Node.js or io.js - ps: Install-Product node $env:nodejs_version # install modules - npm install # Post-install test scripts. test_script: # Output useful info for debugging. - node --version - npm --version # run tests - npm test # Don't actually build. build: off module-deps-6.2.3/bin/000077500000000000000000000000001371176574400145275ustar00rootroot00000000000000module-deps-6.2.3/bin/cmd.js000077500000000000000000000013601371176574400156330ustar00rootroot00000000000000#!/usr/bin/env node var mdeps = require('../'); var subarg = require('subarg'); var fs = require('fs'); var path = require('path'); var argv = subarg(process.argv.slice(2), { alias: { h: 'help', t: 'transform', g: 'globalTransform' } }); if (argv.help) return usage(0); var JSONStream = require('JSONStream'); var files = argv._.map(function (file) { if (file === '-') return process.stdin; return path.resolve(file); }); var md = mdeps(argv); md.pipe(JSONStream.stringify()).pipe(process.stdout); files.forEach(function (file) { md.write(file) }); md.end(); function usage (code) { var r = fs.createReadStream(__dirname + '/usage.txt'); r.pipe(process.stdout); if (code) r.on('end', function () { process.exit(code) }); } module-deps-6.2.3/bin/usage.txt000066400000000000000000000002541371176574400163750ustar00rootroot00000000000000module-deps [FILES] OPTIONS Generate json output for the entry point FILES. OPTIONS are: -t TRANSFORM Apply a TRANSFORM. -g TRANSFORM Apply a global TRANSFORM. module-deps-6.2.3/example/000077500000000000000000000000001371176574400154125ustar00rootroot00000000000000module-deps-6.2.3/example/deps.js000066400000000000000000000002751371176574400167070ustar00rootroot00000000000000var mdeps = require('../'); var JSONStream = require('JSONStream'); var md = mdeps(); md.pipe(JSONStream.stringify()).pipe(process.stdout); md.end({ file: __dirname + '/files/main.js' }); module-deps-6.2.3/example/files/000077500000000000000000000000001371176574400165145ustar00rootroot00000000000000module-deps-6.2.3/example/files/bar.js000066400000000000000000000000671371176574400176210ustar00rootroot00000000000000module.exports = function (n) { return n * 100; }; module-deps-6.2.3/example/files/foo.js000066400000000000000000000001351371176574400176340ustar00rootroot00000000000000var bar = require('./bar'); module.exports = function (n) { return n * 111 + bar(n); }; module-deps-6.2.3/example/files/main.js000066400000000000000000000000741371176574400177770ustar00rootroot00000000000000var foo = require('./foo'); console.log('main: ' + foo(5)); module-deps-6.2.3/example/files/xyz.js000066400000000000000000000000731371176574400177040ustar00rootroot00000000000000var foo = require('./foo'); console.log('xyz: ' + foo(6)); module-deps-6.2.3/index.js000066400000000000000000000504461371176574400154350ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var relativePath = require('cached-path-relative'); var browserResolve = require('browser-resolve'); var nodeResolve = require('resolve'); var detective = require('detective'); var through = require('through2'); var concat = require('concat-stream'); var parents = require('parents'); var combine = require('stream-combiner2'); var duplexer = require('duplexer2'); var xtend = require('xtend'); var defined = require('defined'); var inherits = require('inherits'); var Transform = require('readable-stream').Transform; module.exports = Deps; inherits(Deps, Transform); function Deps (opts) { var self = this; if (!(this instanceof Deps)) return new Deps(opts); Transform.call(this, { objectMode: true }); if (!opts) opts = {}; this.basedir = opts.basedir || process.cwd(); this.persistentCache = opts.persistentCache || function (file, id, pkg, fallback, cb) { process.nextTick(function () { fallback(null, cb); }); }; this.cache = opts.cache; this.fileCache = opts.fileCache; this.pkgCache = opts.packageCache || {}; this.pkgFileCache = {}; this.pkgFileCachePending = {}; this._emittedPkg = {}; this._transformDeps = {}; this.visited = {}; this.walking = {}; this.entries = []; this._input = []; this.paths = opts.paths || process.env.NODE_PATH || ''; if (typeof this.paths === 'string') { var delimiter = path.delimiter || (process.platform === 'win32' ? ';' : ':'); this.paths = this.paths.split(delimiter); } this.paths = this.paths .filter(Boolean) .map(function (p) { return path.resolve(self.basedir, p); }); this.transforms = [].concat(opts.transform).filter(Boolean); this.globalTransforms = [].concat(opts.globalTransform).filter(Boolean); this.resolver = opts.resolve || browserResolve; this.detective = opts.detect || detective; this.options = xtend(opts); if (!this.options.modules) this.options.modules = {}; // If the caller passes options.expose, store resolved pathnames for exposed // modules in it. If not, set it anyway so it's defined later. if (!this.options.expose) this.options.expose = {}; this.pending = 0; this.inputPending = 0; var topfile = path.join(this.basedir, '__fake.js'); this.top = { id: topfile, filename: topfile, paths: this.paths, basedir: this.basedir }; } Deps.prototype._isTopLevel = function (file) { var isTopLevel = this.entries.some(function (main) { var m = relativePath(path.dirname(main), file); return m.split(/[\\\/]/).indexOf('node_modules') < 0; }); if (!isTopLevel) { var m = relativePath(this.basedir, file); isTopLevel = m.split(/[\\\/]/).indexOf('node_modules') < 0; } return isTopLevel; }; Deps.prototype._transform = function (row, enc, next) { var self = this; if (typeof row === 'string') { row = { file: row }; } if (row.transform && row.global) { this.globalTransforms.push([ row.transform, row.options ]); return next(); } else if (row.transform) { this.transforms.push([ row.transform, row.options ]); return next(); } self.pending ++; var basedir = defined(row.basedir, self.basedir); if (row.entry !== false) { self.entries.push(path.resolve(basedir, row.file || row.id)); } self.lookupPackage(row.file, function (err, pkg) { if (err && self.options.ignoreMissing) { self.emit('missing', row.file, self.top); self.pending --; return next(); } if (err) return self.emit('error', err) self.pending --; self._input.push({ row: row, pkg: pkg }); next(); }); }; Deps.prototype._flush = function () { var self = this; var files = {}; self._input.forEach(function (r) { var w = r.row, f = files[w.file || w.id]; if (f) { f.row.entry = f.row.entry || w.entry; var ex = f.row.expose || w.expose; f.row.expose = ex; if (ex && f.row.file === f.row.id && w.file !== w.id) { f.row.id = w.id; } } else files[w.file || w.id] = r; }); Object.keys(files).forEach(function (key) { var r = files[key]; var pkg = r.pkg || {}; var dir = r.row.file ? path.dirname(r.row.file) : self.basedir; if (!pkg.__dirname) pkg.__dirname = dir; self.walk(r.row, xtend(self.top, { filename: path.join(dir, '_fake.js') })); }); if (this.pending === 0) this.push(null); this._ended = true; }; Deps.prototype.resolve = function (id, parent, cb) { var self = this; var opts = self.options; if (xhas(self.cache, parent.id, 'deps', id) && self.cache[parent.id].deps[id]) { var file = self.cache[parent.id].deps[id]; var pkg = self.pkgCache[file]; if (pkg) return cb(null, file, pkg); return self.lookupPackage(file, function (err, pkg) { cb(null, file, pkg); }); } parent.packageFilter = function (p, x) { var pkgdir = path.dirname(x); if (opts.packageFilter) p = opts.packageFilter(p, x); p.__dirname = pkgdir; return p; }; // have `resolve` do all the package.json lookups, // see discussion in https://github.com/browserify/browser-resolve/issues/93#issuecomment-667837808 parent.package = undefined; if (opts.extensions) parent.extensions = opts.extensions; if (opts.modules) parent.modules = opts.modules; self.resolver(id, parent, function onresolve (err, file, pkg, fakePath) { if (err) return cb(err); if (!file) return cb(new Error( 'module not found: "' + id + '" from file ' + parent.filename )); if (!pkg || !pkg.__dirname) { self.lookupPackage(file, function (err, p) { if (err) return cb(err); if (!p) p = {}; if (!p.__dirname) p.__dirname = path.dirname(file); self.pkgCache[file] = p; onresolve(err, file, opts.packageFilter ? opts.packageFilter(p, p.__dirname) : p, fakePath ); }); } else cb(err, file, pkg, fakePath); }); }; Deps.prototype.readFile = function (file, id, pkg) { var self = this; if (xhas(this.fileCache, file)) { return toStream(this.fileCache[file]); } var rs = fs.createReadStream(file, { encoding: 'utf8' }); return rs; }; Deps.prototype.getTransforms = function (file, pkg, opts) { if (!opts) opts = {}; var self = this; var isTopLevel; if (opts.builtin || opts.inNodeModules) isTopLevel = false; else isTopLevel = this._isTopLevel(file); var transforms = [].concat(isTopLevel ? this.transforms : []) .concat(getTransforms(pkg, { globalTransform: this.globalTransforms, transformKey: this.options.transformKey })) ; if (transforms.length === 0) return through(); var pending = transforms.length; var streams = []; var input = through(); var output = through(); var dup = duplexer(input, output); for (var i = 0; i < transforms.length; i++) (function (i) { makeTransform(transforms[i], function (err, trs) { if (err) { return dup.emit('error', err); } streams[i] = trs; if (-- pending === 0) done(); }); })(i); return dup; function done () { var middle = combine.apply(null, streams); middle.on('error', function (err) { err.message += ' while parsing file: ' + file; if (!err.filename) err.filename = file; dup.emit('error', err); }); input.pipe(middle).pipe(output); } function makeTransform (tr, cb) { var trOpts = {}; if (Array.isArray(tr)) { trOpts = tr[1] || {}; tr = tr[0]; } trOpts._flags = trOpts.hasOwnProperty('_flags') ? trOpts._flags : self.options; if (typeof tr === 'function') { var t = tr(file, trOpts); // allow transforms to `stream.emit('dep', path)` to add dependencies for this file t.on('dep', function (dep) { if (!self._transformDeps[file]) self._transformDeps[file] = []; self._transformDeps[file].push(dep); }); self.emit('transform', t, file); nextTick(cb, null, wrapTransform(t)); } else { loadTransform(tr, trOpts, function (err, trs) { if (err) return cb(err); cb(null, wrapTransform(trs)); }); } } function loadTransform (id, trOpts, cb) { var params = { basedir: path.dirname(file), preserveSymlinks: false }; nodeResolve(id, params, function nr (err, res, again) { if (err && again) return cb && cb(err); if (err) { params.basedir = pkg.__dirname; return nodeResolve(id, params, function (e, r) { nr(e, r, true); }); } if (!res) return cb(new Error( 'cannot find transform module ' + tr + ' while transforming ' + file )); var r = require(res); if (typeof r !== 'function') { return cb(new Error( 'Unexpected ' + typeof r + ' exported by the ' + JSON.stringify(res) + ' package. ' + 'Expected a transform function.' )); } var trs = r(file, trOpts); // allow transforms to `stream.emit('dep', path)` to add dependencies for this file trs.on('dep', function (dep) { if (!self._transformDeps[file]) self._transformDeps[file] = []; self._transformDeps[file].push(dep); }); self.emit('transform', trs, file); cb(null, trs); }); } }; Deps.prototype.walk = function (id, parent, cb) { var self = this; var opts = self.options; this.pending ++; var rec = {}; var input; if (typeof id === 'object') { rec = xtend(id); if (rec.entry === false) delete rec.entry; id = rec.file || rec.id; input = true; this.inputPending ++; } self.resolve(id, parent, function (err, file, pkg, fakePath) { // this is checked early because parent.modules is also modified // by this function. var builtin = has(parent.modules, id); if (rec.expose) { // Set options.expose to make the resolved pathname available to the // caller. They may or may not have requested it, but it's harmless // to set this if they didn't. self.options.expose[rec.expose] = self.options.modules[rec.expose] = file; } if (pkg && !self._emittedPkg[pkg.__dirname]) { self._emittedPkg[pkg.__dirname] = true; self.emit('package', pkg); } if (opts.postFilter && !opts.postFilter(id, file, pkg)) { if (--self.pending === 0) self.push(null); if (input) --self.inputPending; return cb && cb(null, undefined); } if (err && rec.source) { file = rec.file; var ts = self.getTransforms(file, pkg); ts.on('error', function (err) { self.emit('error', err); }); ts.pipe(concat(function (body) { rec.source = body.toString('utf8'); fromSource(file, rec.source, pkg); })); return ts.end(rec.source); } if (err && self.options.ignoreMissing) { if (--self.pending === 0) self.push(null); if (input) --self.inputPending; self.emit('missing', id, parent); return cb && cb(null, undefined); } if (err) { var message = 'Can\'t walk dependency graph: ' + err.message; message += '\n required by ' + parent.filename; err.message = message; return self.emit('error', err); } if (self.visited[file]) { if (-- self.pending === 0) self.push(null); if (input) --self.inputPending; return cb && cb(null, file); } self.visited[file] = true; if (rec.source) { var ts = self.getTransforms(file, pkg); ts.on('error', function (err) { self.emit('error', err); }); ts.pipe(concat(function (body) { rec.source = body.toString('utf8'); fromSource(file, rec.source, pkg); })); return ts.end(rec.source); } var c = self.cache && self.cache[file]; if (c) return fromDeps(file, c.source, c.package, fakePath, Object.keys(c.deps)); self.persistentCache(file, id, pkg, persistentCacheFallback, function (err, c) { self.emit('file', file, id); if (err) { self.emit('error', err); return; } fromDeps(file, c.source, c.package, fakePath, Object.keys(c.deps)); }); function persistentCacheFallback (dataAsString, cb) { var stream = dataAsString ? toStream(dataAsString) : self.readFile(file, id, pkg).on('error', cb); stream .pipe(self.getTransforms(fakePath || file, pkg, { builtin: builtin, inNodeModules: parent.inNodeModules })) .on('error', cb) .pipe(concat(function (body) { var src = body.toString('utf8'); try { var deps = getDeps(file, src); } catch (err) { cb(err); } if (deps) { cb(null, { source: src, package: pkg, deps: deps.reduce(function (deps, dep) { deps[dep] = true; return deps; }, {}) }); } })); } }); function getDeps (file, src) { var deps = rec.noparse ? [] : self.parseDeps(file, src); // dependencies emitted by transforms if (self._transformDeps[file]) deps = deps.concat(self._transformDeps[file]); return deps; } function fromSource (file, src, pkg, fakePath) { var deps = getDeps(file, src); if (deps) fromDeps(file, src, pkg, fakePath, deps); } function fromDeps (file, src, pkg, fakePath, deps) { var p = deps.length; var resolved = {}; if (input) --self.inputPending; (function resolve () { if (self.inputPending > 0) return setTimeout(resolve); deps.forEach(function (id) { if (opts.filter && !opts.filter(id)) { resolved[id] = false; if (--p === 0) done(); return; } var isTopLevel = self._isTopLevel(fakePath || file); var current = { id: file, filename: file, basedir: path.dirname(file), paths: self.paths, package: pkg, inNodeModules: parent.inNodeModules || !isTopLevel }; self.walk(id, current, function (err, r) { resolved[id] = r; if (--p === 0) done(); }); }); if (deps.length === 0) done(); })(); function done () { if (!rec.id) rec.id = file; if (!rec.source) rec.source = src; if (!rec.deps) rec.deps = resolved; if (!rec.file) rec.file = file; if (self.entries.indexOf(file) >= 0) { rec.entry = true; } self.push(rec); if (cb) cb(null, file); if (-- self.pending === 0) self.push(null); } } }; Deps.prototype.parseDeps = function (file, src, cb) { var self = this; if (this.options.noParse === true) return []; if (/\.json$/.test(file)) return []; if (Array.isArray(this.options.noParse) && this.options.noParse.indexOf(file) >= 0) { return []; } try { var deps = self.detective(src) } catch (ex) { var message = ex && ex.message ? ex.message : ex; throw new Error( 'Parsing file ' + file + ': ' + message ); } return deps; }; Deps.prototype.lookupPackage = function (file, cb) { var self = this; var cached = this.pkgCache[file]; if (cached) return nextTick(cb, null, cached); if (cached === false) return nextTick(cb, null, undefined); var dirs = parents(file ? path.dirname(file) : self.basedir); (function next () { if (dirs.length === 0) { self.pkgCache[file] = false; return cb(null, undefined); } var dir = dirs.shift(); if (dir.split(/[\\\/]/).slice(-1)[0] === 'node_modules') { return cb(null, undefined); } var pkgfile = path.join(dir, 'package.json'); var cached = self.pkgCache[pkgfile]; if (cached) return nextTick(cb, null, cached); else if (cached === false) return next(); var pcached = self.pkgFileCachePending[pkgfile]; if (pcached) return pcached.push(onpkg); pcached = self.pkgFileCachePending[pkgfile] = []; fs.readFile(pkgfile, function (err, src) { if (err) return onpkg(); try { var pkg = JSON.parse(src) } catch (err) { return onpkg(new Error([ err + ' while parsing json file ' + pkgfile ].join(''))); } pkg.__dirname = dir; self.pkgCache[pkgfile] = pkg; self.pkgCache[file] = pkg; onpkg(null, pkg); }); function onpkg (err, pkg) { if (self.pkgFileCachePending[pkgfile]) { var fns = self.pkgFileCachePending[pkgfile]; delete self.pkgFileCachePending[pkgfile]; fns.forEach(function (f) { f(err, pkg) }); } if (err) cb(err); else if (pkg && typeof pkg === 'object') cb(null, pkg); else { self.pkgCache[pkgfile] = false; next(); } } })(); }; function getTransforms (pkg, opts) { var trx = []; if (opts.transformKey) { var n = pkg; var keys = opts.transformKey; for (var i = 0; i < keys.length; i++) { if (n && typeof n === 'object') n = n[keys[i]]; else break; } if (i === keys.length) { trx = [].concat(n).filter(Boolean); } } return trx.concat(opts.globalTransform || []); } function nextTick (cb) { var args = [].slice.call(arguments, 1); process.nextTick(function () { cb.apply(null, args) }); } function xhas (obj) { if (!obj) return false; for (var i = 1; i < arguments.length; i++) { var key = arguments[i]; if (!has(obj, key)) return false; obj = obj[key]; } return true; } function toStream (dataAsString) { var tr = through(); tr.push(dataAsString); tr.push(null); return tr; } function has (obj, key) { return obj && Object.prototype.hasOwnProperty.call(obj, key); } function wrapTransform (tr) { if (typeof tr.read === 'function') return tr; var input = through(), output = through(); input.pipe(tr).pipe(output); var wrapper = duplexer(input, output); tr.on('error', function (err) { wrapper.emit('error', err) }); return wrapper; } module-deps-6.2.3/package.json000066400000000000000000000023531371176574400162500ustar00rootroot00000000000000{ "name": "module-deps", "version": "6.2.3", "description": "walk the dependency graph to generate json output that can be fed into browser-pack", "main": "index.js", "bin": { "module-deps": "bin/cmd.js" }, "dependencies": { "JSONStream": "^1.0.3", "browser-resolve": "^2.0.0", "cached-path-relative": "^1.0.2", "concat-stream": "~1.6.0", "defined": "^1.0.0", "detective": "^5.2.0", "duplexer2": "^0.1.2", "inherits": "^2.0.1", "parents": "^1.0.0", "readable-stream": "^2.0.2", "resolve": "^1.4.0", "stream-combiner2": "^1.1.1", "subarg": "^1.0.0", "through2": "^2.0.0", "xtend": "^4.0.0" }, "devDependencies": { "browser-pack": "^6.0.2", "tap": "^10.7.3" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/browserify/module-deps.git" }, "homepage": "https://github.com/browserify/module-deps", "keywords": [ "dependency", "graph", "browser", "require", "module", "exports", "json" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "engines": { "node": ">= 0.8.0" }, "license": "MIT" } module-deps-6.2.3/readme.markdown000066400000000000000000000232351371176574400167650ustar00rootroot00000000000000# module-deps walk the dependency graph to generate json output that can be fed into [browser-pack](https://github.com/browserify/browser-pack) [![build status](https://secure.travis-ci.org/browserify/module-deps.png)](http://travis-ci.org/browserify/module-deps) # example ``` js var mdeps = require('module-deps'); var JSONStream = require('JSONStream'); var md = mdeps(); md.pipe(JSONStream.stringify()).pipe(process.stdout); md.end({ file: __dirname + '/files/main.js' }); ``` output: ```json $ node example/deps.js [ {"id":"/home/substack/projects/module-deps/example/files/main.js","source":"var foo = require('./foo');\nconsole.log('main: ' + foo(5));\n","entry":true,"deps":{"./foo":"/home/substack/projects/module-deps/example/files/foo.js"}} , {"id":"/home/substack/projects/module-deps/example/files/foo.js","source":"var bar = require('./bar');\n\nmodule.exports = function (n) {\n return n * 111 + bar(n);\n};\n","deps":{"./bar":"/home/substack/projects/module-deps/example/files/bar.js"}} , {"id":"/home/substack/projects/module-deps/example/files/bar.js","source":"module.exports = function (n) {\n return n * 100;\n};\n","deps":{}} ] ``` and you can feed this json data into [browser-pack](https://github.com/browserify/browser-pack): ```bash $ node example/deps.js | browser-pack | node main: 1055 ``` # usage ``` usage: module-deps [files] generate json output from each entry file ``` # methods ``` js var mdeps = require('module-deps') ``` ## var d = mdeps(opts={}) Return an object transform stream `d` that expects entry filenames or `{ id: ..., file: ... }` objects as input and produces objects for every dependency from a recursive module traversal as output. Each file in `files` can be a string filename or a stream. Optionally pass in some `opts`: * `opts.transform` - a string or array of string transforms (see below) * `opts.transformKey` - an array path of strings showing where to look in the package.json for source transformations. If falsy, don't look at the package.json at all. * `opts.resolve` - custom resolve function using the `opts.resolve(id, parent, cb)` signature that [browser-resolve](https://github.com/shtylman/node-browser-resolve) has * `opts.detect` - a custom dependency detection function. `opts.detect(source)` should return an array of dependency module names. By default [detective](https://github.com/browserify/detective) is used. * `opts.filter` - a function (id) to skip resolution of some module `id` strings. If defined, `opts.filter(id)` should return truthy for all the ids to include and falsey for all the ids to skip. * `opts.postFilter` - a function (id, file, pkg) that gets called after `id` has been resolved. Return false to skip this file. * `opts.packageFilter` - transform the parsed package.json contents before using the values. `opts.packageFilter(pkg, dir)` should return the new `pkg` object to use. * `opts.noParse` - an array of absolute paths to not parse for dependencies. Use this for large dependencies like jquery or threejs which take forever to parse. * `opts.cache` - an object mapping filenames to file objects to skip costly io * `opts.packageCache` - an object mapping filenames to their parent package.json contents for browser fields, main entries, and transforms * `opts.fileCache` - an object mapping filenames to raw source to avoid reading from disk. * `opts.persistentCache` - a complex cache handler that allows async and persistent caching of data. A `persistentCache` needs to follow this interface: ```js function persistentCache ( file, // the path to the file that is loaded id, // the id that is used to reference this file pkg, // the package that this file belongs to fallback fallback, // async fallback handler to be called if the cache doesn't hold the given file cb // callback handler that receives the cache data ) { if (hasError()) { return cb(error) // Pass any error to the callback } var fileData = fs.readFileSync(file) var key = keyFromFile(file, fileData) if (db.has(key)) { return cb(null, { source: db.get(key).toString(), package: pkg, // The package for housekeeping deps: { 'id': // id that is used to reference a required file 'file' // file path to the required file } }) } // // The fallback will process the file in case the file is not // in cache. // // Note that if your implementation doesn't need the file data // then you can pass `null` instead of the source and the fallback will // fetch the data by itself. // fallback(fileData, function (error, cacheableEntry) { if (error) { return cb(error) } db.addToCache(key, cacheableEntry) cb(null, cacheableEntry) }) } ``` * `opts.paths` - array of global paths to search. Defaults to splitting on `':'` in `process.env.NODE_PATH` * `opts.ignoreMissing` - ignore files that failed to resolve # input objects Input objects should be string filenames or objects with these parameters: * `row.file` - filename * `row.entry` - whether to treat this file as an entry point, defaults to `true`. Set to `false` to include this file, but not run it automatically. * `row.expose` - name to be exposed as * `row.noparse` - when true, don't parse the file contents for dependencies or objects can specify transforms: * `row.transform` - string name, path, or function * `row.options` - transform options as an object * `row.global` - boolean, whether the transform is global # output objects Output objects describe files with dependencies. They have these properties: * `row.id` - an identifier for the file, used in the `row.deps` prperty * `row.file` - path to the source file * `row.entry` - true if the file is an entry point * `row.expose` - name to be exposed as * `row.source` - source file content as a string * `row.deps` - object describing dependencies. The keys are strings as used in `require()` calls in the file, and values are the row IDs (file paths) of dependencies. # events ## d.on('transform', function (tr, file) {}) Every time a transform is applied to a `file`, a `'transform'` event fires with the instantiated transform stream `tr`. ## d.on('file', function (file) {}) Every time a file is read, this event fires with the file path. ## d.on('missing', function (id, parent) {}) When `opts.ignoreMissing` is enabled, this event fires for each missing package. ## d.on('package', function (pkg) {}) Every time a package is read, this event fires. The directory name of the package is available in `pkg.__dirname`. # transforms module-deps can be configured to run source transformations on files before parsing them for `require()` calls. These transforms are useful if you want to compile a language like [coffeescript](http://coffeescript.org/) on the fly or if you want to load static assets into your bundle by parsing the AST for `fs.readFileSync()` calls. If the transform is a function, it should take the `file` name as an argument and return a through stream that will be written file contents and should output the new transformed file contents. If the transform is a string, it is treated as a module name that will resolve to a module that is expected to follow this format: ``` js var through = require('through2'); module.exports = function (file, opts) { return through() }; ``` You don't necessarily need to use the [through2](https://github.com/rvagg/through2) module to create a readable/writable filter stream for transforming file contents, but this is an easy way to do it. module-deps looks for `require()` calls and adds their arguments as dependencies of a file. Transform streams can emit `'dep'` events to include additional dependencies that are not consumed with `require()`. When you call `mdeps()` with an `opts.transform`, the transformations you specify will not be run for any files in node_modules/. This is because modules you include should be self-contained and not need to worry about guarding themselves against transformations that may happen upstream. Modules can apply their own transformations by setting a transformation pipeline in their package.json at the `opts.transformKey` path. These transformations only apply to the files directly in the module itself, not to the module's dependants nor to its dependencies. ## package.json transformKey Transform keys live at a configurable location in the package.json denoted by the `opts.transformKey` array. For a transformKey of `['foo','bar']`, the transformKey can be a single string (`"fff"`): ``` json { "foo": { "bar": "fff" } } ``` or an array of strings (`["fff","ggg"]`): ``` json { "foo": { "bar": ["fff","ggg"] } } ``` If you want to pass options to the transforms, you can use a 2-element array inside of the primary array. Here `fff` gets an options object with `{"x":3}` and `ggg` gets `{"y":4}`: ``` json { "foo": { "bar": [["fff",{"x":3}],["ggg",{"y":4}]] } } ``` Options sent to the module-deps constructor are also provided under `opts._flags`. These options are sometimes required if your transform needs to do something different when browserify is run in debug mode, for example. # usage ``` module-deps [FILES] OPTIONS Generate json output for the entry point FILES. OPTIONS are: -t TRANSFORM Apply a TRANSFORM. -g TRANSFORM Apply a global TRANSFORM. ``` # install With [npm](http://npmjs.org), to get the module do: ``` npm install module-deps ``` and to get the `module-deps` command do: ``` npm install -g module-deps ``` # license MIT module-deps-6.2.3/test/000077500000000000000000000000001371176574400147365ustar00rootroot00000000000000module-deps-6.2.3/test/bundle.js000066400000000000000000000011601371176574400165430ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); test('bundle', function (t) { t.plan(1); var p = parser(); p.end(path.join(__dirname, '/files/main.js')); p.on('error', t.fail.bind(t)); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('console', src)({ log: function (s) { t.equal(s, 'main: 1055') } }); }); }); module-deps-6.2.3/test/cache.js000066400000000000000000000021471371176574400163430ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var path = require('path'); var files = { foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = { foo: 'notreal foo', bar: 'notreal bar' }; var cache = {}; cache[files.foo] = { source: sources.foo, deps: { './bar': files.bar } }; cache[files.bar] = { source: sources.bar, deps: {} }; test('uses cache', function (t) { t.plan(1); var p = parser({ cache: cache }); p.end({ id: 'foo', file: files.foo, entry: false }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: 'foo', file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/cache_expose.js000066400000000000000000000024471371176574400177310ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var path = require('path'); var files = { foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = { foo: 'notreal foo', bar: 'notreal bar' }; var cache = {}; cache[files.foo] = { source: sources.foo, deps: { './bar': files.bar } }; cache[files.bar] = { source: sources.bar, deps: {} }; test('cache preserves expose and entry', function (t) { t.plan(1); var p = parser({ cache: cache }); p.write({ id: files.bar, expose: 'bar2', entry: false }); p.end({ id: 'foo', file: files.foo, entry: true, expose: 'foo2' }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: 'foo', expose: 'foo2', entry: true, file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, expose: 'bar2', file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/cache_partial.js000066400000000000000000000021521371176574400200530ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = { foo: 'notreal foo', bar: fs.readFileSync(files.bar, 'utf8') }; var cache = {}; cache[files.foo] = { source: sources.foo, deps: { './bar': files.bar } }; test('uses cache and reads from disk', function (t) { t.plan(1); var p = parser({ cache: cache }); p.end({ id: 'foo', file: files.foo, entry: false }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: 'foo', file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/cache_partial_expose.js000066400000000000000000000052441371176574400214430ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var xtend = require('xtend'); var files = { abc: path.join(__dirname, '/expose/lib/abc.js'), xyz: path.join(__dirname, '/expose/lib/xyz.js'), foo: path.join(__dirname, '/expose/foo.js'), bar: path.join(__dirname, '/expose/bar.js'), main: path.join(__dirname, '/expose/main.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); var cache = {}; cache[files.abc] = { source: sources.abc, deps: {} }; cache[files.xyz] = { source: sources.xyz, deps: {'../foo': files.foo} }; cache[files.foo] = { source: sources.foo, deps: {'./lib/abc': files.abc} }; cache[files.bar] = { source: sources.bar, deps: {xyz: files.xyz} }; cache[files.main] = { source: sources.main, deps: { abc: files.abc, xyz: files.xyz, './bar': files.bar } }; test('preserves expose and entry with partial cache', function(t) { t.plan(1); var partialCache = xtend(cache); delete partialCache[files.bar]; var p = parser({ cache: partialCache }); p.write({ id: 'abc', file: files.abc, expose: 'abc' }); p.write({ id: 'xyz', file: files.xyz, expose: 'xyz' }); p.end({ id: 'main', file: files.main, entry: true }); var rows = []; p.on('data', function (row) { rows.push(row); }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.bar, file: files.bar, source: sources.bar, deps: {xyz: files.xyz} }, { file: files.foo, id: files.foo, source: sources.foo, deps: {'./lib/abc': files.abc} }, { id: 'abc', file: files.abc, source: sources.abc, deps: {}, entry: true, expose: 'abc' }, { id: 'main', file: files.main, source: sources.main, deps: { './bar': files.bar, abc: files.abc, xyz: files.xyz }, entry: true }, { id: 'xyz', file: files.xyz, source: sources.xyz, deps: {'../foo': files.foo}, entry: true, expose: 'xyz' } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/cache_persistent.js000066400000000000000000000067301371176574400206250ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var path = require('path'); var fs = require('fs'); var files = { foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; test('uses persistent cache', function (t) { t.plan(1); var p = parser({ persistentCache: function (file, id, pkg, fallback, cb) { if (file === files.bar) { return fallback(null, cb); } cb(null, { source: 'file at ' + file + '@' + id, package: pkg, deps: { './bar': files.bar } }); } }); p.end({ id: 'foo', file: files.foo, entry: false }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.bar, file: files.bar, source: fs.readFileSync(files.bar, 'utf8'), deps: {} }, { id: 'foo', file: files.foo, source: 'file at ' + files.foo + '@' + files.foo, deps: { './bar': files.bar } } ].sort(cmp)); }); }); test('passes persistent cache error through', function (t) { t.plan(1); var p = parser({ persistentCache: function (file, id, pkg, fallback, cb) { cb(new Error('foo')); } }); p.end({ id: 'foo', file: files.foo, entry: false }); p.on('error', function (err) { t.equals(err.message, 'foo') }); }); test('allow passing of the raw source as string', function (t) { t.plan(1); var p = parser({ persistentCache: function (file, id, pkg, fallback, cb) { fallback(fs.readFileSync(files.bar, 'utf8'), cb); } }); p.end({ id: 'foo', file: files.foo, entry: false }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: 'foo', file: files.foo, source: fs.readFileSync(files.bar, 'utf8'), deps: {} } ].sort(cmp)); }); }); test('send file event with persistent cache', function (t) { t.plan(2); var p = parser({ persistentCache: function (file, id, pkg, fallback, cb) { cb(null, { source: 'file at ' + file + '@' + id, package: pkg, deps: {} }); } }); p.end({ id: 'foo', file: files.foo, entry: false }); p.on('file', function (file, id) { t.same(file, path.resolve(files.foo)); t.same(id, path.resolve(files.foo)); }); }); test('errors of transforms occur in the correct order with a persistent cache', function (t) { t.plan(3); var p = parser({ transform: [ path.join(__dirname, 'cache_persistent', 'error_transform') ], persistentCache: function (file, id, pkg, fallback, cb) { fallback(fs.readFileSync(files.foo, 'utf8'), cb); } }); p.end({ id: 'foo', file: files.foo, entry: false }); var order = 0; p.on('file', function (file, id) { t.same(order, 0); order += 1; }); p.on('error', function (err) { t.same(order, 1); t.same(err.message, 'rawr while parsing file: ' + path.resolve(files.foo)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/cache_persistent/000077500000000000000000000000001371176574400202615ustar00rootroot00000000000000module-deps-6.2.3/test/cache_persistent/error_transform.js000066400000000000000000000002531371176574400240430ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (chunk, enc, callback) { callback(new Error('rawr')); }); }; module-deps-6.2.3/test/cycle.js000066400000000000000000000010561371176574400163750ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var concat = require('concat-stream'); var path = require('path'); test('cycle', function (t) { t.plan(1); var p = mdeps(); p.end(path.join(__dirname, '/cycle/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack).pipe(concat(function (src) { Function('console', src.toString('utf8'))({ log: function (msg) { t.equal(msg, 333) } }); })); }); module-deps-6.2.3/test/cycle/000077500000000000000000000000001371176574400160355ustar00rootroot00000000000000module-deps-6.2.3/test/cycle/bar.js000066400000000000000000000001261371176574400171360ustar00rootroot00000000000000var foo = require('./foo.js'); module.exports = function (n) { return foo.p(n, 1) }; module-deps-6.2.3/test/cycle/foo.js000066400000000000000000000002011371176574400171470ustar00rootroot00000000000000var bar = require('./bar.js'); exports.ooo = function (n) { return n * bar(110) }; exports.p = function (a, b) { return a + b } module-deps-6.2.3/test/cycle/main.js000066400000000000000000000001351371176574400173160ustar00rootroot00000000000000var foo = require('./foo.js'); var bar = require('./bar.js'); console.log(foo.ooo(bar(2))); module-deps-6.2.3/test/deps.js000066400000000000000000000024151371176574400162310ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/files/main.js'), foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('deps', function (t) { t.plan(1); var p = parser(); p.end({ file: files.main, entry: true }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './foo': files.foo } }, { id: files.foo, file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/detect.js000066400000000000000000000015471371176574400165530ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); test('detect', function (t) { t.plan(1); var p = parser({ detect: function (source) { var rx = /require\(["'](.*?)["']\)/g; var m, deps = []; while (m = rx.exec(source)) { deps.push(m[1]); } return deps; } }); p.end(path.join(__dirname, '/files/main.js')); p.on('error', t.fail.bind(t)); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('console', src)({ log: function (s) { t.equal(s, 'main: 1055') } }); }); }); module-deps-6.2.3/test/dotdot.js000066400000000000000000000010231371176574400165650ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var through = require('through2'); var path = require('path'); test('dotdot', function (t) { var expected = [ path.join(__dirname, '/dotdot/index.js'), path.join(__dirname, '/dotdot/abc/index.js') ]; t.plan(expected.length); var d = mdeps(); d.end(path.join(__dirname, '/dotdot/abc/index.js')); d.pipe(through.obj(function (row, enc, next) { t.deepEqual(row.file, expected.shift()); next(); })); }); module-deps-6.2.3/test/dotdot/000077500000000000000000000000001371176574400162335ustar00rootroot00000000000000module-deps-6.2.3/test/dotdot/abc/000077500000000000000000000000001371176574400167605ustar00rootroot00000000000000module-deps-6.2.3/test/dotdot/abc/index.js000066400000000000000000000000471371176574400204260ustar00rootroot00000000000000var x = require('..'); console.log(x); module-deps-6.2.3/test/dotdot/index.js000066400000000000000000000000341371176574400176750ustar00rootroot00000000000000module.exports = 'whatever' module-deps-6.2.3/test/expose.js000066400000000000000000000020371371176574400166010ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('single id export', function (t) { t.plan(1); var p = parser(); p.end({ id: 'foo', file: files.foo, entry: false }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: 'foo', file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/expose/000077500000000000000000000000001371176574400162415ustar00rootroot00000000000000module-deps-6.2.3/test/expose/bar.js000066400000000000000000000000201371176574400173330ustar00rootroot00000000000000require('xyz'); module-deps-6.2.3/test/expose/foo.js000066400000000000000000000000261371176574400173600ustar00rootroot00000000000000require('./lib/abc'); module-deps-6.2.3/test/expose/lib/000077500000000000000000000000001371176574400170075ustar00rootroot00000000000000module-deps-6.2.3/test/expose/lib/abc.js000066400000000000000000000000241371176574400200660ustar00rootroot00000000000000console.log('abc'); module-deps-6.2.3/test/expose/lib/xyz.js000066400000000000000000000000471371176574400202000ustar00rootroot00000000000000require('../foo'); console.log('xyz'); module-deps-6.2.3/test/expose/main.js000066400000000000000000000000621371176574400175210ustar00rootroot00000000000000require('abc'); require('xyz'); require('./bar'); module-deps-6.2.3/test/file_cache.js000066400000000000000000000027401371176574400173410ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var path = require('path'); var through = require('through2'); var files = { foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = { foo: 'require("./bar"); var tongs;', bar: 'notreal tongs' }; var fileCache = {}; fileCache[files.foo] = sources.foo; fileCache[files.bar] = sources.bar; var specialReplace = function(input) { return input.replace(/tongs/g, 'tangs'); }; test('uses file cache', function (t) { t.plan(1); var p = mdeps({ fileCache: fileCache, transform: function (file) { return through(function (buf, enc, next) { this.push(specialReplace(String(buf))); next(); }); }, transformKey: [ 'browserify', 'transform' ] }); p.end({ id: 'foo', file: files.foo, entry: false }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: 'foo', file: files.foo, source: specialReplace(sources.foo), deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: specialReplace(sources.bar), deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/files/000077500000000000000000000000001371176574400160405ustar00rootroot00000000000000module-deps-6.2.3/test/files/bar.js000066400000000000000000000000671371176574400171450ustar00rootroot00000000000000module.exports = function (n) { return n * 100; }; module-deps-6.2.3/test/files/extra.js000066400000000000000000000000251371176574400175160ustar00rootroot00000000000000module.exports = 555 module-deps-6.2.3/test/files/filterable.js000066400000000000000000000003221371176574400205040ustar00rootroot00000000000000 module.exports = { events: require('events'), fs : require('fs'), net : require('net'), http : require('http'), https : require('https'), dgram : require('dgram'), dns : require('dns') } module-deps-6.2.3/test/files/foo.js000066400000000000000000000001351371176574400171600ustar00rootroot00000000000000var bar = require('./bar'); module.exports = function (n) { return n * 111 + bar(n); }; module-deps-6.2.3/test/files/main.js000066400000000000000000000000741371176574400173230ustar00rootroot00000000000000var foo = require('./foo'); console.log('main: ' + foo(5)); module-deps-6.2.3/test/files/pkg_filter/000077500000000000000000000000001371176574400201665ustar00rootroot00000000000000module-deps-6.2.3/test/files/pkg_filter/one.js000066400000000000000000000000231371176574400213000ustar00rootroot00000000000000module.exports = 1 module-deps-6.2.3/test/files/pkg_filter/package.json000066400000000000000000000000271371176574400224530ustar00rootroot00000000000000{ "main": "one.js" } module-deps-6.2.3/test/files/pkg_filter/test.js000066400000000000000000000000331371176574400214770ustar00rootroot00000000000000t.equal(require('./'), 2); module-deps-6.2.3/test/files/pkg_filter/two.js000066400000000000000000000000231371176574400213300ustar00rootroot00000000000000module.exports = 2 module-deps-6.2.3/test/files/quotes/000077500000000000000000000000001371176574400173605ustar00rootroot00000000000000module-deps-6.2.3/test/files/quotes/bar.js000066400000000000000000000000341371176574400204570ustar00rootroot00000000000000module.exports = 'success'; module-deps-6.2.3/test/files/quotes/baz.js000066400000000000000000000000341371176574400204670ustar00rootroot00000000000000module.exports = 'success'; module-deps-6.2.3/test/files/quotes/foo.js000066400000000000000000000000341371176574400204760ustar00rootroot00000000000000module.exports = 'success'; module-deps-6.2.3/test/files/quotes/main.js000066400000000000000000000001241371176574400206370ustar00rootroot00000000000000var foo = require('./foo'); var bar = require("./bar"); var baz = require(`./baz`); module-deps-6.2.3/test/files/resolve/000077500000000000000000000000001371176574400175175ustar00rootroot00000000000000module-deps-6.2.3/test/files/resolve/bar/000077500000000000000000000000001371176574400202635ustar00rootroot00000000000000module-deps-6.2.3/test/files/resolve/bar/bar.js000066400000000000000000000001221371176574400213600ustar00rootroot00000000000000var bar2 = require('./bar2'); module.exports = function () { return 'bar'; };module-deps-6.2.3/test/files/resolve/bar/bar2.js000066400000000000000000000000641371176574400214470ustar00rootroot00000000000000module.exports = function () { return 'bar2'; };module-deps-6.2.3/test/files/resolve/foo/000077500000000000000000000000001371176574400203025ustar00rootroot00000000000000module-deps-6.2.3/test/files/resolve/foo/baz/000077500000000000000000000000001371176574400210565ustar00rootroot00000000000000module-deps-6.2.3/test/files/resolve/foo/baz/baz.js000066400000000000000000000000631371176574400221670ustar00rootroot00000000000000module.exports = function () { return 'baz'; };module-deps-6.2.3/test/files/resolve/foo/foo.js000066400000000000000000000001731371176574400214240ustar00rootroot00000000000000var bar = require('../bar/bar.js'); var baz = require('./baz/baz.js'); module.exports = function () { return 'foo'; };module-deps-6.2.3/test/files/syntax_error.js000066400000000000000000000000451371176574400211340ustar00rootroot00000000000000const a = require('a'); const a = 0; module-deps-6.2.3/test/files/tr_2dep_module/000077500000000000000000000000001371176574400207445ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/f.js000066400000000000000000000000611371176574400215240ustar00rootroot00000000000000module.exports = function (x) { return x + BBB } module-deps-6.2.3/test/files/tr_2dep_module/main.js000066400000000000000000000003311371176574400222230ustar00rootroot00000000000000var f = require('./f.js'); var m = require('m'); var g = require('g'); t.equal(m(f(AAA)), 777, 'transformation scope'); t.equal(g(3), 333, 'sub-transformation applied'); t.equal(typeof GGG, 'undefined', 'GGG leak'); module-deps-6.2.3/test/files/tr_2dep_module/node_modules/000077500000000000000000000000001371176574400234215ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/g/000077500000000000000000000000001371176574400236475ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/g/index.js000066400000000000000000000000611371176574400253110ustar00rootroot00000000000000module.exports = function (x) { return x * GGG } module-deps-6.2.3/test/files/tr_2dep_module/node_modules/g/node_modules/000077500000000000000000000000001371176574400263245ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/g/node_modules/insert-ggg/000077500000000000000000000000001371176574400303725ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/g/node_modules/insert-ggg/index.js000066400000000000000000000003101371176574400320310ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '111')); next(); }); }; module-deps-6.2.3/test/files/tr_2dep_module/node_modules/g/package.json000066400000000000000000000001161371176574400261330ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "insert-ggg" } } module-deps-6.2.3/test/files/tr_2dep_module/node_modules/insert-aaa/000077500000000000000000000000001371176574400254455ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/insert-aaa/index.js000066400000000000000000000003061371176574400271110ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/AAA/g, '5')); next(); }); }; module-deps-6.2.3/test/files/tr_2dep_module/node_modules/insert-bbb/000077500000000000000000000000001371176574400254505ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/insert-bbb/index.js000066400000000000000000000003071371176574400271150ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/BBB/g, '50')); next(); }); }; module-deps-6.2.3/test/files/tr_2dep_module/node_modules/m/000077500000000000000000000000001371176574400236555ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/m/index.js000066400000000000000000000001301371176574400253140ustar00rootroot00000000000000var AAA = 200, BBB = 300; module.exports = function (x) { return AAA + BBB + MMM + x } module-deps-6.2.3/test/files/tr_2dep_module/node_modules/m/node_modules/000077500000000000000000000000001371176574400263325ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/m/node_modules/insert-mmm/000077500000000000000000000000001371176574400304225ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_2dep_module/node_modules/m/node_modules/insert-mmm/index.js000066400000000000000000000003101371176574400320610ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/MMM/g, '222')); next(); }); }; module-deps-6.2.3/test/files/tr_2dep_module/node_modules/m/package.json000066400000000000000000000001161371176574400261410ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "insert-mmm" } } module-deps-6.2.3/test/files/tr_global/000077500000000000000000000000001371176574400200055ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/main.js000066400000000000000000000000601371176574400212630ustar00rootroot00000000000000console.log(AAA + BBB + CCC + DDD + EEE + FFF); module-deps-6.2.3/test/files/tr_global/node_modules/000077500000000000000000000000001371176574400224625ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/node_modules/tr-a/000077500000000000000000000000001371176574400233255ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/node_modules/tr-a/index.js000066400000000000000000000003111371176574400247650ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/AAA/g, '1')); next(); }); }; module-deps-6.2.3/test/files/tr_global/node_modules/tr-b/000077500000000000000000000000001371176574400233265ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/node_modules/tr-b/index.js000066400000000000000000000003121371176574400247670ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/BBB/g, '10')); next(); }); }; module-deps-6.2.3/test/files/tr_global/node_modules/tr-c/000077500000000000000000000000001371176574400233275ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/node_modules/tr-c/index.js000066400000000000000000000003131371176574400247710ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/CCC/g, '100')); next(); }); }; module-deps-6.2.3/test/files/tr_global/node_modules/tr-d/000077500000000000000000000000001371176574400233305ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/node_modules/tr-d/index.js000066400000000000000000000003141371176574400247730ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/DDD/g, '1000')); next(); }); }; module-deps-6.2.3/test/files/tr_global/node_modules/tr-e/000077500000000000000000000000001371176574400233315ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/node_modules/tr-e/index.js000066400000000000000000000003151371176574400247750ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/EEE/g, '10000')); next(); }); }; module-deps-6.2.3/test/files/tr_global/node_modules/tr-f/000077500000000000000000000000001371176574400233325ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_global/node_modules/tr-f/index.js000066400000000000000000000003161371176574400247770ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/FFF/g, '100000')); next(); }); }; module-deps-6.2.3/test/files/tr_global/package.json000066400000000000000000000000761371176574400222760ustar00rootroot00000000000000{ "browserify": { "transform": [ "tr-a", "tr-b" ] } } module-deps-6.2.3/test/files/tr_module/000077500000000000000000000000001371176574400200325ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/f.js000066400000000000000000000000611371176574400206120ustar00rootroot00000000000000module.exports = function (x) { return x + BBB } module-deps-6.2.3/test/files/tr_module/index.js000066400000000000000000000003101371176574400214710ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '123')); next(); }); }; module-deps-6.2.3/test/files/tr_module/main.js000066400000000000000000000003631371176574400213160ustar00rootroot00000000000000var f = require('./f.js'); var m = require('m'); var g = require('g'); t.equal(m(f(AAA)), 555, 'transformation scope'); t.equal(g(3), 333, 'sub-transformation applied'); t.equal(typeof GGG, 'undefined', 'GGG leak'); t.equal(XXX, 123, 'XXX'); module-deps-6.2.3/test/files/tr_module/node_modules/000077500000000000000000000000001371176574400225075ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/node_modules/g/000077500000000000000000000000001371176574400227355ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/node_modules/g/index.js000066400000000000000000000001011371176574400243720ustar00rootroot00000000000000module.exports = function (x) { return x * (GGG - 3 * XXX + 9) } module-deps-6.2.3/test/files/tr_module/node_modules/g/node_modules/000077500000000000000000000000001371176574400254125ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/node_modules/g/node_modules/insert-ggg/000077500000000000000000000000001371176574400274605ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/node_modules/g/node_modules/insert-ggg/index.js000066400000000000000000000003101371176574400311170ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '111')); next(); }); }; module-deps-6.2.3/test/files/tr_module/node_modules/g/package.json000066400000000000000000000001341371176574400252210ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": [ "insert-ggg", "./x.js" ] } } module-deps-6.2.3/test/files/tr_module/node_modules/g/x.js000066400000000000000000000003061371176574400235410ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '3')); next(); }); }; module-deps-6.2.3/test/files/tr_module/node_modules/insert-aaa/000077500000000000000000000000001371176574400245335ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/node_modules/insert-aaa/index.js000066400000000000000000000003061371176574400261770ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/AAA/g, '5')); next(); }); }; module-deps-6.2.3/test/files/tr_module/node_modules/insert-bbb/000077500000000000000000000000001371176574400245365ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/node_modules/insert-bbb/index.js000066400000000000000000000003071371176574400262030ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/BBB/g, '50')); next(); }); }; module-deps-6.2.3/test/files/tr_module/node_modules/m/000077500000000000000000000000001371176574400227435ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_module/node_modules/m/index.js000066400000000000000000000001221371176574400244030ustar00rootroot00000000000000var AAA = 200, BBB = 300; module.exports = function (x) { return AAA + BBB + x } module-deps-6.2.3/test/files/tr_module/package.json000066400000000000000000000000721371176574400223170ustar00rootroot00000000000000{ "browserify": { "transform": [ "./xxx.js" ] } } module-deps-6.2.3/test/files/tr_module/xxx.js000066400000000000000000000003101371176574400212110ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '123')); next(); }); }; module-deps-6.2.3/test/files/tr_no_entry/000077500000000000000000000000001371176574400204025ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_no_entry/main.js000066400000000000000000000000211371176574400216550ustar00rootroot00000000000000console.log(AAA) module-deps-6.2.3/test/files/tr_rel/000077500000000000000000000000001371176574400173275ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_rel/package.json000066400000000000000000000000721371176574400216140ustar00rootroot00000000000000{ "browserify": { "transform": [ "./xxx.js" ] } } module-deps-6.2.3/test/files/tr_rel/subdir/000077500000000000000000000000001371176574400206175ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_rel/subdir/main.js000066400000000000000000000000251371176574400220760ustar00rootroot00000000000000console.log(XXX * 3) module-deps-6.2.3/test/files/tr_rel/xxx.js000066400000000000000000000003101371176574400205060ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '111')); next(); }); }; module-deps-6.2.3/test/files/tr_sh/000077500000000000000000000000001371176574400171575ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_sh/f.js000066400000000000000000000000611371176574400177370ustar00rootroot00000000000000module.exports = function (x) { return x + BBB } module-deps-6.2.3/test/files/tr_sh/main.js000066400000000000000000000003311371176574400204360ustar00rootroot00000000000000var f = require('./f.js'); var m = require('m'); var g = require('g'); t.equal(m(f(AAA)), 555, 'transformation scope'); t.equal(g(3), 333, 'sub-transformation applied'); t.equal(typeof GGG, 'undefined', 'GGG leak'); module-deps-6.2.3/test/files/tr_sh/node_modules/000077500000000000000000000000001371176574400216345ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_sh/node_modules/g/000077500000000000000000000000001371176574400220625ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_sh/node_modules/g/index.js000066400000000000000000000000611371176574400235240ustar00rootroot00000000000000module.exports = function (x) { return x * GGG } module-deps-6.2.3/test/files/tr_sh/node_modules/g/package.json000066400000000000000000000001151371176574400243450ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "./tr_g.js" } } module-deps-6.2.3/test/files/tr_sh/node_modules/g/tr_g.js000066400000000000000000000003071371176574400233530ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '111')); next(); }); }; module-deps-6.2.3/test/files/tr_sh/node_modules/m/000077500000000000000000000000001371176574400220705ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_sh/node_modules/m/index.js000066400000000000000000000001221371176574400235300ustar00rootroot00000000000000var AAA = 200, BBB = 300; module.exports = function (x) { return AAA + BBB + x } module-deps-6.2.3/test/files/tr_sh/tr_a.js000066400000000000000000000003051371176574400204400ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/AAA/g, '5')); next(); }); }; module-deps-6.2.3/test/files/tr_sh/tr_b.js000066400000000000000000000003061371176574400204420ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/BBB/g, '50')); next(); }); }; module-deps-6.2.3/test/files/tr_whole_package/000077500000000000000000000000001371176574400213365ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_whole_package/f.js000066400000000000000000000001241371176574400221160ustar00rootroot00000000000000var calc = require('algo').calc; module.exports = function (x) { return calc(x); } module-deps-6.2.3/test/files/tr_whole_package/main.js000066400000000000000000000001101371176574400226100ustar00rootroot00000000000000var f = require('./f.js'); t.equal(f(14), 11, 'transformation scope'); module-deps-6.2.3/test/files/tr_whole_package/node_modules/000077500000000000000000000000001371176574400240135ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/000077500000000000000000000000001371176574400247355ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/index.js000066400000000000000000000001551371176574400264030ustar00rootroot00000000000000var decrement = require('./lib/decrement'); exports.calc = function (x) { return decrement(x) - GGG - GGG } module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/lib/000077500000000000000000000000001371176574400255035ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/lib/decrement.js000066400000000000000000000000611371176574400300040ustar00rootroot00000000000000module.exports = function (x) { return x - GGG } module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/node_modules/000077500000000000000000000000001371176574400274125ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/node_modules/insert-ggg/000077500000000000000000000000001371176574400314605ustar00rootroot00000000000000module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/node_modules/insert-ggg/index.js000066400000000000000000000003061371176574400331240ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '1')); next(); }); }; module-deps-6.2.3/test/files/tr_whole_package/node_modules/algo/package.json000066400000000000000000000001161371176574400272210ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "insert-ggg" } } module-deps-6.2.3/test/files/transformdeps.js000066400000000000000000000000431371176574400212620ustar00rootroot00000000000000// dependencies added by transform module-deps-6.2.3/test/files/unicode/000077500000000000000000000000001371176574400174665ustar00rootroot00000000000000module-deps-6.2.3/test/files/unicode/bar.js000066400000000000000000000000711371176574400205660ustar00rootroot00000000000000module.exports = function (ñ) { return ñ * 100; }; module-deps-6.2.3/test/files/unicode/foo.js000066400000000000000000000001351371176574400206060ustar00rootroot00000000000000var é = require('./bar'); module.exports = function (ñ) { return ñ * 111 + é(n); }; module-deps-6.2.3/test/files/unicode/main.js000066400000000000000000000000731371176574400207500ustar00rootroot00000000000000var π = require('./foo'); console.log('main: ' + foo(5)); module-deps-6.2.3/test/files/xyz.js000066400000000000000000000000731371176574400172300ustar00rootroot00000000000000var foo = require('./foo'); console.log('xyz: ' + foo(6)); module-deps-6.2.3/test/filter.js000066400000000000000000000015111371176574400165570ustar00rootroot00000000000000var test = require('tap').test; var path = require('path') var mdeps = require('../') var core = ['events', 'util', 'dns', 'dgram', 'http', 'https', 'net', 'fs'] var collect = [] var entry = path.join(__dirname, 'files', 'filterable.js') test('can filter core deps', function (t) { var p = mdeps({ filter: function (e) { return !~core.indexOf(e) } }) p.on('data', function (d) { collect.push(d) t.equal(d.id, entry) t.deepEqual(d.deps, { events: false, fs: false, net: false, http: false, https: false, dgram: false, dns: false }) t.equal(d.entry, true) }); p.on('end', function () { t.equal(collect.length, 1) t.end() }); p.end(entry); }) module-deps-6.2.3/test/ignore_missing.js000066400000000000000000000030601371176574400203070ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/ignore_missing/main.js'), other: path.join(__dirname, '/ignore_missing/other.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('ignoreMissing', function (t) { t.plan(1); var p = parser({ignoreMissing: true}); p.end({file: files.main, entry: true}); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './other': files.other } }, { id: files.other, file: files.other, source: sources.other, deps: { 'missingModule': undefined } } ].sort(cmp)); }); }); test('ignoreMissing off', function (t) { t.plan(1); var p = parser(); p.end({file: files.main, entry: true}); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('error', function (err) { t.match( String(err), /Cannot find module 'missingModule'/ ); }); p.on('end', function () { t.fail('should have errored'); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/ignore_missing/000077500000000000000000000000001371176574400177525ustar00rootroot00000000000000module-deps-6.2.3/test/ignore_missing/main.js000066400000000000000000000000241371176574400212300ustar00rootroot00000000000000require('./other'); module-deps-6.2.3/test/ignore_missing/other.js000066400000000000000000000000321371176574400214240ustar00rootroot00000000000000require('missingModule'); module-deps-6.2.3/test/ignore_missing_cache.js000066400000000000000000000025501371176574400214350ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/ignore_missing/main.js'), other: path.join(__dirname, '/ignore_missing/other.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); var cache = {}; cache[files.main] = { source: sources.main, deps: { './other': files.other } }; cache[files.other] = { source: sources.other, deps: { 'missingModule': undefined } }; test('ignoreMissing with cache', function (t) { t.plan(1); var p = parser({ cache: cache, ignoreMissing: true }); p.end({file: files.main, entry: true}); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './other': files.other } }, { id: files.other, file: files.other, source: sources.other, deps: { 'missingModule': undefined } } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/invalid_pkg.js000066400000000000000000000006141371176574400175640ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var path = require('path'); var fs = require('fs'); test('invalid pkg', function (t) { var d = mdeps(); d.on('package', function (pkg_) { // console.error({pkg_}); }); d.end(path.join(__dirname, '/invalid_pkg/file.js')); d.on('data', function () {}); d.on('end', function () { t.end(); }); }); module-deps-6.2.3/test/invalid_pkg/000077500000000000000000000000001371176574400172255ustar00rootroot00000000000000module-deps-6.2.3/test/invalid_pkg/file.js000066400000000000000000000000161371176574400204770ustar00rootroot00000000000000require('./') module-deps-6.2.3/test/invalid_pkg/index.js000066400000000000000000000000111371176574400206620ustar00rootroot00000000000000T.pass() module-deps-6.2.3/test/invalid_pkg/package.json000066400000000000000000000000201371176574400215030ustar00rootroot00000000000000"just a string" module-deps-6.2.3/test/node_modules/000077500000000000000000000000001371176574400174135ustar00rootroot00000000000000module-deps-6.2.3/test/node_modules/insert-www/000077500000000000000000000000001371176574400215415ustar00rootroot00000000000000module-deps-6.2.3/test/node_modules/insert-www/index.js000066400000000000000000000003251371176574400232060ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/WWW/g, '"world wide wow"')); next(); }); }; module-deps-6.2.3/test/noparse.js000066400000000000000000000021511371176574400167420ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/files/main.js'), foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('noParse', function (t) { t.plan(1); var p = parser({ noParse: [ files.foo ] }); p.end(files.main); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.deepEqual(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './foo': files.foo } }, { id: files.foo, file: files.foo, source: sources.foo, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/noparse_row.js000066400000000000000000000020031371176574400176250ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var concat = require('concat-stream'); var path = require('path'); var files = { main: path.join(__dirname, '/files/main.js'), foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('noParse row', function (t) { t.plan(1); var p = parser(); p.end({ file: files.main, noparse: true }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.deepEqual(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, noparse: true, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/pkg.js000066400000000000000000000010011371176574400160450ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var path = require('path'); var fs = require('fs'); var dirname = path.join(__dirname, '/pkg'); test('pkg', function (t) { t.plan(4); var d = mdeps(); d.on('package', function (pkg_) { var pkg = JSON.parse(fs.readFileSync(dirname + pkg_.dir + '/package.json')); pkg.__dirname = path.join(dirname, pkg_.dir); t.deepEqual(pkg_, pkg); }); d.end(path.join(__dirname, '/pkg/main.js')); d.resume(); }); module-deps-6.2.3/test/pkg/000077500000000000000000000000001371176574400155175ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/main.js000066400000000000000000000000421371176574400167750ustar00rootroot00000000000000require('pkga'); require('pkgb'); module-deps-6.2.3/test/pkg/node_modules/000077500000000000000000000000001371176574400201745ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/node_modules/pkga/000077500000000000000000000000001371176574400211165ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/node_modules/pkga/main.js000066400000000000000000000000001371176574400223660ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/node_modules/pkga/package.json000066400000000000000000000000671371176574400234070ustar00rootroot00000000000000{ "dir": "/node_modules/pkga", "main": "main.js" } module-deps-6.2.3/test/pkg/node_modules/pkgb/000077500000000000000000000000001371176574400211175ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/node_modules/pkgb/main.js000066400000000000000000000000201371176574400223710ustar00rootroot00000000000000require('pkgc');module-deps-6.2.3/test/pkg/node_modules/pkgb/node_modules/000077500000000000000000000000001371176574400235745ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/node_modules/pkgb/node_modules/pkgc/000077500000000000000000000000001371176574400245205ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/node_modules/pkgb/node_modules/pkgc/main.js000066400000000000000000000000001371176574400257700ustar00rootroot00000000000000module-deps-6.2.3/test/pkg/node_modules/pkgb/node_modules/pkgc/package.json000066400000000000000000000001111371176574400267770ustar00rootroot00000000000000{ "dir": "/node_modules/pkgb/node_modules/pkgc", "main": "main.js" } module-deps-6.2.3/test/pkg/node_modules/pkgb/package.json000066400000000000000000000000671371176574400234100ustar00rootroot00000000000000{ "dir": "/node_modules/pkgb", "main": "main.js" } module-deps-6.2.3/test/pkg/package.json000066400000000000000000000000461371176574400200050ustar00rootroot00000000000000{ "dir": "", "main": "index.js" } module-deps-6.2.3/test/pkg_filter.js000066400000000000000000000013251371176574400174230ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var concat = require('concat-stream'); var path = require('path'); test('pkg filter', function (t) { t.plan(3); var p = mdeps({ packageFilter: function (pkg) { if (pkg.name === undefined) { t.equal(pkg.main, 'one.js'); pkg.main = 'two.js' } return pkg; } }); p.end(path.join(__dirname, '/files/pkg_filter/test.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); pack.pipe(concat(function (src) { Function('t', src)(t); })); }); module-deps-6.2.3/test/quotes.js000066400000000000000000000020551371176574400166160ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/files/quotes/main.js'), foo: path.join(__dirname, '/files/quotes/foo.js'), bar: path.join(__dirname, '/files/quotes/bar.js'), baz: path.join(__dirname, '/files/quotes/baz.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('different quote styles', function (t) { t.plan(1); var p = parser(); p.end(files.main); var main = null p.on('data', function (row) { if (row.id === files.main) { main = row } }); p.on('end', function () { t.same(main, { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './foo': files.foo, './bar': files.bar, './baz': files.baz } }); }); }); module-deps-6.2.3/test/resolve.js000066400000000000000000000053311371176574400167550ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var mdeps = require('../'); var test = require('tap').test; var nodeResolve = require('resolve'); var browserResolve = require('browser-resolve'); var missing = path.join(__dirname, '/missing'); var files = { foo: path.join(__dirname, '/files/resolve/foo/foo.js'), bar: path.join(__dirname, '/files/resolve/bar/bar.js'), bar2: path.join(__dirname, '/files/resolve/bar/bar2.js'), baz: path.join(__dirname, '/files/resolve/foo/baz/baz.js') }; var sources = Object.keys(files) .reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); var expectedRows = [ { "deps": {}, "file": files.baz, "id": files.baz, "source": sources.baz }, { "deps": {}, "file": files.bar2, "id": files.bar2, "source": sources.bar2 }, { "deps": { "./bar2": files.bar2 }, "file": files.bar, "id": files.bar, "source": sources.bar }, { "deps": { "../bar/bar.js": files.bar, "./baz/baz.js": files.baz }, "entry": true, "file": files.foo, "id": "foo", "source": sources.foo } ]; test('browser resolve - missing', function (t) { t.plan(1); var d = mdeps({resolve: browserResolve}); d.end({id: 'missing', file: missing, entry: true}); d.on('end', function () { t.fail('errored'); }); d.on('error', function (err) { t.match( String(err), /Cannot find module .*/ ); }); }); test('node resolve - missing', function (t) { t.plan(1); var d = mdeps({resolve: nodeResolve}); d.end({id: 'missing', file: missing, entry: true}); d.on('end', function () { t.fail('errored'); }); d.on('error', function (err) { t.match( String(err), /Cannot find module .*/ ); }); }); test('browser resolve', function (t) { t.plan(1); var d = mdeps({resolve: browserResolve}); d.end({id: 'foo', file: files.foo, entry: true}); var rows = []; d.on('data', function (row) {rows.push(row)}); d.on('end', function () { t.same(rows, expectedRows); }); d.on('error', function () { t.fail('errored'); }); }); test('node resolve', function (t) { t.plan(1); var d = mdeps({resolve: nodeResolve}); d.end({id: 'foo', file: files.foo, entry: true}); var rows = []; d.on('data', function (row) {rows.push(row)}); d.on('end', function () { t.same(rows, expectedRows); }); d.on('error', function () { t.fail('errored'); }); });module-deps-6.2.3/test/row_expose.js000066400000000000000000000014301371176574400174640ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var through = require('through2'); var path = require('path'); // Test that p.options.expose is defined and that the row is properly exposed // (resolved to the absolute pathname corresponding to the `file` value passed // in the row, and set in opts.expose). test('row is exposed', function (t) { t.plan(1); var common_path = path.join(__dirname, '/files/main'); var opts = { expose: {} }; var p = parser(opts); // Note pathname without extension. p.end({ file: common_path, expose: "whatever" }); p.on('error', t.fail.bind(t)); p.pipe(through.obj()); p.on('end', function () { // Note pathname with extension. t.equal(opts.expose.whatever, common_path + '.js'); }); }); module-deps-6.2.3/test/row_expose_name_is_file_transform.js000066400000000000000000000021031371176574400242470ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var through = require('through2'); var path = require('path'); // test that (non global) transforms are applied to an exposed module, where in the // exposed name is identical to the file path. test('row is exposed with a name equal to the path, and transformed', function (t) { t.plan(2); var exposed_path = path.join(__dirname, '/files/main.js'); var found_exposed_path = false; var opts = { expose: {}, transform: function(file) { if (file === exposed_path) { found_exposed_path = true; } return through(); } }; var p = parser(opts); p.end({ file: exposed_path, expose: exposed_path }); p.on('error', t.fail.bind(t)); p.pipe(through.obj()); p.on('end', function () { t.equal(opts.expose[exposed_path], exposed_path); t.ok(found_exposed_path); }); }); module-deps-6.2.3/test/row_expose_transform.js000066400000000000000000000015311371176574400215610ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var through = require('through2'); var path = require('path'); // test that (non global) transforms are applied to an exposed module test('row is exposed and transformed', function (t) { t.plan(2); var exposed_path = path.join(__dirname, '/files/main.js'); var found_exposed_path = false; var opts = { expose: {}, transform: function(file) { if (file === exposed_path) { found_exposed_path = true; } return through(); } }; var p = parser(opts); p.end({ file: exposed_path, expose: "whatever" }); p.on('error', t.fail.bind(t)); p.pipe(through.obj()); p.on('end', function () { t.equal(opts.expose.whatever, exposed_path); t.ok(found_exposed_path); }); }); module-deps-6.2.3/test/source.js000066400000000000000000000032061371176574400165750ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/files/main.js'), foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js'), extra: path.join(__dirname, '/files/extra.js') }; var sources = { foo: fs.readFileSync(files.foo, 'utf8'), bar: fs.readFileSync(files.bar, 'utf8'), extra: fs.readFileSync(files.extra, 'utf8'), main: "console.log(require('./foo')(5)); require('./extra.js')" }; test('source', function (t) { t.plan(1); var p = parser(); p.end({ file: files.main, source: sources.main, entry: true }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './foo': files.foo, './extra.js': files.extra } }, { id: files.foo, file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} }, { id: files.extra, file: files.extra, source: sources.extra, deps: {} }, ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/syntax.js000066400000000000000000000014171371176574400166250ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var through = require('through2'); var path = require('path'); test('syntax error', function (t) { t.plan(2); var input = path.join(__dirname, '/files/syntax_error.js'); // ensure transformDeps functionality does not break when parse errors happen // see https://github.com/browserify/module-deps/commit/9fe46d5#commitcomment-28273437 var p = mdeps({ transform: function () { return through(); } }); p.on('file', function (file) { t.equal(file, input, 'should emit a file event even if there was an error'); }); p.on('error', function (err) { t.ok(err); }); p.end(input); }); module-deps-6.2.3/test/tr_2dep_module.js000066400000000000000000000012001371176574400201710ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); test('transform', function (t) { t.plan(3); var p = mdeps({ transform: [ 'insert-aaa', 'insert-bbb' ], transformKey: [ 'browserify', 'transform' ] }); p.end(path.join(__dirname, '/files/tr_2dep_module/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('t', src)(t); }); }); module-deps-6.2.3/test/tr_deps.js000066400000000000000000000032771371176574400167450ustar00rootroot00000000000000var parser = require('../'); var through = require('through2'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { transformdeps: path.join(__dirname, '/files/transformdeps.js'), foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('deps added by transforms', function (t) { t.plan(1); var p = parser(); p.write({ transform: transform, options: {} }); p.end({ file: files.transformdeps, entry: true }); function transform (file) { if (file === files.transformdeps) return through(function(chunk, enc, cb) { cb(null, chunk); }, function (cb) { this.emit('dep', './foo'); cb(); }); return through(); } var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.transformdeps, file: files.transformdeps, source: sources.transformdeps, entry: true, deps: { './foo': files.foo } }, { id: files.foo, file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/tr_err.js000066400000000000000000000011141371176574400165660ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var through = require('through2'); var path = require('path'); test('transform', function (t) { t.plan(1); var p = mdeps({ transform: function (file) { return through(function () { this.emit('error', new Error('rawr')); }); } }); p.on('error', function (err) { t.ok(/tr_sh[\\\/]main\.js/.test(err)); }); p.end(path.join(__dirname, '/files/tr_sh/main.js')); }); module-deps-6.2.3/test/tr_flags.js000066400000000000000000000024021371176574400170730ustar00rootroot00000000000000var through = require('through2'); var mdeps = require('../'); var test = require('tap').test; test('--debug passed to transforms', function (t) { var empty = require.resolve('./tr_flags/empty.js'); t.plan(5); var p [true, false].forEach(function(debug) { p = mdeps({ debug: debug, transform: function (file, opts) { t.equal(opts._flags.debug, debug, 'debug: ' + debug); return through(); } }) p.on('error', function (err) { return t.fail(err.message) }) p.end(empty); p = mdeps({ debug: debug }) p.write({ transform: function (file, opts) { t.equal(opts._flags.debug, debug, 'debug: ' + debug); return through(); }, options: {} }) p.on('error', function (err) { return t.fail(err.message) }) p.end(empty); }); p = mdeps({ debug: true }) p.write({ transform: function (file, opts) { t.equal(opts._flags, Infinity, 'transform arguments are preserved'); return through(); }, options: { _flags: Infinity } }) p.on('error', function (err) { return t.fail(err.message) }) p.end(empty); }); module-deps-6.2.3/test/tr_flags/000077500000000000000000000000001371176574400165375ustar00rootroot00000000000000module-deps-6.2.3/test/tr_flags/empty.js000066400000000000000000000000001371176574400202210ustar00rootroot00000000000000module-deps-6.2.3/test/tr_fn.js000066400000000000000000000016041371176574400164050ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var through = require('through2'); var path = require('path'); test('transform', function (t) { t.plan(3); var p = mdeps({ transform: function (file) { return through(function (buf, enc, next) { this.push(String(buf) .replace(/AAA/g, '5') .replace(/BBB/g, '50') ); next(); }); }, transformKey: [ 'browserify', 'transform' ] }); p.end(path.join(__dirname, '/files/tr_sh/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('t', src)(t); }); }); module-deps-6.2.3/test/tr_global.js000066400000000000000000000015611371176574400172440ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var concat = require('concat-stream'); var path = require('path'); test('global transforms', function (t) { t.plan(1); var p = mdeps({ transform: [ 'tr-c', 'tr-d' ], globalTransform: [ path.join(__dirname, '/files/tr_global/node_modules/tr-e'), path.join(__dirname, '/files/tr_global/node_modules/tr-f') ], transformKey: [ 'browserify', 'transform' ] }); p.end(path.join(__dirname, '/files/tr_global/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack).pipe(concat(function (src) { Function(['console'], src)({ log: function (msg) { t.equal(msg, 111111); } }); })); }); module-deps-6.2.3/test/tr_module.js000066400000000000000000000011731371176574400172700ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); test('transform', function (t) { t.plan(4); var p = mdeps({ transform: [ 'insert-aaa', 'insert-bbb' ], transformKey: [ 'browserify', 'transform' ] }); p.end(path.join(__dirname, '/files/tr_module/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('t', src)(t); }); }); module-deps-6.2.3/test/tr_no_entry.js000066400000000000000000000016611371176574400176420ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var through = require('through2'); var concat = require('concat-stream'); var path = require('path'); test('transform no entry', function (t) { t.plan(1); var p = mdeps({ transform: [ function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/AAA/g, '"WOW"')); next(); }); } ] }); p.end({ file: path.join(__dirname, '/files/tr_no_entry/main.js'), id: 'xxx' }); p.pipe(JSONStream.stringify()).pipe(packer()) .pipe(concat(function (body) { var con = { log: function (x) { t.equal(x, 'WOW') } }; var src = 'require=' + body.toString('utf8') + ';require("xxx")'; Function('console', src)(con); })) ; }); module-deps-6.2.3/test/tr_opts.js000066400000000000000000000011441371176574400167660ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var concat = require('concat-stream'); var path = require('path'); test('transform options', function (t) { t.plan(1); var p = mdeps({ transformKey: [ 'mdtr' ] }); p.end(path.join(__dirname, '/tr_opts/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack).pipe(concat(function (src) { Function('console', src.toString('utf8'))({ log: function (msg) { t.equal(msg, 999) } }); })); }); module-deps-6.2.3/test/tr_opts/000077500000000000000000000000001371176574400164305ustar00rootroot00000000000000module-deps-6.2.3/test/tr_opts/main.js000066400000000000000000000000361371176574400177110ustar00rootroot00000000000000console.log(FFF * GGG * HHH); module-deps-6.2.3/test/tr_opts/node_modules/000077500000000000000000000000001371176574400211055ustar00rootroot00000000000000module-deps-6.2.3/test/tr_opts/node_modules/fff/000077500000000000000000000000001371176574400216465ustar00rootroot00000000000000module-deps-6.2.3/test/tr_opts/node_modules/fff/index.js000066400000000000000000000006641371176574400233210ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file, opts) { var bufs = []; return through(write, end); function write (buf, enc, next) { if (!Buffer.isBuffer(buf)) buf = Buffer(buf); bufs.push(buf); next(); } function end () { var str = Buffer.concat(bufs).toString('utf8'); this.push(str.replace(/FFF/g, opts.x)); this.push(null); } }; module-deps-6.2.3/test/tr_opts/node_modules/ggg/000077500000000000000000000000001371176574400216515ustar00rootroot00000000000000module-deps-6.2.3/test/tr_opts/node_modules/ggg/index.js000066400000000000000000000006641371176574400233240ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file, opts) { var bufs = []; return through(write, end); function write (buf, enc, next) { if (!Buffer.isBuffer(buf)) buf = Buffer(buf); bufs.push(buf); next(); } function end () { var str = Buffer.concat(bufs).toString('utf8'); this.push(str.replace(/GGG/g, opts.z)); this.push(null); } }; module-deps-6.2.3/test/tr_opts/node_modules/hhh/000077500000000000000000000000001371176574400216545ustar00rootroot00000000000000module-deps-6.2.3/test/tr_opts/node_modules/hhh/index.js000066400000000000000000000006571371176574400233310ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file, opts) { var bufs = []; return through(write, end); function write (buf, enc, next) { if (!Buffer.isBuffer(buf)) buf = Buffer(buf); bufs.push(buf); next(); } function end () { var str = Buffer.concat(bufs).toString('utf8'); this.push(str.replace(/HHH/g, 3)); this.push(null); } }; module-deps-6.2.3/test/tr_opts/package.json000066400000000000000000000001321371176574400207120ustar00rootroot00000000000000{ "mdtr": [ [ "fff", { "x": 3 } ], [ "ggg", { "z": 111 } ], [ "hhh" ] ] } module-deps-6.2.3/test/tr_rel.js000066400000000000000000000012231371176574400165610ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); test('transform', function (t) { t.plan(1); var p = mdeps({ transformKey: [ 'browserify', 'transform' ] }); p.end(path.join(__dirname, '/files/tr_rel/subdir/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('console', src)({ log: function (msg) { t.equal(msg, 333); } }); }); }); module-deps-6.2.3/test/tr_sh.js000066400000000000000000000011651371176574400164160ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); test('transform', function (t) { t.plan(3); var p = mdeps({ transform: [ './tr_a.js', './tr_b.js' ], transformKey: [ 'browserify', 'transform' ] }); p.end(path.join(__dirname, '/files/tr_sh/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('t', src)(t); }); }); module-deps-6.2.3/test/tr_whole_package.js000066400000000000000000000011171371176574400205720ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); test('transform', function (t) { t.plan(1); var p = mdeps({ transformKey: [ 'browserify', 'transform' ] }); p.end(path.join(__dirname, '/files/tr_whole_package/main.js')); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); var src = ''; pack.on('data', function (buf) { src += buf }); pack.on('end', function () { Function('t', src)(t); }); }); module-deps-6.2.3/test/tr_write.js000066400000000000000000000014561371176574400171410ustar00rootroot00000000000000var mdeps = require('../'); var test = require('tap').test; var JSONStream = require('JSONStream'); var packer = require('browser-pack'); var path = require('path'); var concat = require('concat-stream'); test('transform write', function (t) { t.plan(1); var p = mdeps(); p.write({ transform: 'insert-www', options: {} }); p.write({ file: path.join(__dirname, 'tr_write/main.js'), id: path.join(__dirname, 'tr_write/main.js'), entry: true }); p.end(); var pack = packer(); p.pipe(JSONStream.stringify()).pipe(pack); pack.pipe(concat(function (buf) { var src = buf.toString('utf8'); Function('console', src)({ log: function (msg) { t.equal(msg, 'WORLD WIDE WOW'); } }); })); }); module-deps-6.2.3/test/tr_write/000077500000000000000000000000001371176574400165755ustar00rootroot00000000000000module-deps-6.2.3/test/tr_write/main.js000066400000000000000000000000401371176574400200510ustar00rootroot00000000000000console.log(WWW.toUpperCase()); module-deps-6.2.3/test/undef_file.js000066400000000000000000000024211371176574400173730ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/files/main.js'), foo: path.join(__dirname, '/files/foo.js'), bar: path.join(__dirname, '/files/bar.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('undef file', function (t) { t.plan(1); var p = parser(); p.end({ id: files.main, entry: true }); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './foo': files.foo } }, { id: files.foo, file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-6.2.3/test/unicode.js000066400000000000000000000024261371176574400167260ustar00rootroot00000000000000var parser = require('../'); var test = require('tap').test; var fs = require('fs'); var path = require('path'); var files = { main: path.join(__dirname, '/files/unicode/main.js'), foo: path.join(__dirname, '/files/unicode/foo.js'), bar: path.join(__dirname, '/files/unicode/bar.js') }; var sources = Object.keys(files).reduce(function (acc, file) { acc[file] = fs.readFileSync(files[file], 'utf8'); return acc; }, {}); test('unicode deps', function (t) { t.plan(1); var p = parser(); p.end(files.main); var rows = []; p.on('data', function (row) { rows.push(row) }); p.on('end', function () { t.same(rows.sort(cmp), [ { id: files.main, file: files.main, source: sources.main, entry: true, deps: { './foo': files.foo } }, { id: files.foo, file: files.foo, source: sources.foo, deps: { './bar': files.bar } }, { id: files.bar, file: files.bar, source: sources.bar, deps: {} } ].sort(cmp)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 }