summaryrefslogtreecommitdiff
path: root/node_modules/spawn-sync/lib
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-03 02:37:42 -0700
committer8cy <[email protected]>2020-04-03 02:37:42 -0700
commit60867fb030bae582082340ead7dbc7efdc2f5398 (patch)
tree4c6a7356351be2e4914e15c4703172597c45656e /node_modules/spawn-sync/lib
parentcommenting (diff)
downloads5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz
s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/spawn-sync/lib')
-rw-r--r--node_modules/spawn-sync/lib/json-buffer/LICENSE22
-rw-r--r--node_modules/spawn-sync/lib/json-buffer/README.md1
-rw-r--r--node_modules/spawn-sync/lib/json-buffer/index.js56
-rw-r--r--node_modules/spawn-sync/lib/spawn-sync.js89
-rw-r--r--node_modules/spawn-sync/lib/worker.js56
5 files changed, 224 insertions, 0 deletions
diff --git a/node_modules/spawn-sync/lib/json-buffer/LICENSE b/node_modules/spawn-sync/lib/json-buffer/LICENSE
new file mode 100644
index 0000000..f04be4e
--- /dev/null
+++ b/node_modules/spawn-sync/lib/json-buffer/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Dominic Tarr
+
+Permission is hereby granted, free of charge,
+to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to
+deal in the Software without restriction, including
+without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom
+the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file
diff --git a/node_modules/spawn-sync/lib/json-buffer/README.md b/node_modules/spawn-sync/lib/json-buffer/README.md
new file mode 100644
index 0000000..5fd5b29
--- /dev/null
+++ b/node_modules/spawn-sync/lib/json-buffer/README.md
@@ -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 \ No newline at end of file
diff --git a/node_modules/spawn-sync/lib/json-buffer/index.js b/node_modules/spawn-sync/lib/json-buffer/index.js
new file mode 100644
index 0000000..d79314e
--- /dev/null
+++ b/node_modules/spawn-sync/lib/json-buffer/index.js
@@ -0,0 +1,56 @@
+
+'use strict';
+
+//TODO: handle reviver/dehydrate function like normal
+//and handle indentation, like normal.
+//if anyone needs this... please send pull request.
+
+exports.stringify = function stringify (o) {
+ if(o && Buffer.isBuffer(o))
+ return JSON.stringify(':base64:' + o.toString('base64'))
+
+ if(o && o.toJSON)
+ o = o.toJSON()
+
+ if(o && 'object' === typeof o) {
+ var s = ''
+ var array = Array.isArray(o)
+ s = array ? '[' : '{'
+ var first = true
+
+ for(var k in o) {
+ var ignore = 'function' == typeof o[k] || (!array && 'undefined' === typeof o[k])
+ if(Object.hasOwnProperty.call(o, k) && !ignore) {
+ if(!first)
+ s += ','
+ first = false
+ if (array) {
+ s += stringify(o[k])
+ } else if (o[k] !== void(0)) {
+ s += stringify(k) + ':' + stringify(o[k])
+ }
+ }
+ }
+
+ s += array ? ']' : '}'
+
+ return s
+ } else if ('string' === typeof o) {
+ return JSON.stringify(/^:/.test(o) ? ':' + o : o)
+ } else if ('undefined' === typeof o) {
+ return 'null';
+ } else
+ return JSON.stringify(o)
+}
+
+exports.parse = function (s) {
+ return JSON.parse(s, function (key, value) {
+ if('string' === typeof value) {
+ if(/^:base64:/.test(value))
+ return new Buffer(value.substring(8), 'base64')
+ else
+ return /^:/.test(value) ? value.substring(1) : value
+ }
+ return value
+ })
+} \ No newline at end of file
diff --git a/node_modules/spawn-sync/lib/spawn-sync.js b/node_modules/spawn-sync/lib/spawn-sync.js
new file mode 100644
index 0000000..5dbc530
--- /dev/null
+++ b/node_modules/spawn-sync/lib/spawn-sync.js
@@ -0,0 +1,89 @@
+'use strict';
+
+var path = require('path');
+var fs = require('fs');
+var tmpdir = require('os').tmpdir || require('os-shim').tmpdir;
+var cp = require('child_process');
+var sleep;
+var JSON = require('./json-buffer');
+try {
+ sleep = require('try-thread-sleep');
+} catch (ex) {
+ console.warn('Native thread-sleep not available.');
+ console.warn('This will result in much slower performance, but it will still work.');
+ console.warn('You should re-install spawn-sync or upgrade to the lastest version of node if possible.');
+ console.warn('Check ' + path.resolve(__dirname, '../error.log') + ' for more details');
+ sleep = function () {};
+}
+
+var temp = path.normalize(path.join(tmpdir(), 'spawn-sync'));
+
+function randomFileName(name) {
+ function randomHash(count) {
+ if (count === 1)
+ return parseInt(16*Math.random(), 10).toString(16);
+ else {
+ var hash = '';
+ for (var i=0; i<count; i++)
+ hash += randomHash(1);
+ return hash;
+ }
+ }
+
+ return temp + '_' + name + '_' + String(process.pid) + randomHash(20);
+}
+function unlink(filename) {
+ try {
+ fs.unlinkSync(filename);
+ } catch (ex) {
+ if (ex.code !== 'ENOENT') throw ex;
+ }
+}
+function tryUnlink(filename) {
+ // doesn't matter too much if we fail to delete temp files
+ try {
+ fs.unlinkSync(filename);
+ } catch(e) {}
+}
+
+function invoke(cmd) {
+ // location to keep flag for busy waiting fallback
+ var finished = randomFileName("finished");
+ unlink(finished);
+ if (process.platform === 'win32') {
+ cmd = cmd + '& echo "finished" > ' + finished;
+ } else {
+ cmd = cmd + '; echo "finished" > ' + finished;
+ }
+ cp.exec(cmd);
+
+ while (!fs.existsSync(finished)) {
+ // busy wait
+ sleep(200);
+ }
+
+ tryUnlink(finished);
+
+ return 0;
+}
+
+module.exports = spawnSyncFallback;
+function spawnSyncFallback(cmd, commandArgs, options) {
+ var args = [];
+ for (var i = 0; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+
+ // node.js script to run the command
+ var worker = path.normalize(__dirname + '/worker.js');
+ // location to store arguments
+ var input = randomFileName('input');
+ var output = randomFileName('output');
+ unlink(output);
+
+ fs.writeFileSync(input, JSON.stringify(args));
+ invoke('"' + process.execPath + '" "' + worker + '" "' + input + '" "' + output + '"');
+ var res = JSON.parse(fs.readFileSync(output, 'utf8'));
+ tryUnlink(input);tryUnlink(output);
+ return res;
+}
diff --git a/node_modules/spawn-sync/lib/worker.js b/node_modules/spawn-sync/lib/worker.js
new file mode 100644
index 0000000..3e050ac
--- /dev/null
+++ b/node_modules/spawn-sync/lib/worker.js
@@ -0,0 +1,56 @@
+'use strict';
+
+var cp = require('child_process');
+var fs = require('fs');
+var concat = require('concat-stream');
+var JSON = require('./json-buffer');
+
+var inputFile = process.argv[2];
+var outputFile = process.argv[3];
+
+var args = JSON.parse(fs.readFileSync(inputFile, 'utf8'));
+function output(result) {
+ fs.writeFileSync(outputFile, JSON.stringify(result));
+}
+
+var child = cp.spawn.apply(cp, args);
+var options = (args[2] && typeof args[2] === 'object') ?
+ args[2] :
+ (args[1] && typeof args[1] === 'object' && !Array.isArray(args[1])) ?
+ args[1] :
+ {};
+
+var complete = false;
+var stdout, stderr;
+child.stdout && child.stdout.pipe(concat(function (buf) {
+ stdout = buf.length ? buf : new Buffer(0);
+}));
+child.stderr && child.stderr.pipe(concat(function (buf) {
+ stderr = buf.length ? buf : new Buffer(0);
+}));
+child.on('error', function (err) {
+ output({pid: child.pid, error: err.message});
+});
+child.on('close', function (status, signal) {
+ if (options.encoding && options.encoding !== 'buffer') {
+ stdout = stdout.toString(options.encoding);
+ stderr = stderr.toString(options.encoding);
+ }
+ output({
+ pid: child.pid,
+ output: [null, stdout, stderr],
+ stdout: stdout,
+ stderr: stderr,
+ status: status,
+ signal: signal
+ });
+});
+
+if (options.timeout && typeof options.timeout === 'number') {
+ setTimeout(function () {
+ child.kill(options.killSignal || 'SIGTERM');
+ }, options.timeout);
+}
+if (options.input && (typeof options.input === 'string' || Buffer.isBuffer(options.input))) {
+ child.stdin.end(options.input);
+}