Spaces:
Running
Running
Commit
·
2b24a67
1
Parent(s):
77a1685
removed symlink and replaced with a watcher process
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .yarn/install-state.gz +0 -0
- hf_server.js +39 -3
- node_modules/.bin/glob +1 -0
- node_modules/.bin/mkdirp +1 -0
- node_modules/.bin/node-gyp +1 -0
- node_modules/.bin/node-which +1 -0
- node_modules/.bin/nopt +1 -0
- node_modules/.bin/semver +1 -0
- node_modules/.yarn-state.yml +410 -0
- node_modules/@isaacs/cliui/LICENSE.txt +14 -0
- node_modules/@isaacs/cliui/README.md +143 -0
- node_modules/@isaacs/cliui/build/index.cjs +317 -0
- node_modules/@isaacs/cliui/build/index.d.cts +43 -0
- node_modules/@isaacs/cliui/build/lib/index.js +302 -0
- node_modules/@isaacs/cliui/index.mjs +14 -0
- node_modules/@isaacs/cliui/package.json +86 -0
- node_modules/@npmcli/agent/README.md +40 -0
- node_modules/@npmcli/agent/lib/agents.js +202 -0
- node_modules/@npmcli/agent/lib/dns.js +53 -0
- node_modules/@npmcli/agent/lib/errors.js +61 -0
- node_modules/@npmcli/agent/lib/index.js +56 -0
- node_modules/@npmcli/agent/lib/options.js +86 -0
- node_modules/@npmcli/agent/lib/proxy.js +88 -0
- node_modules/@npmcli/agent/package.json +60 -0
- node_modules/@npmcli/fs/LICENSE.md +20 -0
- node_modules/@npmcli/fs/README.md +97 -0
- node_modules/@npmcli/fs/lib/common/get-options.js +20 -0
- node_modules/@npmcli/fs/lib/common/node.js +9 -0
- node_modules/@npmcli/fs/lib/cp/LICENSE +15 -0
- node_modules/@npmcli/fs/lib/cp/errors.js +129 -0
- node_modules/@npmcli/fs/lib/cp/index.js +22 -0
- node_modules/@npmcli/fs/lib/cp/polyfill.js +428 -0
- node_modules/@npmcli/fs/lib/index.js +13 -0
- node_modules/@npmcli/fs/lib/move-file.js +78 -0
- node_modules/@npmcli/fs/lib/readdir-scoped.js +20 -0
- node_modules/@npmcli/fs/lib/with-temp-dir.js +39 -0
- node_modules/@npmcli/fs/package.json +52 -0
- node_modules/@pkgjs/parseargs/.editorconfig +14 -0
- node_modules/@pkgjs/parseargs/CHANGELOG.md +147 -0
- node_modules/@pkgjs/parseargs/LICENSE +201 -0
- node_modules/@pkgjs/parseargs/README.md +413 -0
- node_modules/@pkgjs/parseargs/examples/is-default-value.js +25 -0
- node_modules/@pkgjs/parseargs/examples/limit-long-syntax.js +35 -0
- node_modules/@pkgjs/parseargs/examples/negate.js +43 -0
- node_modules/@pkgjs/parseargs/examples/no-repeated-options.js +31 -0
- node_modules/@pkgjs/parseargs/examples/ordered-options.mjs +41 -0
- node_modules/@pkgjs/parseargs/examples/simple-hard-coded.js +26 -0
- node_modules/@pkgjs/parseargs/index.js +396 -0
- node_modules/@pkgjs/parseargs/internal/errors.js +47 -0
- node_modules/@pkgjs/parseargs/internal/primordials.js +393 -0
.yarn/install-state.gz
CHANGED
Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ
|
|
hf_server.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* All rights reserved.
|
4 |
*/
|
5 |
//@ts-check
|
6 |
-
const VERSION = '0.6.0.hf.
|
7 |
|
8 |
const express = require('express');
|
9 |
const http = require('http');
|
@@ -11,7 +11,10 @@ const session = require('express-session');
|
|
11 |
const axios = require('axios');
|
12 |
const { spawn } = require('child_process');
|
13 |
const { createProxyMiddleware } = require('http-proxy-middleware');
|
14 |
-
|
|
|
|
|
|
|
15 |
const app = express();
|
16 |
|
17 |
const OMNITOOL_INSTALL_SCRIPT = './omnitool_init.sh'; // './omnitool_start.sh';
|
@@ -25,6 +28,9 @@ const OMNITOOL_SPACE_URL = "omnitool-ai-omnitool-on-hf.hf.space";
|
|
25 |
const HF_SPACE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf";
|
26 |
const HF_SPACE_DUPLICATE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf?duplicate=true";
|
27 |
|
|
|
|
|
|
|
28 |
const DELAY_OMNITOOL_SET_TO_RUNNING = 2000; // 2 seconds
|
29 |
const CHECK_OMNI_INTERVAL = 60000; // 1 minute
|
30 |
|
@@ -181,7 +187,7 @@ async function checkOmnitoolStatus()
|
|
181 |
}
|
182 |
} catch (error)
|
183 |
{
|
184 |
-
console.
|
185 |
setOmnitoolRunning(false);
|
186 |
}
|
187 |
}
|
@@ -444,6 +450,36 @@ function omnitoolProxyMiddleware(req, res, next)
|
|
444 |
|
445 |
async function main(app)
|
446 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
await checkOmnitoolStatus();
|
448 |
|
449 |
// Configure session middleware
|
|
|
3 |
* All rights reserved.
|
4 |
*/
|
5 |
//@ts-check
|
6 |
+
const VERSION = '0.6.0.hf.014.b';
|
7 |
|
8 |
const express = require('express');
|
9 |
const http = require('http');
|
|
|
11 |
const axios = require('axios');
|
12 |
const { spawn } = require('child_process');
|
13 |
const { createProxyMiddleware } = require('http-proxy-middleware');
|
14 |
+
const fs = require('fs');
|
15 |
+
const path = require('path');
|
16 |
+
const chokidar = require('chokidar');
|
17 |
+
const fsExtra = require('fs-extra');
|
18 |
const app = express();
|
19 |
|
20 |
const OMNITOOL_INSTALL_SCRIPT = './omnitool_init.sh'; // './omnitool_start.sh';
|
|
|
28 |
const HF_SPACE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf";
|
29 |
const HF_SPACE_DUPLICATE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf?duplicate=true";
|
30 |
|
31 |
+
const sourceDir = './omnitool/packages/omni-server/data.local';
|
32 |
+
const targetDir = '/data/';
|
33 |
+
|
34 |
const DELAY_OMNITOOL_SET_TO_RUNNING = 2000; // 2 seconds
|
35 |
const CHECK_OMNI_INTERVAL = 60000; // 1 minute
|
36 |
|
|
|
187 |
}
|
188 |
} catch (error)
|
189 |
{
|
190 |
+
console.log('Please press [CREATE Omnitool Server] button');
|
191 |
setOmnitoolRunning(false);
|
192 |
}
|
193 |
}
|
|
|
450 |
|
451 |
async function main(app)
|
452 |
{
|
453 |
+
if (fs.existsSync(targetDir)) {
|
454 |
+
fsExtra.copySync(targetDir, sourceDir);
|
455 |
+
const watcher = chokidar.watch(sourceDir, {
|
456 |
+
ignored: /[\/\\]\./,
|
457 |
+
persistent: true
|
458 |
+
});
|
459 |
+
watcher
|
460 |
+
.on('add', function(path) {
|
461 |
+
const targetFile = path.replace(sourceDir, targetDir);
|
462 |
+
fs.copyFile(path, targetFile, (err) => {
|
463 |
+
if (err) throw err;
|
464 |
+
console.log('File', path, 'has been added and copied to', targetFile);
|
465 |
+
});
|
466 |
+
})
|
467 |
+
.on('change', function(path) {
|
468 |
+
const targetFile = path.replace(sourceDir, targetDir);
|
469 |
+
fs.copyFile(path, targetFile, (err) => {
|
470 |
+
if (err) throw err;
|
471 |
+
console.log('File', path, 'has been changed and copied to', targetFile);
|
472 |
+
});
|
473 |
+
})
|
474 |
+
.on('unlink', function(path) {
|
475 |
+
const targetFile = path.replace(sourceDir, targetDir);
|
476 |
+
fs.unlink(targetFile, (err) => {
|
477 |
+
if (err) throw err;
|
478 |
+
console.log('File', path, 'has been removed');
|
479 |
+
});
|
480 |
+
});
|
481 |
+
}
|
482 |
+
|
483 |
await checkOmnitoolStatus();
|
484 |
|
485 |
// Configure session middleware
|
node_modules/.bin/glob
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
../glob/dist/esm/bin.mjs
|
node_modules/.bin/mkdirp
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
../mkdirp/bin/cmd.js
|
node_modules/.bin/node-gyp
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
../node-gyp/bin/node-gyp.js
|
node_modules/.bin/node-which
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
../which/bin/node-which
|
node_modules/.bin/nopt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
../nopt/bin/nopt.js
|
node_modules/.bin/semver
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
../semver/bin/semver.js
|
node_modules/.yarn-state.yml
CHANGED
@@ -5,6 +5,22 @@ __metadata:
|
|
5 |
version: 1
|
6 |
nmMode: classic
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
"@types/http-proxy@npm:1.17.14":
|
9 |
locations:
|
10 |
- "node_modules/@types/http-proxy"
|
@@ -13,10 +29,42 @@ __metadata:
|
|
13 |
locations:
|
14 |
- "node_modules/@types/node"
|
15 |
|
|
|
|
|
|
|
|
|
16 |
"accepts@npm:1.3.8":
|
17 |
locations:
|
18 |
- "node_modules/accepts"
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
"array-flatten@npm:1.1.1":
|
21 |
locations:
|
22 |
- "node_modules/array-flatten"
|
@@ -29,10 +77,22 @@ __metadata:
|
|
29 |
locations:
|
30 |
- "node_modules/axios"
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
"body-parser@npm:1.20.1":
|
33 |
locations:
|
34 |
- "node_modules/body-parser"
|
35 |
|
|
|
|
|
|
|
|
|
36 |
"braces@npm:3.0.2":
|
37 |
locations:
|
38 |
- "node_modules/braces"
|
@@ -41,10 +101,34 @@ __metadata:
|
|
41 |
locations:
|
42 |
- "node_modules/bytes"
|
43 |
|
|
|
|
|
|
|
|
|
44 |
"call-bind@npm:1.0.5":
|
45 |
locations:
|
46 |
- "node_modules/call-bind"
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
"combined-stream@npm:1.0.8":
|
49 |
locations:
|
50 |
- "node_modules/combined-stream"
|
@@ -69,10 +153,21 @@ __metadata:
|
|
69 |
locations:
|
70 |
- "node_modules/express/node_modules/cookie"
|
71 |
|
|
|
|
|
|
|
|
|
72 |
"debug@virtual:0819dbe06c028ed82b45fc11021fc9e474d69a1dd2911cea2d866d094407eaa6ab88fb2220200e1c178168f363713875d8626748d6757a812c36c845e3d6e907#npm:2.6.9":
|
73 |
locations:
|
74 |
- "node_modules/debug"
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
"define-data-property@npm:1.1.1":
|
77 |
locations:
|
78 |
- "node_modules/define-data-property"
|
@@ -89,14 +184,38 @@ __metadata:
|
|
89 |
locations:
|
90 |
- "node_modules/destroy"
|
91 |
|
|
|
|
|
|
|
|
|
92 |
"ee-first@npm:1.1.1":
|
93 |
locations:
|
94 |
- "node_modules/ee-first"
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
"encodeurl@npm:1.0.2":
|
97 |
locations:
|
98 |
- "node_modules/encodeurl"
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
"escape-html@npm:1.0.3":
|
101 |
locations:
|
102 |
- "node_modules/escape-html"
|
@@ -109,6 +228,10 @@ __metadata:
|
|
109 |
locations:
|
110 |
- "node_modules/eventemitter3"
|
111 |
|
|
|
|
|
|
|
|
|
112 |
"express-session@npm:1.17.3":
|
113 |
locations:
|
114 |
- "node_modules/express-session"
|
@@ -129,6 +252,10 @@ __metadata:
|
|
129 |
locations:
|
130 |
- "node_modules/follow-redirects"
|
131 |
|
|
|
|
|
|
|
|
|
132 |
"form-data@npm:4.0.0":
|
133 |
locations:
|
134 |
- "node_modules/form-data"
|
@@ -141,6 +268,22 @@ __metadata:
|
|
141 |
locations:
|
142 |
- "node_modules/fresh"
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
"function-bind@npm:1.1.2":
|
145 |
locations:
|
146 |
- "node_modules/function-bind"
|
@@ -149,10 +292,22 @@ __metadata:
|
|
149 |
locations:
|
150 |
- "node_modules/get-intrinsic"
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
"gopd@npm:1.0.1":
|
153 |
locations:
|
154 |
- "node_modules/gopd"
|
155 |
|
|
|
|
|
|
|
|
|
156 |
"has-property-descriptors@npm:1.0.1":
|
157 |
locations:
|
158 |
- "node_modules/has-property-descriptors"
|
@@ -169,10 +324,18 @@ __metadata:
|
|
169 |
locations:
|
170 |
- "node_modules/hasown"
|
171 |
|
|
|
|
|
|
|
|
|
172 |
"http-errors@npm:2.0.0":
|
173 |
locations:
|
174 |
- "node_modules/http-errors"
|
175 |
|
|
|
|
|
|
|
|
|
176 |
"http-proxy-middleware@virtual:ddbaaf5feb2fb477cdc1694b6534dcee6f008f7380c4eefc34002266e4860044ca2211f32921bfbbc16a5f053003a1ce5712707bb193bec7c255933bc9263e00#npm:2.0.6":
|
177 |
locations:
|
178 |
- "node_modules/http-proxy-middleware"
|
@@ -181,26 +344,58 @@ __metadata:
|
|
181 |
locations:
|
182 |
- "node_modules/http-proxy"
|
183 |
|
|
|
|
|
|
|
|
|
184 |
"iconv-lite@npm:0.4.24":
|
185 |
locations:
|
186 |
- "node_modules/iconv-lite"
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
"inherits@npm:2.0.4":
|
189 |
locations:
|
190 |
- "node_modules/inherits"
|
191 |
|
|
|
|
|
|
|
|
|
192 |
"ipaddr.js@npm:1.9.1":
|
193 |
locations:
|
194 |
- "node_modules/ipaddr.js"
|
195 |
|
|
|
|
|
|
|
|
|
196 |
"is-extglob@npm:2.1.1":
|
197 |
locations:
|
198 |
- "node_modules/is-extglob"
|
199 |
|
|
|
|
|
|
|
|
|
200 |
"is-glob@npm:4.0.3":
|
201 |
locations:
|
202 |
- "node_modules/is-glob"
|
203 |
|
|
|
|
|
|
|
|
|
204 |
"is-number@npm:7.0.0":
|
205 |
locations:
|
206 |
- "node_modules/is-number"
|
@@ -209,6 +404,34 @@ __metadata:
|
|
209 |
locations:
|
210 |
- "node_modules/is-plain-obj"
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
"media-typer@npm:0.3.0":
|
213 |
locations:
|
214 |
- "node_modules/media-typer"
|
@@ -237,7 +460,59 @@ __metadata:
|
|
237 |
locations:
|
238 |
- "node_modules/mime"
|
239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
"ms@npm:2.0.0":
|
|
|
|
|
|
|
|
|
241 |
locations:
|
242 |
- "node_modules/ms"
|
243 |
|
@@ -249,6 +524,18 @@ __metadata:
|
|
249 |
locations:
|
250 |
- "node_modules/negotiator"
|
251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
"object-inspect@npm:1.13.1":
|
253 |
locations:
|
254 |
- "node_modules/object-inspect"
|
@@ -257,8 +544,16 @@ __metadata:
|
|
257 |
locations:
|
258 |
- ""
|
259 |
bin:
|
|
|
|
|
260 |
".":
|
|
|
261 |
"mime": "mime/cli.js"
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
"on-finished@npm:2.4.1":
|
264 |
locations:
|
@@ -268,10 +563,22 @@ __metadata:
|
|
268 |
locations:
|
269 |
- "node_modules/on-headers"
|
270 |
|
|
|
|
|
|
|
|
|
271 |
"parseurl@npm:1.3.3":
|
272 |
locations:
|
273 |
- "node_modules/parseurl"
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
"path-to-regexp@npm:0.1.7":
|
276 |
locations:
|
277 |
- "node_modules/path-to-regexp"
|
@@ -280,6 +587,14 @@ __metadata:
|
|
280 |
locations:
|
281 |
- "node_modules/picomatch"
|
282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
"proxy-addr@npm:2.0.7":
|
284 |
locations:
|
285 |
- "node_modules/proxy-addr"
|
@@ -304,10 +619,18 @@ __metadata:
|
|
304 |
locations:
|
305 |
- "node_modules/raw-body"
|
306 |
|
|
|
|
|
|
|
|
|
307 |
"requires-port@npm:1.0.0":
|
308 |
locations:
|
309 |
- "node_modules/requires-port"
|
310 |
|
|
|
|
|
|
|
|
|
311 |
"safe-buffer@npm:5.2.1":
|
312 |
locations:
|
313 |
- "node_modules/safe-buffer"
|
@@ -316,6 +639,10 @@ __metadata:
|
|
316 |
locations:
|
317 |
- "node_modules/safer-buffer"
|
318 |
|
|
|
|
|
|
|
|
|
319 |
"send@npm:0.18.0":
|
320 |
locations:
|
321 |
- "node_modules/send"
|
@@ -332,14 +659,65 @@ __metadata:
|
|
332 |
locations:
|
333 |
- "node_modules/setprototypeof"
|
334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
"side-channel@npm:1.0.4":
|
336 |
locations:
|
337 |
- "node_modules/side-channel"
|
338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
"statuses@npm:2.0.1":
|
340 |
locations:
|
341 |
- "node_modules/statuses"
|
342 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
"to-regex-range@npm:5.0.1":
|
344 |
locations:
|
345 |
- "node_modules/to-regex-range"
|
@@ -360,6 +738,18 @@ __metadata:
|
|
360 |
locations:
|
361 |
- "node_modules/undici-types"
|
362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
"unpipe@npm:1.0.0":
|
364 |
locations:
|
365 |
- "node_modules/unpipe"
|
@@ -371,3 +761,23 @@ __metadata:
|
|
371 |
"vary@npm:1.1.2":
|
372 |
locations:
|
373 |
- "node_modules/vary"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
version: 1
|
6 |
nmMode: classic
|
7 |
|
8 |
+
"@isaacs/cliui@npm:8.0.2":
|
9 |
+
locations:
|
10 |
+
- "node_modules/@isaacs/cliui"
|
11 |
+
|
12 |
+
"@npmcli/agent@npm:2.2.0":
|
13 |
+
locations:
|
14 |
+
- "node_modules/@npmcli/agent"
|
15 |
+
|
16 |
+
"@npmcli/fs@npm:3.1.0":
|
17 |
+
locations:
|
18 |
+
- "node_modules/@npmcli/fs"
|
19 |
+
|
20 |
+
"@pkgjs/parseargs@npm:0.11.0":
|
21 |
+
locations:
|
22 |
+
- "node_modules/@pkgjs/parseargs"
|
23 |
+
|
24 |
"@types/http-proxy@npm:1.17.14":
|
25 |
locations:
|
26 |
- "node_modules/@types/http-proxy"
|
|
|
29 |
locations:
|
30 |
- "node_modules/@types/node"
|
31 |
|
32 |
+
"abbrev@npm:2.0.0":
|
33 |
+
locations:
|
34 |
+
- "node_modules/abbrev"
|
35 |
+
|
36 |
"accepts@npm:1.3.8":
|
37 |
locations:
|
38 |
- "node_modules/accepts"
|
39 |
|
40 |
+
"agent-base@npm:7.1.0":
|
41 |
+
locations:
|
42 |
+
- "node_modules/agent-base"
|
43 |
+
|
44 |
+
"aggregate-error@npm:3.1.0":
|
45 |
+
locations:
|
46 |
+
- "node_modules/aggregate-error"
|
47 |
+
|
48 |
+
"ansi-regex@npm:5.0.1":
|
49 |
+
locations:
|
50 |
+
- "node_modules/ansi-regex"
|
51 |
+
|
52 |
+
"ansi-regex@npm:6.0.1":
|
53 |
+
locations:
|
54 |
+
- "node_modules/strip-ansi/node_modules/ansi-regex"
|
55 |
+
|
56 |
+
"ansi-styles@npm:4.3.0":
|
57 |
+
locations:
|
58 |
+
- "node_modules/ansi-styles"
|
59 |
+
|
60 |
+
"ansi-styles@npm:6.2.1":
|
61 |
+
locations:
|
62 |
+
- "node_modules/wrap-ansi/node_modules/ansi-styles"
|
63 |
+
|
64 |
+
"anymatch@npm:3.1.3":
|
65 |
+
locations:
|
66 |
+
- "node_modules/anymatch"
|
67 |
+
|
68 |
"array-flatten@npm:1.1.1":
|
69 |
locations:
|
70 |
- "node_modules/array-flatten"
|
|
|
77 |
locations:
|
78 |
- "node_modules/axios"
|
79 |
|
80 |
+
"balanced-match@npm:1.0.2":
|
81 |
+
locations:
|
82 |
+
- "node_modules/balanced-match"
|
83 |
+
|
84 |
+
"binary-extensions@npm:2.2.0":
|
85 |
+
locations:
|
86 |
+
- "node_modules/binary-extensions"
|
87 |
+
|
88 |
"body-parser@npm:1.20.1":
|
89 |
locations:
|
90 |
- "node_modules/body-parser"
|
91 |
|
92 |
+
"brace-expansion@npm:2.0.1":
|
93 |
+
locations:
|
94 |
+
- "node_modules/brace-expansion"
|
95 |
+
|
96 |
"braces@npm:3.0.2":
|
97 |
locations:
|
98 |
- "node_modules/braces"
|
|
|
101 |
locations:
|
102 |
- "node_modules/bytes"
|
103 |
|
104 |
+
"cacache@npm:18.0.1":
|
105 |
+
locations:
|
106 |
+
- "node_modules/cacache"
|
107 |
+
|
108 |
"call-bind@npm:1.0.5":
|
109 |
locations:
|
110 |
- "node_modules/call-bind"
|
111 |
|
112 |
+
"chokidar@npm:3.5.3":
|
113 |
+
locations:
|
114 |
+
- "node_modules/chokidar"
|
115 |
+
|
116 |
+
"chownr@npm:2.0.0":
|
117 |
+
locations:
|
118 |
+
- "node_modules/chownr"
|
119 |
+
|
120 |
+
"clean-stack@npm:2.2.0":
|
121 |
+
locations:
|
122 |
+
- "node_modules/clean-stack"
|
123 |
+
|
124 |
+
"color-convert@npm:2.0.1":
|
125 |
+
locations:
|
126 |
+
- "node_modules/color-convert"
|
127 |
+
|
128 |
+
"color-name@npm:1.1.4":
|
129 |
+
locations:
|
130 |
+
- "node_modules/color-name"
|
131 |
+
|
132 |
"combined-stream@npm:1.0.8":
|
133 |
locations:
|
134 |
- "node_modules/combined-stream"
|
|
|
153 |
locations:
|
154 |
- "node_modules/express/node_modules/cookie"
|
155 |
|
156 |
+
"cross-spawn@npm:7.0.3":
|
157 |
+
locations:
|
158 |
+
- "node_modules/cross-spawn"
|
159 |
+
|
160 |
"debug@virtual:0819dbe06c028ed82b45fc11021fc9e474d69a1dd2911cea2d866d094407eaa6ab88fb2220200e1c178168f363713875d8626748d6757a812c36c845e3d6e907#npm:2.6.9":
|
161 |
locations:
|
162 |
- "node_modules/debug"
|
163 |
|
164 |
+
"debug@virtual:4b12ba5111caf7e8338099bdbc7cb046a9f8e079a44e74d0c03dca469876e3071ebbe671c5e90ae6b78ae33e22c205fa5ed32169a4aabd1404b13c56d09986e1#npm:4.3.4":
|
165 |
+
locations:
|
166 |
+
- "node_modules/socks-proxy-agent/node_modules/debug"
|
167 |
+
- "node_modules/https-proxy-agent/node_modules/debug"
|
168 |
+
- "node_modules/http-proxy-agent/node_modules/debug"
|
169 |
+
- "node_modules/agent-base/node_modules/debug"
|
170 |
+
|
171 |
"define-data-property@npm:1.1.1":
|
172 |
locations:
|
173 |
- "node_modules/define-data-property"
|
|
|
184 |
locations:
|
185 |
- "node_modules/destroy"
|
186 |
|
187 |
+
"eastasianwidth@npm:0.2.0":
|
188 |
+
locations:
|
189 |
+
- "node_modules/eastasianwidth"
|
190 |
+
|
191 |
"ee-first@npm:1.1.1":
|
192 |
locations:
|
193 |
- "node_modules/ee-first"
|
194 |
|
195 |
+
"emoji-regex@npm:8.0.0":
|
196 |
+
locations:
|
197 |
+
- "node_modules/emoji-regex"
|
198 |
+
|
199 |
+
"emoji-regex@npm:9.2.2":
|
200 |
+
locations:
|
201 |
+
- "node_modules/string-width/node_modules/emoji-regex"
|
202 |
+
|
203 |
"encodeurl@npm:1.0.2":
|
204 |
locations:
|
205 |
- "node_modules/encodeurl"
|
206 |
|
207 |
+
"encoding@npm:0.1.13":
|
208 |
+
locations:
|
209 |
+
- "node_modules/encoding"
|
210 |
+
|
211 |
+
"env-paths@npm:2.2.1":
|
212 |
+
locations:
|
213 |
+
- "node_modules/env-paths"
|
214 |
+
|
215 |
+
"err-code@npm:2.0.3":
|
216 |
+
locations:
|
217 |
+
- "node_modules/err-code"
|
218 |
+
|
219 |
"escape-html@npm:1.0.3":
|
220 |
locations:
|
221 |
- "node_modules/escape-html"
|
|
|
228 |
locations:
|
229 |
- "node_modules/eventemitter3"
|
230 |
|
231 |
+
"exponential-backoff@npm:3.1.1":
|
232 |
+
locations:
|
233 |
+
- "node_modules/exponential-backoff"
|
234 |
+
|
235 |
"express-session@npm:1.17.3":
|
236 |
locations:
|
237 |
- "node_modules/express-session"
|
|
|
252 |
locations:
|
253 |
- "node_modules/follow-redirects"
|
254 |
|
255 |
+
"foreground-child@npm:3.1.1":
|
256 |
+
locations:
|
257 |
+
- "node_modules/foreground-child"
|
258 |
+
|
259 |
"form-data@npm:4.0.0":
|
260 |
locations:
|
261 |
- "node_modules/form-data"
|
|
|
268 |
locations:
|
269 |
- "node_modules/fresh"
|
270 |
|
271 |
+
"fs-extra@npm:11.2.0":
|
272 |
+
locations:
|
273 |
+
- "node_modules/fs-extra"
|
274 |
+
|
275 |
+
"fs-minipass@npm:2.1.0":
|
276 |
+
locations:
|
277 |
+
- "node_modules/tar/node_modules/fs-minipass"
|
278 |
+
|
279 |
+
"fs-minipass@npm:3.0.3":
|
280 |
+
locations:
|
281 |
+
- "node_modules/fs-minipass"
|
282 |
+
|
283 |
+
"fsevents@patch:fsevents@npm%3A2.3.3#optional!builtin<compat/fsevents>::version=2.3.3&hash=df0bf1":
|
284 |
+
locations:
|
285 |
+
- "node_modules/fsevents"
|
286 |
+
|
287 |
"function-bind@npm:1.1.2":
|
288 |
locations:
|
289 |
- "node_modules/function-bind"
|
|
|
292 |
locations:
|
293 |
- "node_modules/get-intrinsic"
|
294 |
|
295 |
+
"glob-parent@npm:5.1.2":
|
296 |
+
locations:
|
297 |
+
- "node_modules/glob-parent"
|
298 |
+
|
299 |
+
"glob@npm:10.3.10":
|
300 |
+
locations:
|
301 |
+
- "node_modules/glob"
|
302 |
+
|
303 |
"gopd@npm:1.0.1":
|
304 |
locations:
|
305 |
- "node_modules/gopd"
|
306 |
|
307 |
+
"graceful-fs@npm:4.2.11":
|
308 |
+
locations:
|
309 |
+
- "node_modules/graceful-fs"
|
310 |
+
|
311 |
"has-property-descriptors@npm:1.0.1":
|
312 |
locations:
|
313 |
- "node_modules/has-property-descriptors"
|
|
|
324 |
locations:
|
325 |
- "node_modules/hasown"
|
326 |
|
327 |
+
"http-cache-semantics@npm:4.1.1":
|
328 |
+
locations:
|
329 |
+
- "node_modules/http-cache-semantics"
|
330 |
+
|
331 |
"http-errors@npm:2.0.0":
|
332 |
locations:
|
333 |
- "node_modules/http-errors"
|
334 |
|
335 |
+
"http-proxy-agent@npm:7.0.0":
|
336 |
+
locations:
|
337 |
+
- "node_modules/http-proxy-agent"
|
338 |
+
|
339 |
"http-proxy-middleware@virtual:ddbaaf5feb2fb477cdc1694b6534dcee6f008f7380c4eefc34002266e4860044ca2211f32921bfbbc16a5f053003a1ce5712707bb193bec7c255933bc9263e00#npm:2.0.6":
|
340 |
locations:
|
341 |
- "node_modules/http-proxy-middleware"
|
|
|
344 |
locations:
|
345 |
- "node_modules/http-proxy"
|
346 |
|
347 |
+
"https-proxy-agent@npm:7.0.2":
|
348 |
+
locations:
|
349 |
+
- "node_modules/https-proxy-agent"
|
350 |
+
|
351 |
"iconv-lite@npm:0.4.24":
|
352 |
locations:
|
353 |
- "node_modules/iconv-lite"
|
354 |
|
355 |
+
"iconv-lite@npm:0.6.3":
|
356 |
+
locations:
|
357 |
+
- "node_modules/encoding/node_modules/iconv-lite"
|
358 |
+
|
359 |
+
"imurmurhash@npm:0.1.4":
|
360 |
+
locations:
|
361 |
+
- "node_modules/imurmurhash"
|
362 |
+
|
363 |
+
"indent-string@npm:4.0.0":
|
364 |
+
locations:
|
365 |
+
- "node_modules/indent-string"
|
366 |
+
|
367 |
"inherits@npm:2.0.4":
|
368 |
locations:
|
369 |
- "node_modules/inherits"
|
370 |
|
371 |
+
"ip@npm:2.0.0":
|
372 |
+
locations:
|
373 |
+
- "node_modules/ip"
|
374 |
+
|
375 |
"ipaddr.js@npm:1.9.1":
|
376 |
locations:
|
377 |
- "node_modules/ipaddr.js"
|
378 |
|
379 |
+
"is-binary-path@npm:2.1.0":
|
380 |
+
locations:
|
381 |
+
- "node_modules/is-binary-path"
|
382 |
+
|
383 |
"is-extglob@npm:2.1.1":
|
384 |
locations:
|
385 |
- "node_modules/is-extglob"
|
386 |
|
387 |
+
"is-fullwidth-code-point@npm:3.0.0":
|
388 |
+
locations:
|
389 |
+
- "node_modules/is-fullwidth-code-point"
|
390 |
+
|
391 |
"is-glob@npm:4.0.3":
|
392 |
locations:
|
393 |
- "node_modules/is-glob"
|
394 |
|
395 |
+
"is-lambda@npm:1.0.1":
|
396 |
+
locations:
|
397 |
+
- "node_modules/is-lambda"
|
398 |
+
|
399 |
"is-number@npm:7.0.0":
|
400 |
locations:
|
401 |
- "node_modules/is-number"
|
|
|
404 |
locations:
|
405 |
- "node_modules/is-plain-obj"
|
406 |
|
407 |
+
"isexe@npm:2.0.0":
|
408 |
+
locations:
|
409 |
+
- "node_modules/isexe"
|
410 |
+
|
411 |
+
"isexe@npm:3.1.1":
|
412 |
+
locations:
|
413 |
+
- "node_modules/node-gyp/node_modules/isexe"
|
414 |
+
|
415 |
+
"jackspeak@npm:2.3.6":
|
416 |
+
locations:
|
417 |
+
- "node_modules/jackspeak"
|
418 |
+
|
419 |
+
"jsonfile@npm:6.1.0":
|
420 |
+
locations:
|
421 |
+
- "node_modules/jsonfile"
|
422 |
+
|
423 |
+
"lru-cache@npm:10.1.0":
|
424 |
+
locations:
|
425 |
+
- "node_modules/lru-cache"
|
426 |
+
|
427 |
+
"lru-cache@npm:6.0.0":
|
428 |
+
locations:
|
429 |
+
- "node_modules/semver/node_modules/lru-cache"
|
430 |
+
|
431 |
+
"make-fetch-happen@npm:13.0.0":
|
432 |
+
locations:
|
433 |
+
- "node_modules/make-fetch-happen"
|
434 |
+
|
435 |
"media-typer@npm:0.3.0":
|
436 |
locations:
|
437 |
- "node_modules/media-typer"
|
|
|
460 |
locations:
|
461 |
- "node_modules/mime"
|
462 |
|
463 |
+
"minimatch@npm:9.0.3":
|
464 |
+
locations:
|
465 |
+
- "node_modules/minimatch"
|
466 |
+
|
467 |
+
"minipass-collect@npm:2.0.1":
|
468 |
+
locations:
|
469 |
+
- "node_modules/minipass-collect"
|
470 |
+
|
471 |
+
"minipass-fetch@npm:3.0.4":
|
472 |
+
locations:
|
473 |
+
- "node_modules/minipass-fetch"
|
474 |
+
|
475 |
+
"minipass-flush@npm:1.0.5":
|
476 |
+
locations:
|
477 |
+
- "node_modules/minipass-flush"
|
478 |
+
|
479 |
+
"minipass-pipeline@npm:1.2.4":
|
480 |
+
locations:
|
481 |
+
- "node_modules/minipass-pipeline"
|
482 |
+
|
483 |
+
"minipass-sized@npm:1.0.3":
|
484 |
+
locations:
|
485 |
+
- "node_modules/minipass-sized"
|
486 |
+
|
487 |
+
"minipass@npm:3.3.6":
|
488 |
+
locations:
|
489 |
+
- "node_modules/tar/node_modules/fs-minipass/node_modules/minipass"
|
490 |
+
- "node_modules/minizlib/node_modules/minipass"
|
491 |
+
- "node_modules/minipass-sized/node_modules/minipass"
|
492 |
+
- "node_modules/minipass-pipeline/node_modules/minipass"
|
493 |
+
- "node_modules/minipass-flush/node_modules/minipass"
|
494 |
+
|
495 |
+
"minipass@npm:5.0.0":
|
496 |
+
locations:
|
497 |
+
- "node_modules/tar/node_modules/minipass"
|
498 |
+
|
499 |
+
"minipass@npm:7.0.4":
|
500 |
+
locations:
|
501 |
+
- "node_modules/minipass"
|
502 |
+
|
503 |
+
"minizlib@npm:2.1.2":
|
504 |
+
locations:
|
505 |
+
- "node_modules/minizlib"
|
506 |
+
|
507 |
+
"mkdirp@npm:1.0.4":
|
508 |
+
locations:
|
509 |
+
- "node_modules/mkdirp"
|
510 |
+
|
511 |
"ms@npm:2.0.0":
|
512 |
+
locations:
|
513 |
+
- "node_modules/debug/node_modules/ms"
|
514 |
+
|
515 |
+
"ms@npm:2.1.2":
|
516 |
locations:
|
517 |
- "node_modules/ms"
|
518 |
|
|
|
524 |
locations:
|
525 |
- "node_modules/negotiator"
|
526 |
|
527 |
+
"node-gyp@npm:10.0.1":
|
528 |
+
locations:
|
529 |
+
- "node_modules/node-gyp"
|
530 |
+
|
531 |
+
"nopt@npm:7.2.0":
|
532 |
+
locations:
|
533 |
+
- "node_modules/nopt"
|
534 |
+
|
535 |
+
"normalize-path@npm:3.0.0":
|
536 |
+
locations:
|
537 |
+
- "node_modules/normalize-path"
|
538 |
+
|
539 |
"object-inspect@npm:1.13.1":
|
540 |
locations:
|
541 |
- "node_modules/object-inspect"
|
|
|
544 |
locations:
|
545 |
- ""
|
546 |
bin:
|
547 |
+
"node_modules/node-gyp":
|
548 |
+
"node-which": "which/bin/which.js"
|
549 |
".":
|
550 |
+
"node-gyp": "node-gyp/bin/node-gyp.js"
|
551 |
"mime": "mime/cli.js"
|
552 |
+
"glob": "glob/dist/esm/bin.mjs"
|
553 |
+
"nopt": "nopt/bin/nopt.js"
|
554 |
+
"semver": "semver/bin/semver.js"
|
555 |
+
"mkdirp": "mkdirp/bin/cmd.js"
|
556 |
+
"node-which": "which/bin/node-which"
|
557 |
|
558 |
"on-finished@npm:2.4.1":
|
559 |
locations:
|
|
|
563 |
locations:
|
564 |
- "node_modules/on-headers"
|
565 |
|
566 |
+
"p-map@npm:4.0.0":
|
567 |
+
locations:
|
568 |
+
- "node_modules/p-map"
|
569 |
+
|
570 |
"parseurl@npm:1.3.3":
|
571 |
locations:
|
572 |
- "node_modules/parseurl"
|
573 |
|
574 |
+
"path-key@npm:3.1.1":
|
575 |
+
locations:
|
576 |
+
- "node_modules/path-key"
|
577 |
+
|
578 |
+
"path-scurry@npm:1.10.1":
|
579 |
+
locations:
|
580 |
+
- "node_modules/path-scurry"
|
581 |
+
|
582 |
"path-to-regexp@npm:0.1.7":
|
583 |
locations:
|
584 |
- "node_modules/path-to-regexp"
|
|
|
587 |
locations:
|
588 |
- "node_modules/picomatch"
|
589 |
|
590 |
+
"proc-log@npm:3.0.0":
|
591 |
+
locations:
|
592 |
+
- "node_modules/proc-log"
|
593 |
+
|
594 |
+
"promise-retry@npm:2.0.1":
|
595 |
+
locations:
|
596 |
+
- "node_modules/promise-retry"
|
597 |
+
|
598 |
"proxy-addr@npm:2.0.7":
|
599 |
locations:
|
600 |
- "node_modules/proxy-addr"
|
|
|
619 |
locations:
|
620 |
- "node_modules/raw-body"
|
621 |
|
622 |
+
"readdirp@npm:3.6.0":
|
623 |
+
locations:
|
624 |
+
- "node_modules/readdirp"
|
625 |
+
|
626 |
"requires-port@npm:1.0.0":
|
627 |
locations:
|
628 |
- "node_modules/requires-port"
|
629 |
|
630 |
+
"retry@npm:0.12.0":
|
631 |
+
locations:
|
632 |
+
- "node_modules/retry"
|
633 |
+
|
634 |
"safe-buffer@npm:5.2.1":
|
635 |
locations:
|
636 |
- "node_modules/safe-buffer"
|
|
|
639 |
locations:
|
640 |
- "node_modules/safer-buffer"
|
641 |
|
642 |
+
"semver@npm:7.5.4":
|
643 |
+
locations:
|
644 |
+
- "node_modules/semver"
|
645 |
+
|
646 |
"send@npm:0.18.0":
|
647 |
locations:
|
648 |
- "node_modules/send"
|
|
|
659 |
locations:
|
660 |
- "node_modules/setprototypeof"
|
661 |
|
662 |
+
"shebang-command@npm:2.0.0":
|
663 |
+
locations:
|
664 |
+
- "node_modules/shebang-command"
|
665 |
+
|
666 |
+
"shebang-regex@npm:3.0.0":
|
667 |
+
locations:
|
668 |
+
- "node_modules/shebang-regex"
|
669 |
+
|
670 |
"side-channel@npm:1.0.4":
|
671 |
locations:
|
672 |
- "node_modules/side-channel"
|
673 |
|
674 |
+
"signal-exit@npm:4.1.0":
|
675 |
+
locations:
|
676 |
+
- "node_modules/signal-exit"
|
677 |
+
|
678 |
+
"smart-buffer@npm:4.2.0":
|
679 |
+
locations:
|
680 |
+
- "node_modules/smart-buffer"
|
681 |
+
|
682 |
+
"socks-proxy-agent@npm:8.0.2":
|
683 |
+
locations:
|
684 |
+
- "node_modules/socks-proxy-agent"
|
685 |
+
|
686 |
+
"socks@npm:2.7.1":
|
687 |
+
locations:
|
688 |
+
- "node_modules/socks"
|
689 |
+
|
690 |
+
"ssri@npm:10.0.5":
|
691 |
+
locations:
|
692 |
+
- "node_modules/ssri"
|
693 |
+
|
694 |
"statuses@npm:2.0.1":
|
695 |
locations:
|
696 |
- "node_modules/statuses"
|
697 |
|
698 |
+
"string-width@npm:4.2.3":
|
699 |
+
locations:
|
700 |
+
- "node_modules/wrap-ansi-cjs/node_modules/string-width"
|
701 |
+
- "node_modules/string-width-cjs"
|
702 |
+
|
703 |
+
"string-width@npm:5.1.2":
|
704 |
+
locations:
|
705 |
+
- "node_modules/string-width"
|
706 |
+
|
707 |
+
"strip-ansi@npm:6.0.1":
|
708 |
+
locations:
|
709 |
+
- "node_modules/wrap-ansi-cjs/node_modules/strip-ansi"
|
710 |
+
- "node_modules/strip-ansi-cjs"
|
711 |
+
- "node_modules/string-width-cjs/node_modules/strip-ansi"
|
712 |
+
|
713 |
+
"strip-ansi@npm:7.1.0":
|
714 |
+
locations:
|
715 |
+
- "node_modules/strip-ansi"
|
716 |
+
|
717 |
+
"tar@npm:6.2.0":
|
718 |
+
locations:
|
719 |
+
- "node_modules/tar"
|
720 |
+
|
721 |
"to-regex-range@npm:5.0.1":
|
722 |
locations:
|
723 |
- "node_modules/to-regex-range"
|
|
|
738 |
locations:
|
739 |
- "node_modules/undici-types"
|
740 |
|
741 |
+
"unique-filename@npm:3.0.0":
|
742 |
+
locations:
|
743 |
+
- "node_modules/unique-filename"
|
744 |
+
|
745 |
+
"unique-slug@npm:4.0.0":
|
746 |
+
locations:
|
747 |
+
- "node_modules/unique-slug"
|
748 |
+
|
749 |
+
"universalify@npm:2.0.1":
|
750 |
+
locations:
|
751 |
+
- "node_modules/universalify"
|
752 |
+
|
753 |
"unpipe@npm:1.0.0":
|
754 |
locations:
|
755 |
- "node_modules/unpipe"
|
|
|
761 |
"vary@npm:1.1.2":
|
762 |
locations:
|
763 |
- "node_modules/vary"
|
764 |
+
|
765 |
+
"which@npm:2.0.2":
|
766 |
+
locations:
|
767 |
+
- "node_modules/which"
|
768 |
+
|
769 |
+
"which@npm:4.0.0":
|
770 |
+
locations:
|
771 |
+
- "node_modules/node-gyp/node_modules/which"
|
772 |
+
|
773 |
+
"wrap-ansi@npm:7.0.0":
|
774 |
+
locations:
|
775 |
+
- "node_modules/wrap-ansi-cjs"
|
776 |
+
|
777 |
+
"wrap-ansi@npm:8.1.0":
|
778 |
+
locations:
|
779 |
+
- "node_modules/wrap-ansi"
|
780 |
+
|
781 |
+
"yallist@npm:4.0.0":
|
782 |
+
locations:
|
783 |
+
- "node_modules/yallist"
|
node_modules/@isaacs/cliui/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright (c) 2015, Contributors
|
2 |
+
|
3 |
+
Permission to use, copy, modify, and/or distribute this software
|
4 |
+
for any purpose with or without fee is hereby granted, provided
|
5 |
+
that the above copyright notice and this permission notice
|
6 |
+
appear in all copies.
|
7 |
+
|
8 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9 |
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
10 |
+
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
|
11 |
+
LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
|
12 |
+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
13 |
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
14 |
+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
node_modules/@isaacs/cliui/README.md
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @isaacs/cliui
|
2 |
+
|
3 |
+
Temporary fork of [cliui](http://npm.im/cliui).
|
4 |
+
|
5 |
+

|
6 |
+
[](https://www.npmjs.com/package/cliui)
|
7 |
+
[](https://conventionalcommits.org)
|
8 |
+

|
9 |
+
|
10 |
+
easily create complex multi-column command-line-interfaces.
|
11 |
+
|
12 |
+
## Example
|
13 |
+
|
14 |
+
```js
|
15 |
+
const ui = require('cliui')()
|
16 |
+
|
17 |
+
ui.div('Usage: $0 [command] [options]')
|
18 |
+
|
19 |
+
ui.div({
|
20 |
+
text: 'Options:',
|
21 |
+
padding: [2, 0, 1, 0]
|
22 |
+
})
|
23 |
+
|
24 |
+
ui.div(
|
25 |
+
{
|
26 |
+
text: "-f, --file",
|
27 |
+
width: 20,
|
28 |
+
padding: [0, 4, 0, 4]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
text: "the file to load." +
|
32 |
+
chalk.green("(if this description is long it wraps).")
|
33 |
+
,
|
34 |
+
width: 20
|
35 |
+
},
|
36 |
+
{
|
37 |
+
text: chalk.red("[required]"),
|
38 |
+
align: 'right'
|
39 |
+
}
|
40 |
+
)
|
41 |
+
|
42 |
+
console.log(ui.toString())
|
43 |
+
```
|
44 |
+
|
45 |
+
## Deno/ESM Support
|
46 |
+
|
47 |
+
As of `v7` `cliui` supports [Deno](https://github.com/denoland/deno) and
|
48 |
+
[ESM](https://nodejs.org/api/esm.html#esm_ecmascript_modules):
|
49 |
+
|
50 |
+
```typescript
|
51 |
+
import cliui from "https://deno.land/x/cliui/deno.ts";
|
52 |
+
|
53 |
+
const ui = cliui({})
|
54 |
+
|
55 |
+
ui.div('Usage: $0 [command] [options]')
|
56 |
+
|
57 |
+
ui.div({
|
58 |
+
text: 'Options:',
|
59 |
+
padding: [2, 0, 1, 0]
|
60 |
+
})
|
61 |
+
|
62 |
+
ui.div({
|
63 |
+
text: "-f, --file",
|
64 |
+
width: 20,
|
65 |
+
padding: [0, 4, 0, 4]
|
66 |
+
})
|
67 |
+
|
68 |
+
console.log(ui.toString())
|
69 |
+
```
|
70 |
+
|
71 |
+
<img width="500" src="screenshot.png">
|
72 |
+
|
73 |
+
## Layout DSL
|
74 |
+
|
75 |
+
cliui exposes a simple layout DSL:
|
76 |
+
|
77 |
+
If you create a single `ui.div`, passing a string rather than an
|
78 |
+
object:
|
79 |
+
|
80 |
+
* `\n`: characters will be interpreted as new rows.
|
81 |
+
* `\t`: characters will be interpreted as new columns.
|
82 |
+
* `\s`: characters will be interpreted as padding.
|
83 |
+
|
84 |
+
**as an example...**
|
85 |
+
|
86 |
+
```js
|
87 |
+
var ui = require('./')({
|
88 |
+
width: 60
|
89 |
+
})
|
90 |
+
|
91 |
+
ui.div(
|
92 |
+
'Usage: node ./bin/foo.js\n' +
|
93 |
+
' <regex>\t provide a regex\n' +
|
94 |
+
' <glob>\t provide a glob\t [required]'
|
95 |
+
)
|
96 |
+
|
97 |
+
console.log(ui.toString())
|
98 |
+
```
|
99 |
+
|
100 |
+
**will output:**
|
101 |
+
|
102 |
+
```shell
|
103 |
+
Usage: node ./bin/foo.js
|
104 |
+
<regex> provide a regex
|
105 |
+
<glob> provide a glob [required]
|
106 |
+
```
|
107 |
+
|
108 |
+
## Methods
|
109 |
+
|
110 |
+
```js
|
111 |
+
cliui = require('cliui')
|
112 |
+
```
|
113 |
+
|
114 |
+
### cliui({width: integer})
|
115 |
+
|
116 |
+
Specify the maximum width of the UI being generated.
|
117 |
+
If no width is provided, cliui will try to get the current window's width and use it, and if that doesn't work, width will be set to `80`.
|
118 |
+
|
119 |
+
### cliui({wrap: boolean})
|
120 |
+
|
121 |
+
Enable or disable the wrapping of text in a column.
|
122 |
+
|
123 |
+
### cliui.div(column, column, column)
|
124 |
+
|
125 |
+
Create a row with any number of columns, a column
|
126 |
+
can either be a string, or an object with the following
|
127 |
+
options:
|
128 |
+
|
129 |
+
* **text:** some text to place in the column.
|
130 |
+
* **width:** the width of a column.
|
131 |
+
* **align:** alignment, `right` or `center`.
|
132 |
+
* **padding:** `[top, right, bottom, left]`.
|
133 |
+
* **border:** should a border be placed around the div?
|
134 |
+
|
135 |
+
### cliui.span(column, column, column)
|
136 |
+
|
137 |
+
Similar to `div`, except the next row will be appended without
|
138 |
+
a new line being created.
|
139 |
+
|
140 |
+
### cliui.resetOutput()
|
141 |
+
|
142 |
+
Resets the UI elements of the current cliui instance, maintaining the values
|
143 |
+
set for `width` and `wrap`.
|
node_modules/@isaacs/cliui/build/index.cjs
ADDED
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
const align = {
|
4 |
+
right: alignRight,
|
5 |
+
center: alignCenter
|
6 |
+
};
|
7 |
+
const top = 0;
|
8 |
+
const right = 1;
|
9 |
+
const bottom = 2;
|
10 |
+
const left = 3;
|
11 |
+
class UI {
|
12 |
+
constructor(opts) {
|
13 |
+
var _a;
|
14 |
+
this.width = opts.width;
|
15 |
+
/* c8 ignore start */
|
16 |
+
this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
|
17 |
+
/* c8 ignore stop */
|
18 |
+
this.rows = [];
|
19 |
+
}
|
20 |
+
span(...args) {
|
21 |
+
const cols = this.div(...args);
|
22 |
+
cols.span = true;
|
23 |
+
}
|
24 |
+
resetOutput() {
|
25 |
+
this.rows = [];
|
26 |
+
}
|
27 |
+
div(...args) {
|
28 |
+
if (args.length === 0) {
|
29 |
+
this.div('');
|
30 |
+
}
|
31 |
+
if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
|
32 |
+
return this.applyLayoutDSL(args[0]);
|
33 |
+
}
|
34 |
+
const cols = args.map(arg => {
|
35 |
+
if (typeof arg === 'string') {
|
36 |
+
return this.colFromString(arg);
|
37 |
+
}
|
38 |
+
return arg;
|
39 |
+
});
|
40 |
+
this.rows.push(cols);
|
41 |
+
return cols;
|
42 |
+
}
|
43 |
+
shouldApplyLayoutDSL(...args) {
|
44 |
+
return args.length === 1 && typeof args[0] === 'string' &&
|
45 |
+
/[\t\n]/.test(args[0]);
|
46 |
+
}
|
47 |
+
applyLayoutDSL(str) {
|
48 |
+
const rows = str.split('\n').map(row => row.split('\t'));
|
49 |
+
let leftColumnWidth = 0;
|
50 |
+
// simple heuristic for layout, make sure the
|
51 |
+
// second column lines up along the left-hand.
|
52 |
+
// don't allow the first column to take up more
|
53 |
+
// than 50% of the screen.
|
54 |
+
rows.forEach(columns => {
|
55 |
+
if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
|
56 |
+
leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
|
57 |
+
}
|
58 |
+
});
|
59 |
+
// generate a table:
|
60 |
+
// replacing ' ' with padding calculations.
|
61 |
+
// using the algorithmically generated width.
|
62 |
+
rows.forEach(columns => {
|
63 |
+
this.div(...columns.map((r, i) => {
|
64 |
+
return {
|
65 |
+
text: r.trim(),
|
66 |
+
padding: this.measurePadding(r),
|
67 |
+
width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
|
68 |
+
};
|
69 |
+
}));
|
70 |
+
});
|
71 |
+
return this.rows[this.rows.length - 1];
|
72 |
+
}
|
73 |
+
colFromString(text) {
|
74 |
+
return {
|
75 |
+
text,
|
76 |
+
padding: this.measurePadding(text)
|
77 |
+
};
|
78 |
+
}
|
79 |
+
measurePadding(str) {
|
80 |
+
// measure padding without ansi escape codes
|
81 |
+
const noAnsi = mixin.stripAnsi(str);
|
82 |
+
return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
|
83 |
+
}
|
84 |
+
toString() {
|
85 |
+
const lines = [];
|
86 |
+
this.rows.forEach(row => {
|
87 |
+
this.rowToString(row, lines);
|
88 |
+
});
|
89 |
+
// don't display any lines with the
|
90 |
+
// hidden flag set.
|
91 |
+
return lines
|
92 |
+
.filter(line => !line.hidden)
|
93 |
+
.map(line => line.text)
|
94 |
+
.join('\n');
|
95 |
+
}
|
96 |
+
rowToString(row, lines) {
|
97 |
+
this.rasterize(row).forEach((rrow, r) => {
|
98 |
+
let str = '';
|
99 |
+
rrow.forEach((col, c) => {
|
100 |
+
const { width } = row[c]; // the width with padding.
|
101 |
+
const wrapWidth = this.negatePadding(row[c]); // the width without padding.
|
102 |
+
let ts = col; // temporary string used during alignment/padding.
|
103 |
+
if (wrapWidth > mixin.stringWidth(col)) {
|
104 |
+
ts += ' '.repeat(wrapWidth - mixin.stringWidth(col));
|
105 |
+
}
|
106 |
+
// align the string within its column.
|
107 |
+
if (row[c].align && row[c].align !== 'left' && this.wrap) {
|
108 |
+
const fn = align[row[c].align];
|
109 |
+
ts = fn(ts, wrapWidth);
|
110 |
+
if (mixin.stringWidth(ts) < wrapWidth) {
|
111 |
+
/* c8 ignore start */
|
112 |
+
const w = width || 0;
|
113 |
+
/* c8 ignore stop */
|
114 |
+
ts += ' '.repeat(w - mixin.stringWidth(ts) - 1);
|
115 |
+
}
|
116 |
+
}
|
117 |
+
// apply border and padding to string.
|
118 |
+
const padding = row[c].padding || [0, 0, 0, 0];
|
119 |
+
if (padding[left]) {
|
120 |
+
str += ' '.repeat(padding[left]);
|
121 |
+
}
|
122 |
+
str += addBorder(row[c], ts, '| ');
|
123 |
+
str += ts;
|
124 |
+
str += addBorder(row[c], ts, ' |');
|
125 |
+
if (padding[right]) {
|
126 |
+
str += ' '.repeat(padding[right]);
|
127 |
+
}
|
128 |
+
// if prior row is span, try to render the
|
129 |
+
// current row on the prior line.
|
130 |
+
if (r === 0 && lines.length > 0) {
|
131 |
+
str = this.renderInline(str, lines[lines.length - 1]);
|
132 |
+
}
|
133 |
+
});
|
134 |
+
// remove trailing whitespace.
|
135 |
+
lines.push({
|
136 |
+
text: str.replace(/ +$/, ''),
|
137 |
+
span: row.span
|
138 |
+
});
|
139 |
+
});
|
140 |
+
return lines;
|
141 |
+
}
|
142 |
+
// if the full 'source' can render in
|
143 |
+
// the target line, do so.
|
144 |
+
renderInline(source, previousLine) {
|
145 |
+
const match = source.match(/^ */);
|
146 |
+
/* c8 ignore start */
|
147 |
+
const leadingWhitespace = match ? match[0].length : 0;
|
148 |
+
/* c8 ignore stop */
|
149 |
+
const target = previousLine.text;
|
150 |
+
const targetTextWidth = mixin.stringWidth(target.trimEnd());
|
151 |
+
if (!previousLine.span) {
|
152 |
+
return source;
|
153 |
+
}
|
154 |
+
// if we're not applying wrapping logic,
|
155 |
+
// just always append to the span.
|
156 |
+
if (!this.wrap) {
|
157 |
+
previousLine.hidden = true;
|
158 |
+
return target + source;
|
159 |
+
}
|
160 |
+
if (leadingWhitespace < targetTextWidth) {
|
161 |
+
return source;
|
162 |
+
}
|
163 |
+
previousLine.hidden = true;
|
164 |
+
return target.trimEnd() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimStart();
|
165 |
+
}
|
166 |
+
rasterize(row) {
|
167 |
+
const rrows = [];
|
168 |
+
const widths = this.columnWidths(row);
|
169 |
+
let wrapped;
|
170 |
+
// word wrap all columns, and create
|
171 |
+
// a data-structure that is easy to rasterize.
|
172 |
+
row.forEach((col, c) => {
|
173 |
+
// leave room for left and right padding.
|
174 |
+
col.width = widths[c];
|
175 |
+
if (this.wrap) {
|
176 |
+
wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n');
|
177 |
+
}
|
178 |
+
else {
|
179 |
+
wrapped = col.text.split('\n');
|
180 |
+
}
|
181 |
+
if (col.border) {
|
182 |
+
wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.');
|
183 |
+
wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'");
|
184 |
+
}
|
185 |
+
// add top and bottom padding.
|
186 |
+
if (col.padding) {
|
187 |
+
wrapped.unshift(...new Array(col.padding[top] || 0).fill(''));
|
188 |
+
wrapped.push(...new Array(col.padding[bottom] || 0).fill(''));
|
189 |
+
}
|
190 |
+
wrapped.forEach((str, r) => {
|
191 |
+
if (!rrows[r]) {
|
192 |
+
rrows.push([]);
|
193 |
+
}
|
194 |
+
const rrow = rrows[r];
|
195 |
+
for (let i = 0; i < c; i++) {
|
196 |
+
if (rrow[i] === undefined) {
|
197 |
+
rrow.push('');
|
198 |
+
}
|
199 |
+
}
|
200 |
+
rrow.push(str);
|
201 |
+
});
|
202 |
+
});
|
203 |
+
return rrows;
|
204 |
+
}
|
205 |
+
negatePadding(col) {
|
206 |
+
/* c8 ignore start */
|
207 |
+
let wrapWidth = col.width || 0;
|
208 |
+
/* c8 ignore stop */
|
209 |
+
if (col.padding) {
|
210 |
+
wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
|
211 |
+
}
|
212 |
+
if (col.border) {
|
213 |
+
wrapWidth -= 4;
|
214 |
+
}
|
215 |
+
return wrapWidth;
|
216 |
+
}
|
217 |
+
columnWidths(row) {
|
218 |
+
if (!this.wrap) {
|
219 |
+
return row.map(col => {
|
220 |
+
return col.width || mixin.stringWidth(col.text);
|
221 |
+
});
|
222 |
+
}
|
223 |
+
let unset = row.length;
|
224 |
+
let remainingWidth = this.width;
|
225 |
+
// column widths can be set in config.
|
226 |
+
const widths = row.map(col => {
|
227 |
+
if (col.width) {
|
228 |
+
unset--;
|
229 |
+
remainingWidth -= col.width;
|
230 |
+
return col.width;
|
231 |
+
}
|
232 |
+
return undefined;
|
233 |
+
});
|
234 |
+
// any unset widths should be calculated.
|
235 |
+
/* c8 ignore start */
|
236 |
+
const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
|
237 |
+
/* c8 ignore stop */
|
238 |
+
return widths.map((w, i) => {
|
239 |
+
if (w === undefined) {
|
240 |
+
return Math.max(unsetWidth, _minWidth(row[i]));
|
241 |
+
}
|
242 |
+
return w;
|
243 |
+
});
|
244 |
+
}
|
245 |
+
}
|
246 |
+
function addBorder(col, ts, style) {
|
247 |
+
if (col.border) {
|
248 |
+
if (/[.']-+[.']/.test(ts)) {
|
249 |
+
return '';
|
250 |
+
}
|
251 |
+
if (ts.trim().length !== 0) {
|
252 |
+
return style;
|
253 |
+
}
|
254 |
+
return ' ';
|
255 |
+
}
|
256 |
+
return '';
|
257 |
+
}
|
258 |
+
// calculates the minimum width of
|
259 |
+
// a column, based on padding preferences.
|
260 |
+
function _minWidth(col) {
|
261 |
+
const padding = col.padding || [];
|
262 |
+
const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
|
263 |
+
if (col.border) {
|
264 |
+
return minWidth + 4;
|
265 |
+
}
|
266 |
+
return minWidth;
|
267 |
+
}
|
268 |
+
function getWindowWidth() {
|
269 |
+
/* c8 ignore start */
|
270 |
+
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
|
271 |
+
return process.stdout.columns;
|
272 |
+
}
|
273 |
+
return 80;
|
274 |
+
}
|
275 |
+
/* c8 ignore stop */
|
276 |
+
function alignRight(str, width) {
|
277 |
+
str = str.trim();
|
278 |
+
const strWidth = mixin.stringWidth(str);
|
279 |
+
if (strWidth < width) {
|
280 |
+
return ' '.repeat(width - strWidth) + str;
|
281 |
+
}
|
282 |
+
return str;
|
283 |
+
}
|
284 |
+
function alignCenter(str, width) {
|
285 |
+
str = str.trim();
|
286 |
+
const strWidth = mixin.stringWidth(str);
|
287 |
+
/* c8 ignore start */
|
288 |
+
if (strWidth >= width) {
|
289 |
+
return str;
|
290 |
+
}
|
291 |
+
/* c8 ignore stop */
|
292 |
+
return ' '.repeat((width - strWidth) >> 1) + str;
|
293 |
+
}
|
294 |
+
let mixin;
|
295 |
+
function cliui(opts, _mixin) {
|
296 |
+
mixin = _mixin;
|
297 |
+
return new UI({
|
298 |
+
/* c8 ignore start */
|
299 |
+
width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
|
300 |
+
wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
|
301 |
+
/* c8 ignore stop */
|
302 |
+
});
|
303 |
+
}
|
304 |
+
|
305 |
+
// Bootstrap cliui with CommonJS dependencies:
|
306 |
+
const stringWidth = require('string-width-cjs');
|
307 |
+
const stripAnsi = require('strip-ansi-cjs');
|
308 |
+
const wrap = require('wrap-ansi-cjs');
|
309 |
+
function ui(opts) {
|
310 |
+
return cliui(opts, {
|
311 |
+
stringWidth,
|
312 |
+
stripAnsi,
|
313 |
+
wrap
|
314 |
+
});
|
315 |
+
}
|
316 |
+
|
317 |
+
module.exports = ui;
|
node_modules/@isaacs/cliui/build/index.d.cts
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
interface UIOptions {
|
2 |
+
width: number;
|
3 |
+
wrap?: boolean;
|
4 |
+
rows?: string[];
|
5 |
+
}
|
6 |
+
interface Column {
|
7 |
+
text: string;
|
8 |
+
width?: number;
|
9 |
+
align?: "right" | "left" | "center";
|
10 |
+
padding: number[];
|
11 |
+
border?: boolean;
|
12 |
+
}
|
13 |
+
interface ColumnArray extends Array<Column> {
|
14 |
+
span: boolean;
|
15 |
+
}
|
16 |
+
interface Line {
|
17 |
+
hidden?: boolean;
|
18 |
+
text: string;
|
19 |
+
span?: boolean;
|
20 |
+
}
|
21 |
+
declare class UI {
|
22 |
+
width: number;
|
23 |
+
wrap: boolean;
|
24 |
+
rows: ColumnArray[];
|
25 |
+
constructor(opts: UIOptions);
|
26 |
+
span(...args: ColumnArray): void;
|
27 |
+
resetOutput(): void;
|
28 |
+
div(...args: (Column | string)[]): ColumnArray;
|
29 |
+
private shouldApplyLayoutDSL;
|
30 |
+
private applyLayoutDSL;
|
31 |
+
private colFromString;
|
32 |
+
private measurePadding;
|
33 |
+
toString(): string;
|
34 |
+
rowToString(row: ColumnArray, lines: Line[]): Line[];
|
35 |
+
// if the full 'source' can render in
|
36 |
+
// the target line, do so.
|
37 |
+
private renderInline;
|
38 |
+
private rasterize;
|
39 |
+
private negatePadding;
|
40 |
+
private columnWidths;
|
41 |
+
}
|
42 |
+
declare function ui(opts: UIOptions): UI;
|
43 |
+
export { ui as default };
|
node_modules/@isaacs/cliui/build/lib/index.js
ADDED
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
const align = {
|
3 |
+
right: alignRight,
|
4 |
+
center: alignCenter
|
5 |
+
};
|
6 |
+
const top = 0;
|
7 |
+
const right = 1;
|
8 |
+
const bottom = 2;
|
9 |
+
const left = 3;
|
10 |
+
export class UI {
|
11 |
+
constructor(opts) {
|
12 |
+
var _a;
|
13 |
+
this.width = opts.width;
|
14 |
+
/* c8 ignore start */
|
15 |
+
this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
|
16 |
+
/* c8 ignore stop */
|
17 |
+
this.rows = [];
|
18 |
+
}
|
19 |
+
span(...args) {
|
20 |
+
const cols = this.div(...args);
|
21 |
+
cols.span = true;
|
22 |
+
}
|
23 |
+
resetOutput() {
|
24 |
+
this.rows = [];
|
25 |
+
}
|
26 |
+
div(...args) {
|
27 |
+
if (args.length === 0) {
|
28 |
+
this.div('');
|
29 |
+
}
|
30 |
+
if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
|
31 |
+
return this.applyLayoutDSL(args[0]);
|
32 |
+
}
|
33 |
+
const cols = args.map(arg => {
|
34 |
+
if (typeof arg === 'string') {
|
35 |
+
return this.colFromString(arg);
|
36 |
+
}
|
37 |
+
return arg;
|
38 |
+
});
|
39 |
+
this.rows.push(cols);
|
40 |
+
return cols;
|
41 |
+
}
|
42 |
+
shouldApplyLayoutDSL(...args) {
|
43 |
+
return args.length === 1 && typeof args[0] === 'string' &&
|
44 |
+
/[\t\n]/.test(args[0]);
|
45 |
+
}
|
46 |
+
applyLayoutDSL(str) {
|
47 |
+
const rows = str.split('\n').map(row => row.split('\t'));
|
48 |
+
let leftColumnWidth = 0;
|
49 |
+
// simple heuristic for layout, make sure the
|
50 |
+
// second column lines up along the left-hand.
|
51 |
+
// don't allow the first column to take up more
|
52 |
+
// than 50% of the screen.
|
53 |
+
rows.forEach(columns => {
|
54 |
+
if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
|
55 |
+
leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
|
56 |
+
}
|
57 |
+
});
|
58 |
+
// generate a table:
|
59 |
+
// replacing ' ' with padding calculations.
|
60 |
+
// using the algorithmically generated width.
|
61 |
+
rows.forEach(columns => {
|
62 |
+
this.div(...columns.map((r, i) => {
|
63 |
+
return {
|
64 |
+
text: r.trim(),
|
65 |
+
padding: this.measurePadding(r),
|
66 |
+
width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
|
67 |
+
};
|
68 |
+
}));
|
69 |
+
});
|
70 |
+
return this.rows[this.rows.length - 1];
|
71 |
+
}
|
72 |
+
colFromString(text) {
|
73 |
+
return {
|
74 |
+
text,
|
75 |
+
padding: this.measurePadding(text)
|
76 |
+
};
|
77 |
+
}
|
78 |
+
measurePadding(str) {
|
79 |
+
// measure padding without ansi escape codes
|
80 |
+
const noAnsi = mixin.stripAnsi(str);
|
81 |
+
return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
|
82 |
+
}
|
83 |
+
toString() {
|
84 |
+
const lines = [];
|
85 |
+
this.rows.forEach(row => {
|
86 |
+
this.rowToString(row, lines);
|
87 |
+
});
|
88 |
+
// don't display any lines with the
|
89 |
+
// hidden flag set.
|
90 |
+
return lines
|
91 |
+
.filter(line => !line.hidden)
|
92 |
+
.map(line => line.text)
|
93 |
+
.join('\n');
|
94 |
+
}
|
95 |
+
rowToString(row, lines) {
|
96 |
+
this.rasterize(row).forEach((rrow, r) => {
|
97 |
+
let str = '';
|
98 |
+
rrow.forEach((col, c) => {
|
99 |
+
const { width } = row[c]; // the width with padding.
|
100 |
+
const wrapWidth = this.negatePadding(row[c]); // the width without padding.
|
101 |
+
let ts = col; // temporary string used during alignment/padding.
|
102 |
+
if (wrapWidth > mixin.stringWidth(col)) {
|
103 |
+
ts += ' '.repeat(wrapWidth - mixin.stringWidth(col));
|
104 |
+
}
|
105 |
+
// align the string within its column.
|
106 |
+
if (row[c].align && row[c].align !== 'left' && this.wrap) {
|
107 |
+
const fn = align[row[c].align];
|
108 |
+
ts = fn(ts, wrapWidth);
|
109 |
+
if (mixin.stringWidth(ts) < wrapWidth) {
|
110 |
+
/* c8 ignore start */
|
111 |
+
const w = width || 0;
|
112 |
+
/* c8 ignore stop */
|
113 |
+
ts += ' '.repeat(w - mixin.stringWidth(ts) - 1);
|
114 |
+
}
|
115 |
+
}
|
116 |
+
// apply border and padding to string.
|
117 |
+
const padding = row[c].padding || [0, 0, 0, 0];
|
118 |
+
if (padding[left]) {
|
119 |
+
str += ' '.repeat(padding[left]);
|
120 |
+
}
|
121 |
+
str += addBorder(row[c], ts, '| ');
|
122 |
+
str += ts;
|
123 |
+
str += addBorder(row[c], ts, ' |');
|
124 |
+
if (padding[right]) {
|
125 |
+
str += ' '.repeat(padding[right]);
|
126 |
+
}
|
127 |
+
// if prior row is span, try to render the
|
128 |
+
// current row on the prior line.
|
129 |
+
if (r === 0 && lines.length > 0) {
|
130 |
+
str = this.renderInline(str, lines[lines.length - 1]);
|
131 |
+
}
|
132 |
+
});
|
133 |
+
// remove trailing whitespace.
|
134 |
+
lines.push({
|
135 |
+
text: str.replace(/ +$/, ''),
|
136 |
+
span: row.span
|
137 |
+
});
|
138 |
+
});
|
139 |
+
return lines;
|
140 |
+
}
|
141 |
+
// if the full 'source' can render in
|
142 |
+
// the target line, do so.
|
143 |
+
renderInline(source, previousLine) {
|
144 |
+
const match = source.match(/^ */);
|
145 |
+
/* c8 ignore start */
|
146 |
+
const leadingWhitespace = match ? match[0].length : 0;
|
147 |
+
/* c8 ignore stop */
|
148 |
+
const target = previousLine.text;
|
149 |
+
const targetTextWidth = mixin.stringWidth(target.trimEnd());
|
150 |
+
if (!previousLine.span) {
|
151 |
+
return source;
|
152 |
+
}
|
153 |
+
// if we're not applying wrapping logic,
|
154 |
+
// just always append to the span.
|
155 |
+
if (!this.wrap) {
|
156 |
+
previousLine.hidden = true;
|
157 |
+
return target + source;
|
158 |
+
}
|
159 |
+
if (leadingWhitespace < targetTextWidth) {
|
160 |
+
return source;
|
161 |
+
}
|
162 |
+
previousLine.hidden = true;
|
163 |
+
return target.trimEnd() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimStart();
|
164 |
+
}
|
165 |
+
rasterize(row) {
|
166 |
+
const rrows = [];
|
167 |
+
const widths = this.columnWidths(row);
|
168 |
+
let wrapped;
|
169 |
+
// word wrap all columns, and create
|
170 |
+
// a data-structure that is easy to rasterize.
|
171 |
+
row.forEach((col, c) => {
|
172 |
+
// leave room for left and right padding.
|
173 |
+
col.width = widths[c];
|
174 |
+
if (this.wrap) {
|
175 |
+
wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n');
|
176 |
+
}
|
177 |
+
else {
|
178 |
+
wrapped = col.text.split('\n');
|
179 |
+
}
|
180 |
+
if (col.border) {
|
181 |
+
wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.');
|
182 |
+
wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'");
|
183 |
+
}
|
184 |
+
// add top and bottom padding.
|
185 |
+
if (col.padding) {
|
186 |
+
wrapped.unshift(...new Array(col.padding[top] || 0).fill(''));
|
187 |
+
wrapped.push(...new Array(col.padding[bottom] || 0).fill(''));
|
188 |
+
}
|
189 |
+
wrapped.forEach((str, r) => {
|
190 |
+
if (!rrows[r]) {
|
191 |
+
rrows.push([]);
|
192 |
+
}
|
193 |
+
const rrow = rrows[r];
|
194 |
+
for (let i = 0; i < c; i++) {
|
195 |
+
if (rrow[i] === undefined) {
|
196 |
+
rrow.push('');
|
197 |
+
}
|
198 |
+
}
|
199 |
+
rrow.push(str);
|
200 |
+
});
|
201 |
+
});
|
202 |
+
return rrows;
|
203 |
+
}
|
204 |
+
negatePadding(col) {
|
205 |
+
/* c8 ignore start */
|
206 |
+
let wrapWidth = col.width || 0;
|
207 |
+
/* c8 ignore stop */
|
208 |
+
if (col.padding) {
|
209 |
+
wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
|
210 |
+
}
|
211 |
+
if (col.border) {
|
212 |
+
wrapWidth -= 4;
|
213 |
+
}
|
214 |
+
return wrapWidth;
|
215 |
+
}
|
216 |
+
columnWidths(row) {
|
217 |
+
if (!this.wrap) {
|
218 |
+
return row.map(col => {
|
219 |
+
return col.width || mixin.stringWidth(col.text);
|
220 |
+
});
|
221 |
+
}
|
222 |
+
let unset = row.length;
|
223 |
+
let remainingWidth = this.width;
|
224 |
+
// column widths can be set in config.
|
225 |
+
const widths = row.map(col => {
|
226 |
+
if (col.width) {
|
227 |
+
unset--;
|
228 |
+
remainingWidth -= col.width;
|
229 |
+
return col.width;
|
230 |
+
}
|
231 |
+
return undefined;
|
232 |
+
});
|
233 |
+
// any unset widths should be calculated.
|
234 |
+
/* c8 ignore start */
|
235 |
+
const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
|
236 |
+
/* c8 ignore stop */
|
237 |
+
return widths.map((w, i) => {
|
238 |
+
if (w === undefined) {
|
239 |
+
return Math.max(unsetWidth, _minWidth(row[i]));
|
240 |
+
}
|
241 |
+
return w;
|
242 |
+
});
|
243 |
+
}
|
244 |
+
}
|
245 |
+
function addBorder(col, ts, style) {
|
246 |
+
if (col.border) {
|
247 |
+
if (/[.']-+[.']/.test(ts)) {
|
248 |
+
return '';
|
249 |
+
}
|
250 |
+
if (ts.trim().length !== 0) {
|
251 |
+
return style;
|
252 |
+
}
|
253 |
+
return ' ';
|
254 |
+
}
|
255 |
+
return '';
|
256 |
+
}
|
257 |
+
// calculates the minimum width of
|
258 |
+
// a column, based on padding preferences.
|
259 |
+
function _minWidth(col) {
|
260 |
+
const padding = col.padding || [];
|
261 |
+
const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
|
262 |
+
if (col.border) {
|
263 |
+
return minWidth + 4;
|
264 |
+
}
|
265 |
+
return minWidth;
|
266 |
+
}
|
267 |
+
function getWindowWidth() {
|
268 |
+
/* c8 ignore start */
|
269 |
+
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
|
270 |
+
return process.stdout.columns;
|
271 |
+
}
|
272 |
+
return 80;
|
273 |
+
}
|
274 |
+
/* c8 ignore stop */
|
275 |
+
function alignRight(str, width) {
|
276 |
+
str = str.trim();
|
277 |
+
const strWidth = mixin.stringWidth(str);
|
278 |
+
if (strWidth < width) {
|
279 |
+
return ' '.repeat(width - strWidth) + str;
|
280 |
+
}
|
281 |
+
return str;
|
282 |
+
}
|
283 |
+
function alignCenter(str, width) {
|
284 |
+
str = str.trim();
|
285 |
+
const strWidth = mixin.stringWidth(str);
|
286 |
+
/* c8 ignore start */
|
287 |
+
if (strWidth >= width) {
|
288 |
+
return str;
|
289 |
+
}
|
290 |
+
/* c8 ignore stop */
|
291 |
+
return ' '.repeat((width - strWidth) >> 1) + str;
|
292 |
+
}
|
293 |
+
let mixin;
|
294 |
+
export function cliui(opts, _mixin) {
|
295 |
+
mixin = _mixin;
|
296 |
+
return new UI({
|
297 |
+
/* c8 ignore start */
|
298 |
+
width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
|
299 |
+
wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
|
300 |
+
/* c8 ignore stop */
|
301 |
+
});
|
302 |
+
}
|
node_modules/@isaacs/cliui/index.mjs
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Bootstrap cliui with ESM dependencies:
|
2 |
+
import { cliui } from './build/lib/index.js'
|
3 |
+
|
4 |
+
import stringWidth from 'string-width'
|
5 |
+
import stripAnsi from 'strip-ansi'
|
6 |
+
import wrap from 'wrap-ansi'
|
7 |
+
|
8 |
+
export default function ui (opts) {
|
9 |
+
return cliui(opts, {
|
10 |
+
stringWidth,
|
11 |
+
stripAnsi,
|
12 |
+
wrap
|
13 |
+
})
|
14 |
+
}
|
node_modules/@isaacs/cliui/package.json
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@isaacs/cliui",
|
3 |
+
"version": "8.0.2",
|
4 |
+
"description": "easily create complex multi-column command-line-interfaces",
|
5 |
+
"main": "build/index.cjs",
|
6 |
+
"exports": {
|
7 |
+
".": [
|
8 |
+
{
|
9 |
+
"import": "./index.mjs",
|
10 |
+
"require": "./build/index.cjs"
|
11 |
+
},
|
12 |
+
"./build/index.cjs"
|
13 |
+
]
|
14 |
+
},
|
15 |
+
"type": "module",
|
16 |
+
"module": "./index.mjs",
|
17 |
+
"scripts": {
|
18 |
+
"check": "standardx '**/*.ts' && standardx '**/*.js' && standardx '**/*.cjs'",
|
19 |
+
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js' && standardx --fix '**/*.cjs'",
|
20 |
+
"pretest": "rimraf build && tsc -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs",
|
21 |
+
"test": "c8 mocha ./test/*.cjs",
|
22 |
+
"test:esm": "c8 mocha ./test/**/*.mjs",
|
23 |
+
"postest": "check",
|
24 |
+
"coverage": "c8 report --check-coverage",
|
25 |
+
"precompile": "rimraf build",
|
26 |
+
"compile": "tsc",
|
27 |
+
"postcompile": "npm run build:cjs",
|
28 |
+
"build:cjs": "rollup -c",
|
29 |
+
"prepare": "npm run compile"
|
30 |
+
},
|
31 |
+
"repository": "yargs/cliui",
|
32 |
+
"standard": {
|
33 |
+
"ignore": [
|
34 |
+
"**/example/**"
|
35 |
+
],
|
36 |
+
"globals": [
|
37 |
+
"it"
|
38 |
+
]
|
39 |
+
},
|
40 |
+
"keywords": [
|
41 |
+
"cli",
|
42 |
+
"command-line",
|
43 |
+
"layout",
|
44 |
+
"design",
|
45 |
+
"console",
|
46 |
+
"wrap",
|
47 |
+
"table"
|
48 |
+
],
|
49 |
+
"author": "Ben Coe <[email protected]>",
|
50 |
+
"license": "ISC",
|
51 |
+
"dependencies": {
|
52 |
+
"string-width": "^5.1.2",
|
53 |
+
"string-width-cjs": "npm:string-width@^4.2.0",
|
54 |
+
"strip-ansi": "^7.0.1",
|
55 |
+
"strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
|
56 |
+
"wrap-ansi": "^8.1.0",
|
57 |
+
"wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"
|
58 |
+
},
|
59 |
+
"devDependencies": {
|
60 |
+
"@types/node": "^14.0.27",
|
61 |
+
"@typescript-eslint/eslint-plugin": "^4.0.0",
|
62 |
+
"@typescript-eslint/parser": "^4.0.0",
|
63 |
+
"c8": "^7.3.0",
|
64 |
+
"chai": "^4.2.0",
|
65 |
+
"chalk": "^4.1.0",
|
66 |
+
"cross-env": "^7.0.2",
|
67 |
+
"eslint": "^7.6.0",
|
68 |
+
"eslint-plugin-import": "^2.22.0",
|
69 |
+
"eslint-plugin-node": "^11.1.0",
|
70 |
+
"gts": "^3.0.0",
|
71 |
+
"mocha": "^10.0.0",
|
72 |
+
"rimraf": "^3.0.2",
|
73 |
+
"rollup": "^2.23.1",
|
74 |
+
"rollup-plugin-ts": "^3.0.2",
|
75 |
+
"standardx": "^7.0.0",
|
76 |
+
"typescript": "^4.0.0"
|
77 |
+
},
|
78 |
+
"files": [
|
79 |
+
"build",
|
80 |
+
"index.mjs",
|
81 |
+
"!*.d.ts"
|
82 |
+
],
|
83 |
+
"engines": {
|
84 |
+
"node": ">=12"
|
85 |
+
}
|
86 |
+
}
|
node_modules/@npmcli/agent/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## @npmcli/agent
|
2 |
+
|
3 |
+
A pair of Agent implementations for nodejs that provide consistent keep-alives, granular timeouts, dns caching, and proxy support.
|
4 |
+
|
5 |
+
### Usage
|
6 |
+
|
7 |
+
```js
|
8 |
+
const { getAgent, HttpAgent } = require('@npmcli/agent')
|
9 |
+
const fetch = require('minipass-fetch')
|
10 |
+
|
11 |
+
const main = async () => {
|
12 |
+
// if you know what agent you need, you can create one directly
|
13 |
+
const agent = new HttpAgent(agentOptions)
|
14 |
+
// or you can use the getAgent helper, it will determine and create an Agent
|
15 |
+
// instance for you as well as reuse that agent for new requests as appropriate
|
16 |
+
const agent = getAgent('https://registry.npmjs.org/npm', agentOptions)
|
17 |
+
// minipass-fetch is just an example, this will work for any http client that
|
18 |
+
// supports node's Agents
|
19 |
+
const res = await fetch('https://registry.npmjs.org/npm', { agent })
|
20 |
+
}
|
21 |
+
|
22 |
+
main()
|
23 |
+
```
|
24 |
+
|
25 |
+
### Options
|
26 |
+
|
27 |
+
All options supported by the node Agent implementations are supported here, see [the docs](https://nodejs.org/api/http.html#new-agentoptions) for those.
|
28 |
+
|
29 |
+
Options that have been added by this module include:
|
30 |
+
|
31 |
+
- `family`: what tcp family to use, can be `4` for IPv4, `6` for IPv6 or `0` for both.
|
32 |
+
- `proxy`: a URL to a supported proxy, currently supports `HTTP CONNECT` based http/https proxies as well as socks4 and 5.
|
33 |
+
- `dns`: configuration for the built-in dns cache
|
34 |
+
- `ttl`: how long (in milliseconds) to keep cached dns entries, defaults to `5 * 60 * 100 (5 minutes)`
|
35 |
+
- `lookup`: optional function to override how dns lookups are performed, defaults to `require('dns').lookup`
|
36 |
+
- `timeouts`: a set of granular timeouts, all default to `0`
|
37 |
+
- `connection`: time between initiating connection and actually connecting
|
38 |
+
- `idle`: time between data packets (if a top level `timeout` is provided, it will be copied here)
|
39 |
+
- `response`: time between sending a request and receiving a response
|
40 |
+
- `transfer`: time between starting to receive a request and consuming the response fully
|
node_modules/@npmcli/agent/lib/agents.js
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
const net = require('net')
|
4 |
+
const tls = require('tls')
|
5 |
+
const { once } = require('events')
|
6 |
+
const timers = require('timers/promises')
|
7 |
+
const { normalizeOptions, cacheOptions } = require('./options')
|
8 |
+
const { getProxy, getProxyAgent, proxyCache } = require('./proxy.js')
|
9 |
+
const Errors = require('./errors.js')
|
10 |
+
const { Agent: AgentBase } = require('agent-base')
|
11 |
+
|
12 |
+
module.exports = class Agent extends AgentBase {
|
13 |
+
#options
|
14 |
+
#timeouts
|
15 |
+
#proxy
|
16 |
+
#noProxy
|
17 |
+
#ProxyAgent
|
18 |
+
|
19 |
+
constructor (options = {}) {
|
20 |
+
const { timeouts, proxy, noProxy, ...normalizedOptions } = normalizeOptions(options)
|
21 |
+
|
22 |
+
super(normalizedOptions)
|
23 |
+
|
24 |
+
this.#options = normalizedOptions
|
25 |
+
this.#timeouts = timeouts
|
26 |
+
|
27 |
+
if (proxy) {
|
28 |
+
this.#proxy = new URL(proxy)
|
29 |
+
this.#noProxy = noProxy
|
30 |
+
this.#ProxyAgent = getProxyAgent(proxy)
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
get proxy () {
|
35 |
+
return this.#proxy ? { url: this.#proxy } : {}
|
36 |
+
}
|
37 |
+
|
38 |
+
#getProxy (options) {
|
39 |
+
if (!this.#proxy) {
|
40 |
+
return
|
41 |
+
}
|
42 |
+
|
43 |
+
const proxy = getProxy(`${options.protocol}//${options.host}:${options.port}`, {
|
44 |
+
proxy: this.#proxy,
|
45 |
+
noProxy: this.#noProxy,
|
46 |
+
})
|
47 |
+
|
48 |
+
if (!proxy) {
|
49 |
+
return
|
50 |
+
}
|
51 |
+
|
52 |
+
const cacheKey = cacheOptions({
|
53 |
+
...options,
|
54 |
+
...this.#options,
|
55 |
+
timeouts: this.#timeouts,
|
56 |
+
proxy,
|
57 |
+
})
|
58 |
+
|
59 |
+
if (proxyCache.has(cacheKey)) {
|
60 |
+
return proxyCache.get(cacheKey)
|
61 |
+
}
|
62 |
+
|
63 |
+
let ProxyAgent = this.#ProxyAgent
|
64 |
+
if (Array.isArray(ProxyAgent)) {
|
65 |
+
ProxyAgent = options.secureEndpoint ? ProxyAgent[1] : ProxyAgent[0]
|
66 |
+
}
|
67 |
+
|
68 |
+
const proxyAgent = new ProxyAgent(proxy, this.#options)
|
69 |
+
proxyCache.set(cacheKey, proxyAgent)
|
70 |
+
|
71 |
+
return proxyAgent
|
72 |
+
}
|
73 |
+
|
74 |
+
// takes an array of promises and races them against the connection timeout
|
75 |
+
// which will throw the necessary error if it is hit. This will return the
|
76 |
+
// result of the promise race.
|
77 |
+
async #timeoutConnection ({ promises, options, timeout }, ac = new AbortController()) {
|
78 |
+
if (timeout) {
|
79 |
+
const connectionTimeout = timers.setTimeout(timeout, null, { signal: ac.signal })
|
80 |
+
.then(() => {
|
81 |
+
throw new Errors.ConnectionTimeoutError(`${options.host}:${options.port}`)
|
82 |
+
}).catch((err) => {
|
83 |
+
if (err.name === 'AbortError') {
|
84 |
+
return
|
85 |
+
}
|
86 |
+
throw err
|
87 |
+
})
|
88 |
+
promises.push(connectionTimeout)
|
89 |
+
}
|
90 |
+
|
91 |
+
let result
|
92 |
+
try {
|
93 |
+
result = await Promise.race(promises)
|
94 |
+
ac.abort()
|
95 |
+
} catch (err) {
|
96 |
+
ac.abort()
|
97 |
+
throw err
|
98 |
+
}
|
99 |
+
return result
|
100 |
+
}
|
101 |
+
|
102 |
+
async connect (request, options) {
|
103 |
+
// if the connection does not have its own lookup function
|
104 |
+
// set, then use the one from our options
|
105 |
+
options.lookup ??= this.#options.lookup
|
106 |
+
|
107 |
+
let socket
|
108 |
+
let timeout = this.#timeouts.connection
|
109 |
+
|
110 |
+
const proxy = this.#getProxy(options)
|
111 |
+
if (proxy) {
|
112 |
+
// some of the proxies will wait for the socket to fully connect before
|
113 |
+
// returning so we have to await this while also racing it against the
|
114 |
+
// connection timeout.
|
115 |
+
const start = Date.now()
|
116 |
+
socket = await this.#timeoutConnection({
|
117 |
+
options,
|
118 |
+
timeout,
|
119 |
+
promises: [proxy.connect(request, options)],
|
120 |
+
})
|
121 |
+
// see how much time proxy.connect took and subtract it from
|
122 |
+
// the timeout
|
123 |
+
if (timeout) {
|
124 |
+
timeout = timeout - (Date.now() - start)
|
125 |
+
}
|
126 |
+
} else {
|
127 |
+
socket = (options.secureEndpoint ? tls : net).connect(options)
|
128 |
+
}
|
129 |
+
|
130 |
+
socket.setKeepAlive(this.keepAlive, this.keepAliveMsecs)
|
131 |
+
socket.setNoDelay(this.keepAlive)
|
132 |
+
|
133 |
+
const abortController = new AbortController()
|
134 |
+
const { signal } = abortController
|
135 |
+
|
136 |
+
const connectPromise = socket[options.secureEndpoint ? 'secureConnecting' : 'connecting']
|
137 |
+
? once(socket, options.secureEndpoint ? 'secureConnect' : 'connect', { signal })
|
138 |
+
: Promise.resolve()
|
139 |
+
|
140 |
+
await this.#timeoutConnection({
|
141 |
+
options,
|
142 |
+
timeout,
|
143 |
+
promises: [
|
144 |
+
connectPromise,
|
145 |
+
once(socket, 'error', { signal }).then((err) => {
|
146 |
+
throw err[0]
|
147 |
+
}),
|
148 |
+
],
|
149 |
+
}, abortController)
|
150 |
+
|
151 |
+
if (this.#timeouts.idle) {
|
152 |
+
socket.setTimeout(this.#timeouts.idle, () => {
|
153 |
+
socket.destroy(new Errors.IdleTimeoutError(`${options.host}:${options.port}`))
|
154 |
+
})
|
155 |
+
}
|
156 |
+
|
157 |
+
return socket
|
158 |
+
}
|
159 |
+
|
160 |
+
addRequest (request, options) {
|
161 |
+
const proxy = this.#getProxy(options)
|
162 |
+
// it would be better to call proxy.addRequest here but this causes the
|
163 |
+
// http-proxy-agent to call its super.addRequest which causes the request
|
164 |
+
// to be added to the agent twice. since we only support 3 agents
|
165 |
+
// currently (see the required agents in proxy.js) we have manually
|
166 |
+
// checked that the only public methods we need to call are called in the
|
167 |
+
// next block. this could change in the future and presumably we would get
|
168 |
+
// failing tests until we have properly called the necessary methods on
|
169 |
+
// each of our proxy agents
|
170 |
+
if (proxy?.setRequestProps) {
|
171 |
+
proxy.setRequestProps(request, options)
|
172 |
+
}
|
173 |
+
|
174 |
+
request.setHeader('connection', this.keepAlive ? 'keep-alive' : 'close')
|
175 |
+
|
176 |
+
if (this.#timeouts.response) {
|
177 |
+
let responseTimeout
|
178 |
+
request.once('finish', () => {
|
179 |
+
setTimeout(() => {
|
180 |
+
request.destroy(new Errors.ResponseTimeoutError(request, this.#proxy))
|
181 |
+
}, this.#timeouts.response)
|
182 |
+
})
|
183 |
+
request.once('response', () => {
|
184 |
+
clearTimeout(responseTimeout)
|
185 |
+
})
|
186 |
+
}
|
187 |
+
|
188 |
+
if (this.#timeouts.transfer) {
|
189 |
+
let transferTimeout
|
190 |
+
request.once('response', (res) => {
|
191 |
+
setTimeout(() => {
|
192 |
+
res.destroy(new Errors.TransferTimeoutError(request, this.#proxy))
|
193 |
+
}, this.#timeouts.transfer)
|
194 |
+
res.once('close', () => {
|
195 |
+
clearTimeout(transferTimeout)
|
196 |
+
})
|
197 |
+
})
|
198 |
+
}
|
199 |
+
|
200 |
+
return super.addRequest(request, options)
|
201 |
+
}
|
202 |
+
}
|
node_modules/@npmcli/agent/lib/dns.js
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
const { LRUCache } = require('lru-cache')
|
4 |
+
const dns = require('dns')
|
5 |
+
|
6 |
+
// this is a factory so that each request can have its own opts (i.e. ttl)
|
7 |
+
// while still sharing the cache across all requests
|
8 |
+
const cache = new LRUCache({ max: 50 })
|
9 |
+
|
10 |
+
const getOptions = ({
|
11 |
+
family = 0,
|
12 |
+
hints = dns.ADDRCONFIG,
|
13 |
+
all = false,
|
14 |
+
verbatim = undefined,
|
15 |
+
ttl = 5 * 60 * 1000,
|
16 |
+
lookup = dns.lookup,
|
17 |
+
}) => ({
|
18 |
+
// hints and lookup are returned since both are top level properties to (net|tls).connect
|
19 |
+
hints,
|
20 |
+
lookup: (hostname, ...args) => {
|
21 |
+
const callback = args.pop() // callback is always last arg
|
22 |
+
const lookupOptions = args[0] ?? {}
|
23 |
+
|
24 |
+
const options = {
|
25 |
+
family,
|
26 |
+
hints,
|
27 |
+
all,
|
28 |
+
verbatim,
|
29 |
+
...(typeof lookupOptions === 'number' ? { family: lookupOptions } : lookupOptions),
|
30 |
+
}
|
31 |
+
|
32 |
+
const key = JSON.stringify({ hostname, ...options })
|
33 |
+
|
34 |
+
if (cache.has(key)) {
|
35 |
+
const cached = cache.get(key)
|
36 |
+
return process.nextTick(callback, null, ...cached)
|
37 |
+
}
|
38 |
+
|
39 |
+
lookup(hostname, options, (err, ...result) => {
|
40 |
+
if (err) {
|
41 |
+
return callback(err)
|
42 |
+
}
|
43 |
+
|
44 |
+
cache.set(key, result, { ttl })
|
45 |
+
return callback(null, ...result)
|
46 |
+
})
|
47 |
+
},
|
48 |
+
})
|
49 |
+
|
50 |
+
module.exports = {
|
51 |
+
cache,
|
52 |
+
getOptions,
|
53 |
+
}
|
node_modules/@npmcli/agent/lib/errors.js
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
class InvalidProxyProtocolError extends Error {
|
4 |
+
constructor (url) {
|
5 |
+
super(`Invalid protocol \`${url.protocol}\` connecting to proxy \`${url.host}\``)
|
6 |
+
this.code = 'EINVALIDPROXY'
|
7 |
+
this.proxy = url
|
8 |
+
}
|
9 |
+
}
|
10 |
+
|
11 |
+
class ConnectionTimeoutError extends Error {
|
12 |
+
constructor (host) {
|
13 |
+
super(`Timeout connecting to host \`${host}\``)
|
14 |
+
this.code = 'ECONNECTIONTIMEOUT'
|
15 |
+
this.host = host
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
class IdleTimeoutError extends Error {
|
20 |
+
constructor (host) {
|
21 |
+
super(`Idle timeout reached for host \`${host}\``)
|
22 |
+
this.code = 'EIDLETIMEOUT'
|
23 |
+
this.host = host
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
class ResponseTimeoutError extends Error {
|
28 |
+
constructor (request, proxy) {
|
29 |
+
let msg = 'Response timeout '
|
30 |
+
if (proxy) {
|
31 |
+
msg += `from proxy \`${proxy.host}\` `
|
32 |
+
}
|
33 |
+
msg += `connecting to host \`${request.host}\``
|
34 |
+
super(msg)
|
35 |
+
this.code = 'ERESPONSETIMEOUT'
|
36 |
+
this.proxy = proxy
|
37 |
+
this.request = request
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
class TransferTimeoutError extends Error {
|
42 |
+
constructor (request, proxy) {
|
43 |
+
let msg = 'Transfer timeout '
|
44 |
+
if (proxy) {
|
45 |
+
msg += `from proxy \`${proxy.host}\` `
|
46 |
+
}
|
47 |
+
msg += `for \`${request.host}\``
|
48 |
+
super(msg)
|
49 |
+
this.code = 'ETRANSFERTIMEOUT'
|
50 |
+
this.proxy = proxy
|
51 |
+
this.request = request
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
module.exports = {
|
56 |
+
InvalidProxyProtocolError,
|
57 |
+
ConnectionTimeoutError,
|
58 |
+
IdleTimeoutError,
|
59 |
+
ResponseTimeoutError,
|
60 |
+
TransferTimeoutError,
|
61 |
+
}
|
node_modules/@npmcli/agent/lib/index.js
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
const { LRUCache } = require('lru-cache')
|
4 |
+
const { normalizeOptions, cacheOptions } = require('./options')
|
5 |
+
const { getProxy, proxyCache } = require('./proxy.js')
|
6 |
+
const dns = require('./dns.js')
|
7 |
+
const Agent = require('./agents.js')
|
8 |
+
|
9 |
+
const agentCache = new LRUCache({ max: 20 })
|
10 |
+
|
11 |
+
const getAgent = (url, { agent, proxy, noProxy, ...options } = {}) => {
|
12 |
+
// false has meaning so this can't be a simple truthiness check
|
13 |
+
if (agent != null) {
|
14 |
+
return agent
|
15 |
+
}
|
16 |
+
|
17 |
+
url = new URL(url)
|
18 |
+
|
19 |
+
const proxyForUrl = getProxy(url, { proxy, noProxy })
|
20 |
+
const normalizedOptions = {
|
21 |
+
...normalizeOptions(options),
|
22 |
+
proxy: proxyForUrl,
|
23 |
+
}
|
24 |
+
|
25 |
+
const cacheKey = cacheOptions({
|
26 |
+
...normalizedOptions,
|
27 |
+
secureEndpoint: url.protocol === 'https:',
|
28 |
+
})
|
29 |
+
|
30 |
+
if (agentCache.has(cacheKey)) {
|
31 |
+
return agentCache.get(cacheKey)
|
32 |
+
}
|
33 |
+
|
34 |
+
const newAgent = new Agent(normalizedOptions)
|
35 |
+
agentCache.set(cacheKey, newAgent)
|
36 |
+
|
37 |
+
return newAgent
|
38 |
+
}
|
39 |
+
|
40 |
+
module.exports = {
|
41 |
+
getAgent,
|
42 |
+
Agent,
|
43 |
+
// these are exported for backwards compatability
|
44 |
+
HttpAgent: Agent,
|
45 |
+
HttpsAgent: Agent,
|
46 |
+
cache: {
|
47 |
+
proxy: proxyCache,
|
48 |
+
agent: agentCache,
|
49 |
+
dns: dns.cache,
|
50 |
+
clear: () => {
|
51 |
+
proxyCache.clear()
|
52 |
+
agentCache.clear()
|
53 |
+
dns.cache.clear()
|
54 |
+
},
|
55 |
+
},
|
56 |
+
}
|
node_modules/@npmcli/agent/lib/options.js
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
const dns = require('./dns')
|
4 |
+
|
5 |
+
const normalizeOptions = (opts) => {
|
6 |
+
const family = parseInt(opts.family ?? '0', 10)
|
7 |
+
const keepAlive = opts.keepAlive ?? true
|
8 |
+
|
9 |
+
const normalized = {
|
10 |
+
// nodejs http agent options. these are all the defaults
|
11 |
+
// but kept here to increase the likelihood of cache hits
|
12 |
+
// https://nodejs.org/api/http.html#new-agentoptions
|
13 |
+
keepAliveMsecs: keepAlive ? 1000 : undefined,
|
14 |
+
maxSockets: opts.maxSockets ?? 15,
|
15 |
+
maxTotalSockets: Infinity,
|
16 |
+
maxFreeSockets: keepAlive ? 256 : undefined,
|
17 |
+
scheduling: 'fifo',
|
18 |
+
// then spread the rest of the options
|
19 |
+
...opts,
|
20 |
+
// we already set these to their defaults that we want
|
21 |
+
family,
|
22 |
+
keepAlive,
|
23 |
+
// our custom timeout options
|
24 |
+
timeouts: {
|
25 |
+
// the standard timeout option is mapped to our idle timeout
|
26 |
+
// and then deleted below
|
27 |
+
idle: opts.timeout ?? 0,
|
28 |
+
connection: 0,
|
29 |
+
response: 0,
|
30 |
+
transfer: 0,
|
31 |
+
...opts.timeouts,
|
32 |
+
},
|
33 |
+
// get the dns options that go at the top level of socket connection
|
34 |
+
...dns.getOptions({ family, ...opts.dns }),
|
35 |
+
}
|
36 |
+
|
37 |
+
// remove timeout since we already used it to set our own idle timeout
|
38 |
+
delete normalized.timeout
|
39 |
+
|
40 |
+
return normalized
|
41 |
+
}
|
42 |
+
|
43 |
+
const createKey = (obj) => {
|
44 |
+
let key = ''
|
45 |
+
const sorted = Object.entries(obj).sort((a, b) => a[0] - b[0])
|
46 |
+
for (let [k, v] of sorted) {
|
47 |
+
if (v == null) {
|
48 |
+
v = 'null'
|
49 |
+
} else if (v instanceof URL) {
|
50 |
+
v = v.toString()
|
51 |
+
} else if (typeof v === 'object') {
|
52 |
+
v = createKey(v)
|
53 |
+
}
|
54 |
+
key += `${k}:${v}:`
|
55 |
+
}
|
56 |
+
return key
|
57 |
+
}
|
58 |
+
|
59 |
+
const cacheOptions = ({ secureEndpoint, ...options }) => createKey({
|
60 |
+
secureEndpoint: !!secureEndpoint,
|
61 |
+
// socket connect options
|
62 |
+
family: options.family,
|
63 |
+
hints: options.hints,
|
64 |
+
localAddress: options.localAddress,
|
65 |
+
// tls specific connect options
|
66 |
+
strictSsl: secureEndpoint ? !!options.rejectUnauthorized : false,
|
67 |
+
ca: secureEndpoint ? options.ca : null,
|
68 |
+
cert: secureEndpoint ? options.cert : null,
|
69 |
+
key: secureEndpoint ? options.key : null,
|
70 |
+
// http agent options
|
71 |
+
keepAlive: options.keepAlive,
|
72 |
+
keepAliveMsecs: options.keepAliveMsecs,
|
73 |
+
maxSockets: options.maxSockets,
|
74 |
+
maxTotalSockets: options.maxTotalSockets,
|
75 |
+
maxFreeSockets: options.maxFreeSockets,
|
76 |
+
scheduling: options.scheduling,
|
77 |
+
// timeout options
|
78 |
+
timeouts: options.timeouts,
|
79 |
+
// proxy
|
80 |
+
proxy: options.proxy,
|
81 |
+
})
|
82 |
+
|
83 |
+
module.exports = {
|
84 |
+
normalizeOptions,
|
85 |
+
cacheOptions,
|
86 |
+
}
|
node_modules/@npmcli/agent/lib/proxy.js
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
const { HttpProxyAgent } = require('http-proxy-agent')
|
4 |
+
const { HttpsProxyAgent } = require('https-proxy-agent')
|
5 |
+
const { SocksProxyAgent } = require('socks-proxy-agent')
|
6 |
+
const { LRUCache } = require('lru-cache')
|
7 |
+
const { InvalidProxyProtocolError } = require('./errors.js')
|
8 |
+
|
9 |
+
const PROXY_CACHE = new LRUCache({ max: 20 })
|
10 |
+
|
11 |
+
const SOCKS_PROTOCOLS = new Set(SocksProxyAgent.protocols)
|
12 |
+
|
13 |
+
const PROXY_ENV_KEYS = new Set(['https_proxy', 'http_proxy', 'proxy', 'no_proxy'])
|
14 |
+
|
15 |
+
const PROXY_ENV = Object.entries(process.env).reduce((acc, [key, value]) => {
|
16 |
+
key = key.toLowerCase()
|
17 |
+
if (PROXY_ENV_KEYS.has(key)) {
|
18 |
+
acc[key] = value
|
19 |
+
}
|
20 |
+
return acc
|
21 |
+
}, {})
|
22 |
+
|
23 |
+
const getProxyAgent = (url) => {
|
24 |
+
url = new URL(url)
|
25 |
+
|
26 |
+
const protocol = url.protocol.slice(0, -1)
|
27 |
+
if (SOCKS_PROTOCOLS.has(protocol)) {
|
28 |
+
return SocksProxyAgent
|
29 |
+
}
|
30 |
+
if (protocol === 'https' || protocol === 'http') {
|
31 |
+
return [HttpProxyAgent, HttpsProxyAgent]
|
32 |
+
}
|
33 |
+
|
34 |
+
throw new InvalidProxyProtocolError(url)
|
35 |
+
}
|
36 |
+
|
37 |
+
const isNoProxy = (url, noProxy) => {
|
38 |
+
if (typeof noProxy === 'string') {
|
39 |
+
noProxy = noProxy.split(',').map((p) => p.trim()).filter(Boolean)
|
40 |
+
}
|
41 |
+
|
42 |
+
if (!noProxy || !noProxy.length) {
|
43 |
+
return false
|
44 |
+
}
|
45 |
+
|
46 |
+
const hostSegments = url.hostname.split('.').reverse()
|
47 |
+
|
48 |
+
return noProxy.some((no) => {
|
49 |
+
const noSegments = no.split('.').filter(Boolean).reverse()
|
50 |
+
if (!noSegments.length) {
|
51 |
+
return false
|
52 |
+
}
|
53 |
+
|
54 |
+
for (let i = 0; i < noSegments.length; i++) {
|
55 |
+
if (hostSegments[i] !== noSegments[i]) {
|
56 |
+
return false
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
return true
|
61 |
+
})
|
62 |
+
}
|
63 |
+
|
64 |
+
const getProxy = (url, { proxy, noProxy }) => {
|
65 |
+
url = new URL(url)
|
66 |
+
|
67 |
+
if (!proxy) {
|
68 |
+
proxy = url.protocol === 'https:'
|
69 |
+
? PROXY_ENV.https_proxy
|
70 |
+
: PROXY_ENV.https_proxy || PROXY_ENV.http_proxy || PROXY_ENV.proxy
|
71 |
+
}
|
72 |
+
|
73 |
+
if (!noProxy) {
|
74 |
+
noProxy = PROXY_ENV.no_proxy
|
75 |
+
}
|
76 |
+
|
77 |
+
if (!proxy || isNoProxy(url, noProxy)) {
|
78 |
+
return null
|
79 |
+
}
|
80 |
+
|
81 |
+
return new URL(proxy)
|
82 |
+
}
|
83 |
+
|
84 |
+
module.exports = {
|
85 |
+
getProxyAgent,
|
86 |
+
getProxy,
|
87 |
+
proxyCache: PROXY_CACHE,
|
88 |
+
}
|
node_modules/@npmcli/agent/package.json
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@npmcli/agent",
|
3 |
+
"version": "2.2.0",
|
4 |
+
"description": "the http/https agent used by the npm cli",
|
5 |
+
"main": "lib/index.js",
|
6 |
+
"scripts": {
|
7 |
+
"gencerts": "bash scripts/create-cert.sh",
|
8 |
+
"test": "tap",
|
9 |
+
"lint": "eslint \"**/*.js\"",
|
10 |
+
"postlint": "template-oss-check",
|
11 |
+
"template-oss-apply": "template-oss-apply --force",
|
12 |
+
"lintfix": "npm run lint -- --fix",
|
13 |
+
"snap": "tap",
|
14 |
+
"posttest": "npm run lint"
|
15 |
+
},
|
16 |
+
"author": "GitHub Inc.",
|
17 |
+
"license": "ISC",
|
18 |
+
"bugs": {
|
19 |
+
"url": "https://github.com/npm/agent/issues"
|
20 |
+
},
|
21 |
+
"homepage": "https://github.com/npm/agent#readme",
|
22 |
+
"files": [
|
23 |
+
"bin/",
|
24 |
+
"lib/"
|
25 |
+
],
|
26 |
+
"engines": {
|
27 |
+
"node": "^16.14.0 || >=18.0.0"
|
28 |
+
},
|
29 |
+
"templateOSS": {
|
30 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
31 |
+
"version": "4.19.0",
|
32 |
+
"publish": "true"
|
33 |
+
},
|
34 |
+
"dependencies": {
|
35 |
+
"agent-base": "^7.1.0",
|
36 |
+
"http-proxy-agent": "^7.0.0",
|
37 |
+
"https-proxy-agent": "^7.0.1",
|
38 |
+
"lru-cache": "^10.0.1",
|
39 |
+
"socks-proxy-agent": "^8.0.1"
|
40 |
+
},
|
41 |
+
"devDependencies": {
|
42 |
+
"@npmcli/eslint-config": "^4.0.0",
|
43 |
+
"@npmcli/template-oss": "4.19.0",
|
44 |
+
"minipass-fetch": "^3.0.3",
|
45 |
+
"nock": "^13.2.7",
|
46 |
+
"semver": "^7.5.4",
|
47 |
+
"simple-socks": "^3.1.0",
|
48 |
+
"tap": "^16.3.0"
|
49 |
+
},
|
50 |
+
"repository": {
|
51 |
+
"type": "git",
|
52 |
+
"url": "https://github.com/npm/agent.git"
|
53 |
+
},
|
54 |
+
"tap": {
|
55 |
+
"nyc-arg": [
|
56 |
+
"--exclude",
|
57 |
+
"tap-snapshots/**"
|
58 |
+
]
|
59 |
+
}
|
60 |
+
}
|
node_modules/@npmcli/fs/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
|
2 |
+
|
3 |
+
ISC License
|
4 |
+
|
5 |
+
Copyright npm, Inc.
|
6 |
+
|
7 |
+
Permission to use, copy, modify, and/or distribute this
|
8 |
+
software for any purpose with or without fee is hereby
|
9 |
+
granted, provided that the above copyright notice and this
|
10 |
+
permission notice appear in all copies.
|
11 |
+
|
12 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
13 |
+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
14 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
15 |
+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
16 |
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
17 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
18 |
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
19 |
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
20 |
+
USE OR PERFORMANCE OF THIS SOFTWARE.
|
node_modules/@npmcli/fs/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @npmcli/fs
|
2 |
+
|
3 |
+
polyfills, and extensions, of the core `fs` module.
|
4 |
+
|
5 |
+
## Features
|
6 |
+
|
7 |
+
- `fs.cp` polyfill for node < 16.7.0
|
8 |
+
- `fs.withTempDir` added
|
9 |
+
- `fs.readdirScoped` added
|
10 |
+
- `fs.moveFile` added
|
11 |
+
|
12 |
+
## `fs.withTempDir(root, fn, options) -> Promise`
|
13 |
+
|
14 |
+
### Parameters
|
15 |
+
|
16 |
+
- `root`: the directory in which to create the temporary directory
|
17 |
+
- `fn`: a function that will be called with the path to the temporary directory
|
18 |
+
- `options`
|
19 |
+
- `tmpPrefix`: a prefix to be used in the generated directory name
|
20 |
+
|
21 |
+
### Usage
|
22 |
+
|
23 |
+
The `withTempDir` function creates a temporary directory, runs the provided
|
24 |
+
function (`fn`), then removes the temporary directory and resolves or rejects
|
25 |
+
based on the result of `fn`.
|
26 |
+
|
27 |
+
```js
|
28 |
+
const fs = require('@npmcli/fs')
|
29 |
+
const os = require('os')
|
30 |
+
|
31 |
+
// this function will be called with the full path to the temporary directory
|
32 |
+
// it is called with `await` behind the scenes, so can be async if desired.
|
33 |
+
const myFunction = async (tempPath) => {
|
34 |
+
return 'done!'
|
35 |
+
}
|
36 |
+
|
37 |
+
const main = async () => {
|
38 |
+
const result = await fs.withTempDir(os.tmpdir(), myFunction)
|
39 |
+
// result === 'done!'
|
40 |
+
}
|
41 |
+
|
42 |
+
main()
|
43 |
+
```
|
44 |
+
|
45 |
+
## `fs.readdirScoped(root) -> Promise`
|
46 |
+
|
47 |
+
### Parameters
|
48 |
+
|
49 |
+
- `root`: the directory to read
|
50 |
+
|
51 |
+
### Usage
|
52 |
+
|
53 |
+
Like `fs.readdir` but handling `@org/module` dirs as if they were
|
54 |
+
a single entry.
|
55 |
+
|
56 |
+
```javascript
|
57 |
+
const readdir = require('readdir-scoped-modules')
|
58 |
+
const entries = await readdir('node_modules')
|
59 |
+
// entries will be something like: ['a', '@org/foo', '@org/bar']
|
60 |
+
```
|
61 |
+
|
62 |
+
## `fs.moveFile(source, dest, options) -> Promise`
|
63 |
+
|
64 |
+
A fork of [move-file](https://github.com/sindresorhus/move-file) with
|
65 |
+
support for Common JS.
|
66 |
+
|
67 |
+
### Highlights
|
68 |
+
|
69 |
+
- Promise API.
|
70 |
+
- Supports moving a file across partitions and devices.
|
71 |
+
- Optionally prevent overwriting an existing file.
|
72 |
+
- Creates non-existent destination directories for you.
|
73 |
+
- Automatically recurses when source is a directory.
|
74 |
+
|
75 |
+
### Parameters
|
76 |
+
|
77 |
+
- `source`: File, or directory, you want to move.
|
78 |
+
- `dest`: Where you want the file or directory moved.
|
79 |
+
- `options`
|
80 |
+
- `overwrite` (`boolean`, default: `true`): Overwrite existing destination file(s).
|
81 |
+
|
82 |
+
### Usage
|
83 |
+
|
84 |
+
The built-in
|
85 |
+
[`fs.rename()`](https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback)
|
86 |
+
is just a JavaScript wrapper for the C `rename(2)` function, which doesn't
|
87 |
+
support moving files across partitions or devices. This module is what you
|
88 |
+
would have expected `fs.rename()` to be.
|
89 |
+
|
90 |
+
```js
|
91 |
+
const { moveFile } = require('@npmcli/fs');
|
92 |
+
|
93 |
+
(async () => {
|
94 |
+
await moveFile('source/unicorn.png', 'destination/unicorn.png');
|
95 |
+
console.log('The file has been moved');
|
96 |
+
})();
|
97 |
+
```
|
node_modules/@npmcli/fs/lib/common/get-options.js
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// given an input that may or may not be an object, return an object that has
|
2 |
+
// a copy of every defined property listed in 'copy'. if the input is not an
|
3 |
+
// object, assign it to the property named by 'wrap'
|
4 |
+
const getOptions = (input, { copy, wrap }) => {
|
5 |
+
const result = {}
|
6 |
+
|
7 |
+
if (input && typeof input === 'object') {
|
8 |
+
for (const prop of copy) {
|
9 |
+
if (input[prop] !== undefined) {
|
10 |
+
result[prop] = input[prop]
|
11 |
+
}
|
12 |
+
}
|
13 |
+
} else {
|
14 |
+
result[wrap] = input
|
15 |
+
}
|
16 |
+
|
17 |
+
return result
|
18 |
+
}
|
19 |
+
|
20 |
+
module.exports = getOptions
|
node_modules/@npmcli/fs/lib/common/node.js
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const semver = require('semver')
|
2 |
+
|
3 |
+
const satisfies = (range) => {
|
4 |
+
return semver.satisfies(process.version, range, { includePrerelease: true })
|
5 |
+
}
|
6 |
+
|
7 |
+
module.exports = {
|
8 |
+
satisfies,
|
9 |
+
}
|
node_modules/@npmcli/fs/lib/cp/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(The MIT License)
|
2 |
+
|
3 |
+
Copyright (c) 2011-2017 JP Richardson
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
6 |
+
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
|
7 |
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
8 |
+
furnished to do so, subject to the following conditions:
|
9 |
+
|
10 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
11 |
+
|
12 |
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13 |
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
14 |
+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15 |
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/@npmcli/fs/lib/cp/errors.js
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
const { inspect } = require('util')
|
3 |
+
|
4 |
+
// adapted from node's internal/errors
|
5 |
+
// https://github.com/nodejs/node/blob/c8a04049/lib/internal/errors.js
|
6 |
+
|
7 |
+
// close copy of node's internal SystemError class.
|
8 |
+
class SystemError {
|
9 |
+
constructor (code, prefix, context) {
|
10 |
+
// XXX context.code is undefined in all constructors used in cp/polyfill
|
11 |
+
// that may be a bug copied from node, maybe the constructor should use
|
12 |
+
// `code` not `errno`? nodejs/node#41104
|
13 |
+
let message = `${prefix}: ${context.syscall} returned ` +
|
14 |
+
`${context.code} (${context.message})`
|
15 |
+
|
16 |
+
if (context.path !== undefined) {
|
17 |
+
message += ` ${context.path}`
|
18 |
+
}
|
19 |
+
if (context.dest !== undefined) {
|
20 |
+
message += ` => ${context.dest}`
|
21 |
+
}
|
22 |
+
|
23 |
+
this.code = code
|
24 |
+
Object.defineProperties(this, {
|
25 |
+
name: {
|
26 |
+
value: 'SystemError',
|
27 |
+
enumerable: false,
|
28 |
+
writable: true,
|
29 |
+
configurable: true,
|
30 |
+
},
|
31 |
+
message: {
|
32 |
+
value: message,
|
33 |
+
enumerable: false,
|
34 |
+
writable: true,
|
35 |
+
configurable: true,
|
36 |
+
},
|
37 |
+
info: {
|
38 |
+
value: context,
|
39 |
+
enumerable: true,
|
40 |
+
configurable: true,
|
41 |
+
writable: false,
|
42 |
+
},
|
43 |
+
errno: {
|
44 |
+
get () {
|
45 |
+
return context.errno
|
46 |
+
},
|
47 |
+
set (value) {
|
48 |
+
context.errno = value
|
49 |
+
},
|
50 |
+
enumerable: true,
|
51 |
+
configurable: true,
|
52 |
+
},
|
53 |
+
syscall: {
|
54 |
+
get () {
|
55 |
+
return context.syscall
|
56 |
+
},
|
57 |
+
set (value) {
|
58 |
+
context.syscall = value
|
59 |
+
},
|
60 |
+
enumerable: true,
|
61 |
+
configurable: true,
|
62 |
+
},
|
63 |
+
})
|
64 |
+
|
65 |
+
if (context.path !== undefined) {
|
66 |
+
Object.defineProperty(this, 'path', {
|
67 |
+
get () {
|
68 |
+
return context.path
|
69 |
+
},
|
70 |
+
set (value) {
|
71 |
+
context.path = value
|
72 |
+
},
|
73 |
+
enumerable: true,
|
74 |
+
configurable: true,
|
75 |
+
})
|
76 |
+
}
|
77 |
+
|
78 |
+
if (context.dest !== undefined) {
|
79 |
+
Object.defineProperty(this, 'dest', {
|
80 |
+
get () {
|
81 |
+
return context.dest
|
82 |
+
},
|
83 |
+
set (value) {
|
84 |
+
context.dest = value
|
85 |
+
},
|
86 |
+
enumerable: true,
|
87 |
+
configurable: true,
|
88 |
+
})
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
toString () {
|
93 |
+
return `${this.name} [${this.code}]: ${this.message}`
|
94 |
+
}
|
95 |
+
|
96 |
+
[Symbol.for('nodejs.util.inspect.custom')] (_recurseTimes, ctx) {
|
97 |
+
return inspect(this, {
|
98 |
+
...ctx,
|
99 |
+
getters: true,
|
100 |
+
customInspect: false,
|
101 |
+
})
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
function E (code, message) {
|
106 |
+
module.exports[code] = class NodeError extends SystemError {
|
107 |
+
constructor (ctx) {
|
108 |
+
super(code, message, ctx)
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
E('ERR_FS_CP_DIR_TO_NON_DIR', 'Cannot overwrite directory with non-directory')
|
114 |
+
E('ERR_FS_CP_EEXIST', 'Target already exists')
|
115 |
+
E('ERR_FS_CP_EINVAL', 'Invalid src or dest')
|
116 |
+
E('ERR_FS_CP_FIFO_PIPE', 'Cannot copy a FIFO pipe')
|
117 |
+
E('ERR_FS_CP_NON_DIR_TO_DIR', 'Cannot overwrite non-directory with directory')
|
118 |
+
E('ERR_FS_CP_SOCKET', 'Cannot copy a socket file')
|
119 |
+
E('ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY', 'Cannot overwrite symlink in subdirectory of self')
|
120 |
+
E('ERR_FS_CP_UNKNOWN', 'Cannot copy an unknown file type')
|
121 |
+
E('ERR_FS_EISDIR', 'Path is a directory')
|
122 |
+
|
123 |
+
module.exports.ERR_INVALID_ARG_TYPE = class ERR_INVALID_ARG_TYPE extends Error {
|
124 |
+
constructor (name, expected, actual) {
|
125 |
+
super()
|
126 |
+
this.code = 'ERR_INVALID_ARG_TYPE'
|
127 |
+
this.message = `The ${name} argument must be ${expected}. Received ${typeof actual}`
|
128 |
+
}
|
129 |
+
}
|
node_modules/@npmcli/fs/lib/cp/index.js
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const fs = require('fs/promises')
|
2 |
+
const getOptions = require('../common/get-options.js')
|
3 |
+
const node = require('../common/node.js')
|
4 |
+
const polyfill = require('./polyfill.js')
|
5 |
+
|
6 |
+
// node 16.7.0 added fs.cp
|
7 |
+
const useNative = node.satisfies('>=16.7.0')
|
8 |
+
|
9 |
+
const cp = async (src, dest, opts) => {
|
10 |
+
const options = getOptions(opts, {
|
11 |
+
copy: ['dereference', 'errorOnExist', 'filter', 'force', 'preserveTimestamps', 'recursive'],
|
12 |
+
})
|
13 |
+
|
14 |
+
// the polyfill is tested separately from this module, no need to hack
|
15 |
+
// process.version to try to trigger it just for coverage
|
16 |
+
// istanbul ignore next
|
17 |
+
return useNative
|
18 |
+
? fs.cp(src, dest, options)
|
19 |
+
: polyfill(src, dest, options)
|
20 |
+
}
|
21 |
+
|
22 |
+
module.exports = cp
|
node_modules/@npmcli/fs/lib/cp/polyfill.js
ADDED
@@ -0,0 +1,428 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// this file is a modified version of the code in node 17.2.0
|
2 |
+
// which is, in turn, a modified version of the fs-extra module on npm
|
3 |
+
// node core changes:
|
4 |
+
// - Use of the assert module has been replaced with core's error system.
|
5 |
+
// - All code related to the glob dependency has been removed.
|
6 |
+
// - Bring your own custom fs module is not currently supported.
|
7 |
+
// - Some basic code cleanup.
|
8 |
+
// changes here:
|
9 |
+
// - remove all callback related code
|
10 |
+
// - drop sync support
|
11 |
+
// - change assertions back to non-internal methods (see options.js)
|
12 |
+
// - throws ENOTDIR when rmdir gets an ENOENT for a path that exists in Windows
|
13 |
+
'use strict'
|
14 |
+
|
15 |
+
const {
|
16 |
+
ERR_FS_CP_DIR_TO_NON_DIR,
|
17 |
+
ERR_FS_CP_EEXIST,
|
18 |
+
ERR_FS_CP_EINVAL,
|
19 |
+
ERR_FS_CP_FIFO_PIPE,
|
20 |
+
ERR_FS_CP_NON_DIR_TO_DIR,
|
21 |
+
ERR_FS_CP_SOCKET,
|
22 |
+
ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY,
|
23 |
+
ERR_FS_CP_UNKNOWN,
|
24 |
+
ERR_FS_EISDIR,
|
25 |
+
ERR_INVALID_ARG_TYPE,
|
26 |
+
} = require('./errors.js')
|
27 |
+
const {
|
28 |
+
constants: {
|
29 |
+
errno: {
|
30 |
+
EEXIST,
|
31 |
+
EISDIR,
|
32 |
+
EINVAL,
|
33 |
+
ENOTDIR,
|
34 |
+
},
|
35 |
+
},
|
36 |
+
} = require('os')
|
37 |
+
const {
|
38 |
+
chmod,
|
39 |
+
copyFile,
|
40 |
+
lstat,
|
41 |
+
mkdir,
|
42 |
+
readdir,
|
43 |
+
readlink,
|
44 |
+
stat,
|
45 |
+
symlink,
|
46 |
+
unlink,
|
47 |
+
utimes,
|
48 |
+
} = require('fs/promises')
|
49 |
+
const {
|
50 |
+
dirname,
|
51 |
+
isAbsolute,
|
52 |
+
join,
|
53 |
+
parse,
|
54 |
+
resolve,
|
55 |
+
sep,
|
56 |
+
toNamespacedPath,
|
57 |
+
} = require('path')
|
58 |
+
const { fileURLToPath } = require('url')
|
59 |
+
|
60 |
+
const defaultOptions = {
|
61 |
+
dereference: false,
|
62 |
+
errorOnExist: false,
|
63 |
+
filter: undefined,
|
64 |
+
force: true,
|
65 |
+
preserveTimestamps: false,
|
66 |
+
recursive: false,
|
67 |
+
}
|
68 |
+
|
69 |
+
async function cp (src, dest, opts) {
|
70 |
+
if (opts != null && typeof opts !== 'object') {
|
71 |
+
throw new ERR_INVALID_ARG_TYPE('options', ['Object'], opts)
|
72 |
+
}
|
73 |
+
return cpFn(
|
74 |
+
toNamespacedPath(getValidatedPath(src)),
|
75 |
+
toNamespacedPath(getValidatedPath(dest)),
|
76 |
+
{ ...defaultOptions, ...opts })
|
77 |
+
}
|
78 |
+
|
79 |
+
function getValidatedPath (fileURLOrPath) {
|
80 |
+
const path = fileURLOrPath != null && fileURLOrPath.href
|
81 |
+
&& fileURLOrPath.origin
|
82 |
+
? fileURLToPath(fileURLOrPath)
|
83 |
+
: fileURLOrPath
|
84 |
+
return path
|
85 |
+
}
|
86 |
+
|
87 |
+
async function cpFn (src, dest, opts) {
|
88 |
+
// Warn about using preserveTimestamps on 32-bit node
|
89 |
+
// istanbul ignore next
|
90 |
+
if (opts.preserveTimestamps && process.arch === 'ia32') {
|
91 |
+
const warning = 'Using the preserveTimestamps option in 32-bit ' +
|
92 |
+
'node is not recommended'
|
93 |
+
process.emitWarning(warning, 'TimestampPrecisionWarning')
|
94 |
+
}
|
95 |
+
const stats = await checkPaths(src, dest, opts)
|
96 |
+
const { srcStat, destStat } = stats
|
97 |
+
await checkParentPaths(src, srcStat, dest)
|
98 |
+
if (opts.filter) {
|
99 |
+
return handleFilter(checkParentDir, destStat, src, dest, opts)
|
100 |
+
}
|
101 |
+
return checkParentDir(destStat, src, dest, opts)
|
102 |
+
}
|
103 |
+
|
104 |
+
async function checkPaths (src, dest, opts) {
|
105 |
+
const { 0: srcStat, 1: destStat } = await getStats(src, dest, opts)
|
106 |
+
if (destStat) {
|
107 |
+
if (areIdentical(srcStat, destStat)) {
|
108 |
+
throw new ERR_FS_CP_EINVAL({
|
109 |
+
message: 'src and dest cannot be the same',
|
110 |
+
path: dest,
|
111 |
+
syscall: 'cp',
|
112 |
+
errno: EINVAL,
|
113 |
+
})
|
114 |
+
}
|
115 |
+
if (srcStat.isDirectory() && !destStat.isDirectory()) {
|
116 |
+
throw new ERR_FS_CP_DIR_TO_NON_DIR({
|
117 |
+
message: `cannot overwrite directory ${src} ` +
|
118 |
+
`with non-directory ${dest}`,
|
119 |
+
path: dest,
|
120 |
+
syscall: 'cp',
|
121 |
+
errno: EISDIR,
|
122 |
+
})
|
123 |
+
}
|
124 |
+
if (!srcStat.isDirectory() && destStat.isDirectory()) {
|
125 |
+
throw new ERR_FS_CP_NON_DIR_TO_DIR({
|
126 |
+
message: `cannot overwrite non-directory ${src} ` +
|
127 |
+
`with directory ${dest}`,
|
128 |
+
path: dest,
|
129 |
+
syscall: 'cp',
|
130 |
+
errno: ENOTDIR,
|
131 |
+
})
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
|
136 |
+
throw new ERR_FS_CP_EINVAL({
|
137 |
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`,
|
138 |
+
path: dest,
|
139 |
+
syscall: 'cp',
|
140 |
+
errno: EINVAL,
|
141 |
+
})
|
142 |
+
}
|
143 |
+
return { srcStat, destStat }
|
144 |
+
}
|
145 |
+
|
146 |
+
function areIdentical (srcStat, destStat) {
|
147 |
+
return destStat.ino && destStat.dev && destStat.ino === srcStat.ino &&
|
148 |
+
destStat.dev === srcStat.dev
|
149 |
+
}
|
150 |
+
|
151 |
+
function getStats (src, dest, opts) {
|
152 |
+
const statFunc = opts.dereference ?
|
153 |
+
(file) => stat(file, { bigint: true }) :
|
154 |
+
(file) => lstat(file, { bigint: true })
|
155 |
+
return Promise.all([
|
156 |
+
statFunc(src),
|
157 |
+
statFunc(dest).catch((err) => {
|
158 |
+
// istanbul ignore next: unsure how to cover.
|
159 |
+
if (err.code === 'ENOENT') {
|
160 |
+
return null
|
161 |
+
}
|
162 |
+
// istanbul ignore next: unsure how to cover.
|
163 |
+
throw err
|
164 |
+
}),
|
165 |
+
])
|
166 |
+
}
|
167 |
+
|
168 |
+
async function checkParentDir (destStat, src, dest, opts) {
|
169 |
+
const destParent = dirname(dest)
|
170 |
+
const dirExists = await pathExists(destParent)
|
171 |
+
if (dirExists) {
|
172 |
+
return getStatsForCopy(destStat, src, dest, opts)
|
173 |
+
}
|
174 |
+
await mkdir(destParent, { recursive: true })
|
175 |
+
return getStatsForCopy(destStat, src, dest, opts)
|
176 |
+
}
|
177 |
+
|
178 |
+
function pathExists (dest) {
|
179 |
+
return stat(dest).then(
|
180 |
+
() => true,
|
181 |
+
// istanbul ignore next: not sure when this would occur
|
182 |
+
(err) => (err.code === 'ENOENT' ? false : Promise.reject(err)))
|
183 |
+
}
|
184 |
+
|
185 |
+
// Recursively check if dest parent is a subdirectory of src.
|
186 |
+
// It works for all file types including symlinks since it
|
187 |
+
// checks the src and dest inodes. It starts from the deepest
|
188 |
+
// parent and stops once it reaches the src parent or the root path.
|
189 |
+
async function checkParentPaths (src, srcStat, dest) {
|
190 |
+
const srcParent = resolve(dirname(src))
|
191 |
+
const destParent = resolve(dirname(dest))
|
192 |
+
if (destParent === srcParent || destParent === parse(destParent).root) {
|
193 |
+
return
|
194 |
+
}
|
195 |
+
let destStat
|
196 |
+
try {
|
197 |
+
destStat = await stat(destParent, { bigint: true })
|
198 |
+
} catch (err) {
|
199 |
+
// istanbul ignore else: not sure when this would occur
|
200 |
+
if (err.code === 'ENOENT') {
|
201 |
+
return
|
202 |
+
}
|
203 |
+
// istanbul ignore next: not sure when this would occur
|
204 |
+
throw err
|
205 |
+
}
|
206 |
+
if (areIdentical(srcStat, destStat)) {
|
207 |
+
throw new ERR_FS_CP_EINVAL({
|
208 |
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`,
|
209 |
+
path: dest,
|
210 |
+
syscall: 'cp',
|
211 |
+
errno: EINVAL,
|
212 |
+
})
|
213 |
+
}
|
214 |
+
return checkParentPaths(src, srcStat, destParent)
|
215 |
+
}
|
216 |
+
|
217 |
+
const normalizePathToArray = (path) =>
|
218 |
+
resolve(path).split(sep).filter(Boolean)
|
219 |
+
|
220 |
+
// Return true if dest is a subdir of src, otherwise false.
|
221 |
+
// It only checks the path strings.
|
222 |
+
function isSrcSubdir (src, dest) {
|
223 |
+
const srcArr = normalizePathToArray(src)
|
224 |
+
const destArr = normalizePathToArray(dest)
|
225 |
+
return srcArr.every((cur, i) => destArr[i] === cur)
|
226 |
+
}
|
227 |
+
|
228 |
+
async function handleFilter (onInclude, destStat, src, dest, opts, cb) {
|
229 |
+
const include = await opts.filter(src, dest)
|
230 |
+
if (include) {
|
231 |
+
return onInclude(destStat, src, dest, opts, cb)
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
function startCopy (destStat, src, dest, opts) {
|
236 |
+
if (opts.filter) {
|
237 |
+
return handleFilter(getStatsForCopy, destStat, src, dest, opts)
|
238 |
+
}
|
239 |
+
return getStatsForCopy(destStat, src, dest, opts)
|
240 |
+
}
|
241 |
+
|
242 |
+
async function getStatsForCopy (destStat, src, dest, opts) {
|
243 |
+
const statFn = opts.dereference ? stat : lstat
|
244 |
+
const srcStat = await statFn(src)
|
245 |
+
// istanbul ignore else: can't portably test FIFO
|
246 |
+
if (srcStat.isDirectory() && opts.recursive) {
|
247 |
+
return onDir(srcStat, destStat, src, dest, opts)
|
248 |
+
} else if (srcStat.isDirectory()) {
|
249 |
+
throw new ERR_FS_EISDIR({
|
250 |
+
message: `${src} is a directory (not copied)`,
|
251 |
+
path: src,
|
252 |
+
syscall: 'cp',
|
253 |
+
errno: EINVAL,
|
254 |
+
})
|
255 |
+
} else if (srcStat.isFile() ||
|
256 |
+
srcStat.isCharacterDevice() ||
|
257 |
+
srcStat.isBlockDevice()) {
|
258 |
+
return onFile(srcStat, destStat, src, dest, opts)
|
259 |
+
} else if (srcStat.isSymbolicLink()) {
|
260 |
+
return onLink(destStat, src, dest)
|
261 |
+
} else if (srcStat.isSocket()) {
|
262 |
+
throw new ERR_FS_CP_SOCKET({
|
263 |
+
message: `cannot copy a socket file: ${dest}`,
|
264 |
+
path: dest,
|
265 |
+
syscall: 'cp',
|
266 |
+
errno: EINVAL,
|
267 |
+
})
|
268 |
+
} else if (srcStat.isFIFO()) {
|
269 |
+
throw new ERR_FS_CP_FIFO_PIPE({
|
270 |
+
message: `cannot copy a FIFO pipe: ${dest}`,
|
271 |
+
path: dest,
|
272 |
+
syscall: 'cp',
|
273 |
+
errno: EINVAL,
|
274 |
+
})
|
275 |
+
}
|
276 |
+
// istanbul ignore next: should be unreachable
|
277 |
+
throw new ERR_FS_CP_UNKNOWN({
|
278 |
+
message: `cannot copy an unknown file type: ${dest}`,
|
279 |
+
path: dest,
|
280 |
+
syscall: 'cp',
|
281 |
+
errno: EINVAL,
|
282 |
+
})
|
283 |
+
}
|
284 |
+
|
285 |
+
function onFile (srcStat, destStat, src, dest, opts) {
|
286 |
+
if (!destStat) {
|
287 |
+
return _copyFile(srcStat, src, dest, opts)
|
288 |
+
}
|
289 |
+
return mayCopyFile(srcStat, src, dest, opts)
|
290 |
+
}
|
291 |
+
|
292 |
+
async function mayCopyFile (srcStat, src, dest, opts) {
|
293 |
+
if (opts.force) {
|
294 |
+
await unlink(dest)
|
295 |
+
return _copyFile(srcStat, src, dest, opts)
|
296 |
+
} else if (opts.errorOnExist) {
|
297 |
+
throw new ERR_FS_CP_EEXIST({
|
298 |
+
message: `${dest} already exists`,
|
299 |
+
path: dest,
|
300 |
+
syscall: 'cp',
|
301 |
+
errno: EEXIST,
|
302 |
+
})
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
async function _copyFile (srcStat, src, dest, opts) {
|
307 |
+
await copyFile(src, dest)
|
308 |
+
if (opts.preserveTimestamps) {
|
309 |
+
return handleTimestampsAndMode(srcStat.mode, src, dest)
|
310 |
+
}
|
311 |
+
return setDestMode(dest, srcStat.mode)
|
312 |
+
}
|
313 |
+
|
314 |
+
async function handleTimestampsAndMode (srcMode, src, dest) {
|
315 |
+
// Make sure the file is writable before setting the timestamp
|
316 |
+
// otherwise open fails with EPERM when invoked with 'r+'
|
317 |
+
// (through utimes call)
|
318 |
+
if (fileIsNotWritable(srcMode)) {
|
319 |
+
await makeFileWritable(dest, srcMode)
|
320 |
+
return setDestTimestampsAndMode(srcMode, src, dest)
|
321 |
+
}
|
322 |
+
return setDestTimestampsAndMode(srcMode, src, dest)
|
323 |
+
}
|
324 |
+
|
325 |
+
function fileIsNotWritable (srcMode) {
|
326 |
+
return (srcMode & 0o200) === 0
|
327 |
+
}
|
328 |
+
|
329 |
+
function makeFileWritable (dest, srcMode) {
|
330 |
+
return setDestMode(dest, srcMode | 0o200)
|
331 |
+
}
|
332 |
+
|
333 |
+
async function setDestTimestampsAndMode (srcMode, src, dest) {
|
334 |
+
await setDestTimestamps(src, dest)
|
335 |
+
return setDestMode(dest, srcMode)
|
336 |
+
}
|
337 |
+
|
338 |
+
function setDestMode (dest, srcMode) {
|
339 |
+
return chmod(dest, srcMode)
|
340 |
+
}
|
341 |
+
|
342 |
+
async function setDestTimestamps (src, dest) {
|
343 |
+
// The initial srcStat.atime cannot be trusted
|
344 |
+
// because it is modified by the read(2) system call
|
345 |
+
// (See https://nodejs.org/api/fs.html#fs_stat_time_values)
|
346 |
+
const updatedSrcStat = await stat(src)
|
347 |
+
return utimes(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
|
348 |
+
}
|
349 |
+
|
350 |
+
function onDir (srcStat, destStat, src, dest, opts) {
|
351 |
+
if (!destStat) {
|
352 |
+
return mkDirAndCopy(srcStat.mode, src, dest, opts)
|
353 |
+
}
|
354 |
+
return copyDir(src, dest, opts)
|
355 |
+
}
|
356 |
+
|
357 |
+
async function mkDirAndCopy (srcMode, src, dest, opts) {
|
358 |
+
await mkdir(dest)
|
359 |
+
await copyDir(src, dest, opts)
|
360 |
+
return setDestMode(dest, srcMode)
|
361 |
+
}
|
362 |
+
|
363 |
+
async function copyDir (src, dest, opts) {
|
364 |
+
const dir = await readdir(src)
|
365 |
+
for (let i = 0; i < dir.length; i++) {
|
366 |
+
const item = dir[i]
|
367 |
+
const srcItem = join(src, item)
|
368 |
+
const destItem = join(dest, item)
|
369 |
+
const { destStat } = await checkPaths(srcItem, destItem, opts)
|
370 |
+
await startCopy(destStat, srcItem, destItem, opts)
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
async function onLink (destStat, src, dest) {
|
375 |
+
let resolvedSrc = await readlink(src)
|
376 |
+
if (!isAbsolute(resolvedSrc)) {
|
377 |
+
resolvedSrc = resolve(dirname(src), resolvedSrc)
|
378 |
+
}
|
379 |
+
if (!destStat) {
|
380 |
+
return symlink(resolvedSrc, dest)
|
381 |
+
}
|
382 |
+
let resolvedDest
|
383 |
+
try {
|
384 |
+
resolvedDest = await readlink(dest)
|
385 |
+
} catch (err) {
|
386 |
+
// Dest exists and is a regular file or directory,
|
387 |
+
// Windows may throw UNKNOWN error. If dest already exists,
|
388 |
+
// fs throws error anyway, so no need to guard against it here.
|
389 |
+
// istanbul ignore next: can only test on windows
|
390 |
+
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') {
|
391 |
+
return symlink(resolvedSrc, dest)
|
392 |
+
}
|
393 |
+
// istanbul ignore next: should not be possible
|
394 |
+
throw err
|
395 |
+
}
|
396 |
+
if (!isAbsolute(resolvedDest)) {
|
397 |
+
resolvedDest = resolve(dirname(dest), resolvedDest)
|
398 |
+
}
|
399 |
+
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
|
400 |
+
throw new ERR_FS_CP_EINVAL({
|
401 |
+
message: `cannot copy ${resolvedSrc} to a subdirectory of self ` +
|
402 |
+
`${resolvedDest}`,
|
403 |
+
path: dest,
|
404 |
+
syscall: 'cp',
|
405 |
+
errno: EINVAL,
|
406 |
+
})
|
407 |
+
}
|
408 |
+
// Do not copy if src is a subdir of dest since unlinking
|
409 |
+
// dest in this case would result in removing src contents
|
410 |
+
// and therefore a broken symlink would be created.
|
411 |
+
const srcStat = await stat(src)
|
412 |
+
if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
|
413 |
+
throw new ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY({
|
414 |
+
message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
|
415 |
+
path: dest,
|
416 |
+
syscall: 'cp',
|
417 |
+
errno: EINVAL,
|
418 |
+
})
|
419 |
+
}
|
420 |
+
return copyLink(resolvedSrc, dest)
|
421 |
+
}
|
422 |
+
|
423 |
+
async function copyLink (resolvedSrc, dest) {
|
424 |
+
await unlink(dest)
|
425 |
+
return symlink(resolvedSrc, dest)
|
426 |
+
}
|
427 |
+
|
428 |
+
module.exports = cp
|
node_modules/@npmcli/fs/lib/index.js
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
const cp = require('./cp/index.js')
|
4 |
+
const withTempDir = require('./with-temp-dir.js')
|
5 |
+
const readdirScoped = require('./readdir-scoped.js')
|
6 |
+
const moveFile = require('./move-file.js')
|
7 |
+
|
8 |
+
module.exports = {
|
9 |
+
cp,
|
10 |
+
withTempDir,
|
11 |
+
readdirScoped,
|
12 |
+
moveFile,
|
13 |
+
}
|
node_modules/@npmcli/fs/lib/move-file.js
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { dirname, join, resolve, relative, isAbsolute } = require('path')
|
2 |
+
const fs = require('fs/promises')
|
3 |
+
|
4 |
+
const pathExists = async path => {
|
5 |
+
try {
|
6 |
+
await fs.access(path)
|
7 |
+
return true
|
8 |
+
} catch (er) {
|
9 |
+
return er.code !== 'ENOENT'
|
10 |
+
}
|
11 |
+
}
|
12 |
+
|
13 |
+
const moveFile = async (source, destination, options = {}, root = true, symlinks = []) => {
|
14 |
+
if (!source || !destination) {
|
15 |
+
throw new TypeError('`source` and `destination` file required')
|
16 |
+
}
|
17 |
+
|
18 |
+
options = {
|
19 |
+
overwrite: true,
|
20 |
+
...options,
|
21 |
+
}
|
22 |
+
|
23 |
+
if (!options.overwrite && await pathExists(destination)) {
|
24 |
+
throw new Error(`The destination file exists: ${destination}`)
|
25 |
+
}
|
26 |
+
|
27 |
+
await fs.mkdir(dirname(destination), { recursive: true })
|
28 |
+
|
29 |
+
try {
|
30 |
+
await fs.rename(source, destination)
|
31 |
+
} catch (error) {
|
32 |
+
if (error.code === 'EXDEV' || error.code === 'EPERM') {
|
33 |
+
const sourceStat = await fs.lstat(source)
|
34 |
+
if (sourceStat.isDirectory()) {
|
35 |
+
const files = await fs.readdir(source)
|
36 |
+
await Promise.all(files.map((file) =>
|
37 |
+
moveFile(join(source, file), join(destination, file), options, false, symlinks)
|
38 |
+
))
|
39 |
+
} else if (sourceStat.isSymbolicLink()) {
|
40 |
+
symlinks.push({ source, destination })
|
41 |
+
} else {
|
42 |
+
await fs.copyFile(source, destination)
|
43 |
+
}
|
44 |
+
} else {
|
45 |
+
throw error
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
if (root) {
|
50 |
+
await Promise.all(symlinks.map(async ({ source: symSource, destination: symDestination }) => {
|
51 |
+
let target = await fs.readlink(symSource)
|
52 |
+
// junction symlinks in windows will be absolute paths, so we need to
|
53 |
+
// make sure they point to the symlink destination
|
54 |
+
if (isAbsolute(target)) {
|
55 |
+
target = resolve(symDestination, relative(symSource, target))
|
56 |
+
}
|
57 |
+
// try to determine what the actual file is so we can create the correct
|
58 |
+
// type of symlink in windows
|
59 |
+
let targetStat = 'file'
|
60 |
+
try {
|
61 |
+
targetStat = await fs.stat(resolve(dirname(symSource), target))
|
62 |
+
if (targetStat.isDirectory()) {
|
63 |
+
targetStat = 'junction'
|
64 |
+
}
|
65 |
+
} catch {
|
66 |
+
// targetStat remains 'file'
|
67 |
+
}
|
68 |
+
await fs.symlink(
|
69 |
+
target,
|
70 |
+
symDestination,
|
71 |
+
targetStat
|
72 |
+
)
|
73 |
+
}))
|
74 |
+
await fs.rm(source, { recursive: true, force: true })
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
module.exports = moveFile
|
node_modules/@npmcli/fs/lib/readdir-scoped.js
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { readdir } = require('fs/promises')
|
2 |
+
const { join } = require('path')
|
3 |
+
|
4 |
+
const readdirScoped = async (dir) => {
|
5 |
+
const results = []
|
6 |
+
|
7 |
+
for (const item of await readdir(dir)) {
|
8 |
+
if (item.startsWith('@')) {
|
9 |
+
for (const scopedItem of await readdir(join(dir, item))) {
|
10 |
+
results.push(join(item, scopedItem))
|
11 |
+
}
|
12 |
+
} else {
|
13 |
+
results.push(item)
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
return results
|
18 |
+
}
|
19 |
+
|
20 |
+
module.exports = readdirScoped
|
node_modules/@npmcli/fs/lib/with-temp-dir.js
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { join, sep } = require('path')
|
2 |
+
|
3 |
+
const getOptions = require('./common/get-options.js')
|
4 |
+
const { mkdir, mkdtemp, rm } = require('fs/promises')
|
5 |
+
|
6 |
+
// create a temp directory, ensure its permissions match its parent, then call
|
7 |
+
// the supplied function passing it the path to the directory. clean up after
|
8 |
+
// the function finishes, whether it throws or not
|
9 |
+
const withTempDir = async (root, fn, opts) => {
|
10 |
+
const options = getOptions(opts, {
|
11 |
+
copy: ['tmpPrefix'],
|
12 |
+
})
|
13 |
+
// create the directory
|
14 |
+
await mkdir(root, { recursive: true })
|
15 |
+
|
16 |
+
const target = await mkdtemp(join(`${root}${sep}`, options.tmpPrefix || ''))
|
17 |
+
let err
|
18 |
+
let result
|
19 |
+
|
20 |
+
try {
|
21 |
+
result = await fn(target)
|
22 |
+
} catch (_err) {
|
23 |
+
err = _err
|
24 |
+
}
|
25 |
+
|
26 |
+
try {
|
27 |
+
await rm(target, { force: true, recursive: true })
|
28 |
+
} catch {
|
29 |
+
// ignore errors
|
30 |
+
}
|
31 |
+
|
32 |
+
if (err) {
|
33 |
+
throw err
|
34 |
+
}
|
35 |
+
|
36 |
+
return result
|
37 |
+
}
|
38 |
+
|
39 |
+
module.exports = withTempDir
|
node_modules/@npmcli/fs/package.json
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@npmcli/fs",
|
3 |
+
"version": "3.1.0",
|
4 |
+
"description": "filesystem utilities for the npm cli",
|
5 |
+
"main": "lib/index.js",
|
6 |
+
"files": [
|
7 |
+
"bin/",
|
8 |
+
"lib/"
|
9 |
+
],
|
10 |
+
"scripts": {
|
11 |
+
"snap": "tap",
|
12 |
+
"test": "tap",
|
13 |
+
"npmclilint": "npmcli-lint",
|
14 |
+
"lint": "eslint \"**/*.js\"",
|
15 |
+
"lintfix": "npm run lint -- --fix",
|
16 |
+
"posttest": "npm run lint",
|
17 |
+
"postsnap": "npm run lintfix --",
|
18 |
+
"postlint": "template-oss-check",
|
19 |
+
"template-oss-apply": "template-oss-apply --force"
|
20 |
+
},
|
21 |
+
"repository": {
|
22 |
+
"type": "git",
|
23 |
+
"url": "https://github.com/npm/fs.git"
|
24 |
+
},
|
25 |
+
"keywords": [
|
26 |
+
"npm",
|
27 |
+
"oss"
|
28 |
+
],
|
29 |
+
"author": "GitHub Inc.",
|
30 |
+
"license": "ISC",
|
31 |
+
"devDependencies": {
|
32 |
+
"@npmcli/eslint-config": "^4.0.0",
|
33 |
+
"@npmcli/template-oss": "4.8.0",
|
34 |
+
"tap": "^16.0.1"
|
35 |
+
},
|
36 |
+
"dependencies": {
|
37 |
+
"semver": "^7.3.5"
|
38 |
+
},
|
39 |
+
"engines": {
|
40 |
+
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
|
41 |
+
},
|
42 |
+
"templateOSS": {
|
43 |
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
44 |
+
"version": "4.8.0"
|
45 |
+
},
|
46 |
+
"tap": {
|
47 |
+
"nyc-arg": [
|
48 |
+
"--exclude",
|
49 |
+
"tap-snapshots/**"
|
50 |
+
]
|
51 |
+
}
|
52 |
+
}
|
node_modules/@pkgjs/parseargs/.editorconfig
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# EditorConfig is awesome: http://EditorConfig.org
|
2 |
+
|
3 |
+
# top-most EditorConfig file
|
4 |
+
root = true
|
5 |
+
|
6 |
+
# Copied from Node.js to ease compatibility in PR.
|
7 |
+
[*]
|
8 |
+
charset = utf-8
|
9 |
+
end_of_line = lf
|
10 |
+
indent_size = 2
|
11 |
+
indent_style = space
|
12 |
+
insert_final_newline = true
|
13 |
+
trim_trailing_whitespace = true
|
14 |
+
quote_type = single
|
node_modules/@pkgjs/parseargs/CHANGELOG.md
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Changelog
|
2 |
+
|
3 |
+
## [0.11.0](https://github.com/pkgjs/parseargs/compare/v0.10.0...v0.11.0) (2022-10-08)
|
4 |
+
|
5 |
+
|
6 |
+
### Features
|
7 |
+
|
8 |
+
* add `default` option parameter ([#142](https://github.com/pkgjs/parseargs/issues/142)) ([cd20847](https://github.com/pkgjs/parseargs/commit/cd20847a00b2f556aa9c085ac83b942c60868ec1))
|
9 |
+
|
10 |
+
## [0.10.0](https://github.com/pkgjs/parseargs/compare/v0.9.1...v0.10.0) (2022-07-21)
|
11 |
+
|
12 |
+
|
13 |
+
### Features
|
14 |
+
|
15 |
+
* add parsed meta-data to returned properties ([#129](https://github.com/pkgjs/parseargs/issues/129)) ([91bfb4d](https://github.com/pkgjs/parseargs/commit/91bfb4d3f7b6937efab1b27c91c45d1205f1497e))
|
16 |
+
|
17 |
+
## [0.9.1](https://github.com/pkgjs/parseargs/compare/v0.9.0...v0.9.1) (2022-06-20)
|
18 |
+
|
19 |
+
|
20 |
+
### Bug Fixes
|
21 |
+
|
22 |
+
* **runtime:** support node 14+ ([#135](https://github.com/pkgjs/parseargs/issues/135)) ([6a1c5a6](https://github.com/pkgjs/parseargs/commit/6a1c5a6f7cadf2f035e004027e2742e3c4ce554b))
|
23 |
+
|
24 |
+
## [0.9.0](https://github.com/pkgjs/parseargs/compare/v0.8.0...v0.9.0) (2022-05-23)
|
25 |
+
|
26 |
+
|
27 |
+
### ⚠ BREAKING CHANGES
|
28 |
+
|
29 |
+
* drop handling of electron arguments (#121)
|
30 |
+
|
31 |
+
### Code Refactoring
|
32 |
+
|
33 |
+
* drop handling of electron arguments ([#121](https://github.com/pkgjs/parseargs/issues/121)) ([a2ffd53](https://github.com/pkgjs/parseargs/commit/a2ffd537c244a062371522b955acb45a404fc9f2))
|
34 |
+
|
35 |
+
## [0.8.0](https://github.com/pkgjs/parseargs/compare/v0.7.1...v0.8.0) (2022-05-16)
|
36 |
+
|
37 |
+
|
38 |
+
### ⚠ BREAKING CHANGES
|
39 |
+
|
40 |
+
* switch type:string option arguments to greedy, but with error for suspect cases in strict mode (#88)
|
41 |
+
* positionals now opt-in when strict:true (#116)
|
42 |
+
* create result.values with null prototype (#111)
|
43 |
+
|
44 |
+
### Features
|
45 |
+
|
46 |
+
* create result.values with null prototype ([#111](https://github.com/pkgjs/parseargs/issues/111)) ([9d539c3](https://github.com/pkgjs/parseargs/commit/9d539c3d57f269c160e74e0656ad4fa84ff92ec2))
|
47 |
+
* positionals now opt-in when strict:true ([#116](https://github.com/pkgjs/parseargs/issues/116)) ([3643338](https://github.com/pkgjs/parseargs/commit/364333826b746e8a7dc5505b4b22fd19ac51df3b))
|
48 |
+
* switch type:string option arguments to greedy, but with error for suspect cases in strict mode ([#88](https://github.com/pkgjs/parseargs/issues/88)) ([c2b5e72](https://github.com/pkgjs/parseargs/commit/c2b5e72161991dfdc535909f1327cc9b970fe7e8))
|
49 |
+
|
50 |
+
### [0.7.1](https://github.com/pkgjs/parseargs/compare/v0.7.0...v0.7.1) (2022-04-15)
|
51 |
+
|
52 |
+
|
53 |
+
### Bug Fixes
|
54 |
+
|
55 |
+
* resist pollution ([#106](https://github.com/pkgjs/parseargs/issues/106)) ([ecf2dec](https://github.com/pkgjs/parseargs/commit/ecf2dece0a9f2a76d789384d5d71c68ffe64022a))
|
56 |
+
|
57 |
+
## [0.7.0](https://github.com/pkgjs/parseargs/compare/v0.6.0...v0.7.0) (2022-04-13)
|
58 |
+
|
59 |
+
|
60 |
+
### Features
|
61 |
+
|
62 |
+
* Add strict mode to parser ([#74](https://github.com/pkgjs/parseargs/issues/74)) ([8267d02](https://github.com/pkgjs/parseargs/commit/8267d02083a87b8b8a71fcce08348d1e031ea91c))
|
63 |
+
|
64 |
+
## [0.6.0](https://github.com/pkgjs/parseargs/compare/v0.5.0...v0.6.0) (2022-04-11)
|
65 |
+
|
66 |
+
|
67 |
+
### ⚠ BREAKING CHANGES
|
68 |
+
|
69 |
+
* rework results to remove redundant `flags` property and store value true for boolean options (#83)
|
70 |
+
* switch to existing ERR_INVALID_ARG_VALUE (#97)
|
71 |
+
|
72 |
+
### Code Refactoring
|
73 |
+
|
74 |
+
* rework results to remove redundant `flags` property and store value true for boolean options ([#83](https://github.com/pkgjs/parseargs/issues/83)) ([be153db](https://github.com/pkgjs/parseargs/commit/be153dbed1d488cb7b6e27df92f601ba7337713d))
|
75 |
+
* switch to existing ERR_INVALID_ARG_VALUE ([#97](https://github.com/pkgjs/parseargs/issues/97)) ([084a23f](https://github.com/pkgjs/parseargs/commit/084a23f9fde2da030b159edb1c2385f24579ce40))
|
76 |
+
|
77 |
+
## [0.5.0](https://github.com/pkgjs/parseargs/compare/v0.4.0...v0.5.0) (2022-04-10)
|
78 |
+
|
79 |
+
|
80 |
+
### ⚠ BREAKING CHANGES
|
81 |
+
|
82 |
+
* Require type to be specified for each supplied option (#95)
|
83 |
+
|
84 |
+
### Features
|
85 |
+
|
86 |
+
* Require type to be specified for each supplied option ([#95](https://github.com/pkgjs/parseargs/issues/95)) ([02cd018](https://github.com/pkgjs/parseargs/commit/02cd01885b8aaa59f2db8308f2d4479e64340068))
|
87 |
+
|
88 |
+
## [0.4.0](https://github.com/pkgjs/parseargs/compare/v0.3.0...v0.4.0) (2022-03-12)
|
89 |
+
|
90 |
+
|
91 |
+
### ⚠ BREAKING CHANGES
|
92 |
+
|
93 |
+
* parsing, revisit short option groups, add support for combined short and value (#75)
|
94 |
+
* restructure configuration to take options bag (#63)
|
95 |
+
|
96 |
+
### Code Refactoring
|
97 |
+
|
98 |
+
* parsing, revisit short option groups, add support for combined short and value ([#75](https://github.com/pkgjs/parseargs/issues/75)) ([a92600f](https://github.com/pkgjs/parseargs/commit/a92600fa6c214508ab1e016fa55879a314f541af))
|
99 |
+
* restructure configuration to take options bag ([#63](https://github.com/pkgjs/parseargs/issues/63)) ([b412095](https://github.com/pkgjs/parseargs/commit/b4120957d90e809ee8b607b06e747d3e6a6b213e))
|
100 |
+
|
101 |
+
## [0.3.0](https://github.com/pkgjs/parseargs/compare/v0.2.0...v0.3.0) (2022-02-06)
|
102 |
+
|
103 |
+
|
104 |
+
### Features
|
105 |
+
|
106 |
+
* **parser:** support short-option groups ([#59](https://github.com/pkgjs/parseargs/issues/59)) ([882067b](https://github.com/pkgjs/parseargs/commit/882067bc2d7cbc6b796f8e5a079a99bc99d4e6ba))
|
107 |
+
|
108 |
+
## [0.2.0](https://github.com/pkgjs/parseargs/compare/v0.1.1...v0.2.0) (2022-02-05)
|
109 |
+
|
110 |
+
|
111 |
+
### Features
|
112 |
+
|
113 |
+
* basic support for shorts ([#50](https://github.com/pkgjs/parseargs/issues/50)) ([a2f36d7](https://github.com/pkgjs/parseargs/commit/a2f36d7da4145af1c92f76806b7fe2baf6beeceb))
|
114 |
+
|
115 |
+
|
116 |
+
### Bug Fixes
|
117 |
+
|
118 |
+
* always store value for a=b ([#43](https://github.com/pkgjs/parseargs/issues/43)) ([a85e8dc](https://github.com/pkgjs/parseargs/commit/a85e8dc06379fd2696ee195cc625de8fac6aee42))
|
119 |
+
* support single dash as positional ([#49](https://github.com/pkgjs/parseargs/issues/49)) ([d795bf8](https://github.com/pkgjs/parseargs/commit/d795bf877d068fd67aec381f30b30b63f97109ad))
|
120 |
+
|
121 |
+
### [0.1.1](https://github.com/pkgjs/parseargs/compare/v0.1.0...v0.1.1) (2022-01-25)
|
122 |
+
|
123 |
+
|
124 |
+
### Bug Fixes
|
125 |
+
|
126 |
+
* only use arrays in results for multiples ([#42](https://github.com/pkgjs/parseargs/issues/42)) ([c357584](https://github.com/pkgjs/parseargs/commit/c357584847912506319ed34a0840080116f4fd65))
|
127 |
+
|
128 |
+
## 0.1.0 (2022-01-22)
|
129 |
+
|
130 |
+
|
131 |
+
### Features
|
132 |
+
|
133 |
+
* expand scenarios covered by default arguments for environments ([#20](https://github.com/pkgjs/parseargs/issues/20)) ([582ada7](https://github.com/pkgjs/parseargs/commit/582ada7be0eca3a73d6e0bd016e7ace43449fa4c))
|
134 |
+
* update readme and include contributing guidelines ([8edd6fc](https://github.com/pkgjs/parseargs/commit/8edd6fc863cd705f6fac732724159ebe8065a2b0))
|
135 |
+
|
136 |
+
|
137 |
+
### Bug Fixes
|
138 |
+
|
139 |
+
* do not strip excess leading dashes on long option names ([#21](https://github.com/pkgjs/parseargs/issues/21)) ([f848590](https://github.com/pkgjs/parseargs/commit/f848590ebf3249ed5979ff47e003fa6e1a8ec5c0))
|
140 |
+
* name & readme ([3f057c1](https://github.com/pkgjs/parseargs/commit/3f057c1b158a1bdbe878c64b57460c58e56e465f))
|
141 |
+
* package.json values ([9bac300](https://github.com/pkgjs/parseargs/commit/9bac300e00cd76c77076bf9e75e44f8929512da9))
|
142 |
+
* update readme name ([957d8d9](https://github.com/pkgjs/parseargs/commit/957d8d96e1dcb48297c0a14345d44c0123b2883e))
|
143 |
+
|
144 |
+
|
145 |
+
### Build System
|
146 |
+
|
147 |
+
* first release as minor ([421c6e2](https://github.com/pkgjs/parseargs/commit/421c6e2569a8668ad14fac5a5af5be60479a7571))
|
node_modules/@pkgjs/parseargs/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright [yyyy] [name of copyright owner]
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
node_modules/@pkgjs/parseargs/README.md
ADDED
@@ -0,0 +1,413 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- omit in toc -->
|
2 |
+
# parseArgs
|
3 |
+
|
4 |
+
[![Coverage][coverage-image]][coverage-url]
|
5 |
+
|
6 |
+
Polyfill of `util.parseArgs()`
|
7 |
+
|
8 |
+
## `util.parseArgs([config])`
|
9 |
+
|
10 |
+
<!-- YAML
|
11 |
+
added: v18.3.0
|
12 |
+
changes:
|
13 |
+
- version: REPLACEME
|
14 |
+
pr-url: https://github.com/nodejs/node/pull/43459
|
15 |
+
description: add support for returning detailed parse information
|
16 |
+
using `tokens` in input `config` and returned properties.
|
17 |
+
-->
|
18 |
+
|
19 |
+
> Stability: 1 - Experimental
|
20 |
+
|
21 |
+
* `config` {Object} Used to provide arguments for parsing and to configure
|
22 |
+
the parser. `config` supports the following properties:
|
23 |
+
* `args` {string\[]} array of argument strings. **Default:** `process.argv`
|
24 |
+
with `execPath` and `filename` removed.
|
25 |
+
* `options` {Object} Used to describe arguments known to the parser.
|
26 |
+
Keys of `options` are the long names of options and values are an
|
27 |
+
{Object} accepting the following properties:
|
28 |
+
* `type` {string} Type of argument, which must be either `boolean` or `string`.
|
29 |
+
* `multiple` {boolean} Whether this option can be provided multiple
|
30 |
+
times. If `true`, all values will be collected in an array. If
|
31 |
+
`false`, values for the option are last-wins. **Default:** `false`.
|
32 |
+
* `short` {string} A single character alias for the option.
|
33 |
+
* `default` {string | boolean | string\[] | boolean\[]} The default option
|
34 |
+
value when it is not set by args. It must be of the same type as the
|
35 |
+
the `type` property. When `multiple` is `true`, it must be an array.
|
36 |
+
* `strict` {boolean} Should an error be thrown when unknown arguments
|
37 |
+
are encountered, or when arguments are passed that do not match the
|
38 |
+
`type` configured in `options`.
|
39 |
+
**Default:** `true`.
|
40 |
+
* `allowPositionals` {boolean} Whether this command accepts positional
|
41 |
+
arguments.
|
42 |
+
**Default:** `false` if `strict` is `true`, otherwise `true`.
|
43 |
+
* `tokens` {boolean} Return the parsed tokens. This is useful for extending
|
44 |
+
the built-in behavior, from adding additional checks through to reprocessing
|
45 |
+
the tokens in different ways.
|
46 |
+
**Default:** `false`.
|
47 |
+
|
48 |
+
* Returns: {Object} The parsed command line arguments:
|
49 |
+
* `values` {Object} A mapping of parsed option names with their {string}
|
50 |
+
or {boolean} values.
|
51 |
+
* `positionals` {string\[]} Positional arguments.
|
52 |
+
* `tokens` {Object\[] | undefined} See [parseArgs tokens](#parseargs-tokens)
|
53 |
+
section. Only returned if `config` includes `tokens: true`.
|
54 |
+
|
55 |
+
Provides a higher level API for command-line argument parsing than interacting
|
56 |
+
with `process.argv` directly. Takes a specification for the expected arguments
|
57 |
+
and returns a structured object with the parsed options and positionals.
|
58 |
+
|
59 |
+
```mjs
|
60 |
+
import { parseArgs } from 'node:util';
|
61 |
+
const args = ['-f', '--bar', 'b'];
|
62 |
+
const options = {
|
63 |
+
foo: {
|
64 |
+
type: 'boolean',
|
65 |
+
short: 'f'
|
66 |
+
},
|
67 |
+
bar: {
|
68 |
+
type: 'string'
|
69 |
+
}
|
70 |
+
};
|
71 |
+
const {
|
72 |
+
values,
|
73 |
+
positionals
|
74 |
+
} = parseArgs({ args, options });
|
75 |
+
console.log(values, positionals);
|
76 |
+
// Prints: [Object: null prototype] { foo: true, bar: 'b' } []
|
77 |
+
```
|
78 |
+
|
79 |
+
```cjs
|
80 |
+
const { parseArgs } = require('node:util');
|
81 |
+
const args = ['-f', '--bar', 'b'];
|
82 |
+
const options = {
|
83 |
+
foo: {
|
84 |
+
type: 'boolean',
|
85 |
+
short: 'f'
|
86 |
+
},
|
87 |
+
bar: {
|
88 |
+
type: 'string'
|
89 |
+
}
|
90 |
+
};
|
91 |
+
const {
|
92 |
+
values,
|
93 |
+
positionals
|
94 |
+
} = parseArgs({ args, options });
|
95 |
+
console.log(values, positionals);
|
96 |
+
// Prints: [Object: null prototype] { foo: true, bar: 'b' } []
|
97 |
+
```
|
98 |
+
|
99 |
+
`util.parseArgs` is experimental and behavior may change. Join the
|
100 |
+
conversation in [pkgjs/parseargs][] to contribute to the design.
|
101 |
+
|
102 |
+
### `parseArgs` `tokens`
|
103 |
+
|
104 |
+
Detailed parse information is available for adding custom behaviours by
|
105 |
+
specifying `tokens: true` in the configuration.
|
106 |
+
The returned tokens have properties describing:
|
107 |
+
|
108 |
+
* all tokens
|
109 |
+
* `kind` {string} One of 'option', 'positional', or 'option-terminator'.
|
110 |
+
* `index` {number} Index of element in `args` containing token. So the
|
111 |
+
source argument for a token is `args[token.index]`.
|
112 |
+
* option tokens
|
113 |
+
* `name` {string} Long name of option.
|
114 |
+
* `rawName` {string} How option used in args, like `-f` of `--foo`.
|
115 |
+
* `value` {string | undefined} Option value specified in args.
|
116 |
+
Undefined for boolean options.
|
117 |
+
* `inlineValue` {boolean | undefined} Whether option value specified inline,
|
118 |
+
like `--foo=bar`.
|
119 |
+
* positional tokens
|
120 |
+
* `value` {string} The value of the positional argument in args (i.e. `args[index]`).
|
121 |
+
* option-terminator token
|
122 |
+
|
123 |
+
The returned tokens are in the order encountered in the input args. Options
|
124 |
+
that appear more than once in args produce a token for each use. Short option
|
125 |
+
groups like `-xy` expand to a token for each option. So `-xxx` produces
|
126 |
+
three tokens.
|
127 |
+
|
128 |
+
For example to use the returned tokens to add support for a negated option
|
129 |
+
like `--no-color`, the tokens can be reprocessed to change the value stored
|
130 |
+
for the negated option.
|
131 |
+
|
132 |
+
```mjs
|
133 |
+
import { parseArgs } from 'node:util';
|
134 |
+
|
135 |
+
const options = {
|
136 |
+
'color': { type: 'boolean' },
|
137 |
+
'no-color': { type: 'boolean' },
|
138 |
+
'logfile': { type: 'string' },
|
139 |
+
'no-logfile': { type: 'boolean' },
|
140 |
+
};
|
141 |
+
const { values, tokens } = parseArgs({ options, tokens: true });
|
142 |
+
|
143 |
+
// Reprocess the option tokens and overwrite the returned values.
|
144 |
+
tokens
|
145 |
+
.filter((token) => token.kind === 'option')
|
146 |
+
.forEach((token) => {
|
147 |
+
if (token.name.startsWith('no-')) {
|
148 |
+
// Store foo:false for --no-foo
|
149 |
+
const positiveName = token.name.slice(3);
|
150 |
+
values[positiveName] = false;
|
151 |
+
delete values[token.name];
|
152 |
+
} else {
|
153 |
+
// Resave value so last one wins if both --foo and --no-foo.
|
154 |
+
values[token.name] = token.value ?? true;
|
155 |
+
}
|
156 |
+
});
|
157 |
+
|
158 |
+
const color = values.color;
|
159 |
+
const logfile = values.logfile ?? 'default.log';
|
160 |
+
|
161 |
+
console.log({ logfile, color });
|
162 |
+
```
|
163 |
+
|
164 |
+
```cjs
|
165 |
+
const { parseArgs } = require('node:util');
|
166 |
+
|
167 |
+
const options = {
|
168 |
+
'color': { type: 'boolean' },
|
169 |
+
'no-color': { type: 'boolean' },
|
170 |
+
'logfile': { type: 'string' },
|
171 |
+
'no-logfile': { type: 'boolean' },
|
172 |
+
};
|
173 |
+
const { values, tokens } = parseArgs({ options, tokens: true });
|
174 |
+
|
175 |
+
// Reprocess the option tokens and overwrite the returned values.
|
176 |
+
tokens
|
177 |
+
.filter((token) => token.kind === 'option')
|
178 |
+
.forEach((token) => {
|
179 |
+
if (token.name.startsWith('no-')) {
|
180 |
+
// Store foo:false for --no-foo
|
181 |
+
const positiveName = token.name.slice(3);
|
182 |
+
values[positiveName] = false;
|
183 |
+
delete values[token.name];
|
184 |
+
} else {
|
185 |
+
// Resave value so last one wins if both --foo and --no-foo.
|
186 |
+
values[token.name] = token.value ?? true;
|
187 |
+
}
|
188 |
+
});
|
189 |
+
|
190 |
+
const color = values.color;
|
191 |
+
const logfile = values.logfile ?? 'default.log';
|
192 |
+
|
193 |
+
console.log({ logfile, color });
|
194 |
+
```
|
195 |
+
|
196 |
+
Example usage showing negated options, and when an option is used
|
197 |
+
multiple ways then last one wins.
|
198 |
+
|
199 |
+
```console
|
200 |
+
$ node negate.js
|
201 |
+
{ logfile: 'default.log', color: undefined }
|
202 |
+
$ node negate.js --no-logfile --no-color
|
203 |
+
{ logfile: false, color: false }
|
204 |
+
$ node negate.js --logfile=test.log --color
|
205 |
+
{ logfile: 'test.log', color: true }
|
206 |
+
$ node negate.js --no-logfile --logfile=test.log --color --no-color
|
207 |
+
{ logfile: 'test.log', color: false }
|
208 |
+
```
|
209 |
+
|
210 |
+
-----
|
211 |
+
|
212 |
+
<!-- omit in toc -->
|
213 |
+
## Table of Contents
|
214 |
+
- [`util.parseArgs([config])`](#utilparseargsconfig)
|
215 |
+
- [Scope](#scope)
|
216 |
+
- [Version Matchups](#version-matchups)
|
217 |
+
- [🚀 Getting Started](#-getting-started)
|
218 |
+
- [🙌 Contributing](#-contributing)
|
219 |
+
- [💡 `process.mainArgs` Proposal](#-processmainargs-proposal)
|
220 |
+
- [Implementation:](#implementation)
|
221 |
+
- [📃 Examples](#-examples)
|
222 |
+
- [F.A.Qs](#faqs)
|
223 |
+
- [Links & Resources](#links--resources)
|
224 |
+
|
225 |
+
-----
|
226 |
+
|
227 |
+
## Scope
|
228 |
+
|
229 |
+
It is already possible to build great arg parsing modules on top of what Node.js provides; the prickly API is abstracted away by these modules. Thus, process.parseArgs() is not necessarily intended for library authors; it is intended for developers of simple CLI tools, ad-hoc scripts, deployed Node.js applications, and learning materials.
|
230 |
+
|
231 |
+
It is exceedingly difficult to provide an API which would both be friendly to these Node.js users while being extensible enough for libraries to build upon. We chose to prioritize these use cases because these are currently not well-served by Node.js' API.
|
232 |
+
|
233 |
+
----
|
234 |
+
|
235 |
+
## Version Matchups
|
236 |
+
|
237 |
+
| Node.js | @pkgjs/parseArgs |
|
238 |
+
| -- | -- |
|
239 |
+
| [v18.3.0](https://nodejs.org/docs/latest-v18.x/api/util.html#utilparseargsconfig) | [v0.9.1](https://github.com/pkgjs/parseargs/tree/v0.9.1#utilparseargsconfig) |
|
240 |
+
| [v16.17.0](https://nodejs.org/dist/latest-v16.x/docs/api/util.html#utilparseargsconfig), [v18.7.0](https://nodejs.org/docs/latest-v18.x/api/util.html#utilparseargsconfig) | [0.10.0](https://github.com/pkgjs/parseargs/tree/v0.10.0#utilparseargsconfig) |
|
241 |
+
|
242 |
+
----
|
243 |
+
|
244 |
+
## 🚀 Getting Started
|
245 |
+
|
246 |
+
1. **Install dependencies.**
|
247 |
+
|
248 |
+
```bash
|
249 |
+
npm install
|
250 |
+
```
|
251 |
+
|
252 |
+
2. **Open the index.js file and start editing!**
|
253 |
+
|
254 |
+
3. **Test your code by calling parseArgs through our test file**
|
255 |
+
|
256 |
+
```bash
|
257 |
+
npm test
|
258 |
+
```
|
259 |
+
|
260 |
+
----
|
261 |
+
|
262 |
+
## 🙌 Contributing
|
263 |
+
|
264 |
+
Any person who wants to contribute to the initiative is welcome! Please first read the [Contributing Guide](CONTRIBUTING.md)
|
265 |
+
|
266 |
+
Additionally, reading the [`Examples w/ Output`](#-examples-w-output) section of this document will be the best way to familiarize yourself with the target expected behavior for parseArgs() once it is fully implemented.
|
267 |
+
|
268 |
+
This package was implemented using [tape](https://www.npmjs.com/package/tape) as its test harness.
|
269 |
+
|
270 |
+
----
|
271 |
+
|
272 |
+
## 💡 `process.mainArgs` Proposal
|
273 |
+
|
274 |
+
> Note: This can be moved forward independently of the `util.parseArgs()` proposal/work.
|
275 |
+
|
276 |
+
### Implementation:
|
277 |
+
|
278 |
+
```javascript
|
279 |
+
process.mainArgs = process.argv.slice(process._exec ? 1 : 2)
|
280 |
+
```
|
281 |
+
|
282 |
+
----
|
283 |
+
|
284 |
+
## 📃 Examples
|
285 |
+
|
286 |
+
```js
|
287 |
+
const { parseArgs } = require('@pkgjs/parseargs');
|
288 |
+
```
|
289 |
+
|
290 |
+
```js
|
291 |
+
const { parseArgs } = require('@pkgjs/parseargs');
|
292 |
+
// specify the options that may be used
|
293 |
+
const options = {
|
294 |
+
foo: { type: 'string'},
|
295 |
+
bar: { type: 'boolean' },
|
296 |
+
};
|
297 |
+
const args = ['--foo=a', '--bar'];
|
298 |
+
const { values, positionals } = parseArgs({ args, options });
|
299 |
+
// values = { foo: 'a', bar: true }
|
300 |
+
// positionals = []
|
301 |
+
```
|
302 |
+
|
303 |
+
```js
|
304 |
+
const { parseArgs } = require('@pkgjs/parseargs');
|
305 |
+
// type:string & multiple
|
306 |
+
const options = {
|
307 |
+
foo: {
|
308 |
+
type: 'string',
|
309 |
+
multiple: true,
|
310 |
+
},
|
311 |
+
};
|
312 |
+
const args = ['--foo=a', '--foo', 'b'];
|
313 |
+
const { values, positionals } = parseArgs({ args, options });
|
314 |
+
// values = { foo: [ 'a', 'b' ] }
|
315 |
+
// positionals = []
|
316 |
+
```
|
317 |
+
|
318 |
+
```js
|
319 |
+
const { parseArgs } = require('@pkgjs/parseargs');
|
320 |
+
// shorts
|
321 |
+
const options = {
|
322 |
+
foo: {
|
323 |
+
short: 'f',
|
324 |
+
type: 'boolean'
|
325 |
+
},
|
326 |
+
};
|
327 |
+
const args = ['-f', 'b'];
|
328 |
+
const { values, positionals } = parseArgs({ args, options, allowPositionals: true });
|
329 |
+
// values = { foo: true }
|
330 |
+
// positionals = ['b']
|
331 |
+
```
|
332 |
+
|
333 |
+
```js
|
334 |
+
const { parseArgs } = require('@pkgjs/parseargs');
|
335 |
+
// unconfigured
|
336 |
+
const options = {};
|
337 |
+
const args = ['-f', '--foo=a', '--bar', 'b'];
|
338 |
+
const { values, positionals } = parseArgs({ strict: false, args, options, allowPositionals: true });
|
339 |
+
// values = { f: true, foo: 'a', bar: true }
|
340 |
+
// positionals = ['b']
|
341 |
+
```
|
342 |
+
|
343 |
+
----
|
344 |
+
|
345 |
+
## F.A.Qs
|
346 |
+
|
347 |
+
- Is `cmd --foo=bar baz` the same as `cmd baz --foo=bar`?
|
348 |
+
- yes
|
349 |
+
- Does the parser execute a function?
|
350 |
+
- no
|
351 |
+
- Does the parser execute one of several functions, depending on input?
|
352 |
+
- no
|
353 |
+
- Can subcommands take options that are distinct from the main command?
|
354 |
+
- no
|
355 |
+
- Does it output generated help when no options match?
|
356 |
+
- no
|
357 |
+
- Does it generated short usage? Like: `usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]`
|
358 |
+
- no (no usage/help at all)
|
359 |
+
- Does the user provide the long usage text? For each option? For the whole command?
|
360 |
+
- no
|
361 |
+
- Do subcommands (if implemented) have their own usage output?
|
362 |
+
- no
|
363 |
+
- Does usage print if the user runs `cmd --help`?
|
364 |
+
- no
|
365 |
+
- Does it set `process.exitCode`?
|
366 |
+
- no
|
367 |
+
- Does usage print to stderr or stdout?
|
368 |
+
- N/A
|
369 |
+
- Does it check types? (Say, specify that an option is a boolean, number, etc.)
|
370 |
+
- no
|
371 |
+
- Can an option have more than one type? (string or false, for example)
|
372 |
+
- no
|
373 |
+
- Can the user define a type? (Say, `type: path` to call `path.resolve()` on the argument.)
|
374 |
+
- no
|
375 |
+
- Does a `--foo=0o22` mean 0, 22, 18, or "0o22"?
|
376 |
+
- `"0o22"`
|
377 |
+
- Does it coerce types?
|
378 |
+
- no
|
379 |
+
- Does `--no-foo` coerce to `--foo=false`? For all options? Only boolean options?
|
380 |
+
- no, it sets `{values:{'no-foo': true}}`
|
381 |
+
- Is `--foo` the same as `--foo=true`? Only for known booleans? Only at the end?
|
382 |
+
- no, they are not the same. There is no special handling of `true` as a value so it is just another string.
|
383 |
+
- Does it read environment variables? Ie, is `FOO=1 cmd` the same as `cmd --foo=1`?
|
384 |
+
- no
|
385 |
+
- Do unknown arguments raise an error? Are they parsed? Are they treated as positional arguments?
|
386 |
+
- no, they are parsed, not treated as positionals
|
387 |
+
- Does `--` signal the end of options?
|
388 |
+
- yes
|
389 |
+
- Is `--` included as a positional?
|
390 |
+
- no
|
391 |
+
- Is `program -- foo` the same as `program foo`?
|
392 |
+
- yes, both store `{positionals:['foo']}`
|
393 |
+
- Does the API specify whether a `--` was present/relevant?
|
394 |
+
- no
|
395 |
+
- Is `-bar` the same as `--bar`?
|
396 |
+
- no, `-bar` is a short option or options, with expansion logic that follows the
|
397 |
+
[Utility Syntax Guidelines in POSIX.1-2017](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html). `-bar` expands to `-b`, `-a`, `-r`.
|
398 |
+
- Is `---foo` the same as `--foo`?
|
399 |
+
- no
|
400 |
+
- the first is a long option named `'-foo'`
|
401 |
+
- the second is a long option named `'foo'`
|
402 |
+
- Is `-` a positional? ie, `bash some-test.sh | tap -`
|
403 |
+
- yes
|
404 |
+
|
405 |
+
## Links & Resources
|
406 |
+
|
407 |
+
* [Initial Tooling Issue](https://github.com/nodejs/tooling/issues/19)
|
408 |
+
* [Initial Proposal](https://github.com/nodejs/node/pull/35015)
|
409 |
+
* [parseArgs Proposal](https://github.com/nodejs/node/pull/42675)
|
410 |
+
|
411 |
+
[coverage-image]: https://img.shields.io/nycrc/pkgjs/parseargs
|
412 |
+
[coverage-url]: https://github.com/pkgjs/parseargs/blob/main/.nycrc
|
413 |
+
[pkgjs/parseargs]: https://github.com/pkgjs/parseargs
|
node_modules/@pkgjs/parseargs/examples/is-default-value.js
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
// This example shows how to understand if a default value is used or not.
|
4 |
+
|
5 |
+
// 1. const { parseArgs } = require('node:util'); // from node
|
6 |
+
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
7 |
+
const { parseArgs } = require('..'); // in repo
|
8 |
+
|
9 |
+
const options = {
|
10 |
+
file: { short: 'f', type: 'string', default: 'FOO' },
|
11 |
+
};
|
12 |
+
|
13 |
+
const { values, tokens } = parseArgs({ options, tokens: true });
|
14 |
+
|
15 |
+
const isFileDefault = !tokens.some((token) => token.kind === 'option' &&
|
16 |
+
token.name === 'file'
|
17 |
+
);
|
18 |
+
|
19 |
+
console.log(values);
|
20 |
+
console.log(`Is the file option [${values.file}] the default value? ${isFileDefault}`);
|
21 |
+
|
22 |
+
// Try the following:
|
23 |
+
// node is-default-value.js
|
24 |
+
// node is-default-value.js -f FILE
|
25 |
+
// node is-default-value.js --file FILE
|
node_modules/@pkgjs/parseargs/examples/limit-long-syntax.js
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
// This is an example of using tokens to add a custom behaviour.
|
4 |
+
//
|
5 |
+
// Require the use of `=` for long options and values by blocking
|
6 |
+
// the use of space separated values.
|
7 |
+
// So allow `--foo=bar`, and not allow `--foo bar`.
|
8 |
+
//
|
9 |
+
// Note: this is not a common behaviour, most CLIs allow both forms.
|
10 |
+
|
11 |
+
// 1. const { parseArgs } = require('node:util'); // from node
|
12 |
+
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
13 |
+
const { parseArgs } = require('..'); // in repo
|
14 |
+
|
15 |
+
const options = {
|
16 |
+
file: { short: 'f', type: 'string' },
|
17 |
+
log: { type: 'string' },
|
18 |
+
};
|
19 |
+
|
20 |
+
const { values, tokens } = parseArgs({ options, tokens: true });
|
21 |
+
|
22 |
+
const badToken = tokens.find((token) => token.kind === 'option' &&
|
23 |
+
token.value != null &&
|
24 |
+
token.rawName.startsWith('--') &&
|
25 |
+
!token.inlineValue
|
26 |
+
);
|
27 |
+
if (badToken) {
|
28 |
+
throw new Error(`Option value for '${badToken.rawName}' must be inline, like '${badToken.rawName}=VALUE'`);
|
29 |
+
}
|
30 |
+
|
31 |
+
console.log(values);
|
32 |
+
|
33 |
+
// Try the following:
|
34 |
+
// node limit-long-syntax.js -f FILE --log=LOG
|
35 |
+
// node limit-long-syntax.js --file FILE
|
node_modules/@pkgjs/parseargs/examples/negate.js
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
// This example is used in the documentation.
|
4 |
+
|
5 |
+
// How might I add my own support for --no-foo?
|
6 |
+
|
7 |
+
// 1. const { parseArgs } = require('node:util'); // from node
|
8 |
+
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
9 |
+
const { parseArgs } = require('..'); // in repo
|
10 |
+
|
11 |
+
const options = {
|
12 |
+
'color': { type: 'boolean' },
|
13 |
+
'no-color': { type: 'boolean' },
|
14 |
+
'logfile': { type: 'string' },
|
15 |
+
'no-logfile': { type: 'boolean' },
|
16 |
+
};
|
17 |
+
const { values, tokens } = parseArgs({ options, tokens: true });
|
18 |
+
|
19 |
+
// Reprocess the option tokens and overwrite the returned values.
|
20 |
+
tokens
|
21 |
+
.filter((token) => token.kind === 'option')
|
22 |
+
.forEach((token) => {
|
23 |
+
if (token.name.startsWith('no-')) {
|
24 |
+
// Store foo:false for --no-foo
|
25 |
+
const positiveName = token.name.slice(3);
|
26 |
+
values[positiveName] = false;
|
27 |
+
delete values[token.name];
|
28 |
+
} else {
|
29 |
+
// Resave value so last one wins if both --foo and --no-foo.
|
30 |
+
values[token.name] = token.value ?? true;
|
31 |
+
}
|
32 |
+
});
|
33 |
+
|
34 |
+
const color = values.color;
|
35 |
+
const logfile = values.logfile ?? 'default.log';
|
36 |
+
|
37 |
+
console.log({ logfile, color });
|
38 |
+
|
39 |
+
// Try the following:
|
40 |
+
// node negate.js
|
41 |
+
// node negate.js --no-logfile --no-color
|
42 |
+
// negate.js --logfile=test.log --color
|
43 |
+
// node negate.js --no-logfile --logfile=test.log --color --no-color
|
node_modules/@pkgjs/parseargs/examples/no-repeated-options.js
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
// This is an example of using tokens to add a custom behaviour.
|
4 |
+
//
|
5 |
+
// Throw an error if an option is used more than once.
|
6 |
+
|
7 |
+
// 1. const { parseArgs } = require('node:util'); // from node
|
8 |
+
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
9 |
+
const { parseArgs } = require('..'); // in repo
|
10 |
+
|
11 |
+
const options = {
|
12 |
+
ding: { type: 'boolean', short: 'd' },
|
13 |
+
beep: { type: 'boolean', short: 'b' }
|
14 |
+
};
|
15 |
+
const { values, tokens } = parseArgs({ options, tokens: true });
|
16 |
+
|
17 |
+
const seenBefore = new Set();
|
18 |
+
tokens.forEach((token) => {
|
19 |
+
if (token.kind !== 'option') return;
|
20 |
+
if (seenBefore.has(token.name)) {
|
21 |
+
throw new Error(`option '${token.name}' used multiple times`);
|
22 |
+
}
|
23 |
+
seenBefore.add(token.name);
|
24 |
+
});
|
25 |
+
|
26 |
+
console.log(values);
|
27 |
+
|
28 |
+
// Try the following:
|
29 |
+
// node no-repeated-options --ding --beep
|
30 |
+
// node no-repeated-options --beep -b
|
31 |
+
// node no-repeated-options -ddd
|
node_modules/@pkgjs/parseargs/examples/ordered-options.mjs
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// This is an example of using tokens to add a custom behaviour.
|
2 |
+
//
|
3 |
+
// This adds a option order check so that --some-unstable-option
|
4 |
+
// may only be used after --enable-experimental-options
|
5 |
+
//
|
6 |
+
// Note: this is not a common behaviour, the order of different options
|
7 |
+
// does not usually matter.
|
8 |
+
|
9 |
+
import { parseArgs } from '../index.js';
|
10 |
+
|
11 |
+
function findTokenIndex(tokens, target) {
|
12 |
+
return tokens.findIndex((token) => token.kind === 'option' &&
|
13 |
+
token.name === target
|
14 |
+
);
|
15 |
+
}
|
16 |
+
|
17 |
+
const experimentalName = 'enable-experimental-options';
|
18 |
+
const unstableName = 'some-unstable-option';
|
19 |
+
|
20 |
+
const options = {
|
21 |
+
[experimentalName]: { type: 'boolean' },
|
22 |
+
[unstableName]: { type: 'boolean' },
|
23 |
+
};
|
24 |
+
|
25 |
+
const { values, tokens } = parseArgs({ options, tokens: true });
|
26 |
+
|
27 |
+
const experimentalIndex = findTokenIndex(tokens, experimentalName);
|
28 |
+
const unstableIndex = findTokenIndex(tokens, unstableName);
|
29 |
+
if (unstableIndex !== -1 &&
|
30 |
+
((experimentalIndex === -1) || (unstableIndex < experimentalIndex))) {
|
31 |
+
throw new Error(`'--${experimentalName}' must be specified before '--${unstableName}'`);
|
32 |
+
}
|
33 |
+
|
34 |
+
console.log(values);
|
35 |
+
|
36 |
+
/* eslint-disable max-len */
|
37 |
+
// Try the following:
|
38 |
+
// node ordered-options.mjs
|
39 |
+
// node ordered-options.mjs --some-unstable-option
|
40 |
+
// node ordered-options.mjs --some-unstable-option --enable-experimental-options
|
41 |
+
// node ordered-options.mjs --enable-experimental-options --some-unstable-option
|
node_modules/@pkgjs/parseargs/examples/simple-hard-coded.js
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
// This example is used in the documentation.
|
4 |
+
|
5 |
+
// 1. const { parseArgs } = require('node:util'); // from node
|
6 |
+
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
7 |
+
const { parseArgs } = require('..'); // in repo
|
8 |
+
|
9 |
+
const args = ['-f', '--bar', 'b'];
|
10 |
+
const options = {
|
11 |
+
foo: {
|
12 |
+
type: 'boolean',
|
13 |
+
short: 'f'
|
14 |
+
},
|
15 |
+
bar: {
|
16 |
+
type: 'string'
|
17 |
+
}
|
18 |
+
};
|
19 |
+
const {
|
20 |
+
values,
|
21 |
+
positionals
|
22 |
+
} = parseArgs({ args, options });
|
23 |
+
console.log(values, positionals);
|
24 |
+
|
25 |
+
// Try the following:
|
26 |
+
// node simple-hard-coded.js
|
node_modules/@pkgjs/parseargs/index.js
ADDED
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
const {
|
4 |
+
ArrayPrototypeForEach,
|
5 |
+
ArrayPrototypeIncludes,
|
6 |
+
ArrayPrototypeMap,
|
7 |
+
ArrayPrototypePush,
|
8 |
+
ArrayPrototypePushApply,
|
9 |
+
ArrayPrototypeShift,
|
10 |
+
ArrayPrototypeSlice,
|
11 |
+
ArrayPrototypeUnshiftApply,
|
12 |
+
ObjectEntries,
|
13 |
+
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
14 |
+
StringPrototypeCharAt,
|
15 |
+
StringPrototypeIndexOf,
|
16 |
+
StringPrototypeSlice,
|
17 |
+
StringPrototypeStartsWith,
|
18 |
+
} = require('./internal/primordials');
|
19 |
+
|
20 |
+
const {
|
21 |
+
validateArray,
|
22 |
+
validateBoolean,
|
23 |
+
validateBooleanArray,
|
24 |
+
validateObject,
|
25 |
+
validateString,
|
26 |
+
validateStringArray,
|
27 |
+
validateUnion,
|
28 |
+
} = require('./internal/validators');
|
29 |
+
|
30 |
+
const {
|
31 |
+
kEmptyObject,
|
32 |
+
} = require('./internal/util');
|
33 |
+
|
34 |
+
const {
|
35 |
+
findLongOptionForShort,
|
36 |
+
isLoneLongOption,
|
37 |
+
isLoneShortOption,
|
38 |
+
isLongOptionAndValue,
|
39 |
+
isOptionValue,
|
40 |
+
isOptionLikeValue,
|
41 |
+
isShortOptionAndValue,
|
42 |
+
isShortOptionGroup,
|
43 |
+
useDefaultValueOption,
|
44 |
+
objectGetOwn,
|
45 |
+
optionsGetOwn,
|
46 |
+
} = require('./utils');
|
47 |
+
|
48 |
+
const {
|
49 |
+
codes: {
|
50 |
+
ERR_INVALID_ARG_VALUE,
|
51 |
+
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
|
52 |
+
ERR_PARSE_ARGS_UNKNOWN_OPTION,
|
53 |
+
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
|
54 |
+
},
|
55 |
+
} = require('./internal/errors');
|
56 |
+
|
57 |
+
function getMainArgs() {
|
58 |
+
// Work out where to slice process.argv for user supplied arguments.
|
59 |
+
|
60 |
+
// Check node options for scenarios where user CLI args follow executable.
|
61 |
+
const execArgv = process.execArgv;
|
62 |
+
if (ArrayPrototypeIncludes(execArgv, '-e') ||
|
63 |
+
ArrayPrototypeIncludes(execArgv, '--eval') ||
|
64 |
+
ArrayPrototypeIncludes(execArgv, '-p') ||
|
65 |
+
ArrayPrototypeIncludes(execArgv, '--print')) {
|
66 |
+
return ArrayPrototypeSlice(process.argv, 1);
|
67 |
+
}
|
68 |
+
|
69 |
+
// Normally first two arguments are executable and script, then CLI arguments
|
70 |
+
return ArrayPrototypeSlice(process.argv, 2);
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* In strict mode, throw for possible usage errors like --foo --bar
|
75 |
+
*
|
76 |
+
* @param {object} token - from tokens as available from parseArgs
|
77 |
+
*/
|
78 |
+
function checkOptionLikeValue(token) {
|
79 |
+
if (!token.inlineValue && isOptionLikeValue(token.value)) {
|
80 |
+
// Only show short example if user used short option.
|
81 |
+
const example = StringPrototypeStartsWith(token.rawName, '--') ?
|
82 |
+
`'${token.rawName}=-XYZ'` :
|
83 |
+
`'--${token.name}=-XYZ' or '${token.rawName}-XYZ'`;
|
84 |
+
const errorMessage = `Option '${token.rawName}' argument is ambiguous.
|
85 |
+
Did you forget to specify the option argument for '${token.rawName}'?
|
86 |
+
To specify an option argument starting with a dash use ${example}.`;
|
87 |
+
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(errorMessage);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* In strict mode, throw for usage errors.
|
93 |
+
*
|
94 |
+
* @param {object} config - from config passed to parseArgs
|
95 |
+
* @param {object} token - from tokens as available from parseArgs
|
96 |
+
*/
|
97 |
+
function checkOptionUsage(config, token) {
|
98 |
+
if (!ObjectHasOwn(config.options, token.name)) {
|
99 |
+
throw new ERR_PARSE_ARGS_UNKNOWN_OPTION(
|
100 |
+
token.rawName, config.allowPositionals);
|
101 |
+
}
|
102 |
+
|
103 |
+
const short = optionsGetOwn(config.options, token.name, 'short');
|
104 |
+
const shortAndLong = `${short ? `-${short}, ` : ''}--${token.name}`;
|
105 |
+
const type = optionsGetOwn(config.options, token.name, 'type');
|
106 |
+
if (type === 'string' && typeof token.value !== 'string') {
|
107 |
+
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong} <value>' argument missing`);
|
108 |
+
}
|
109 |
+
// (Idiomatic test for undefined||null, expecting undefined.)
|
110 |
+
if (type === 'boolean' && token.value != null) {
|
111 |
+
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong}' does not take an argument`);
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Store the option value in `values`.
|
118 |
+
*
|
119 |
+
* @param {string} longOption - long option name e.g. 'foo'
|
120 |
+
* @param {string|undefined} optionValue - value from user args
|
121 |
+
* @param {object} options - option configs, from parseArgs({ options })
|
122 |
+
* @param {object} values - option values returned in `values` by parseArgs
|
123 |
+
*/
|
124 |
+
function storeOption(longOption, optionValue, options, values) {
|
125 |
+
if (longOption === '__proto__') {
|
126 |
+
return; // No. Just no.
|
127 |
+
}
|
128 |
+
|
129 |
+
// We store based on the option value rather than option type,
|
130 |
+
// preserving the users intent for author to deal with.
|
131 |
+
const newValue = optionValue ?? true;
|
132 |
+
if (optionsGetOwn(options, longOption, 'multiple')) {
|
133 |
+
// Always store value in array, including for boolean.
|
134 |
+
// values[longOption] starts out not present,
|
135 |
+
// first value is added as new array [newValue],
|
136 |
+
// subsequent values are pushed to existing array.
|
137 |
+
// (note: values has null prototype, so simpler usage)
|
138 |
+
if (values[longOption]) {
|
139 |
+
ArrayPrototypePush(values[longOption], newValue);
|
140 |
+
} else {
|
141 |
+
values[longOption] = [newValue];
|
142 |
+
}
|
143 |
+
} else {
|
144 |
+
values[longOption] = newValue;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Store the default option value in `values`.
|
150 |
+
*
|
151 |
+
* @param {string} longOption - long option name e.g. 'foo'
|
152 |
+
* @param {string
|
153 |
+
* | boolean
|
154 |
+
* | string[]
|
155 |
+
* | boolean[]} optionValue - default value from option config
|
156 |
+
* @param {object} values - option values returned in `values` by parseArgs
|
157 |
+
*/
|
158 |
+
function storeDefaultOption(longOption, optionValue, values) {
|
159 |
+
if (longOption === '__proto__') {
|
160 |
+
return; // No. Just no.
|
161 |
+
}
|
162 |
+
|
163 |
+
values[longOption] = optionValue;
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Process args and turn into identified tokens:
|
168 |
+
* - option (along with value, if any)
|
169 |
+
* - positional
|
170 |
+
* - option-terminator
|
171 |
+
*
|
172 |
+
* @param {string[]} args - from parseArgs({ args }) or mainArgs
|
173 |
+
* @param {object} options - option configs, from parseArgs({ options })
|
174 |
+
*/
|
175 |
+
function argsToTokens(args, options) {
|
176 |
+
const tokens = [];
|
177 |
+
let index = -1;
|
178 |
+
let groupCount = 0;
|
179 |
+
|
180 |
+
const remainingArgs = ArrayPrototypeSlice(args);
|
181 |
+
while (remainingArgs.length > 0) {
|
182 |
+
const arg = ArrayPrototypeShift(remainingArgs);
|
183 |
+
const nextArg = remainingArgs[0];
|
184 |
+
if (groupCount > 0)
|
185 |
+
groupCount--;
|
186 |
+
else
|
187 |
+
index++;
|
188 |
+
|
189 |
+
// Check if `arg` is an options terminator.
|
190 |
+
// Guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
191 |
+
if (arg === '--') {
|
192 |
+
// Everything after a bare '--' is considered a positional argument.
|
193 |
+
ArrayPrototypePush(tokens, { kind: 'option-terminator', index });
|
194 |
+
ArrayPrototypePushApply(
|
195 |
+
tokens, ArrayPrototypeMap(remainingArgs, (arg) => {
|
196 |
+
return { kind: 'positional', index: ++index, value: arg };
|
197 |
+
})
|
198 |
+
);
|
199 |
+
break; // Finished processing args, leave while loop.
|
200 |
+
}
|
201 |
+
|
202 |
+
if (isLoneShortOption(arg)) {
|
203 |
+
// e.g. '-f'
|
204 |
+
const shortOption = StringPrototypeCharAt(arg, 1);
|
205 |
+
const longOption = findLongOptionForShort(shortOption, options);
|
206 |
+
let value;
|
207 |
+
let inlineValue;
|
208 |
+
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
209 |
+
isOptionValue(nextArg)) {
|
210 |
+
// e.g. '-f', 'bar'
|
211 |
+
value = ArrayPrototypeShift(remainingArgs);
|
212 |
+
inlineValue = false;
|
213 |
+
}
|
214 |
+
ArrayPrototypePush(
|
215 |
+
tokens,
|
216 |
+
{ kind: 'option', name: longOption, rawName: arg,
|
217 |
+
index, value, inlineValue });
|
218 |
+
if (value != null) ++index;
|
219 |
+
continue;
|
220 |
+
}
|
221 |
+
|
222 |
+
if (isShortOptionGroup(arg, options)) {
|
223 |
+
// Expand -fXzy to -f -X -z -y
|
224 |
+
const expanded = [];
|
225 |
+
for (let index = 1; index < arg.length; index++) {
|
226 |
+
const shortOption = StringPrototypeCharAt(arg, index);
|
227 |
+
const longOption = findLongOptionForShort(shortOption, options);
|
228 |
+
if (optionsGetOwn(options, longOption, 'type') !== 'string' ||
|
229 |
+
index === arg.length - 1) {
|
230 |
+
// Boolean option, or last short in group. Well formed.
|
231 |
+
ArrayPrototypePush(expanded, `-${shortOption}`);
|
232 |
+
} else {
|
233 |
+
// String option in middle. Yuck.
|
234 |
+
// Expand -abfFILE to -a -b -fFILE
|
235 |
+
ArrayPrototypePush(expanded, `-${StringPrototypeSlice(arg, index)}`);
|
236 |
+
break; // finished short group
|
237 |
+
}
|
238 |
+
}
|
239 |
+
ArrayPrototypeUnshiftApply(remainingArgs, expanded);
|
240 |
+
groupCount = expanded.length;
|
241 |
+
continue;
|
242 |
+
}
|
243 |
+
|
244 |
+
if (isShortOptionAndValue(arg, options)) {
|
245 |
+
// e.g. -fFILE
|
246 |
+
const shortOption = StringPrototypeCharAt(arg, 1);
|
247 |
+
const longOption = findLongOptionForShort(shortOption, options);
|
248 |
+
const value = StringPrototypeSlice(arg, 2);
|
249 |
+
ArrayPrototypePush(
|
250 |
+
tokens,
|
251 |
+
{ kind: 'option', name: longOption, rawName: `-${shortOption}`,
|
252 |
+
index, value, inlineValue: true });
|
253 |
+
continue;
|
254 |
+
}
|
255 |
+
|
256 |
+
if (isLoneLongOption(arg)) {
|
257 |
+
// e.g. '--foo'
|
258 |
+
const longOption = StringPrototypeSlice(arg, 2);
|
259 |
+
let value;
|
260 |
+
let inlineValue;
|
261 |
+
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
262 |
+
isOptionValue(nextArg)) {
|
263 |
+
// e.g. '--foo', 'bar'
|
264 |
+
value = ArrayPrototypeShift(remainingArgs);
|
265 |
+
inlineValue = false;
|
266 |
+
}
|
267 |
+
ArrayPrototypePush(
|
268 |
+
tokens,
|
269 |
+
{ kind: 'option', name: longOption, rawName: arg,
|
270 |
+
index, value, inlineValue });
|
271 |
+
if (value != null) ++index;
|
272 |
+
continue;
|
273 |
+
}
|
274 |
+
|
275 |
+
if (isLongOptionAndValue(arg)) {
|
276 |
+
// e.g. --foo=bar
|
277 |
+
const equalIndex = StringPrototypeIndexOf(arg, '=');
|
278 |
+
const longOption = StringPrototypeSlice(arg, 2, equalIndex);
|
279 |
+
const value = StringPrototypeSlice(arg, equalIndex + 1);
|
280 |
+
ArrayPrototypePush(
|
281 |
+
tokens,
|
282 |
+
{ kind: 'option', name: longOption, rawName: `--${longOption}`,
|
283 |
+
index, value, inlineValue: true });
|
284 |
+
continue;
|
285 |
+
}
|
286 |
+
|
287 |
+
ArrayPrototypePush(tokens, { kind: 'positional', index, value: arg });
|
288 |
+
}
|
289 |
+
|
290 |
+
return tokens;
|
291 |
+
}
|
292 |
+
|
293 |
+
const parseArgs = (config = kEmptyObject) => {
|
294 |
+
const args = objectGetOwn(config, 'args') ?? getMainArgs();
|
295 |
+
const strict = objectGetOwn(config, 'strict') ?? true;
|
296 |
+
const allowPositionals = objectGetOwn(config, 'allowPositionals') ?? !strict;
|
297 |
+
const returnTokens = objectGetOwn(config, 'tokens') ?? false;
|
298 |
+
const options = objectGetOwn(config, 'options') ?? { __proto__: null };
|
299 |
+
// Bundle these up for passing to strict-mode checks.
|
300 |
+
const parseConfig = { args, strict, options, allowPositionals };
|
301 |
+
|
302 |
+
// Validate input configuration.
|
303 |
+
validateArray(args, 'args');
|
304 |
+
validateBoolean(strict, 'strict');
|
305 |
+
validateBoolean(allowPositionals, 'allowPositionals');
|
306 |
+
validateBoolean(returnTokens, 'tokens');
|
307 |
+
validateObject(options, 'options');
|
308 |
+
ArrayPrototypeForEach(
|
309 |
+
ObjectEntries(options),
|
310 |
+
({ 0: longOption, 1: optionConfig }) => {
|
311 |
+
validateObject(optionConfig, `options.${longOption}`);
|
312 |
+
|
313 |
+
// type is required
|
314 |
+
const optionType = objectGetOwn(optionConfig, 'type');
|
315 |
+
validateUnion(optionType, `options.${longOption}.type`, ['string', 'boolean']);
|
316 |
+
|
317 |
+
if (ObjectHasOwn(optionConfig, 'short')) {
|
318 |
+
const shortOption = optionConfig.short;
|
319 |
+
validateString(shortOption, `options.${longOption}.short`);
|
320 |
+
if (shortOption.length !== 1) {
|
321 |
+
throw new ERR_INVALID_ARG_VALUE(
|
322 |
+
`options.${longOption}.short`,
|
323 |
+
shortOption,
|
324 |
+
'must be a single character'
|
325 |
+
);
|
326 |
+
}
|
327 |
+
}
|
328 |
+
|
329 |
+
const multipleOption = objectGetOwn(optionConfig, 'multiple');
|
330 |
+
if (ObjectHasOwn(optionConfig, 'multiple')) {
|
331 |
+
validateBoolean(multipleOption, `options.${longOption}.multiple`);
|
332 |
+
}
|
333 |
+
|
334 |
+
const defaultValue = objectGetOwn(optionConfig, 'default');
|
335 |
+
if (defaultValue !== undefined) {
|
336 |
+
let validator;
|
337 |
+
switch (optionType) {
|
338 |
+
case 'string':
|
339 |
+
validator = multipleOption ? validateStringArray : validateString;
|
340 |
+
break;
|
341 |
+
|
342 |
+
case 'boolean':
|
343 |
+
validator = multipleOption ? validateBooleanArray : validateBoolean;
|
344 |
+
break;
|
345 |
+
}
|
346 |
+
validator(defaultValue, `options.${longOption}.default`);
|
347 |
+
}
|
348 |
+
}
|
349 |
+
);
|
350 |
+
|
351 |
+
// Phase 1: identify tokens
|
352 |
+
const tokens = argsToTokens(args, options);
|
353 |
+
|
354 |
+
// Phase 2: process tokens into parsed option values and positionals
|
355 |
+
const result = {
|
356 |
+
values: { __proto__: null },
|
357 |
+
positionals: [],
|
358 |
+
};
|
359 |
+
if (returnTokens) {
|
360 |
+
result.tokens = tokens;
|
361 |
+
}
|
362 |
+
ArrayPrototypeForEach(tokens, (token) => {
|
363 |
+
if (token.kind === 'option') {
|
364 |
+
if (strict) {
|
365 |
+
checkOptionUsage(parseConfig, token);
|
366 |
+
checkOptionLikeValue(token);
|
367 |
+
}
|
368 |
+
storeOption(token.name, token.value, options, result.values);
|
369 |
+
} else if (token.kind === 'positional') {
|
370 |
+
if (!allowPositionals) {
|
371 |
+
throw new ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL(token.value);
|
372 |
+
}
|
373 |
+
ArrayPrototypePush(result.positionals, token.value);
|
374 |
+
}
|
375 |
+
});
|
376 |
+
|
377 |
+
// Phase 3: fill in default values for missing args
|
378 |
+
ArrayPrototypeForEach(ObjectEntries(options), ({ 0: longOption,
|
379 |
+
1: optionConfig }) => {
|
380 |
+
const mustSetDefault = useDefaultValueOption(longOption,
|
381 |
+
optionConfig,
|
382 |
+
result.values);
|
383 |
+
if (mustSetDefault) {
|
384 |
+
storeDefaultOption(longOption,
|
385 |
+
objectGetOwn(optionConfig, 'default'),
|
386 |
+
result.values);
|
387 |
+
}
|
388 |
+
});
|
389 |
+
|
390 |
+
|
391 |
+
return result;
|
392 |
+
};
|
393 |
+
|
394 |
+
module.exports = {
|
395 |
+
parseArgs,
|
396 |
+
};
|
node_modules/@pkgjs/parseargs/internal/errors.js
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict';
|
2 |
+
|
3 |
+
class ERR_INVALID_ARG_TYPE extends TypeError {
|
4 |
+
constructor(name, expected, actual) {
|
5 |
+
super(`${name} must be ${expected} got ${actual}`);
|
6 |
+
this.code = 'ERR_INVALID_ARG_TYPE';
|
7 |
+
}
|
8 |
+
}
|
9 |
+
|
10 |
+
class ERR_INVALID_ARG_VALUE extends TypeError {
|
11 |
+
constructor(arg1, arg2, expected) {
|
12 |
+
super(`The property ${arg1} ${expected}. Received '${arg2}'`);
|
13 |
+
this.code = 'ERR_INVALID_ARG_VALUE';
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
class ERR_PARSE_ARGS_INVALID_OPTION_VALUE extends Error {
|
18 |
+
constructor(message) {
|
19 |
+
super(message);
|
20 |
+
this.code = 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE';
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
class ERR_PARSE_ARGS_UNKNOWN_OPTION extends Error {
|
25 |
+
constructor(option, allowPositionals) {
|
26 |
+
const suggestDashDash = allowPositionals ? `. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- ${JSON.stringify(option)}` : '';
|
27 |
+
super(`Unknown option '${option}'${suggestDashDash}`);
|
28 |
+
this.code = 'ERR_PARSE_ARGS_UNKNOWN_OPTION';
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
class ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL extends Error {
|
33 |
+
constructor(positional) {
|
34 |
+
super(`Unexpected argument '${positional}'. This command does not take positional arguments`);
|
35 |
+
this.code = 'ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL';
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
module.exports = {
|
40 |
+
codes: {
|
41 |
+
ERR_INVALID_ARG_TYPE,
|
42 |
+
ERR_INVALID_ARG_VALUE,
|
43 |
+
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
|
44 |
+
ERR_PARSE_ARGS_UNKNOWN_OPTION,
|
45 |
+
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
|
46 |
+
}
|
47 |
+
};
|
node_modules/@pkgjs/parseargs/internal/primordials.js
ADDED
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
This file is copied from https://github.com/nodejs/node/blob/v14.19.3/lib/internal/per_context/primordials.js
|
3 |
+
under the following license:
|
4 |
+
|
5 |
+
Copyright Node.js contributors. All rights reserved.
|
6 |
+
|
7 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 |
+
of this software and associated documentation files (the "Software"), to
|
9 |
+
deal in the Software without restriction, including without limitation the
|
10 |
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
11 |
+
sell copies of the Software, and to permit persons to whom the Software is
|
12 |
+
furnished to do so, subject to the following conditions:
|
13 |
+
|
14 |
+
The above copyright notice and this permission notice shall be included in
|
15 |
+
all copies or substantial portions of the Software.
|
16 |
+
|
17 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
23 |
+
IN THE SOFTWARE.
|
24 |
+
*/
|
25 |
+
|
26 |
+
'use strict';
|
27 |
+
|
28 |
+
/* eslint-disable node-core/prefer-primordials */
|
29 |
+
|
30 |
+
// This file subclasses and stores the JS builtins that come from the VM
|
31 |
+
// so that Node.js's builtin modules do not need to later look these up from
|
32 |
+
// the global proxy, which can be mutated by users.
|
33 |
+
|
34 |
+
// Use of primordials have sometimes a dramatic impact on performance, please
|
35 |
+
// benchmark all changes made in performance-sensitive areas of the codebase.
|
36 |
+
// See: https://github.com/nodejs/node/pull/38248
|
37 |
+
|
38 |
+
const primordials = {};
|
39 |
+
|
40 |
+
const {
|
41 |
+
defineProperty: ReflectDefineProperty,
|
42 |
+
getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
|
43 |
+
ownKeys: ReflectOwnKeys,
|
44 |
+
} = Reflect;
|
45 |
+
|
46 |
+
// `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.
|
47 |
+
// It is using `bind.bind(call)` to avoid using `Function.prototype.bind`
|
48 |
+
// and `Function.prototype.call` after it may have been mutated by users.
|
49 |
+
const { apply, bind, call } = Function.prototype;
|
50 |
+
const uncurryThis = bind.bind(call);
|
51 |
+
primordials.uncurryThis = uncurryThis;
|
52 |
+
|
53 |
+
// `applyBind` is equivalent to `func => Function.prototype.apply.bind(func)`.
|
54 |
+
// It is using `bind.bind(apply)` to avoid using `Function.prototype.bind`
|
55 |
+
// and `Function.prototype.apply` after it may have been mutated by users.
|
56 |
+
const applyBind = bind.bind(apply);
|
57 |
+
primordials.applyBind = applyBind;
|
58 |
+
|
59 |
+
// Methods that accept a variable number of arguments, and thus it's useful to
|
60 |
+
// also create `${prefix}${key}Apply`, which uses `Function.prototype.apply`,
|
61 |
+
// instead of `Function.prototype.call`, and thus doesn't require iterator
|
62 |
+
// destructuring.
|
63 |
+
const varargsMethods = [
|
64 |
+
// 'ArrayPrototypeConcat' is omitted, because it performs the spread
|
65 |
+
// on its own for arrays and array-likes with a truthy
|
66 |
+
// @@isConcatSpreadable symbol property.
|
67 |
+
'ArrayOf',
|
68 |
+
'ArrayPrototypePush',
|
69 |
+
'ArrayPrototypeUnshift',
|
70 |
+
// 'FunctionPrototypeCall' is omitted, since there's 'ReflectApply'
|
71 |
+
// and 'FunctionPrototypeApply'.
|
72 |
+
'MathHypot',
|
73 |
+
'MathMax',
|
74 |
+
'MathMin',
|
75 |
+
'StringPrototypeConcat',
|
76 |
+
'TypedArrayOf',
|
77 |
+
];
|
78 |
+
|
79 |
+
function getNewKey(key) {
|
80 |
+
return typeof key === 'symbol' ?
|
81 |
+
`Symbol${key.description[7].toUpperCase()}${key.description.slice(8)}` :
|
82 |
+
`${key[0].toUpperCase()}${key.slice(1)}`;
|
83 |
+
}
|
84 |
+
|
85 |
+
function copyAccessor(dest, prefix, key, { enumerable, get, set }) {
|
86 |
+
ReflectDefineProperty(dest, `${prefix}Get${key}`, {
|
87 |
+
value: uncurryThis(get),
|
88 |
+
enumerable
|
89 |
+
});
|
90 |
+
if (set !== undefined) {
|
91 |
+
ReflectDefineProperty(dest, `${prefix}Set${key}`, {
|
92 |
+
value: uncurryThis(set),
|
93 |
+
enumerable
|
94 |
+
});
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
function copyPropsRenamed(src, dest, prefix) {
|
99 |
+
for (const key of ReflectOwnKeys(src)) {
|
100 |
+
const newKey = getNewKey(key);
|
101 |
+
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
102 |
+
if ('get' in desc) {
|
103 |
+
copyAccessor(dest, prefix, newKey, desc);
|
104 |
+
} else {
|
105 |
+
const name = `${prefix}${newKey}`;
|
106 |
+
ReflectDefineProperty(dest, name, desc);
|
107 |
+
if (varargsMethods.includes(name)) {
|
108 |
+
ReflectDefineProperty(dest, `${name}Apply`, {
|
109 |
+
// `src` is bound as the `this` so that the static `this` points
|
110 |
+
// to the object it was defined on,
|
111 |
+
// e.g.: `ArrayOfApply` gets a `this` of `Array`:
|
112 |
+
value: applyBind(desc.value, src),
|
113 |
+
});
|
114 |
+
}
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
function copyPropsRenamedBound(src, dest, prefix) {
|
120 |
+
for (const key of ReflectOwnKeys(src)) {
|
121 |
+
const newKey = getNewKey(key);
|
122 |
+
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
123 |
+
if ('get' in desc) {
|
124 |
+
copyAccessor(dest, prefix, newKey, desc);
|
125 |
+
} else {
|
126 |
+
const { value } = desc;
|
127 |
+
if (typeof value === 'function') {
|
128 |
+
desc.value = value.bind(src);
|
129 |
+
}
|
130 |
+
|
131 |
+
const name = `${prefix}${newKey}`;
|
132 |
+
ReflectDefineProperty(dest, name, desc);
|
133 |
+
if (varargsMethods.includes(name)) {
|
134 |
+
ReflectDefineProperty(dest, `${name}Apply`, {
|
135 |
+
value: applyBind(value, src),
|
136 |
+
});
|
137 |
+
}
|
138 |
+
}
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
function copyPrototype(src, dest, prefix) {
|
143 |
+
for (const key of ReflectOwnKeys(src)) {
|
144 |
+
const newKey = getNewKey(key);
|
145 |
+
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
146 |
+
if ('get' in desc) {
|
147 |
+
copyAccessor(dest, prefix, newKey, desc);
|
148 |
+
} else {
|
149 |
+
const { value } = desc;
|
150 |
+
if (typeof value === 'function') {
|
151 |
+
desc.value = uncurryThis(value);
|
152 |
+
}
|
153 |
+
|
154 |
+
const name = `${prefix}${newKey}`;
|
155 |
+
ReflectDefineProperty(dest, name, desc);
|
156 |
+
if (varargsMethods.includes(name)) {
|
157 |
+
ReflectDefineProperty(dest, `${name}Apply`, {
|
158 |
+
value: applyBind(value),
|
159 |
+
});
|
160 |
+
}
|
161 |
+
}
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
// Create copies of configurable value properties of the global object
|
166 |
+
[
|
167 |
+
'Proxy',
|
168 |
+
'globalThis',
|
169 |
+
].forEach((name) => {
|
170 |
+
// eslint-disable-next-line no-restricted-globals
|
171 |
+
primordials[name] = globalThis[name];
|
172 |
+
});
|
173 |
+
|
174 |
+
// Create copies of URI handling functions
|
175 |
+
[
|
176 |
+
decodeURI,
|
177 |
+
decodeURIComponent,
|
178 |
+
encodeURI,
|
179 |
+
encodeURIComponent,
|
180 |
+
].forEach((fn) => {
|
181 |
+
primordials[fn.name] = fn;
|
182 |
+
});
|
183 |
+
|
184 |
+
// Create copies of the namespace objects
|
185 |
+
[
|
186 |
+
'JSON',
|
187 |
+
'Math',
|
188 |
+
'Proxy',
|
189 |
+
'Reflect',
|
190 |
+
].forEach((name) => {
|
191 |
+
// eslint-disable-next-line no-restricted-globals
|
192 |
+
copyPropsRenamed(global[name], primordials, name);
|
193 |
+
});
|
194 |
+
|
195 |
+
// Create copies of intrinsic objects
|
196 |
+
[
|
197 |
+
'Array',
|
198 |
+
'ArrayBuffer',
|
199 |
+
'BigInt',
|
200 |
+
'BigInt64Array',
|
201 |
+
'BigUint64Array',
|
202 |
+
'Boolean',
|
203 |
+
'DataView',
|
204 |
+
'Date',
|
205 |
+
'Error',
|
206 |
+
'EvalError',
|
207 |
+
'Float32Array',
|
208 |
+
'Float64Array',
|
209 |
+
'Function',
|
210 |
+
'Int16Array',
|
211 |
+
'Int32Array',
|
212 |
+
'Int8Array',
|
213 |
+
'Map',
|
214 |
+
'Number',
|
215 |
+
'Object',
|
216 |
+
'RangeError',
|
217 |
+
'ReferenceError',
|
218 |
+
'RegExp',
|
219 |
+
'Set',
|
220 |
+
'String',
|
221 |
+
'Symbol',
|
222 |
+
'SyntaxError',
|
223 |
+
'TypeError',
|
224 |
+
'URIError',
|
225 |
+
'Uint16Array',
|
226 |
+
'Uint32Array',
|
227 |
+
'Uint8Array',
|
228 |
+
'Uint8ClampedArray',
|
229 |
+
'WeakMap',
|
230 |
+
'WeakSet',
|
231 |
+
].forEach((name) => {
|
232 |
+
// eslint-disable-next-line no-restricted-globals
|
233 |
+
const original = global[name];
|
234 |
+
primordials[name] = original;
|
235 |
+
copyPropsRenamed(original, primordials, name);
|
236 |
+
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
237 |
+
});
|
238 |
+
|
239 |
+
// Create copies of intrinsic objects that require a valid `this` to call
|
240 |
+
// static methods.
|
241 |
+
// Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all
|
242 |
+
[
|
243 |
+
'Promise',
|
244 |
+
].forEach((name) => {
|
245 |
+
// eslint-disable-next-line no-restricted-globals
|
246 |
+
const original = global[name];
|
247 |
+
primordials[name] = original;
|
248 |
+
copyPropsRenamedBound(original, primordials, name);
|
249 |
+
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
250 |
+
});
|
251 |
+
|
252 |
+
// Create copies of abstract intrinsic objects that are not directly exposed
|
253 |
+
// on the global object.
|
254 |
+
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
|
255 |
+
[
|
256 |
+
{ name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) },
|
257 |
+
{ name: 'ArrayIterator', original: {
|
258 |
+
prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
|
259 |
+
} },
|
260 |
+
{ name: 'StringIterator', original: {
|
261 |
+
prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
|
262 |
+
} },
|
263 |
+
].forEach(({ name, original }) => {
|
264 |
+
primordials[name] = original;
|
265 |
+
// The static %TypedArray% methods require a valid `this`, but can't be bound,
|
266 |
+
// as they need a subclass constructor as the receiver:
|
267 |
+
copyPrototype(original, primordials, name);
|
268 |
+
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
269 |
+
});
|
270 |
+
|
271 |
+
/* eslint-enable node-core/prefer-primordials */
|
272 |
+
|
273 |
+
const {
|
274 |
+
ArrayPrototypeForEach,
|
275 |
+
FunctionPrototypeCall,
|
276 |
+
Map,
|
277 |
+
ObjectFreeze,
|
278 |
+
ObjectSetPrototypeOf,
|
279 |
+
Set,
|
280 |
+
SymbolIterator,
|
281 |
+
WeakMap,
|
282 |
+
WeakSet,
|
283 |
+
} = primordials;
|
284 |
+
|
285 |
+
// Because these functions are used by `makeSafe`, which is exposed
|
286 |
+
// on the `primordials` object, it's important to use const references
|
287 |
+
// to the primordials that they use:
|
288 |
+
const createSafeIterator = (factory, next) => {
|
289 |
+
class SafeIterator {
|
290 |
+
constructor(iterable) {
|
291 |
+
this._iterator = factory(iterable);
|
292 |
+
}
|
293 |
+
next() {
|
294 |
+
return next(this._iterator);
|
295 |
+
}
|
296 |
+
[SymbolIterator]() {
|
297 |
+
return this;
|
298 |
+
}
|
299 |
+
}
|
300 |
+
ObjectSetPrototypeOf(SafeIterator.prototype, null);
|
301 |
+
ObjectFreeze(SafeIterator.prototype);
|
302 |
+
ObjectFreeze(SafeIterator);
|
303 |
+
return SafeIterator;
|
304 |
+
};
|
305 |
+
|
306 |
+
primordials.SafeArrayIterator = createSafeIterator(
|
307 |
+
primordials.ArrayPrototypeSymbolIterator,
|
308 |
+
primordials.ArrayIteratorPrototypeNext
|
309 |
+
);
|
310 |
+
primordials.SafeStringIterator = createSafeIterator(
|
311 |
+
primordials.StringPrototypeSymbolIterator,
|
312 |
+
primordials.StringIteratorPrototypeNext
|
313 |
+
);
|
314 |
+
|
315 |
+
const copyProps = (src, dest) => {
|
316 |
+
ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
|
317 |
+
if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
|
318 |
+
ReflectDefineProperty(
|
319 |
+
dest,
|
320 |
+
key,
|
321 |
+
ReflectGetOwnPropertyDescriptor(src, key));
|
322 |
+
}
|
323 |
+
});
|
324 |
+
};
|
325 |
+
|
326 |
+
const makeSafe = (unsafe, safe) => {
|
327 |
+
if (SymbolIterator in unsafe.prototype) {
|
328 |
+
const dummy = new unsafe();
|
329 |
+
let next; // We can reuse the same `next` method.
|
330 |
+
|
331 |
+
ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {
|
332 |
+
if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {
|
333 |
+
const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key);
|
334 |
+
if (
|
335 |
+
typeof desc.value === 'function' &&
|
336 |
+
desc.value.length === 0 &&
|
337 |
+
SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {})
|
338 |
+
) {
|
339 |
+
const createIterator = uncurryThis(desc.value);
|
340 |
+
next = next ?? uncurryThis(createIterator(dummy).next);
|
341 |
+
const SafeIterator = createSafeIterator(createIterator, next);
|
342 |
+
desc.value = function() {
|
343 |
+
return new SafeIterator(this);
|
344 |
+
};
|
345 |
+
}
|
346 |
+
ReflectDefineProperty(safe.prototype, key, desc);
|
347 |
+
}
|
348 |
+
});
|
349 |
+
} else {
|
350 |
+
copyProps(unsafe.prototype, safe.prototype);
|
351 |
+
}
|
352 |
+
copyProps(unsafe, safe);
|
353 |
+
|
354 |
+
ObjectSetPrototypeOf(safe.prototype, null);
|
355 |
+
ObjectFreeze(safe.prototype);
|
356 |
+
ObjectFreeze(safe);
|
357 |
+
return safe;
|
358 |
+
};
|
359 |
+
primordials.makeSafe = makeSafe;
|
360 |
+
|
361 |
+
// Subclass the constructors because we need to use their prototype
|
362 |
+
// methods later.
|
363 |
+
// Defining the `constructor` is necessary here to avoid the default
|
364 |
+
// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`.
|
365 |
+
primordials.SafeMap = makeSafe(
|
366 |
+
Map,
|
367 |
+
class SafeMap extends Map {
|
368 |
+
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
369 |
+
}
|
370 |
+
);
|
371 |
+
primordials.SafeWeakMap = makeSafe(
|
372 |
+
WeakMap,
|
373 |
+
class SafeWeakMap extends WeakMap {
|
374 |
+
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
375 |
+
}
|
376 |
+
);
|
377 |
+
primordials.SafeSet = makeSafe(
|
378 |
+
Set,
|
379 |
+
class SafeSet extends Set {
|
380 |
+
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
381 |
+
}
|
382 |
+
);
|
383 |
+
primordials.SafeWeakSet = makeSafe(
|
384 |
+
WeakSet,
|
385 |
+
class SafeWeakSet extends WeakSet {
|
386 |
+
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
387 |
+
}
|
388 |
+
);
|
389 |
+
|
390 |
+
ObjectSetPrototypeOf(primordials, null);
|
391 |
+
ObjectFreeze(primordials);
|
392 |
+
|
393 |
+
module.exports = primordials;
|