diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index d1ad248..9e6614c 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -19,9 +19,9 @@ jobs: node-version: [12.x, 14.x, 16.x, 18.x] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm ci diff --git a/.gitignore b/.gitignore index 2ea9c66..176cf06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# typescript output +/dist + # Logs logs *.log diff --git a/index.js b/index.js index 3b472a6..ef0bc9d 100644 --- a/index.js +++ b/index.js @@ -1,468 +1,2 @@ -'use strict'; - -import which from 'which'; -import { spawn, fork } from 'child_process'; -import { dirname, join } from 'path'; -import { fileURLToPath } from 'url'; -import { createRequire } from 'module'; - -const __filename = fileURLToPath( - import.meta.url); -const __dirname = dirname(__filename); -const sync = which.sync; - -/** - * Supported package commands - */ -const SYS_COMMANDS = { - brew: 'brew install', - port: 'sudo port install', - pkgin: 'sudo pkgin install', - winget: 'winget install', - choco: 'choco install', - powershell: "powershell 'Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))'", - 'apt-get': 'sudo apt-get install', - yum: 'sudo yum install', - dnf: 'sudo dnf install', - nix: 'nix-env --install', - zypper: 'sudo zypper in', - emerge: 'sudo emerge -a', - pacman: 'sudo pacman -S', - pkg: 'pkg install', - pkg_add: 'pkg_add', - crew: 'crew install' -}; - -/** - * Supported package managers - */ -const SYS_MANAGERS = { - darwin: ['brew', 'port', 'pkgin'], - win32: ['winget', 'choco', 'powershell'], - linux: ['apt-get', 'yum', 'dnf', 'nix', 'zypper', 'emerge', 'pacman', 'crew'], - freebsd: ['pkg', 'pkg_add'], - sunos: ['pkg'], - netbsd: ['none'], - win64: ['choco'], - shell: ['powershell'], -}; - -function Sys() { } - -function sysManager() { - let managers = SYS_MANAGERS[process.platform]; - if (!managers || !managers.length) { - return 'unknown platform \'' + process.platform + '\''; - } - - managers = managers.filter(function (mng) { - return (where(mng) !== null); - }); - - if (!managers.length) { - return 'System OS package manager not found'; - } - - return SYS_COMMANDS[managers[0]].split(' '); -} - -/** - * Gets the system package manager install command. - * - * @returns {Object} - *``` - * sudo: boolean, // true or false, - * command: string, // 'apk-get' - system package manager command, - * installer: string, // 'sudo apk-get install' - full install command - *``` - * - Defaults to 'get os-manager installer' if no package manager is found. - * - * @throws if `process.platform` is none of darwin, freebsd, linux, sunos or win32. - */ -export const packager = Sys.packager = function () { - let sys = sysManager(); - if (isArray(sys) && sys[0]) - return { - sudo: (sys[0] === 'sudo'), - command: ((!sys[2]) ? sys[0] : sys[1]), - installer: sys.join(' ') - } - else - return new Error(sys); -}; - -/** - * Install package using the system package manager command. - * - * @param {String|Array} application package to install. - * @param {Function} progress callback for any output doing installation. - * - Any value returned in `callback` will be the final resolved result. - * - * @returns {Promise} Promise Output of spawn command. - * - E.g. 'sudo apg-get install' for Debian based systems. - * - Defaults to 'get os-manager installer' if no package manager is found. - * @rejects On any spawn error, or if `process.platform` is none of - * darwin, freebsd, linux, sunos or win32. - */ -export const installer = Sys.installer = function (application, progress) { - if (!application) - return new Promise((resolve, reject) => { return reject("No package, application name missing."); }); - - let manager = sysManager(); - if (!isArray(manager)) - return new Promise((resolve, reject) => { return reject(manager); }); - let cmd = manager[0]; - let args = null; - let install = null; - if (manager[1]) - args = [manager[1]]; - if (manager[2]) - install = [manager[2]]; - - let silentCmd = isWindows() ? ['--accept-package-agreements', '--accept-source-agreements', '-h'] : ['-y']; - let whatToInstall = isArray(application) ? [].concat(application).concat(silentCmd) : [].concat([application]).concat(silentCmd); - let system = whatToInstall; - if ((args) && (!install)) - system = args.concat(whatToInstall); - else if ((args) && (install)) - system = args.concat(install).concat(whatToInstall); - - if (cmd != 'powershell') { - if (cmd.includes('choco') && isWindows()) { - cmd = where('choco'); - system = [cmd].concat(system); - cmd = join(__dirname, 'bin', 'sudo.bat'); - } - - return spawning(cmd, system, progress); - } else { - return new Promise((resolve, reject) => { return reject('No package manager installed!') }); - } -} - -/** - * Like the unix `which` utility. - * - * Finds the first instance of a specified executable in the PATH environment variable. - * - * @param String executable - * - * @returns String|Null - */ -export const where = Sys.where = function (executable) { - let found = sync(executable, { - nothrow: true - }); - - return found; -} - -/** - * Spawn subprocess with `Promise` features, pass callbacks for `.on('data')` events, with ability to run as admin. - * - * @param {String} command - platform command - * @param {Array} argument - command arguments - * @param {Function|Object} progressOptions - either callback for `stdout.on('data')` event or `options`. - * - the callback will receive an object: - *```js - * spawn: object, // child process **spawn** `instance`. - * output: string, // any **output** data. - * fork: object, // if created, child process **fork** `instance`. - *``` - * - any `return` is the **`resolve()` .then()** result. - * @param {Object} options - Any child process `spawn` options, defaults: stdio: 'pipe'. - * - Additionally: - *```js - * sudo: boolean, // run as administrator. - * fork: string, // execute an additional module, a child_process.`fork` IPC communication channel. - * onerror: callable, // callback for `stderr.on('data')` event. - * onprogress: callable, // callback for `stdout.on('data')` event. - * onmessage: callable, // callback for `on('message')` for `fork` event. - *``` - */ -export const spawning = Sys.spawning = function (command, argument, progressOptions, options) { - return new Promise((resolve, reject) => { - options = options || { - stdio: 'pipe', - sudo: false, - fork: null, - onerror: null, - onprogress: null, - onmessage: null, - }; - - options.stdio = options.stdio || 'pipe'; - const forked = isString(options.fork) ? fork(options.fork) : null; - let progress = progressOptions; - if (isObjectOnly(progressOptions)) - options = Object.assign(options, progressOptions); - - if (isFunction(options.onprogress)) - progress = options.onprogress; - - let error = null; - let output = null; - let sudo = options.sudo || false; - let onerror = options.onerror || null; - let onmessage = options.onmessage || null; - - delete options.sudo; - delete options.fork; - delete options.onerror; - delete options.onprogress; - delete options.onmessage; - - if (sudo) { - argument = [command].concat(argument); - command = isWindows() ? join(__dirname, 'bin', 'sudo.bat') : 'sudo'; - }; - - const spawned = spawn(command, argument, options); - spawned.on('error', (data) => { - - return reject(data); - }); - - spawned.on('close', (code) => { - if (code === 0) { - return resolve(output); - } - - return reject(error, code); - }); - - spawned.on('exit', (code) => { - if (forked) - setTimeout(() => { - forked.kill(); - }, 1000); - - if (code === 0) { - return resolve(output); - } - - return reject(error, code); - }); - - spawned.stdout.on('data', (data) => { - let input = data.toString(); - output += input; - try { - if (isFunction(progress)) { - output = progress({ spawn: spawned, output: input, fork: forked }) || output; - } - } catch (e) { - return reject(e.toString()); - } - - if (argument.includes('fake-js')) { - spawned.kill('SIGKILL'); - return resolve('For testing only. ' + output); - } - }); - - spawned.stderr.on('data', (data) => { - let err = data.toString(); - error += err; - if (isFunction(onerror))/* c8 ignore next */ - error = onerror(err) || error; - }); - - if (forked) { - forked.on('message', (data) => { - if (isFunction(onmessage)) - onmessage(data); - }); - } - - if (argument.includes('fake-js') && Object.getOwnPropertyDescriptor(process, 'platform').value == 'darwin') { - spawned.kill('SIGKILL'); - return resolve('For testing only. ' + output); - } - }); -} - -let toString = Object.prototype.toString; - -/** - * Determine if a value is an Array. - * - * @param {Object} value The value to test. - * @returns {boolean} True if value is an Array, otherwise false. - */ -export const isArray = Sys.isArray = function (value) { - return toString.call(value) === '[object Array]'; -} - -/** - * Determine if a value is undefined. - * - * @param {Object} value The value to test. - * @returns {boolean} True if the value is undefined, otherwise false. - */ -export const isUndefined = Sys.isUndefined = function (value) { - return typeof value === 'undefined'; -} - -/** - * Determine if a value is a Buffer. - * - * @param {Object} value The value to test. - * @returns {boolean} True if value is a Buffer, otherwise false. - */ -export const isBuffer = Sys.isBuffer = function (value) { - return value !== null && !isUndefined(value) && value.constructor !== null && !isUndefined(value.constructor) && - typeof value.constructor.isBuffer === 'function' && value.constructor.isBuffer(value); -} - -/** - * Determine if a value is an ArrayBuffer. - * - * @param {Object} value The value to test. - * @returns {boolean} True if value is an ArrayBuffer, otherwise false - */ -export const isArrayBuffer = Sys.isArrayBuffer = function (value) { - return toString.call(value) === '[object ArrayBuffer]'; -} - -/** - * Determine if a value is a String. - * - * @param {Object} value The value to test. - * @returns {boolean} True if value is a String, otherwise false. - */ -export const isString = Sys.isString = function (value) { - return typeof value === 'string'; -} - -/** - * Determine if a value is a Number. - * - * @param {Object} value The value to test. - * @returns {boolean} True if value is a Number, otherwise false. - */ -export const isNumber = Sys.isNumber = function (value) { - return typeof value === 'number'; -} - -/** - * Determine if a value is an Object - * - * @param {Object} value The value to test. - * @returns {boolean} True if value is an Object, otherwise false. - */ -export const isObject = Sys.isObject = function (value) { - return value !== null && typeof value === 'object'; -} - -/** - * Determine if a value is only a Object, not an `Array` or `Function`. - * - * @param {Object} value The value to test. - * @return {boolean} True if value is a `Object` only, otherwise false. - */ -export const isObjectOnly = Sys.isObjectOnly = function (value) { - if (toString.call(value) !== '[object Object]') { - return false; - } - - let prototype = Object.getPrototypeOf(value); - return prototype === null || prototype === Object.prototype; -} - -/** - * Determine if a value is a Blob - * - * @param {Object} value The value to test - * @returns {boolean} True if value is a Blob, otherwise false - */ -export const isBlob = Sys.isBlob = function (value) { - return toString.call(value) === '[object Blob]'; -} - -/** - * Determine if a value is a Function - * - * @param {Object} value The value to test - * @returns {boolean} True if value is a Function, otherwise false - */ -export const isFunction = Sys.isFunction = function (value) { - return toString.call(value) === '[object Function]'; -} - -/** - * Determine if a value is a Date - * - * @param {Object} value The value to test - * @returns {boolean} True if value is a Date, otherwise false - */ -export const isDate = Sys.isDate = function (value) { - return toString.call(value) === '[object Date]'; -} - -/** - * Determine if a value is a Stream - * - * @param {Object} value The value to test - * @returns {boolean} True if value is a Stream, otherwise false - */ -export const isStream = Sys.isStream = function (value) { - return isObject(value) && isFunction(value.pipe); -} - -/** - * Determine if a value is a boolean - * - * @param {Object} value The value to test - * @returns {boolean} True if value is a boolean, otherwise false - */ -export const isBool = Sys.isBool = function (value) { - return (value === true) || (value === false); -} - -/** - * Determine if a value is a null - * - * @param {Object} value The value to test - * @returns {boolean} True if value is a null, otherwise false - */ -export const isNull = Sys.isNull = function (value) { - return value === null; -} - -/** - * Determine if platform is Windows - * - * @returns {boolean} True if Windows OS, otherwise false - */ -export const isWindows = Sys.isWindows = function () { - return process.platform === 'win32'; -} - -/** - * Determine if platform is Linux - * - * @returns {boolean} True if Linux OS, otherwise false - */ -export const isLinux = Sys.isLinux = function () { - return process.platform === 'linux'; -} - -/** - * Determine if platform is Apple Mac - * - * @returns {boolean} True if Apple macOS, otherwise false - */ -export const isMac = Sys.isMac = function () { - return process.platform === 'darwin'; -} - -/** - * Include an `CommonJS` module the old way. - * - * @param {string} module - */ -export const require = createRequire(import.meta.url); - -export default Sys; -export const System = Sys; +export * from './dist/index.js' +export { default as default } from './dist/index.js' diff --git a/package-lock.json b/package-lock.json index a031f6a..b148e2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,1233 @@ { "name": "node-sys", "version": "1.1.7", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "node-sys", + "version": "1.1.7", + "license": "MIT", + "dependencies": { + "minimist": "1.2.6", + "which": "^2.0.2" + }, + "bin": { + "node-sys": "bin/installer.js" + }, + "devDependencies": { + "@types/chai": "^4.3.3", + "@types/minimist": "1.2.2", + "@types/mocha": "^9.1.1", + "@types/node": "^18.7.13", + "@types/which": "^2.0.1", + "chai": "^4.3.6", + "mocha": "^8.4.0", + "typescript": "^4.7.4" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@types/chai": { + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.3.tgz", + "integrity": "sha512-hC7OMnszpxhZPduX+m+nrx+uFoLkWOMiR4oa/AZF3MuSETYTZmFfJAHqZEM8MVlvfG7BEUcgvtwoCTxBp6hm3g==", + "dev": true + }, + "node_modules/@types/minimist": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz", + "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==", + "dev": true + }, + "node_modules/@types/mocha": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz", + "integrity": "sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==", + "dev": true + }, + "node_modules/@types/node": { + "version": "18.7.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", + "integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==", + "dev": true + }, + "node_modules/@types/which": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@types/which/-/which-2.0.1.tgz", + "integrity": "sha512-Jjakcv8Roqtio6w1gr0D7y6twbhx6gGgFGF5BLwajPpnOIOxFkakFhCq+LmyyeAz7BX6ULrjBOxdKaCDy+4+dQ==", + "dev": true + }, + "node_modules/@ungap/promise-all-settled": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", + "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", + "dev": true + }, + "node_modules/ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/anymatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", + "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, + "node_modules/camelcase": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.1.tgz", + "integrity": "sha512-tVI4q5jjFV5CavAU8DXfza/TJcZutVKo/5Foskmsqcm0MsL91moHvwiGNnqaa2o6PF/7yT5ikDRcVcl8Rj6LCA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/chai": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.6.tgz", + "integrity": "sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==", + "dev": true, + "dependencies": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^3.0.1", + "get-func-name": "^2.0.0", + "loupe": "^2.3.1", + "pathval": "^1.1.1", + "type-detect": "^4.0.5" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chalk/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/chokidar": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.1.tgz", + "integrity": "sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==", + "dev": true, + "dependencies": { + "anymatch": "~3.1.1", + "braces": "~3.0.2", + "glob-parent": "~5.1.0", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.5.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.1" + } + }, + "node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/cliui/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "node_modules/debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/debug/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "node_modules/decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dev": true, + "dependencies": { + "type-detect": "^4.0.0" + }, + "engines": { + "node": ">=0.12" + } + }, + "node_modules/diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "dev": true, + "bin": { + "flat": "cli.js" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + "dev": true, + "engines": { + "node": ">=4.x" + } + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true, + "bin": { + "he": "bin/he" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, + "node_modules/js-yaml": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.0.0.tgz", + "integrity": "sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-symbols": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz", + "integrity": "sha512-FN8JBzLx6CzeMrB0tg6pqlGU1wCrXW+ZXGH481kfsBqer0hToTIiHdjH4Mq8xJUbvATujKCvaREGWpGUionraA==", + "dev": true, + "dependencies": { + "chalk": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/loupe": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.4.tgz", + "integrity": "sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.0" + } + }, + "node_modules/minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, + "node_modules/mocha": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-8.4.0.tgz", + "integrity": "sha512-hJaO0mwDXmZS4ghXsvPVriOhsxQ7ofcpQdm8dE+jISUOKopitvnXFQmpRR7jd2K6VBG6E26gU3IAbXXGIbu4sQ==", + "dev": true, + "dependencies": { + "@ungap/promise-all-settled": "1.1.2", + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.5.1", + "debug": "4.3.1", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "7.1.6", + "growl": "1.10.5", + "he": "1.2.0", + "js-yaml": "4.0.0", + "log-symbols": "4.0.0", + "minimatch": "3.0.4", + "ms": "2.1.3", + "nanoid": "3.1.20", + "serialize-javascript": "5.0.1", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "which": "2.0.2", + "wide-align": "1.1.3", + "workerpool": "6.1.0", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" + }, + "bin": { + "_mocha": "bin/_mocha", + "mocha": "bin/mocha" + }, + "engines": { + "node": ">= 10.12.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mochajs" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "node_modules/nanoid": { + "version": "3.1.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz", + "integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==", + "dev": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/pathval": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/picomatch": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", + "integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "dependencies": { + "safe-buffer": "^5.1.0" + } + }, + "node_modules/readdirp": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz", + "integrity": "sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/serialize-javascript": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-5.0.1.tgz", + "integrity": "sha512-SaaNal9imEO737H2c05Og0/8LUXG7EnsZyMa8MzkmuHoELfT6txuj0cMqRj6zfPKnmQ1yasR4PCJc8x+M4JSPA==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" + } + }, + "node_modules/string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dev": true, + "dependencies": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "dependencies": { + "ansi-regex": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wide-align": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", + "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", + "dev": true, + "dependencies": { + "string-width": "^1.0.2 || 2" + } + }, + "node_modules/workerpool": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.1.0.tgz", + "integrity": "sha512-toV7q9rWNYha963Pl/qyeZ6wG+3nnsyvolaNUS8+R5Wtw6qJPTxIlOP1ZSvcGhEJw+l3HMMmtiNo9Gl61G4GVg==", + "dev": true + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", + "dev": true, + "dependencies": { + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs-parser": { + "version": "20.2.4", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs-unparser": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", + "dev": true, + "dependencies": { + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/yargs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + } + }, "dependencies": { + "@types/chai": { + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.3.tgz", + "integrity": "sha512-hC7OMnszpxhZPduX+m+nrx+uFoLkWOMiR4oa/AZF3MuSETYTZmFfJAHqZEM8MVlvfG7BEUcgvtwoCTxBp6hm3g==", + "dev": true + }, + "@types/minimist": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz", + "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==", + "dev": true + }, + "@types/mocha": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz", + "integrity": "sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==", + "dev": true + }, + "@types/node": { + "version": "18.7.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.13.tgz", + "integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==", + "dev": true + }, + "@types/which": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@types/which/-/which-2.0.1.tgz", + "integrity": "sha512-Jjakcv8Roqtio6w1gr0D7y6twbhx6gGgFGF5BLwajPpnOIOxFkakFhCq+LmyyeAz7BX6ULrjBOxdKaCDy+4+dQ==", + "dev": true + }, "@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", @@ -670,6 +1894,12 @@ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, + "typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 2c33809..7a1e304 100644 --- a/package.json +++ b/package.json @@ -3,16 +3,20 @@ "version": "1.1.7", "description": "Universal package installer, get the command for managing packages, or auto install any package, using one command for all platforms. Automate the installation of macOS Brew, and Windows Chocolatey package managers. A promisify child process of spawn, and run as administrator. A series of strick type checkers.", "type": "module", - "main": "index.js", + "main": "./dist/index.js", "bin": { "node-sys": "bin/installer.js" }, "scripts": { - "test": "mocha -R list test/*.js --timeout=0", + "test": "npm run build && mocha -R list test/*.js --timeout=0", "coverage": "npx c8 --reporter json --reporter text npm test && npx codecov -f coverage/coverage-final.json", - "get-installer": "node ./bin/installer.js --get" + "get-installer": "node ./bin/installer.js --get", + "build": "tsc -p ./ || echo done", + "prepare": "npm run build" }, "files": [ + "dist", + "src", "index.js", "LICENSE", "README.md", @@ -53,7 +57,8 @@ ], "author": "l. stubbs ", "contributors": [ - "Arve Seljebu" + "Arve Seljebu", + "Amin Yahyaabadi " ], "license": "MIT", "bugs": { @@ -61,14 +66,22 @@ }, "homepage": "https://github.com/techno-express/node-sys#readme", "engines": { - "node": ">=12.0.0" + "node": ">=12.22" }, "dependencies": { - "which": "^2.0.2", - "minimist": "1.2.6" + "minimist": "1.2.6", + "which": "^2.0.2" + }, + "optionalDependencies": { + "@types/node": "^18.7.13" }, "devDependencies": { + "@types/chai": "^4.3.3", + "@types/minimist": "1.2.2", + "@types/mocha": "^9.1.1", + "@types/which": "^2.0.1", "chai": "^4.3.6", - "mocha": "^8.4.0" + "mocha": "^8.4.0", + "typescript": "^4.7.4" } } diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..b7fa6f1 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,525 @@ +'use strict'; + +import which from 'which'; +import { spawn, fork, SpawnOptionsWithoutStdio } from 'child_process'; +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; +import { createRequire } from 'module'; +import { Blob } from 'buffer'; +import { Stream } from 'stream'; + +const __filename = fileURLToPath(import.meta.url); + +const __dirname = dirname(__filename); + +const sync = which.sync; + +/** + * Supported package commands + */ +const SYS_COMMANDS = { + brew: 'brew install', + port: 'sudo port install', + pkgin: 'sudo pkgin install', + winget: 'winget install', + choco: 'choco install', + powershell: + "powershell 'Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))'", + 'apt-get': 'sudo apt-get install', + yum: 'sudo yum install', + dnf: 'sudo dnf install', + nix: 'nix-env --install', + zypper: 'sudo zypper in', + emerge: 'sudo emerge -a', + pacman: 'sudo pacman -S', + pkg: 'pkg install', + pkg_add: 'pkg_add', + crew: 'crew install', +} as Record; + +/** + * Supported package managers + */ +const SYS_MANAGERS = { + darwin: ['brew', 'port', 'pkgin'], + win32: ['winget', 'choco', 'powershell'], + linux: [ + 'apt-get', + 'yum', + 'dnf', + 'nix', + 'zypper', + 'emerge', + 'pacman', + 'crew', + ], + freebsd: ['pkg', 'pkg_add'], + sunos: ['pkg'], + netbsd: ['none'], + win64: ['choco'], + shell: ['powershell'], +} as Record; + +function Sys() {} + +function sysManager(): string | string[] { + let managers = SYS_MANAGERS[process.platform]; + + if (!managers || !managers.length) { + return "unknown platform '" + process.platform + "'"; + } + + managers = managers.filter(function (mng) { + return where(mng) !== null; + }); + + if (!managers.length) { + return 'System OS package manager not found'; + } + + return SYS_COMMANDS[managers[0]].split(' '); +} + +/** + * Gets the system package manager install command. + * + * @returns {Object} + *``` + * sudo: boolean, // true or false, + * command: string, // 'apk-get' - system package manager command, + * installer: string, // 'sudo apk-get install' - full install command + *``` + * - Defaults to 'get os-manager installer' if no package manager is found. + * + * @throws if `process.platform` is none of darwin, freebsd, linux, sunos or win32. + */ +export const packager = (Sys.packager = function (): object | Error { + let sys = sysManager(); + if (isArray(sys) && sys[0]) + return { + sudo: sys[0] === 'sudo', + command: !sys[2] ? sys[0] : sys[1], + installer: sys.join(' '), + }; + else return new Error(sys as string); +}); + +/** + * Install package using the system package manager command. + * + * @param {String|Array} application package to install. + * @param {Function} progress callback for any output doing installation. + * - Any value returned in `callback` will be the final resolved result. + * + * @returns {Promise} Promise Output of spawn command. + * - E.g. 'sudo apg-get install' for Debian based systems. + * - Defaults to 'get os-manager installer' if no package manager is found. + * @rejects On any spawn error, or if `process.platform` is none of + * darwin, freebsd, linux, sunos or win32. + */ +export const installer = (Sys.installer = function ( + application: string | string[], + progress: Function +): Promise { + if (!application) + return new Promise((_resolve, reject) => { + return reject('No package, application name missing.'); + }); + let manager = sysManager(); + if (!isArray(manager)) + return new Promise((_resolve, reject) => { + return reject(manager); + }); + let cmd = manager[0]; + let args: string[] | null = null; + let install: string[] | null = null; + if (manager[1]) args = [manager[1]]; + if (manager[2]) install = [manager[2]]; + let silentCmd = isWindows() + ? ['--accept-package-agreements', '--accept-source-agreements', '-h'] + : ['-y']; + let whatToInstall: string[] = isArray(application) + ? application.concat(silentCmd) + : [application].concat(silentCmd); + let system = whatToInstall; + if (args && !install) system = args.concat(whatToInstall); + else if (args && install) + system = args.concat(install).concat(whatToInstall); + + if (cmd != 'powershell') { + if (cmd.includes('choco') && isWindows()) { + cmd = where('choco'); + system = [cmd].concat(system); + cmd = join(__dirname, 'bin', 'sudo.bat'); + } + + return spawning(cmd, system, progress); + } else { + return new Promise((_resolve, reject) => { + return reject('No package manager installed!'); + }); + } +}); + +/** + * Like the unix `which` utility. + * + * Finds the first instance of a specified executable in the PATH environment variable. + * + * @param String executable + * + * @returns String|Null + */ +export const where = (Sys.where = function (executable: string) { + let found = sync(executable, { + nothrow: true, + }); + return found; +}); + +/** + * Spawn subprocess with `Promise` features, pass callbacks for `.on('data')` events, with ability to run as admin. + * + * @param {String} command - platform command + * @param {Array} argument - command arguments + * @param {Function|Object} progressOptions - either callback for `stdout.on('data')` event or `options`. + * - the callback will receive an object: + *```js + * spawn: object, // child process **spawn** `instance`. + * output: string, // any **output** data. + * fork: object, // if created, child process **fork** `instance`. + *``` + * - any `return` is the **`resolve()` .then()** result. + * @param {Object} options - Any child process `spawn` options, defaults: stdio: 'pipe'. + * - Additionally: + *```js + * sudo: boolean, // run as administrator. + * fork: string, // execute an additional module, a child_process.`fork` IPC communication channel. + * onerror: callable, // callback for `stderr.on('data')` event. + * onprogress: callable, // callback for `stdout.on('data')` event. + * onmessage: callable, // callback for `on('message')` for `fork` event. + *``` + */ +export const spawning = (Sys.spawning = function ( + command: string, + argument: Array, + progressOptions: Function | object, + options?: + | (SpawnOptionsWithoutStdio & { + sudo?: boolean; + fork?: boolean | null; + onerror?: Function | null; + onprogress?: Function | null; + onmessage?: Function | null; + }) + | undefined +): Promise { + return new Promise((resolve, reject) => { + options = options || { + stdio: 'pipe', + sudo: false, + fork: null, + onerror: null, + onprogress: null, + onmessage: null, + }; + options.stdio = options.stdio || 'pipe'; + const forked = isString(options.fork) ? fork(options.fork) : null; + let progress = progressOptions; + if (isObjectOnly(progressOptions)) + options = Object.assign(options, progressOptions); + if (isFunction(options.onprogress)) progress = options.onprogress; + let error: Error | null = null; + let output: string | null = null; + let sudo = options.sudo || false; + let onerror = options.onerror || null; + let onmessage = options.onmessage || null; + delete options.sudo; + delete options.fork; + delete options.onerror; + delete options.onprogress; + delete options.onmessage; + + if (sudo) { + argument = [command].concat(argument); + + // sudo + if (isWindows()) { + command = join(__dirname, 'bin', 'sudo.bat'); + } else { + if (where('sudo') !== null) { + command = 'sudo'; + } else { + command = ''; + } + } + } + + const spawned = spawn(command, argument, options); + spawned.on('error', (data) => { + return reject(data); + }); + spawned.on('close', (code) => { + if (code === 0) { + return resolve(output); + } + + return reject(error, code); + }); + spawned.on('exit', (code) => { + if (forked) + setTimeout(() => { + forked.kill(); + }, 1000); + + if (code === 0) { + return resolve(output); + } + + return reject(error, code); + }); + spawned.stdout.on('data', (data) => { + let input = data.toString(); + output += input; + + try { + if (isFunction(progress)) { + output = + progress({ + spawn: spawned, + output: input, + fork: forked, + }) || output; + } + } catch (e) { + return reject((e as Error).toString()); + } + + if (argument.includes('fake-js')) { + spawned.kill('SIGKILL'); + return resolve('For testing only. ' + output); + } + }); + spawned.stderr.on('data', (data) => { + let err = data.toString(); + error += err; + if (isFunction(onerror)) + /* c8 ignore next */ + error = onerror(err) || error; + }); + + if (forked) { + forked.on('message', (data) => { + if (isFunction(onmessage)) onmessage(data); + }); + } + + if ( + argument.includes('fake-js') && + Object.getOwnPropertyDescriptor(process, 'platform')?.value == + 'darwin' + ) { + spawned.kill('SIGKILL'); + return resolve('For testing only. ' + output); + } + }); +}); +let toString = Object.prototype.toString; + +/** + * Determine if a value is an Array. + * + * @param {Object} value The value to test. + * @returns {boolean} True if value is an Array, otherwise false. + */ +export const isArray = (Sys.isArray = Array.isArray); + +/** + * Determine if a value is undefined. + * + * @param {Object} value The value to test. + * @returns {boolean} True if the value is undefined, otherwise false. + */ +export const isUndefined = (Sys.isUndefined = function ( + value: any +): value is undefined { + return typeof value === 'undefined'; +}); + +/** + * Determine if a value is a Buffer. + * + * @param {Object} value The value to test. + * @returns {boolean} True if value is a Buffer, otherwise false. + */ +export const isBuffer = (Sys.isBuffer = function (value: any): value is Buffer { + return ( + value !== null && + !isUndefined(value) && + value.constructor !== null && + !isUndefined(value.constructor) && + typeof value.constructor.isBuffer === 'function' && + value.constructor.isBuffer(value) + ); +}); + +/** + * Determine if a value is an ArrayBuffer. + * + * @param {Object} value The value to test. + * @returns {boolean} True if value is an ArrayBuffer, otherwise false + */ +export const isArrayBuffer = (Sys.isArrayBuffer = function ( + value: any +): value is ArrayBuffer { + return toString.call(value) === '[object ArrayBuffer]'; +}); + +/** + * Determine if a value is a String. + * + * @param {Object} value The value to test. + * @returns {boolean} True if value is a String, otherwise false. + */ +export const isString = (Sys.isString = function (value: any): value is string { + return typeof value === 'string'; +}); + +/** + * Determine if a value is a Number. + * + * @param {Object} value The value to test. + * @returns {boolean} True if value is a Number, otherwise false. + */ +export const isNumber = (Sys.isNumber = function (value: any): value is number { + return typeof value === 'number'; +}); + +/** + * Determine if a value is an Object + * + * @param {Object} value The value to test. + * @returns {boolean} True if value is an Object, otherwise false. + */ +export const isObject = (Sys.isObject = function (value: any): value is object { + return value !== null && typeof value === 'object'; +}); + +/** + * Determine if a value is only a Object, not an `Array` or `Function`. + * + * @param {Object} value The value to test. + * @return {boolean} True if value is a `Object` only, otherwise false. + */ +export const isObjectOnly = (Sys.isObjectOnly = function ( + value: any +): value is object { + if (toString.call(value) !== '[object Object]') { + return false; + } + + let prototype = Object.getPrototypeOf(value); + return prototype === null || prototype === Object.prototype; +}); + +/** + * Determine if a value is a Blob + * + * @param {Object} value The value to test + * @returns {boolean} True if value is a Blob, otherwise false + */ +export const isBlob = (Sys.isBlob = function (value: any): value is Blob { + return toString.call(value) === '[object Blob]'; +}); + +/** + * Determine if a value is a Function + * + * @param {Object} value The value to test + * @returns {boolean} True if value is a Function, otherwise false + */ +export const isFunction = (Sys.isFunction = function ( + value: any +): value is Function { + return toString.call(value) === '[object Function]'; +}); + +/** + * Determine if a value is a Date + * + * @param {Object} value The value to test + * @returns {boolean} True if value is a Date, otherwise false + */ +export const isDate = (Sys.isDate = function (value: any): value is Date { + return toString.call(value) === '[object Date]'; +}); + +/** + * Determine if a value is a Stream + * + * @param {Object} value The value to test + * @returns {boolean} True if value is a Stream, otherwise false + */ +export const isStream = (Sys.isStream = function (value: any): value is Stream { + return ( + isObject(value) && + 'pipe' in value && + isFunction((value as { pipe: any }).pipe) + ); +}); + +/** + * Determine if a value is a boolean + * + * @param {Object} value The value to test + * @returns {boolean} True if value is a boolean, otherwise false + */ +export const isBool = (Sys.isBool = function (value: any): value is boolean { + return value === true || value === false; +}); + +/** + * Determine if a value is a null + * + * @param {Object} value The value to test + * @returns {boolean} True if value is a null, otherwise false + */ +export const isNull = (Sys.isNull = function (value: any): value is null { + return value === null; +}); + +/** + * Determine if platform is Windows + * + * @returns {boolean} True if Windows OS, otherwise false + */ +export const isWindows = (Sys.isWindows = function (): boolean { + return process.platform === 'win32'; +}); + +/** + * Determine if platform is Linux + * + * @returns {boolean} True if Linux OS, otherwise false + */ +export const isLinux = (Sys.isLinux = function (): boolean { + return process.platform === 'linux'; +}); + +/** + * Determine if platform is Apple Mac + * + * @returns {boolean} True if Apple macOS, otherwise false + */ +export const isMac = (Sys.isMac = function (): boolean { + return process.platform === 'darwin'; +}); + +/** + * Include an `CommonJS` module the old way. + * + * @param {string} module + */ +export const require = createRequire(import.meta.url); +export default Sys; +export const System = Sys; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5dd0463 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "strict": true, + "strictNullChecks": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noFallthroughCasesInSwitch": true, + "declaration": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "incremental": true, + "inlineSourceMap": false, + "inlineSources": false, + "preserveSymlinks": true, + "removeComments": false, + "lib": ["ES2020"], + "target": "ES2020", + "allowJs": true, + "esModuleInterop": true, + "module": "EsNext", + "moduleResolution": "node", + "importHelpers": false, + "outDir": "./dist" + }, + "compileOnSave": false, + "include": ["src"] +}