From c698cd0cb43e2a3aebb4721bc0275937ce928987 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Mar 2023 17:57:34 +0000 Subject: [PATCH 1/2] Bump @ava/typescript from 3.0.1 to 4.0.0 Bumps [@ava/typescript](https://github.com/avajs/typescript) from 3.0.1 to 4.0.0. - [Release notes](https://github.com/avajs/typescript/releases) - [Commits](https://github.com/avajs/typescript/compare/v3.0.1...v4.0.0) --- updated-dependencies: - dependency-name: "@ava/typescript" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package-lock.json | 142 +++++++++++++++++++++++++--------------------- package.json | 2 +- 2 files changed, 77 insertions(+), 67 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3c8ef940bc..155ccffb64 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "zlib": "^1.0.5" }, "devDependencies": { - "@ava/typescript": "3.0.1", + "@ava/typescript": "4.0.0", "@types/adm-zip": "^0.5.0", "@types/get-folder-size": "^2.0.0", "@types/js-yaml": "^4.0.5", @@ -201,16 +201,16 @@ } }, "node_modules/@ava/typescript": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@ava/typescript/-/typescript-3.0.1.tgz", - "integrity": "sha512-/JXIUuKsvkaneaiA9ckk3ksFTqvu0mDNlChASrTe2BnDsvMbhQdPWyqQjJ9WRJWVhhs5TWn1/0Pp1G6Rv8Syrw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@ava/typescript/-/typescript-4.0.0.tgz", + "integrity": "sha512-QFIPeqkEbdvn7Pob0wVeYpeZD0eXd8nDYdCl+knJVaIJrHdF2fXa58vFaig26cmYwnsEN0KRNTYJKbqW1B0lfg==", "dev": true, "dependencies": { "escape-string-regexp": "^5.0.0", - "execa": "^5.1.1" + "execa": "^7.1.0" }, "engines": { - "node": ">=12.22 <13 || >=14.17 <15 || >=16.4 <17 || >=17" + "node": ">=14.19 <15 || >=16.15 <17 || >=18" } }, "node_modules/@ava/typescript/node_modules/escape-string-regexp": { @@ -3102,40 +3102,28 @@ } }, "node_modules/execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-7.1.0.tgz", + "integrity": "sha512-T6nIJO3LHxUZ6ahVRaxXz9WLEruXLqdcluA+UuTptXmLM7nDAn9lx9IfkxPyzEL21583qSt4RmL44pO71EHaJQ==", "dev": true, "dependencies": { "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", + "get-stream": "^6.0.1", + "human-signals": "^4.3.0", + "is-stream": "^3.0.0", "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" }, "engines": { - "node": ">=10" + "node": "^14.18.0 || ^16.14.0 || >=18.0.0" }, "funding": { "url": "https://github.com/sindresorhus/execa?sponsor=1" } }, - "node_modules/execa/node_modules/get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" @@ -3387,6 +3375,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-stream": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/get-symbol-description": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.0.tgz", @@ -3619,12 +3619,12 @@ } }, "node_modules/human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.0.tgz", + "integrity": "sha512-zyzVyMjpGBX2+6cDVZeFPCdtOtdsxOeseRhB9tkQ6xXmGUNrcnBzdEKPy3VPNYz+4gy1oukVOXcrJCunSyc6QQ==", "dev": true, "engines": { - "node": ">=10.17.0" + "node": ">=14.18.0" } }, "node_modules/ignore": { @@ -3998,12 +3998,12 @@ } }, "node_modules/is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", "dev": true, "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -4400,18 +4400,6 @@ "url": "https://github.com/sindresorhus/mem?sponsor=1" } }, - "node_modules/mem/node_modules/mimic-fn": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -4458,11 +4446,15 @@ } }, "node_modules/mimic-fn": { - "version": "2.1.0", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", "dev": true, "engines": { - "node": ">=6" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/minimatch": { @@ -4599,15 +4591,30 @@ } }, "node_modules/npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", "dev": true, "dependencies": { - "path-key": "^3.0.0" + "path-key": "^4.0.0" }, "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npm-run-path/node_modules/path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/object-inspect": { @@ -4718,15 +4725,15 @@ } }, "node_modules/onetime": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", - "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", "dev": true, "dependencies": { - "mimic-fn": "^2.1.0" + "mimic-fn": "^4.0.0" }, "engines": { - "node": ">=6" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -5563,12 +5570,15 @@ } }, "node_modules/strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", "dev": true, "engines": { - "node": ">=6" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/strip-json-comments": { diff --git a/package.json b/package.json index 3c57d73568..7465804922 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "micromatch is an unspecified dependency of ava" ], "devDependencies": { - "@ava/typescript": "3.0.1", + "@ava/typescript": "4.0.0", "@types/adm-zip": "^0.5.0", "@types/get-folder-size": "^2.0.0", "@types/js-yaml": "^4.0.5", From a1d0ff06316efef15a14f3295f3576b6e11d069b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 13 Mar 2023 18:05:03 +0000 Subject: [PATCH 2/2] Update checked-in dependencies --- node_modules/.package-lock.json | 140 +- node_modules/@ava/typescript/README.md | 16 +- node_modules/@ava/typescript/index.js | 40 +- node_modules/@ava/typescript/package.json | 19 +- node_modules/execa/index.d.ts | 1248 +++++++++++------ node_modules/execa/index.js | 119 +- node_modules/execa/lib/command.js | 70 +- node_modules/execa/lib/error.js | 9 +- node_modules/execa/lib/kill.js | 33 +- node_modules/execa/lib/pipe.js | 42 + node_modules/execa/lib/promise.js | 48 +- node_modules/execa/lib/stdio.js | 7 +- node_modules/execa/lib/stream.js | 78 +- node_modules/execa/lib/verbose.js | 19 + node_modules/execa/package.json | 50 +- node_modules/execa/readme.md | 419 ++++-- .../get-stream/buffer-stream.js | 0 .../node_modules => }/get-stream/index.d.ts | 0 .../node_modules => }/get-stream/index.js | 0 .../node_modules => }/get-stream/license | 0 .../node_modules => }/get-stream/package.json | 0 .../node_modules => }/get-stream/readme.md | 0 node_modules/human-signals/CHANGELOG.md | 11 - node_modules/human-signals/LICENSE | 2 +- node_modules/human-signals/README.md | 26 +- node_modules/human-signals/build/src/core.js | 6 +- .../human-signals/build/src/core.js.map | 1 - .../human-signals/build/src/main.d.ts | 52 - node_modules/human-signals/build/src/main.js | 39 +- .../human-signals/build/src/main.js.map | 1 - .../human-signals/build/src/realtime.js | 8 +- .../human-signals/build/src/realtime.js.map | 1 - .../human-signals/build/src/signals.js | 16 +- .../human-signals/build/src/signals.js.map | 1 - .../human-signals/build/types/main.d.ts | 73 + node_modules/human-signals/package.json | 37 +- node_modules/is-stream/index.d.ts | 160 +-- node_modules/is-stream/index.js | 49 +- node_modules/is-stream/package.json | 16 +- node_modules/is-stream/readme.md | 12 +- .../mem/node_modules/mimic-fn/index.d.ts | 52 - .../mem/node_modules/mimic-fn/index.js | 71 - .../mem/node_modules/mimic-fn/readme.md | 90 -- node_modules/mimic-fn/index.d.ts | 88 +- node_modules/mimic-fn/index.js | 74 +- node_modules/mimic-fn/license | 2 +- node_modules/mimic-fn/package.json | 15 +- node_modules/mimic-fn/readme.md | 47 +- node_modules/npm-run-path/index.d.ts | 129 +- node_modules/npm-run-path/index.js | 51 +- node_modules/npm-run-path/license | 2 +- .../node_modules/path-key/index.d.ts | 31 + .../node_modules/path-key/index.js | 12 + .../node_modules/path-key}/license | 0 .../node_modules/path-key}/package.json | 28 +- .../node_modules/path-key/readme.md | 57 + node_modules/npm-run-path/package.json | 17 +- node_modules/npm-run-path/readme.md | 44 +- node_modules/onetime/index.d.ts | 29 +- node_modules/onetime/index.js | 13 +- node_modules/onetime/package.json | 14 +- node_modules/onetime/readme.md | 12 +- node_modules/strip-final-newline/index.js | 10 +- node_modules/strip-final-newline/license | 2 +- node_modules/strip-final-newline/package.json | 13 +- node_modules/strip-final-newline/readme.md | 21 +- 66 files changed, 2201 insertions(+), 1591 deletions(-) create mode 100644 node_modules/execa/lib/pipe.js create mode 100644 node_modules/execa/lib/verbose.js rename node_modules/{execa/node_modules => }/get-stream/buffer-stream.js (100%) rename node_modules/{execa/node_modules => }/get-stream/index.d.ts (100%) rename node_modules/{execa/node_modules => }/get-stream/index.js (100%) rename node_modules/{execa/node_modules => }/get-stream/license (100%) rename node_modules/{execa/node_modules => }/get-stream/package.json (100%) rename node_modules/{execa/node_modules => }/get-stream/readme.md (100%) delete mode 100644 node_modules/human-signals/CHANGELOG.md delete mode 100644 node_modules/human-signals/build/src/core.js.map delete mode 100644 node_modules/human-signals/build/src/main.d.ts delete mode 100644 node_modules/human-signals/build/src/main.js.map delete mode 100644 node_modules/human-signals/build/src/realtime.js.map delete mode 100644 node_modules/human-signals/build/src/signals.js.map create mode 100644 node_modules/human-signals/build/types/main.d.ts delete mode 100644 node_modules/mem/node_modules/mimic-fn/index.d.ts delete mode 100644 node_modules/mem/node_modules/mimic-fn/index.js delete mode 100644 node_modules/mem/node_modules/mimic-fn/readme.md create mode 100644 node_modules/npm-run-path/node_modules/path-key/index.d.ts create mode 100644 node_modules/npm-run-path/node_modules/path-key/index.js rename node_modules/{mem/node_modules/mimic-fn => npm-run-path/node_modules/path-key}/license (100%) rename node_modules/{mem/node_modules/mimic-fn => npm-run-path/node_modules/path-key}/package.json (64%) create mode 100644 node_modules/npm-run-path/node_modules/path-key/readme.md diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 7be9f594f8..96ef755a9d 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -142,16 +142,16 @@ } }, "node_modules/@ava/typescript": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@ava/typescript/-/typescript-3.0.1.tgz", - "integrity": "sha512-/JXIUuKsvkaneaiA9ckk3ksFTqvu0mDNlChASrTe2BnDsvMbhQdPWyqQjJ9WRJWVhhs5TWn1/0Pp1G6Rv8Syrw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@ava/typescript/-/typescript-4.0.0.tgz", + "integrity": "sha512-QFIPeqkEbdvn7Pob0wVeYpeZD0eXd8nDYdCl+knJVaIJrHdF2fXa58vFaig26cmYwnsEN0KRNTYJKbqW1B0lfg==", "dev": true, "dependencies": { "escape-string-regexp": "^5.0.0", - "execa": "^5.1.1" + "execa": "^7.1.0" }, "engines": { - "node": ">=12.22 <13 || >=14.17 <15 || >=16.4 <17 || >=17" + "node": ">=14.19 <15 || >=16.15 <17 || >=18" } }, "node_modules/@ava/typescript/node_modules/escape-string-regexp": { @@ -3043,40 +3043,28 @@ } }, "node_modules/execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-7.1.0.tgz", + "integrity": "sha512-T6nIJO3LHxUZ6ahVRaxXz9WLEruXLqdcluA+UuTptXmLM7nDAn9lx9IfkxPyzEL21583qSt4RmL44pO71EHaJQ==", "dev": true, "dependencies": { "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", + "get-stream": "^6.0.1", + "human-signals": "^4.3.0", + "is-stream": "^3.0.0", "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" }, "engines": { - "node": ">=10" + "node": "^14.18.0 || ^16.14.0 || >=18.0.0" }, "funding": { "url": "https://github.com/sindresorhus/execa?sponsor=1" } }, - "node_modules/execa/node_modules/get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" @@ -3328,6 +3316,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-stream": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/get-symbol-description": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.0.tgz", @@ -3560,12 +3560,12 @@ } }, "node_modules/human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.0.tgz", + "integrity": "sha512-zyzVyMjpGBX2+6cDVZeFPCdtOtdsxOeseRhB9tkQ6xXmGUNrcnBzdEKPy3VPNYz+4gy1oukVOXcrJCunSyc6QQ==", "dev": true, "engines": { - "node": ">=10.17.0" + "node": ">=14.18.0" } }, "node_modules/ignore": { @@ -3939,12 +3939,12 @@ } }, "node_modules/is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", "dev": true, "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -4341,18 +4341,6 @@ "url": "https://github.com/sindresorhus/mem?sponsor=1" } }, - "node_modules/mem/node_modules/mimic-fn": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -4399,11 +4387,15 @@ } }, "node_modules/mimic-fn": { - "version": "2.1.0", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", "dev": true, "engines": { - "node": ">=6" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/minimatch": { @@ -4540,15 +4532,30 @@ } }, "node_modules/npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", "dev": true, "dependencies": { - "path-key": "^3.0.0" + "path-key": "^4.0.0" }, "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npm-run-path/node_modules/path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/object-inspect": { @@ -4659,15 +4666,15 @@ } }, "node_modules/onetime": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", - "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", "dev": true, "dependencies": { - "mimic-fn": "^2.1.0" + "mimic-fn": "^4.0.0" }, "engines": { - "node": ">=6" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -5504,12 +5511,15 @@ } }, "node_modules/strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", "dev": true, "engines": { - "node": ">=6" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/strip-json-comments": { diff --git a/node_modules/@ava/typescript/README.md b/node_modules/@ava/typescript/README.md index 4c7c1ff14c..f5c4225e79 100644 --- a/node_modules/@ava/typescript/README.md +++ b/node_modules/@ava/typescript/README.md @@ -1,21 +1,11 @@ # @ava/typescript -Adds [TypeScript](https://www.typescriptlang.org/) support to [AVA 4](https://avajs.dev). +Adds [TypeScript](https://www.typescriptlang.org/) support to [AVA](https://avajs.dev). This is designed to work for projects that precompile TypeScript. It allows AVA to load the compiled JavaScript, while configuring AVA to treat the TypeScript files as test files. In other words, say you have a test file at `src/test.ts`. You've configured TypeScript to output to `build/`. Using `@ava/typescript` you can run the test using `npx ava src/test.ts`. -## For AVA 3 users - -Use version 2: - -```console -npm install --save-dev @ava/typescript@2 -``` - -Note that v2 does not support ES modules. This requires v3 and AVA 4. - ## Enabling TypeScript support Add this package to your project: @@ -47,7 +37,7 @@ You can enable compilation via the `compile` property. If `false`, AVA will assu Output files are expected to have the `.js` extension. -AVA searches your entire project for `*.js`, `*.cjs`, `*.mjs` and `*.ts` files (or other extensions you've configured). It will ignore such files found in the `rewritePaths` targets (e.g. `build/`). If you use more specific paths, for instance `build/main/`, you may need to change AVA's `files` configuration to ignore other directories. +AVA searches your entire project for `*.js`, `*.cjs`, `*.mjs`, `*.ts`, `*.cts` and `*.mts` files (or other extensions you've configured). It will ignore such files found in the `rewritePaths` targets (e.g. `build/`). If you use more specific paths, for instance `build/main/`, you may need to change AVA's `files` configuration to ignore other directories. ## ES Modules @@ -75,6 +65,8 @@ You can configure AVA to recognize additional file extensions. To add (partial } ``` +If you use the [`allowJs` TypeScript option](https://www.typescriptlang.org/tsconfig/allowJs.html) you'll have to specify the `js`, `cjs` and `mjs` extensions for them to be rewritten. + See also AVA's [`extensions` option](https://github.com/avajs/ava/blob/master/docs/06-configuration.md#options). † Note that the [*preserve* mode for JSX](https://www.typescriptlang.org/docs/handbook/jsx.html) is not (yet) supported. diff --git a/node_modules/@ava/typescript/index.js b/node_modules/@ava/typescript/index.js index ad5983ccc5..ab9b35a3f6 100644 --- a/node_modules/@ava/typescript/index.js +++ b/node_modules/@ava/typescript/index.js @@ -2,7 +2,7 @@ import fs from 'node:fs'; import path from 'node:path'; import {pathToFileURL} from 'node:url'; import escapeStringRegexp from 'escape-string-regexp'; -import execa from 'execa'; +import {execa} from 'execa'; const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url))); const help = `See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md`; @@ -83,7 +83,7 @@ export default function typescriptProvider({negotiateProtocol}) { validate(config, configProperties); const { - extensions = ['ts'], + extensions = ['ts', 'cts', 'mts'], rewritePaths: relativeRewritePaths, compile, } = config; @@ -118,7 +118,7 @@ export default function typescriptProvider({negotiateProtocol}) { return rewritePaths.some(([from]) => filePath.startsWith(from)); }, - resolveTestFile(testfile) { + resolveTestFile(testfile) { // Used under AVA 3.2 protocol by legacy watcher implementation. if (!testFileExtension.test(testfile)) { return testfile; } @@ -129,8 +129,14 @@ export default function typescriptProvider({negotiateProtocol}) { } const [from, to] = rewrite; - // TODO: Support JSX preserve mode — https://www.typescriptlang.org/docs/handbook/jsx.html - return `${to}${testfile.slice(from.length)}`.replace(testFileExtension, '.js'); + let newExtension = '.js'; + if (testfile.endsWith('.cts')) { + newExtension = '.cjs'; + } else if (testfile.endsWith('.mts')) { + newExtension = '.mjs'; + } + + return `${to}${testfile.slice(from.length)}`.replace(testFileExtension, newExtension); }, updateGlobs({filePatterns, ignoredByWatcherPatterns}) { @@ -142,7 +148,11 @@ export default function typescriptProvider({negotiateProtocol}) { ], ignoredByWatcherPatterns: [ ...ignoredByWatcherPatterns, - ...Object.values(relativeRewritePaths).map(to => `${to}**/*.js.map`), + ...Object.values(relativeRewritePaths).flatMap(to => [ + `${to}**/*.js.map`, + `${to}**/*.cjs.map`, + `${to}**/*.mjs.map`, + ]), ], }; }, @@ -150,7 +160,7 @@ export default function typescriptProvider({negotiateProtocol}) { }, worker({extensionsToLoadAsModules, state: {extensions, rewritePaths}}) { - const useImport = extensionsToLoadAsModules.includes('js'); + const importJs = extensionsToLoadAsModules.includes('js'); const testFileExtension = new RegExp(`\\.(${extensions.map(ext => escapeStringRegexp(ext)).join('|')})$`); return { @@ -160,9 +170,19 @@ export default function typescriptProvider({negotiateProtocol}) { async load(ref, {requireFn}) { const [from, to] = rewritePaths.find(([from]) => ref.startsWith(from)); - // TODO: Support JSX preserve mode — https://www.typescriptlang.org/docs/handbook/jsx.html - const rewritten = `${to}${ref.slice(from.length)}`.replace(testFileExtension, '.js'); - return useImport ? import(pathToFileURL(rewritten)) : requireFn(rewritten); // eslint-disable-line node/no-unsupported-features/es-syntax + let rewritten = `${to}${ref.slice(from.length)}`; + let useImport = true; + if (ref.endsWith('.cts')) { + rewritten = rewritten.replace(/\.cts$/, '.cjs'); + useImport = false; + } else if (ref.endsWith('.mts')) { + rewritten = rewritten.replace(/\.mts$/, '.mjs'); + } else { + rewritten = rewritten.replace(testFileExtension, '.js'); + useImport = importJs; + } + + return useImport ? import(pathToFileURL(rewritten)) : requireFn(rewritten); }, }; }, diff --git a/node_modules/@ava/typescript/package.json b/node_modules/@ava/typescript/package.json index 355fcc0fd5..e497836881 100644 --- a/node_modules/@ava/typescript/package.json +++ b/node_modules/@ava/typescript/package.json @@ -1,9 +1,9 @@ { "name": "@ava/typescript", - "version": "3.0.1", + "version": "4.0.0", "description": "TypeScript provider for AVA", "engines": { - "node": ">=12.22 <13 || >=14.17 <15 || >=16.4 <17 || >=17" + "node": ">=14.19 <15 || >=16.15 <17 || >=18" }, "files": [ "index.js" @@ -24,14 +24,14 @@ }, "dependencies": { "escape-string-regexp": "^5.0.0", - "execa": "^5.1.1" + "execa": "^7.1.0" }, "devDependencies": { - "ava": "4.0.0-rc.1", - "c8": "^7.10.0", - "del": "^6.0.0", - "typescript": "^4.4.4", - "xo": "^0.46.3" + "ava": "^5.2.0", + "c8": "^7.13.0", + "del": "^7.0.0", + "typescript": "^4.9.5", + "xo": "^0.53.1" }, "c8": { "reporter": [ @@ -52,7 +52,8 @@ }, "xo": { "ignores": [ - "test/broken-fixtures" + "test/broken-fixtures", + "test/fixtures/**/compiled/**" ] } } diff --git a/node_modules/execa/index.d.ts b/node_modules/execa/index.d.ts index 417d535575..5910390391 100644 --- a/node_modules/execa/index.d.ts +++ b/node_modules/execa/index.d.ts @@ -1,564 +1,930 @@ -/// -import {ChildProcess} from 'child_process'; -import {Stream, Readable as ReadableStream} from 'stream'; +import {type Buffer} from 'node:buffer'; +import {type ChildProcess} from 'node:child_process'; +import {type Stream, type Readable as ReadableStream, type Writable as WritableStream} from 'node:stream'; + +export type StdioOption = + | 'pipe' + | 'overlapped' + | 'ipc' + | 'ignore' + | 'inherit' + | Stream + | number + | undefined; + +export type CommonOptions = { + /** + Kill the spawned process when the parent process exits unless either: + - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached) + - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit -declare namespace execa { - type StdioOption = - | 'pipe' - | 'ipc' - | 'ignore' - | 'inherit' - | Stream - | number - | undefined; + @default true + */ + readonly cleanup?: boolean; - interface CommonOptions { - /** - Kill the spawned process when the parent process exits unless either: - - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached) - - the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit + /** + Prefer locally installed binaries when looking for a binary to execute. - @default true - */ - readonly cleanup?: boolean; + If you `$ npm install foo`, you can then `execa('foo')`. - /** - Prefer locally installed binaries when looking for a binary to execute. + @default `true` with `$`/`$.sync`, `false` otherwise + */ + readonly preferLocal?: boolean; - If you `$ npm install foo`, you can then `execa('foo')`. + /** + Preferred path to find locally installed binaries in (use with `preferLocal`). - @default false - */ - readonly preferLocal?: boolean; + @default process.cwd() + */ + readonly localDir?: string | URL; - /** - Preferred path to find locally installed binaries in (use with `preferLocal`). + /** + Path to the Node.js executable to use in child processes. - @default process.cwd() - */ - readonly localDir?: string; + This can be either an absolute path or a path relative to the `cwd` option. - /** - Path to the Node.js executable to use in child processes. + Requires `preferLocal` to be `true`. - This can be either an absolute path or a path relative to the `cwd` option. + For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process. - Requires `preferLocal` to be `true`. + @default process.execPath + */ + readonly execPath?: string; - For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process. + /** + Buffer the output from the spawned process. When set to `false`, you must read the output of `stdout` and `stderr` (or `all` if the `all` option is `true`). Otherwise the returned promise will not be resolved/rejected. - @default process.execPath - */ - readonly execPath?: string; + If the spawned process fails, `error.stdout`, `error.stderr`, and `error.all` will contain the buffered data. - /** - Buffer the output from the spawned process. When set to `false`, you must read the output of `stdout` and `stderr` (or `all` if the `all` option is `true`). Otherwise the returned promise will not be resolved/rejected. + @default true + */ + readonly buffer?: boolean; - If the spawned process fails, `error.stdout`, `error.stderr`, and `error.all` will contain the buffered data. + /** + Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). - @default true - */ - readonly buffer?: boolean; + @default 'pipe' + */ + readonly stdin?: StdioOption; - /** - Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). + /** + Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). - @default 'pipe' - */ - readonly stdin?: StdioOption; + @default 'pipe' + */ + readonly stdout?: StdioOption; - /** - Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). + /** + Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). - @default 'pipe' - */ - readonly stdout?: StdioOption; + @default 'pipe' + */ + readonly stderr?: StdioOption; - /** - Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). + /** + Setting this to `false` resolves the promise with the error instead of rejecting it. - @default 'pipe' - */ - readonly stderr?: StdioOption; + @default true + */ + readonly reject?: boolean; - /** - Setting this to `false` resolves the promise with the error instead of rejecting it. + /** + Add an `.all` property on the promise and the resolved value. The property contains the output of the process with `stdout` and `stderr` interleaved. - @default true - */ - readonly reject?: boolean; + @default false + */ + readonly all?: boolean; - /** - Add an `.all` property on the promise and the resolved value. The property contains the output of the process with `stdout` and `stderr` interleaved. + /** + Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output. - @default false - */ - readonly all?: boolean; + @default true + */ + readonly stripFinalNewline?: boolean; - /** - Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output. + /** + Set to `false` if you don't want to extend the environment variables when providing the `env` property. - @default true - */ - readonly stripFinalNewline?: boolean; + @default true + */ + readonly extendEnv?: boolean; - /** - Set to `false` if you don't want to extend the environment variables when providing the `env` property. + /** + Current working directory of the child process. - @default true - */ - readonly extendEnv?: boolean; + @default process.cwd() + */ + readonly cwd?: string | URL; - /** - Current working directory of the child process. + /** + Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this. - @default process.cwd() - */ - readonly cwd?: string; + @default process.env + */ + readonly env?: NodeJS.ProcessEnv; - /** - Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this. + /** + Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified. + */ + readonly argv0?: string; - @default process.env - */ - readonly env?: NodeJS.ProcessEnv; + /** + Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration. - /** - Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified. - */ - readonly argv0?: string; + @default 'pipe' + */ + readonly stdio?: 'pipe' | 'overlapped' | 'ignore' | 'inherit' | readonly StdioOption[]; - /** - Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration. + /** + Specify the kind of serialization used for sending messages between processes when using the `stdio: 'ipc'` option or `execaNode()`: + - `json`: Uses `JSON.stringify()` and `JSON.parse()`. + - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value) - @default 'pipe' - */ - readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[]; + [More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization) - /** - Specify the kind of serialization used for sending messages between processes when using the `stdio: 'ipc'` option or `execa.node()`: - - `json`: Uses `JSON.stringify()` and `JSON.parse()`. - - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value) + @default 'json' + */ + readonly serialization?: 'json' | 'advanced'; - Requires Node.js `13.2.0` or later. + /** + Prepare child to run independently of its parent process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached). - [More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization) + @default false + */ + readonly detached?: boolean; - @default 'json' - */ - readonly serialization?: 'json' | 'advanced'; + /** + Sets the user identity of the process. + */ + readonly uid?: number; - /** - Prepare child to run independently of its parent process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached). + /** + Sets the group identity of the process. + */ + readonly gid?: number; - @default false - */ - readonly detached?: boolean; + /** + If `true`, runs `command` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows. - /** - Sets the user identity of the process. - */ - readonly uid?: number; + We recommend against using this option since it is: + - not cross-platform, encouraging shell-specific syntax. + - slower, because of the additional shell interpretation. + - unsafe, potentially allowing command injection. - /** - Sets the group identity of the process. - */ - readonly gid?: number; + @default false + */ + readonly shell?: boolean | string; - /** - If `true`, runs `command` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows. + /** + Specify the character encoding used to decode the `stdout` and `stderr` output. If set to `null`, then `stdout` and `stderr` will be a `Buffer` instead of a string. - We recommend against using this option since it is: - - not cross-platform, encouraging shell-specific syntax. - - slower, because of the additional shell interpretation. - - unsafe, potentially allowing command injection. + @default 'utf8' + */ + readonly encoding?: EncodingType; - @default false - */ - readonly shell?: boolean | string; + /** + If `timeout` is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `SIGTERM`) if the child runs longer than `timeout` milliseconds. - /** - Specify the character encoding used to decode the `stdout` and `stderr` output. If set to `null`, then `stdout` and `stderr` will be a `Buffer` instead of a string. + @default 0 + */ + readonly timeout?: number; - @default 'utf8' - */ - readonly encoding?: EncodingType; + /** + Largest amount of data in bytes allowed on `stdout` or `stderr`. Default: 100 MB. - /** - If `timeout` is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `SIGTERM`) if the child runs longer than `timeout` milliseconds. + @default 100_000_000 + */ + readonly maxBuffer?: number; - @default 0 - */ - readonly timeout?: number; + /** + Signal value to be used when the spawned process will be killed. - /** - Largest amount of data in bytes allowed on `stdout` or `stderr`. Default: 100 MB. + @default 'SIGTERM' + */ + readonly killSignal?: string | number; - @default 100_000_000 - */ - readonly maxBuffer?: number; + /** + You can abort the spawned process using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). - /** - Signal value to be used when the spawned process will be killed. + When `AbortController.abort()` is called, [`.isCanceled`](https://github.com/sindresorhus/execa#iscanceled) becomes `false`. - @default 'SIGTERM' - */ - readonly killSignal?: string | number; + *Requires Node.js 16 or later.* - /** - If `true`, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to `true` automatically when the `shell` option is `true`. + @example + ``` + import {execa} from 'execa'; - @default false - */ - readonly windowsVerbatimArguments?: boolean; + const abortController = new AbortController(); + const subprocess = execa('node', [], {signal: abortController.signal}); - /** - On Windows, do not create a new console window. Please note this also prevents `CTRL-C` [from working](https://github.com/nodejs/node/issues/29837) on Windows. + setTimeout(() => { + abortController.abort(); + }, 1000); - @default true - */ - readonly windowsHide?: boolean; + try { + await subprocess; + } catch (error) { + console.log(subprocess.killed); // true + console.log(error.isCanceled); // true } + ``` + */ + readonly signal?: AbortSignal; - interface Options extends CommonOptions { - /** - Write some input to the `stdin` of your binary. - */ - readonly input?: string | Buffer | ReadableStream; - } + /** + If `true`, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to `true` automatically when the `shell` option is `true`. - interface SyncOptions extends CommonOptions { - /** - Write some input to the `stdin` of your binary. - */ - readonly input?: string | Buffer; - } + @default false + */ + readonly windowsVerbatimArguments?: boolean; + + /** + On Windows, do not create a new console window. Please note this also prevents `CTRL-C` [from working](https://github.com/nodejs/node/issues/29837) on Windows. - interface NodeOptions extends Options { - /** - The Node.js executable to use. + @default true + */ + readonly windowsHide?: boolean; - @default process.execPath - */ - readonly nodePath?: string; + /** + Print each command on `stderr` before executing it. - /** - List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable. + This can also be enabled by setting the `NODE_DEBUG=execa` environment variable in the current process. - @default process.execArgv - */ - readonly nodeOptions?: string[]; - } + @default false + */ + readonly verbose?: boolean; +}; - interface ExecaReturnBase { - /** - The file and arguments that were run, for logging purposes. - - This is not escaped and should not be executed directly as a process, including using `execa()` or `execa.command()`. - */ - command: string; - - /** - Same as `command` but escaped. - - This is meant to be copy and pasted into a shell, for debugging purposes. - Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execa.command()`. - */ - escapedCommand: string; - - /** - The numeric exit code of the process that was run. - */ - exitCode: number; - - /** - The output of the process on stdout. - */ - stdout: StdoutStderrType; - - /** - The output of the process on stderr. - */ - stderr: StdoutStderrType; - - /** - Whether the process failed to run. - */ - failed: boolean; - - /** - Whether the process timed out. - */ - timedOut: boolean; - - /** - Whether the process was killed. - */ - killed: boolean; - - /** - The name of the signal that was used to terminate the process. For example, `SIGFPE`. - - If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. - */ - signal?: string; - - /** - A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`. - - If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen. - */ - signalDescription?: string; - } +export type Options = { + /** + Write some input to the `stdin` of your binary. - interface ExecaSyncReturnValue - extends ExecaReturnBase { - } + If the input is a file, use the `inputFile` option instead. + */ + readonly input?: string | Buffer | ReadableStream; /** - Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance. + Use a file as input to the the `stdin` of your binary. - The child process fails when: - - its exit code is not `0` - - it was killed with a signal - - timing out - - being canceled - - there's not enough memory or there are already too many child processes + If the input is not a file, use the `input` option instead. */ - interface ExecaReturnValue - extends ExecaSyncReturnValue { - /** - The output of the process with `stdout` and `stderr` interleaved. + readonly inputFile?: string; +} & CommonOptions; - This is `undefined` if either: - - the `all` option is `false` (default value) - - `execa.sync()` was used - */ - all?: StdoutErrorType; +export type SyncOptions = { + /** + Write some input to the `stdin` of your binary. - /** - Whether the process was canceled. - */ - isCanceled: boolean; - } + If the input is a file, use the `inputFile` option instead. + */ + readonly input?: string | Buffer; - interface ExecaSyncError - extends Error, - ExecaReturnBase { - /** - Error message when the child process failed to run. In addition to the underlying error message, it also contains some information related to why the child process errored. + /** + Use a file as input to the the `stdin` of your binary. - The child process stderr then stdout are appended to the end, separated with newlines and not interleaved. - */ - message: string; + If the input is not a file, use the `input` option instead. + */ + readonly inputFile?: string; +} & CommonOptions; - /** - This is the same as the `message` property except it does not include the child process stdout/stderr. - */ - shortMessage: string; +export type NodeOptions = { + /** + The Node.js executable to use. - /** - Original error message. This is the same as the `message` property except it includes neither the child process stdout/stderr nor some additional information added by Execa. + @default process.execPath + */ + readonly nodePath?: string; - This is `undefined` unless the child process exited due to an `error` event or a timeout. - */ - originalMessage?: string; - } + /** + List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable. - interface ExecaError - extends ExecaSyncError { - /** - The output of the process with `stdout` and `stderr` interleaved. - - This is `undefined` if either: - - the `all` option is `false` (default value) - - `execa.sync()` was used - */ - all?: StdoutErrorType; - - /** - Whether the process was canceled. - */ - isCanceled: boolean; - } + @default process.execArgv + */ + readonly nodeOptions?: string[]; +} & Options; - interface KillOptions { - /** - Milliseconds to wait for the child process to terminate before sending `SIGKILL`. +type StdoutStderrAll = string | Buffer | undefined; - Can be disabled with `false`. +export type ExecaReturnBase = { + /** + The file and arguments that were run, for logging purposes. - @default 5000 - */ - forceKillAfterTimeout?: number | false; - } + This is not escaped and should not be executed directly as a process, including using `execa()` or `execaCommand()`. + */ + command: string; - interface ExecaChildPromise { - /** - Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr). - - This is `undefined` if either: - - the `all` option is `false` (the default value) - - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio) - */ - all?: ReadableStream; - - catch( - onRejected?: (reason: ExecaError) => ResultType | PromiseLike - ): Promise | ResultType>; - - /** - Same as the original [`child_process#kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal), except if `signal` is `SIGTERM` (the default value) and the child process is not terminated after 5 seconds, force it by sending `SIGKILL`. - */ - kill(signal?: string, options?: KillOptions): void; - - /** - Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This is preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. - */ - cancel(): void; - } + /** + Same as `command` but escaped. - type ExecaChildProcess = ChildProcess & - ExecaChildPromise & - Promise>; -} + This is meant to be copy and pasted into a shell, for debugging purposes. + Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execaCommand()`. + */ + escapedCommand: string; -declare const execa: { /** - Execute a file. + The numeric exit code of the process that was run. + */ + exitCode: number; - Think of this as a mix of `child_process.execFile` and `child_process.spawn`. + /** + The output of the process on stdout. + */ + stdout: StdoutStderrType; - @param file - The program/script to execute. - @param arguments - Arguments to pass to `file` on execution. - @returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. + /** + The output of the process on stderr. + */ + stderr: StdoutStderrType; - @example - ``` - import execa = require('execa'); + /** + Whether the process failed to run. + */ + failed: boolean; - (async () => { - const {stdout} = await execa('echo', ['unicorns']); - console.log(stdout); - //=> 'unicorns' + /** + Whether the process timed out. + */ + timedOut: boolean; - // Cancelling a spawned process + /** + Whether the process was killed. + */ + killed: boolean; - const subprocess = execa('node'); + /** + The name of the signal that was used to terminate the process. For example, `SIGFPE`. - setTimeout(() => { - subprocess.cancel() - }, 1000); + If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. + */ + signal?: string; - try { - await subprocess; - } catch (error) { - console.log(subprocess.killed); // true - console.log(error.isCanceled); // true - } - })(); + /** + A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`. - // Pipe the child process stdout to the current stdout - execa('echo', ['unicorns']).stdout.pipe(process.stdout); - ``` + If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen. */ - ( - file: string, - arguments?: readonly string[], - options?: execa.Options - ): execa.ExecaChildProcess; - ( - file: string, - arguments?: readonly string[], - options?: execa.Options - ): execa.ExecaChildProcess; - (file: string, options?: execa.Options): execa.ExecaChildProcess; - (file: string, options?: execa.Options): execa.ExecaChildProcess< - Buffer - >; + signalDescription?: string; +}; + +export type ExecaSyncReturnValue = { +} & ExecaReturnBase; + +/** +Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance. +The child process fails when: +- its exit code is not `0` +- it was killed with a signal +- timing out +- being canceled +- there's not enough memory or there are already too many child processes +*/ +export type ExecaReturnValue = { /** - Execute a file synchronously. + The output of the process with `stdout` and `stderr` interleaved. - This method throws an `Error` if the command fails. + This is `undefined` if either: + - the `all` option is `false` (default value) + - `execaSync()` was used + */ + all?: StdoutStderrType; + + /** + Whether the process was canceled. - @param file - The program/script to execute. - @param arguments - Arguments to pass to `file` on execution. - @returns A result `Object` with `stdout` and `stderr` properties. + You can cancel the spawned process using the [`signal`](https://github.com/sindresorhus/execa#signal-1) option. */ - sync( - file: string, - arguments?: readonly string[], - options?: execa.SyncOptions - ): execa.ExecaSyncReturnValue; - sync( - file: string, - arguments?: readonly string[], - options?: execa.SyncOptions - ): execa.ExecaSyncReturnValue; - sync(file: string, options?: execa.SyncOptions): execa.ExecaSyncReturnValue; - sync( - file: string, - options?: execa.SyncOptions - ): execa.ExecaSyncReturnValue; + isCanceled: boolean; +} & ExecaSyncReturnValue; + +export type ExecaSyncError = { + /** + Error message when the child process failed to run. In addition to the underlying error message, it also contains some information related to why the child process errored. + + The child process stderr then stdout are appended to the end, separated with newlines and not interleaved. + */ + message: string; + + /** + This is the same as the `message` property except it does not include the child process stdout/stderr. + */ + shortMessage: string; + + /** + Original error message. This is the same as the `message` property except it includes neither the child process stdout/stderr nor some additional information added by Execa. + + This is `undefined` unless the child process exited due to an `error` event or a timeout. + */ + originalMessage?: string; +} & Error & ExecaReturnBase; + +export type ExecaError = { + /** + The output of the process with `stdout` and `stderr` interleaved. + + This is `undefined` if either: + - the `all` option is `false` (default value) + - `execaSync()` was used + */ + all?: StdoutStderrType; + + /** + Whether the process was canceled. + */ + isCanceled: boolean; +} & ExecaSyncError; + +export type KillOptions = { + /** + Milliseconds to wait for the child process to terminate before sending `SIGKILL`. + + Can be disabled with `false`. + + @default 5000 + */ + forceKillAfterTimeout?: number | false; +}; + +export type ExecaChildPromise = { + /** + Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr). + + This is `undefined` if either: + - the `all` option is `false` (the default value) + - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio) + */ + all?: ReadableStream; + + catch( + onRejected?: (reason: ExecaError) => ResultType | PromiseLike + ): Promise | ResultType>; + + /** + Same as the original [`child_process#kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal), except if `signal` is `SIGTERM` (the default value) and the child process is not terminated after 5 seconds, force it by sending `SIGKILL`. + */ + kill(signal?: string, options?: KillOptions): void; + + /** + Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This used to be preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. But now this is deprecated and you should either use `.kill()` or the `signal` option when creating the child process. + */ + cancel(): void; + + /** + [Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process's `stdout` to `target`, which can be: + - Another `execa()` return value + - A writable stream + - A file path string + + If the `target` is another `execa()` return value, it is returned. Otherwise, the original `execa()` return value is returned. This allows chaining `pipeStdout()` then `await`ing the final result. + + The `stdout` option] must be kept as `pipe`, its default value. + */ + pipeStdout?>(target: Target): Target; + pipeStdout?(target: WritableStream | string): ExecaChildProcess; /** - Same as `execa()` except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execa.command('echo unicorns')`. + Like `pipeStdout()` but piping the child process's `stderr` instead. + + The `stderr` option must be kept as `pipe`, its default value. + */ + pipeStderr?>(target: Target): Target; + pipeStderr?(target: WritableStream | string): ExecaChildProcess; - If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if `command` is not a constant but a variable, for example with `__dirname` or `process.cwd()`. Except for spaces, no escaping/quoting is needed. + /** + Combines both `pipeStdout()` and `pipeStderr()`. - The `shell` option must be used if the `command` uses shell-specific features (for example, `&&` or `||`), as opposed to being a simple `file` followed by its `arguments`. + Either the `stdout` option or the `stderr` option must be kept as `pipe`, their default value. Also, the `all` option must be set to `true`. + */ + pipeAll?>(target: Target): Target; + pipeAll?(target: WritableStream | string): ExecaChildProcess; +}; - @param command - The program/script to execute and its arguments. - @returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. +export type ExecaChildProcess = ChildProcess & +ExecaChildPromise & +Promise>; + +/** +Executes a command using `file ...arguments`. `arguments` are specified as an array of strings. Returns a `childProcess`. + +Arguments are automatically escaped. They can contain any character, including spaces. + +This is the preferred method when executing single commands. + +@param file - The program/script to execute. +@param arguments - Arguments to pass to `file` on execution. +@returns An `ExecaChildProcess` that is both: + - a `Promise` resolving or rejecting with a `childProcessResult`. + - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties. +@throws A `childProcessResult` error + +@example Promise interface +``` +import {execa} from 'execa'; + +const {stdout} = await execa('echo', ['unicorns']); +console.log(stdout); +//=> 'unicorns' +``` + +@example Redirect output to a file +``` +import {execa} from 'execa'; + +// Similar to `echo unicorns > stdout.txt` in Bash +await execa('echo', ['unicorns']).pipeStdout('stdout.txt'); + +// Similar to `echo unicorns 2> stdout.txt` in Bash +await execa('echo', ['unicorns']).pipeStderr('stderr.txt'); + +// Similar to `echo unicorns &> stdout.txt` in Bash +await execa('echo', ['unicorns'], {all: true}).pipeAll('all.txt'); +``` + +@example Redirect input from a file +``` +import {execa} from 'execa'; + +// Similar to `cat < stdin.txt` in Bash +const {stdout} = await execa('cat', {inputFile: 'stdin.txt'}); +console.log(stdout); +//=> 'unicorns' +``` + +@example Save and pipe output from a child process +``` +import {execa} from 'execa'; + +const {stdout} = await execa('echo', ['unicorns']).pipeStdout(process.stdout); +// Prints `unicorns` +console.log(stdout); +// Also returns 'unicorns' +``` + +@example Pipe multiple processes +``` +import {execa} from 'execa'; + +// Similar to `echo unicorns | cat` in Bash +const {stdout} = await execa('echo', ['unicorns']).pipeStdout(execa('cat')); +console.log(stdout); +//=> 'unicorns' +``` + +@example Handling errors +``` +import {execa} from 'execa'; + +// Catching an error +try { + await execa('unknown', ['command']); +} catch (error) { + console.log(error); + /* + { + message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', + errno: -2, + code: 'ENOENT', + syscall: 'spawn unknown', + path: 'unknown', + spawnargs: ['command'], + originalMessage: 'spawn unknown ENOENT', + shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', + command: 'unknown command', + escapedCommand: 'unknown command', + stdout: '', + stderr: '', + failed: true, + timedOut: false, + isCanceled: false, + killed: false + } + \*\/ +} +``` + +@example Graceful termination +``` +const subprocess = execa('node'); + +setTimeout(() => { + subprocess.kill('SIGTERM', { + forceKillAfterTimeout: 2000 + }); +}, 1000); +``` +*/ +export function execa( + file: string, + arguments?: readonly string[], + options?: Options +): ExecaChildProcess; +export function execa( + file: string, + arguments?: readonly string[], + options?: Options +): ExecaChildProcess; +export function execa(file: string, options?: Options): ExecaChildProcess; +export function execa(file: string, options?: Options): ExecaChildProcess; + +/** +Same as `execa()` but synchronous. + +@param file - The program/script to execute. +@param arguments - Arguments to pass to `file` on execution. +@returns A `childProcessResult` object +@throws A `childProcessResult` error + +@example Promise interface +``` +import {execa} from 'execa'; + +const {stdout} = execaSync('echo', ['unicorns']); +console.log(stdout); +//=> 'unicorns' +``` + +@example Redirect input from a file +``` +import {execa} from 'execa'; + +// Similar to `cat < stdin.txt` in Bash +const {stdout} = execaSync('cat', {inputFile: 'stdin.txt'}); +console.log(stdout); +//=> 'unicorns' +``` + +@example Handling errors +``` +import {execa} from 'execa'; + +// Catching an error +try { + execaSync('unknown', ['command']); +} catch (error) { + console.log(error); + /* + { + message: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT', + errno: -2, + code: 'ENOENT', + syscall: 'spawnSync unknown', + path: 'unknown', + spawnargs: ['command'], + originalMessage: 'spawnSync unknown ENOENT', + shortMessage: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT', + command: 'unknown command', + escapedCommand: 'unknown command', + stdout: '', + stderr: '', + failed: true, + timedOut: false, + isCanceled: false, + killed: false + } + \*\/ +} +``` +*/ +export function execaSync( + file: string, + arguments?: readonly string[], + options?: SyncOptions +): ExecaSyncReturnValue; +export function execaSync( + file: string, + arguments?: readonly string[], + options?: SyncOptions +): ExecaSyncReturnValue; +export function execaSync(file: string, options?: SyncOptions): ExecaSyncReturnValue; +export function execaSync( + file: string, + options?: SyncOptions +): ExecaSyncReturnValue; + +/** +Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`. + +Arguments are automatically escaped. They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`. + +This is the preferred method when executing a user-supplied `command` string, such as in a REPL. + +@param command - The program/script to execute and its arguments. +@returns An `ExecaChildProcess` that is both: + - a `Promise` resolving or rejecting with a `childProcessResult`. + - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties. +@throws A `childProcessResult` error + +@example +``` +import {execaCommand} from 'execa'; + +const {stdout} = await execaCommand('echo unicorns'); +console.log(stdout); +//=> 'unicorns' +``` +*/ +export function execaCommand(command: string, options?: Options): ExecaChildProcess; +export function execaCommand(command: string, options?: Options): ExecaChildProcess; + +/** +Same as `execaCommand()` but synchronous. + +@param command - The program/script to execute and its arguments. +@returns A `childProcessResult` object +@throws A `childProcessResult` error + +@example +``` +import {execaCommandSync} from 'execa'; + +const {stdout} = execaCommandSync('echo unicorns'); +console.log(stdout); +//=> 'unicorns' +``` +*/ +export function execaCommandSync(command: string, options?: SyncOptions): ExecaSyncReturnValue; +export function execaCommandSync(command: string, options?: SyncOptions): ExecaSyncReturnValue; + +type TemplateExpression = + | string + | number + | ExecaReturnValue + | ExecaSyncReturnValue + | Array | ExecaSyncReturnValue>; + +type Execa$ = { + /** + Returns a new instance of `$` but with different default `options`. Consecutive calls are merged to previous ones. + + This can be used to either: + - Set options for a specific command: `` $(options)`command` `` + - Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand` `` + + @param options - Options to set + @returns A new instance of `$` with those `options` set @example ``` - import execa = require('execa'); + import {$} from 'execa'; + + const $$ = $({stdio: 'inherit'}); - (async () => { - const {stdout} = await execa.command('echo unicorns'); - console.log(stdout); - //=> 'unicorns' - })(); + await $$`echo unicorns`; + //=> 'unicorns' + + await $$`echo rainbows`; + //=> 'rainbows' ``` */ - command(command: string, options?: execa.Options): execa.ExecaChildProcess; - command(command: string, options?: execa.Options): execa.ExecaChildProcess; + (options: Options): Execa$; + (options: Options): Execa$; + (options: Options): Execa$; + ( + templates: TemplateStringsArray, + ...expressions: TemplateExpression[] + ): ExecaChildProcess; /** - Same as `execa.command()` but synchronous. + Same as $\`command\` but synchronous. - @param command - The program/script to execute and its arguments. - @returns A result `Object` with `stdout` and `stderr` properties. - */ - commandSync(command: string, options?: execa.SyncOptions): execa.ExecaSyncReturnValue; - commandSync(command: string, options?: execa.SyncOptions): execa.ExecaSyncReturnValue; + @returns A `childProcessResult` object + @throws A `childProcessResult` error - /** - Execute a Node.js script as a child process. + @example Basic + ``` + import {$} from 'execa'; + + const branch = $.sync`git branch --show-current`; + $.sync`dep deploy --branch=${branch}`; + ``` - Same as `execa('node', [scriptPath, ...arguments], options)` except (like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)): - - the current Node version and options are used. This can be overridden using the `nodePath` and `nodeArguments` options. - - the `shell` option cannot be used - - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio) + @example Multiple arguments + ``` + import {$} from 'execa'; - @param scriptPath - Node.js script to execute. - @param arguments - Arguments to pass to `scriptPath` on execution. - @returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. + const args = ['unicorns', '&', 'rainbows!']; + const {stdout} = $.sync`echo ${args}`; + console.log(stdout); + //=> 'unicorns & rainbows!' + ``` + + @example With options + ``` + import {$} from 'execa'; + + $.sync({stdio: 'inherit'})`echo unicorns`; + //=> 'unicorns' + ``` + + @example Shared options + ``` + import {$} from 'execa'; + + const $$ = $({stdio: 'inherit'}); + + $$.sync`echo unicorns`; + //=> 'unicorns' + + $$.sync`echo rainbows`; + //=> 'rainbows' + ``` */ - node( - scriptPath: string, - arguments?: readonly string[], - options?: execa.NodeOptions - ): execa.ExecaChildProcess; - node( - scriptPath: string, - arguments?: readonly string[], - options?: execa.Options - ): execa.ExecaChildProcess; - node(scriptPath: string, options?: execa.Options): execa.ExecaChildProcess; - node(scriptPath: string, options?: execa.Options): execa.ExecaChildProcess; + sync( + templates: TemplateStringsArray, + ...expressions: TemplateExpression[] + ): ExecaSyncReturnValue; }; -export = execa; +/** +Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`. + +Arguments are automatically escaped. They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``. + +This is the preferred method when executing multiple commands in a script file. + +The `command` string can inject any `${value}` with the following types: string, number, `childProcess` or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${childProcess}`, the process's `stdout` is used. + +@returns An `ExecaChildProcess` that is both: + - a `Promise` resolving or rejecting with a `childProcessResult`. + - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties. +@throws A `childProcessResult` error + +@example Basic +``` +import {$} from 'execa'; + +const branch = await $`git branch --show-current`; +await $`dep deploy --branch=${branch}`; +``` + +@example Multiple arguments +``` +import {$} from 'execa'; + +const args = ['unicorns', '&', 'rainbows!']; +const {stdout} = await $`echo ${args}`; +console.log(stdout); +//=> 'unicorns & rainbows!' +``` + +@example With options +``` +import {$} from 'execa'; + +await $({stdio: 'inherit'})`echo unicorns`; +//=> 'unicorns' +``` + +@example Shared options +``` +import {$} from 'execa'; + +const $$ = $({stdio: 'inherit'}); + +await $$`echo unicorns`; +//=> 'unicorns' + +await $$`echo rainbows`; +//=> 'rainbows' +``` +*/ +export const $: Execa$; + +/** +Execute a Node.js script as a child process. + +Arguments are automatically escaped. They can contain any character, including spaces. + +This is the preferred method when executing Node.js files. + +Like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options): + - the current Node version and options are used. This can be overridden using the `nodePath` and `nodeOptions` options. + - the `shell` option cannot be used + - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to `stdio` + +@param scriptPath - Node.js script to execute. +@param arguments - Arguments to pass to `scriptPath` on execution. +@returns An `ExecaChildProcess` that is both: + - a `Promise` resolving or rejecting with a `childProcessResult`. + - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties. +@throws A `childProcessResult` error + +@example +``` +import {execa} from 'execa'; + +await execaNode('scriptPath', ['argument']); +``` +*/ +export function execaNode( + scriptPath: string, + arguments?: readonly string[], + options?: NodeOptions +): ExecaChildProcess; +export function execaNode( + scriptPath: string, + arguments?: readonly string[], + options?: NodeOptions +): ExecaChildProcess; +export function execaNode(scriptPath: string, options?: NodeOptions): ExecaChildProcess; +export function execaNode(scriptPath: string, options?: NodeOptions): ExecaChildProcess; diff --git a/node_modules/execa/index.js b/node_modules/execa/index.js index 6fc9f12954..87c827624c 100644 --- a/node_modules/execa/index.js +++ b/node_modules/execa/index.js @@ -1,16 +1,19 @@ -'use strict'; -const path = require('path'); -const childProcess = require('child_process'); -const crossSpawn = require('cross-spawn'); -const stripFinalNewline = require('strip-final-newline'); -const npmRunPath = require('npm-run-path'); -const onetime = require('onetime'); -const makeError = require('./lib/error'); -const normalizeStdio = require('./lib/stdio'); -const {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} = require('./lib/kill'); -const {handleInput, getSpawnedResult, makeAllStream, validateInputSync} = require('./lib/stream'); -const {mergePromise, getSpawnedPromise} = require('./lib/promise'); -const {joinCommand, parseCommand, getEscapedCommand} = require('./lib/command'); +import {Buffer} from 'node:buffer'; +import path from 'node:path'; +import childProcess from 'node:child_process'; +import process from 'node:process'; +import crossSpawn from 'cross-spawn'; +import stripFinalNewline from 'strip-final-newline'; +import {npmRunPathEnv} from 'npm-run-path'; +import onetime from 'onetime'; +import {makeError} from './lib/error.js'; +import {normalizeStdio, normalizeStdioNode} from './lib/stdio.js'; +import {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} from './lib/kill.js'; +import {addPipeMethods} from './lib/pipe.js'; +import {handleInput, getSpawnedResult, makeAllStream, handleInputSync} from './lib/stream.js'; +import {mergePromise, getSpawnedPromise} from './lib/promise.js'; +import {joinCommand, parseCommand, parseTemplates, getEscapedCommand} from './lib/command.js'; +import {logCommand, verboseDefault} from './lib/verbose.js'; const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100; @@ -18,7 +21,7 @@ const getEnv = ({env: envOption, extendEnv, preferLocal, localDir, execPath}) => const env = extendEnv ? {...process.env, ...envOption} : envOption; if (preferLocal) { - return npmRunPath.env({env, cwd: localDir, execPath}); + return npmRunPathEnv({env, cwd: localDir, execPath}); } return env; @@ -43,7 +46,8 @@ const handleArguments = (file, args, options = {}) => { cleanup: true, all: false, windowsHide: true, - ...options + verbose: verboseDefault, + ...options, }; options.env = getEnv(options); @@ -60,7 +64,7 @@ const handleArguments = (file, args, options = {}) => { const handleOutput = (options, value, error) => { if (typeof value !== 'string' && !Buffer.isBuffer(value)) { - // When `execa.sync()` errors, we normalize it to '' to mimic `execa()` + // When `execaSync()` errors, we normalize it to '' to mimic `execa()` return error === undefined ? undefined : ''; } @@ -71,10 +75,11 @@ const handleOutput = (options, value, error) => { return value; }; -const execa = (file, args, options) => { +export function execa(file, args, options) { const parsed = handleArguments(file, args, options); const command = joinCommand(file, args); const escapedCommand = getEscapedCommand(file, args); + logCommand(escapedCommand, parsed.options); validateTimeout(parsed.options); @@ -94,9 +99,10 @@ const execa = (file, args, options) => { parsed, timedOut: false, isCanceled: false, - killed: false + killed: false, })); - return mergePromise(dummySpawned, errorPromise); + mergePromise(dummySpawned, errorPromise); + return dummySpawned; } const spawnedPromise = getSpawnedPromise(spawned); @@ -126,8 +132,8 @@ const execa = (file, args, options) => { escapedCommand, parsed, timedOut, - isCanceled: context.isCanceled, - killed: spawned.killed + isCanceled: context.isCanceled || (parsed.options.signal ? parsed.options.signal.aborted : false), + killed: spawned.killed, }); if (!parsed.options.reject) { @@ -147,31 +153,32 @@ const execa = (file, args, options) => { failed: false, timedOut: false, isCanceled: false, - killed: false + killed: false, }; }; const handlePromiseOnce = onetime(handlePromise); - handleInput(spawned, parsed.options.input); + handleInput(spawned, parsed.options); spawned.all = makeAllStream(spawned, parsed.options); - return mergePromise(spawned, handlePromiseOnce); -}; - -module.exports = execa; + addPipeMethods(spawned); + mergePromise(spawned, handlePromiseOnce); + return spawned; +} -module.exports.sync = (file, args, options) => { +export function execaSync(file, args, options) { const parsed = handleArguments(file, args, options); const command = joinCommand(file, args); const escapedCommand = getEscapedCommand(file, args); + logCommand(escapedCommand, parsed.options); - validateInputSync(parsed.options); + const input = handleInputSync(parsed.options); let result; try { - result = childProcess.spawnSync(parsed.file, parsed.args, parsed.options); + result = childProcess.spawnSync(parsed.file, parsed.args, {...parsed.options, input}); } catch (error) { throw makeError({ error, @@ -183,7 +190,7 @@ module.exports.sync = (file, args, options) => { parsed, timedOut: false, isCanceled: false, - killed: false + killed: false, }); } @@ -202,7 +209,7 @@ module.exports.sync = (file, args, options) => { parsed, timedOut: result.error && result.error.code === 'ETIMEDOUT', isCanceled: false, - killed: result.signal !== null + killed: result.signal !== null, }); if (!parsed.options.reject) { @@ -221,32 +228,52 @@ module.exports.sync = (file, args, options) => { failed: false, timedOut: false, isCanceled: false, - killed: false + killed: false, }; -}; +} + +function create$(options) { + function $(templatesOrOptions, ...expressions) { + if (Array.isArray(templatesOrOptions)) { + const [file, ...args] = parseTemplates(templatesOrOptions, expressions); + return execa(file, args, options); + } + + return create$({...options, ...templatesOrOptions}); + } -module.exports.command = (command, options) => { + $.sync = (templates, ...expressions) => { + const [file, ...args] = parseTemplates(templates, expressions); + return execaSync(file, args, options); + }; + + return $; +} + +export const $ = create$({preferLocal: true}); + +export function execaCommand(command, options) { const [file, ...args] = parseCommand(command); return execa(file, args, options); -}; +} -module.exports.commandSync = (command, options) => { +export function execaCommandSync(command, options) { const [file, ...args] = parseCommand(command); - return execa.sync(file, args, options); -}; + return execaSync(file, args, options); +} -module.exports.node = (scriptPath, args, options = {}) => { +export function execaNode(scriptPath, args, options = {}) { if (args && !Array.isArray(args) && typeof args === 'object') { options = args; args = []; } - const stdio = normalizeStdio.node(options); + const stdio = normalizeStdioNode(options); const defaultExecArgv = process.execArgv.filter(arg => !arg.startsWith('--inspect')); const { nodePath = process.execPath, - nodeOptions = defaultExecArgv + nodeOptions = defaultExecArgv, } = options; return execa( @@ -254,7 +281,7 @@ module.exports.node = (scriptPath, args, options = {}) => { [ ...nodeOptions, scriptPath, - ...(Array.isArray(args) ? args : []) + ...(Array.isArray(args) ? args : []), ], { ...options, @@ -262,7 +289,7 @@ module.exports.node = (scriptPath, args, options = {}) => { stdout: undefined, stderr: undefined, stdio, - shell: false - } + shell: false, + }, ); -}; +} diff --git a/node_modules/execa/lib/command.js b/node_modules/execa/lib/command.js index 859b006a06..b6d2e5ef58 100644 --- a/node_modules/execa/lib/command.js +++ b/node_modules/execa/lib/command.js @@ -1,4 +1,6 @@ -'use strict'; +import {Buffer} from 'node:buffer'; +import {ChildProcess} from 'node:child_process'; + const normalizeArgs = (file, args = []) => { if (!Array.isArray(args)) { return [file]; @@ -18,18 +20,14 @@ const escapeArg = arg => { return `"${arg.replace(DOUBLE_QUOTES_REGEXP, '\\"')}"`; }; -const joinCommand = (file, args) => { - return normalizeArgs(file, args).join(' '); -}; +export const joinCommand = (file, args) => normalizeArgs(file, args).join(' '); -const getEscapedCommand = (file, args) => { - return normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' '); -}; +export const getEscapedCommand = (file, args) => normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' '); const SPACES_REGEXP = / +/g; -// Handle `execa.command()` -const parseCommand = command => { +// Handle `execaCommand()` +export const parseCommand = 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 @@ -45,8 +43,54 @@ const parseCommand = command => { return tokens; }; -module.exports = { - joinCommand, - getEscapedCommand, - parseCommand +const parseExpression = expression => { + const typeOfExpression = typeof expression; + + if (typeOfExpression === 'string') { + return expression; + } + + if (typeOfExpression === 'number') { + return String(expression); + } + + if ( + typeOfExpression === 'object' + && expression !== null + && !(expression instanceof ChildProcess) + && 'stdout' in expression + ) { + const typeOfStdout = typeof expression.stdout; + + if (typeOfStdout === 'string') { + return expression.stdout; + } + + if (Buffer.isBuffer(expression.stdout)) { + return expression.stdout.toString(); + } + + throw new TypeError(`Unexpected "${typeOfStdout}" stdout in template expression`); + } + + throw new TypeError(`Unexpected "${typeOfExpression}" in template expression`); +}; + +const parseTemplate = (template, index, templates, expressions) => { + const templateString = template ?? templates.raw[index]; + const templateTokens = templateString.split(SPACES_REGEXP).filter(Boolean); + + if (index === expressions.length) { + return templateTokens; + } + + const expression = expressions[index]; + + return Array.isArray(expression) + ? [...templateTokens, ...expression.map(expression => parseExpression(expression))] + : [...templateTokens, parseExpression(expression)]; }; + +export const parseTemplates = (templates, expressions) => templates.flatMap( + (template, index) => parseTemplate(template, index, templates, expressions), +); diff --git a/node_modules/execa/lib/error.js b/node_modules/execa/lib/error.js index 42144674dc..b12c144428 100644 --- a/node_modules/execa/lib/error.js +++ b/node_modules/execa/lib/error.js @@ -1,5 +1,4 @@ -'use strict'; -const {signalsByName} = require('human-signals'); +import {signalsByName} from 'human-signals'; const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => { if (timedOut) { @@ -25,7 +24,7 @@ const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription return 'failed'; }; -const makeError = ({ +export const makeError = ({ stdout, stderr, all, @@ -37,7 +36,7 @@ const makeError = ({ timedOut, isCanceled, killed, - parsed: {options: {timeout}} + parsed: {options: {timeout}}, }) => { // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`. // We normalize them to `undefined` @@ -84,5 +83,3 @@ const makeError = ({ return error; }; - -module.exports = makeError; diff --git a/node_modules/execa/lib/kill.js b/node_modules/execa/lib/kill.js index 287a14238e..efc6b9ba41 100644 --- a/node_modules/execa/lib/kill.js +++ b/node_modules/execa/lib/kill.js @@ -1,11 +1,10 @@ -'use strict'; -const os = require('os'); -const onExit = require('signal-exit'); +import os from 'node:os'; +import onExit from 'signal-exit'; const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5; // Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior -const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => { +export const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => { const killResult = kill(signal); setKillTimeout(kill, signal, options, killResult); return killResult; @@ -30,14 +29,10 @@ const setKillTimeout = (kill, signal, options, killResult) => { } }; -const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => { - return isSigterm(signal) && forceKillAfterTimeout !== false && killResult; -}; +const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => isSigterm(signal) && forceKillAfterTimeout !== false && killResult; -const isSigterm = signal => { - return signal === os.constants.signals.SIGTERM || - (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM'); -}; +const isSigterm = signal => signal === os.constants.signals.SIGTERM + || (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM'); const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { if (forceKillAfterTimeout === true) { @@ -52,7 +47,7 @@ const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { }; // `childProcess.cancel()` -const spawnedCancel = (spawned, context) => { +export const spawnedCancel = (spawned, context) => { const killResult = spawned.kill(); if (killResult) { @@ -66,7 +61,7 @@ const timeoutKill = (spawned, signal, reject) => { }; // `timeout` option handling -const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => { +export const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => { if (timeout === 0 || timeout === undefined) { return spawnedPromise; } @@ -85,14 +80,14 @@ const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise return Promise.race([timeoutPromise, safeSpawnedPromise]); }; -const validateTimeout = ({timeout}) => { +export const validateTimeout = ({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 = async (spawned, {cleanup, detached}, timedPromise) => { +export const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => { if (!cleanup || detached) { return timedPromise; } @@ -105,11 +100,3 @@ const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => { removeExitHandler(); }); }; - -module.exports = { - spawnedKill, - spawnedCancel, - setupTimeout, - validateTimeout, - setExitHandler -}; diff --git a/node_modules/execa/lib/pipe.js b/node_modules/execa/lib/pipe.js new file mode 100644 index 0000000000..e73ffcc989 --- /dev/null +++ b/node_modules/execa/lib/pipe.js @@ -0,0 +1,42 @@ +import {createWriteStream} from 'node:fs'; +import {ChildProcess} from 'node:child_process'; +import {isWritableStream} from 'is-stream'; + +const isExecaChildProcess = target => target instanceof ChildProcess && typeof target.then === 'function'; + +const pipeToTarget = (spawned, streamName, target) => { + if (typeof target === 'string') { + spawned[streamName].pipe(createWriteStream(target)); + return spawned; + } + + if (isWritableStream(target)) { + spawned[streamName].pipe(target); + return spawned; + } + + if (!isExecaChildProcess(target)) { + throw new TypeError('The second argument must be a string, a stream or an Execa child process.'); + } + + if (!isWritableStream(target.stdin)) { + throw new TypeError('The target child process\'s stdin must be available.'); + } + + spawned[streamName].pipe(target.stdin); + return target; +}; + +export const addPipeMethods = spawned => { + if (spawned.stdout !== null) { + spawned.pipeStdout = pipeToTarget.bind(undefined, spawned, 'stdout'); + } + + if (spawned.stderr !== null) { + spawned.pipeStderr = pipeToTarget.bind(undefined, spawned, 'stderr'); + } + + if (spawned.all !== undefined) { + spawned.pipeAll = pipeToTarget.bind(undefined, spawned, 'all'); + } +}; diff --git a/node_modules/execa/lib/promise.js b/node_modules/execa/lib/promise.js index bd9d52333d..a4773f30b0 100644 --- a/node_modules/execa/lib/promise.js +++ b/node_modules/execa/lib/promise.js @@ -1,46 +1,36 @@ -'use strict'; - +// eslint-disable-next-line unicorn/prefer-top-level-await const nativePromisePrototype = (async () => {})().constructor.prototype; + const descriptors = ['then', 'catch', 'finally'].map(property => [ property, - Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property) + Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property), ]); // The return value is a mixin of `childProcess` and `Promise` -const mergePromise = (spawned, promise) => { +export const mergePromise = (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); + 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 = 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); - }); - } +export const getSpawnedPromise = spawned => new Promise((resolve, reject) => { + spawned.on('exit', (exitCode, signal) => { + resolve({exitCode, signal}); }); -}; -module.exports = { - mergePromise, - getSpawnedPromise -}; + spawned.on('error', error => { + reject(error); + }); + if (spawned.stdin) { + spawned.stdin.on('error', error => { + reject(error); + }); + } +}); diff --git a/node_modules/execa/lib/stdio.js b/node_modules/execa/lib/stdio.js index 45129ed7ef..e8c1132dc1 100644 --- a/node_modules/execa/lib/stdio.js +++ b/node_modules/execa/lib/stdio.js @@ -1,9 +1,8 @@ -'use strict'; const aliases = ['stdin', 'stdout', 'stderr']; const hasAlias = options => aliases.some(alias => options[alias] !== undefined); -const normalizeStdio = options => { +export const normalizeStdio = options => { if (!options) { return; } @@ -30,10 +29,8 @@ const normalizeStdio = options => { return Array.from({length}, (value, index) => stdio[index]); }; -module.exports = normalizeStdio; - // `ipc` is pushed unless it is already present -module.exports.node = options => { +export const normalizeStdioNode = options => { const stdio = normalizeStdio(options); if (stdio === 'ipc') { diff --git a/node_modules/execa/lib/stream.js b/node_modules/execa/lib/stream.js index d445dd4710..5f79b791d9 100644 --- a/node_modules/execa/lib/stream.js +++ b/node_modules/execa/lib/stream.js @@ -1,13 +1,48 @@ -'use strict'; -const isStream = require('is-stream'); -const getStream = require('get-stream'); -const mergeStream = require('merge-stream'); - -// `input` option -const handleInput = (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) { +import {createReadStream, readFileSync} from 'node:fs'; +import {isStream} from 'is-stream'; +import getStream from 'get-stream'; +import mergeStream from 'merge-stream'; + +const validateInputOptions = input => { + if (input !== undefined) { + throw new TypeError('The `input` and `inputFile` options cannot be both set.'); + } +}; + +const getInputSync = ({input, inputFile}) => { + if (typeof inputFile !== 'string') { + return input; + } + + validateInputOptions(input); + return readFileSync(inputFile); +}; + +// `input` and `inputFile` option in sync mode +export const handleInputSync = options => { + const input = getInputSync(options); + + if (isStream(input)) { + throw new TypeError('The `input` option cannot be a stream in sync mode'); + } + + return input; +}; + +const getInput = ({input, inputFile}) => { + if (typeof inputFile !== 'string') { + return input; + } + + validateInputOptions(input); + return createReadStream(inputFile); +}; + +// `input` and `inputFile` option in async mode +export const handleInput = (spawned, options) => { + const input = getInput(options); + + if (input === undefined) { return; } @@ -19,7 +54,7 @@ const handleInput = (spawned, input) => { }; // `all` interleaves `stdout` and `stderr` -const makeAllStream = (spawned, {all}) => { +export const makeAllStream = (spawned, {all}) => { if (!all || (!spawned.stdout && !spawned.stderr)) { return; } @@ -39,7 +74,8 @@ const makeAllStream = (spawned, {all}) => { // On failure, `result.stdout|stderr|all` should contain the currently buffered stream const getBufferedData = async (stream, streamPromise) => { - if (!stream) { + // When `buffer` is `false`, `streamPromise` is `undefined` and there is no buffered data to retrieve + if (!stream || streamPromise === undefined) { return; } @@ -65,7 +101,7 @@ const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => { }; // Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all) -const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => { +export const getSpawnedResult = 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}); @@ -77,21 +113,7 @@ const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuf {error, signal: error.signal, timedOut: error.timedOut}, getBufferedData(stdout, stdoutPromise), getBufferedData(stderr, stderrPromise), - getBufferedData(all, allPromise) + getBufferedData(all, allPromise), ]); } }; - -const validateInputSync = ({input}) => { - if (isStream(input)) { - throw new TypeError('The `input` option cannot be a stream in sync mode'); - } -}; - -module.exports = { - handleInput, - makeAllStream, - getSpawnedResult, - validateInputSync -}; - diff --git a/node_modules/execa/lib/verbose.js b/node_modules/execa/lib/verbose.js new file mode 100644 index 0000000000..5f5490ed02 --- /dev/null +++ b/node_modules/execa/lib/verbose.js @@ -0,0 +1,19 @@ +import {debuglog} from 'node:util'; +import process from 'node:process'; + +export const verboseDefault = debuglog('execa').enabled; + +const padField = (field, padding) => String(field).padStart(padding, '0'); + +const getTimestamp = () => { + const date = new Date(); + return `${padField(date.getHours(), 2)}:${padField(date.getMinutes(), 2)}:${padField(date.getSeconds(), 2)}.${padField(date.getMilliseconds(), 3)}`; +}; + +export const logCommand = (escapedCommand, {verbose}) => { + if (!verbose) { + return; + } + + process.stderr.write(`[${getTimestamp()}] ${escapedCommand}\n`); +}; diff --git a/node_modules/execa/package.json b/node_modules/execa/package.json index 441e23c8a8..8a705ad6d0 100644 --- a/node_modules/execa/package.json +++ b/node_modules/execa/package.json @@ -1,6 +1,6 @@ { "name": "execa", - "version": "5.1.1", + "version": "7.1.0", "description": "Process execution for humans", "license": "MIT", "repository": "sindresorhus/execa", @@ -10,11 +10,13 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=10" + "node": "^14.18.0 || ^16.14.0 || >=18.0.0" }, "scripts": { - "test": "xo && nyc ava && tsd" + "test": "xo && c8 ava && tsd" }, "files": [ "index.js", @@ -40,27 +42,28 @@ ], "dependencies": { "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", + "get-stream": "^6.0.1", + "human-signals": "^4.3.0", + "is-stream": "^3.0.0", "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" }, "devDependencies": { - "@types/node": "^14.14.10", - "ava": "^2.4.0", - "get-node": "^11.0.1", + "@types/node": "^18.13.0", + "ava": "^5.2.0", + "c8": "^7.12.0", + "get-node": "^13.5.0", "is-running": "^2.1.0", - "nyc": "^15.1.0", - "p-event": "^4.2.0", - "tempfile": "^3.0.0", - "tsd": "^0.13.1", - "xo": "^0.35.0" + "p-event": "^5.0.1", + "path-key": "^4.0.0", + "tempfile": "^4.0.0", + "tsd": "^0.25.0", + "xo": "^0.53.1" }, - "nyc": { + "c8": { "reporter": [ "text", "lcov" @@ -70,5 +73,14 @@ "**/test.js", "**/test/**" ] + }, + "ava": { + "workerThreads": false + }, + "xo": { + "rules": { + "unicorn/no-empty-file": "off", + "@typescript-eslint/ban-types": "off" + } } } diff --git a/node_modules/execa/readme.md b/node_modules/execa/readme.md index 843edbc7d1..4b756c64e9 100644 --- a/node_modules/execa/readme.md +++ b/node_modules/execa/readme.md @@ -1,4 +1,7 @@ - + + + execa logo +
[![Coverage Status](https://codecov.io/gh/sindresorhus/execa/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/execa) @@ -9,123 +12,173 @@ This package improves [`child_process`](https://nodejs.org/api/child_process.html) methods with: -- Promise interface. +- [Promise interface](#execacommandcommand-options). +- [Scripts interface](#scripts-interface), like `zx`. +- Improved [Windows support](https://github.com/IndigoUnited/node-cross-spawn#why), including [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries. +- Executes [locally installed binaries](#preferlocal) without `npx`. +- [Cleans up](#cleanup) child processes when the parent process ends. +- [Graceful termination](#optionsforcekillaftertimeout). +- Get [interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal. - [Strips the final newline](#stripfinalnewline) from the output so you don't have to do `stdout.trim()`. -- Supports [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries cross-platform. -- [Improved Windows support.](https://github.com/IndigoUnited/node-cross-spawn#why) -- Higher max buffer. 100 MB instead of 200 KB. -- [Executes locally installed binaries by name.](#preferlocal) -- [Cleans up spawned processes when the parent process dies.](#cleanup) -- [Get interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal. [*(Async only)*](#execasyncfile-arguments-options) -- [Can specify file and arguments as a single string without a shell](#execacommandcommand-options) +- Convenience methods to pipe processes' [input](#input) and [output](#redirect-output-to-a-file). +- Can specify file and arguments [as a single string](#execacommandcommand-options) without a shell. +- [Verbose mode](#verbose-mode) for debugging. - More descriptive errors. +- Higher max buffer: 100 MB instead of 1 MB. ## Install -``` -$ npm install execa +```sh +npm install execa ``` ## Usage +### Promise interface + ```js -const execa = require('execa'); +import {execa} from 'execa'; -(async () => { - const {stdout} = await execa('echo', ['unicorns']); - console.log(stdout); - //=> 'unicorns' -})(); +const {stdout} = await execa('echo', ['unicorns']); +console.log(stdout); +//=> 'unicorns' ``` -### Pipe the child process stdout to the parent +### Scripts interface + +For more information about Execa scripts, please see [this page](docs/scripts.md). + +#### Basic ```js -const execa = require('execa'); +import {$} from 'execa'; -execa('echo', ['unicorns']).stdout.pipe(process.stdout); +const branch = await $`git branch --show-current`; +await $`dep deploy --branch=${branch}`; ``` -### Handling Errors +#### Multiple arguments ```js -const execa = require('execa'); - -(async () => { - // Catching an error - try { - await execa('unknown', ['command']); - } catch (error) { - console.log(error); - /* - { - message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', - errno: -2, - code: 'ENOENT', - syscall: 'spawn unknown', - path: 'unknown', - spawnargs: ['command'], - originalMessage: 'spawn unknown ENOENT', - shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', - command: 'unknown command', - escapedCommand: 'unknown command', - stdout: '', - stderr: '', - all: '', - failed: true, - timedOut: false, - isCanceled: false, - killed: false - } - */ - } +import {$} from 'execa'; -})(); +const args = ['unicorns', '&', 'rainbows!']; +const {stdout} = await $`echo ${args}`; +console.log(stdout); +//=> 'unicorns & rainbows!' ``` -### Cancelling a spawned process +#### With options + +```js +import {$} from 'execa'; + +await $({stdio: 'inherit'})`echo unicorns`; +//=> 'unicorns' +``` + +#### Shared options ```js -const execa = require('execa'); +import {$} from 'execa'; -(async () => { - const subprocess = execa('node'); +const $$ = $({stdio: 'inherit'}); - setTimeout(() => { - subprocess.cancel(); - }, 1000); +await $$`echo unicorns`; +//=> 'unicorns' - try { - await subprocess; - } catch (error) { - console.log(subprocess.killed); // true - console.log(error.isCanceled); // true - } -})() +await $$`echo rainbows`; +//=> 'rainbows' +``` + +#### Verbose mode + +```sh +> node file.js +unicorns +rainbows + +> NODE_DEBUG=execa node file.js +[16:50:03.305] echo unicorns +unicorns +[16:50:03.308] echo rainbows +rainbows +``` + +### Input/output + +#### Redirect output to a file + +```js +import {execa} from 'execa'; + +// Similar to `echo unicorns > stdout.txt` in Bash +await execa('echo', ['unicorns']).pipeStdout('stdout.txt'); + +// Similar to `echo unicorns 2> stdout.txt` in Bash +await execa('echo', ['unicorns']).pipeStderr('stderr.txt'); + +// Similar to `echo unicorns &> stdout.txt` in Bash +await execa('echo', ['unicorns'], {all: true}).pipeAll('all.txt'); +``` + +#### Redirect input from a file + +```js +import {execa} from 'execa'; + +// Similar to `cat < stdin.txt` in Bash +const {stdout} = await execa('cat', {inputFile: 'stdin.txt'}); +console.log(stdout); +//=> 'unicorns' +``` + +#### Save and pipe output from a child process + +```js +import {execa} from 'execa'; + +const {stdout} = await execa('echo', ['unicorns']).pipeStdout(process.stdout); +// Prints `unicorns` +console.log(stdout); +// Also returns 'unicorns' +``` + +#### Pipe multiple processes + +```js +import {execa} from 'execa'; + +// Similar to `echo unicorns | cat` in Bash +const {stdout} = await execa('echo', ['unicorns']).pipeStdout(execa('cat')); +console.log(stdout); +//=> 'unicorns' ``` -### Catching an error with the sync method +### Handling Errors ```js +import {execa} from 'execa'; + +// Catching an error try { - execa.sync('unknown', ['command']); + await execa('unknown', ['command']); } catch (error) { console.log(error); /* { - message: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT', + message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', errno: -2, code: 'ENOENT', - syscall: 'spawnSync unknown', + syscall: 'spawn unknown', path: 'unknown', spawnargs: ['command'], - originalMessage: 'spawnSync unknown ENOENT', - shortMessage: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT', + originalMessage: 'spawn unknown ENOENT', + shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', command: 'unknown command', escapedCommand: 'unknown command', stdout: '', stderr: '', - all: '', failed: true, timedOut: false, isCanceled: false, @@ -135,7 +188,7 @@ try { } ``` -### Kill a process +### Graceful termination Using SIGTERM, and after 2 seconds, kill it with SIGKILL. @@ -151,17 +204,84 @@ setTimeout(() => { ## API -### execa(file, arguments, options?) +### Methods + +#### execa(file, arguments?, options?) + +Executes a command using `file ...arguments`. `arguments` are specified as an array of strings. Returns a [`childProcess`](#childprocess). + +Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces. + +This is the preferred method when executing single commands. + +#### execaNode(scriptPath, arguments?, options?) + +Executes a Node.js file using `node scriptPath ...arguments`. `arguments` are specified as an array of strings. Returns a [`childProcess`](#childprocess). + +Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces. + +This is the preferred method when executing Node.js files. + +Like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options): + - the current Node version and options are used. This can be overridden using the [`nodePath`](#nodepath-for-node-only) and [`nodeOptions`](#nodeoptions-for-node-only) options. + - the [`shell`](#shell) option cannot be used + - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio) + +#### $\`command\` + +Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess). + +Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``. + +This is the preferred method when executing multiple commands in a script file. + +The `command` string can inject any `${value}` with the following types: string, number, [`childProcess`](#childprocess) or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${childProcess}`, the process's `stdout` is used. + +For more information, please see [this section](#scripts-interface) and [this page](docs/scripts.md). + +#### $(options) + +Returns a new instance of [`$`](#command) but with different default `options`. Consecutive calls are merged to previous ones. + +This can be used to either: + - Set options for a specific command: `` $(options)`command` `` + - Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand`; `` + +#### execaCommand(command, options?) -Execute a file. Think of this as a mix of [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback) and [`child_process.spawn()`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). +Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess). -No escaping/quoting is needed. +Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`. -Unless the [`shell`](#shell) option is used, no shell interpreter (Bash, `cmd.exe`, etc.) is used, so shell features such as variables substitution (`echo $PATH`) are not allowed. +This is the preferred method when executing a user-supplied `command` string, such as in a REPL. -Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) which: - - is also a `Promise` resolving or rejecting with a [`childProcessResult`](#childProcessResult). - - exposes the following additional methods and properties. +### execaSync(file, arguments?, options?) + +Same as [`execa()`](#execacommandcommand-options) but synchronous. + +Returns or throws a [`childProcessResult`](#childProcessResult). + +### $.sync\`command\` + +Same as [$\`command\`](#command) but synchronous. + +Returns or throws a [`childProcessResult`](#childProcessResult). + +### execaCommandSync(command, options?) + +Same as [`execaCommand()`](#execacommand-command-options) but synchronous. + +Returns or throws a [`childProcessResult`](#childProcessResult). + +### Shell syntax + +For all the [methods above](#methods), no shell interpreter (Bash, cmd.exe, etc.) is used unless the [`shell` option](#shell) is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped. + +### childProcess + +The return value of all [asynchronous methods](#methods) is both: + - a `Promise` resolving or rejecting with a [`childProcessResult`](#childProcessResult). + - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following additional methods and properties. #### kill(signal?, options?) @@ -176,10 +296,6 @@ Milliseconds to wait for the child process to terminate before sending `SIGKILL` Can be disabled with `false`. -#### cancel() - -Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This is preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. - #### all Type: `ReadableStream | undefined` @@ -190,34 +306,28 @@ This is `undefined` if either: - the [`all` option](#all-2) is `false` (the default value) - both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio) -### execa.sync(file, arguments?, options?) - -Execute a file synchronously. - -Returns or throws a [`childProcessResult`](#childProcessResult). - -### execa.command(command, options?) +#### pipeStdout(target) -Same as [`execa()`](#execafile-arguments-options) except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execa.command('echo unicorns')`. +[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process's `stdout` to `target`, which can be: + - Another [`execa()` return value](#pipe-multiple-processes) + - A [writable stream](#save-and-pipe-output-from-a-child-process) + - A [file path string](#redirect-output-to-a-file) -If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if `command` is not a constant but a variable, for example with `__dirname` or `process.cwd()`. Except for spaces, no escaping/quoting is needed. +If the `target` is another [`execa()` return value](#execacommandcommand-options), it is returned. Otherwise, the original `execa()` return value is returned. This allows chaining `pipeStdout()` then `await`ing the [final result](#childprocessresult). -The [`shell` option](#shell) must be used if the `command` uses shell-specific features (for example, `&&` or `||`), as opposed to being a simple `file` followed by its `arguments`. +The [`stdout` option](#stdout-1) must be kept as `pipe`, its default value. -### execa.commandSync(command, options?) +#### pipeStderr(target) -Same as [`execa.command()`](#execacommand-command-options) but synchronous. +Like [`pipeStdout()`](#pipestdouttarget) but piping the child process's `stderr` instead. -Returns or throws a [`childProcessResult`](#childProcessResult). +The [`stderr` option](#stderr-1) must be kept as `pipe`, its default value. -### execa.node(scriptPath, arguments?, options?) +#### pipeAll(target) -Execute a Node.js script as a child process. +Combines both [`pipeStdout()`](#pipestdouttarget) and [`pipeStderr()`](#pipestderrtarget). -Same as `execa('node', [scriptPath, ...arguments], options)` except (like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)): - - the current Node version and options are used. This can be overridden using the [`nodePath`](#nodepath-for-node-only) and [`nodeOptions`](#nodeoptions-for-node-only) options. - - the [`shell`](#shell) option cannot be used - - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio) +Either the [`stdout` option](#stdout-1) or the [`stderr` option](#stderr-1) must be kept as `pipe`, their default value. Also, the [`all` option](#all-2) must be set to `true`. ### childProcessResult @@ -238,16 +348,16 @@ Type: `string` The file and arguments that were run, for logging purposes. -This is not escaped and should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execa.command()`](#execacommandcommand-options). +This is not escaped and should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options). #### escapedCommand Type: `string` -Same as [`command`](#command) but escaped. +Same as [`command`](#command-1) but escaped. This is meant to be copy and pasted into a shell, for debugging purposes. -Since the escaping is fairly basic, this should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execa.command()`](#execacommandcommand-options). +Since the escaping is fairly basic, this should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options). #### exitCode @@ -275,7 +385,7 @@ The output of the process with `stdout` and `stderr` interleaved. This is `undefined` if either: - the [`all` option](#all-2) is `false` (the default value) - - `execa.sync()` was used + - `execaSync()` was used #### failed @@ -295,6 +405,8 @@ Type: `boolean` Whether the process was canceled. +You can cancel the spawned process using the [`signal`](#signal-1) option. + #### killed Type: `boolean` @@ -355,14 +467,14 @@ Kill the spawned process when the parent process exits unless either: #### preferLocal Type: `boolean`\ -Default: `false` +Default: `true` with [`$`](#command)/[`$.sync`](#synccommand), `false` otherwise Prefer locally installed binaries when looking for a binary to execute.\ If you `$ npm install foo`, you can then `execa('foo')`. #### localDir -Type: `string`\ +Type: `string | URL`\ Default: `process.cwd()` Preferred path to find locally installed binaries in (use with `preferLocal`). @@ -396,6 +508,16 @@ Type: `string | Buffer | stream.Readable` Write some input to the `stdin` of your binary.\ Streams are not allowed when using the synchronous methods. +If the input is a file, use the [`inputFile` option](#inputfile) instead. + +#### inputFile + +Type: `string` + +Use a file as input to the the `stdin` of your binary. + +If the input is not a file, use the [`input` option](#input) instead. + #### stdin Type: `string | number | Stream | undefined`\ @@ -451,7 +573,7 @@ Execa also accepts the below options which are the same as the options for [`chi #### cwd -Type: `string`\ +Type: `string | URL`\ Default: `process.cwd()` Current working directory of the child process. @@ -481,12 +603,10 @@ Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_ Type: `string`\ Default: `'json'` -Specify the kind of serialization used for sending messages between processes when using the [`stdio: 'ipc'`](#stdio) option or [`execa.node()`](#execanodescriptpath-arguments-options): +Specify the kind of serialization used for sending messages between processes when using the [`stdio: 'ipc'`](#stdio) option or [`execaNode()`](#execanodescriptpath-arguments-options): - `json`: Uses `JSON.stringify()` and `JSON.parse()`. - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value) -Requires Node.js `13.2.0` or later. - [More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization) #### detached @@ -547,6 +667,16 @@ Default: `SIGTERM` Signal value to be used when the spawned process will be killed. +#### signal + +Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) + +You can abort the spawned process using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). + +When `AbortController.abort()` is called, [`.isCanceled`](#iscanceled) becomes `false`. + +*Requires Node.js 16 or later.* + #### windowsVerbatimArguments Type: `boolean`\ @@ -561,6 +691,15 @@ Default: `true` On Windows, do not create a new console window. Please note this also prevents `CTRL-C` [from working](https://github.com/nodejs/node/issues/29837) on Windows. +#### verbose + +Type: `boolean`\ +Default: `false` + +[Print each command](#verbose-mode) on `stderr` before executing it. + +This can also be enabled by setting the `NODE_DEBUG=execa` environment variable in the current process. + #### nodePath *(For `.node()` only)* Type: `string`\ @@ -582,59 +721,43 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Gracefully handle failures by using automatic retries and exponential backoff with the [`p-retry`](https://github.com/sindresorhus/p-retry) package: ```js -const pRetry = require('p-retry'); +import pRetry from 'p-retry'; const run = async () => { const results = await execa('curl', ['-sSL', 'https://sindresorhus.com/unicorn']); return results; }; -(async () => { - console.log(await pRetry(run, {retries: 5})); -})(); +console.log(await pRetry(run, {retries: 5})); ``` -### Save and pipe output from a child process - -Let's say you want to show the output of a child process in real-time while also saving it to a variable. - -```js -const execa = require('execa'); - -const subprocess = execa('echo', ['foo']); -subprocess.stdout.pipe(process.stdout); - -(async () => { - const {stdout} = await subprocess; - console.log('child output:', stdout); -})(); -``` - -### Redirect output to a file +### Cancelling a spawned process ```js -const execa = require('execa'); +import {execa} from 'execa'; -const subprocess = execa('echo', ['foo']) -subprocess.stdout.pipe(fs.createWriteStream('stdout.txt')) -``` - -### Redirect input from a file +const abortController = new AbortController(); +const subprocess = execa('node', [], {signal: abortController.signal}); -```js -const execa = require('execa'); +setTimeout(() => { + abortController.abort(); +}, 1000); -const subprocess = execa('cat') -fs.createReadStream('stdin.txt').pipe(subprocess.stdin) +try { + await subprocess; +} catch (error) { + console.log(subprocess.killed); // true + console.log(error.isCanceled); // true +} ``` ### Execute the current package's binary ```js -const {getBinPathSync} = require('get-bin-path'); +import {getBinPath} from 'get-bin-path'; -const binPath = getBinPathSync(); -const subprocess = execa(binPath); +const binPath = await getBinPath(); +await execa(binPath); ``` `execa` can be combined with [`get-bin-path`](https://github.com/ehmicky/get-bin-path) to test the current package's binary. As opposed to hard-coding the path to the binary, this validates that the `package.json` `bin` field is correctly set up. diff --git a/node_modules/execa/node_modules/get-stream/buffer-stream.js b/node_modules/get-stream/buffer-stream.js similarity index 100% rename from node_modules/execa/node_modules/get-stream/buffer-stream.js rename to node_modules/get-stream/buffer-stream.js diff --git a/node_modules/execa/node_modules/get-stream/index.d.ts b/node_modules/get-stream/index.d.ts similarity index 100% rename from node_modules/execa/node_modules/get-stream/index.d.ts rename to node_modules/get-stream/index.d.ts diff --git a/node_modules/execa/node_modules/get-stream/index.js b/node_modules/get-stream/index.js similarity index 100% rename from node_modules/execa/node_modules/get-stream/index.js rename to node_modules/get-stream/index.js diff --git a/node_modules/execa/node_modules/get-stream/license b/node_modules/get-stream/license similarity index 100% rename from node_modules/execa/node_modules/get-stream/license rename to node_modules/get-stream/license diff --git a/node_modules/execa/node_modules/get-stream/package.json b/node_modules/get-stream/package.json similarity index 100% rename from node_modules/execa/node_modules/get-stream/package.json rename to node_modules/get-stream/package.json diff --git a/node_modules/execa/node_modules/get-stream/readme.md b/node_modules/get-stream/readme.md similarity index 100% rename from node_modules/execa/node_modules/get-stream/readme.md rename to node_modules/get-stream/readme.md diff --git a/node_modules/human-signals/CHANGELOG.md b/node_modules/human-signals/CHANGELOG.md deleted file mode 100644 index 70d0392933..0000000000 --- a/node_modules/human-signals/CHANGELOG.md +++ /dev/null @@ -1,11 +0,0 @@ -# 2.1.0 - -## TypeScript types - -- Add [TypeScript definitions](src/main.d.ts) - -# 2.0.0 - -## Breaking changes - -- Minimal supported Node.js version is now `10.17.0` diff --git a/node_modules/human-signals/LICENSE b/node_modules/human-signals/LICENSE index 9af9492617..642f59b66d 100644 --- a/node_modules/human-signals/LICENSE +++ b/node_modules/human-signals/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2019 ehmicky + Copyright 2022 ehmicky Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/node_modules/human-signals/README.md b/node_modules/human-signals/README.md index 2af37c370c..9818e8b6e9 100644 --- a/node_modules/human-signals/README.md +++ b/node_modules/human-signals/README.md @@ -1,9 +1,8 @@ -[![Codecov](https://img.shields.io/codecov/c/github/ehmicky/human-signals.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/human-signals) -[![Travis](https://img.shields.io/badge/cross-platform-4cc61e.svg?logo=travis)](https://travis-ci.org/ehmicky/human-signals) -[![Node](https://img.shields.io/node/v/human-signals.svg?logo=node.js)](https://www.npmjs.com/package/human-signals) -[![Gitter](https://img.shields.io/gitter/room/ehmicky/human-signals.svg?logo=gitter)](https://gitter.im/ehmicky/human-signals) -[![Twitter](https://img.shields.io/badge/%E2%80%8B-twitter-4cc61e.svg?logo=twitter)](https://twitter.com/intent/follow?screen_name=ehmicky) -[![Medium](https://img.shields.io/badge/%E2%80%8B-medium-4cc61e.svg?logo=medium)](https://medium.com/@ehmicky) +[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/human-signals) +[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/types/main.d.ts) +[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/human-signals) +[![Twitter](https://img.shields.io/badge/-Twitter-808080.svg?logo=twitter&colorA=404040)](https://twitter.com/intent/follow?screen_name=ehmicky) +[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky) Human-friendly process signals. @@ -20,7 +19,7 @@ this includes: # Example ```js -const { signalsByName, signalsByNumber } = require('human-signals') +import { signalsByName, signalsByNumber } from 'human-signals' console.log(signalsByName.SIGINT) // { @@ -51,6 +50,11 @@ console.log(signalsByNumber[8]) npm install human-signals ``` +This package works in Node.js >=14.18.0. It is an ES module and must be loaded +using +[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), +not `require()`. + # Usage ## signalsByName @@ -101,7 +105,7 @@ Whether the current OS can handle this signal in Node.js using [`process.on(name, handler)`](https://nodejs.org/api/process.html#process_signal_events). The list of supported signals -[is OS-specific](https://github.com/ehmicky/cross-platform-node-guide/blob/master/docs/6_networking_ipc/signals.md#cross-platform-signals). +[is OS-specific](https://github.com/ehmicky/cross-platform-node-guide/blob/main/docs/6_networking_ipc/signals.md#cross-platform-signals). ### action @@ -126,11 +130,7 @@ Which standard defined that signal. # Support -If you found a bug or would like a new feature, _don't hesitate_ to -[submit an issue on GitHub](../../issues). - -For other questions, feel free to -[chat with us on Gitter](https://gitter.im/ehmicky/human-signals). +For any question, _don't hesitate_ to [submit an issue on GitHub](../../issues). Everyone is welcome regardless of personal background. We enforce a [Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and diff --git a/node_modules/human-signals/build/src/core.js b/node_modules/human-signals/build/src/core.js index 98e8fced05..c3a97737e9 100644 --- a/node_modules/human-signals/build/src/core.js +++ b/node_modules/human-signals/build/src/core.js @@ -1,6 +1,6 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.SIGNALS=void 0; -const SIGNALS=[ + +export const SIGNALS=[ { name:"SIGHUP", number:1, @@ -269,5 +269,5 @@ name:"SIGUNUSED", number:31, action:"terminate", description:"Invalid system call", -standard:"other"}];exports.SIGNALS=SIGNALS; +standard:"other"}]; //# sourceMappingURL=core.js.map \ No newline at end of file diff --git a/node_modules/human-signals/build/src/core.js.map b/node_modules/human-signals/build/src/core.js.map deleted file mode 100644 index cbfce26de3..0000000000 --- a/node_modules/human-signals/build/src/core.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../../src/core.js"],"names":["SIGNALS","name","number","action","description","standard","forced"],"mappings":";;AAEO,KAAMA,CAAAA,OAAO,CAAG;AACrB;AACEC,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,iBAJf;AAKEC,QAAQ,CAAE,OALZ,CADqB;;AAQrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,+BAJf;AAKEC,QAAQ,CAAE,MALZ,CARqB;;AAerB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,gCAJf;AAKEC,QAAQ,CAAE,OALZ,CAfqB;;AAsBrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,6BAJf;AAKEC,QAAQ,CAAE,MALZ,CAtBqB;;AA6BrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,qBAJf;AAKEC,QAAQ,CAAE,OALZ,CA7BqB;;AAoCrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,SAJf;AAKEC,QAAQ,CAAE,MALZ,CApCqB;;AA2CrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,SAJf;AAKEC,QAAQ,CAAE,KALZ,CA3CqB;;AAkDrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW;AACT,mEALJ;AAMEC,QAAQ,CAAE,KANZ,CAlDqB;;AA0DrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,mDAJf;AAKEC,QAAQ,CAAE,OALZ,CA1DqB;;AAiErB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,iCAJf;AAKEC,QAAQ,CAAE,MALZ,CAjEqB;;AAwErB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,CAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,oBAJf;AAKEC,QAAQ,CAAE,OALZ;AAMEC,MAAM,CAAE,IANV,CAxEqB;;AAgFrB;AACEL,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,6BAJf;AAKEC,QAAQ,CAAE,OALZ,CAhFqB;;AAuFrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,oBAJf;AAKEC,QAAQ,CAAE,MALZ,CAvFqB;;AA8FrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,6BAJf;AAKEC,QAAQ,CAAE,OALZ,CA9FqB;;AAqGrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,uBAJf;AAKEC,QAAQ,CAAE,OALZ,CArGqB;;AA4GrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,kBAJf;AAKEC,QAAQ,CAAE,OALZ,CA5GqB;;AAmHrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,aAJf;AAKEC,QAAQ,CAAE,MALZ,CAnHqB;;AA0HrB;AACEJ,IAAI,CAAE,WADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,8BAJf;AAKEC,QAAQ,CAAE,OALZ,CA1HqB;;AAiIrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,QAHV;AAIEC,WAAW,CAAE,8CAJf;AAKEC,QAAQ,CAAE,OALZ,CAjIqB;;AAwIrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,QAHV;AAIEC,WAAW,CAAE,8CAJf;AAKEC,QAAQ,CAAE,OALZ,CAxIqB;;AA+IrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,SAHV;AAIEC,WAAW,CAAE,UAJf;AAKEC,QAAQ,CAAE,OALZ;AAMEC,MAAM,CAAE,IANV,CA/IqB;;AAuJrB;AACEL,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,OAHV;AAIEC,WAAW,CAAE,QAJf;AAKEC,QAAQ,CAAE,OALZ;AAMEC,MAAM,CAAE,IANV,CAvJqB;;AA+JrB;AACEL,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,OAHV;AAIEC,WAAW,CAAE,oCAJf;AAKEC,QAAQ,CAAE,OALZ,CA/JqB;;AAsKrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,OAHV;AAIEC,WAAW,CAAE,+CAJf;AAKEC,QAAQ,CAAE,OALZ,CAtKqB;;AA6KrB;AACEJ,IAAI,CAAE,UADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,mCAJf;AAKEC,QAAQ,CAAE,OALZ,CA7KqB;;AAoLrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,OAHV;AAIEC,WAAW,CAAE,oDAJf;AAKEC,QAAQ,CAAE,OALZ,CApLqB;;AA2LrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,QAHV;AAIEC,WAAW,CAAE,kCAJf;AAKEC,QAAQ,CAAE,KALZ,CA3LqB;;AAkMrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,mBAJf;AAKEC,QAAQ,CAAE,KALZ,CAlMqB;;AAyMrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,cAJf;AAKEC,QAAQ,CAAE,KALZ,CAzMqB;;AAgNrB;AACEJ,IAAI,CAAE,WADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,kBAJf;AAKEC,QAAQ,CAAE,KALZ,CAhNqB;;AAuNrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,kBAJf;AAKEC,QAAQ,CAAE,KALZ,CAvNqB;;AA8NrB;AACEJ,IAAI,CAAE,UADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,QAHV;AAIEC,WAAW,CAAE,8BAJf;AAKEC,QAAQ,CAAE,KALZ,CA9NqB;;AAqOrB;AACEJ,IAAI,CAAE,OADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,kBAJf;AAKEC,QAAQ,CAAE,OALZ,CArOqB;;AA4OrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,eAJf;AAKEC,QAAQ,CAAE,OALZ,CA5OqB;;AAmPrB;AACEJ,IAAI,CAAE,SADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,QAHV;AAIEC,WAAW,CAAE,iCAJf;AAKEC,QAAQ,CAAE,OALZ,CAnPqB;;AA0PrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,6BAJf;AAKEC,QAAQ,CAAE,SALZ,CA1PqB;;AAiQrB;AACEJ,IAAI,CAAE,QADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,MAHV;AAIEC,WAAW,CAAE,qBAJf;AAKEC,QAAQ,CAAE,OALZ,CAjQqB;;AAwQrB;AACEJ,IAAI,CAAE,WADR;AAEEC,MAAM,CAAE,EAFV;AAGEC,MAAM,CAAE,WAHV;AAIEC,WAAW,CAAE,qBAJf;AAKEC,QAAQ,CAAE,OALZ,CAxQqB,CAAhB,C","sourcesContent":["/* eslint-disable max-lines */\n// List of known process signals with information about them\nexport const SIGNALS = [\n {\n name: 'SIGHUP',\n number: 1,\n action: 'terminate',\n description: 'Terminal closed',\n standard: 'posix',\n },\n {\n name: 'SIGINT',\n number: 2,\n action: 'terminate',\n description: 'User interruption with CTRL-C',\n standard: 'ansi',\n },\n {\n name: 'SIGQUIT',\n number: 3,\n action: 'core',\n description: 'User interruption with CTRL-\\\\',\n standard: 'posix',\n },\n {\n name: 'SIGILL',\n number: 4,\n action: 'core',\n description: 'Invalid machine instruction',\n standard: 'ansi',\n },\n {\n name: 'SIGTRAP',\n number: 5,\n action: 'core',\n description: 'Debugger breakpoint',\n standard: 'posix',\n },\n {\n name: 'SIGABRT',\n number: 6,\n action: 'core',\n description: 'Aborted',\n standard: 'ansi',\n },\n {\n name: 'SIGIOT',\n number: 6,\n action: 'core',\n description: 'Aborted',\n standard: 'bsd',\n },\n {\n name: 'SIGBUS',\n number: 7,\n action: 'core',\n description:\n 'Bus error due to misaligned, non-existing address or paging error',\n standard: 'bsd',\n },\n {\n name: 'SIGEMT',\n number: 7,\n action: 'terminate',\n description: 'Command should be emulated but is not implemented',\n standard: 'other',\n },\n {\n name: 'SIGFPE',\n number: 8,\n action: 'core',\n description: 'Floating point arithmetic error',\n standard: 'ansi',\n },\n {\n name: 'SIGKILL',\n number: 9,\n action: 'terminate',\n description: 'Forced termination',\n standard: 'posix',\n forced: true,\n },\n {\n name: 'SIGUSR1',\n number: 10,\n action: 'terminate',\n description: 'Application-specific signal',\n standard: 'posix',\n },\n {\n name: 'SIGSEGV',\n number: 11,\n action: 'core',\n description: 'Segmentation fault',\n standard: 'ansi',\n },\n {\n name: 'SIGUSR2',\n number: 12,\n action: 'terminate',\n description: 'Application-specific signal',\n standard: 'posix',\n },\n {\n name: 'SIGPIPE',\n number: 13,\n action: 'terminate',\n description: 'Broken pipe or socket',\n standard: 'posix',\n },\n {\n name: 'SIGALRM',\n number: 14,\n action: 'terminate',\n description: 'Timeout or timer',\n standard: 'posix',\n },\n {\n name: 'SIGTERM',\n number: 15,\n action: 'terminate',\n description: 'Termination',\n standard: 'ansi',\n },\n {\n name: 'SIGSTKFLT',\n number: 16,\n action: 'terminate',\n description: 'Stack is empty or overflowed',\n standard: 'other',\n },\n {\n name: 'SIGCHLD',\n number: 17,\n action: 'ignore',\n description: 'Child process terminated, paused or unpaused',\n standard: 'posix',\n },\n {\n name: 'SIGCLD',\n number: 17,\n action: 'ignore',\n description: 'Child process terminated, paused or unpaused',\n standard: 'other',\n },\n {\n name: 'SIGCONT',\n number: 18,\n action: 'unpause',\n description: 'Unpaused',\n standard: 'posix',\n forced: true,\n },\n {\n name: 'SIGSTOP',\n number: 19,\n action: 'pause',\n description: 'Paused',\n standard: 'posix',\n forced: true,\n },\n {\n name: 'SIGTSTP',\n number: 20,\n action: 'pause',\n description: 'Paused using CTRL-Z or \"suspend\"',\n standard: 'posix',\n },\n {\n name: 'SIGTTIN',\n number: 21,\n action: 'pause',\n description: 'Background process cannot read terminal input',\n standard: 'posix',\n },\n {\n name: 'SIGBREAK',\n number: 21,\n action: 'terminate',\n description: 'User interruption with CTRL-BREAK',\n standard: 'other',\n },\n {\n name: 'SIGTTOU',\n number: 22,\n action: 'pause',\n description: 'Background process cannot write to terminal output',\n standard: 'posix',\n },\n {\n name: 'SIGURG',\n number: 23,\n action: 'ignore',\n description: 'Socket received out-of-band data',\n standard: 'bsd',\n },\n {\n name: 'SIGXCPU',\n number: 24,\n action: 'core',\n description: 'Process timed out',\n standard: 'bsd',\n },\n {\n name: 'SIGXFSZ',\n number: 25,\n action: 'core',\n description: 'File too big',\n standard: 'bsd',\n },\n {\n name: 'SIGVTALRM',\n number: 26,\n action: 'terminate',\n description: 'Timeout or timer',\n standard: 'bsd',\n },\n {\n name: 'SIGPROF',\n number: 27,\n action: 'terminate',\n description: 'Timeout or timer',\n standard: 'bsd',\n },\n {\n name: 'SIGWINCH',\n number: 28,\n action: 'ignore',\n description: 'Terminal window size changed',\n standard: 'bsd',\n },\n {\n name: 'SIGIO',\n number: 29,\n action: 'terminate',\n description: 'I/O is available',\n standard: 'other',\n },\n {\n name: 'SIGPOLL',\n number: 29,\n action: 'terminate',\n description: 'Watched event',\n standard: 'other',\n },\n {\n name: 'SIGINFO',\n number: 29,\n action: 'ignore',\n description: 'Request for process information',\n standard: 'other',\n },\n {\n name: 'SIGPWR',\n number: 30,\n action: 'terminate',\n description: 'Device running out of power',\n standard: 'systemv',\n },\n {\n name: 'SIGSYS',\n number: 31,\n action: 'core',\n description: 'Invalid system call',\n standard: 'other',\n },\n {\n name: 'SIGUNUSED',\n number: 31,\n action: 'terminate',\n description: 'Invalid system call',\n standard: 'other',\n },\n]\n/* eslint-enable max-lines */\n"],"file":"src/core.js"} \ No newline at end of file diff --git a/node_modules/human-signals/build/src/main.d.ts b/node_modules/human-signals/build/src/main.d.ts deleted file mode 100644 index 2dc5ea78e5..0000000000 --- a/node_modules/human-signals/build/src/main.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Object whose keys are signal names and values are signal objects. - */ -export declare const signalsByName: { [signalName: string]: Signal } -/** - * Object whose keys are signal numbers and values are signal objects. - */ -export declare const signalsByNumber: { [signalNumber: string]: Signal } - -export declare type SignalAction = - | 'terminate' - | 'core' - | 'ignore' - | 'pause' - | 'unpause' -export declare type SignalStandard = - | 'ansi' - | 'posix' - | 'bsd' - | 'systemv' - | 'other' - -export declare type Signal = { - /** - * Standard name of the signal, for example 'SIGINT'. - */ - name: string - /** - * Code number of the signal, for example 2. While most number are cross-platform, some are different between different OS. - */ - number: number - /** - * Human-friendly description for the signal, for example 'User interruption with CTRL-C'. - */ - description: string - /** - * Whether the current OS can handle this signal in Node.js using process.on(name, handler). The list of supported signals is OS-specific. - */ - supported: boolean - /** - * What is the default action for this signal when it is not handled. - */ - action: SignalAction - /** - * Whether the signal's default action cannot be prevented. This is true for SIGTERM, SIGKILL and SIGSTOP. - */ - forced: boolean - /** - * Which standard defined that signal. - */ - standard: SignalStandard -} diff --git a/node_modules/human-signals/build/src/main.js b/node_modules/human-signals/build/src/main.js index 88f5fd29be..6b91fcc786 100644 --- a/node_modules/human-signals/build/src/main.js +++ b/node_modules/human-signals/build/src/main.js @@ -1,33 +1,38 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.signalsByNumber=exports.signalsByName=void 0;var _os=require("os"); +import{constants}from"node:os"; -var _signals=require("./signals.js"); -var _realtime=require("./realtime.js"); +import{SIGRTMAX}from"./realtime.js"; +import{getSignals}from"./signals.js"; const getSignalsByName=function(){ -const signals=(0,_signals.getSignals)(); -return signals.reduce(getSignalByName,{}); +const signals=getSignals(); +return Object.fromEntries(signals.map(getSignalByName)); }; -const getSignalByName=function( -signalByNameMemo, -{name,number,description,supported,action,forced,standard}) +const getSignalByName=function({ +name, +number, +description, +supported, +action, +forced, +standard}) { -return{ -...signalByNameMemo, -[name]:{name,number,description,supported,action,forced,standard}}; +return[ +name, +{name,number,description,supported,action,forced,standard}]; }; -const signalsByName=getSignalsByName();exports.signalsByName=signalsByName; +export const signalsByName=getSignalsByName(); const getSignalsByNumber=function(){ -const signals=(0,_signals.getSignals)(); -const length=_realtime.SIGRTMAX+1; +const signals=getSignals(); +const length=SIGRTMAX+1; const signalsA=Array.from({length},(value,number)=> getSignalByNumber(number,signals)); @@ -58,14 +63,14 @@ standard}}; const findSignalByNumber=function(number,signals){ -const signal=signals.find(({name})=>_os.constants.signals[name]===number); +const signal=signals.find(({name})=>constants.signals[name]===number); if(signal!==undefined){ return signal; } -return signals.find(signalA=>signalA.number===number); +return signals.find((signalA)=>signalA.number===number); }; -const signalsByNumber=getSignalsByNumber();exports.signalsByNumber=signalsByNumber; +export const signalsByNumber=getSignalsByNumber(); //# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/node_modules/human-signals/build/src/main.js.map b/node_modules/human-signals/build/src/main.js.map deleted file mode 100644 index 3fdcede941..0000000000 --- a/node_modules/human-signals/build/src/main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../../src/main.js"],"names":["getSignalsByName","signals","reduce","getSignalByName","signalByNameMemo","name","number","description","supported","action","forced","standard","signalsByName","getSignalsByNumber","length","SIGRTMAX","signalsA","Array","from","value","getSignalByNumber","Object","assign","signal","findSignalByNumber","undefined","find","constants","signalA","signalsByNumber"],"mappings":"2HAAA;;AAEA;AACA;;;;AAIA,KAAMA,CAAAA,gBAAgB,CAAG,UAAW;AAClC,KAAMC,CAAAA,OAAO,CAAG,yBAAhB;AACA,MAAOA,CAAAA,OAAO,CAACC,MAAR,CAAeC,eAAf,CAAgC,EAAhC,CAAP;AACD,CAHD;;AAKA,KAAMA,CAAAA,eAAe,CAAG;AACtBC,gBADsB;AAEtB,CAAEC,IAAF,CAAQC,MAAR,CAAgBC,WAAhB,CAA6BC,SAA7B,CAAwCC,MAAxC,CAAgDC,MAAhD,CAAwDC,QAAxD,CAFsB;AAGtB;AACA,MAAO;AACL,GAAGP,gBADE;AAEL,CAACC,IAAD,EAAQ,CAAEA,IAAF,CAAQC,MAAR,CAAgBC,WAAhB,CAA6BC,SAA7B,CAAwCC,MAAxC,CAAgDC,MAAhD,CAAwDC,QAAxD,CAFH,CAAP;;AAID,CARD;;AAUO,KAAMC,CAAAA,aAAa,CAAGZ,gBAAgB,EAAtC,C;;;;;AAKP,KAAMa,CAAAA,kBAAkB,CAAG,UAAW;AACpC,KAAMZ,CAAAA,OAAO,CAAG,yBAAhB;AACA,KAAMa,CAAAA,MAAM,CAAGC,mBAAW,CAA1B;AACA,KAAMC,CAAAA,QAAQ,CAAGC,KAAK,CAACC,IAAN,CAAW,CAAEJ,MAAF,CAAX,CAAuB,CAACK,KAAD,CAAQb,MAAR;AACtCc,iBAAiB,CAACd,MAAD,CAASL,OAAT,CADF,CAAjB;;AAGA,MAAOoB,CAAAA,MAAM,CAACC,MAAP,CAAc,EAAd,CAAkB,GAAGN,QAArB,CAAP;AACD,CAPD;;AASA,KAAMI,CAAAA,iBAAiB,CAAG,SAASd,MAAT,CAAiBL,OAAjB,CAA0B;AAClD,KAAMsB,CAAAA,MAAM,CAAGC,kBAAkB,CAAClB,MAAD,CAASL,OAAT,CAAjC;;AAEA,GAAIsB,MAAM,GAAKE,SAAf,CAA0B;AACxB,MAAO,EAAP;AACD;;AAED,KAAM,CAAEpB,IAAF,CAAQE,WAAR,CAAqBC,SAArB,CAAgCC,MAAhC,CAAwCC,MAAxC,CAAgDC,QAAhD,EAA6DY,MAAnE;AACA,MAAO;AACL,CAACjB,MAAD,EAAU;AACRD,IADQ;AAERC,MAFQ;AAGRC,WAHQ;AAIRC,SAJQ;AAKRC,MALQ;AAMRC,MANQ;AAORC,QAPQ,CADL,CAAP;;;AAWD,CAnBD;;;;AAuBA,KAAMa,CAAAA,kBAAkB,CAAG,SAASlB,MAAT,CAAiBL,OAAjB,CAA0B;AACnD,KAAMsB,CAAAA,MAAM,CAAGtB,OAAO,CAACyB,IAAR,CAAa,CAAC,CAAErB,IAAF,CAAD,GAAcsB,cAAU1B,OAAV,CAAkBI,IAAlB,IAA4BC,MAAvD,CAAf;;AAEA,GAAIiB,MAAM,GAAKE,SAAf,CAA0B;AACxB,MAAOF,CAAAA,MAAP;AACD;;AAED,MAAOtB,CAAAA,OAAO,CAACyB,IAAR,CAAaE,OAAO,EAAIA,OAAO,CAACtB,MAAR,GAAmBA,MAA3C,CAAP;AACD,CARD;;AAUO,KAAMuB,CAAAA,eAAe,CAAGhB,kBAAkB,EAA1C,C","sourcesContent":["import { constants } from 'os'\n\nimport { getSignals } from './signals.js'\nimport { SIGRTMAX } from './realtime.js'\n\n// Retrieve `signalsByName`, an object mapping signal name to signal properties.\n// We make sure the object is sorted by `number`.\nconst getSignalsByName = function() {\n const signals = getSignals()\n return signals.reduce(getSignalByName, {})\n}\n\nconst getSignalByName = function(\n signalByNameMemo,\n { name, number, description, supported, action, forced, standard },\n) {\n return {\n ...signalByNameMemo,\n [name]: { name, number, description, supported, action, forced, standard },\n }\n}\n\nexport const signalsByName = getSignalsByName()\n\n// Retrieve `signalsByNumber`, an object mapping signal number to signal\n// properties.\n// We make sure the object is sorted by `number`.\nconst getSignalsByNumber = function() {\n const signals = getSignals()\n const length = SIGRTMAX + 1\n const signalsA = Array.from({ length }, (value, number) =>\n getSignalByNumber(number, signals),\n )\n return Object.assign({}, ...signalsA)\n}\n\nconst getSignalByNumber = function(number, signals) {\n const signal = findSignalByNumber(number, signals)\n\n if (signal === undefined) {\n return {}\n }\n\n const { name, description, supported, action, forced, standard } = signal\n return {\n [number]: {\n name,\n number,\n description,\n supported,\n action,\n forced,\n standard,\n },\n }\n}\n\n// Several signals might end up sharing the same number because of OS-specific\n// numbers, in which case those prevail.\nconst findSignalByNumber = function(number, signals) {\n const signal = signals.find(({ name }) => constants.signals[name] === number)\n\n if (signal !== undefined) {\n return signal\n }\n\n return signals.find(signalA => signalA.number === number)\n}\n\nexport const signalsByNumber = getSignalsByNumber()\n"],"file":"src/main.js"} \ No newline at end of file diff --git a/node_modules/human-signals/build/src/realtime.js b/node_modules/human-signals/build/src/realtime.js index f665516fd0..16a6627072 100644 --- a/node_modules/human-signals/build/src/realtime.js +++ b/node_modules/human-signals/build/src/realtime.js @@ -1,8 +1,8 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.SIGRTMAX=exports.getRealtimeSignals=void 0; -const getRealtimeSignals=function(){ + +export const getRealtimeSignals=function(){ const length=SIGRTMAX-SIGRTMIN+1; return Array.from({length},getRealtimeSignal); -};exports.getRealtimeSignals=getRealtimeSignals; +}; const getRealtimeSignal=function(value,index){ return{ @@ -15,5 +15,5 @@ standard:"posix"}; }; const SIGRTMIN=34; -const SIGRTMAX=64;exports.SIGRTMAX=SIGRTMAX; +export const SIGRTMAX=64; //# sourceMappingURL=realtime.js.map \ No newline at end of file diff --git a/node_modules/human-signals/build/src/realtime.js.map b/node_modules/human-signals/build/src/realtime.js.map deleted file mode 100644 index 808bbd12f7..0000000000 --- a/node_modules/human-signals/build/src/realtime.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../../src/realtime.js"],"names":["getRealtimeSignals","length","SIGRTMAX","SIGRTMIN","Array","from","getRealtimeSignal","value","index","name","number","action","description","standard"],"mappings":";AACO,KAAMA,CAAAA,kBAAkB,CAAG,UAAW;AAC3C,KAAMC,CAAAA,MAAM,CAAGC,QAAQ,CAAGC,QAAX,CAAsB,CAArC;AACA,MAAOC,CAAAA,KAAK,CAACC,IAAN,CAAW,CAAEJ,MAAF,CAAX,CAAuBK,iBAAvB,CAAP;AACD,CAHM,C;;AAKP,KAAMA,CAAAA,iBAAiB,CAAG,SAASC,KAAT,CAAgBC,KAAhB,CAAuB;AAC/C,MAAO;AACLC,IAAI,CAAG,QAAOD,KAAK,CAAG,CAAE,EADnB;AAELE,MAAM,CAAEP,QAAQ,CAAGK,KAFd;AAGLG,MAAM,CAAE,WAHH;AAILC,WAAW,CAAE,wCAJR;AAKLC,QAAQ,CAAE,OALL,CAAP;;AAOD,CARD;;AAUA,KAAMV,CAAAA,QAAQ,CAAG,EAAjB;AACO,KAAMD,CAAAA,QAAQ,CAAG,EAAjB,C","sourcesContent":["// List of realtime signals with information about them\nexport const getRealtimeSignals = function() {\n const length = SIGRTMAX - SIGRTMIN + 1\n return Array.from({ length }, getRealtimeSignal)\n}\n\nconst getRealtimeSignal = function(value, index) {\n return {\n name: `SIGRT${index + 1}`,\n number: SIGRTMIN + index,\n action: 'terminate',\n description: 'Application-specific signal (realtime)',\n standard: 'posix',\n }\n}\n\nconst SIGRTMIN = 34\nexport const SIGRTMAX = 64\n"],"file":"src/realtime.js"} \ No newline at end of file diff --git a/node_modules/human-signals/build/src/signals.js b/node_modules/human-signals/build/src/signals.js index ab3b387d91..60f6b2f65f 100644 --- a/node_modules/human-signals/build/src/signals.js +++ b/node_modules/human-signals/build/src/signals.js @@ -1,15 +1,15 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.getSignals=void 0;var _os=require("os"); +import{constants}from"node:os"; -var _core=require("./core.js"); -var _realtime=require("./realtime.js"); +import{SIGNALS}from"./core.js"; +import{getRealtimeSignals}from"./realtime.js"; -const getSignals=function(){ -const realtimeSignals=(0,_realtime.getRealtimeSignals)(); -const signals=[..._core.SIGNALS,...realtimeSignals].map(normalizeSignal); +export const getSignals=function(){ +const realtimeSignals=getRealtimeSignals(); +const signals=[...SIGNALS,...realtimeSignals].map(normalizeSignal); return signals; -};exports.getSignals=getSignals; +}; @@ -27,7 +27,7 @@ standard}) { const{ signals:{[name]:constantSignal}}= -_os.constants; +constants; const supported=constantSignal!==undefined; const number=supported?constantSignal:defaultNumber; return{name,number,description,supported,action,forced,standard}; diff --git a/node_modules/human-signals/build/src/signals.js.map b/node_modules/human-signals/build/src/signals.js.map deleted file mode 100644 index 2a6b919ecf..0000000000 --- a/node_modules/human-signals/build/src/signals.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../../src/signals.js"],"names":["getSignals","realtimeSignals","signals","SIGNALS","map","normalizeSignal","name","number","defaultNumber","description","action","forced","standard","constantSignal","constants","supported","undefined"],"mappings":"gGAAA;;AAEA;AACA;;;;AAIO,KAAMA,CAAAA,UAAU,CAAG,UAAW;AACnC,KAAMC,CAAAA,eAAe,CAAG,kCAAxB;AACA,KAAMC,CAAAA,OAAO,CAAG,CAAC,GAAGC,aAAJ,CAAa,GAAGF,eAAhB,EAAiCG,GAAjC,CAAqCC,eAArC,CAAhB;AACA,MAAOH,CAAAA,OAAP;AACD,CAJM,C;;;;;;;;AAYP,KAAMG,CAAAA,eAAe,CAAG,SAAS;AAC/BC,IAD+B;AAE/BC,MAAM,CAAEC,aAFuB;AAG/BC,WAH+B;AAI/BC,MAJ+B;AAK/BC,MAAM,CAAG,KALsB;AAM/BC,QAN+B,CAAT;AAOrB;AACD,KAAM;AACJV,OAAO,CAAE,CAAE,CAACI,IAAD,EAAQO,cAAV,CADL;AAEFC,aAFJ;AAGA,KAAMC,CAAAA,SAAS,CAAGF,cAAc,GAAKG,SAArC;AACA,KAAMT,CAAAA,MAAM,CAAGQ,SAAS,CAAGF,cAAH,CAAoBL,aAA5C;AACA,MAAO,CAAEF,IAAF,CAAQC,MAAR,CAAgBE,WAAhB,CAA6BM,SAA7B,CAAwCL,MAAxC,CAAgDC,MAAhD,CAAwDC,QAAxD,CAAP;AACD,CAdD","sourcesContent":["import { constants } from 'os'\n\nimport { SIGNALS } from './core.js'\nimport { getRealtimeSignals } from './realtime.js'\n\n// Retrieve list of know signals (including realtime) with information about\n// them\nexport const getSignals = function() {\n const realtimeSignals = getRealtimeSignals()\n const signals = [...SIGNALS, ...realtimeSignals].map(normalizeSignal)\n return signals\n}\n\n// Normalize signal:\n// - `number`: signal numbers are OS-specific. This is taken into account by\n// `os.constants.signals`. However we provide a default `number` since some\n// signals are not defined for some OS.\n// - `forced`: set default to `false`\n// - `supported`: set value\nconst normalizeSignal = function({\n name,\n number: defaultNumber,\n description,\n action,\n forced = false,\n standard,\n}) {\n const {\n signals: { [name]: constantSignal },\n } = constants\n const supported = constantSignal !== undefined\n const number = supported ? constantSignal : defaultNumber\n return { name, number, description, supported, action, forced, standard }\n}\n"],"file":"src/signals.js"} \ No newline at end of file diff --git a/node_modules/human-signals/build/types/main.d.ts b/node_modules/human-signals/build/types/main.d.ts new file mode 100644 index 0000000000..a0724ae923 --- /dev/null +++ b/node_modules/human-signals/build/types/main.d.ts @@ -0,0 +1,73 @@ +/** + * What is the default action for this signal when it is not handled. + */ +export type SignalAction = 'terminate' | 'core' | 'ignore' | 'pause' | 'unpause' + +/** + * Which standard defined that signal. + */ +export type SignalStandard = 'ansi' | 'posix' | 'bsd' | 'systemv' | 'other' + +/** + * Standard name of the signal, for example 'SIGINT'. + */ +export type SignalName = `SIG${string}` + +/** + * Code number of the signal, for example 2. + * While most number are cross-platform, some are different between different + * OS. + */ +export type SignalNumber = number + +export type Signal = { + /** + * Standard name of the signal, for example 'SIGINT'. + */ + name: SignalName + + /** + * Code number of the signal, for example 2. + * While most number are cross-platform, some are different between different + * OS. + */ + number: SignalNumber + + /** + * Human-friendly description for the signal, for example + * 'User interruption with CTRL-C'. + */ + description: string + + /** + * Whether the current OS can handle this signal in Node.js using + * `process.on(name, handler)`. The list of supported signals is OS-specific. + */ + supported: boolean + + /** + * What is the default action for this signal when it is not handled. + */ + action: SignalAction + + /** + * Whether the signal's default action cannot be prevented. + * This is true for SIGTERM, SIGKILL and SIGSTOP. + */ + forced: boolean + + /** + * Which standard defined that signal. + */ + standard: SignalStandard +} + +/** + * Object whose keys are signal names and values are signal objects. + */ +export declare const signalsByName: { [signalName: SignalName]: Signal } + +/** + * Object whose keys are signal numbers and values are signal objects. + */ +export declare const signalsByNumber: { [signalNumber: SignalNumber]: Signal } diff --git a/node_modules/human-signals/package.json b/node_modules/human-signals/package.json index fd1d0274f6..fd5df7f0d0 100644 --- a/node_modules/human-signals/package.json +++ b/node_modules/human-signals/package.json @@ -1,26 +1,27 @@ { "name": "human-signals", - "version": "2.1.0", - "main": "build/src/main.js", + "version": "4.3.0", + "type": "module", + "exports": { + "types": "./build/types/main.d.ts", + "default": "./build/src/main.js" + }, + "main": "./build/src/main.js", + "types": "./build/types/main.d.ts", "files": [ - "build/src", - "!~" + "build/src/**/*.{js,json}", + "build/types/**/*.d.ts" ], + "sideEffects": false, "scripts": { "test": "gulp test" }, - "husky": { - "hooks": { - "pre-push": "gulp check --full" - } - }, "description": "Human-friendly process signals", "keywords": [ "signal", "signals", "handlers", "error-handling", - "errors", "interrupts", "sigterm", "sigint", @@ -32,13 +33,14 @@ "operating-system", "es6", "javascript", + "typescript", "linux", "macos", "windows", "nodejs" ], "license": "Apache-2.0", - "homepage": "https://git.io/JeluP", + "homepage": "https://www.github.com/ehmicky/human-signals", "repository": "ehmicky/human-signals", "bugs": { "url": "https://github.com/ehmicky/human-signals/issues" @@ -48,17 +50,12 @@ "lib": "src", "test": "test" }, - "types": "build/src/main.d.ts", - "dependencies": {}, "devDependencies": { - "@ehmicky/dev-tasks": "^0.31.9", - "ajv": "^6.12.0", - "ava": "^3.5.0", - "gulp": "^4.0.2", - "husky": "^4.2.3", - "test-each": "^2.0.0" + "@ehmicky/dev-tasks": "^1.0.102", + "ajv": "^8.11.0", + "test-each": "^5.5.0" }, "engines": { - "node": ">=10.17.0" + "node": ">=14.18.0" } } diff --git a/node_modules/is-stream/index.d.ts b/node_modules/is-stream/index.d.ts index eee2e83e81..df994e096a 100644 --- a/node_modules/is-stream/index.d.ts +++ b/node_modules/is-stream/index.d.ts @@ -1,79 +1,81 @@ -import * as stream from 'stream'; - -declare const isStream: { - /** - @returns Whether `stream` is a [`Stream`](https://nodejs.org/api/stream.html#stream_stream). - - @example - ``` - import * as fs from 'fs'; - import isStream = require('is-stream'); - - isStream(fs.createReadStream('unicorn.png')); - //=> true - - isStream({}); - //=> false - ``` - */ - (stream: unknown): stream is stream.Stream; - - /** - @returns Whether `stream` is a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable). - - @example - ``` - import * as fs from 'fs'; - import isStream = require('is-stream'); - - isStream.writable(fs.createWriteStrem('unicorn.txt')); - //=> true - ``` - */ - writable(stream: unknown): stream is stream.Writable; - - /** - @returns Whether `stream` is a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable). - - @example - ``` - import * as fs from 'fs'; - import isStream = require('is-stream'); - - isStream.readable(fs.createReadStream('unicorn.png')); - //=> true - ``` - */ - readable(stream: unknown): stream is stream.Readable; - - /** - @returns Whether `stream` is a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex). - - @example - ``` - import {Duplex} from 'stream'; - import isStream = require('is-stream'); - - isStream.duplex(new Duplex()); - //=> true - ``` - */ - duplex(stream: unknown): stream is stream.Duplex; - - /** - @returns Whether `stream` is a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform). - - @example - ``` - import * as fs from 'fs'; - import Stringify = require('streaming-json-stringify'); - import isStream = require('is-stream'); - - isStream.transform(Stringify()); - //=> true - ``` - */ - transform(input: unknown): input is stream.Transform; -}; - -export = isStream; +import { + Stream, + Writable as WritableStream, + Readable as ReadableStream, + Duplex as DuplexStream, + Transform as TransformStream, +} from 'node:stream'; + +/** +@returns Whether `stream` is a [`Stream`](https://nodejs.org/api/stream.html#stream_stream). + +@example +``` +import fs from 'node:fs'; +import {isStream} from 'is-stream'; + +isStream(fs.createReadStream('unicorn.png')); +//=> true + +isStream({}); +//=> false +``` +*/ +export function isStream(stream: unknown): stream is Stream; + +/** +@returns Whether `stream` is a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable). + +@example +``` +import fs from 'node:fs'; +import {isWritableStream} from 'is-stream'; + +isWritableStream(fs.createWriteStrem('unicorn.txt')); +//=> true +``` +*/ +export function isWritableStream(stream: unknown): stream is WritableStream; + +/** +@returns Whether `stream` is a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable). + +@example +``` +import fs from 'node:fs'; +import {isReadableStream} from 'is-stream'; + +isReadableStream(fs.createReadStream('unicorn.png')); +//=> true +``` +*/ +export function isReadableStream(stream: unknown): stream is ReadableStream; + +/** +@returns Whether `stream` is a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex). + +@example +``` +import {Duplex as DuplexStream} from 'node:stream'; +import {isDuplexStream} from 'is-stream'; + +isDuplexStream(new DuplexStream()); +//=> true +``` +*/ +export function isDuplexStream(stream: unknown): stream is DuplexStream; + +/** +@returns Whether `stream` is a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform). + +@example +``` +import fs from 'node:fs'; +import StringifyStream from 'streaming-json-stringify'; +import {isTransformStream} from 'is-stream'; + +isTransformStream(StringifyStream()); +//=> true +``` +*/ +export function isTransformStream(stream: unknown): stream is TransformStream; diff --git a/node_modules/is-stream/index.js b/node_modules/is-stream/index.js index 2e43434daa..887e601e02 100644 --- a/node_modules/is-stream/index.js +++ b/node_modules/is-stream/index.js @@ -1,28 +1,29 @@ -'use strict'; +export function isStream(stream) { + return stream !== null + && typeof stream === 'object' + && typeof stream.pipe === 'function'; +} -const isStream = stream => - stream !== null && - typeof stream === 'object' && - typeof stream.pipe === 'function'; +export function isWritableStream(stream) { + return isStream(stream) + && stream.writable !== false + && typeof stream._write === 'function' + && typeof stream._writableState === 'object'; +} -isStream.writable = stream => - isStream(stream) && - stream.writable !== false && - typeof stream._write === 'function' && - typeof stream._writableState === 'object'; +export function isReadableStream(stream) { + return isStream(stream) + && stream.readable !== false + && typeof stream._read === 'function' + && typeof stream._readableState === 'object'; +} -isStream.readable = stream => - isStream(stream) && - stream.readable !== false && - typeof stream._read === 'function' && - typeof stream._readableState === 'object'; +export function isDuplexStream(stream) { + return isWritableStream(stream) + && isReadableStream(stream); +} -isStream.duplex = stream => - isStream.writable(stream) && - isStream.readable(stream); - -isStream.transform = stream => - isStream.duplex(stream) && - typeof stream._transform === 'function'; - -module.exports = isStream; +export function isTransformStream(stream) { + return isDuplexStream(stream) + && typeof stream._transform === 'function'; +} diff --git a/node_modules/is-stream/package.json b/node_modules/is-stream/package.json index 9b68e6ae2d..e970c7296e 100644 --- a/node_modules/is-stream/package.json +++ b/node_modules/is-stream/package.json @@ -1,6 +1,6 @@ { "name": "is-stream", - "version": "2.0.1", + "version": "3.0.0", "description": "Check if something is a Node.js stream", "license": "MIT", "repository": "sindresorhus/is-stream", @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" @@ -33,10 +35,10 @@ "is" ], "devDependencies": { - "@types/node": "^11.13.6", - "ava": "^1.4.1", - "tempy": "^0.3.0", - "tsd": "^0.7.2", - "xo": "^0.24.0" + "@types/node": "^16.4.13", + "ava": "^3.15.0", + "tempy": "^1.0.1", + "tsd": "^0.17.0", + "xo": "^0.44.0" } } diff --git a/node_modules/is-stream/readme.md b/node_modules/is-stream/readme.md index 19308e7335..c6f8c1b2cb 100644 --- a/node_modules/is-stream/readme.md +++ b/node_modules/is-stream/readme.md @@ -11,8 +11,8 @@ $ npm install is-stream ## Usage ```js -const fs = require('fs'); -const isStream = require('is-stream'); +import fs from 'node:fs'; +import {isStream} from 'is-stream'; isStream(fs.createReadStream('unicorn.png')); //=> true @@ -27,19 +27,19 @@ isStream({}); Returns a `boolean` for whether it's a [`Stream`](https://nodejs.org/api/stream.html#stream_stream). -#### isStream.writable(stream) +#### isWritableStream(stream) Returns a `boolean` for whether it's a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable). -#### isStream.readable(stream) +#### isReadableStream(stream) Returns a `boolean` for whether it's a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable). -#### isStream.duplex(stream) +#### isDuplexStream(stream) Returns a `boolean` for whether it's a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex). -#### isStream.transform(stream) +#### isTransformStream(stream) Returns a `boolean` for whether it's a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform). diff --git a/node_modules/mem/node_modules/mimic-fn/index.d.ts b/node_modules/mem/node_modules/mimic-fn/index.d.ts deleted file mode 100644 index 2a72e0a565..0000000000 --- a/node_modules/mem/node_modules/mimic-fn/index.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -export interface Options { - /** - Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error. - - @default false - */ - readonly ignoreNonConfigurable?: boolean; -} - -/** -Modifies the `to` function to mimic the `from` function. Returns the `to` function. - -`name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied. - -`to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment. - -@param to - Mimicking function. -@param from - Function to mimic. -@returns The modified `to` function. - -@example -``` -import mimicFunction from 'mimic-fn'; - -function foo() {} -foo.unicorn = '🦄'; - -function wrapper() { - return foo(); -} - -console.log(wrapper.name); -//=> 'wrapper' - -mimicFunction(wrapper, foo); - -console.log(wrapper.name); -//=> 'foo' - -console.log(wrapper.unicorn); -//=> '🦄' -``` -*/ -export default function mimicFunction< - ArgumentsType extends unknown[], - ReturnType, - FunctionType extends (...arguments: ArgumentsType) => ReturnType ->( - to: (...arguments: ArgumentsType) => ReturnType, - from: FunctionType, - options?: Options, -): FunctionType; diff --git a/node_modules/mem/node_modules/mimic-fn/index.js b/node_modules/mem/node_modules/mimic-fn/index.js deleted file mode 100644 index bc9ef7d566..0000000000 --- a/node_modules/mem/node_modules/mimic-fn/index.js +++ /dev/null @@ -1,71 +0,0 @@ -const copyProperty = (to, from, property, ignoreNonConfigurable) => { - // `Function#length` should reflect the parameters of `to` not `from` since we keep its body. - // `Function#prototype` is non-writable and non-configurable so can never be modified. - if (property === 'length' || property === 'prototype') { - return; - } - - // `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here. - if (property === 'arguments' || property === 'caller') { - return; - } - - const toDescriptor = Object.getOwnPropertyDescriptor(to, property); - const fromDescriptor = Object.getOwnPropertyDescriptor(from, property); - - if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) { - return; - } - - Object.defineProperty(to, property, fromDescriptor); -}; - -// `Object.defineProperty()` throws if the property exists, is not configurable and either: -// - one its descriptors is changed -// - it is non-writable and its value is changed -const canCopyProperty = function (toDescriptor, fromDescriptor) { - return toDescriptor === undefined || toDescriptor.configurable || ( - toDescriptor.writable === fromDescriptor.writable && - toDescriptor.enumerable === fromDescriptor.enumerable && - toDescriptor.configurable === fromDescriptor.configurable && - (toDescriptor.writable || toDescriptor.value === fromDescriptor.value) - ); -}; - -const changePrototype = (to, from) => { - const fromPrototype = Object.getPrototypeOf(from); - if (fromPrototype === Object.getPrototypeOf(to)) { - return; - } - - Object.setPrototypeOf(to, fromPrototype); -}; - -const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`; - -const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString'); -const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name'); - -// We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected. -// We use `bind()` instead of a closure for the same reason. -// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times. -const changeToString = (to, from, name) => { - const withName = name === '' ? '' : `with ${name.trim()}() `; - const newToString = wrappedToString.bind(null, withName, from.toString()); - // Ensure `to.toString.toString` is non-enumerable and has the same `same` - Object.defineProperty(newToString, 'name', toStringName); - Object.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString}); -}; - -export default function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) { - const {name} = to; - - for (const property of Reflect.ownKeys(from)) { - copyProperty(to, from, property, ignoreNonConfigurable); - } - - changePrototype(to, from); - changeToString(to, from, name); - - return to; -} diff --git a/node_modules/mem/node_modules/mimic-fn/readme.md b/node_modules/mem/node_modules/mimic-fn/readme.md deleted file mode 100644 index 9f571cea2f..0000000000 --- a/node_modules/mem/node_modules/mimic-fn/readme.md +++ /dev/null @@ -1,90 +0,0 @@ -mimic-fn -
- -> Make a function mimic another one - -Useful when you wrap a function in another function and like to preserve the original name and other properties. - -## Install - -``` -$ npm install mimic-fn -``` - -## Usage - -```js -import mimicFunction from 'mimic-fn'; - -function foo() {} -foo.unicorn = '🦄'; - -function wrapper() { - return foo(); -} - -console.log(wrapper.name); -//=> 'wrapper' - -mimicFunction(wrapper, foo); - -console.log(wrapper.name); -//=> 'foo' - -console.log(wrapper.unicorn); -//=> '🦄' - -console.log(String(wrapper)); -//=> '/* Wrapped with wrapper() */\nfunction foo() {}' -``` - - -## API - -### mimicFunction(to, from, options?) - -Modifies the `to` function to mimic the `from` function. Returns the `to` function. - -`name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied. - -`to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment. - -#### to - -Type: `Function` - -Mimicking function. - -#### from - -Type: `Function` - -Function to mimic. - -#### options - -Type: `object` - -##### ignoreNonConfigurable - -Type: `boolean`\ -Default: `false` - -Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error. - -## Related - -- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function -- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name and other properties - ---- - -
- - Get professional support for this package with a Tidelift subscription - -
- - Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. -
-
diff --git a/node_modules/mimic-fn/index.d.ts b/node_modules/mimic-fn/index.d.ts index b4047d5890..2a72e0a565 100644 --- a/node_modules/mimic-fn/index.d.ts +++ b/node_modules/mimic-fn/index.d.ts @@ -1,54 +1,52 @@ -declare const mimicFn: { +export interface Options { /** - Make a function mimic another one. It will copy over the properties `name`, `length`, `displayName`, and any custom properties you may have set. + Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error. - @param to - Mimicking function. - @param from - Function to mimic. - @returns The modified `to` function. + @default false + */ + readonly ignoreNonConfigurable?: boolean; +} - @example - ``` - import mimicFn = require('mimic-fn'); +/** +Modifies the `to` function to mimic the `from` function. Returns the `to` function. - function foo() {} - foo.unicorn = '🦄'; +`name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied. - function wrapper() { - return foo(); - } +`to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment. - console.log(wrapper.name); - //=> 'wrapper' +@param to - Mimicking function. +@param from - Function to mimic. +@returns The modified `to` function. - mimicFn(wrapper, foo); +@example +``` +import mimicFunction from 'mimic-fn'; - console.log(wrapper.name); - //=> 'foo' +function foo() {} +foo.unicorn = '🦄'; - console.log(wrapper.unicorn); - //=> '🦄' - ``` - */ - < - ArgumentsType extends unknown[], - ReturnType, - FunctionType extends (...arguments: ArgumentsType) => ReturnType - >( - to: (...arguments: ArgumentsType) => ReturnType, - from: FunctionType - ): FunctionType; - - // TODO: Remove this for the next major release, refactor the whole definition to: - // declare function mimicFn< - // ArgumentsType extends unknown[], - // ReturnType, - // FunctionType extends (...arguments: ArgumentsType) => ReturnType - // >( - // to: (...arguments: ArgumentsType) => ReturnType, - // from: FunctionType - // ): FunctionType; - // export = mimicFn; - default: typeof mimicFn; -}; - -export = mimicFn; +function wrapper() { + return foo(); +} + +console.log(wrapper.name); +//=> 'wrapper' + +mimicFunction(wrapper, foo); + +console.log(wrapper.name); +//=> 'foo' + +console.log(wrapper.unicorn); +//=> '🦄' +``` +*/ +export default function mimicFunction< + ArgumentsType extends unknown[], + ReturnType, + FunctionType extends (...arguments: ArgumentsType) => ReturnType +>( + to: (...arguments: ArgumentsType) => ReturnType, + from: FunctionType, + options?: Options, +): FunctionType; diff --git a/node_modules/mimic-fn/index.js b/node_modules/mimic-fn/index.js index 1a59705175..bc9ef7d566 100644 --- a/node_modules/mimic-fn/index.js +++ b/node_modules/mimic-fn/index.js @@ -1,13 +1,71 @@ -'use strict'; +const copyProperty = (to, from, property, ignoreNonConfigurable) => { + // `Function#length` should reflect the parameters of `to` not `from` since we keep its body. + // `Function#prototype` is non-writable and non-configurable so can never be modified. + if (property === 'length' || property === 'prototype') { + return; + } -const mimicFn = (to, from) => { - for (const prop of Reflect.ownKeys(from)) { - Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop)); + // `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here. + if (property === 'arguments' || property === 'caller') { + return; } - return to; + const toDescriptor = Object.getOwnPropertyDescriptor(to, property); + const fromDescriptor = Object.getOwnPropertyDescriptor(from, property); + + if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) { + return; + } + + Object.defineProperty(to, property, fromDescriptor); +}; + +// `Object.defineProperty()` throws if the property exists, is not configurable and either: +// - one its descriptors is changed +// - it is non-writable and its value is changed +const canCopyProperty = function (toDescriptor, fromDescriptor) { + return toDescriptor === undefined || toDescriptor.configurable || ( + toDescriptor.writable === fromDescriptor.writable && + toDescriptor.enumerable === fromDescriptor.enumerable && + toDescriptor.configurable === fromDescriptor.configurable && + (toDescriptor.writable || toDescriptor.value === fromDescriptor.value) + ); +}; + +const changePrototype = (to, from) => { + const fromPrototype = Object.getPrototypeOf(from); + if (fromPrototype === Object.getPrototypeOf(to)) { + return; + } + + Object.setPrototypeOf(to, fromPrototype); +}; + +const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`; + +const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString'); +const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name'); + +// We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected. +// We use `bind()` instead of a closure for the same reason. +// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times. +const changeToString = (to, from, name) => { + const withName = name === '' ? '' : `with ${name.trim()}() `; + const newToString = wrappedToString.bind(null, withName, from.toString()); + // Ensure `to.toString.toString` is non-enumerable and has the same `same` + Object.defineProperty(newToString, 'name', toStringName); + Object.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString}); }; -module.exports = mimicFn; -// TODO: Remove this for the next major release -module.exports.default = mimicFn; +export default function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) { + const {name} = to; + + for (const property of Reflect.ownKeys(from)) { + copyProperty(to, from, property, ignoreNonConfigurable); + } + + changePrototype(to, from); + changeToString(to, from, name); + + return to; +} diff --git a/node_modules/mimic-fn/license b/node_modules/mimic-fn/license index e7af2f7710..fa7ceba3eb 100644 --- a/node_modules/mimic-fn/license +++ b/node_modules/mimic-fn/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/node_modules/mimic-fn/package.json b/node_modules/mimic-fn/package.json index 5c00a5ae07..edf1918fe5 100644 --- a/node_modules/mimic-fn/package.json +++ b/node_modules/mimic-fn/package.json @@ -1,16 +1,19 @@ { "name": "mimic-fn", - "version": "2.1.0", + "version": "4.0.0", "description": "Make a function mimic another one", "license": "MIT", "repository": "sindresorhus/mimic-fn", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=6" + "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" @@ -35,8 +38,8 @@ "change" ], "devDependencies": { - "ava": "^1.4.1", - "tsd": "^0.7.1", - "xo": "^0.24.0" + "ava": "^3.15.0", + "tsd": "^0.14.0", + "xo": "^0.38.2" } } diff --git a/node_modules/mimic-fn/readme.md b/node_modules/mimic-fn/readme.md index 0ef8a13d7e..9f571cea2f 100644 --- a/node_modules/mimic-fn/readme.md +++ b/node_modules/mimic-fn/readme.md @@ -1,21 +1,20 @@ -# mimic-fn [![Build Status](https://travis-ci.org/sindresorhus/mimic-fn.svg?branch=master)](https://travis-ci.org/sindresorhus/mimic-fn) +mimic-fn +
> Make a function mimic another one Useful when you wrap a function in another function and like to preserve the original name and other properties. - ## Install ``` $ npm install mimic-fn ``` - ## Usage ```js -const mimicFn = require('mimic-fn'); +import mimicFunction from 'mimic-fn'; function foo() {} foo.unicorn = '🦄'; @@ -27,23 +26,28 @@ function wrapper() { console.log(wrapper.name); //=> 'wrapper' -mimicFn(wrapper, foo); +mimicFunction(wrapper, foo); console.log(wrapper.name); //=> 'foo' console.log(wrapper.unicorn); //=> '🦄' + +console.log(String(wrapper)); +//=> '/* Wrapped with wrapper() */\nfunction foo() {}' ``` ## API -It will copy over the properties `name`, `length`, `displayName`, and any custom properties you may have set. +### mimicFunction(to, from, options?) -### mimicFn(to, from) +Modifies the `to` function to mimic the `from` function. Returns the `to` function. -Modifies the `to` function and returns it. +`name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied. + +`to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment. #### to @@ -57,13 +61,30 @@ Type: `Function` Function to mimic. +#### options -## Related +Type: `object` -- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function -- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name, length and other properties +##### ignoreNonConfigurable + +Type: `boolean`\ +Default: `false` +Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error. -## License +## Related -MIT © [Sindre Sorhus](https://sindresorhus.com) +- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function +- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name and other properties + +--- + +
+ + Get professional support for this package with a Tidelift subscription + +
+ + Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. +
+
diff --git a/node_modules/npm-run-path/index.d.ts b/node_modules/npm-run-path/index.d.ts index af10d41a67..fad851b897 100644 --- a/node_modules/npm-run-path/index.d.ts +++ b/node_modules/npm-run-path/index.d.ts @@ -1,89 +1,84 @@ -declare namespace npmRunPath { - interface RunPathOptions { - /** - Working directory. +export interface RunPathOptions { + /** + Working directory. - @default process.cwd() - */ - readonly cwd?: string; + @default process.cwd() + */ + readonly cwd?: string | URL; - /** - PATH to be appended. Default: [`PATH`](https://github.com/sindresorhus/path-key). + /** + PATH to be appended. Default: [`PATH`](https://github.com/sindresorhus/path-key). - Set it to an empty string to exclude the default PATH. - */ - readonly path?: string; + Set it to an empty string to exclude the default PATH. + */ + readonly path?: string; - /** - Path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH. + /** + Path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH. - This can be either an absolute path or a path relative to the `cwd` option. + This can be either an absolute path or a path relative to the `cwd` option. - @default process.execPath - */ - readonly execPath?: string; - } + @default process.execPath + */ + readonly execPath?: string; +} - interface ProcessEnv { - [key: string]: string | undefined; - } +export type ProcessEnv = Record; - interface EnvOptions { - /** - Working directory. +export interface EnvOptions { + /** + The working directory. - @default process.cwd() - */ - readonly cwd?: string; + @default process.cwd() + */ + readonly cwd?: string | URL; - /** - Accepts an object of environment variables, like `process.env`, and modifies the PATH using the correct [PATH key](https://github.com/sindresorhus/path-key). Use this if you're modifying the PATH for use in the `child_process` options. - */ - readonly env?: ProcessEnv; + /** + Accepts an object of environment variables, like `process.env`, and modifies the PATH using the correct [PATH key](https://github.com/sindresorhus/path-key). Use this if you're modifying the PATH for use in the `child_process` options. + */ + readonly env?: ProcessEnv; - /** - Path to the current Node.js executable. Its directory is pushed to the front of PATH. + /** + The path to the current Node.js executable. Its directory is pushed to the front of PATH. - This can be either an absolute path or a path relative to the `cwd` option. + This can be either an absolute path or a path relative to the `cwd` option. - @default process.execPath - */ - readonly execPath?: string; - } + @default process.execPath + */ + readonly execPath?: string; } -declare const npmRunPath: { - /** - Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries. +/** +Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries. - @returns The augmented path string. +@returns The augmented path string. - @example - ``` - import * as childProcess from 'child_process'; - import npmRunPath = require('npm-run-path'); +@example +``` +import childProcess from 'node:child_process'; +import {npmRunPath} from 'npm-run-path'; - console.log(process.env.PATH); - //=> '/usr/local/bin' +console.log(process.env.PATH); +//=> '/usr/local/bin' - console.log(npmRunPath()); - //=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin' +console.log(npmRunPath()); +//=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin' +``` +*/ +export function npmRunPath(options?: RunPathOptions): string; - // `foo` is a locally installed binary - childProcess.execFileSync('foo', { - env: npmRunPath.env() - }); - ``` - */ - (options?: npmRunPath.RunPathOptions): string; - - /** - @returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object. - */ - env(options?: npmRunPath.EnvOptions): npmRunPath.ProcessEnv; +/** +@returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object. - // TODO: Remove this for the next major release - default: typeof npmRunPath; -}; +@example +``` +import childProcess from 'node:child_process'; +import {npmRunPathEnv} from 'npm-run-path'; -export = npmRunPath; +// `foo` is a locally installed binary +childProcess.execFileSync('foo', { + env: npmRunPathEnv() +}); +``` +*/ +export function npmRunPathEnv(options?: EnvOptions): ProcessEnv; diff --git a/node_modules/npm-run-path/index.js b/node_modules/npm-run-path/index.js index 8c94abc986..77dfae2177 100644 --- a/node_modules/npm-run-path/index.js +++ b/node_modules/npm-run-path/index.js @@ -1,17 +1,18 @@ -'use strict'; -const path = require('path'); -const pathKey = require('path-key'); - -const npmRunPath = options => { - options = { - cwd: process.cwd(), - path: process.env[pathKey()], - execPath: process.execPath, - ...options - }; +import process from 'node:process'; +import path from 'node:path'; +import url from 'node:url'; +import pathKey from 'path-key'; + +export function npmRunPath(options = {}) { + const { + cwd = process.cwd(), + path: path_ = process.env[pathKey()], + execPath = process.execPath, + } = options; let previous; - let cwdPath = path.resolve(options.cwd); + const cwdString = cwd instanceof URL ? url.fileURLToPath(cwd) : cwd; + let cwdPath = path.resolve(cwdString); const result = []; while (previous !== cwdPath) { @@ -20,28 +21,18 @@ const npmRunPath = options => { cwdPath = path.resolve(cwdPath, '..'); } - // Ensure the running `node` binary is used - const execPathDir = path.resolve(options.cwd, options.execPath, '..'); - result.push(execPathDir); + // Ensure the running `node` binary is used. + result.push(path.resolve(cwdString, execPath, '..')); - return result.concat(options.path).join(path.delimiter); -}; + return [...result, path_].join(path.delimiter); +} -module.exports = npmRunPath; -// TODO: Remove this for the next major release -module.exports.default = npmRunPath; +export function npmRunPathEnv({env = process.env, ...options} = {}) { + env = {...env}; -module.exports.env = options => { - options = { - env: process.env, - ...options - }; - - const env = {...options.env}; const path = pathKey({env}); - options.path = env[path]; - env[path] = module.exports(options); + env[path] = npmRunPath(options); return env; -}; +} diff --git a/node_modules/npm-run-path/license b/node_modules/npm-run-path/license index e7af2f7710..fa7ceba3eb 100644 --- a/node_modules/npm-run-path/license +++ b/node_modules/npm-run-path/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/node_modules/npm-run-path/node_modules/path-key/index.d.ts b/node_modules/npm-run-path/node_modules/path-key/index.d.ts new file mode 100644 index 0000000000..f411d623a9 --- /dev/null +++ b/node_modules/npm-run-path/node_modules/path-key/index.d.ts @@ -0,0 +1,31 @@ +export interface Options { + /** + Use a custom environment variables object. + + Default: [`process.env`](https://nodejs.org/api/process.html#process_process_env). + */ + readonly env?: Record; + + /** + Get the PATH key for a specific platform. + + Default: [`process.platform`](https://nodejs.org/api/process.html#process_process_platform). + */ + readonly platform?: NodeJS.Platform; +} + +/** +Get the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable key cross-platform. + +@example +``` +import pathKey from 'path-key'; + +const key = pathKey(); +//=> 'PATH' + +const PATH = process.env[key]; +//=> '/usr/local/bin:/usr/bin:/bin' +``` +*/ +export default function pathKey(options?: Options): string; diff --git a/node_modules/npm-run-path/node_modules/path-key/index.js b/node_modules/npm-run-path/node_modules/path-key/index.js new file mode 100644 index 0000000000..2c02914b07 --- /dev/null +++ b/node_modules/npm-run-path/node_modules/path-key/index.js @@ -0,0 +1,12 @@ +export default function pathKey(options = {}) { + const { + env = process.env, + platform = process.platform + } = options; + + if (platform !== 'win32') { + return 'PATH'; + } + + return Object.keys(env).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path'; +} diff --git a/node_modules/mem/node_modules/mimic-fn/license b/node_modules/npm-run-path/node_modules/path-key/license similarity index 100% rename from node_modules/mem/node_modules/mimic-fn/license rename to node_modules/npm-run-path/node_modules/path-key/license diff --git a/node_modules/mem/node_modules/mimic-fn/package.json b/node_modules/npm-run-path/node_modules/path-key/package.json similarity index 64% rename from node_modules/mem/node_modules/mimic-fn/package.json rename to node_modules/npm-run-path/node_modules/path-key/package.json index edf1918fe5..f7f04db548 100644 --- a/node_modules/mem/node_modules/mimic-fn/package.json +++ b/node_modules/npm-run-path/node_modules/path-key/package.json @@ -1,9 +1,9 @@ { - "name": "mimic-fn", + "name": "path-key", "version": "4.0.0", - "description": "Make a function mimic another one", + "description": "Get the PATH environment variable key cross-platform", "license": "MIT", - "repository": "sindresorhus/mimic-fn", + "repository": "sindresorhus/path-key", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", @@ -23,21 +23,17 @@ "index.d.ts" ], "keywords": [ - "function", - "mimic", - "imitate", - "rename", - "copy", - "inherit", - "properties", - "name", - "func", - "fn", - "set", - "infer", - "change" + "path", + "key", + "environment", + "env", + "variable", + "get", + "cross-platform", + "windows" ], "devDependencies": { + "@types/node": "^14.14.37", "ava": "^3.15.0", "tsd": "^0.14.0", "xo": "^0.38.2" diff --git a/node_modules/npm-run-path/node_modules/path-key/readme.md b/node_modules/npm-run-path/node_modules/path-key/readme.md new file mode 100644 index 0000000000..aa2250646f --- /dev/null +++ b/node_modules/npm-run-path/node_modules/path-key/readme.md @@ -0,0 +1,57 @@ +# path-key + +> Get the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable key cross-platform + +It's usually `PATH` but on Windows it can be any casing like `Path`... + +## Install + +``` +$ npm install path-key +``` + +## Usage + +```js +import pathKey from 'path-key'; + +const key = pathKey(); +//=> 'PATH' + +const PATH = process.env[key]; +//=> '/usr/local/bin:/usr/bin:/bin' +``` + +## API + +### pathKey(options?) + +#### options + +Type: `object` + +##### env + +Type: `object`\ +Default: [`process.env`](https://nodejs.org/api/process.html#process_process_env) + +Use a custom environment variables object. + +#### platform + +Type: `string`\ +Default: [`process.platform`](https://nodejs.org/api/process.html#process_process_platform) + +Get the PATH key for a specific platform. + +--- + +
+ + Get professional support for this package with a Tidelift subscription + +
+ + Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. +
+
diff --git a/node_modules/npm-run-path/package.json b/node_modules/npm-run-path/package.json index 39497091c3..df46566e33 100644 --- a/node_modules/npm-run-path/package.json +++ b/node_modules/npm-run-path/package.json @@ -1,16 +1,19 @@ { "name": "npm-run-path", - "version": "4.0.1", + "version": "5.1.0", "description": "Get your PATH prepended with locally installed binaries", "license": "MIT", "repository": "sindresorhus/npm-run-path", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" @@ -34,11 +37,11 @@ "executable" ], "dependencies": { - "path-key": "^3.0.0" + "path-key": "^4.0.0" }, "devDependencies": { - "ava": "^1.4.1", - "tsd": "^0.7.2", - "xo": "^0.24.0" + "ava": "^3.15.0", + "tsd": "^0.17.0", + "xo": "^0.45.0" } } diff --git a/node_modules/npm-run-path/readme.md b/node_modules/npm-run-path/readme.md index 557fbeb6c4..f2ab84b808 100644 --- a/node_modules/npm-run-path/readme.md +++ b/node_modules/npm-run-path/readme.md @@ -1,22 +1,20 @@ -# npm-run-path [![Build Status](https://travis-ci.org/sindresorhus/npm-run-path.svg?branch=master)](https://travis-ci.org/sindresorhus/npm-run-path) +# npm-run-path > Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries In [npm run scripts](https://docs.npmjs.com/cli/run-script) you can execute locally installed binaries by name. This enables the same outside npm. - ## Install -``` -$ npm install npm-run-path +```sh +npm install npm-run-path ``` - ## Usage ```js -const childProcess = require('child_process'); -const npmRunPath = require('npm-run-path'); +import childProcess from 'node:child_process'; +import {npmRunPath, npmRunPathEnv} from 'npm-run-path'; console.log(process.env.PATH); //=> '/usr/local/bin' @@ -26,16 +24,15 @@ console.log(npmRunPath()); // `foo` is a locally installed binary childProcess.execFileSync('foo', { - env: npmRunPath.env() + env: npmRunPathEnv() }); ``` - ## API ### npmRunPath(options?) -Returns the augmented path string. +Returns the augmented PATH string. #### options @@ -43,29 +40,30 @@ Type: `object` ##### cwd -Type: `string`
+Type: `string | URL`\ Default: `process.cwd()` -Working directory. +The working directory. ##### path -Type: `string`
+Type: `string`\ Default: [`PATH`](https://github.com/sindresorhus/path-key) -PATH to be appended.
+The PATH to be appended. + Set it to an empty string to exclude the default PATH. ##### execPath -Type: `string`
+Type: `string`\ Default: `process.execPath` -Path to the current Node.js executable. Its directory is pushed to the front of PATH. +The path to the current Node.js executable. Its directory is pushed to the front of PATH. This can be either an absolute path or a path relative to the [`cwd` option](#cwd). -### npmRunPath.env(options?) +### npmRunPathEnv(options?) Returns the augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object. @@ -75,33 +73,31 @@ Type: `object` ##### cwd -Type: `string`
+Type: `string | URL`\ Default: `process.cwd()` -Working directory. +The working directory. ##### env -Type: `Object` +Type: `object` Accepts an object of environment variables, like `process.env`, and modifies the PATH using the correct [PATH key](https://github.com/sindresorhus/path-key). Use this if you're modifying the PATH for use in the `child_process` options. ##### execPath -Type: `string`
+Type: `string`\ Default: `process.execPath` -Path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH. +The path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH. This can be either an absolute path or a path relative to the [`cwd` option](#cwd). - ## Related - [npm-run-path-cli](https://github.com/sindresorhus/npm-run-path-cli) - CLI for this module - [execa](https://github.com/sindresorhus/execa) - Execute a locally installed binary - ---
diff --git a/node_modules/onetime/index.d.ts b/node_modules/onetime/index.d.ts index ea84caba32..3c80803f99 100644 --- a/node_modules/onetime/index.d.ts +++ b/node_modules/onetime/index.d.ts @@ -1,12 +1,10 @@ -declare namespace onetime { - interface Options { - /** - Throw an error when called more than once. +export interface Options { + /** + Throw an error when called more than once. - @default false - */ - throw?: boolean; - } + @default false + */ + readonly throw?: boolean; } declare const onetime: { @@ -18,11 +16,11 @@ declare const onetime: { @example ``` - import onetime = require('onetime'); + import onetime from 'onetime'; - let i = 0; + let index = 0; - const foo = onetime(() => ++i); + const foo = onetime(() => ++index); foo(); //=> 1 foo(); //=> 1 @@ -33,7 +31,7 @@ declare const onetime: { */ ( fn: (...arguments: ArgumentsType) => ReturnType, - options?: onetime.Options + options?: Options ): (...arguments: ArgumentsType) => ReturnType; /** @@ -44,7 +42,7 @@ declare const onetime: { @example ``` - import onetime = require('onetime'); + import onetime from 'onetime'; const foo = onetime(() => {}); foo(); @@ -56,9 +54,6 @@ declare const onetime: { ``` */ callCount(fn: (...arguments: any[]) => unknown): number; - - // TODO: Remove this for the next major release - default: typeof onetime; }; -export = onetime; +export default onetime; diff --git a/node_modules/onetime/index.js b/node_modules/onetime/index.js index 99c5fc1cb4..eae4f33e4c 100644 --- a/node_modules/onetime/index.js +++ b/node_modules/onetime/index.js @@ -1,5 +1,4 @@ -'use strict'; -const mimicFn = require('mimic-fn'); +import mimicFunction from 'mimic-fn'; const calledFunctions = new WeakMap(); @@ -25,20 +24,18 @@ const onetime = (function_, options = {}) => { return returnValue; }; - mimicFn(onetime, function_); + mimicFunction(onetime, function_); calledFunctions.set(onetime, callCount); return onetime; }; -module.exports = onetime; -// TODO: Remove this for the next major release -module.exports.default = onetime; - -module.exports.callCount = function_ => { +onetime.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_); }; + +export default onetime; diff --git a/node_modules/onetime/package.json b/node_modules/onetime/package.json index c4fe4e245d..367a963495 100644 --- a/node_modules/onetime/package.json +++ b/node_modules/onetime/package.json @@ -1,6 +1,6 @@ { "name": "onetime", - "version": "5.1.2", + "version": "6.0.0", "description": "Ensure a function is only called once", "license": "MIT", "repository": "sindresorhus/onetime", @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=6" + "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" @@ -33,11 +35,11 @@ "prevent" ], "dependencies": { - "mimic-fn": "^2.1.0" + "mimic-fn": "^4.0.0" }, "devDependencies": { - "ava": "^1.4.1", - "tsd": "^0.7.1", - "xo": "^0.24.0" + "ava": "^3.15.0", + "tsd": "^0.14.0", + "xo": "^0.38.2" } } diff --git a/node_modules/onetime/readme.md b/node_modules/onetime/readme.md index 2d133d3a09..e2b26fb3d3 100644 --- a/node_modules/onetime/readme.md +++ b/node_modules/onetime/readme.md @@ -1,4 +1,4 @@ -# onetime [![Build Status](https://travis-ci.com/sindresorhus/onetime.svg?branch=master)](https://travis-ci.com/github/sindresorhus/onetime) +# onetime > Ensure a function is only called once @@ -15,11 +15,11 @@ $ npm install onetime ## Usage ```js -const onetime = require('onetime'); +import onetime from 'onetime'; -let i = 0; +let index = 0; -const foo = onetime(() => ++i); +const foo = onetime(() => ++index); foo(); //=> 1 foo(); //=> 1 @@ -29,7 +29,7 @@ onetime.callCount(foo); //=> 3 ``` ```js -const onetime = require('onetime'); +import onetime from 'onetime'; const foo = onetime(() => {}, {throw: true}); @@ -69,7 +69,7 @@ Returns a number representing how many times `fn` has been called. Note: It throws an error if you pass in a function that is not wrapped by `onetime`. ```js -const onetime = require('onetime'); +import onetime from 'onetime'; const foo = onetime(() => {}); diff --git a/node_modules/strip-final-newline/index.js b/node_modules/strip-final-newline/index.js index 78fc0c5939..034b56f865 100644 --- a/node_modules/strip-final-newline/index.js +++ b/node_modules/strip-final-newline/index.js @@ -1,16 +1,14 @@ -'use strict'; - -module.exports = input => { +export default function 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); + input = input.slice(0, -1); } if (input[input.length - 1] === CR) { - input = input.slice(0, input.length - 1); + input = input.slice(0, -1); } return input; -}; +} diff --git a/node_modules/strip-final-newline/license b/node_modules/strip-final-newline/license index e7af2f7710..fa7ceba3eb 100644 --- a/node_modules/strip-final-newline/license +++ b/node_modules/strip-final-newline/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/node_modules/strip-final-newline/package.json b/node_modules/strip-final-newline/package.json index 40b7e802c9..23ac8622e4 100644 --- a/node_modules/strip-final-newline/package.json +++ b/node_modules/strip-final-newline/package.json @@ -1,16 +1,19 @@ { "name": "strip-final-newline", - "version": "2.0.0", + "version": "3.0.0", "description": "Strip the final newline character from a string/buffer", "license": "MIT", "repository": "sindresorhus/strip-final-newline", + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" + "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=6" + "node": ">=12" }, "scripts": { "test": "xo && ava" @@ -34,7 +37,7 @@ "buffer" ], "devDependencies": { - "ava": "^0.25.0", - "xo": "^0.23.0" + "ava": "^3.15.0", + "xo": "^0.39.1" } } diff --git a/node_modules/strip-final-newline/readme.md b/node_modules/strip-final-newline/readme.md index 32dfd50904..8d9090b64f 100644 --- a/node_modules/strip-final-newline/readme.md +++ b/node_modules/strip-final-newline/readme.md @@ -1,21 +1,19 @@ -# strip-final-newline [![Build Status](https://travis-ci.com/sindresorhus/strip-final-newline.svg?branch=master)](https://travis-ci.com/sindresorhus/strip-final-newline) +# strip-final-newline > Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from a string/buffer Can be useful when parsing the output of, for example, `ChildProcess#execFile`, as [binaries usually output a newline at the end](https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline). Normally, you would use `stdout.trim()`, but that would also remove newlines at the start and whitespace. - ## Install ``` $ npm install strip-final-newline ``` - ## Usage ```js -const stripFinalNewline = require('strip-final-newline'); +import stripFinalNewline from 'strip-final-newline'; stripFinalNewline('foo\nbar\n\n'); //=> 'foo\nbar\n' @@ -24,7 +22,14 @@ stripFinalNewline(Buffer.from('foo\nbar\n\n')).toString(); //=> 'foo\nbar\n' ``` - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) +--- + +
+ + Get professional support for this package with a Tidelift subscription + +
+ + Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. +
+