Commit ed4b5d28 authored by Ross Gammon's avatar Ross Gammon

Imported Upstream version 2.2.5

parent 25131a07
{
"root": true,
"extends": [
"@satazor/eslint-config/es5",
"@satazor/eslint-config/addons/node"
]
}
\ No newline at end of file
{
"predef": [
"console",
"describe",
"it",
"after",
"afterEach",
"before",
"beforeEach"
],
"indent": 4,
"node": true,
"devel": true,
"bitwise": false,
"curly": false,
"eqeqeq": true,
"forin": false,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": true,
"plusplus": false,
"regexp": false,
"undef": true,
"unused": "vars",
"quotmark": "single",
"strict": false,
"trailing": true,
"camelcase": true,
"asi": false,
"boss": true,
"debug": false,
"eqnull": true,
"es5": false,
"esnext": false,
"evil": false,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": true,
"multistr": false,
"onecase": true,
"regexdash": false,
"scripturl": false,
"smarttabs": false,
"shadow": false,
"sub": false,
"supernew": true,
"validthis": false,
"nomen": false,
"white": true
}
......@@ -2,7 +2,6 @@ language: node_js
node_js:
- '0.10'
- '0.12'
- 'iojs-1'
- 'iojs-2'
- 'iojs-3'
- '4'
- '5'
- '6'
......@@ -6,9 +6,9 @@
[downloads-image]:http://img.shields.io/npm/dm/cross-spawn-async.svg
[npm-image]:http://img.shields.io/npm/v/cross-spawn-async.svg
[travis-url]:https://travis-ci.org/IndigoUnited/node-cross-spawn-async
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-cross-spawn-async.svg
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-cross-spawn-async/master.svg
[appveyor-url]:https://ci.appveyor.com/project/satazor/node-cross-spawn-async
[appveyor-image]:https://img.shields.io/appveyor/ci/satazor/node-cross-spawn-async.svg
[appveyor-image]:https://img.shields.io/appveyor/ci/satazor/node-cross-spawn-async/master.svg
[david-dm-url]:https://david-dm.org/IndigoUnited/node-cross-spawn-async
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-cross-spawn-async.svg
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-cross-spawn-async#info=devDependencies
......@@ -16,6 +16,8 @@
A cross platform solution to node's spawn.
**This module is deprecated, use [cross-spawn](https://github.com/IndigoUnited/node-cross-spawn) instead which no longer requires a build toolchain.**
## Installation
......@@ -42,7 +44,7 @@ Exactly the same way as node's [`spawn`](https://nodejs.org/api/child_process.ht
```javascript
var spawn = require('cross-spawn-async');
var process = spawn('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });
var child = spawn('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });
```
......
......@@ -13,10 +13,9 @@ environment:
matrix:
- nodejs_version: 0.10
- nodejs_version: 0.12
- nodejs_version: 1
- nodejs_version: 2
- nodejs_version: 3
- nodejs_version: 4
- nodejs_version: 5
- nodejs_version: 6
# get the latest stable version of Node 0.STABLE.latest
install:
......
var cp = require('child_process');
var parse = require('./lib/parse');
'use strict';
var cp = require('child_process');
var parse = require('./lib/parse');
var enoent = require('./lib/enoent');
function spawn(command, args, options) {
......@@ -19,7 +21,7 @@ function spawn(command, args, options) {
return spawned;
}
module.exports = spawn;
module.exports = spawn;
module.exports.spawn = spawn;
module.exports._parse = parse;
module.exports._enoent = enoent;
......@@ -47,5 +47,5 @@ function verifyENOENT(status, parsed, syscall) {
}
module.exports.hookChildProcess = hookChildProcess;
module.exports.verifyENOENT = verifyENOENT;
module.exports.notFoundError = notFoundError;
module.exports.verifyENOENT = verifyENOENT;
module.exports.notFoundError = notFoundError;
var fs = require('fs');
var LRU = require('lru-cache');
'use strict';
var fs = require('fs');
var LRU = require('lru-cache');
var resolveCommand = require('./resolveCommand');
var mixIn = require('./util/mixIn');
var isWin = process.platform === 'win32';
var shebangCache = LRU({ max: 50, maxAge: 30 * 1000 }); // Cache just for 30sec
var isWin = process.platform === 'win32';
var shebangCache = new LRU({ max: 50, maxAge: 30 * 1000 }); // Cache just for 30sec
function readShebang(command) {
var buffer;
......@@ -24,10 +25,10 @@ function readShebang(command) {
fd = fs.openSync(command, 'r');
fs.readSync(fd, buffer, 0, 150, 0);
fs.closeSync(fd);
} catch (e) {}
} catch (e) { /* empty */ }
// Check if it is a shebang
match = buffer.toString().trim().match(/\#\!(.+)/i);
match = buffer.toString().trim().match(/#!(.+)/i);
if (match) {
shebang = match[1].replace(/\/usr\/bin\/env\s+/i, ''); // Remove /usr/bin/env
......@@ -46,11 +47,11 @@ function escapeArg(arg, quote) {
// If we are not going to quote the argument,
// escape shell metacharacters, including double and single quotes:
if (!quote) {
arg = arg.replace(/([\(\)%!\^<>&|;,"' ])/g, '^$1');
arg = arg.replace(/([\(\)%!\^<>&|;,"'\s])/g, '^$1');
} else {
// Sequence of backslashes followed by a double quote:
// double up all the backslashes and escape the double quote
arg = arg.replace(/(\\*)"/gi, '$1$1\\"');
arg = arg.replace(/(\\*)"/g, '$1$1\\"');
// Sequence of backslashes followed by the end of the string
// (which will become a double quote later):
......@@ -69,11 +70,11 @@ function escapeArg(arg, quote) {
function escapeCommand(command) {
// Do not escape if this command is not dangerous..
// We do this so that commands like "echo" or "ifconfig" work
// Quoting them, will make them unnaccessible
// Quoting them, will make them unaccessible
return /^[a-z0-9_-]+$/i.test(command) ? command : escapeArg(command, true);
}
function parseCall(command, args, options) {
function parse(command, args, options) {
var shebang;
var applyQuotes;
var file;
......@@ -86,7 +87,7 @@ function parseCall(command, args, options) {
}
args = args ? args.slice(0) : []; // Clone array to avoid changing the original
options = mixIn({}, options);
options = options || {};
original = command;
if (isWin) {
......@@ -120,8 +121,8 @@ function parseCall(command, args, options) {
args: args,
options: options,
file: file,
original: original
original: original,
};
}
module.exports = parseCall;
module.exports = parse;
'use strict';
var path = require('path');
var path = require('path');
var which = require('which');
var LRU = require('lru-cache');
var LRU = require('lru-cache');
var resolveCache = LRU({ max: 50, maxAge: 30 * 1000 }); // Cache just for 30sec
var commandCache = new LRU({ max: 50, maxAge: 30 * 1000 }); // Cache just for 30sec
var hasSepInPathRegExp = new RegExp(process.platform === 'win32' ? /[\/\\]/ : /\//);
function resolveCommand(command, noExtension) {
var resolved;
// If command looks like a file path, make it absolute to make it canonical
// and also to circuvent a bug in which, see: https://github.com/npm/node-which/issues/33
if (hasSepInPathRegExp.test(command)) {
command = path.resolve(command);
}
noExtension = !!noExtension;
resolved = resolveCache.get(command + '!' + noExtension);
resolved = commandCache.get(command + '!' + noExtension);
// Check if its resolved in the cache
if (resolveCache.has(command)) {
return resolveCache.get(command);
if (commandCache.has(command)) {
return commandCache.get(command);
}
try {
resolved = !noExtension ?
which.sync(command) :
which.sync(command, { pathExt: path.delimiter + (process.env.PATHEXT || '') });
} catch (e) {}
which.sync(command, { pathExt: path.delimiter + (process.env.PATHEXT || '') });
} catch (e) { /* empty */ }
resolveCache.set(command + '!' + noExtension, resolved);
commandCache.set(command + '!' + noExtension, resolved);
return resolved;
}
......
'use strict';
function mixIn(target, source) {
var key;
// No need to check for hasOwnProperty.. this is used
// just in plain objects
for (key in source) {
target[key] = source[key];
}
return target;
}
module.exports = mixIn;
{
"name": "cross-spawn-async",
"version": "2.1.9",
"version": "2.2.5",
"description": "Cross platform child_process#spawn",
"main": "index.js",
"scripts": {
"test": "node test/prepare && mocha --bail test/test"
"test": "node test/prepare && mocha --bail test/test",
"lint": "eslint '{*.js,lib/**/*.js,test/**/*.js}'"
},
"bugs": {
"url": "https://github.com/IndigoUnited/node-cross-spawn-async/issues/"
......@@ -31,13 +32,15 @@
"license": "MIT",
"dependencies": {
"lru-cache": "^4.0.0",
"which": "^1.2.4"
"which": "^1.2.8"
},
"devDependencies": {
"@satazor/eslint-config": "^3.0.0",
"eslint": "^3.0.0",
"expect.js": "^0.3.0",
"glob": "^7.0.0",
"mkdirp": "^0.5.1",
"mocha": "^2.2.5",
"mocha": "^3.0.2",
"rimraf": "^2.5.0"
}
}
{
"env": {
"mocha": true
},
"rules": {
"no-invalid-this": 0
}
}
\ No newline at end of file
'use strict';
var args = process.argv.slice(2);
args.forEach(function (arg, index) {
......
'use strict';
process.exit(25);
#!/usr/bin/env node
'use strict';
process.stdout.write('shebang works!');
'use strict';
var glob = require('glob');
var fs = require('fs');
var fs = require('fs');
var fixturesDir = __dirname + '/fixtures';
......@@ -8,7 +10,7 @@ glob.sync('prepare_*', { cwd: __dirname + '/fixtures' }).forEach(function (file)
var finalFile = file.replace(/^prepare_/, '').replace(/\.sh$/, '');
fs.writeFileSync(fixturesDir + '/' + finalFile, contents);
fs.chmodSync(fixturesDir + '/' + finalFile, 0777);
fs.chmodSync(fixturesDir + '/' + finalFile, parseInt('0777', 8));
process.stdout.write('Copied "' + file + '" to "' + finalFile + '"\n');
});
'use strict';
var path = require('path');
var fs = require('fs');
var which = require('which');
var rimraf = require('rimraf');
var mkdirp = require('mkdirp');
var expect = require('expect.js');
var path = require('path');
var fs = require('fs');
var which = require('which');
var rimraf = require('rimraf');
var mkdirp = require('mkdirp');
var expect = require('expect.js');
var buffered = require('./util/buffered');
var spawn = require('../');
var spawn = require('../');
var isWin = process.platform === 'win32';
var isWin = process.platform === 'win32';
// Fix AppVeyor tests because Git bin folder is in PATH and it has a "echo" program there
if (isWin) {
......@@ -32,7 +32,7 @@ describe('cross-spawn-async', function () {
// Give it some time, RIMRAF was giving problems on windows
this.timeout(10000);
rimraf(__dirname + '/tmp', function (err) {
rimraf(__dirname + '/tmp', function () {
// Ignore errors, RIMRAF was giving problems on windows
next(null);
});
......@@ -66,7 +66,7 @@ describe('cross-spawn-async', function () {
var file = __dirname + '/fixtures/shebang_noenv';
fs.writeFileSync(file, '#!' + nodejs + '\n\nprocess.stdout.write(\'shebang works!\');', {
mode: parseInt('0777', 8)
mode: parseInt('0777', 8),
});
buffered(file, function (err, data, code) {
......@@ -90,7 +90,24 @@ describe('cross-spawn-async', function () {
it('should support shebang in executables with relative path', function (next) {
var executable = './' + path.relative(process.cwd(), __dirname + '/fixtures/shebang');
fs.writeFileSync(__dirname + '/tmp/shebang', '#!/usr/bin/env node\n\nprocess.stdout.write(\'yeah\');', { mode: parseInt('0777', 8) });
fs.writeFileSync(__dirname + '/tmp/shebang', '#!/usr/bin/env node\n\nprocess.stdout.write(\'yeah\');',
{ mode: parseInt('0777', 8) });
process.env.PATH = path.normalize(__dirname + '/tmp/') + path.delimiter + process.env.PATH;
buffered(executable, function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
expect(data).to.equal('shebang works!');
next();
});
});
it('should support shebang in executables with relative path that starts with `..`', function (next) {
var executable = '../' + path.basename(process.cwd()) + '/' + path.relative(process.cwd(), __dirname + '/fixtures/shebang');
fs.writeFileSync(__dirname + '/tmp/shebang', '#!/usr/bin/env node\n\nprocess.stdout.write(\'yeah\');',
{ mode: parseInt('0777', 8) });
process.env.PATH = path.normalize(__dirname + '/tmp/') + path.delimiter + process.env.PATH;
buffered(executable, function (err, data, code) {
......@@ -103,7 +120,8 @@ describe('cross-spawn-async', function () {
});
it('should support shebang in executables with extensions', function (next) {
fs.writeFileSync(__dirname + '/tmp/shebang.js', '#!/usr/bin/env node\n\nprocess.stdout.write(\'shebang with extension\');', { mode: parseInt('0777', 8) });
fs.writeFileSync(__dirname + '/tmp/shebang.js', '#!/usr/bin/env node\n\nprocess.stdout.write(\'shebang with extension\');',
{ mode: parseInt('0777', 8) });
process.env.PATH = path.normalize(__dirname + '/tmp/') + path.delimiter + process.env.PATH;
buffered(__dirname + '/tmp/shebang.js', function (err, data, code) {
......@@ -154,12 +172,26 @@ describe('cross-spawn-async', function () {
});
});
it('should handle arguments with quotes', function (next) {
buffered('node', [
__dirname + '/fixtures/echo',
'"foo"',
'foo"bar"foo',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
expect(data).to.equal('"foo"\nfoo"bar"foo');
next();
});
});
it('should handle empty arguments', function (next) {
buffered('node', [
__dirname + '/fixtures/echo',
'foo',
'',
'bar'
'bar',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -168,7 +200,7 @@ describe('cross-spawn-async', function () {
buffered('echo', [
'foo',
'',
'bar'
'bar',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -182,7 +214,7 @@ describe('cross-spawn-async', function () {
it('should handle non-string arguments', function (next) {
buffered('node', [
__dirname + '/fixtures/echo',
1234
1234,
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -196,7 +228,7 @@ describe('cross-spawn-async', function () {
buffered('node', [
__dirname + '/fixtures/echo',
'I am',
'André Cruz'
'André Cruz',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -211,7 +243,7 @@ describe('cross-spawn-async', function () {
__dirname + '/fixtures/echo',
'foo',
'\\"',
'bar'
'bar',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -226,7 +258,7 @@ describe('cross-spawn-async', function () {
__dirname + '/fixtures/echo',
'foo',
'bar\\',
'baz'
'baz',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -251,7 +283,7 @@ describe('cross-spawn-async', function () {
'|;',
'foo',
', ',
'foo'
'foo',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -280,7 +312,7 @@ describe('cross-spawn-async', function () {
'|;',
'foo',
', ',
'foo'
'foo',
], function (err, data, code) {
expect(err).to.not.be.ok();
expect(code).to.be(0);
......@@ -408,7 +440,7 @@ describe('cross-spawn-async', function () {
this.timeout(5000);
spawned = spawn(__dirname + '/fixtures/shebang_enoent')
.on('error', function (err) {
.on('error', function () {
spawned.removeAllListeners();
clearTimeout(timeout);
next(new Error('Should not emit error'));
......@@ -433,7 +465,7 @@ describe('cross-spawn-async', function () {
this.timeout(5000);
spawned = spawn(__dirname + '/fixtures/exit1')
.on('error', function (err) {
.on('error', function () {
spawned.removeAllListeners();
clearTimeout(timeout);
next(new Error('Should not emit error'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment