update
This commit is contained in:
201
package/node_modules/@pkgjs/parseargs/LICENSE
generated
vendored
Normal file
201
package/node_modules/@pkgjs/parseargs/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
25
package/node_modules/@pkgjs/parseargs/examples/is-default-value.js
generated
vendored
Normal file
25
package/node_modules/@pkgjs/parseargs/examples/is-default-value.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
// This example shows how to understand if a default value is used or not.
|
||||
|
||||
// 1. const { parseArgs } = require('node:util'); // from node
|
||||
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||
const { parseArgs } = require('..'); // in repo
|
||||
|
||||
const options = {
|
||||
file: { short: 'f', type: 'string', default: 'FOO' },
|
||||
};
|
||||
|
||||
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||
|
||||
const isFileDefault = !tokens.some((token) => token.kind === 'option' &&
|
||||
token.name === 'file'
|
||||
);
|
||||
|
||||
console.log(values);
|
||||
console.log(`Is the file option [${values.file}] the default value? ${isFileDefault}`);
|
||||
|
||||
// Try the following:
|
||||
// node is-default-value.js
|
||||
// node is-default-value.js -f FILE
|
||||
// node is-default-value.js --file FILE
|
35
package/node_modules/@pkgjs/parseargs/examples/limit-long-syntax.js
generated
vendored
Normal file
35
package/node_modules/@pkgjs/parseargs/examples/limit-long-syntax.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
// This is an example of using tokens to add a custom behaviour.
|
||||
//
|
||||
// Require the use of `=` for long options and values by blocking
|
||||
// the use of space separated values.
|
||||
// So allow `--foo=bar`, and not allow `--foo bar`.
|
||||
//
|
||||
// Note: this is not a common behaviour, most CLIs allow both forms.
|
||||
|
||||
// 1. const { parseArgs } = require('node:util'); // from node
|
||||
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||
const { parseArgs } = require('..'); // in repo
|
||||
|
||||
const options = {
|
||||
file: { short: 'f', type: 'string' },
|
||||
log: { type: 'string' },
|
||||
};
|
||||
|
||||
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||
|
||||
const badToken = tokens.find((token) => token.kind === 'option' &&
|
||||
token.value != null &&
|
||||
token.rawName.startsWith('--') &&
|
||||
!token.inlineValue
|
||||
);
|
||||
if (badToken) {
|
||||
throw new Error(`Option value for '${badToken.rawName}' must be inline, like '${badToken.rawName}=VALUE'`);
|
||||
}
|
||||
|
||||
console.log(values);
|
||||
|
||||
// Try the following:
|
||||
// node limit-long-syntax.js -f FILE --log=LOG
|
||||
// node limit-long-syntax.js --file FILE
|
43
package/node_modules/@pkgjs/parseargs/examples/negate.js
generated
vendored
Normal file
43
package/node_modules/@pkgjs/parseargs/examples/negate.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
// This example is used in the documentation.
|
||||
|
||||
// How might I add my own support for --no-foo?
|
||||
|
||||
// 1. const { parseArgs } = require('node:util'); // from node
|
||||
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||
const { parseArgs } = require('..'); // in repo
|
||||
|
||||
const options = {
|
||||
'color': { type: 'boolean' },
|
||||
'no-color': { type: 'boolean' },
|
||||
'logfile': { type: 'string' },
|
||||
'no-logfile': { type: 'boolean' },
|
||||
};
|
||||
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||
|
||||
// Reprocess the option tokens and overwrite the returned values.
|
||||
tokens
|
||||
.filter((token) => token.kind === 'option')
|
||||
.forEach((token) => {
|
||||
if (token.name.startsWith('no-')) {
|
||||
// Store foo:false for --no-foo
|
||||
const positiveName = token.name.slice(3);
|
||||
values[positiveName] = false;
|
||||
delete values[token.name];
|
||||
} else {
|
||||
// Resave value so last one wins if both --foo and --no-foo.
|
||||
values[token.name] = token.value ?? true;
|
||||
}
|
||||
});
|
||||
|
||||
const color = values.color;
|
||||
const logfile = values.logfile ?? 'default.log';
|
||||
|
||||
console.log({ logfile, color });
|
||||
|
||||
// Try the following:
|
||||
// node negate.js
|
||||
// node negate.js --no-logfile --no-color
|
||||
// negate.js --logfile=test.log --color
|
||||
// node negate.js --no-logfile --logfile=test.log --color --no-color
|
31
package/node_modules/@pkgjs/parseargs/examples/no-repeated-options.js
generated
vendored
Normal file
31
package/node_modules/@pkgjs/parseargs/examples/no-repeated-options.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
// This is an example of using tokens to add a custom behaviour.
|
||||
//
|
||||
// Throw an error if an option is used more than once.
|
||||
|
||||
// 1. const { parseArgs } = require('node:util'); // from node
|
||||
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||
const { parseArgs } = require('..'); // in repo
|
||||
|
||||
const options = {
|
||||
ding: { type: 'boolean', short: 'd' },
|
||||
beep: { type: 'boolean', short: 'b' }
|
||||
};
|
||||
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||
|
||||
const seenBefore = new Set();
|
||||
tokens.forEach((token) => {
|
||||
if (token.kind !== 'option') return;
|
||||
if (seenBefore.has(token.name)) {
|
||||
throw new Error(`option '${token.name}' used multiple times`);
|
||||
}
|
||||
seenBefore.add(token.name);
|
||||
});
|
||||
|
||||
console.log(values);
|
||||
|
||||
// Try the following:
|
||||
// node no-repeated-options --ding --beep
|
||||
// node no-repeated-options --beep -b
|
||||
// node no-repeated-options -ddd
|
41
package/node_modules/@pkgjs/parseargs/examples/ordered-options.mjs
generated
vendored
Normal file
41
package/node_modules/@pkgjs/parseargs/examples/ordered-options.mjs
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// This is an example of using tokens to add a custom behaviour.
|
||||
//
|
||||
// This adds a option order check so that --some-unstable-option
|
||||
// may only be used after --enable-experimental-options
|
||||
//
|
||||
// Note: this is not a common behaviour, the order of different options
|
||||
// does not usually matter.
|
||||
|
||||
import { parseArgs } from '../index.js';
|
||||
|
||||
function findTokenIndex(tokens, target) {
|
||||
return tokens.findIndex((token) => token.kind === 'option' &&
|
||||
token.name === target
|
||||
);
|
||||
}
|
||||
|
||||
const experimentalName = 'enable-experimental-options';
|
||||
const unstableName = 'some-unstable-option';
|
||||
|
||||
const options = {
|
||||
[experimentalName]: { type: 'boolean' },
|
||||
[unstableName]: { type: 'boolean' },
|
||||
};
|
||||
|
||||
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||
|
||||
const experimentalIndex = findTokenIndex(tokens, experimentalName);
|
||||
const unstableIndex = findTokenIndex(tokens, unstableName);
|
||||
if (unstableIndex !== -1 &&
|
||||
((experimentalIndex === -1) || (unstableIndex < experimentalIndex))) {
|
||||
throw new Error(`'--${experimentalName}' must be specified before '--${unstableName}'`);
|
||||
}
|
||||
|
||||
console.log(values);
|
||||
|
||||
/* eslint-disable max-len */
|
||||
// Try the following:
|
||||
// node ordered-options.mjs
|
||||
// node ordered-options.mjs --some-unstable-option
|
||||
// node ordered-options.mjs --some-unstable-option --enable-experimental-options
|
||||
// node ordered-options.mjs --enable-experimental-options --some-unstable-option
|
26
package/node_modules/@pkgjs/parseargs/examples/simple-hard-coded.js
generated
vendored
Normal file
26
package/node_modules/@pkgjs/parseargs/examples/simple-hard-coded.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
// This example is used in the documentation.
|
||||
|
||||
// 1. const { parseArgs } = require('node:util'); // from node
|
||||
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||
const { parseArgs } = require('..'); // in repo
|
||||
|
||||
const args = ['-f', '--bar', 'b'];
|
||||
const options = {
|
||||
foo: {
|
||||
type: 'boolean',
|
||||
short: 'f'
|
||||
},
|
||||
bar: {
|
||||
type: 'string'
|
||||
}
|
||||
};
|
||||
const {
|
||||
values,
|
||||
positionals
|
||||
} = parseArgs({ args, options });
|
||||
console.log(values, positionals);
|
||||
|
||||
// Try the following:
|
||||
// node simple-hard-coded.js
|
396
package/node_modules/@pkgjs/parseargs/index.js
generated
vendored
Normal file
396
package/node_modules/@pkgjs/parseargs/index.js
generated
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
ArrayPrototypeForEach,
|
||||
ArrayPrototypeIncludes,
|
||||
ArrayPrototypeMap,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypePushApply,
|
||||
ArrayPrototypeShift,
|
||||
ArrayPrototypeSlice,
|
||||
ArrayPrototypeUnshiftApply,
|
||||
ObjectEntries,
|
||||
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
||||
StringPrototypeCharAt,
|
||||
StringPrototypeIndexOf,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
} = require('./internal/primordials');
|
||||
|
||||
const {
|
||||
validateArray,
|
||||
validateBoolean,
|
||||
validateBooleanArray,
|
||||
validateObject,
|
||||
validateString,
|
||||
validateStringArray,
|
||||
validateUnion,
|
||||
} = require('./internal/validators');
|
||||
|
||||
const {
|
||||
kEmptyObject,
|
||||
} = require('./internal/util');
|
||||
|
||||
const {
|
||||
findLongOptionForShort,
|
||||
isLoneLongOption,
|
||||
isLoneShortOption,
|
||||
isLongOptionAndValue,
|
||||
isOptionValue,
|
||||
isOptionLikeValue,
|
||||
isShortOptionAndValue,
|
||||
isShortOptionGroup,
|
||||
useDefaultValueOption,
|
||||
objectGetOwn,
|
||||
optionsGetOwn,
|
||||
} = require('./utils');
|
||||
|
||||
const {
|
||||
codes: {
|
||||
ERR_INVALID_ARG_VALUE,
|
||||
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
|
||||
ERR_PARSE_ARGS_UNKNOWN_OPTION,
|
||||
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
|
||||
},
|
||||
} = require('./internal/errors');
|
||||
|
||||
function getMainArgs() {
|
||||
// Work out where to slice process.argv for user supplied arguments.
|
||||
|
||||
// Check node options for scenarios where user CLI args follow executable.
|
||||
const execArgv = process.execArgv;
|
||||
if (ArrayPrototypeIncludes(execArgv, '-e') ||
|
||||
ArrayPrototypeIncludes(execArgv, '--eval') ||
|
||||
ArrayPrototypeIncludes(execArgv, '-p') ||
|
||||
ArrayPrototypeIncludes(execArgv, '--print')) {
|
||||
return ArrayPrototypeSlice(process.argv, 1);
|
||||
}
|
||||
|
||||
// Normally first two arguments are executable and script, then CLI arguments
|
||||
return ArrayPrototypeSlice(process.argv, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* In strict mode, throw for possible usage errors like --foo --bar
|
||||
*
|
||||
* @param {object} token - from tokens as available from parseArgs
|
||||
*/
|
||||
function checkOptionLikeValue(token) {
|
||||
if (!token.inlineValue && isOptionLikeValue(token.value)) {
|
||||
// Only show short example if user used short option.
|
||||
const example = StringPrototypeStartsWith(token.rawName, '--') ?
|
||||
`'${token.rawName}=-XYZ'` :
|
||||
`'--${token.name}=-XYZ' or '${token.rawName}-XYZ'`;
|
||||
const errorMessage = `Option '${token.rawName}' argument is ambiguous.
|
||||
Did you forget to specify the option argument for '${token.rawName}'?
|
||||
To specify an option argument starting with a dash use ${example}.`;
|
||||
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In strict mode, throw for usage errors.
|
||||
*
|
||||
* @param {object} config - from config passed to parseArgs
|
||||
* @param {object} token - from tokens as available from parseArgs
|
||||
*/
|
||||
function checkOptionUsage(config, token) {
|
||||
if (!ObjectHasOwn(config.options, token.name)) {
|
||||
throw new ERR_PARSE_ARGS_UNKNOWN_OPTION(
|
||||
token.rawName, config.allowPositionals);
|
||||
}
|
||||
|
||||
const short = optionsGetOwn(config.options, token.name, 'short');
|
||||
const shortAndLong = `${short ? `-${short}, ` : ''}--${token.name}`;
|
||||
const type = optionsGetOwn(config.options, token.name, 'type');
|
||||
if (type === 'string' && typeof token.value !== 'string') {
|
||||
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong} <value>' argument missing`);
|
||||
}
|
||||
// (Idiomatic test for undefined||null, expecting undefined.)
|
||||
if (type === 'boolean' && token.value != null) {
|
||||
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong}' does not take an argument`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store the option value in `values`.
|
||||
*
|
||||
* @param {string} longOption - long option name e.g. 'foo'
|
||||
* @param {string|undefined} optionValue - value from user args
|
||||
* @param {object} options - option configs, from parseArgs({ options })
|
||||
* @param {object} values - option values returned in `values` by parseArgs
|
||||
*/
|
||||
function storeOption(longOption, optionValue, options, values) {
|
||||
if (longOption === '__proto__') {
|
||||
return; // No. Just no.
|
||||
}
|
||||
|
||||
// We store based on the option value rather than option type,
|
||||
// preserving the users intent for author to deal with.
|
||||
const newValue = optionValue ?? true;
|
||||
if (optionsGetOwn(options, longOption, 'multiple')) {
|
||||
// Always store value in array, including for boolean.
|
||||
// values[longOption] starts out not present,
|
||||
// first value is added as new array [newValue],
|
||||
// subsequent values are pushed to existing array.
|
||||
// (note: values has null prototype, so simpler usage)
|
||||
if (values[longOption]) {
|
||||
ArrayPrototypePush(values[longOption], newValue);
|
||||
} else {
|
||||
values[longOption] = [newValue];
|
||||
}
|
||||
} else {
|
||||
values[longOption] = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the default option value in `values`.
|
||||
*
|
||||
* @param {string} longOption - long option name e.g. 'foo'
|
||||
* @param {string
|
||||
* | boolean
|
||||
* | string[]
|
||||
* | boolean[]} optionValue - default value from option config
|
||||
* @param {object} values - option values returned in `values` by parseArgs
|
||||
*/
|
||||
function storeDefaultOption(longOption, optionValue, values) {
|
||||
if (longOption === '__proto__') {
|
||||
return; // No. Just no.
|
||||
}
|
||||
|
||||
values[longOption] = optionValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process args and turn into identified tokens:
|
||||
* - option (along with value, if any)
|
||||
* - positional
|
||||
* - option-terminator
|
||||
*
|
||||
* @param {string[]} args - from parseArgs({ args }) or mainArgs
|
||||
* @param {object} options - option configs, from parseArgs({ options })
|
||||
*/
|
||||
function argsToTokens(args, options) {
|
||||
const tokens = [];
|
||||
let index = -1;
|
||||
let groupCount = 0;
|
||||
|
||||
const remainingArgs = ArrayPrototypeSlice(args);
|
||||
while (remainingArgs.length > 0) {
|
||||
const arg = ArrayPrototypeShift(remainingArgs);
|
||||
const nextArg = remainingArgs[0];
|
||||
if (groupCount > 0)
|
||||
groupCount--;
|
||||
else
|
||||
index++;
|
||||
|
||||
// Check if `arg` is an options terminator.
|
||||
// Guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
||||
if (arg === '--') {
|
||||
// Everything after a bare '--' is considered a positional argument.
|
||||
ArrayPrototypePush(tokens, { kind: 'option-terminator', index });
|
||||
ArrayPrototypePushApply(
|
||||
tokens, ArrayPrototypeMap(remainingArgs, (arg) => {
|
||||
return { kind: 'positional', index: ++index, value: arg };
|
||||
})
|
||||
);
|
||||
break; // Finished processing args, leave while loop.
|
||||
}
|
||||
|
||||
if (isLoneShortOption(arg)) {
|
||||
// e.g. '-f'
|
||||
const shortOption = StringPrototypeCharAt(arg, 1);
|
||||
const longOption = findLongOptionForShort(shortOption, options);
|
||||
let value;
|
||||
let inlineValue;
|
||||
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
||||
isOptionValue(nextArg)) {
|
||||
// e.g. '-f', 'bar'
|
||||
value = ArrayPrototypeShift(remainingArgs);
|
||||
inlineValue = false;
|
||||
}
|
||||
ArrayPrototypePush(
|
||||
tokens,
|
||||
{ kind: 'option', name: longOption, rawName: arg,
|
||||
index, value, inlineValue });
|
||||
if (value != null) ++index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isShortOptionGroup(arg, options)) {
|
||||
// Expand -fXzy to -f -X -z -y
|
||||
const expanded = [];
|
||||
for (let index = 1; index < arg.length; index++) {
|
||||
const shortOption = StringPrototypeCharAt(arg, index);
|
||||
const longOption = findLongOptionForShort(shortOption, options);
|
||||
if (optionsGetOwn(options, longOption, 'type') !== 'string' ||
|
||||
index === arg.length - 1) {
|
||||
// Boolean option, or last short in group. Well formed.
|
||||
ArrayPrototypePush(expanded, `-${shortOption}`);
|
||||
} else {
|
||||
// String option in middle. Yuck.
|
||||
// Expand -abfFILE to -a -b -fFILE
|
||||
ArrayPrototypePush(expanded, `-${StringPrototypeSlice(arg, index)}`);
|
||||
break; // finished short group
|
||||
}
|
||||
}
|
||||
ArrayPrototypeUnshiftApply(remainingArgs, expanded);
|
||||
groupCount = expanded.length;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isShortOptionAndValue(arg, options)) {
|
||||
// e.g. -fFILE
|
||||
const shortOption = StringPrototypeCharAt(arg, 1);
|
||||
const longOption = findLongOptionForShort(shortOption, options);
|
||||
const value = StringPrototypeSlice(arg, 2);
|
||||
ArrayPrototypePush(
|
||||
tokens,
|
||||
{ kind: 'option', name: longOption, rawName: `-${shortOption}`,
|
||||
index, value, inlineValue: true });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isLoneLongOption(arg)) {
|
||||
// e.g. '--foo'
|
||||
const longOption = StringPrototypeSlice(arg, 2);
|
||||
let value;
|
||||
let inlineValue;
|
||||
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
||||
isOptionValue(nextArg)) {
|
||||
// e.g. '--foo', 'bar'
|
||||
value = ArrayPrototypeShift(remainingArgs);
|
||||
inlineValue = false;
|
||||
}
|
||||
ArrayPrototypePush(
|
||||
tokens,
|
||||
{ kind: 'option', name: longOption, rawName: arg,
|
||||
index, value, inlineValue });
|
||||
if (value != null) ++index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isLongOptionAndValue(arg)) {
|
||||
// e.g. --foo=bar
|
||||
const equalIndex = StringPrototypeIndexOf(arg, '=');
|
||||
const longOption = StringPrototypeSlice(arg, 2, equalIndex);
|
||||
const value = StringPrototypeSlice(arg, equalIndex + 1);
|
||||
ArrayPrototypePush(
|
||||
tokens,
|
||||
{ kind: 'option', name: longOption, rawName: `--${longOption}`,
|
||||
index, value, inlineValue: true });
|
||||
continue;
|
||||
}
|
||||
|
||||
ArrayPrototypePush(tokens, { kind: 'positional', index, value: arg });
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
const parseArgs = (config = kEmptyObject) => {
|
||||
const args = objectGetOwn(config, 'args') ?? getMainArgs();
|
||||
const strict = objectGetOwn(config, 'strict') ?? true;
|
||||
const allowPositionals = objectGetOwn(config, 'allowPositionals') ?? !strict;
|
||||
const returnTokens = objectGetOwn(config, 'tokens') ?? false;
|
||||
const options = objectGetOwn(config, 'options') ?? { __proto__: null };
|
||||
// Bundle these up for passing to strict-mode checks.
|
||||
const parseConfig = { args, strict, options, allowPositionals };
|
||||
|
||||
// Validate input configuration.
|
||||
validateArray(args, 'args');
|
||||
validateBoolean(strict, 'strict');
|
||||
validateBoolean(allowPositionals, 'allowPositionals');
|
||||
validateBoolean(returnTokens, 'tokens');
|
||||
validateObject(options, 'options');
|
||||
ArrayPrototypeForEach(
|
||||
ObjectEntries(options),
|
||||
({ 0: longOption, 1: optionConfig }) => {
|
||||
validateObject(optionConfig, `options.${longOption}`);
|
||||
|
||||
// type is required
|
||||
const optionType = objectGetOwn(optionConfig, 'type');
|
||||
validateUnion(optionType, `options.${longOption}.type`, ['string', 'boolean']);
|
||||
|
||||
if (ObjectHasOwn(optionConfig, 'short')) {
|
||||
const shortOption = optionConfig.short;
|
||||
validateString(shortOption, `options.${longOption}.short`);
|
||||
if (shortOption.length !== 1) {
|
||||
throw new ERR_INVALID_ARG_VALUE(
|
||||
`options.${longOption}.short`,
|
||||
shortOption,
|
||||
'must be a single character'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const multipleOption = objectGetOwn(optionConfig, 'multiple');
|
||||
if (ObjectHasOwn(optionConfig, 'multiple')) {
|
||||
validateBoolean(multipleOption, `options.${longOption}.multiple`);
|
||||
}
|
||||
|
||||
const defaultValue = objectGetOwn(optionConfig, 'default');
|
||||
if (defaultValue !== undefined) {
|
||||
let validator;
|
||||
switch (optionType) {
|
||||
case 'string':
|
||||
validator = multipleOption ? validateStringArray : validateString;
|
||||
break;
|
||||
|
||||
case 'boolean':
|
||||
validator = multipleOption ? validateBooleanArray : validateBoolean;
|
||||
break;
|
||||
}
|
||||
validator(defaultValue, `options.${longOption}.default`);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Phase 1: identify tokens
|
||||
const tokens = argsToTokens(args, options);
|
||||
|
||||
// Phase 2: process tokens into parsed option values and positionals
|
||||
const result = {
|
||||
values: { __proto__: null },
|
||||
positionals: [],
|
||||
};
|
||||
if (returnTokens) {
|
||||
result.tokens = tokens;
|
||||
}
|
||||
ArrayPrototypeForEach(tokens, (token) => {
|
||||
if (token.kind === 'option') {
|
||||
if (strict) {
|
||||
checkOptionUsage(parseConfig, token);
|
||||
checkOptionLikeValue(token);
|
||||
}
|
||||
storeOption(token.name, token.value, options, result.values);
|
||||
} else if (token.kind === 'positional') {
|
||||
if (!allowPositionals) {
|
||||
throw new ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL(token.value);
|
||||
}
|
||||
ArrayPrototypePush(result.positionals, token.value);
|
||||
}
|
||||
});
|
||||
|
||||
// Phase 3: fill in default values for missing args
|
||||
ArrayPrototypeForEach(ObjectEntries(options), ({ 0: longOption,
|
||||
1: optionConfig }) => {
|
||||
const mustSetDefault = useDefaultValueOption(longOption,
|
||||
optionConfig,
|
||||
result.values);
|
||||
if (mustSetDefault) {
|
||||
storeDefaultOption(longOption,
|
||||
objectGetOwn(optionConfig, 'default'),
|
||||
result.values);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
parseArgs,
|
||||
};
|
47
package/node_modules/@pkgjs/parseargs/internal/errors.js
generated
vendored
Normal file
47
package/node_modules/@pkgjs/parseargs/internal/errors.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
class ERR_INVALID_ARG_TYPE extends TypeError {
|
||||
constructor(name, expected, actual) {
|
||||
super(`${name} must be ${expected} got ${actual}`);
|
||||
this.code = 'ERR_INVALID_ARG_TYPE';
|
||||
}
|
||||
}
|
||||
|
||||
class ERR_INVALID_ARG_VALUE extends TypeError {
|
||||
constructor(arg1, arg2, expected) {
|
||||
super(`The property ${arg1} ${expected}. Received '${arg2}'`);
|
||||
this.code = 'ERR_INVALID_ARG_VALUE';
|
||||
}
|
||||
}
|
||||
|
||||
class ERR_PARSE_ARGS_INVALID_OPTION_VALUE extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.code = 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE';
|
||||
}
|
||||
}
|
||||
|
||||
class ERR_PARSE_ARGS_UNKNOWN_OPTION extends Error {
|
||||
constructor(option, allowPositionals) {
|
||||
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)}` : '';
|
||||
super(`Unknown option '${option}'${suggestDashDash}`);
|
||||
this.code = 'ERR_PARSE_ARGS_UNKNOWN_OPTION';
|
||||
}
|
||||
}
|
||||
|
||||
class ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL extends Error {
|
||||
constructor(positional) {
|
||||
super(`Unexpected argument '${positional}'. This command does not take positional arguments`);
|
||||
this.code = 'ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
codes: {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_ARG_VALUE,
|
||||
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
|
||||
ERR_PARSE_ARGS_UNKNOWN_OPTION,
|
||||
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
|
||||
}
|
||||
};
|
393
package/node_modules/@pkgjs/parseargs/internal/primordials.js
generated
vendored
Normal file
393
package/node_modules/@pkgjs/parseargs/internal/primordials.js
generated
vendored
Normal file
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
This file is copied from https://github.com/nodejs/node/blob/v14.19.3/lib/internal/per_context/primordials.js
|
||||
under the following license:
|
||||
|
||||
Copyright Node.js contributors. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/* eslint-disable node-core/prefer-primordials */
|
||||
|
||||
// This file subclasses and stores the JS builtins that come from the VM
|
||||
// so that Node.js's builtin modules do not need to later look these up from
|
||||
// the global proxy, which can be mutated by users.
|
||||
|
||||
// Use of primordials have sometimes a dramatic impact on performance, please
|
||||
// benchmark all changes made in performance-sensitive areas of the codebase.
|
||||
// See: https://github.com/nodejs/node/pull/38248
|
||||
|
||||
const primordials = {};
|
||||
|
||||
const {
|
||||
defineProperty: ReflectDefineProperty,
|
||||
getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
|
||||
ownKeys: ReflectOwnKeys,
|
||||
} = Reflect;
|
||||
|
||||
// `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.
|
||||
// It is using `bind.bind(call)` to avoid using `Function.prototype.bind`
|
||||
// and `Function.prototype.call` after it may have been mutated by users.
|
||||
const { apply, bind, call } = Function.prototype;
|
||||
const uncurryThis = bind.bind(call);
|
||||
primordials.uncurryThis = uncurryThis;
|
||||
|
||||
// `applyBind` is equivalent to `func => Function.prototype.apply.bind(func)`.
|
||||
// It is using `bind.bind(apply)` to avoid using `Function.prototype.bind`
|
||||
// and `Function.prototype.apply` after it may have been mutated by users.
|
||||
const applyBind = bind.bind(apply);
|
||||
primordials.applyBind = applyBind;
|
||||
|
||||
// Methods that accept a variable number of arguments, and thus it's useful to
|
||||
// also create `${prefix}${key}Apply`, which uses `Function.prototype.apply`,
|
||||
// instead of `Function.prototype.call`, and thus doesn't require iterator
|
||||
// destructuring.
|
||||
const varargsMethods = [
|
||||
// 'ArrayPrototypeConcat' is omitted, because it performs the spread
|
||||
// on its own for arrays and array-likes with a truthy
|
||||
// @@isConcatSpreadable symbol property.
|
||||
'ArrayOf',
|
||||
'ArrayPrototypePush',
|
||||
'ArrayPrototypeUnshift',
|
||||
// 'FunctionPrototypeCall' is omitted, since there's 'ReflectApply'
|
||||
// and 'FunctionPrototypeApply'.
|
||||
'MathHypot',
|
||||
'MathMax',
|
||||
'MathMin',
|
||||
'StringPrototypeConcat',
|
||||
'TypedArrayOf',
|
||||
];
|
||||
|
||||
function getNewKey(key) {
|
||||
return typeof key === 'symbol' ?
|
||||
`Symbol${key.description[7].toUpperCase()}${key.description.slice(8)}` :
|
||||
`${key[0].toUpperCase()}${key.slice(1)}`;
|
||||
}
|
||||
|
||||
function copyAccessor(dest, prefix, key, { enumerable, get, set }) {
|
||||
ReflectDefineProperty(dest, `${prefix}Get${key}`, {
|
||||
value: uncurryThis(get),
|
||||
enumerable
|
||||
});
|
||||
if (set !== undefined) {
|
||||
ReflectDefineProperty(dest, `${prefix}Set${key}`, {
|
||||
value: uncurryThis(set),
|
||||
enumerable
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function copyPropsRenamed(src, dest, prefix) {
|
||||
for (const key of ReflectOwnKeys(src)) {
|
||||
const newKey = getNewKey(key);
|
||||
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
||||
if ('get' in desc) {
|
||||
copyAccessor(dest, prefix, newKey, desc);
|
||||
} else {
|
||||
const name = `${prefix}${newKey}`;
|
||||
ReflectDefineProperty(dest, name, desc);
|
||||
if (varargsMethods.includes(name)) {
|
||||
ReflectDefineProperty(dest, `${name}Apply`, {
|
||||
// `src` is bound as the `this` so that the static `this` points
|
||||
// to the object it was defined on,
|
||||
// e.g.: `ArrayOfApply` gets a `this` of `Array`:
|
||||
value: applyBind(desc.value, src),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function copyPropsRenamedBound(src, dest, prefix) {
|
||||
for (const key of ReflectOwnKeys(src)) {
|
||||
const newKey = getNewKey(key);
|
||||
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
||||
if ('get' in desc) {
|
||||
copyAccessor(dest, prefix, newKey, desc);
|
||||
} else {
|
||||
const { value } = desc;
|
||||
if (typeof value === 'function') {
|
||||
desc.value = value.bind(src);
|
||||
}
|
||||
|
||||
const name = `${prefix}${newKey}`;
|
||||
ReflectDefineProperty(dest, name, desc);
|
||||
if (varargsMethods.includes(name)) {
|
||||
ReflectDefineProperty(dest, `${name}Apply`, {
|
||||
value: applyBind(value, src),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function copyPrototype(src, dest, prefix) {
|
||||
for (const key of ReflectOwnKeys(src)) {
|
||||
const newKey = getNewKey(key);
|
||||
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
||||
if ('get' in desc) {
|
||||
copyAccessor(dest, prefix, newKey, desc);
|
||||
} else {
|
||||
const { value } = desc;
|
||||
if (typeof value === 'function') {
|
||||
desc.value = uncurryThis(value);
|
||||
}
|
||||
|
||||
const name = `${prefix}${newKey}`;
|
||||
ReflectDefineProperty(dest, name, desc);
|
||||
if (varargsMethods.includes(name)) {
|
||||
ReflectDefineProperty(dest, `${name}Apply`, {
|
||||
value: applyBind(value),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create copies of configurable value properties of the global object
|
||||
[
|
||||
'Proxy',
|
||||
'globalThis',
|
||||
].forEach((name) => {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
primordials[name] = globalThis[name];
|
||||
});
|
||||
|
||||
// Create copies of URI handling functions
|
||||
[
|
||||
decodeURI,
|
||||
decodeURIComponent,
|
||||
encodeURI,
|
||||
encodeURIComponent,
|
||||
].forEach((fn) => {
|
||||
primordials[fn.name] = fn;
|
||||
});
|
||||
|
||||
// Create copies of the namespace objects
|
||||
[
|
||||
'JSON',
|
||||
'Math',
|
||||
'Proxy',
|
||||
'Reflect',
|
||||
].forEach((name) => {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
copyPropsRenamed(global[name], primordials, name);
|
||||
});
|
||||
|
||||
// Create copies of intrinsic objects
|
||||
[
|
||||
'Array',
|
||||
'ArrayBuffer',
|
||||
'BigInt',
|
||||
'BigInt64Array',
|
||||
'BigUint64Array',
|
||||
'Boolean',
|
||||
'DataView',
|
||||
'Date',
|
||||
'Error',
|
||||
'EvalError',
|
||||
'Float32Array',
|
||||
'Float64Array',
|
||||
'Function',
|
||||
'Int16Array',
|
||||
'Int32Array',
|
||||
'Int8Array',
|
||||
'Map',
|
||||
'Number',
|
||||
'Object',
|
||||
'RangeError',
|
||||
'ReferenceError',
|
||||
'RegExp',
|
||||
'Set',
|
||||
'String',
|
||||
'Symbol',
|
||||
'SyntaxError',
|
||||
'TypeError',
|
||||
'URIError',
|
||||
'Uint16Array',
|
||||
'Uint32Array',
|
||||
'Uint8Array',
|
||||
'Uint8ClampedArray',
|
||||
'WeakMap',
|
||||
'WeakSet',
|
||||
].forEach((name) => {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
const original = global[name];
|
||||
primordials[name] = original;
|
||||
copyPropsRenamed(original, primordials, name);
|
||||
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
||||
});
|
||||
|
||||
// Create copies of intrinsic objects that require a valid `this` to call
|
||||
// static methods.
|
||||
// Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all
|
||||
[
|
||||
'Promise',
|
||||
].forEach((name) => {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
const original = global[name];
|
||||
primordials[name] = original;
|
||||
copyPropsRenamedBound(original, primordials, name);
|
||||
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
||||
});
|
||||
|
||||
// Create copies of abstract intrinsic objects that are not directly exposed
|
||||
// on the global object.
|
||||
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
|
||||
[
|
||||
{ name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) },
|
||||
{ name: 'ArrayIterator', original: {
|
||||
prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
|
||||
} },
|
||||
{ name: 'StringIterator', original: {
|
||||
prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
|
||||
} },
|
||||
].forEach(({ name, original }) => {
|
||||
primordials[name] = original;
|
||||
// The static %TypedArray% methods require a valid `this`, but can't be bound,
|
||||
// as they need a subclass constructor as the receiver:
|
||||
copyPrototype(original, primordials, name);
|
||||
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
||||
});
|
||||
|
||||
/* eslint-enable node-core/prefer-primordials */
|
||||
|
||||
const {
|
||||
ArrayPrototypeForEach,
|
||||
FunctionPrototypeCall,
|
||||
Map,
|
||||
ObjectFreeze,
|
||||
ObjectSetPrototypeOf,
|
||||
Set,
|
||||
SymbolIterator,
|
||||
WeakMap,
|
||||
WeakSet,
|
||||
} = primordials;
|
||||
|
||||
// Because these functions are used by `makeSafe`, which is exposed
|
||||
// on the `primordials` object, it's important to use const references
|
||||
// to the primordials that they use:
|
||||
const createSafeIterator = (factory, next) => {
|
||||
class SafeIterator {
|
||||
constructor(iterable) {
|
||||
this._iterator = factory(iterable);
|
||||
}
|
||||
next() {
|
||||
return next(this._iterator);
|
||||
}
|
||||
[SymbolIterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
ObjectSetPrototypeOf(SafeIterator.prototype, null);
|
||||
ObjectFreeze(SafeIterator.prototype);
|
||||
ObjectFreeze(SafeIterator);
|
||||
return SafeIterator;
|
||||
};
|
||||
|
||||
primordials.SafeArrayIterator = createSafeIterator(
|
||||
primordials.ArrayPrototypeSymbolIterator,
|
||||
primordials.ArrayIteratorPrototypeNext
|
||||
);
|
||||
primordials.SafeStringIterator = createSafeIterator(
|
||||
primordials.StringPrototypeSymbolIterator,
|
||||
primordials.StringIteratorPrototypeNext
|
||||
);
|
||||
|
||||
const copyProps = (src, dest) => {
|
||||
ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
|
||||
if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
|
||||
ReflectDefineProperty(
|
||||
dest,
|
||||
key,
|
||||
ReflectGetOwnPropertyDescriptor(src, key));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const makeSafe = (unsafe, safe) => {
|
||||
if (SymbolIterator in unsafe.prototype) {
|
||||
const dummy = new unsafe();
|
||||
let next; // We can reuse the same `next` method.
|
||||
|
||||
ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {
|
||||
if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {
|
||||
const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key);
|
||||
if (
|
||||
typeof desc.value === 'function' &&
|
||||
desc.value.length === 0 &&
|
||||
SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {})
|
||||
) {
|
||||
const createIterator = uncurryThis(desc.value);
|
||||
next = next ?? uncurryThis(createIterator(dummy).next);
|
||||
const SafeIterator = createSafeIterator(createIterator, next);
|
||||
desc.value = function() {
|
||||
return new SafeIterator(this);
|
||||
};
|
||||
}
|
||||
ReflectDefineProperty(safe.prototype, key, desc);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
copyProps(unsafe.prototype, safe.prototype);
|
||||
}
|
||||
copyProps(unsafe, safe);
|
||||
|
||||
ObjectSetPrototypeOf(safe.prototype, null);
|
||||
ObjectFreeze(safe.prototype);
|
||||
ObjectFreeze(safe);
|
||||
return safe;
|
||||
};
|
||||
primordials.makeSafe = makeSafe;
|
||||
|
||||
// Subclass the constructors because we need to use their prototype
|
||||
// methods later.
|
||||
// Defining the `constructor` is necessary here to avoid the default
|
||||
// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`.
|
||||
primordials.SafeMap = makeSafe(
|
||||
Map,
|
||||
class SafeMap extends Map {
|
||||
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||
}
|
||||
);
|
||||
primordials.SafeWeakMap = makeSafe(
|
||||
WeakMap,
|
||||
class SafeWeakMap extends WeakMap {
|
||||
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||
}
|
||||
);
|
||||
primordials.SafeSet = makeSafe(
|
||||
Set,
|
||||
class SafeSet extends Set {
|
||||
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||
}
|
||||
);
|
||||
primordials.SafeWeakSet = makeSafe(
|
||||
WeakSet,
|
||||
class SafeWeakSet extends WeakSet {
|
||||
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||
}
|
||||
);
|
||||
|
||||
ObjectSetPrototypeOf(primordials, null);
|
||||
ObjectFreeze(primordials);
|
||||
|
||||
module.exports = primordials;
|
14
package/node_modules/@pkgjs/parseargs/internal/util.js
generated
vendored
Normal file
14
package/node_modules/@pkgjs/parseargs/internal/util.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
// This is a placeholder for util.js in node.js land.
|
||||
|
||||
const {
|
||||
ObjectCreate,
|
||||
ObjectFreeze,
|
||||
} = require('./primordials');
|
||||
|
||||
const kEmptyObject = ObjectFreeze(ObjectCreate(null));
|
||||
|
||||
module.exports = {
|
||||
kEmptyObject,
|
||||
};
|
89
package/node_modules/@pkgjs/parseargs/internal/validators.js
generated
vendored
Normal file
89
package/node_modules/@pkgjs/parseargs/internal/validators.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
// This file is a proxy of the original file located at:
|
||||
// https://github.com/nodejs/node/blob/main/lib/internal/validators.js
|
||||
// Every addition or modification to this file must be evaluated
|
||||
// during the PR review.
|
||||
|
||||
const {
|
||||
ArrayIsArray,
|
||||
ArrayPrototypeIncludes,
|
||||
ArrayPrototypeJoin,
|
||||
} = require('./primordials');
|
||||
|
||||
const {
|
||||
codes: {
|
||||
ERR_INVALID_ARG_TYPE
|
||||
}
|
||||
} = require('./errors');
|
||||
|
||||
function validateString(value, name) {
|
||||
if (typeof value !== 'string') {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'String', value);
|
||||
}
|
||||
}
|
||||
|
||||
function validateUnion(value, name, union) {
|
||||
if (!ArrayPrototypeIncludes(union, value)) {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, `('${ArrayPrototypeJoin(union, '|')}')`, value);
|
||||
}
|
||||
}
|
||||
|
||||
function validateBoolean(value, name) {
|
||||
if (typeof value !== 'boolean') {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'Boolean', value);
|
||||
}
|
||||
}
|
||||
|
||||
function validateArray(value, name) {
|
||||
if (!ArrayIsArray(value)) {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'Array', value);
|
||||
}
|
||||
}
|
||||
|
||||
function validateStringArray(value, name) {
|
||||
validateArray(value, name);
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
validateString(value[i], `${name}[${i}]`);
|
||||
}
|
||||
}
|
||||
|
||||
function validateBooleanArray(value, name) {
|
||||
validateArray(value, name);
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
validateBoolean(value[i], `${name}[${i}]`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
* @param {string} name
|
||||
* @param {{
|
||||
* allowArray?: boolean,
|
||||
* allowFunction?: boolean,
|
||||
* nullable?: boolean
|
||||
* }} [options]
|
||||
*/
|
||||
function validateObject(value, name, options) {
|
||||
const useDefaultOptions = options == null;
|
||||
const allowArray = useDefaultOptions ? false : options.allowArray;
|
||||
const allowFunction = useDefaultOptions ? false : options.allowFunction;
|
||||
const nullable = useDefaultOptions ? false : options.nullable;
|
||||
if ((!nullable && value === null) ||
|
||||
(!allowArray && ArrayIsArray(value)) ||
|
||||
(typeof value !== 'object' && (
|
||||
!allowFunction || typeof value !== 'function'
|
||||
))) {
|
||||
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateArray,
|
||||
validateObject,
|
||||
validateString,
|
||||
validateStringArray,
|
||||
validateUnion,
|
||||
validateBoolean,
|
||||
validateBooleanArray,
|
||||
};
|
36
package/node_modules/@pkgjs/parseargs/package.json
generated
vendored
Normal file
36
package/node_modules/@pkgjs/parseargs/package.json
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "@pkgjs/parseargs",
|
||||
"version": "0.11.0",
|
||||
"description": "Polyfill of future proposal for `util.parseArgs()`",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"main": "index.js",
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "c8 --check-coverage tape 'test/*.js'",
|
||||
"test": "c8 tape 'test/*.js'",
|
||||
"posttest": "eslint .",
|
||||
"fix": "npm run posttest -- --fix"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:pkgjs/parseargs.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pkgjs/parseargs/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pkgjs/parseargs#readme",
|
||||
"devDependencies": {
|
||||
"c8": "^7.10.0",
|
||||
"eslint": "^8.2.0",
|
||||
"eslint-plugin-node-core": "iansu/eslint-plugin-node-core",
|
||||
"tape": "^5.2.2"
|
||||
}
|
||||
}
|
198
package/node_modules/@pkgjs/parseargs/utils.js
generated
vendored
Normal file
198
package/node_modules/@pkgjs/parseargs/utils.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
ArrayPrototypeFind,
|
||||
ObjectEntries,
|
||||
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
||||
StringPrototypeCharAt,
|
||||
StringPrototypeIncludes,
|
||||
StringPrototypeStartsWith,
|
||||
} = require('./internal/primordials');
|
||||
|
||||
const {
|
||||
validateObject,
|
||||
} = require('./internal/validators');
|
||||
|
||||
// These are internal utilities to make the parsing logic easier to read, and
|
||||
// add lots of detail for the curious. They are in a separate file to allow
|
||||
// unit testing, although that is not essential (this could be rolled into
|
||||
// main file and just tested implicitly via API).
|
||||
//
|
||||
// These routines are for internal use, not for export to client.
|
||||
|
||||
/**
|
||||
* Return the named property, but only if it is an own property.
|
||||
*/
|
||||
function objectGetOwn(obj, prop) {
|
||||
if (ObjectHasOwn(obj, prop))
|
||||
return obj[prop];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the named options property, but only if it is an own property.
|
||||
*/
|
||||
function optionsGetOwn(options, longOption, prop) {
|
||||
if (ObjectHasOwn(options, longOption))
|
||||
return objectGetOwn(options[longOption], prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument may be used as an option value.
|
||||
* @example
|
||||
* isOptionValue('V') // returns true
|
||||
* isOptionValue('-v') // returns true (greedy)
|
||||
* isOptionValue('--foo') // returns true (greedy)
|
||||
* isOptionValue(undefined) // returns false
|
||||
*/
|
||||
function isOptionValue(value) {
|
||||
if (value == null) return false;
|
||||
|
||||
// Open Group Utility Conventions are that an option-argument
|
||||
// is the argument after the option, and may start with a dash.
|
||||
return true; // greedy!
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether there is possible confusion and user may have omitted
|
||||
* the option argument, like `--port --verbose` when `port` of type:string.
|
||||
* In strict mode we throw errors if value is option-like.
|
||||
*/
|
||||
function isOptionLikeValue(value) {
|
||||
if (value == null) return false;
|
||||
|
||||
return value.length > 1 && StringPrototypeCharAt(value, 0) === '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if `arg` is just a short option.
|
||||
* @example '-f'
|
||||
*/
|
||||
function isLoneShortOption(arg) {
|
||||
return arg.length === 2 &&
|
||||
StringPrototypeCharAt(arg, 0) === '-' &&
|
||||
StringPrototypeCharAt(arg, 1) !== '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if `arg` is a lone long option.
|
||||
* @example
|
||||
* isLoneLongOption('a') // returns false
|
||||
* isLoneLongOption('-a') // returns false
|
||||
* isLoneLongOption('--foo') // returns true
|
||||
* isLoneLongOption('--foo=bar') // returns false
|
||||
*/
|
||||
function isLoneLongOption(arg) {
|
||||
return arg.length > 2 &&
|
||||
StringPrototypeStartsWith(arg, '--') &&
|
||||
!StringPrototypeIncludes(arg, '=', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if `arg` is a long option and value in the same argument.
|
||||
* @example
|
||||
* isLongOptionAndValue('--foo') // returns false
|
||||
* isLongOptionAndValue('--foo=bar') // returns true
|
||||
*/
|
||||
function isLongOptionAndValue(arg) {
|
||||
return arg.length > 2 &&
|
||||
StringPrototypeStartsWith(arg, '--') &&
|
||||
StringPrototypeIncludes(arg, '=', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if `arg` is a short option group.
|
||||
*
|
||||
* See Guideline 5 of the [Open Group Utility Conventions](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html).
|
||||
* One or more options without option-arguments, followed by at most one
|
||||
* option that takes an option-argument, should be accepted when grouped
|
||||
* behind one '-' delimiter.
|
||||
* @example
|
||||
* isShortOptionGroup('-a', {}) // returns false
|
||||
* isShortOptionGroup('-ab', {}) // returns true
|
||||
* // -fb is an option and a value, not a short option group
|
||||
* isShortOptionGroup('-fb', {
|
||||
* options: { f: { type: 'string' } }
|
||||
* }) // returns false
|
||||
* isShortOptionGroup('-bf', {
|
||||
* options: { f: { type: 'string' } }
|
||||
* }) // returns true
|
||||
* // -bfb is an edge case, return true and caller sorts it out
|
||||
* isShortOptionGroup('-bfb', {
|
||||
* options: { f: { type: 'string' } }
|
||||
* }) // returns true
|
||||
*/
|
||||
function isShortOptionGroup(arg, options) {
|
||||
if (arg.length <= 2) return false;
|
||||
if (StringPrototypeCharAt(arg, 0) !== '-') return false;
|
||||
if (StringPrototypeCharAt(arg, 1) === '-') return false;
|
||||
|
||||
const firstShort = StringPrototypeCharAt(arg, 1);
|
||||
const longOption = findLongOptionForShort(firstShort, options);
|
||||
return optionsGetOwn(options, longOption, 'type') !== 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if arg is a short string option followed by its value.
|
||||
* @example
|
||||
* isShortOptionAndValue('-a', {}); // returns false
|
||||
* isShortOptionAndValue('-ab', {}); // returns false
|
||||
* isShortOptionAndValue('-fFILE', {
|
||||
* options: { foo: { short: 'f', type: 'string' }}
|
||||
* }) // returns true
|
||||
*/
|
||||
function isShortOptionAndValue(arg, options) {
|
||||
validateObject(options, 'options');
|
||||
|
||||
if (arg.length <= 2) return false;
|
||||
if (StringPrototypeCharAt(arg, 0) !== '-') return false;
|
||||
if (StringPrototypeCharAt(arg, 1) === '-') return false;
|
||||
|
||||
const shortOption = StringPrototypeCharAt(arg, 1);
|
||||
const longOption = findLongOptionForShort(shortOption, options);
|
||||
return optionsGetOwn(options, longOption, 'type') === 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the long option associated with a short option. Looks for a configured
|
||||
* `short` and returns the short option itself if a long option is not found.
|
||||
* @example
|
||||
* findLongOptionForShort('a', {}) // returns 'a'
|
||||
* findLongOptionForShort('b', {
|
||||
* options: { bar: { short: 'b' } }
|
||||
* }) // returns 'bar'
|
||||
*/
|
||||
function findLongOptionForShort(shortOption, options) {
|
||||
validateObject(options, 'options');
|
||||
const longOptionEntry = ArrayPrototypeFind(
|
||||
ObjectEntries(options),
|
||||
({ 1: optionConfig }) => objectGetOwn(optionConfig, 'short') === shortOption
|
||||
);
|
||||
return longOptionEntry?.[0] ?? shortOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given option includes a default value
|
||||
* and that option has not been set by the input args.
|
||||
*
|
||||
* @param {string} longOption - long option name e.g. 'foo'
|
||||
* @param {object} optionConfig - the option configuration properties
|
||||
* @param {object} values - option values returned in `values` by parseArgs
|
||||
*/
|
||||
function useDefaultValueOption(longOption, optionConfig, values) {
|
||||
return objectGetOwn(optionConfig, 'default') !== undefined &&
|
||||
values[longOption] === undefined;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
findLongOptionForShort,
|
||||
isLoneLongOption,
|
||||
isLoneShortOption,
|
||||
isLongOptionAndValue,
|
||||
isOptionValue,
|
||||
isOptionLikeValue,
|
||||
isShortOptionAndValue,
|
||||
isShortOptionGroup,
|
||||
useDefaultValueOption,
|
||||
objectGetOwn,
|
||||
optionsGetOwn,
|
||||
};
|
Reference in New Issue
Block a user