module-deps
Advanced tools
Comparing version 4.0.8 to 4.1.0
62
index.js
@@ -30,2 +30,7 @@ var fs = require('fs'); | ||
this.basedir = opts.basedir || process.cwd(); | ||
this.persistentCache = opts.persistentCache || function (file, id, pkg, fallback, cb) { | ||
setImmediate(function () { | ||
fallback(null, cb); | ||
}); | ||
}; | ||
this.cache = opts.cache; | ||
@@ -200,6 +205,3 @@ this.fileCache = opts.fileCache; | ||
if (xhas(this.fileCache, file)) { | ||
var tr = through(); | ||
tr.push(this.fileCache[file]); | ||
tr.push(null); | ||
return tr; | ||
return toStream(this.fileCache[file]); | ||
} | ||
@@ -381,15 +383,40 @@ var rs = fs.createReadStream(file, { | ||
self.readFile(file, id, pkg) | ||
.pipe(self.getTransforms(fakePath || file, pkg, { | ||
builtin: builtin, | ||
inNodeModules: parent.inNodeModules | ||
})) | ||
.pipe(concat(function (body) { | ||
fromSource(file, body.toString('utf8'), pkg, fakePath); | ||
})) | ||
; | ||
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 = rec.noparse ? [] : self.parseDeps(file, src); | ||
var deps = getDeps(file, src); | ||
if (deps) fromDeps(file, src, pkg, fakePath, deps); | ||
@@ -556,2 +583,9 @@ } | ||
function toStream (dataAsString) { | ||
var tr = through(); | ||
tr.push(dataAsString); | ||
tr.push(null); | ||
return tr; | ||
} | ||
function has (obj, key) { | ||
@@ -558,0 +592,0 @@ return obj && Object.prototype.hasOwnProperty.call(obj, key); |
{ | ||
"name": "module-deps", | ||
"version": "4.0.8", | ||
"version": "4.1.0", | ||
"description": "walk the dependency graph to generate json output that can be fed into browser-pack", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
75223
115
1983
290
18