2671 lines
74 KiB
JavaScript
Executable File
2671 lines
74 KiB
JavaScript
Executable File
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
|
|
if you want to view the source visit the plugins github repository
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var obsidian = require('obsidian');
|
|
var path = require('path');
|
|
var childProcess = require('child_process');
|
|
var fs = require('fs');
|
|
var _os = require('os');
|
|
var assert = require('assert');
|
|
var require$$1 = require('events');
|
|
var require$$0$1 = require('buffer');
|
|
var require$$0 = require('stream');
|
|
var require$$1$1 = require('util');
|
|
|
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
|
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
var childProcess__default = /*#__PURE__*/_interopDefaultLegacy(childProcess);
|
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
var _os__default = /*#__PURE__*/_interopDefaultLegacy(_os);
|
|
var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
|
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
|
|
/*! *****************************************************************************
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
PERFORMANCE OF THIS SOFTWARE.
|
|
***************************************************************************** */
|
|
|
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
}
|
|
|
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
|
|
function createCommonjsModule(fn, basedir, module) {
|
|
return module = {
|
|
path: basedir,
|
|
exports: {},
|
|
require: function (path, base) {
|
|
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
}
|
|
}, fn(module, module.exports), module.exports;
|
|
}
|
|
|
|
function commonjsRequire () {
|
|
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
}
|
|
|
|
var windows = isexe$2;
|
|
isexe$2.sync = sync$4;
|
|
|
|
|
|
|
|
function checkPathExt (path, options) {
|
|
var pathext = options.pathExt !== undefined ?
|
|
options.pathExt : process.env.PATHEXT;
|
|
|
|
if (!pathext) {
|
|
return true
|
|
}
|
|
|
|
pathext = pathext.split(';');
|
|
if (pathext.indexOf('') !== -1) {
|
|
return true
|
|
}
|
|
for (var i = 0; i < pathext.length; i++) {
|
|
var p = pathext[i].toLowerCase();
|
|
if (p && path.substr(-p.length).toLowerCase() === p) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
function checkStat$1 (stat, path, options) {
|
|
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
return false
|
|
}
|
|
return checkPathExt(path, options)
|
|
}
|
|
|
|
function isexe$2 (path, options, cb) {
|
|
fs__default['default'].stat(path, function (er, stat) {
|
|
cb(er, er ? false : checkStat$1(stat, path, options));
|
|
});
|
|
}
|
|
|
|
function sync$4 (path, options) {
|
|
return checkStat$1(fs__default['default'].statSync(path), path, options)
|
|
}
|
|
|
|
var mode = isexe$1;
|
|
isexe$1.sync = sync$3;
|
|
|
|
|
|
|
|
function isexe$1 (path, options, cb) {
|
|
fs__default['default'].stat(path, function (er, stat) {
|
|
cb(er, er ? false : checkStat(stat, options));
|
|
});
|
|
}
|
|
|
|
function sync$3 (path, options) {
|
|
return checkStat(fs__default['default'].statSync(path), options)
|
|
}
|
|
|
|
function checkStat (stat, options) {
|
|
return stat.isFile() && checkMode(stat, options)
|
|
}
|
|
|
|
function checkMode (stat, options) {
|
|
var mod = stat.mode;
|
|
var uid = stat.uid;
|
|
var gid = stat.gid;
|
|
|
|
var myUid = options.uid !== undefined ?
|
|
options.uid : process.getuid && process.getuid();
|
|
var myGid = options.gid !== undefined ?
|
|
options.gid : process.getgid && process.getgid();
|
|
|
|
var u = parseInt('100', 8);
|
|
var g = parseInt('010', 8);
|
|
var o = parseInt('001', 8);
|
|
var ug = u | g;
|
|
|
|
var ret = (mod & o) ||
|
|
(mod & g) && gid === myGid ||
|
|
(mod & u) && uid === myUid ||
|
|
(mod & ug) && myUid === 0;
|
|
|
|
return ret
|
|
}
|
|
|
|
var core$1;
|
|
if (process.platform === 'win32' || commonjsGlobal.TESTING_WINDOWS) {
|
|
core$1 = windows;
|
|
} else {
|
|
core$1 = mode;
|
|
}
|
|
|
|
var isexe_1 = isexe;
|
|
isexe.sync = sync$2;
|
|
|
|
function isexe (path, options, cb) {
|
|
if (typeof options === 'function') {
|
|
cb = options;
|
|
options = {};
|
|
}
|
|
|
|
if (!cb) {
|
|
if (typeof Promise !== 'function') {
|
|
throw new TypeError('callback not provided')
|
|
}
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
isexe(path, options || {}, function (er, is) {
|
|
if (er) {
|
|
reject(er);
|
|
} else {
|
|
resolve(is);
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
core$1(path, options || {}, function (er, is) {
|
|
// ignore EACCES because that just means we aren't allowed to run it
|
|
if (er) {
|
|
if (er.code === 'EACCES' || options && options.ignoreErrors) {
|
|
er = null;
|
|
is = false;
|
|
}
|
|
}
|
|
cb(er, is);
|
|
});
|
|
}
|
|
|
|
function sync$2 (path, options) {
|
|
// my kingdom for a filtered catch
|
|
try {
|
|
return core$1.sync(path, options || {})
|
|
} catch (er) {
|
|
if (options && options.ignoreErrors || er.code === 'EACCES') {
|
|
return false
|
|
} else {
|
|
throw er
|
|
}
|
|
}
|
|
}
|
|
|
|
const isWindows = process.platform === 'win32' ||
|
|
process.env.OSTYPE === 'cygwin' ||
|
|
process.env.OSTYPE === 'msys';
|
|
|
|
|
|
const COLON = isWindows ? ';' : ':';
|
|
|
|
|
|
const getNotFoundError = (cmd) =>
|
|
Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' });
|
|
|
|
const getPathInfo = (cmd, opt) => {
|
|
const colon = opt.colon || COLON;
|
|
|
|
// If it has a slash, then we don't bother searching the pathenv.
|
|
// just check the file itself, and that's it.
|
|
const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? ['']
|
|
: (
|
|
[
|
|
// windows always checks the cwd first
|
|
...(isWindows ? [process.cwd()] : []),
|
|
...(opt.path || process.env.PATH ||
|
|
/* istanbul ignore next: very unusual */ '').split(colon),
|
|
]
|
|
);
|
|
const pathExtExe = isWindows
|
|
? opt.pathExt || process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM'
|
|
: '';
|
|
const pathExt = isWindows ? pathExtExe.split(colon) : [''];
|
|
|
|
if (isWindows) {
|
|
if (cmd.indexOf('.') !== -1 && pathExt[0] !== '')
|
|
pathExt.unshift('');
|
|
}
|
|
|
|
return {
|
|
pathEnv,
|
|
pathExt,
|
|
pathExtExe,
|
|
}
|
|
};
|
|
|
|
const which = (cmd, opt, cb) => {
|
|
if (typeof opt === 'function') {
|
|
cb = opt;
|
|
opt = {};
|
|
}
|
|
if (!opt)
|
|
opt = {};
|
|
|
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
const found = [];
|
|
|
|
const step = i => new Promise((resolve, reject) => {
|
|
if (i === pathEnv.length)
|
|
return opt.all && found.length ? resolve(found)
|
|
: reject(getNotFoundError(cmd))
|
|
|
|
const ppRaw = pathEnv[i];
|
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
|
|
const pCmd = path__default['default'].join(pathPart, cmd);
|
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd
|
|
: pCmd;
|
|
|
|
resolve(subStep(p, i, 0));
|
|
});
|
|
|
|
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
|
|
if (ii === pathExt.length)
|
|
return resolve(step(i + 1))
|
|
const ext = pathExt[ii];
|
|
isexe_1(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
if (!er && is) {
|
|
if (opt.all)
|
|
found.push(p + ext);
|
|
else
|
|
return resolve(p + ext)
|
|
}
|
|
return resolve(subStep(p, i, ii + 1))
|
|
});
|
|
});
|
|
|
|
return cb ? step(0).then(res => cb(null, res), cb) : step(0)
|
|
};
|
|
|
|
const whichSync = (cmd, opt) => {
|
|
opt = opt || {};
|
|
|
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
const found = [];
|
|
|
|
for (let i = 0; i < pathEnv.length; i ++) {
|
|
const ppRaw = pathEnv[i];
|
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
|
|
const pCmd = path__default['default'].join(pathPart, cmd);
|
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd
|
|
: pCmd;
|
|
|
|
for (let j = 0; j < pathExt.length; j ++) {
|
|
const cur = p + pathExt[j];
|
|
try {
|
|
const is = isexe_1.sync(cur, { pathExt: pathExtExe });
|
|
if (is) {
|
|
if (opt.all)
|
|
found.push(cur);
|
|
else
|
|
return cur
|
|
}
|
|
} catch (ex) {}
|
|
}
|
|
}
|
|
|
|
if (opt.all && found.length)
|
|
return found
|
|
|
|
if (opt.nothrow)
|
|
return null
|
|
|
|
throw getNotFoundError(cmd)
|
|
};
|
|
|
|
var which_1 = which;
|
|
which.sync = whichSync;
|
|
|
|
const pathKey = (options = {}) => {
|
|
const environment = options.env || process.env;
|
|
const platform = options.platform || process.platform;
|
|
|
|
if (platform !== 'win32') {
|
|
return 'PATH';
|
|
}
|
|
|
|
return Object.keys(environment).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';
|
|
};
|
|
|
|
var pathKey_1 = pathKey;
|
|
// TODO: Remove this for the next major release
|
|
var _default$2 = pathKey;
|
|
pathKey_1.default = _default$2;
|
|
|
|
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
const env = parsed.options.env || process.env;
|
|
const cwd = process.cwd();
|
|
const hasCustomCwd = parsed.options.cwd != null;
|
|
// Worker threads do not have process.chdir()
|
|
const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined && !process.chdir.disabled;
|
|
|
|
// If a custom `cwd` was specified, we need to change the process cwd
|
|
// because `which` will do stat calls but does not support a custom cwd
|
|
if (shouldSwitchCwd) {
|
|
try {
|
|
process.chdir(parsed.options.cwd);
|
|
} catch (err) {
|
|
/* Empty */
|
|
}
|
|
}
|
|
|
|
let resolved;
|
|
|
|
try {
|
|
resolved = which_1.sync(parsed.command, {
|
|
path: env[pathKey_1({ env })],
|
|
pathExt: withoutPathExt ? path__default['default'].delimiter : undefined,
|
|
});
|
|
} catch (e) {
|
|
/* Empty */
|
|
} finally {
|
|
if (shouldSwitchCwd) {
|
|
process.chdir(cwd);
|
|
}
|
|
}
|
|
|
|
// If we successfully resolved, ensure that an absolute path is returned
|
|
// Note that when a custom `cwd` was used, we need to resolve to an absolute path based on it
|
|
if (resolved) {
|
|
resolved = path__default['default'].resolve(hasCustomCwd ? parsed.options.cwd : '', resolved);
|
|
}
|
|
|
|
return resolved;
|
|
}
|
|
|
|
function resolveCommand(parsed) {
|
|
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
|
|
}
|
|
|
|
var resolveCommand_1 = resolveCommand;
|
|
|
|
// See http://www.robvanderwoude.com/escapechars.php
|
|
const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
|
|
|
|
function escapeCommand(arg) {
|
|
// Escape meta chars
|
|
arg = arg.replace(metaCharsRegExp, '^$1');
|
|
|
|
return arg;
|
|
}
|
|
|
|
function escapeArgument(arg, doubleEscapeMetaChars) {
|
|
// Convert to string
|
|
arg = `${arg}`;
|
|
|
|
// Algorithm below is based on https://qntm.org/cmd
|
|
|
|
// Sequence of backslashes followed by a double quote:
|
|
// double up all the backslashes and escape the double quote
|
|
arg = arg.replace(/(\\*)"/g, '$1$1\\"');
|
|
|
|
// Sequence of backslashes followed by the end of the string
|
|
// (which will become a double quote later):
|
|
// double up all the backslashes
|
|
arg = arg.replace(/(\\*)$/, '$1$1');
|
|
|
|
// All other backslashes occur literally
|
|
|
|
// Quote the whole thing:
|
|
arg = `"${arg}"`;
|
|
|
|
// Escape meta chars
|
|
arg = arg.replace(metaCharsRegExp, '^$1');
|
|
|
|
// Double escape meta chars if necessary
|
|
if (doubleEscapeMetaChars) {
|
|
arg = arg.replace(metaCharsRegExp, '^$1');
|
|
}
|
|
|
|
return arg;
|
|
}
|
|
|
|
var command$2 = escapeCommand;
|
|
var argument = escapeArgument;
|
|
|
|
var _escape = {
|
|
command: command$2,
|
|
argument: argument
|
|
};
|
|
|
|
var shebangRegex = /^#!(.*)/;
|
|
|
|
var shebangCommand = (string = '') => {
|
|
const match = string.match(shebangRegex);
|
|
|
|
if (!match) {
|
|
return null;
|
|
}
|
|
|
|
const [path, argument] = match[0].replace(/#! ?/, '').split(' ');
|
|
const binary = path.split('/').pop();
|
|
|
|
if (binary === 'env') {
|
|
return argument;
|
|
}
|
|
|
|
return argument ? `${binary} ${argument}` : binary;
|
|
};
|
|
|
|
function readShebang(command) {
|
|
// Read the first 150 bytes from the file
|
|
const size = 150;
|
|
const buffer = Buffer.alloc(size);
|
|
|
|
let fd;
|
|
|
|
try {
|
|
fd = fs__default['default'].openSync(command, 'r');
|
|
fs__default['default'].readSync(fd, buffer, 0, size, 0);
|
|
fs__default['default'].closeSync(fd);
|
|
} catch (e) { /* Empty */ }
|
|
|
|
// Attempt to extract shebang (null is returned if not a shebang)
|
|
return shebangCommand(buffer.toString());
|
|
}
|
|
|
|
var readShebang_1 = readShebang;
|
|
|
|
const isWin$2 = process.platform === 'win32';
|
|
const isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
|
|
function detectShebang(parsed) {
|
|
parsed.file = resolveCommand_1(parsed);
|
|
|
|
const shebang = parsed.file && readShebang_1(parsed.file);
|
|
|
|
if (shebang) {
|
|
parsed.args.unshift(parsed.file);
|
|
parsed.command = shebang;
|
|
|
|
return resolveCommand_1(parsed);
|
|
}
|
|
|
|
return parsed.file;
|
|
}
|
|
|
|
function parseNonShell(parsed) {
|
|
if (!isWin$2) {
|
|
return parsed;
|
|
}
|
|
|
|
// Detect & add support for shebangs
|
|
const commandFile = detectShebang(parsed);
|
|
|
|
// We don't need a shell if the command filename is an executable
|
|
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
|
|
// If a shell is required, use cmd.exe and take care of escaping everything correctly
|
|
// Note that `forceShell` is an hidden option used only in tests
|
|
if (parsed.options.forceShell || needsShell) {
|
|
// Need to double escape meta chars if the command is a cmd-shim located in `node_modules/.bin/`
|
|
// The cmd-shim simply calls execute the package bin file with NodeJS, proxying any argument
|
|
// Because the escape of metachars with ^ gets interpreted when the cmd.exe is first called,
|
|
// we need to double escape them
|
|
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
|
|
// Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\bar)
|
|
// This is necessary otherwise it will always fail with ENOENT in those cases
|
|
parsed.command = path__default['default'].normalize(parsed.command);
|
|
|
|
// Escape command & arguments
|
|
parsed.command = _escape.command(parsed.command);
|
|
parsed.args = parsed.args.map((arg) => _escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
|
|
const shellCommand = [parsed.command].concat(parsed.args).join(' ');
|
|
|
|
parsed.args = ['/d', '/s', '/c', `"${shellCommand}"`];
|
|
parsed.command = process.env.comspec || 'cmd.exe';
|
|
parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped
|
|
}
|
|
|
|
return parsed;
|
|
}
|
|
|
|
function parse(command, args, options) {
|
|
// Normalize arguments, similar to nodejs
|
|
if (args && !Array.isArray(args)) {
|
|
options = args;
|
|
args = null;
|
|
}
|
|
|
|
args = args ? args.slice(0) : []; // Clone array to avoid changing the original
|
|
options = Object.assign({}, options); // Clone object to avoid changing the original
|
|
|
|
// Build our parsed object
|
|
const parsed = {
|
|
command,
|
|
args,
|
|
options,
|
|
file: undefined,
|
|
original: {
|
|
command,
|
|
args,
|
|
},
|
|
};
|
|
|
|
// Delegate further parsing to shell or non-shell
|
|
return options.shell ? parsed : parseNonShell(parsed);
|
|
}
|
|
|
|
var parse_1 = parse;
|
|
|
|
const isWin$1 = process.platform === 'win32';
|
|
|
|
function notFoundError(original, syscall) {
|
|
return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
|
|
code: 'ENOENT',
|
|
errno: 'ENOENT',
|
|
syscall: `${syscall} ${original.command}`,
|
|
path: original.command,
|
|
spawnargs: original.args,
|
|
});
|
|
}
|
|
|
|
function hookChildProcess(cp, parsed) {
|
|
if (!isWin$1) {
|
|
return;
|
|
}
|
|
|
|
const originalEmit = cp.emit;
|
|
|
|
cp.emit = function (name, arg1) {
|
|
// If emitting "exit" event and exit code is 1, we need to check if
|
|
// the command exists and emit an "error" instead
|
|
// See https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
|
if (name === 'exit') {
|
|
const err = verifyENOENT(arg1, parsed);
|
|
|
|
if (err) {
|
|
return originalEmit.call(cp, 'error', err);
|
|
}
|
|
}
|
|
|
|
return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params
|
|
};
|
|
}
|
|
|
|
function verifyENOENT(status, parsed) {
|
|
if (isWin$1 && status === 1 && !parsed.file) {
|
|
return notFoundError(parsed.original, 'spawn');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
function verifyENOENTSync(status, parsed) {
|
|
if (isWin$1 && status === 1 && !parsed.file) {
|
|
return notFoundError(parsed.original, 'spawnSync');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
var enoent = {
|
|
hookChildProcess,
|
|
verifyENOENT,
|
|
verifyENOENTSync,
|
|
notFoundError,
|
|
};
|
|
|
|
function spawn(command, args, options) {
|
|
// Parse the arguments
|
|
const parsed = parse_1(command, args, options);
|
|
|
|
// Spawn the child process
|
|
const spawned = childProcess__default['default'].spawn(parsed.command, parsed.args, parsed.options);
|
|
|
|
// Hook into child process "exit" event to emit an error if the command
|
|
// does not exists, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
|
enoent.hookChildProcess(spawned, parsed);
|
|
|
|
return spawned;
|
|
}
|
|
|
|
function spawnSync(command, args, options) {
|
|
// Parse the arguments
|
|
const parsed = parse_1(command, args, options);
|
|
|
|
// Spawn the child process
|
|
const result = childProcess__default['default'].spawnSync(parsed.command, parsed.args, parsed.options);
|
|
|
|
// Analyze if the command does not exist, see: https://github.com/IndigoUnited/node-cross-spawn/issues/16
|
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
|
|
return result;
|
|
}
|
|
|
|
var crossSpawn = spawn;
|
|
var spawn_1 = spawn;
|
|
var sync$1 = spawnSync;
|
|
|
|
var _parse = parse_1;
|
|
var _enoent = enoent;
|
|
crossSpawn.spawn = spawn_1;
|
|
crossSpawn.sync = sync$1;
|
|
crossSpawn._parse = _parse;
|
|
crossSpawn._enoent = _enoent;
|
|
|
|
var stripFinalNewline = input => {
|
|
const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
|
|
const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt();
|
|
|
|
if (input[input.length - 1] === LF) {
|
|
input = input.slice(0, input.length - 1);
|
|
}
|
|
|
|
if (input[input.length - 1] === CR) {
|
|
input = input.slice(0, input.length - 1);
|
|
}
|
|
|
|
return input;
|
|
};
|
|
|
|
var npmRunPath_1 = createCommonjsModule(function (module) {
|
|
|
|
|
|
|
|
const npmRunPath = options => {
|
|
options = {
|
|
cwd: process.cwd(),
|
|
path: process.env[pathKey_1()],
|
|
execPath: process.execPath,
|
|
...options
|
|
};
|
|
|
|
let previous;
|
|
let cwdPath = path__default['default'].resolve(options.cwd);
|
|
const result = [];
|
|
|
|
while (previous !== cwdPath) {
|
|
result.push(path__default['default'].join(cwdPath, 'node_modules/.bin'));
|
|
previous = cwdPath;
|
|
cwdPath = path__default['default'].resolve(cwdPath, '..');
|
|
}
|
|
|
|
// Ensure the running `node` binary is used
|
|
const execPathDir = path__default['default'].resolve(options.cwd, options.execPath, '..');
|
|
result.push(execPathDir);
|
|
|
|
return result.concat(options.path).join(path__default['default'].delimiter);
|
|
};
|
|
|
|
module.exports = npmRunPath;
|
|
// TODO: Remove this for the next major release
|
|
module.exports.default = npmRunPath;
|
|
|
|
module.exports.env = options => {
|
|
options = {
|
|
env: process.env,
|
|
...options
|
|
};
|
|
|
|
const env = {...options.env};
|
|
const path = pathKey_1({env});
|
|
|
|
options.path = env[path];
|
|
env[path] = module.exports(options);
|
|
|
|
return env;
|
|
};
|
|
});
|
|
|
|
const mimicFn = (to, from) => {
|
|
for (const prop of Reflect.ownKeys(from)) {
|
|
Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
|
|
}
|
|
|
|
return to;
|
|
};
|
|
|
|
var mimicFn_1 = mimicFn;
|
|
// TODO: Remove this for the next major release
|
|
var _default$1 = mimicFn;
|
|
mimicFn_1.default = _default$1;
|
|
|
|
const calledFunctions = new WeakMap();
|
|
|
|
const onetime = (function_, options = {}) => {
|
|
if (typeof function_ !== 'function') {
|
|
throw new TypeError('Expected a function');
|
|
}
|
|
|
|
let returnValue;
|
|
let callCount = 0;
|
|
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
|
|
const onetime = function (...arguments_) {
|
|
calledFunctions.set(onetime, ++callCount);
|
|
|
|
if (callCount === 1) {
|
|
returnValue = function_.apply(this, arguments_);
|
|
function_ = null;
|
|
} else if (options.throw === true) {
|
|
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
}
|
|
|
|
return returnValue;
|
|
};
|
|
|
|
mimicFn_1(onetime, function_);
|
|
calledFunctions.set(onetime, callCount);
|
|
|
|
return onetime;
|
|
};
|
|
|
|
var onetime_1 = onetime;
|
|
// TODO: Remove this for the next major release
|
|
var _default = onetime;
|
|
|
|
var callCount = function_ => {
|
|
if (!calledFunctions.has(function_)) {
|
|
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
}
|
|
|
|
return calledFunctions.get(function_);
|
|
};
|
|
onetime_1.default = _default;
|
|
onetime_1.callCount = callCount;
|
|
|
|
var core = createCommonjsModule(function (module, exports) {
|
|
Object.defineProperty(exports,"__esModule",{value:true});exports.SIGNALS=void 0;
|
|
|
|
const SIGNALS=[
|
|
{
|
|
name:"SIGHUP",
|
|
number:1,
|
|
action:"terminate",
|
|
description:"Terminal closed",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGINT",
|
|
number:2,
|
|
action:"terminate",
|
|
description:"User interruption with CTRL-C",
|
|
standard:"ansi"},
|
|
|
|
{
|
|
name:"SIGQUIT",
|
|
number:3,
|
|
action:"core",
|
|
description:"User interruption with CTRL-\\",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGILL",
|
|
number:4,
|
|
action:"core",
|
|
description:"Invalid machine instruction",
|
|
standard:"ansi"},
|
|
|
|
{
|
|
name:"SIGTRAP",
|
|
number:5,
|
|
action:"core",
|
|
description:"Debugger breakpoint",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGABRT",
|
|
number:6,
|
|
action:"core",
|
|
description:"Aborted",
|
|
standard:"ansi"},
|
|
|
|
{
|
|
name:"SIGIOT",
|
|
number:6,
|
|
action:"core",
|
|
description:"Aborted",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGBUS",
|
|
number:7,
|
|
action:"core",
|
|
description:
|
|
"Bus error due to misaligned, non-existing address or paging error",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGEMT",
|
|
number:7,
|
|
action:"terminate",
|
|
description:"Command should be emulated but is not implemented",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGFPE",
|
|
number:8,
|
|
action:"core",
|
|
description:"Floating point arithmetic error",
|
|
standard:"ansi"},
|
|
|
|
{
|
|
name:"SIGKILL",
|
|
number:9,
|
|
action:"terminate",
|
|
description:"Forced termination",
|
|
standard:"posix",
|
|
forced:true},
|
|
|
|
{
|
|
name:"SIGUSR1",
|
|
number:10,
|
|
action:"terminate",
|
|
description:"Application-specific signal",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGSEGV",
|
|
number:11,
|
|
action:"core",
|
|
description:"Segmentation fault",
|
|
standard:"ansi"},
|
|
|
|
{
|
|
name:"SIGUSR2",
|
|
number:12,
|
|
action:"terminate",
|
|
description:"Application-specific signal",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGPIPE",
|
|
number:13,
|
|
action:"terminate",
|
|
description:"Broken pipe or socket",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGALRM",
|
|
number:14,
|
|
action:"terminate",
|
|
description:"Timeout or timer",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGTERM",
|
|
number:15,
|
|
action:"terminate",
|
|
description:"Termination",
|
|
standard:"ansi"},
|
|
|
|
{
|
|
name:"SIGSTKFLT",
|
|
number:16,
|
|
action:"terminate",
|
|
description:"Stack is empty or overflowed",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGCHLD",
|
|
number:17,
|
|
action:"ignore",
|
|
description:"Child process terminated, paused or unpaused",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGCLD",
|
|
number:17,
|
|
action:"ignore",
|
|
description:"Child process terminated, paused or unpaused",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGCONT",
|
|
number:18,
|
|
action:"unpause",
|
|
description:"Unpaused",
|
|
standard:"posix",
|
|
forced:true},
|
|
|
|
{
|
|
name:"SIGSTOP",
|
|
number:19,
|
|
action:"pause",
|
|
description:"Paused",
|
|
standard:"posix",
|
|
forced:true},
|
|
|
|
{
|
|
name:"SIGTSTP",
|
|
number:20,
|
|
action:"pause",
|
|
description:"Paused using CTRL-Z or \"suspend\"",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGTTIN",
|
|
number:21,
|
|
action:"pause",
|
|
description:"Background process cannot read terminal input",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGBREAK",
|
|
number:21,
|
|
action:"terminate",
|
|
description:"User interruption with CTRL-BREAK",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGTTOU",
|
|
number:22,
|
|
action:"pause",
|
|
description:"Background process cannot write to terminal output",
|
|
standard:"posix"},
|
|
|
|
{
|
|
name:"SIGURG",
|
|
number:23,
|
|
action:"ignore",
|
|
description:"Socket received out-of-band data",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGXCPU",
|
|
number:24,
|
|
action:"core",
|
|
description:"Process timed out",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGXFSZ",
|
|
number:25,
|
|
action:"core",
|
|
description:"File too big",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGVTALRM",
|
|
number:26,
|
|
action:"terminate",
|
|
description:"Timeout or timer",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGPROF",
|
|
number:27,
|
|
action:"terminate",
|
|
description:"Timeout or timer",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGWINCH",
|
|
number:28,
|
|
action:"ignore",
|
|
description:"Terminal window size changed",
|
|
standard:"bsd"},
|
|
|
|
{
|
|
name:"SIGIO",
|
|
number:29,
|
|
action:"terminate",
|
|
description:"I/O is available",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGPOLL",
|
|
number:29,
|
|
action:"terminate",
|
|
description:"Watched event",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGINFO",
|
|
number:29,
|
|
action:"ignore",
|
|
description:"Request for process information",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGPWR",
|
|
number:30,
|
|
action:"terminate",
|
|
description:"Device running out of power",
|
|
standard:"systemv"},
|
|
|
|
{
|
|
name:"SIGSYS",
|
|
number:31,
|
|
action:"core",
|
|
description:"Invalid system call",
|
|
standard:"other"},
|
|
|
|
{
|
|
name:"SIGUNUSED",
|
|
number:31,
|
|
action:"terminate",
|
|
description:"Invalid system call",
|
|
standard:"other"}];exports.SIGNALS=SIGNALS;
|
|
|
|
});
|
|
|
|
var realtime = createCommonjsModule(function (module, exports) {
|
|
Object.defineProperty(exports,"__esModule",{value:true});exports.SIGRTMAX=exports.getRealtimeSignals=void 0;
|
|
const getRealtimeSignals=function(){
|
|
const length=SIGRTMAX-SIGRTMIN+1;
|
|
return Array.from({length},getRealtimeSignal);
|
|
};exports.getRealtimeSignals=getRealtimeSignals;
|
|
|
|
const getRealtimeSignal=function(value,index){
|
|
return {
|
|
name:`SIGRT${index+1}`,
|
|
number:SIGRTMIN+index,
|
|
action:"terminate",
|
|
description:"Application-specific signal (realtime)",
|
|
standard:"posix"};
|
|
|
|
};
|
|
|
|
const SIGRTMIN=34;
|
|
const SIGRTMAX=64;exports.SIGRTMAX=SIGRTMAX;
|
|
|
|
});
|
|
|
|
var signals$2 = createCommonjsModule(function (module, exports) {
|
|
Object.defineProperty(exports,"__esModule",{value:true});exports.getSignals=void 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getSignals=function(){
|
|
const realtimeSignals=(0, realtime.getRealtimeSignals)();
|
|
const signals=[...core.SIGNALS,...realtimeSignals].map(normalizeSignal);
|
|
return signals;
|
|
};exports.getSignals=getSignals;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const normalizeSignal=function({
|
|
name,
|
|
number:defaultNumber,
|
|
description,
|
|
action,
|
|
forced=false,
|
|
standard})
|
|
{
|
|
const{
|
|
signals:{[name]:constantSignal}}=
|
|
_os__default['default'].constants;
|
|
const supported=constantSignal!==undefined;
|
|
const number=supported?constantSignal:defaultNumber;
|
|
return {name,number,description,supported,action,forced,standard};
|
|
};
|
|
|
|
});
|
|
|
|
var main = createCommonjsModule(function (module, exports) {
|
|
Object.defineProperty(exports,"__esModule",{value:true});exports.signalsByNumber=exports.signalsByName=void 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getSignalsByName=function(){
|
|
const signals=(0, signals$2.getSignals)();
|
|
return signals.reduce(getSignalByName,{});
|
|
};
|
|
|
|
const getSignalByName=function(
|
|
signalByNameMemo,
|
|
{name,number,description,supported,action,forced,standard})
|
|
{
|
|
return {
|
|
...signalByNameMemo,
|
|
[name]:{name,number,description,supported,action,forced,standard}};
|
|
|
|
};
|
|
|
|
const signalsByName=getSignalsByName();exports.signalsByName=signalsByName;
|
|
|
|
|
|
|
|
|
|
const getSignalsByNumber=function(){
|
|
const signals=(0, signals$2.getSignals)();
|
|
const length=realtime.SIGRTMAX+1;
|
|
const signalsA=Array.from({length},(value,number)=>
|
|
getSignalByNumber(number,signals));
|
|
|
|
return Object.assign({},...signalsA);
|
|
};
|
|
|
|
const getSignalByNumber=function(number,signals){
|
|
const signal=findSignalByNumber(number,signals);
|
|
|
|
if(signal===undefined){
|
|
return {};
|
|
}
|
|
|
|
const{name,description,supported,action,forced,standard}=signal;
|
|
return {
|
|
[number]:{
|
|
name,
|
|
number,
|
|
description,
|
|
supported,
|
|
action,
|
|
forced,
|
|
standard}};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const findSignalByNumber=function(number,signals){
|
|
const signal=signals.find(({name})=>_os__default['default'].constants.signals[name]===number);
|
|
|
|
if(signal!==undefined){
|
|
return signal;
|
|
}
|
|
|
|
return signals.find(signalA=>signalA.number===number);
|
|
};
|
|
|
|
const signalsByNumber=getSignalsByNumber();exports.signalsByNumber=signalsByNumber;
|
|
|
|
});
|
|
|
|
const {signalsByName} = main;
|
|
|
|
const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {
|
|
if (timedOut) {
|
|
return `timed out after ${timeout} milliseconds`;
|
|
}
|
|
|
|
if (isCanceled) {
|
|
return 'was canceled';
|
|
}
|
|
|
|
if (errorCode !== undefined) {
|
|
return `failed with ${errorCode}`;
|
|
}
|
|
|
|
if (signal !== undefined) {
|
|
return `was killed with ${signal} (${signalDescription})`;
|
|
}
|
|
|
|
if (exitCode !== undefined) {
|
|
return `failed with exit code ${exitCode}`;
|
|
}
|
|
|
|
return 'failed';
|
|
};
|
|
|
|
const makeError = ({
|
|
stdout,
|
|
stderr,
|
|
all,
|
|
error,
|
|
signal,
|
|
exitCode,
|
|
command,
|
|
escapedCommand,
|
|
timedOut,
|
|
isCanceled,
|
|
killed,
|
|
parsed: {options: {timeout}}
|
|
}) => {
|
|
// `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.
|
|
// We normalize them to `undefined`
|
|
exitCode = exitCode === null ? undefined : exitCode;
|
|
signal = signal === null ? undefined : signal;
|
|
const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;
|
|
|
|
const errorCode = error && error.code;
|
|
|
|
const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});
|
|
const execaMessage = `Command ${prefix}: ${command}`;
|
|
const isError = Object.prototype.toString.call(error) === '[object Error]';
|
|
const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
|
|
const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');
|
|
|
|
if (isError) {
|
|
error.originalMessage = error.message;
|
|
error.message = message;
|
|
} else {
|
|
error = new Error(message);
|
|
}
|
|
|
|
error.shortMessage = shortMessage;
|
|
error.command = command;
|
|
error.escapedCommand = escapedCommand;
|
|
error.exitCode = exitCode;
|
|
error.signal = signal;
|
|
error.signalDescription = signalDescription;
|
|
error.stdout = stdout;
|
|
error.stderr = stderr;
|
|
|
|
if (all !== undefined) {
|
|
error.all = all;
|
|
}
|
|
|
|
if ('bufferedData' in error) {
|
|
delete error.bufferedData;
|
|
}
|
|
|
|
error.failed = true;
|
|
error.timedOut = Boolean(timedOut);
|
|
error.isCanceled = isCanceled;
|
|
error.killed = killed && !timedOut;
|
|
|
|
return error;
|
|
};
|
|
|
|
var error = makeError;
|
|
|
|
const aliases = ['stdin', 'stdout', 'stderr'];
|
|
|
|
const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
|
|
|
|
const normalizeStdio = options => {
|
|
if (!options) {
|
|
return;
|
|
}
|
|
|
|
const {stdio} = options;
|
|
|
|
if (stdio === undefined) {
|
|
return aliases.map(alias => options[alias]);
|
|
}
|
|
|
|
if (hasAlias(options)) {
|
|
throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
|
|
}
|
|
|
|
if (typeof stdio === 'string') {
|
|
return stdio;
|
|
}
|
|
|
|
if (!Array.isArray(stdio)) {
|
|
throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
|
|
}
|
|
|
|
const length = Math.max(stdio.length, aliases.length);
|
|
return Array.from({length}, (value, index) => stdio[index]);
|
|
};
|
|
|
|
var stdio = normalizeStdio;
|
|
|
|
// `ipc` is pushed unless it is already present
|
|
var node$1 = options => {
|
|
const stdio = normalizeStdio(options);
|
|
|
|
if (stdio === 'ipc') {
|
|
return 'ipc';
|
|
}
|
|
|
|
if (stdio === undefined || typeof stdio === 'string') {
|
|
return [stdio, stdio, stdio, 'ipc'];
|
|
}
|
|
|
|
if (stdio.includes('ipc')) {
|
|
return stdio;
|
|
}
|
|
|
|
return [...stdio, 'ipc'];
|
|
};
|
|
stdio.node = node$1;
|
|
|
|
var signals$1 = createCommonjsModule(function (module) {
|
|
// This is not the set of all possible signals.
|
|
//
|
|
// It IS, however, the set of all signals that trigger
|
|
// an exit on either Linux or BSD systems. Linux is a
|
|
// superset of the signal names supported on BSD, and
|
|
// the unknown signals just fail to register, so we can
|
|
// catch that easily enough.
|
|
//
|
|
// Don't bother with SIGKILL. It's uncatchable, which
|
|
// means that we can't fire any callbacks anyway.
|
|
//
|
|
// If a user does happen to register a handler on a non-
|
|
// fatal signal like SIGWINCH or something, and then
|
|
// exit, it'll end up firing `process.emit('exit')`, so
|
|
// the handler will be fired anyway.
|
|
//
|
|
// SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
|
// artificially, inherently leave the process in a
|
|
// state from which it is not safe to try and enter JS
|
|
// listeners.
|
|
module.exports = [
|
|
'SIGABRT',
|
|
'SIGALRM',
|
|
'SIGHUP',
|
|
'SIGINT',
|
|
'SIGTERM'
|
|
];
|
|
|
|
if (process.platform !== 'win32') {
|
|
module.exports.push(
|
|
'SIGVTALRM',
|
|
'SIGXCPU',
|
|
'SIGXFSZ',
|
|
'SIGUSR2',
|
|
'SIGTRAP',
|
|
'SIGSYS',
|
|
'SIGQUIT',
|
|
'SIGIOT'
|
|
// should detect profiler and enable/disable accordingly.
|
|
// see #21
|
|
// 'SIGPROF'
|
|
);
|
|
}
|
|
|
|
if (process.platform === 'linux') {
|
|
module.exports.push(
|
|
'SIGIO',
|
|
'SIGPOLL',
|
|
'SIGPWR',
|
|
'SIGSTKFLT',
|
|
'SIGUNUSED'
|
|
);
|
|
}
|
|
});
|
|
|
|
// Note: since nyc uses this module to output coverage, any lines
|
|
// that are in the direct sync flow of nyc's outputCoverage are
|
|
// ignored, since we can never get coverage for them.
|
|
|
|
var signals = signals$1;
|
|
var isWin = /^win/i.test(process.platform);
|
|
|
|
var EE = require$$1__default['default'];
|
|
/* istanbul ignore if */
|
|
if (typeof EE !== 'function') {
|
|
EE = EE.EventEmitter;
|
|
}
|
|
|
|
var emitter;
|
|
if (process.__signal_exit_emitter__) {
|
|
emitter = process.__signal_exit_emitter__;
|
|
} else {
|
|
emitter = process.__signal_exit_emitter__ = new EE();
|
|
emitter.count = 0;
|
|
emitter.emitted = {};
|
|
}
|
|
|
|
// Because this emitter is a global, we have to check to see if a
|
|
// previous version of this library failed to enable infinite listeners.
|
|
// I know what you're about to say. But literally everything about
|
|
// signal-exit is a compromise with evil. Get used to it.
|
|
if (!emitter.infinite) {
|
|
emitter.setMaxListeners(Infinity);
|
|
emitter.infinite = true;
|
|
}
|
|
|
|
var signalExit = function (cb, opts) {
|
|
assert__default['default'].equal(typeof cb, 'function', 'a callback must be provided for exit handler');
|
|
|
|
if (loaded === false) {
|
|
load();
|
|
}
|
|
|
|
var ev = 'exit';
|
|
if (opts && opts.alwaysLast) {
|
|
ev = 'afterexit';
|
|
}
|
|
|
|
var remove = function () {
|
|
emitter.removeListener(ev, cb);
|
|
if (emitter.listeners('exit').length === 0 &&
|
|
emitter.listeners('afterexit').length === 0) {
|
|
unload();
|
|
}
|
|
};
|
|
emitter.on(ev, cb);
|
|
|
|
return remove
|
|
};
|
|
|
|
var unload_1 = unload;
|
|
function unload () {
|
|
if (!loaded) {
|
|
return
|
|
}
|
|
loaded = false;
|
|
|
|
signals.forEach(function (sig) {
|
|
try {
|
|
process.removeListener(sig, sigListeners[sig]);
|
|
} catch (er) {}
|
|
});
|
|
process.emit = originalProcessEmit;
|
|
process.reallyExit = originalProcessReallyExit;
|
|
emitter.count -= 1;
|
|
}
|
|
|
|
function emit (event, code, signal) {
|
|
if (emitter.emitted[event]) {
|
|
return
|
|
}
|
|
emitter.emitted[event] = true;
|
|
emitter.emit(event, code, signal);
|
|
}
|
|
|
|
// { <signal>: <listener fn>, ... }
|
|
var sigListeners = {};
|
|
signals.forEach(function (sig) {
|
|
sigListeners[sig] = function listener () {
|
|
// If there are no other listeners, an exit is coming!
|
|
// Simplest way: remove us and then re-send the signal.
|
|
// We know that this will kill the process, so we can
|
|
// safely emit now.
|
|
var listeners = process.listeners(sig);
|
|
if (listeners.length === emitter.count) {
|
|
unload();
|
|
emit('exit', null, sig);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', null, sig);
|
|
/* istanbul ignore next */
|
|
if (isWin && sig === 'SIGHUP') {
|
|
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
|
// so use a supported signal instead
|
|
sig = 'SIGINT';
|
|
}
|
|
process.kill(process.pid, sig);
|
|
}
|
|
};
|
|
});
|
|
|
|
var signals_1 = function () {
|
|
return signals
|
|
};
|
|
|
|
var load_1 = load;
|
|
|
|
var loaded = false;
|
|
|
|
function load () {
|
|
if (loaded) {
|
|
return
|
|
}
|
|
loaded = true;
|
|
|
|
// This is the number of onSignalExit's that are in play.
|
|
// It's important so that we can count the correct number of
|
|
// listeners on signals, and don't wait for the other one to
|
|
// handle it instead of us.
|
|
emitter.count += 1;
|
|
|
|
signals = signals.filter(function (sig) {
|
|
try {
|
|
process.on(sig, sigListeners[sig]);
|
|
return true
|
|
} catch (er) {
|
|
return false
|
|
}
|
|
});
|
|
|
|
process.emit = processEmit;
|
|
process.reallyExit = processReallyExit;
|
|
}
|
|
|
|
var originalProcessReallyExit = process.reallyExit;
|
|
function processReallyExit (code) {
|
|
process.exitCode = code || 0;
|
|
emit('exit', process.exitCode, null);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', process.exitCode, null);
|
|
/* istanbul ignore next */
|
|
originalProcessReallyExit.call(process, process.exitCode);
|
|
}
|
|
|
|
var originalProcessEmit = process.emit;
|
|
function processEmit (ev, arg) {
|
|
if (ev === 'exit') {
|
|
if (arg !== undefined) {
|
|
process.exitCode = arg;
|
|
}
|
|
var ret = originalProcessEmit.apply(this, arguments);
|
|
emit('exit', process.exitCode, null);
|
|
/* istanbul ignore next */
|
|
emit('afterexit', process.exitCode, null);
|
|
return ret
|
|
} else {
|
|
return originalProcessEmit.apply(this, arguments)
|
|
}
|
|
}
|
|
signalExit.unload = unload_1;
|
|
signalExit.signals = signals_1;
|
|
signalExit.load = load_1;
|
|
|
|
const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
|
|
|
|
// Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior
|
|
const spawnedKill$1 = (kill, signal = 'SIGTERM', options = {}) => {
|
|
const killResult = kill(signal);
|
|
setKillTimeout(kill, signal, options, killResult);
|
|
return killResult;
|
|
};
|
|
|
|
const setKillTimeout = (kill, signal, options, killResult) => {
|
|
if (!shouldForceKill(signal, options, killResult)) {
|
|
return;
|
|
}
|
|
|
|
const timeout = getForceKillAfterTimeout(options);
|
|
const t = setTimeout(() => {
|
|
kill('SIGKILL');
|
|
}, timeout);
|
|
|
|
// Guarded because there's no `.unref()` when `execa` is used in the renderer
|
|
// process in Electron. This cannot be tested since we don't run tests in
|
|
// Electron.
|
|
// istanbul ignore else
|
|
if (t.unref) {
|
|
t.unref();
|
|
}
|
|
};
|
|
|
|
const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => {
|
|
return isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
|
|
};
|
|
|
|
const isSigterm = signal => {
|
|
return signal === _os__default['default'].constants.signals.SIGTERM ||
|
|
(typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
|
|
};
|
|
|
|
const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {
|
|
if (forceKillAfterTimeout === true) {
|
|
return DEFAULT_FORCE_KILL_TIMEOUT;
|
|
}
|
|
|
|
if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
|
|
throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);
|
|
}
|
|
|
|
return forceKillAfterTimeout;
|
|
};
|
|
|
|
// `childProcess.cancel()`
|
|
const spawnedCancel$1 = (spawned, context) => {
|
|
const killResult = spawned.kill();
|
|
|
|
if (killResult) {
|
|
context.isCanceled = true;
|
|
}
|
|
};
|
|
|
|
const timeoutKill = (spawned, signal, reject) => {
|
|
spawned.kill(signal);
|
|
reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));
|
|
};
|
|
|
|
// `timeout` option handling
|
|
const setupTimeout$1 = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => {
|
|
if (timeout === 0 || timeout === undefined) {
|
|
return spawnedPromise;
|
|
}
|
|
|
|
let timeoutId;
|
|
const timeoutPromise = new Promise((resolve, reject) => {
|
|
timeoutId = setTimeout(() => {
|
|
timeoutKill(spawned, killSignal, reject);
|
|
}, timeout);
|
|
});
|
|
|
|
const safeSpawnedPromise = spawnedPromise.finally(() => {
|
|
clearTimeout(timeoutId);
|
|
});
|
|
|
|
return Promise.race([timeoutPromise, safeSpawnedPromise]);
|
|
};
|
|
|
|
const validateTimeout$1 = ({timeout}) => {
|
|
if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
|
|
throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
|
|
}
|
|
};
|
|
|
|
// `cleanup` option handling
|
|
const setExitHandler$1 = async (spawned, {cleanup, detached}, timedPromise) => {
|
|
if (!cleanup || detached) {
|
|
return timedPromise;
|
|
}
|
|
|
|
const removeExitHandler = signalExit(() => {
|
|
spawned.kill();
|
|
});
|
|
|
|
return timedPromise.finally(() => {
|
|
removeExitHandler();
|
|
});
|
|
};
|
|
|
|
var kill = {
|
|
spawnedKill: spawnedKill$1,
|
|
spawnedCancel: spawnedCancel$1,
|
|
setupTimeout: setupTimeout$1,
|
|
validateTimeout: validateTimeout$1,
|
|
setExitHandler: setExitHandler$1
|
|
};
|
|
|
|
const isStream = stream =>
|
|
stream !== null &&
|
|
typeof stream === 'object' &&
|
|
typeof stream.pipe === 'function';
|
|
|
|
isStream.writable = stream =>
|
|
isStream(stream) &&
|
|
stream.writable !== false &&
|
|
typeof stream._write === 'function' &&
|
|
typeof stream._writableState === 'object';
|
|
|
|
isStream.readable = stream =>
|
|
isStream(stream) &&
|
|
stream.readable !== false &&
|
|
typeof stream._read === 'function' &&
|
|
typeof stream._readableState === 'object';
|
|
|
|
isStream.duplex = stream =>
|
|
isStream.writable(stream) &&
|
|
isStream.readable(stream);
|
|
|
|
isStream.transform = stream =>
|
|
isStream.duplex(stream) &&
|
|
typeof stream._transform === 'function' &&
|
|
typeof stream._transformState === 'object';
|
|
|
|
var isStream_1 = isStream;
|
|
|
|
const {PassThrough: PassThroughStream} = require$$0__default['default'];
|
|
|
|
var bufferStream = options => {
|
|
options = {...options};
|
|
|
|
const {array} = options;
|
|
let {encoding} = options;
|
|
const isBuffer = encoding === 'buffer';
|
|
let objectMode = false;
|
|
|
|
if (array) {
|
|
objectMode = !(encoding || isBuffer);
|
|
} else {
|
|
encoding = encoding || 'utf8';
|
|
}
|
|
|
|
if (isBuffer) {
|
|
encoding = null;
|
|
}
|
|
|
|
const stream = new PassThroughStream({objectMode});
|
|
|
|
if (encoding) {
|
|
stream.setEncoding(encoding);
|
|
}
|
|
|
|
let length = 0;
|
|
const chunks = [];
|
|
|
|
stream.on('data', chunk => {
|
|
chunks.push(chunk);
|
|
|
|
if (objectMode) {
|
|
length = chunks.length;
|
|
} else {
|
|
length += chunk.length;
|
|
}
|
|
});
|
|
|
|
stream.getBufferedValue = () => {
|
|
if (array) {
|
|
return chunks;
|
|
}
|
|
|
|
return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
|
|
};
|
|
|
|
stream.getBufferedLength = () => length;
|
|
|
|
return stream;
|
|
};
|
|
|
|
const {constants: BufferConstants} = require$$0__default$1['default'];
|
|
|
|
const {promisify} = require$$1__default$1['default'];
|
|
|
|
|
|
const streamPipelinePromisified = promisify(require$$0__default['default'].pipeline);
|
|
|
|
class MaxBufferError extends Error {
|
|
constructor() {
|
|
super('maxBuffer exceeded');
|
|
this.name = 'MaxBufferError';
|
|
}
|
|
}
|
|
|
|
async function getStream(inputStream, options) {
|
|
if (!inputStream) {
|
|
throw new Error('Expected a stream');
|
|
}
|
|
|
|
options = {
|
|
maxBuffer: Infinity,
|
|
...options
|
|
};
|
|
|
|
const {maxBuffer} = options;
|
|
const stream = bufferStream(options);
|
|
|
|
await new Promise((resolve, reject) => {
|
|
const rejectPromise = error => {
|
|
// Don't retrieve an oversized buffer.
|
|
if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
|
|
error.bufferedData = stream.getBufferedValue();
|
|
}
|
|
|
|
reject(error);
|
|
};
|
|
|
|
(async () => {
|
|
try {
|
|
await streamPipelinePromisified(inputStream, stream);
|
|
resolve();
|
|
} catch (error) {
|
|
rejectPromise(error);
|
|
}
|
|
})();
|
|
|
|
stream.on('data', () => {
|
|
if (stream.getBufferedLength() > maxBuffer) {
|
|
rejectPromise(new MaxBufferError());
|
|
}
|
|
});
|
|
});
|
|
|
|
return stream.getBufferedValue();
|
|
}
|
|
|
|
var getStream_1 = getStream;
|
|
var buffer = (stream, options) => getStream(stream, {...options, encoding: 'buffer'});
|
|
var array = (stream, options) => getStream(stream, {...options, array: true});
|
|
var MaxBufferError_1 = MaxBufferError;
|
|
getStream_1.buffer = buffer;
|
|
getStream_1.array = array;
|
|
getStream_1.MaxBufferError = MaxBufferError_1;
|
|
|
|
const { PassThrough } = require$$0__default['default'];
|
|
|
|
var mergeStream = function (/*streams...*/) {
|
|
var sources = [];
|
|
var output = new PassThrough({objectMode: true});
|
|
|
|
output.setMaxListeners(0);
|
|
|
|
output.add = add;
|
|
output.isEmpty = isEmpty;
|
|
|
|
output.on('unpipe', remove);
|
|
|
|
Array.prototype.slice.call(arguments).forEach(add);
|
|
|
|
return output
|
|
|
|
function add (source) {
|
|
if (Array.isArray(source)) {
|
|
source.forEach(add);
|
|
return this
|
|
}
|
|
|
|
sources.push(source);
|
|
source.once('end', remove.bind(null, source));
|
|
source.once('error', output.emit.bind(output, 'error'));
|
|
source.pipe(output, {end: false});
|
|
return this
|
|
}
|
|
|
|
function isEmpty () {
|
|
return sources.length == 0;
|
|
}
|
|
|
|
function remove (source) {
|
|
sources = sources.filter(function (it) { return it !== source });
|
|
if (!sources.length && output.readable) { output.end(); }
|
|
}
|
|
};
|
|
|
|
// `input` option
|
|
const handleInput$1 = (spawned, input) => {
|
|
// Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
|
|
// @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
|
|
if (input === undefined || spawned.stdin === undefined) {
|
|
return;
|
|
}
|
|
|
|
if (isStream_1(input)) {
|
|
input.pipe(spawned.stdin);
|
|
} else {
|
|
spawned.stdin.end(input);
|
|
}
|
|
};
|
|
|
|
// `all` interleaves `stdout` and `stderr`
|
|
const makeAllStream$1 = (spawned, {all}) => {
|
|
if (!all || (!spawned.stdout && !spawned.stderr)) {
|
|
return;
|
|
}
|
|
|
|
const mixed = mergeStream();
|
|
|
|
if (spawned.stdout) {
|
|
mixed.add(spawned.stdout);
|
|
}
|
|
|
|
if (spawned.stderr) {
|
|
mixed.add(spawned.stderr);
|
|
}
|
|
|
|
return mixed;
|
|
};
|
|
|
|
// On failure, `result.stdout|stderr|all` should contain the currently buffered stream
|
|
const getBufferedData = async (stream, streamPromise) => {
|
|
if (!stream) {
|
|
return;
|
|
}
|
|
|
|
stream.destroy();
|
|
|
|
try {
|
|
return await streamPromise;
|
|
} catch (error) {
|
|
return error.bufferedData;
|
|
}
|
|
};
|
|
|
|
const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
|
|
if (!stream || !buffer) {
|
|
return;
|
|
}
|
|
|
|
if (encoding) {
|
|
return getStream_1(stream, {encoding, maxBuffer});
|
|
}
|
|
|
|
return getStream_1.buffer(stream, {maxBuffer});
|
|
};
|
|
|
|
// Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)
|
|
const getSpawnedResult$1 = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => {
|
|
const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});
|
|
const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});
|
|
const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});
|
|
|
|
try {
|
|
return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);
|
|
} catch (error) {
|
|
return Promise.all([
|
|
{error, signal: error.signal, timedOut: error.timedOut},
|
|
getBufferedData(stdout, stdoutPromise),
|
|
getBufferedData(stderr, stderrPromise),
|
|
getBufferedData(all, allPromise)
|
|
]);
|
|
}
|
|
};
|
|
|
|
const validateInputSync$1 = ({input}) => {
|
|
if (isStream_1(input)) {
|
|
throw new TypeError('The `input` option cannot be a stream in sync mode');
|
|
}
|
|
};
|
|
|
|
var stream = {
|
|
handleInput: handleInput$1,
|
|
makeAllStream: makeAllStream$1,
|
|
getSpawnedResult: getSpawnedResult$1,
|
|
validateInputSync: validateInputSync$1
|
|
};
|
|
|
|
const nativePromisePrototype = (async () => {})().constructor.prototype;
|
|
const descriptors = ['then', 'catch', 'finally'].map(property => [
|
|
property,
|
|
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property)
|
|
]);
|
|
|
|
// The return value is a mixin of `childProcess` and `Promise`
|
|
const mergePromise$1 = (spawned, promise) => {
|
|
for (const [property, descriptor] of descriptors) {
|
|
// Starting the main `promise` is deferred to avoid consuming streams
|
|
const value = typeof promise === 'function' ?
|
|
(...args) => Reflect.apply(descriptor.value, promise(), args) :
|
|
descriptor.value.bind(promise);
|
|
|
|
Reflect.defineProperty(spawned, property, {...descriptor, value});
|
|
}
|
|
|
|
return spawned;
|
|
};
|
|
|
|
// Use promises instead of `child_process` events
|
|
const getSpawnedPromise$1 = spawned => {
|
|
return new Promise((resolve, reject) => {
|
|
spawned.on('exit', (exitCode, signal) => {
|
|
resolve({exitCode, signal});
|
|
});
|
|
|
|
spawned.on('error', error => {
|
|
reject(error);
|
|
});
|
|
|
|
if (spawned.stdin) {
|
|
spawned.stdin.on('error', error => {
|
|
reject(error);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
var promise = {
|
|
mergePromise: mergePromise$1,
|
|
getSpawnedPromise: getSpawnedPromise$1
|
|
};
|
|
|
|
const normalizeArgs = (file, args = []) => {
|
|
if (!Array.isArray(args)) {
|
|
return [file];
|
|
}
|
|
|
|
return [file, ...args];
|
|
};
|
|
|
|
const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
|
|
const DOUBLE_QUOTES_REGEXP = /"/g;
|
|
|
|
const escapeArg = arg => {
|
|
if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
|
|
return arg;
|
|
}
|
|
|
|
return `"${arg.replace(DOUBLE_QUOTES_REGEXP, '\\"')}"`;
|
|
};
|
|
|
|
const joinCommand$1 = (file, args) => {
|
|
return normalizeArgs(file, args).join(' ');
|
|
};
|
|
|
|
const getEscapedCommand$1 = (file, args) => {
|
|
return normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' ');
|
|
};
|
|
|
|
const SPACES_REGEXP = / +/g;
|
|
|
|
// Handle `execa.command()`
|
|
const parseCommand$1 = command => {
|
|
const tokens = [];
|
|
for (const token of command.trim().split(SPACES_REGEXP)) {
|
|
// Allow spaces to be escaped by a backslash if not meant as a delimiter
|
|
const previousToken = tokens[tokens.length - 1];
|
|
if (previousToken && previousToken.endsWith('\\')) {
|
|
// Merge previous token with current one
|
|
tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;
|
|
} else {
|
|
tokens.push(token);
|
|
}
|
|
}
|
|
|
|
return tokens;
|
|
};
|
|
|
|
var command$1 = {
|
|
joinCommand: joinCommand$1,
|
|
getEscapedCommand: getEscapedCommand$1,
|
|
parseCommand: parseCommand$1
|
|
};
|
|
|
|
const {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} = kill;
|
|
const {handleInput, getSpawnedResult, makeAllStream, validateInputSync} = stream;
|
|
const {mergePromise, getSpawnedPromise} = promise;
|
|
const {joinCommand, parseCommand, getEscapedCommand} = command$1;
|
|
|
|
const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
|
|
|
|
const getEnv = ({env: envOption, extendEnv, preferLocal, localDir, execPath}) => {
|
|
const env = extendEnv ? {...process.env, ...envOption} : envOption;
|
|
|
|
if (preferLocal) {
|
|
return npmRunPath_1.env({env, cwd: localDir, execPath});
|
|
}
|
|
|
|
return env;
|
|
};
|
|
|
|
const handleArguments = (file, args, options = {}) => {
|
|
const parsed = crossSpawn._parse(file, args, options);
|
|
file = parsed.command;
|
|
args = parsed.args;
|
|
options = parsed.options;
|
|
|
|
options = {
|
|
maxBuffer: DEFAULT_MAX_BUFFER,
|
|
buffer: true,
|
|
stripFinalNewline: true,
|
|
extendEnv: true,
|
|
preferLocal: false,
|
|
localDir: options.cwd || process.cwd(),
|
|
execPath: process.execPath,
|
|
encoding: 'utf8',
|
|
reject: true,
|
|
cleanup: true,
|
|
all: false,
|
|
windowsHide: true,
|
|
...options
|
|
};
|
|
|
|
options.env = getEnv(options);
|
|
|
|
options.stdio = stdio(options);
|
|
|
|
if (process.platform === 'win32' && path__default['default'].basename(file, '.exe') === 'cmd') {
|
|
// #116
|
|
args.unshift('/q');
|
|
}
|
|
|
|
return {file, args, options, parsed};
|
|
};
|
|
|
|
const handleOutput = (options, value, error) => {
|
|
if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
|
|
// When `execa.sync()` errors, we normalize it to '' to mimic `execa()`
|
|
return error === undefined ? undefined : '';
|
|
}
|
|
|
|
if (options.stripFinalNewline) {
|
|
return stripFinalNewline(value);
|
|
}
|
|
|
|
return value;
|
|
};
|
|
|
|
const execa = (file, args, options) => {
|
|
const parsed = handleArguments(file, args, options);
|
|
const command = joinCommand(file, args);
|
|
const escapedCommand = getEscapedCommand(file, args);
|
|
|
|
validateTimeout(parsed.options);
|
|
|
|
let spawned;
|
|
try {
|
|
spawned = childProcess__default['default'].spawn(parsed.file, parsed.args, parsed.options);
|
|
} catch (error$1) {
|
|
// Ensure the returned error is always both a promise and a child process
|
|
const dummySpawned = new childProcess__default['default'].ChildProcess();
|
|
const errorPromise = Promise.reject(error({
|
|
error: error$1,
|
|
stdout: '',
|
|
stderr: '',
|
|
all: '',
|
|
command,
|
|
escapedCommand,
|
|
parsed,
|
|
timedOut: false,
|
|
isCanceled: false,
|
|
killed: false
|
|
}));
|
|
return mergePromise(dummySpawned, errorPromise);
|
|
}
|
|
|
|
const spawnedPromise = getSpawnedPromise(spawned);
|
|
const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);
|
|
const processDone = setExitHandler(spawned, parsed.options, timedPromise);
|
|
|
|
const context = {isCanceled: false};
|
|
|
|
spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));
|
|
spawned.cancel = spawnedCancel.bind(null, spawned, context);
|
|
|
|
const handlePromise = async () => {
|
|
const [{error: error$1, exitCode, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
|
|
const stdout = handleOutput(parsed.options, stdoutResult);
|
|
const stderr = handleOutput(parsed.options, stderrResult);
|
|
const all = handleOutput(parsed.options, allResult);
|
|
|
|
if (error$1 || exitCode !== 0 || signal !== null) {
|
|
const returnedError = error({
|
|
error: error$1,
|
|
exitCode,
|
|
signal,
|
|
stdout,
|
|
stderr,
|
|
all,
|
|
command,
|
|
escapedCommand,
|
|
parsed,
|
|
timedOut,
|
|
isCanceled: context.isCanceled,
|
|
killed: spawned.killed
|
|
});
|
|
|
|
if (!parsed.options.reject) {
|
|
return returnedError;
|
|
}
|
|
|
|
throw returnedError;
|
|
}
|
|
|
|
return {
|
|
command,
|
|
escapedCommand,
|
|
exitCode: 0,
|
|
stdout,
|
|
stderr,
|
|
all,
|
|
failed: false,
|
|
timedOut: false,
|
|
isCanceled: false,
|
|
killed: false
|
|
};
|
|
};
|
|
|
|
const handlePromiseOnce = onetime_1(handlePromise);
|
|
|
|
handleInput(spawned, parsed.options.input);
|
|
|
|
spawned.all = makeAllStream(spawned, parsed.options);
|
|
|
|
return mergePromise(spawned, handlePromiseOnce);
|
|
};
|
|
|
|
var execa_1 = execa;
|
|
|
|
var sync = (file, args, options) => {
|
|
const parsed = handleArguments(file, args, options);
|
|
const command = joinCommand(file, args);
|
|
const escapedCommand = getEscapedCommand(file, args);
|
|
|
|
validateInputSync(parsed.options);
|
|
|
|
let result;
|
|
try {
|
|
result = childProcess__default['default'].spawnSync(parsed.file, parsed.args, parsed.options);
|
|
} catch (error$1) {
|
|
throw error({
|
|
error: error$1,
|
|
stdout: '',
|
|
stderr: '',
|
|
all: '',
|
|
command,
|
|
escapedCommand,
|
|
parsed,
|
|
timedOut: false,
|
|
isCanceled: false,
|
|
killed: false
|
|
});
|
|
}
|
|
|
|
const stdout = handleOutput(parsed.options, result.stdout, result.error);
|
|
const stderr = handleOutput(parsed.options, result.stderr, result.error);
|
|
|
|
if (result.error || result.status !== 0 || result.signal !== null) {
|
|
const error$1 = error({
|
|
stdout,
|
|
stderr,
|
|
error: result.error,
|
|
signal: result.signal,
|
|
exitCode: result.status,
|
|
command,
|
|
escapedCommand,
|
|
parsed,
|
|
timedOut: result.error && result.error.code === 'ETIMEDOUT',
|
|
isCanceled: false,
|
|
killed: result.signal !== null
|
|
});
|
|
|
|
if (!parsed.options.reject) {
|
|
return error$1;
|
|
}
|
|
|
|
throw error$1;
|
|
}
|
|
|
|
return {
|
|
command,
|
|
escapedCommand,
|
|
exitCode: 0,
|
|
stdout,
|
|
stderr,
|
|
failed: false,
|
|
timedOut: false,
|
|
isCanceled: false,
|
|
killed: false
|
|
};
|
|
};
|
|
|
|
var command = (command, options) => {
|
|
const [file, ...args] = parseCommand(command);
|
|
return execa(file, args, options);
|
|
};
|
|
|
|
var commandSync = (command, options) => {
|
|
const [file, ...args] = parseCommand(command);
|
|
return execa.sync(file, args, options);
|
|
};
|
|
|
|
var node = (scriptPath, args, options = {}) => {
|
|
if (args && !Array.isArray(args) && typeof args === 'object') {
|
|
options = args;
|
|
args = [];
|
|
}
|
|
|
|
const stdio$1 = stdio.node(options);
|
|
const defaultExecArgv = process.execArgv.filter(arg => !arg.startsWith('--inspect'));
|
|
|
|
const {
|
|
nodePath = process.execPath,
|
|
nodeOptions = defaultExecArgv
|
|
} = options;
|
|
|
|
return execa(
|
|
nodePath,
|
|
[
|
|
...nodeOptions,
|
|
scriptPath,
|
|
...(Array.isArray(args) ? args : [])
|
|
],
|
|
{
|
|
...options,
|
|
stdin: undefined,
|
|
stdout: undefined,
|
|
stderr: undefined,
|
|
stdio: stdio$1,
|
|
shell: false
|
|
}
|
|
);
|
|
};
|
|
execa_1.sync = sync;
|
|
execa_1.command = command;
|
|
execa_1.commandSync = commandSync;
|
|
execa_1.node = node;
|
|
|
|
async function runAppleScriptAsync(script) {
|
|
if (process.platform !== 'darwin') {
|
|
throw new Error('macOS only');
|
|
}
|
|
|
|
const {stdout} = await execa_1('osascript', ['-e', script]);
|
|
return stdout;
|
|
}
|
|
|
|
obsidian.addIcon('DEVONthink-logo-neutral', `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
<svg width="100%" height="100%" viewBox="0 0 75 70" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
|
|
<g transform="matrix(1,0,0,1,-24,-28)">
|
|
<g>
|
|
<path d="M49.214,61.093L27.76,73.903C27.76,73.903 33.326,94.068 60.807,94.212C84.019,94.333 94.959,74.348 95.626,63.402C96.311,52.176 90.679,31.855 69.477,31.855C43.67,31.855 47.178,59.386 49.214,61.093Z" style="fill:none;stroke:currentColor;stroke-width:6px;"/>
|
|
<path d="M65.37,59.193C56.43,57.776 60.045,46.29 67.466,46.434C72.172,46.525 77.034,49.196 77.319,57.169C77.529,63.05 73.829,69.654 63.674,69.882C53.519,70.11 49.214,61.093 49.214,61.093C49.214,61.093 55.701,71.918 47.914,78.584C38.756,86.423 27.922,73.893 27.922,73.893" style="fill:none;stroke:currentColor;stroke-width:6px;"/>
|
|
</g>
|
|
</g>
|
|
</svg>
|
|
`);
|
|
obsidian.addIcon('DEVONthink-logo-blue', `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
<svg width="100%" height="100%" viewBox="0 0 75 70" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
|
|
<g transform="matrix(1,0,0,1,-24,-28)">
|
|
<g>
|
|
<path d="M49.214,61.093L27.76,73.903C27.76,73.903 33.326,94.068 60.807,94.212C84.019,94.333 94.959,74.348 95.626,63.402C96.311,52.176 90.679,31.855 69.477,31.855C43.67,31.855 47.178,59.386 49.214,61.093Z" style="fill:none;stroke:#36C6EE;stroke-width:6px;"/>
|
|
<path d="M65.37,59.193C56.43,57.776 60.045,46.29 67.466,46.434C72.172,46.525 77.034,49.196 77.319,57.169C77.529,63.05 73.829,69.654 63.674,69.882C53.519,70.11 49.214,61.093 49.214,61.093C49.214,61.093 55.701,71.918 47.914,78.584C38.756,86.423 27.922,73.893 27.922,73.893" style="fill:none;stroke:#36C6EE;stroke-width:6px;"/>
|
|
</g>
|
|
</g>
|
|
</svg>
|
|
`);
|
|
const DEFAULT_SETTINGS = {
|
|
ribbonButtonAction: 'open',
|
|
DEVONlinkIconColor: 'DEVONthink-logo-blue',
|
|
maximumRelatedItemsSetting: 10,
|
|
relatedItemsPrefixSetting: "- ",
|
|
linkTypeSetting: "Intelligent Linking"
|
|
};
|
|
class DEVONlinkPlugin extends obsidian.Plugin {
|
|
onload() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
console.log('Loading the DEVONlink plugin.');
|
|
yield this.loadSettings();
|
|
this.ribbonIcon = this.addRibbonIcon(this.settings.DEVONlinkIconColor, 'DEVONlink', () => {
|
|
this.doRibbonAction();
|
|
});
|
|
this.addCommand({
|
|
id: 'open-indexed-note-in-DEVONthink',
|
|
name: 'Open indexed note in DEVONthink',
|
|
checkCallback: this.openInDEVONthink.bind(this)
|
|
});
|
|
this.addCommand({
|
|
id: 'reveal-indexed-note-in-DEVONthink',
|
|
name: 'Reveal indexed note in DEVONthink',
|
|
checkCallback: this.revealInDEVONthink.bind(this)
|
|
});
|
|
this.addCommand({
|
|
id: 'insert-related-items-from-DEVONthink-analysis',
|
|
name: 'Insert related items from DEVONthink concordance',
|
|
checkCallback: this.insertRelatedFromDEVONthink.bind(this)
|
|
});
|
|
this.addSettingTab(new DEVONlinkSettingsTab(this.app, this));
|
|
});
|
|
}
|
|
onunload() {
|
|
console.log('Unloading the DEVONlink plugin');
|
|
}
|
|
resetRibbonIcon() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
this.ribbonIcon.detach();
|
|
this.ribbonIcon = this.addRibbonIcon(this.settings.DEVONlinkIconColor, 'DEVONlink', () => {
|
|
this.doRibbonAction();
|
|
});
|
|
});
|
|
}
|
|
loadSettings() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
|
|
});
|
|
}
|
|
saveSettings() {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
yield this.saveData(this.settings);
|
|
});
|
|
}
|
|
doRibbonAction() {
|
|
if (this.settings.ribbonButtonAction == "open") {
|
|
this.openInDEVONthink(false);
|
|
}
|
|
else if (this.settings.ribbonButtonAction == "reveal") {
|
|
this.revealInDEVONthink(false);
|
|
}
|
|
else if (this.settings.ribbonButtonAction == "related") {
|
|
this.insertRelatedFromDEVONthink(false);
|
|
}
|
|
}
|
|
;
|
|
getVaultPath(someVaultAdapter) {
|
|
return someVaultAdapter.getBasePath();
|
|
}
|
|
insertRelatedFromDEVONthink(checking) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const activeView = this.app.workspace.getActiveViewOfType(obsidian.MarkdownView);
|
|
let activeFile = this.app.workspace.getActiveFile();
|
|
if (!checking) {
|
|
if (activeView) {
|
|
const editor = activeView.editor;
|
|
let noteFilename = activeFile.name;
|
|
let vaultAdapter = this.app.vault.adapter;
|
|
let maximumRelatedItemsSetting = this.settings.maximumRelatedItemsSetting;
|
|
let relatedItemsPrefix = this.settings.relatedItemsPrefixSetting;
|
|
let vaultName = this.app.vault.getName();
|
|
// let fullNotePath = `${this.app.vault.adapter.basePath}/${activeFile.name}`; // Not actually the "full' path, can't catch folders within the Vault
|
|
if (vaultAdapter instanceof obsidian.FileSystemAdapter) {
|
|
// let vaultPath = vaultAdapter.getBasePath(); // No longer needed, but leaving it in in case I ever decide to return to try to figure out how to get the path right. It would be a more robust solution than relying on filenames.
|
|
// let homeFolderPath = await runAppleScriptAsync('get POSIX path of the (path to home folder)'); // see above
|
|
// attempting to get path to work: await runAppleScriptAsync('tell application id "DNtp" to open window for record (first item in (lookup records with path "~' + vaultPath + '/' + notePath + '") in database (get database with uuid "'+ this.settings.databaseUUID + '")) with force'); // see above
|
|
let currentLinkType = this.settings.linkTypeSetting;
|
|
let wikiLinkLine = `"${relatedItemsPrefix}" & "[[" & name of eachRecord & "]]" & return`;
|
|
let DEVONthinkLinkLine = `"${relatedItemsPrefix}" & "[" & name of eachRecord & "](" & reference URL of eachRecord & ")" & return`;
|
|
let appleScript = `tell application id "DNtp"
|
|
if not running then
|
|
run
|
|
end if
|
|
try
|
|
set theDatabases to databases
|
|
repeat with thisDatabase in theDatabases
|
|
set theNoteRecords to (lookup records with file "${noteFilename}" in thisDatabase)
|
|
if theNoteRecords is not {} then
|
|
set theNoteRecord to the first item in theNoteRecords
|
|
try
|
|
set seeAlso to compare record theNoteRecord to theNoteRecord's database
|
|
set listOfRecords to ""
|
|
set maximumItems to ${maximumRelatedItemsSetting}
|
|
set itemCount to 0
|
|
repeat with eachRecord in seeAlso
|
|
if itemCount is not 0 then
|
|
if itemCount is greater than maximumItems then
|
|
return listOfRecords
|
|
else
|
|
if ("${currentLinkType}" is equal to "intelligentLinking") then
|
|
if eachRecord's type is markdown then
|
|
if eachRecord's path contains "${vaultName}" then
|
|
set listOfRecords to listOfRecords & ${wikiLinkLine}
|
|
else
|
|
set listOfRecords to listOfRecords & ${DEVONthinkLinkLine}
|
|
end if
|
|
else
|
|
set listOfRecords to listOfRecords & ${DEVONthinkLinkLine}
|
|
end if
|
|
else if ("${currentLinkType}" is equal to "wikiLinks") then
|
|
set listOfRecords to listOfRecords & ${wikiLinkLine}
|
|
else if ("${currentLinkType}" is equal to "devonthinkURL") then
|
|
set listOfRecords to listOfRecords & ${DEVONthinkLinkLine}
|
|
end if
|
|
end if
|
|
end if
|
|
set itemCount to itemCount + 1
|
|
end repeat
|
|
return listOfRecords
|
|
on error
|
|
return "failure"
|
|
end try
|
|
end if
|
|
end repeat
|
|
return "failure"
|
|
end try
|
|
end tell`;
|
|
let DEVONlinkResults = yield runAppleScriptAsync(appleScript);
|
|
if (DEVONlinkResults == "failure") {
|
|
new obsidian.Notice("Sorry, DEVONlink couldn't find a matching record in your DEVONthink databases. Make sure your notes are indexed, the index is up to date, and the DEVONthink database with the indexed notes is open.");
|
|
console.log("Debugging DEVONlink. Failed filename: '" + noteFilename + "'.");
|
|
}
|
|
else {
|
|
console.log(DEVONlinkResults);
|
|
editor.getCursor();
|
|
// let lineText = editor.getLine(cursor.line);
|
|
editor.replaceSelection(DEVONlinkResults);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
else {
|
|
new obsidian.Notice("No active pane. Try again with a note open in edit mode.");
|
|
}
|
|
}
|
|
return false;
|
|
});
|
|
}
|
|
openInDEVONthink(checking) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
let activeFile = this.app.workspace.getActiveFile();
|
|
if (!checking) {
|
|
if (activeFile) {
|
|
let noteFilename = activeFile.name;
|
|
let vaultAdapter = this.app.vault.adapter;
|
|
if (vaultAdapter instanceof obsidian.FileSystemAdapter) {
|
|
// let vaultPath = vaultAdapter.getBasePath(); // No longer needed, but leaving it in in case I ever decide to return to try to figure out how to get the path right. It would be a more robust solution than relying on filenames.
|
|
// let homeFolderPath = await runAppleScriptAsync('get POSIX path of the (path to home folder)'); // see above
|
|
// attempting to get path to work: await runAppleScriptAsync('tell application id "DNtp" to open window for record (first item in (lookup records with path "~' + vaultPath + '/' + notePath + '") in database (get database with uuid "'+ this.settings.databaseUUID + '")) with force'); // see above
|
|
let DEVONlinkResults = yield runAppleScriptAsync(`tell application id "DNtp"
|
|
activate
|
|
try
|
|
set theDatabases to databases
|
|
repeat with thisDatabase in theDatabases
|
|
try
|
|
set theNoteRecord to (first item in (lookup records with file "${noteFilename}" in thisDatabase))
|
|
set newDEVONthinkWindow to open window for record theNoteRecord with force
|
|
activate
|
|
return "success"
|
|
end try
|
|
end repeat
|
|
on error
|
|
return "failure"
|
|
end try
|
|
end tell`);
|
|
if (DEVONlinkResults != "success") {
|
|
new obsidian.Notice("Sorry, DEVONlink couldn't find a matching record in your DEVONthink databases. Make sure your notes are indexed, the index is up to date, and the DEVONthink database with the indexed notes is open.");
|
|
console.log("Debugging DEVONlink. Failed filename: '" + noteFilename + "'.");
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
else {
|
|
new obsidian.Notice("No active pane. Try again with a note open.");
|
|
}
|
|
}
|
|
return false;
|
|
});
|
|
}
|
|
revealInDEVONthink(checking) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
let activeFile = this.app.workspace.getActiveFile();
|
|
if (!checking) {
|
|
if (activeFile) {
|
|
let noteFilename = activeFile.name;
|
|
let vaultAdapter = this.app.vault.adapter;
|
|
if (vaultAdapter instanceof obsidian.FileSystemAdapter) {
|
|
// let vaultPath = vaultAdapter.getBasePath(); // No longer needed, but leaving it in in case I ever decide to return to try to figure out how to get the path right. It would be a more robust solution than relying on filenames.
|
|
// let homeFolderPath = await runAppleScriptAsync('get POSIX path of the (path to home folder)'); // see above
|
|
// attempting to get path to work: await runAppleScriptAsync('tell application id "DNtp" to open window for record (first item in (lookup records with path "~' + vaultPath + '/' + notePath + '") in database (get database with uuid "'+ this.settings.databaseUUID + '")) with force'); // see above
|
|
let DEVONlinkResults = yield runAppleScriptAsync(`tell application id "DNtp"
|
|
activate
|
|
try
|
|
set theDatabases to databases
|
|
repeat with thisDatabase in theDatabases
|
|
try
|
|
set theNoteRecord to (first item in (lookup records with file "${noteFilename}" in thisDatabase))
|
|
set theParentRecord to the first parent of theNoteRecord
|
|
set newDEVONthinkWindow to open window for record theParentRecord with force
|
|
set newDEVONthinkWindow's selection to theNoteRecord as list
|
|
activate
|
|
return "success"
|
|
end try
|
|
end repeat
|
|
on error
|
|
return "failure"
|
|
end try
|
|
end tell`);
|
|
if (DEVONlinkResults != "success") {
|
|
new obsidian.Notice("Sorry, DEVONlink couldn't find a matching record in your DEVONthink databases. Make sure your notes are indexed, the index is up to date, and the DEVONthink database with the indexed notes is open.");
|
|
console.log("Debugging DEVONlink. Failed filename: '" + noteFilename + "'.");
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
else {
|
|
new obsidian.Notice("No active pane. Try again with a note open.");
|
|
}
|
|
}
|
|
return false;
|
|
});
|
|
}
|
|
}
|
|
class DEVONlinkSettingsTab extends obsidian.PluginSettingTab {
|
|
constructor(app, plugin) {
|
|
super(app, plugin);
|
|
this.plugin = plugin;
|
|
}
|
|
display() {
|
|
let { containerEl } = this;
|
|
containerEl.empty();
|
|
containerEl.createEl('h2', { text: 'DEVONlink Settings' });
|
|
new obsidian.Setting(containerEl)
|
|
.setName('Ribbon button action')
|
|
.setDesc('Should the ribbon button open the note in DEVONthink, or reveal it in the DEVONthink database?')
|
|
.addDropdown(buttonMenu => buttonMenu
|
|
.addOption("open", "Open the note in the database")
|
|
.addOption("reveal", "Reveal the note in the database")
|
|
.addOption("related", "Insert a list of items related to the active note")
|
|
.setValue(this.plugin.settings.ribbonButtonAction)
|
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
|
this.plugin.settings.ribbonButtonAction = value;
|
|
yield this.plugin.saveSettings();
|
|
})));
|
|
new obsidian.Setting(containerEl)
|
|
.setName('Ribbon button colour')
|
|
.setDesc('Should the ribbon button be DEVONthink blue or inherit the theme colour?')
|
|
.addDropdown(buttonMenu => buttonMenu
|
|
.addOption("DEVONthink-logo-neutral", "Inherit the theme colour")
|
|
.addOption("DEVONthink-logo-blue", "DEVONthink blue")
|
|
.setValue(this.plugin.settings.DEVONlinkIconColor)
|
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
|
this.plugin.settings.DEVONlinkIconColor = value;
|
|
this.plugin.resetRibbonIcon();
|
|
yield this.plugin.saveSettings();
|
|
})));
|
|
new obsidian.Setting(containerEl)
|
|
.setName('Maximum items returned with the Related Items command')
|
|
.setDesc('Set the maximum number of related items DEVONlink will try to return when using the Related Items command.')
|
|
.addText(textbox => textbox
|
|
.setValue(this.plugin.settings.maximumRelatedItemsSetting.toString())
|
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
|
if (Number(value)) {
|
|
this.plugin.settings.maximumRelatedItemsSetting = Number(value);
|
|
yield this.plugin.saveSettings();
|
|
}
|
|
else {
|
|
new obsidian.Notice("It looks like you haven't entered a number. Please use integers (e.g.: 1, 2, or 3) only. Resetting the maximum related items to the default value of 5.");
|
|
this.plugin.settings.maximumRelatedItemsSetting = 5;
|
|
yield this.plugin.saveSettings();
|
|
}
|
|
})));
|
|
new obsidian.Setting(containerEl)
|
|
.setName('Related items list prefix')
|
|
.setDesc('The Related Items command returns a list of `[[`-wrapped file names. This setting allows you to configure what the list items look like. E.g., use `- ` for a bulleted list or `!` for embeds.')
|
|
.addText(textbox => textbox
|
|
.setValue(this.plugin.settings.relatedItemsPrefixSetting)
|
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
|
this.plugin.settings.relatedItemsPrefixSetting = value;
|
|
yield this.plugin.saveSettings();
|
|
})));
|
|
new obsidian.Setting(containerEl)
|
|
.setName('Link type for related items')
|
|
.setDesc('Set the type of link returned by the Related Items command')
|
|
.addDropdown(buttonMenu => buttonMenu
|
|
.addOption("wikilinks", "[[Wikilinks]]")
|
|
.addOption("devonthinkURL", "DEVONthink x-devonthink-item links")
|
|
/*
|
|
* "Wikilinks") {
|
|
linkLine = `"${relatedItemsPrefix}" & "[[" & name of eachRecord & "]]" & return`
|
|
} else if (currentLinkType == "DEVONthink URL") {
|
|
linkLine = `"${relatedItemsPrefix}" & "[" & name of eachRecord & "](" & reference URL of eachRecord & ")" & return`
|
|
} else if (currentLinkType == "Intelligent Linking") {
|
|
* */
|
|
.addOption("intelligentLinking", "Automatically switch between Wikilinks and DEVONthink URL")
|
|
.setValue(this.plugin.settings.linkTypeSetting)
|
|
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
|
|
this.plugin.settings.linkTypeSetting = value;
|
|
yield this.plugin.saveSettings();
|
|
})));
|
|
}
|
|
}
|
|
|
|
module.exports = DEVONlinkPlugin;
|
|
|
|
|
|
/* nosourcemap */ |