cross-spawn-cb 0.5.6 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -24
- package/lib/index.js +1 -3
- package/lib/spawn-sync/spawn-sync.js +19 -60
- package/lib/spawn-sync/worker.js +51 -41
- package/lib/spawnCallback.js +2 -1
- package/lib/spawnSyncCallback.js +4 -3
- package/package.json +6 -7
- package/lib/json-buffer/LICENSE +0 -22
- package/lib/json-buffer/README.md +0 -1
- package/lib/json-buffer/index.js +0 -49
package/LICENSE
CHANGED
|
@@ -43,30 +43,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
43
43
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
44
44
|
THE SOFTWARE.
|
|
45
45
|
|
|
46
|
-
---------------json-buffer-----------------------
|
|
47
|
-
Copyright (c) 2013 Dominic Tarr
|
|
48
|
-
|
|
49
|
-
Permission is hereby granted, free of charge,
|
|
50
|
-
to any person obtaining a copy of this software and
|
|
51
|
-
associated documentation files (the "Software"), to
|
|
52
|
-
deal in the Software without restriction, including
|
|
53
|
-
without limitation the rights to use, copy, modify,
|
|
54
|
-
merge, publish, distribute, sublicense, and/or sell
|
|
55
|
-
copies of the Software, and to permit persons to whom
|
|
56
|
-
the Software is furnished to do so,
|
|
57
|
-
subject to the following conditions:
|
|
58
|
-
|
|
59
|
-
The above copyright notice and this permission notice
|
|
60
|
-
shall be included in all copies or substantial portions of the Software.
|
|
61
|
-
|
|
62
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
63
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
64
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
65
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
|
66
|
-
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
67
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
68
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
69
|
-
|
|
70
46
|
---------------path-key-----------------------
|
|
71
47
|
MIT License
|
|
72
48
|
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
require('./polyfills');
|
|
2
2
|
module.exports = require('./spawnCallback');
|
|
3
3
|
module.exports.sync = require('./spawnSyncCallback');
|
|
4
|
-
|
|
5
|
-
var pathKey = require('./path-key');
|
|
6
|
-
module.exports.pathKey = pathKey.default || pathKey;
|
|
4
|
+
module.exports.pathKey = require('./path-key').default;
|
|
@@ -5,76 +5,35 @@ var path = require('path');
|
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var tmpdir = require('os').tmpdir || require('os-shim').tmpdir;
|
|
7
7
|
var cp = require('child_process');
|
|
8
|
-
var JSON = require('
|
|
9
|
-
var sleep =
|
|
8
|
+
var JSON = require('json-buffer');
|
|
9
|
+
var sleep = require('thread-sleep-compat');
|
|
10
|
+
var suffix = require('temp-suffix')
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function randomFileName(name) {
|
|
14
|
-
function randomHash(count) {
|
|
15
|
-
if (count === 1) return parseInt(16 * Math.random(), 10).toString(16);
|
|
16
|
-
else {
|
|
17
|
-
var hash = '';
|
|
18
|
-
for (var i = 0; i < count; i++) hash += randomHash(1);
|
|
19
|
-
return hash;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return temp + '_' + name + '_' + String(process.pid) + randomHash(20);
|
|
24
|
-
}
|
|
25
|
-
function unlink(filename) {
|
|
26
|
-
try {
|
|
27
|
-
fs.unlinkSync(filename);
|
|
28
|
-
} catch (ex) {
|
|
29
|
-
if (ex.code !== 'ENOENT') throw ex;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function tryUnlink(filename) {
|
|
33
|
-
// doesn't matter too much if we fail to delete temp files
|
|
12
|
+
function unlinkSafe(filename) {
|
|
34
13
|
try {
|
|
35
14
|
fs.unlinkSync(filename);
|
|
36
15
|
} catch (e) {}
|
|
37
16
|
}
|
|
38
17
|
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
var finished = randomFileName('finished');
|
|
42
|
-
unlink(finished);
|
|
43
|
-
if (process.platform === 'win32') {
|
|
44
|
-
cmd = cmd + '& echo "finished" > ' + finished;
|
|
45
|
-
} else {
|
|
46
|
-
cmd = cmd + '; echo "finished" > ' + finished;
|
|
47
|
-
}
|
|
48
|
-
cp.exec(cmd);
|
|
49
|
-
|
|
50
|
-
while (!fs.existsSync(finished)) {
|
|
51
|
-
// busy wait
|
|
52
|
-
sleep(200);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
tryUnlink(finished);
|
|
56
|
-
|
|
57
|
-
return 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
module.exports = spawnSyncFallback;
|
|
61
|
-
function spawnSyncFallback(cmd, commandArgs, options) {
|
|
62
|
-
var args = [];
|
|
63
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
64
|
-
args.push(arguments[i]);
|
|
65
|
-
}
|
|
18
|
+
module.exports = function spawnSyncFallback(/*cmd, commandArgs, options*/) {
|
|
19
|
+
var args = Array.prototype.slice.call(arguments, 0);
|
|
66
20
|
|
|
67
|
-
// node.js script to run the command
|
|
68
|
-
var worker = path.normalize(__dirname + '/worker.js');
|
|
69
21
|
// location to store arguments
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
|
|
22
|
+
var temp = tmpdir();
|
|
23
|
+
var input = path.join(temp, suffix('ss-input'));
|
|
24
|
+
var output = path.join(temp, suffix('ss-output'));
|
|
73
25
|
|
|
74
26
|
fs.writeFileSync(input, JSON.stringify(args));
|
|
75
|
-
|
|
27
|
+
unlinkSafe(output);
|
|
28
|
+
|
|
29
|
+
var worker = path.normalize(__dirname + '/worker.js');
|
|
30
|
+
cp.exec('"' + process.execPath + '" "' + worker + '" "' + input + '" "' + output + '"');
|
|
31
|
+
while (!fs.existsSync(output)) {
|
|
32
|
+
// busy wait
|
|
33
|
+
sleep(200);
|
|
34
|
+
}
|
|
76
35
|
var res = JSON.parse(fs.readFileSync(output, 'utf8'));
|
|
77
|
-
|
|
78
|
-
|
|
36
|
+
unlinkSafe(input);
|
|
37
|
+
unlinkSafe(output);
|
|
79
38
|
return res;
|
|
80
39
|
}
|
package/lib/spawn-sync/worker.js
CHANGED
|
@@ -5,56 +5,66 @@ require('../polyfills');
|
|
|
5
5
|
|
|
6
6
|
var spawn = require('../cross-spawn').spawn;
|
|
7
7
|
var fs = require('fs');
|
|
8
|
-
var
|
|
9
|
-
var JSON = require('../json-buffer');
|
|
8
|
+
var JSON = require('json-buffer');
|
|
10
9
|
|
|
11
10
|
var inputFile = process.argv[2];
|
|
12
11
|
var outputFile = process.argv[3];
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
function output(result) {
|
|
14
|
+
fs.writeFile(outputFile+'.tmp', JSON.stringify(result), function() {
|
|
15
|
+
fs.rename(outputFile+'.tmp', outputFile, function() {
|
|
16
|
+
process.exit(0)
|
|
17
|
+
})
|
|
18
|
+
});
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
fs.readFile(inputFile, 'utf8', function(err, contents) {
|
|
22
|
+
if (err) return output({ error: err.message });
|
|
23
|
+
var args = JSON.parse(contents);
|
|
24
|
+
|
|
25
|
+
var child = spawn.apply(null, args);
|
|
26
|
+
var options = args[2] && typeof args[2] === 'object' ? args[2] : args[1] && typeof args[1] === 'object' && !Array.isArray(args[1]) ? args[1] : {};
|
|
21
27
|
|
|
22
|
-
var stdout, stderr;
|
|
23
|
-
child.stdout
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
stdout
|
|
28
|
+
var stdout, stderr;
|
|
29
|
+
if (child.stdout) {
|
|
30
|
+
stdout = [];
|
|
31
|
+
child.stdout.on('data', function(chunk) {
|
|
32
|
+
stdout.push(chunk);
|
|
27
33
|
})
|
|
28
|
-
|
|
29
|
-
child.stderr
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
stderr
|
|
34
|
+
}
|
|
35
|
+
if (child.stderr) {
|
|
36
|
+
stderr = [];
|
|
37
|
+
child.stderr.on('data', function(chunk) {
|
|
38
|
+
stderr.push(chunk);
|
|
33
39
|
})
|
|
34
|
-
);
|
|
35
|
-
child.on('error', function (err) {
|
|
36
|
-
output({ pid: child.pid, error: err.message });
|
|
37
|
-
});
|
|
38
|
-
child.on('close', function (status, signal) {
|
|
39
|
-
if (options.encoding && options.encoding !== 'buffer') {
|
|
40
|
-
stdout = stdout.toString(options.encoding);
|
|
41
|
-
stderr = stderr.toString(options.encoding);
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
pid: child.pid,
|
|
45
|
-
output: [null, stdout, stderr],
|
|
46
|
-
stdout: stdout,
|
|
47
|
-
stderr: stderr,
|
|
48
|
-
status: status,
|
|
49
|
-
signal: signal,
|
|
41
|
+
child.on('error', function (err) {
|
|
42
|
+
output({ pid: child.pid, error: err.message });
|
|
50
43
|
});
|
|
51
|
-
|
|
44
|
+
child.on('close', function (status, signal) {
|
|
45
|
+
if (stdout) stdout = Buffer.concat(stdout)
|
|
46
|
+
if (stderr) stderr = Buffer.concat(stderr)
|
|
52
47
|
|
|
53
|
-
if (options.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
if (options.encoding && options.encoding !== 'buffer') {
|
|
49
|
+
stdout = stdout.toString(options.encoding);
|
|
50
|
+
stderr = stderr.toString(options.encoding);
|
|
51
|
+
}
|
|
52
|
+
output({
|
|
53
|
+
pid: child.pid,
|
|
54
|
+
output: [null, stdout, stderr],
|
|
55
|
+
stdout: stdout,
|
|
56
|
+
stderr: stderr,
|
|
57
|
+
status: status,
|
|
58
|
+
signal: signal,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (options.timeout && typeof options.timeout === 'number') {
|
|
63
|
+
setTimeout(function () {
|
|
64
|
+
child.kill(options.killSignal || 'SIGTERM');
|
|
65
|
+
}, options.timeout);
|
|
66
|
+
}
|
|
67
|
+
if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {
|
|
68
|
+
child.stdin.end(options.input);
|
|
69
|
+
}
|
|
70
|
+
})
|
package/lib/spawnCallback.js
CHANGED
|
@@ -39,9 +39,10 @@ module.exports = function spawnCallback(command, args, options, callback) {
|
|
|
39
39
|
if (err.code !== 'OK') return callback(err);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
cp.on('close', function close(status) {
|
|
42
|
+
cp.on('close', function close(status, signal) {
|
|
43
43
|
nextTick(function closeNextTick() {
|
|
44
44
|
result.status = status;
|
|
45
|
+
result.signal = signal;
|
|
45
46
|
var err = result.status ? new Error('Non-zero exit code: ' + result.status) : null;
|
|
46
47
|
if (result.stderr && result.stderr.length) {
|
|
47
48
|
err = err || new Error('stderr has content');
|
package/lib/spawnSyncCallback.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
var assign = require('just-extend');
|
|
1
2
|
var spawnSync = require('./cross-spawn').sync;
|
|
2
3
|
|
|
3
4
|
module.exports = function spawnSyncCallback(command, args, options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var result = spawnSync(command, args, {
|
|
5
|
+
var syncOptions = assign({}, options || {}, {
|
|
6
|
+
env: options.env || process.env,
|
|
7
7
|
stdio: 'pipe',
|
|
8
8
|
encoding: 'utf-8',
|
|
9
9
|
});
|
|
10
|
+
var result = spawnSync(command, args, syncOptions);
|
|
10
11
|
if (result.stdout && (options.stdout === 'inherit' || options.stdio === 'inherit')) {
|
|
11
12
|
process.stdout.write(result.stdout);
|
|
12
13
|
result.stdout = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-spawn-cb",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "Cross spawn with a completion callback",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cross-spawn",
|
|
@@ -18,20 +18,21 @@
|
|
|
18
18
|
"lint": "eslint .",
|
|
19
19
|
"prepublishOnly": "dtd \"npm run lint\" \"depcheck\"",
|
|
20
20
|
"test": "mocha-compat test/spec/**/*.test.js",
|
|
21
|
-
"test:engines": "nvu engines npm test",
|
|
22
21
|
"build": "rollup -c config/rollup.pk.config.js && rollup -c config/rollup.cs.config.js"
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
|
25
24
|
"lib"
|
|
26
25
|
],
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"concat-stream": "^1.6.2",
|
|
29
27
|
"cross-spawn": "^7.0.3",
|
|
28
|
+
"json-buffer": "^3.0.1",
|
|
30
29
|
"just-extend": "^6.0.1",
|
|
31
30
|
"next-tick": "^1.1.0",
|
|
32
31
|
"object-keys": "^1.1.1",
|
|
33
32
|
"once": "^1.4.0",
|
|
34
|
-
"os-shim": "^0.1.3"
|
|
33
|
+
"os-shim": "^0.1.3",
|
|
34
|
+
"temp-suffix": "^0.1.0",
|
|
35
|
+
"thread-sleep-compat": "^0.0.1"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@babel/preset-env": "^7.18.6",
|
|
@@ -40,15 +41,13 @@
|
|
|
40
41
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
41
42
|
"@typescript-eslint/parser": "^5.30.0",
|
|
42
43
|
"depcheck": "^1.4.3",
|
|
43
|
-
"dis-dat": "^0.1.
|
|
44
|
+
"dis-dat": "^0.1.7",
|
|
44
45
|
"eslint": "^8.18.0",
|
|
45
46
|
"eslint-config-prettier": "^8.5.0",
|
|
46
47
|
"eslint-config-standard": "^17.0.0",
|
|
47
48
|
"eslint-plugin-import": "^2.26.0",
|
|
48
|
-
"eslint-plugin-node": "^11.1.0",
|
|
49
49
|
"eslint-plugin-promise": "^6.0.0",
|
|
50
50
|
"mocha-compat": "^3.5.5",
|
|
51
|
-
"node-version-use": "^0.2.3",
|
|
52
51
|
"prettier": "^2.7.1",
|
|
53
52
|
"rollup": "^2.75.7",
|
|
54
53
|
"rollup-plugin-babel": "^4.4.0",
|
package/lib/json-buffer/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2013 Dominic Tarr
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge,
|
|
4
|
-
to any person obtaining a copy of this software and
|
|
5
|
-
associated documentation files (the "Software"), to
|
|
6
|
-
deal in the Software without restriction, including
|
|
7
|
-
without limitation the rights to use, copy, modify,
|
|
8
|
-
merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom
|
|
10
|
-
the Software is furnished to do so,
|
|
11
|
-
subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice
|
|
14
|
-
shall be included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
18
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
|
20
|
-
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Code based on https://github.com/dominictarr/json-buffer but adapted to be simpler to run in a purely node.js environment
|
package/lib/json-buffer/index.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
//TODO: handle reviver/dehydrate function like normal
|
|
4
|
-
//and handle indentation, like normal.
|
|
5
|
-
//if anyone needs this... please send pull request.
|
|
6
|
-
|
|
7
|
-
exports.stringify = function stringify(o) {
|
|
8
|
-
if (o && Buffer.isBuffer(o)) return JSON.stringify(':base64:' + o.toString('base64'));
|
|
9
|
-
|
|
10
|
-
if (o && o.toJSON) o = o.toJSON();
|
|
11
|
-
|
|
12
|
-
if (o && 'object' === typeof o) {
|
|
13
|
-
var s = '';
|
|
14
|
-
var array = Array.isArray(o);
|
|
15
|
-
s = array ? '[' : '{';
|
|
16
|
-
var first = true;
|
|
17
|
-
|
|
18
|
-
for (var k in o) {
|
|
19
|
-
var ignore = 'function' == typeof o[k] || (!array && 'undefined' === typeof o[k]);
|
|
20
|
-
if (Object.hasOwnProperty.call(o, k) && !ignore) {
|
|
21
|
-
if (!first) s += ',';
|
|
22
|
-
first = false;
|
|
23
|
-
if (array) {
|
|
24
|
-
s += stringify(o[k]);
|
|
25
|
-
} else if (o[k] !== void 0) {
|
|
26
|
-
s += stringify(k) + ':' + stringify(o[k]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
s += array ? ']' : '}';
|
|
32
|
-
|
|
33
|
-
return s;
|
|
34
|
-
} else if ('string' === typeof o) {
|
|
35
|
-
return JSON.stringify(/^:/.test(o) ? ':' + o : o);
|
|
36
|
-
} else if ('undefined' === typeof o) {
|
|
37
|
-
return 'null';
|
|
38
|
-
} else return JSON.stringify(o);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
exports.parse = function (s) {
|
|
42
|
-
return JSON.parse(s, function (key, value) {
|
|
43
|
-
if ('string' === typeof value) {
|
|
44
|
-
if (/^:base64:/.test(value)) return new Buffer(value.substring(8), 'base64');
|
|
45
|
-
else return /^:/.test(value) ? value.substring(1) : value;
|
|
46
|
-
}
|
|
47
|
-
return value;
|
|
48
|
-
});
|
|
49
|
-
};
|