[Pkg-javascript-commits] [node-module-deps] 38/444: module test passes
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 09:47:41 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 a5d8f40b35695f4b0d553dccc50d06e345acb677
Author: James Halliday <mail at substack.net>
Date: Wed Feb 27 15:42:07 2013 -0800
module test passes
---
index.js | 64 +++++++++++++++++-----
.../g/node_modules/insert-ggg/index.js | 2 +-
.../tr_module/node_modules/insert-aaa/index.js | 2 +-
.../tr_module/node_modules/insert-bbb/index.js | 2 +-
test/tr_module.js | 2 +-
5 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/index.js b/index.js
index 582b396..eeeaec6 100644
--- a/index.js
+++ b/index.js
@@ -2,6 +2,7 @@ var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var parseShell = require('shell-quote').parse;
+var duplexer = require('duplexer');
var browserResolve = require('browser-resolve');
var detective = require('detective');
@@ -70,24 +71,16 @@ module.exports = function (mains, opts) {
(function ap (trs) {
if (trs.length === 0) return done();
- var tr = trs[0];
- var cmd = parseShell(tr);
+ var s = makeTransform(file, trs[0]);
+ s.on('error', output.emit.bind(output, 'error'));
- 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
- );
- }
+ s.on('data', function (buf) { data += buf });
+ s.on('end', function () {
src = data;
ap(trs.slice(1));
});
- ps.stdin.end(src);
+ s.end(src);
})(transf);
function done () {
@@ -122,4 +115,49 @@ module.exports = function (mains, opts) {
if (--pending === 0) output.queue(null);
}
}
+
+ function makeTransform (file, tr) {
+ if (/\s/.test(tr)) return cmdTransform(file, tr);
+
+ var tout = through(), tin = through();
+ tin.pause();
+
+ var parent = { id: file, filename: file, paths: [] };
+ resolve(tr, parent, function (err, res) {
+ if (err) return output.emit('error', err);
+ var t = res
+ ? require(res)(file)
+ : cmdTransform(file, tr)
+ ;
+ t.pipe(tout);
+ tin.pipe(t);
+ tin.resume();
+ });
+ return duplexer(tin, tout);
+ }
+
+ function cmdTransform (file, tr) {
+ var cmd = parseShell(tr);
+ var env = Object.create(process.env);
+ env._ = tr;
+ env.FILENAME = file;
+ var current = { id: file, filename: file, paths: [] };
+
+ var ps = spawn(cmd[0], cmd.slice(1), {
+ cwd: path.dirname(file),
+ env: env
+ });
+ var error = '';
+ ps.stderr.on('data', function (buf) { error += buf });
+ ps.on('close', function (code) {
+ if (code !== 0) {
+ return output.emit('error', [
+ 'process ' + tr + ' exited with code ' + code,
+ ' while parsing ' + file + '\n',
+ error.split('\n').join('\n ')
+ ].join(''));
+ }
+ });
+ return duplexer(ps.stdin, ps.stdout);
+ }
};
diff --git a/test/files/tr_module/node_modules/g/node_modules/insert-ggg/index.js b/test/files/tr_module/node_modules/g/node_modules/insert-ggg/index.js
index 859c662..d0e4862 100644
--- a/test/files/tr_module/node_modules/g/node_modules/insert-ggg/index.js
+++ b/test/files/tr_module/node_modules/g/node_modules/insert-ggg/index.js
@@ -2,6 +2,6 @@ var through = require('through');
module.exports = function (file) {
return through(function (buf) {
- this.queue(String(buf).replace(/GGG/g, '111');
+ this.queue(String(buf).replace(/GGG/g, '111'));
});
};
diff --git a/test/files/tr_module/node_modules/insert-aaa/index.js b/test/files/tr_module/node_modules/insert-aaa/index.js
index 48fbf71..0394d4e 100644
--- a/test/files/tr_module/node_modules/insert-aaa/index.js
+++ b/test/files/tr_module/node_modules/insert-aaa/index.js
@@ -2,6 +2,6 @@ var through = require('through');
module.exports = function (file) {
return through(function (buf) {
- this.queue(String(buf).replace(/AAA/g, '5');
+ this.queue(String(buf).replace(/AAA/g, '5'));
});
};
diff --git a/test/files/tr_module/node_modules/insert-bbb/index.js b/test/files/tr_module/node_modules/insert-bbb/index.js
index 43df177..d48906a 100644
--- a/test/files/tr_module/node_modules/insert-bbb/index.js
+++ b/test/files/tr_module/node_modules/insert-bbb/index.js
@@ -2,6 +2,6 @@ var through = require('through');
module.exports = function (file) {
return through(function (buf) {
- this.queue(String(buf).replace(/BBB/g, '50');
+ this.queue(String(buf).replace(/BBB/g, '50'));
});
};
diff --git a/test/tr_module.js b/test/tr_module.js
index f4ca9c6..87f5552 100644
--- a/test/tr_module.js
+++ b/test/tr_module.js
@@ -5,7 +5,7 @@ var packer = require('browser-pack');
test('transform', function (t) {
t.plan(3);
- var p = mdeps(__dirname + '/files/tr/main.js', {
+ var p = mdeps(__dirname + '/files/tr_module/main.js', {
transform: [ 'insert-aaa', 'insert-bbb' ]
});
var pack = packer();
--
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