UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

531 lines (515 loc) 17.2 kB
import { __commonJS, __require } from './chunk-NYLAFCGV.mjs'; // ../../node_modules/isexe/windows.js var require_windows = __commonJS({ "../../node_modules/isexe/windows.js"(exports, module) { module.exports = isexe; isexe.sync = sync; var fs = __require("fs"); function checkPathExt(path, options) { var pathext = options.pathExt !== void 0 ? 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(stat, path, options) { if (!stat.isSymbolicLink() && !stat.isFile()) { return false; } return checkPathExt(path, options); } function isexe(path, options, cb) { fs.stat(path, function(er, stat) { cb(er, er ? false : checkStat(stat, path, options)); }); } function sync(path, options) { return checkStat(fs.statSync(path), path, options); } } }); // ../../node_modules/isexe/mode.js var require_mode = __commonJS({ "../../node_modules/isexe/mode.js"(exports, module) { module.exports = isexe; isexe.sync = sync; var fs = __require("fs"); function isexe(path, options, cb) { fs.stat(path, function(er, stat) { cb(er, er ? false : checkStat(stat, options)); }); } function sync(path, options) { return checkStat(fs.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 !== void 0 ? options.uid : process.getuid && process.getuid(); var myGid = options.gid !== void 0 ? 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; } } }); // ../../node_modules/isexe/index.js var require_isexe = __commonJS({ "../../node_modules/isexe/index.js"(exports, module) { __require("fs"); var core; if (process.platform === "win32" || global.TESTING_WINDOWS) { core = require_windows(); } else { core = require_mode(); } module.exports = isexe; isexe.sync = sync; 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(path, options || {}, function(er, is) { if (er) { if (er.code === "EACCES" || options && options.ignoreErrors) { er = null; is = false; } } cb(er, is); }); } function sync(path, options) { try { return core.sync(path, options || {}); } catch (er) { if (options && options.ignoreErrors || er.code === "EACCES") { return false; } else { throw er; } } } } }); // ../../node_modules/which/which.js var require_which = __commonJS({ "../../node_modules/which/which.js"(exports, module) { var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys"; var path = __require("path"); var COLON = isWindows ? ";" : ":"; var isexe = require_isexe(); var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" }); var getPathInfo = (cmd, opt) => { const colon = opt.colon || COLON; 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 }; }; var 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.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(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); }; var 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.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.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); }; module.exports = which; which.sync = whichSync; } }); // ../../node_modules/path-key/index.js var require_path_key = __commonJS({ "../../node_modules/path-key/index.js"(exports, module) { var 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"; }; module.exports = pathKey; module.exports.default = pathKey; } }); // ../../node_modules/cross-spawn/lib/util/resolveCommand.js var require_resolveCommand = __commonJS({ "../../node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) { var path = __require("path"); var which = require_which(); var getPathKey = require_path_key(); function resolveCommandAttempt(parsed, withoutPathExt) { const env = parsed.options.env || process.env; const cwd = process.cwd(); const hasCustomCwd = parsed.options.cwd != null; const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled; if (shouldSwitchCwd) { try { process.chdir(parsed.options.cwd); } catch (err) { } } let resolved; try { resolved = which.sync(parsed.command, { path: env[getPathKey({ env })], pathExt: withoutPathExt ? path.delimiter : void 0 }); } catch (e) { } finally { if (shouldSwitchCwd) { process.chdir(cwd); } } if (resolved) { resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved); } return resolved; } function resolveCommand(parsed) { return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true); } module.exports = resolveCommand; } }); // ../../node_modules/cross-spawn/lib/util/escape.js var require_escape = __commonJS({ "../../node_modules/cross-spawn/lib/util/escape.js"(exports, module) { var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g; function escapeCommand(arg) { arg = arg.replace(metaCharsRegExp, "^$1"); return arg; } function escapeArgument(arg, doubleEscapeMetaChars) { arg = `${arg}`; arg = arg.replace(/(\\*)"/g, '$1$1\\"'); arg = arg.replace(/(\\*)$/, "$1$1"); arg = `"${arg}"`; arg = arg.replace(metaCharsRegExp, "^$1"); if (doubleEscapeMetaChars) { arg = arg.replace(metaCharsRegExp, "^$1"); } return arg; } module.exports.command = escapeCommand; module.exports.argument = escapeArgument; } }); // ../../node_modules/cross-spawn/node_modules/shebang-regex/index.js var require_shebang_regex = __commonJS({ "../../node_modules/cross-spawn/node_modules/shebang-regex/index.js"(exports, module) { module.exports = /^#!(.*)/; } }); // ../../node_modules/cross-spawn/node_modules/shebang-command/index.js var require_shebang_command = __commonJS({ "../../node_modules/cross-spawn/node_modules/shebang-command/index.js"(exports, module) { var shebangRegex = require_shebang_regex(); module.exports = (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; }; } }); // ../../node_modules/cross-spawn/lib/util/readShebang.js var require_readShebang = __commonJS({ "../../node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) { var fs = __require("fs"); var shebangCommand = require_shebang_command(); function readShebang(command) { const size = 150; const buffer = Buffer.alloc(size); let fd; try { fd = fs.openSync(command, "r"); fs.readSync(fd, buffer, 0, size, 0); fs.closeSync(fd); } catch (e) { } return shebangCommand(buffer.toString()); } module.exports = readShebang; } }); // ../../node_modules/cross-spawn/lib/parse.js var require_parse = __commonJS({ "../../node_modules/cross-spawn/lib/parse.js"(exports, module) { var path = __require("path"); var resolveCommand = require_resolveCommand(); var escape = require_escape(); var readShebang = require_readShebang(); var isWin = process.platform === "win32"; var isExecutableRegExp = /\.(?:com|exe)$/i; var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i; function detectShebang(parsed) { parsed.file = resolveCommand(parsed); const shebang = parsed.file && readShebang(parsed.file); if (shebang) { parsed.args.unshift(parsed.file); parsed.command = shebang; return resolveCommand(parsed); } return parsed.file; } function parseNonShell(parsed) { if (!isWin) { return parsed; } const commandFile = detectShebang(parsed); const needsShell = !isExecutableRegExp.test(commandFile); if (parsed.options.forceShell || needsShell) { const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile); parsed.command = path.normalize(parsed.command); 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; } return parsed; } function parse(command, args, options) { if (args && !Array.isArray(args)) { options = args; args = null; } args = args ? args.slice(0) : []; options = Object.assign({}, options); const parsed = { command, args, options, file: void 0, original: { command, args } }; return options.shell ? parsed : parseNonShell(parsed); } module.exports = parse; } }); // ../../node_modules/cross-spawn/lib/enoent.js var require_enoent = __commonJS({ "../../node_modules/cross-spawn/lib/enoent.js"(exports, module) { var isWin = 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) { return; } const originalEmit = cp.emit; cp.emit = function(name, arg1) { if (name === "exit") { const err = verifyENOENT(arg1, parsed); if (err) { return originalEmit.call(cp, "error", err); } } return originalEmit.apply(cp, arguments); }; } function verifyENOENT(status, parsed) { if (isWin && status === 1 && !parsed.file) { return notFoundError(parsed.original, "spawn"); } return null; } function verifyENOENTSync(status, parsed) { if (isWin && status === 1 && !parsed.file) { return notFoundError(parsed.original, "spawnSync"); } return null; } module.exports = { hookChildProcess, verifyENOENT, verifyENOENTSync, notFoundError }; } }); // ../../node_modules/cross-spawn/index.js var require_cross_spawn = __commonJS({ "../../node_modules/cross-spawn/index.js"(exports, module) { var cp = __require("child_process"); var parse = require_parse(); var enoent = require_enoent(); function spawn(command, args, options) { const parsed = parse(command, args, options); const spawned = cp.spawn(parsed.command, parsed.args, parsed.options); enoent.hookChildProcess(spawned, parsed); return spawned; } function spawnSync(command, args, options) { const parsed = parse(command, args, options); const result = cp.spawnSync(parsed.command, parsed.args, parsed.options); result.error = result.error || enoent.verifyENOENTSync(result.status, parsed); return result; } module.exports = spawn; module.exports.spawn = spawn; module.exports.sync = spawnSync; module.exports._parse = parse; module.exports._enoent = enoent; } }); // ../../node_modules/merge-stream/index.js var require_merge_stream = __commonJS({ "../../node_modules/merge-stream/index.js"(exports, module) { var { PassThrough } = __require("stream"); module.exports = function() { 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(); } } }; } }); export { require_cross_spawn, require_merge_stream, require_path_key };