[Pkg-javascript-commits] [node-module-deps] 31/444: top-level transforms work
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 09:47:40 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 56147f9455366c2a0a1b27029e7d686bb3531c76
Author: James Halliday <mail at substack.net>
Date: Wed Feb 27 03:48:08 2013 -0800
top-level transforms work
---
index.js | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/index.js b/index.js
index 19da475..17f1a9a 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,7 @@
var fs = require('fs');
var path = require('path');
+var spawn = require('child_process').spawn;
+var parseShell = require('shell-quote').parse;
var browserResolve = require('browser-resolve');
var detective = require('detective');
@@ -19,6 +21,7 @@ module.exports = function (mains, opts) {
if (!opts) opts = {};
if (opts.cache === undefined) opts.cache = cache;
+ if (!opts.transform) opts.transform = [];
var resolve = opts.resolve || browserResolve;
opts.includeSource = true;
@@ -41,14 +44,41 @@ module.exports = function (mains, opts) {
visited[file] = true;
fs.readFile(file, 'utf8', function (err, src) {
- if (err) output.emit('error', err);
- else parseDeps(file, src);
+ if (err) return output.emit('error', err);
- if (--pending === 0) output.queue(null);
+ applyTransforms(file, src);
});
});
}
+ function applyTransforms (file, src) {
+ (function ap (trs) {
+ if (trs.length === 0) return done();
+ var tr = trs[0];
+ var cmd = parseShell(tr);
+
+ var ps = spawn(cmd[0], cmd.slice(1), {
+ cwd: path.dirname(file)
+ });
+ var data = '';
+ ps.stdout.on('data', function (buf) { data += buf });
+ ps.on('close', function (code) {
+ if (code !== 0) {
+ return output.emit('error',
+ 'process ' + tr + ' exited with code ' + code
+ );
+ }
+ src = data;
+ ap(trs.slice(1));
+ });
+ ps.stdin.end(src);
+ })(opts.transform.slice());
+
+ function done () {
+ parseDeps(file, src);
+ }
+ }
+
function parseDeps (file, src) {
var deps = detective(src);
var p = deps.length;
@@ -73,6 +103,7 @@ module.exports = function (mains, opts) {
rec.entry = true;
}
output.queue(rec);
+ if (--pending === 0) output.queue(null);
}
}
};
--
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