[Pkg-javascript-commits] [node-module-deps] 216/444: much faster caching scheme
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 09:47:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-module-deps.
commit c87c8e989ce244c008e5aeaf950027116bbd3b84
Author: James Halliday <mail at substack.net>
Date: Fri May 9 15:35:01 2014 -0700
much faster caching scheme
---
index.js | 36 +++++++++++++++++++++++++++---------
readme.markdown | 4 ++++
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/index.js b/index.js
index d898d89..3ebe22f 100644
--- a/index.js
+++ b/index.js
@@ -102,15 +102,15 @@ Deps.prototype.resolve = function (id, parent, cb) {
var self = this;
var opts = self.options;
- var c = this.cache && this.cache[parent.id];
- var resolver = c && typeof c === 'object'
- && !Buffer.isBuffer(c) && c.deps[id]
- ? function (xid, xparent, fn) {
- var file = self.cache[parent.id].deps[id];
- fn(null, file, self.pkgCache && self.pkgCache[file]);
- }
- : self.resolver
- ;
+ if (xhas(self.cache, parent.id, 'deps', id)
+ && self.cache[parent.id].deps) {
+ 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);
+ });
+ }
var pkgdir;
parent.packageFilter = function (p, x) {
@@ -154,6 +154,7 @@ Deps.prototype.readFile = function (file, pkg) {
}
var rs = fs.createReadStream(file);
rs.on('error', function (err) { tr.emit('error', err) });
+ this.emit('file', file);
return rs.pipe(this.getTransforms(file, pkg));
};
@@ -265,6 +266,9 @@ Deps.prototype.walk = function (id, parent, cb) {
}
self.visited[file] = true;
+ var c = self.cache && self.cache[file];
+ if (c) return fromDeps(file, c.source, c.package, Object.keys(c.deps));
+
self.readFile(file, pkg).pipe(concat(function (body) {
var src = body.toString('utf8');
var deps = self.parseDeps(file, src);
@@ -413,3 +417,17 @@ 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 has (obj, key) {
+ return Object.prototype.hasOwnProperty.call(obj, key);
+}
diff --git a/readme.markdown b/readme.markdown
index 070f540..2d66b98 100644
--- a/readme.markdown
+++ b/readme.markdown
@@ -99,6 +99,10 @@ in `process.env.NODE_PATH`
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.
+
# transforms
module-deps can be configured to run source transformations on files before
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-module-deps.git
More information about the Pkg-javascript-commits
mailing list