module-deps
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -5,2 +5,8 @@ # module-deps Change Log | ||
## 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 | ||
@@ -7,0 +13,0 @@ * Restore support for node < 4.0.0. |
49
index.js
var fs = require('fs'); | ||
var path = require('path'); | ||
var relativePath = require('cached-path-relative') | ||
var relativePath = require('cached-path-relative'); | ||
@@ -41,2 +41,3 @@ var browserResolve = require('browser-resolve'); | ||
this._emittedPkg = {}; | ||
this._transformDeps = {}; | ||
this.visited = {}; | ||
@@ -210,4 +211,2 @@ this.walking = {}; | ||
}); | ||
rs.on('error', function (err) { self.emit('error', err) }); | ||
this.emit('file', file, id); | ||
return rs; | ||
@@ -240,3 +239,5 @@ }; | ||
makeTransform(transforms[i], function (err, trs) { | ||
if (err) return self.emit('error', err) | ||
if (err) { | ||
return dup.emit('error', err); | ||
} | ||
streams[i] = trs; | ||
@@ -253,3 +254,3 @@ if (-- pending === 0) done(); | ||
if (!err.filename) err.filename = file; | ||
self.emit('error', err); | ||
dup.emit('error', err); | ||
}); | ||
@@ -268,2 +269,7 @@ input.pipe(middle).pipe(output); | ||
var t = tr(file, trOpts); | ||
// allow transforms to `stream.emit('dep', path)` to add dependencies for this file | ||
self._transformDeps[file] = []; | ||
t.on('dep', function (dep) { | ||
self._transformDeps[file].push(dep); | ||
}); | ||
self.emit('transform', t, file); | ||
@@ -281,3 +287,6 @@ nextTick(cb, null, wrapTransform(t)); | ||
function loadTransform (id, trOpts, cb) { | ||
var params = { basedir: path.dirname(file) }; | ||
var params = { | ||
basedir: path.dirname(file), | ||
preserveSymlinks: false | ||
}; | ||
nodeResolve(id, params, function nr (err, res, again) { | ||
@@ -289,3 +298,3 @@ if (err && again) return cb && cb(err); | ||
return nodeResolve(id, params, function (e, r) { | ||
nr(e, r, true) | ||
nr(e, r, true); | ||
}); | ||
@@ -309,2 +318,7 @@ } | ||
var trs = r(file, trOpts); | ||
// allow transforms to `stream.emit('dep', path)` to add dependencies for this file | ||
self._transformDeps[file] = []; | ||
trs.on('dep', function (dep) { | ||
self._transformDeps[file].push(dep); | ||
}); | ||
self.emit('transform', trs, file); | ||
@@ -357,2 +371,5 @@ cb(null, trs); | ||
var ts = self.getTransforms(file, pkg); | ||
ts.on('error', function (err) { | ||
self.emit('error', err); | ||
}); | ||
ts.pipe(concat(function (body) { | ||
@@ -380,2 +397,5 @@ rec.source = body.toString('utf8'); | ||
var ts = self.getTransforms(file, pkg); | ||
ts.on('error', function (err) { | ||
self.emit('error', err); | ||
}); | ||
ts.pipe(concat(function (body) { | ||
@@ -392,2 +412,3 @@ rec.source = body.toString('utf8'); | ||
self.persistentCache(file, id, pkg, persistentCacheFallback, function (err, c) { | ||
self.emit('file', file, id); | ||
if (err) { | ||
@@ -401,3 +422,3 @@ self.emit('error', err); | ||
function persistentCacheFallback (dataAsString, cb) { | ||
var stream = dataAsString ? toStream(dataAsString) : self.readFile(file, id, pkg); | ||
var stream = dataAsString ? toStream(dataAsString) : self.readFile(file, id, pkg).on('error', cb); | ||
stream | ||
@@ -408,2 +429,3 @@ .pipe(self.getTransforms(fakePath || file, pkg, { | ||
})) | ||
.on('error', cb) | ||
.pipe(concat(function (body) { | ||
@@ -427,3 +449,6 @@ var src = body.toString('utf8'); | ||
function getDeps (file, src) { | ||
return rec.noparse ? [] : self.parseDeps(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; | ||
} | ||
@@ -538,3 +563,3 @@ | ||
err + ' while parsing json file ' + pkgfile | ||
].join(''))) | ||
].join(''))); | ||
} | ||
@@ -554,4 +579,4 @@ pkg.__dirname = dir; | ||
} | ||
if (err) cb(err) | ||
else if (pkg) cb(null, pkg) | ||
if (err) cb(err); | ||
else if (pkg && typeof pkg === 'object') cb(null, pkg); | ||
else { | ||
@@ -558,0 +583,0 @@ self.pkgCache[pkgfile] = false; |
{ | ||
"name": "module-deps", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"description": "walk the dependency graph to generate json output that can be fed into browser-pack", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"readable-stream": "^2.0.2", | ||
"resolve": "^1.1.3", | ||
"resolve": "^1.4.0", | ||
"stream-combiner2": "^1.1.1", | ||
@@ -23,0 +23,0 @@ "subarg": "^1.0.0", |
@@ -16,3 +16,3 @@ var parser = require('../'); | ||
if (file === files.bar) { | ||
return fallback(null, cb) | ||
return fallback(null, cb); | ||
} | ||
@@ -23,3 +23,3 @@ cb(null, { | ||
deps: { './bar': files.bar } | ||
}) | ||
}); | ||
} | ||
@@ -53,3 +53,3 @@ }); | ||
persistentCache: function (file, id, pkg, fallback, cb) { | ||
cb(new Error('foo')) | ||
cb(new Error('foo')); | ||
} | ||
@@ -65,3 +65,3 @@ }); | ||
persistentCache: function (file, id, pkg, fallback, cb) { | ||
fallback(fs.readFileSync(files.bar, 'utf8'), cb) | ||
fallback(fs.readFileSync(files.bar, 'utf8'), cb); | ||
} | ||
@@ -85,2 +85,43 @@ }); | ||
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 } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80103
111
2111
294
1
22
19
Updatedresolve@^1.4.0