From 60867fb030bae582082340ead7dbc7efdc2f5398 Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Fri, 3 Apr 2020 02:37:42 -0700 Subject: 2020/04/03, 02:34, v1.2.0 --- node_modules/spawn-sync/lib/spawn-sync.js | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 node_modules/spawn-sync/lib/spawn-sync.js (limited to 'node_modules/spawn-sync/lib/spawn-sync.js') 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 ' + 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; +} -- cgit v1.2.3