pax_global_header00006660000000000000000000000064130505303300014502gustar00rootroot0000000000000052 comment=4cce7975e909b91775411731a28e9d7e123e7079 module-deps-4.1.1/000077500000000000000000000000001305053033000137235ustar00rootroot00000000000000module-deps-4.1.1/.travis.yml000066400000000000000000000001641305053033000160350ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" - "0.12" - "iojs" before_install: - npm install -g npm@~1.4.6 module-deps-4.1.1/LICENSE000066400000000000000000000020611305053033000147270ustar00rootroot00000000000000This 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-4.1.1/bin/000077500000000000000000000000001305053033000144735ustar00rootroot00000000000000module-deps-4.1.1/bin/cmd.js000077500000000000000000000013601305053033000155770ustar00rootroot00000000000000#!/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-4.1.1/bin/usage.txt000066400000000000000000000002541305053033000163410ustar00rootroot00000000000000module-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-4.1.1/example/000077500000000000000000000000001305053033000153565ustar00rootroot00000000000000module-deps-4.1.1/example/deps.js000066400000000000000000000002751305053033000166530ustar00rootroot00000000000000var 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-4.1.1/example/files/000077500000000000000000000000001305053033000164605ustar00rootroot00000000000000module-deps-4.1.1/example/files/bar.js000066400000000000000000000000671305053033000175650ustar00rootroot00000000000000module.exports = function (n) { return n * 100; }; module-deps-4.1.1/example/files/foo.js000066400000000000000000000001351305053033000176000ustar00rootroot00000000000000var bar = require('./bar'); module.exports = function (n) { return n * 111 + bar(n); }; module-deps-4.1.1/example/files/main.js000066400000000000000000000000741305053033000177430ustar00rootroot00000000000000var foo = require('./foo'); console.log('main: ' + foo(5)); module-deps-4.1.1/example/files/xyz.js000066400000000000000000000000731305053033000176500ustar00rootroot00000000000000var foo = require('./foo'); console.log('xyz: ' + foo(6)); module-deps-4.1.1/index.js000066400000000000000000000453351305053033000154020ustar00rootroot00000000000000var 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.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.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; }; 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' }); rs.on('error', function (err) { self.emit('error', err) }); this.emit('file', file, id); 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 self.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; self.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); 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) }; 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); 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.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) 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.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) { 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); stream .pipe(self.getTransforms(fakePath || file, pkg, { builtin: builtin, inNodeModules: parent.inNodeModules })) .pipe(concat(function (body) { var src = body.toString('utf8'); var deps = getDeps(file, src); if (deps) { cb(null, { source: src, package: pkg, deps: deps.reduce(function (deps, dep) { deps[dep] = true; return deps; }, {}) }); } })); } }); function getDeps (file, src) { return rec.noparse ? [] : self.parseDeps(file, src); } 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, 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) { 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 = detective(src) } catch (ex) { var message = ex && ex.message ? ex.message : ex; this.emit('error', new Error( 'Parsing file ' + file + ': ' + message )); return; } 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) 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-4.1.1/package.json000066400000000000000000000023441305053033000162140ustar00rootroot00000000000000{ "name": "module-deps", "version": "4.1.1", "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": "^1.7.0", "cached-path-relative": "^1.0.0", "concat-stream": "~1.5.0", "defined": "^1.0.0", "detective": "^4.0.0", "duplexer2": "^0.1.2", "inherits": "^2.0.1", "parents": "^1.0.0", "readable-stream": "^2.0.2", "resolve": "^1.1.3", "stream-combiner2": "^1.1.1", "subarg": "^1.0.0", "through2": "^2.0.0", "xtend": "^4.0.0" }, "devDependencies": { "tap": "^1.0.0", "browser-pack": "^5.0.0" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/substack/module-deps.git" }, "homepage": "https://github.com/substack/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.6" }, "license": "MIT" } module-deps-4.1.1/readme.markdown000066400000000000000000000211151305053033000167240ustar00rootroot00000000000000# module-deps walk the dependency graph to generate json output that can be fed into [browser-pack](https://github.com/substack/browser-pack) [![build status](https://secure.travis-ci.org/substack/module-deps.png)](http://travis-ci.org/substack/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: ``` $ 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/substack/browser-pack): ``` $ 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.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: ``` 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.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 # 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. 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-4.1.1/test/000077500000000000000000000000001305053033000147025ustar00rootroot00000000000000module-deps-4.1.1/test/bundle.js000066400000000000000000000011601305053033000165070ustar00rootroot00000000000000var 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-4.1.1/test/cache.js000066400000000000000000000021471305053033000163070ustar00rootroot00000000000000var 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-4.1.1/test/cache_expose.js000066400000000000000000000024471305053033000176750ustar00rootroot00000000000000var 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-4.1.1/test/cache_partial.js000066400000000000000000000021521305053033000200170ustar00rootroot00000000000000var 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-4.1.1/test/cache_partial_expose.js000066400000000000000000000052441305053033000214070ustar00rootroot00000000000000var 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-4.1.1/test/cache_persistent.js000066400000000000000000000043751305053033000205740ustar00rootroot00000000000000var 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)); }); }); function cmp (a, b) { return a.id < b.id ? -1 : 1 } module-deps-4.1.1/test/cycle.js000066400000000000000000000010561305053033000163410ustar00rootroot00000000000000var 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-4.1.1/test/cycle/000077500000000000000000000000001305053033000160015ustar00rootroot00000000000000module-deps-4.1.1/test/cycle/bar.js000066400000000000000000000001261305053033000171020ustar00rootroot00000000000000var foo = require('./foo.js'); module.exports = function (n) { return foo.p(n, 1) }; module-deps-4.1.1/test/cycle/foo.js000066400000000000000000000002011305053033000171130ustar00rootroot00000000000000var bar = require('./bar.js'); exports.ooo = function (n) { return n * bar(110) }; exports.p = function (a, b) { return a + b } module-deps-4.1.1/test/cycle/main.js000066400000000000000000000001351305053033000172620ustar00rootroot00000000000000var foo = require('./foo.js'); var bar = require('./bar.js'); console.log(foo.ooo(bar(2))); module-deps-4.1.1/test/deps.js000066400000000000000000000024151305053033000161750ustar00rootroot00000000000000var 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-4.1.1/test/dotdot.js000066400000000000000000000010231305053033000165310ustar00rootroot00000000000000var 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-4.1.1/test/dotdot/000077500000000000000000000000001305053033000161775ustar00rootroot00000000000000module-deps-4.1.1/test/dotdot/abc/000077500000000000000000000000001305053033000167245ustar00rootroot00000000000000module-deps-4.1.1/test/dotdot/abc/index.js000066400000000000000000000000471305053033000203720ustar00rootroot00000000000000var x = require('..'); console.log(x); module-deps-4.1.1/test/dotdot/index.js000066400000000000000000000000341305053033000176410ustar00rootroot00000000000000module.exports = 'whatever' module-deps-4.1.1/test/expose.js000066400000000000000000000020371305053033000165450ustar00rootroot00000000000000var 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-4.1.1/test/expose/000077500000000000000000000000001305053033000162055ustar00rootroot00000000000000module-deps-4.1.1/test/expose/bar.js000066400000000000000000000000201305053033000172770ustar00rootroot00000000000000require('xyz'); module-deps-4.1.1/test/expose/foo.js000066400000000000000000000000261305053033000173240ustar00rootroot00000000000000require('./lib/abc'); module-deps-4.1.1/test/expose/lib/000077500000000000000000000000001305053033000167535ustar00rootroot00000000000000module-deps-4.1.1/test/expose/lib/abc.js000066400000000000000000000000241305053033000200320ustar00rootroot00000000000000console.log('abc'); module-deps-4.1.1/test/expose/lib/xyz.js000066400000000000000000000000471305053033000201440ustar00rootroot00000000000000require('../foo'); console.log('xyz'); module-deps-4.1.1/test/expose/main.js000066400000000000000000000000621305053033000174650ustar00rootroot00000000000000require('abc'); require('xyz'); require('./bar'); module-deps-4.1.1/test/file_cache.js000066400000000000000000000027401305053033000173050ustar00rootroot00000000000000var 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-4.1.1/test/files/000077500000000000000000000000001305053033000160045ustar00rootroot00000000000000module-deps-4.1.1/test/files/bar.js000066400000000000000000000000671305053033000171110ustar00rootroot00000000000000module.exports = function (n) { return n * 100; }; module-deps-4.1.1/test/files/extra.js000066400000000000000000000000251305053033000174620ustar00rootroot00000000000000module.exports = 555 module-deps-4.1.1/test/files/filterable.js000066400000000000000000000003221305053033000204500ustar00rootroot00000000000000 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-4.1.1/test/files/foo.js000066400000000000000000000001351305053033000171240ustar00rootroot00000000000000var bar = require('./bar'); module.exports = function (n) { return n * 111 + bar(n); }; module-deps-4.1.1/test/files/main.js000066400000000000000000000000741305053033000172670ustar00rootroot00000000000000var foo = require('./foo'); console.log('main: ' + foo(5)); module-deps-4.1.1/test/files/pkg_filter/000077500000000000000000000000001305053033000201325ustar00rootroot00000000000000module-deps-4.1.1/test/files/pkg_filter/one.js000066400000000000000000000000231305053033000212440ustar00rootroot00000000000000module.exports = 1 module-deps-4.1.1/test/files/pkg_filter/package.json000066400000000000000000000000271305053033000224170ustar00rootroot00000000000000{ "main": "one.js" } module-deps-4.1.1/test/files/pkg_filter/test.js000066400000000000000000000000331305053033000214430ustar00rootroot00000000000000t.equal(require('./'), 2); module-deps-4.1.1/test/files/pkg_filter/two.js000066400000000000000000000000231305053033000212740ustar00rootroot00000000000000module.exports = 2 module-deps-4.1.1/test/files/tr_2dep_module/000077500000000000000000000000001305053033000207105ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/f.js000066400000000000000000000000611305053033000214700ustar00rootroot00000000000000module.exports = function (x) { return x + BBB } module-deps-4.1.1/test/files/tr_2dep_module/main.js000066400000000000000000000003311305053033000221670ustar00rootroot00000000000000var 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-4.1.1/test/files/tr_2dep_module/node_modules/000077500000000000000000000000001305053033000233655ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/g/000077500000000000000000000000001305053033000236135ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/g/index.js000066400000000000000000000000611305053033000252550ustar00rootroot00000000000000module.exports = function (x) { return x * GGG } module-deps-4.1.1/test/files/tr_2dep_module/node_modules/g/node_modules/000077500000000000000000000000001305053033000262705ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/g/node_modules/insert-ggg/000077500000000000000000000000001305053033000303365ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/g/node_modules/insert-ggg/index.js000066400000000000000000000003101305053033000317750ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '111')); next(); }); }; module-deps-4.1.1/test/files/tr_2dep_module/node_modules/g/package.json000066400000000000000000000001161305053033000260770ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "insert-ggg" } } module-deps-4.1.1/test/files/tr_2dep_module/node_modules/insert-aaa/000077500000000000000000000000001305053033000254115ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/insert-aaa/index.js000066400000000000000000000003061305053033000270550ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/AAA/g, '5')); next(); }); }; module-deps-4.1.1/test/files/tr_2dep_module/node_modules/insert-bbb/000077500000000000000000000000001305053033000254145ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/insert-bbb/index.js000066400000000000000000000003071305053033000270610ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/BBB/g, '50')); next(); }); }; module-deps-4.1.1/test/files/tr_2dep_module/node_modules/m/000077500000000000000000000000001305053033000236215ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/m/index.js000066400000000000000000000001301305053033000252600ustar00rootroot00000000000000var AAA = 200, BBB = 300; module.exports = function (x) { return AAA + BBB + MMM + x } module-deps-4.1.1/test/files/tr_2dep_module/node_modules/m/node_modules/000077500000000000000000000000001305053033000262765ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/m/node_modules/insert-mmm/000077500000000000000000000000001305053033000303665ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_2dep_module/node_modules/m/node_modules/insert-mmm/index.js000066400000000000000000000003101305053033000320250ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/MMM/g, '222')); next(); }); }; module-deps-4.1.1/test/files/tr_2dep_module/node_modules/m/package.json000066400000000000000000000001161305053033000261050ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "insert-mmm" } } module-deps-4.1.1/test/files/tr_global/000077500000000000000000000000001305053033000177515ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/main.js000066400000000000000000000000601305053033000212270ustar00rootroot00000000000000console.log(AAA + BBB + CCC + DDD + EEE + FFF); module-deps-4.1.1/test/files/tr_global/node_modules/000077500000000000000000000000001305053033000224265ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/node_modules/tr-a/000077500000000000000000000000001305053033000232715ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/node_modules/tr-a/index.js000066400000000000000000000003111305053033000247310ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/AAA/g, '1')); next(); }); }; module-deps-4.1.1/test/files/tr_global/node_modules/tr-b/000077500000000000000000000000001305053033000232725ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/node_modules/tr-b/index.js000066400000000000000000000003121305053033000247330ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/BBB/g, '10')); next(); }); }; module-deps-4.1.1/test/files/tr_global/node_modules/tr-c/000077500000000000000000000000001305053033000232735ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/node_modules/tr-c/index.js000066400000000000000000000003131305053033000247350ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/CCC/g, '100')); next(); }); }; module-deps-4.1.1/test/files/tr_global/node_modules/tr-d/000077500000000000000000000000001305053033000232745ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/node_modules/tr-d/index.js000066400000000000000000000003141305053033000247370ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/DDD/g, '1000')); next(); }); }; module-deps-4.1.1/test/files/tr_global/node_modules/tr-e/000077500000000000000000000000001305053033000232755ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/node_modules/tr-e/index.js000066400000000000000000000003151305053033000247410ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/EEE/g, '10000')); next(); }); }; module-deps-4.1.1/test/files/tr_global/node_modules/tr-f/000077500000000000000000000000001305053033000232765ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_global/node_modules/tr-f/index.js000066400000000000000000000003161305053033000247430ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(buf.toString().replace(/FFF/g, '100000')); next(); }); }; module-deps-4.1.1/test/files/tr_global/package.json000066400000000000000000000000761305053033000222420ustar00rootroot00000000000000{ "browserify": { "transform": [ "tr-a", "tr-b" ] } } module-deps-4.1.1/test/files/tr_module/000077500000000000000000000000001305053033000177765ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/f.js000066400000000000000000000000611305053033000205560ustar00rootroot00000000000000module.exports = function (x) { return x + BBB } module-deps-4.1.1/test/files/tr_module/index.js000066400000000000000000000003101305053033000214350ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '123')); next(); }); }; module-deps-4.1.1/test/files/tr_module/main.js000066400000000000000000000003631305053033000212620ustar00rootroot00000000000000var 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-4.1.1/test/files/tr_module/node_modules/000077500000000000000000000000001305053033000224535ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/node_modules/g/000077500000000000000000000000001305053033000227015ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/node_modules/g/index.js000066400000000000000000000001011305053033000243360ustar00rootroot00000000000000module.exports = function (x) { return x * (GGG - 3 * XXX + 9) } module-deps-4.1.1/test/files/tr_module/node_modules/g/node_modules/000077500000000000000000000000001305053033000253565ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/node_modules/g/node_modules/insert-ggg/000077500000000000000000000000001305053033000274245ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/node_modules/g/node_modules/insert-ggg/index.js000066400000000000000000000003101305053033000310630ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '111')); next(); }); }; module-deps-4.1.1/test/files/tr_module/node_modules/g/package.json000066400000000000000000000001341305053033000251650ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": [ "insert-ggg", "./x.js" ] } } module-deps-4.1.1/test/files/tr_module/node_modules/g/x.js000066400000000000000000000003061305053033000235050ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '3')); next(); }); }; module-deps-4.1.1/test/files/tr_module/node_modules/insert-aaa/000077500000000000000000000000001305053033000244775ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/node_modules/insert-aaa/index.js000066400000000000000000000003061305053033000261430ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/AAA/g, '5')); next(); }); }; module-deps-4.1.1/test/files/tr_module/node_modules/insert-bbb/000077500000000000000000000000001305053033000245025ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/node_modules/insert-bbb/index.js000066400000000000000000000003071305053033000261470ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/BBB/g, '50')); next(); }); }; module-deps-4.1.1/test/files/tr_module/node_modules/m/000077500000000000000000000000001305053033000227075ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_module/node_modules/m/index.js000066400000000000000000000001221305053033000243470ustar00rootroot00000000000000var AAA = 200, BBB = 300; module.exports = function (x) { return AAA + BBB + x } module-deps-4.1.1/test/files/tr_module/package.json000066400000000000000000000000721305053033000222630ustar00rootroot00000000000000{ "browserify": { "transform": [ "./xxx.js" ] } } module-deps-4.1.1/test/files/tr_module/xxx.js000066400000000000000000000003101305053033000211550ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '123')); next(); }); }; module-deps-4.1.1/test/files/tr_no_entry/000077500000000000000000000000001305053033000203465ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_no_entry/main.js000066400000000000000000000000211305053033000216210ustar00rootroot00000000000000console.log(AAA) module-deps-4.1.1/test/files/tr_rel/000077500000000000000000000000001305053033000172735ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_rel/package.json000066400000000000000000000000721305053033000215600ustar00rootroot00000000000000{ "browserify": { "transform": [ "./xxx.js" ] } } module-deps-4.1.1/test/files/tr_rel/subdir/000077500000000000000000000000001305053033000205635ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_rel/subdir/main.js000066400000000000000000000000251305053033000220420ustar00rootroot00000000000000console.log(XXX * 3) module-deps-4.1.1/test/files/tr_rel/xxx.js000066400000000000000000000003101305053033000204520ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/XXX/g, '111')); next(); }); }; module-deps-4.1.1/test/files/tr_sh/000077500000000000000000000000001305053033000171235ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_sh/f.js000066400000000000000000000000611305053033000177030ustar00rootroot00000000000000module.exports = function (x) { return x + BBB } module-deps-4.1.1/test/files/tr_sh/main.js000066400000000000000000000003311305053033000204020ustar00rootroot00000000000000var 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-4.1.1/test/files/tr_sh/node_modules/000077500000000000000000000000001305053033000216005ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_sh/node_modules/g/000077500000000000000000000000001305053033000220265ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_sh/node_modules/g/index.js000066400000000000000000000000611305053033000234700ustar00rootroot00000000000000module.exports = function (x) { return x * GGG } module-deps-4.1.1/test/files/tr_sh/node_modules/g/package.json000066400000000000000000000001151305053033000243110ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "./tr_g.js" } } module-deps-4.1.1/test/files/tr_sh/node_modules/g/tr_g.js000066400000000000000000000003071305053033000233170ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '111')); next(); }); }; module-deps-4.1.1/test/files/tr_sh/node_modules/m/000077500000000000000000000000001305053033000220345ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_sh/node_modules/m/index.js000066400000000000000000000001221305053033000234740ustar00rootroot00000000000000var AAA = 200, BBB = 300; module.exports = function (x) { return AAA + BBB + x } module-deps-4.1.1/test/files/tr_sh/tr_a.js000066400000000000000000000003051305053033000204040ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/AAA/g, '5')); next(); }); }; module-deps-4.1.1/test/files/tr_sh/tr_b.js000066400000000000000000000003061305053033000204060ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/BBB/g, '50')); next(); }); }; module-deps-4.1.1/test/files/tr_whole_package/000077500000000000000000000000001305053033000213025ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_whole_package/f.js000066400000000000000000000001241305053033000220620ustar00rootroot00000000000000var calc = require('algo').calc; module.exports = function (x) { return calc(x); } module-deps-4.1.1/test/files/tr_whole_package/main.js000066400000000000000000000001101305053033000225540ustar00rootroot00000000000000var f = require('./f.js'); t.equal(f(14), 11, 'transformation scope'); module-deps-4.1.1/test/files/tr_whole_package/node_modules/000077500000000000000000000000001305053033000237575ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/000077500000000000000000000000001305053033000247015ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/index.js000066400000000000000000000001551305053033000263470ustar00rootroot00000000000000var decrement = require('./lib/decrement'); exports.calc = function (x) { return decrement(x) - GGG - GGG } module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/lib/000077500000000000000000000000001305053033000254475ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/lib/decrement.js000066400000000000000000000000611305053033000277500ustar00rootroot00000000000000module.exports = function (x) { return x - GGG } module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/node_modules/000077500000000000000000000000001305053033000273565ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/node_modules/insert-ggg/000077500000000000000000000000001305053033000314245ustar00rootroot00000000000000module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/node_modules/insert-ggg/index.js000066400000000000000000000003061305053033000330700ustar00rootroot00000000000000var through = require('through2'); module.exports = function (file) { return through(function (buf, enc, next) { this.push(String(buf).replace(/GGG/g, '1')); next(); }); }; module-deps-4.1.1/test/files/tr_whole_package/node_modules/algo/package.json000066400000000000000000000001161305053033000271650ustar00rootroot00000000000000{ "main": "index.js", "browserify": { "transform": "insert-ggg" } } module-deps-4.1.1/test/files/unicode/000077500000000000000000000000001305053033000174325ustar00rootroot00000000000000module-deps-4.1.1/test/files/unicode/bar.js000066400000000000000000000000711305053033000205320ustar00rootroot00000000000000module.exports = function (ñ) { return ñ * 100; }; module-deps-4.1.1/test/files/unicode/foo.js000066400000000000000000000001351305053033000205520ustar00rootroot00000000000000var é = require('./bar'); module.exports = function (ñ) { return ñ * 111 + é(n); }; module-deps-4.1.1/test/files/unicode/main.js000066400000000000000000000000731305053033000207140ustar00rootroot00000000000000var π = require('./foo'); console.log('main: ' + foo(5)); module-deps-4.1.1/test/files/xyz.js000066400000000000000000000000731305053033000171740ustar00rootroot00000000000000var foo = require('./foo'); console.log('xyz: ' + foo(6)); module-deps-4.1.1/test/filter.js000066400000000000000000000015111305053033000165230ustar00rootroot00000000000000var 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-4.1.1/test/ignore_missing.js000066400000000000000000000030601305053033000202530ustar00rootroot00000000000000var 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-4.1.1/test/ignore_missing/000077500000000000000000000000001305053033000177165ustar00rootroot00000000000000module-deps-4.1.1/test/ignore_missing/main.js000066400000000000000000000000241305053033000211740ustar00rootroot00000000000000require('./other'); module-deps-4.1.1/test/ignore_missing/other.js000066400000000000000000000000321305053033000213700ustar00rootroot00000000000000require('missingModule'); module-deps-4.1.1/test/ignore_missing_cache.js000066400000000000000000000025501305053033000214010ustar00rootroot00000000000000var 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-4.1.1/test/node_modules/000077500000000000000000000000001305053033000173575ustar00rootroot00000000000000module-deps-4.1.1/test/node_modules/insert-www/000077500000000000000000000000001305053033000215055ustar00rootroot00000000000000module-deps-4.1.1/test/node_modules/insert-www/index.js000066400000000000000000000003251305053033000231520ustar00rootroot00000000000000var 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-4.1.1/test/noparse.js000066400000000000000000000021511305053033000167060ustar00rootroot00000000000000var 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-4.1.1/test/noparse_row.js000066400000000000000000000020031305053033000175710ustar00rootroot00000000000000var 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-4.1.1/test/pkg.js000066400000000000000000000010011305053033000160110ustar00rootroot00000000000000var 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-4.1.1/test/pkg/000077500000000000000000000000001305053033000154635ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/main.js000066400000000000000000000000421305053033000167410ustar00rootroot00000000000000require('pkga'); require('pkgb'); module-deps-4.1.1/test/pkg/node_modules/000077500000000000000000000000001305053033000201405ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/node_modules/pkga/000077500000000000000000000000001305053033000210625ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/node_modules/pkga/main.js000066400000000000000000000000001305053033000223320ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/node_modules/pkga/package.json000066400000000000000000000000671305053033000233530ustar00rootroot00000000000000{ "dir": "/node_modules/pkga", "main": "main.js" } module-deps-4.1.1/test/pkg/node_modules/pkgb/000077500000000000000000000000001305053033000210635ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/node_modules/pkgb/main.js000066400000000000000000000000201305053033000223350ustar00rootroot00000000000000require('pkgc');module-deps-4.1.1/test/pkg/node_modules/pkgb/node_modules/000077500000000000000000000000001305053033000235405ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/node_modules/pkgb/node_modules/pkgc/000077500000000000000000000000001305053033000244645ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/node_modules/pkgb/node_modules/pkgc/main.js000066400000000000000000000000001305053033000257340ustar00rootroot00000000000000module-deps-4.1.1/test/pkg/node_modules/pkgb/node_modules/pkgc/package.json000066400000000000000000000001111305053033000267430ustar00rootroot00000000000000{ "dir": "/node_modules/pkgb/node_modules/pkgc", "main": "main.js" } module-deps-4.1.1/test/pkg/node_modules/pkgb/package.json000066400000000000000000000000671305053033000233540ustar00rootroot00000000000000{ "dir": "/node_modules/pkgb", "main": "main.js" } module-deps-4.1.1/test/pkg/package.json000066400000000000000000000000461305053033000177510ustar00rootroot00000000000000{ "dir": "", "main": "index.js" } module-deps-4.1.1/test/pkg_filter.js000066400000000000000000000012251305053033000173660ustar00rootroot00000000000000var 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) { 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-4.1.1/test/row_expose.js000066400000000000000000000014301305053033000174300ustar00rootroot00000000000000var 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-4.1.1/test/row_expose_name_is_file_transform.js000066400000000000000000000021031305053033000242130ustar00rootroot00000000000000var 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-4.1.1/test/row_expose_transform.js000066400000000000000000000015311305053033000215250ustar00rootroot00000000000000var 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-4.1.1/test/source.js000066400000000000000000000032061305053033000165410ustar00rootroot00000000000000var 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-4.1.1/test/tr_2dep_module.js000066400000000000000000000012001305053033000201350ustar00rootroot00000000000000var 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-4.1.1/test/tr_err.js000066400000000000000000000011141305053033000165320ustar00rootroot00000000000000var 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-4.1.1/test/tr_flags.js000066400000000000000000000024021305053033000170370ustar00rootroot00000000000000var 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-4.1.1/test/tr_flags/000077500000000000000000000000001305053033000165035ustar00rootroot00000000000000module-deps-4.1.1/test/tr_flags/empty.js000066400000000000000000000000001305053033000201650ustar00rootroot00000000000000module-deps-4.1.1/test/tr_fn.js000066400000000000000000000016041305053033000163510ustar00rootroot00000000000000var 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-4.1.1/test/tr_global.js000066400000000000000000000015611305053033000172100ustar00rootroot00000000000000var 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-4.1.1/test/tr_module.js000066400000000000000000000011731305053033000172340ustar00rootroot00000000000000var 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-4.1.1/test/tr_no_entry.js000066400000000000000000000016611305053033000176060ustar00rootroot00000000000000var 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-4.1.1/test/tr_opts.js000066400000000000000000000011441305053033000167320ustar00rootroot00000000000000var 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-4.1.1/test/tr_opts/000077500000000000000000000000001305053033000163745ustar00rootroot00000000000000module-deps-4.1.1/test/tr_opts/main.js000066400000000000000000000000361305053033000176550ustar00rootroot00000000000000console.log(FFF * GGG * HHH); module-deps-4.1.1/test/tr_opts/node_modules/000077500000000000000000000000001305053033000210515ustar00rootroot00000000000000module-deps-4.1.1/test/tr_opts/node_modules/fff/000077500000000000000000000000001305053033000216125ustar00rootroot00000000000000module-deps-4.1.1/test/tr_opts/node_modules/fff/index.js000066400000000000000000000006641305053033000232650ustar00rootroot00000000000000var 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-4.1.1/test/tr_opts/node_modules/ggg/000077500000000000000000000000001305053033000216155ustar00rootroot00000000000000module-deps-4.1.1/test/tr_opts/node_modules/ggg/index.js000066400000000000000000000006641305053033000232700ustar00rootroot00000000000000var 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-4.1.1/test/tr_opts/node_modules/hhh/000077500000000000000000000000001305053033000216205ustar00rootroot00000000000000module-deps-4.1.1/test/tr_opts/node_modules/hhh/index.js000066400000000000000000000006571305053033000232750ustar00rootroot00000000000000var 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-4.1.1/test/tr_opts/package.json000066400000000000000000000001321305053033000206560ustar00rootroot00000000000000{ "mdtr": [ [ "fff", { "x": 3 } ], [ "ggg", { "z": 111 } ], [ "hhh" ] ] } module-deps-4.1.1/test/tr_rel.js000066400000000000000000000012231305053033000165250ustar00rootroot00000000000000var 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-4.1.1/test/tr_sh.js000066400000000000000000000011651305053033000163620ustar00rootroot00000000000000var 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-4.1.1/test/tr_whole_package.js000066400000000000000000000011171305053033000205360ustar00rootroot00000000000000var 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-4.1.1/test/tr_write.js000066400000000000000000000014561305053033000171050ustar00rootroot00000000000000var 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-4.1.1/test/tr_write/000077500000000000000000000000001305053033000165415ustar00rootroot00000000000000module-deps-4.1.1/test/tr_write/main.js000066400000000000000000000000401305053033000200150ustar00rootroot00000000000000console.log(WWW.toUpperCase()); module-deps-4.1.1/test/undef_file.js000066400000000000000000000024211305053033000173370ustar00rootroot00000000000000var 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-4.1.1/test/unicode.js000066400000000000000000000024261305053033000166720ustar00rootroot00000000000000var 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 }