diff --git a/node_modules/jackspeak/LICENSE.md b/node_modules/jackspeak/LICENSE.md index c5402b9577a8c..8cb5cc6e616c0 100644 --- a/node_modules/jackspeak/LICENSE.md +++ b/node_modules/jackspeak/LICENSE.md @@ -11,7 +11,7 @@ from liability. ## Acceptance In order to receive this license, you must agree to its -rules. The rules of this license are both obligations +rules. The rules of this license are both obligations under that agreement and conditions to your license. You must not do anything with this software that triggers a rule that you cannot or will not follow. @@ -34,7 +34,7 @@ changes, also gets the text of this license or a link to If anyone notifies you in writing that you have not complied with [Notices](#notices), you can keep your license by taking all practical steps to comply within 30 -days after the notice. If you do not do so, your license +days after the notice. If you do not do so, your license ends immediately. ## Patent @@ -49,7 +49,7 @@ No contributor can revoke this license. ## No Liability -***As far as the law allows, this software comes as is, +**_As far as the law allows, this software comes as is, without any warranty or condition, and no contributor will be liable to anyone for any damages related to this -software or this license, under any kind of legal claim.*** +software or this license, under any kind of legal claim._** diff --git a/node_modules/jackspeak/dist/commonjs/index.js b/node_modules/jackspeak/dist/commonjs/index.js index a66dde30a9dd6..b0e016d175ad0 100644 --- a/node_modules/jackspeak/dist/commonjs/index.js +++ b/node_modules/jackspeak/dist/commonjs/index.js @@ -365,9 +365,13 @@ class Jack { * an explicit CLI setting. */ parse(args = process.argv) { - if (args === process.argv) { - args = args.slice(process._eval !== undefined ? 1 : 2); - } + this.loadEnvDefaults(); + const p = this.parseRaw(args); + this.applyDefaults(p); + this.writeEnv(p); + return p; + } + loadEnvDefaults() { if (this.#envPrefix) { for (const [field, my] of Object.entries(this.#configSet)) { const ek = toEnvKey(this.#envPrefix, field); @@ -377,6 +381,25 @@ class Jack { } } } + } + applyDefaults(p) { + for (const [field, c] of Object.entries(this.#configSet)) { + if (c.default !== undefined && !(field in p.values)) { + //@ts-ignore + p.values[field] = c.default; + } + } + } + /** + * Only parse the command line arguments passed in. + * Does not strip off the `node script.js` bits, so it must be just the + * arguments you wish to have parsed. + * Does not read from or write to the environment, or set defaults. + */ + parseRaw(args) { + if (args === process.argv) { + args = args.slice(process._eval !== undefined ? 1 : 2); + } const options = toParseArgsOptionsConfig(this.#configSet); const result = (0, parse_args_js_1.parseArgs)({ args, @@ -393,9 +416,10 @@ class Jack { for (const token of result.tokens) { if (token.kind === 'positional') { p.positionals.push(token.value); - if (this.#options.stopAtPositional) { + if (this.#options.stopAtPositional || + this.#options.stopAtPositionalTest?.(token.value)) { p.positionals.push(...args.slice(token.index + 1)); - return p; + break; } } else if (token.kind === 'option') { @@ -469,12 +493,6 @@ class Jack { } } } - for (const [field, c] of Object.entries(this.#configSet)) { - if (c.default !== undefined && !(field in p.values)) { - //@ts-ignore - p.values[field] = c.default; - } - } for (const [field, value] of Object.entries(p.values)) { const valid = this.#configSet[field]?.validate; const validOptions = this.#configSet[field]?.validOptions; @@ -489,7 +507,6 @@ class Jack { throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`, { cause }); } } - this.#writeEnv(p); return p; } /** @@ -557,7 +574,7 @@ class Jack { } } } - #writeEnv(p) { + writeEnv(p) { if (!this.#env || !this.#envPrefix) return; for (const [field, value] of Object.entries(p.values)) { @@ -912,6 +929,7 @@ class Jack { ...(def.validate ? { validate: def.validate } : {}), ...(def.validOptions ? { validOptions: def.validOptions } : {}), ...(def.default !== undefined ? { default: def.default } : {}), + ...(def.hint ? { hint: def.hint } : {}), }, ])); } @@ -925,22 +943,52 @@ class Jack { exports.Jack = Jack; // Unwrap and un-indent, so we can wrap description // strings however makes them look nice in the code. -const normalize = (s, pre = false) => pre ? - // prepend a ZWSP to each line so cliui doesn't strip it. - s - .split('\n') - .map(l => `\u200b${l}`) - .join('\n') - : s - // remove single line breaks, except for lists - .replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`) - // normalize mid-line whitespace - .replace(/([^\n])[ \t]+([^\n])/g, '$1 $2') - // two line breaks are enough - .replace(/\n{3,}/g, '\n\n') - // remove any spaces at the start of a line - .replace(/\n[ \t]+/g, '\n') - .trim(); +const normalize = (s, pre = false) => { + if (pre) + // prepend a ZWSP to each line so cliui doesn't strip it. + return s + .split('\n') + .map(l => `\u200b${l}`) + .join('\n'); + return s + .split(/^\s*```\s*$/gm) + .map((s, i) => { + if (i % 2 === 1) { + if (!s.trim()) { + return `\`\`\`\n\`\`\`\n`; + } + // outdent the ``` blocks, but preserve whitespace otherwise. + const split = s.split('\n'); + // throw out the \n at the start and end + split.pop(); + split.shift(); + const si = split.reduce((shortest, l) => { + /* c8 ignore next */ + const ind = l.match(/^\s*/)?.[0] ?? ''; + if (ind.length) + return Math.min(ind.length, shortest); + else + return shortest; + }, Infinity); + /* c8 ignore next */ + const i = isFinite(si) ? si : 0; + return ('\n```\n' + + split.map(s => `\u200b${s.substring(i)}`).join('\n') + + '\n```\n'); + } + return (s + // remove single line breaks, except for lists + .replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`) + // normalize mid-line whitespace + .replace(/([^\n])[ \t]+([^\n])/g, '$1 $2') + // two line breaks are enough + .replace(/\n{3,}/g, '\n\n') + // remove any spaces at the start of a line + .replace(/\n[ \t]+/g, '\n') + .trim()); + }) + .join('\n'); +}; // normalize for markdown printing, remove leading spaces on lines const normalizeMarkdown = (s, pre = false) => { const n = normalize(s, pre).replace(/\\/g, '\\\\'); diff --git a/node_modules/jackspeak/dist/commonjs/parse-args.js b/node_modules/jackspeak/dist/commonjs/parse-args.js index ab628be8c9d5c..fc918a41fe603 100644 --- a/node_modules/jackspeak/dist/commonjs/parse-args.js +++ b/node_modules/jackspeak/dist/commonjs/parse-args.js @@ -25,10 +25,10 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); exports.parseArgs = void 0; const util = __importStar(require("util")); -const pv = typeof process === 'object' && +const pv = (typeof process === 'object' && !!process && - typeof process.version === 'string' - ? process.version + typeof process.version === 'string') ? + process.version : 'v0.0.0'; const pvs = pv .replace(/^v/, '') diff --git a/node_modules/jackspeak/dist/esm/index.js b/node_modules/jackspeak/dist/esm/index.js index 6c4882b4e06bc..8eef5b4e8f5f8 100644 --- a/node_modules/jackspeak/dist/esm/index.js +++ b/node_modules/jackspeak/dist/esm/index.js @@ -357,9 +357,13 @@ export class Jack { * an explicit CLI setting. */ parse(args = process.argv) { - if (args === process.argv) { - args = args.slice(process._eval !== undefined ? 1 : 2); - } + this.loadEnvDefaults(); + const p = this.parseRaw(args); + this.applyDefaults(p); + this.writeEnv(p); + return p; + } + loadEnvDefaults() { if (this.#envPrefix) { for (const [field, my] of Object.entries(this.#configSet)) { const ek = toEnvKey(this.#envPrefix, field); @@ -369,6 +373,25 @@ export class Jack { } } } + } + applyDefaults(p) { + for (const [field, c] of Object.entries(this.#configSet)) { + if (c.default !== undefined && !(field in p.values)) { + //@ts-ignore + p.values[field] = c.default; + } + } + } + /** + * Only parse the command line arguments passed in. + * Does not strip off the `node script.js` bits, so it must be just the + * arguments you wish to have parsed. + * Does not read from or write to the environment, or set defaults. + */ + parseRaw(args) { + if (args === process.argv) { + args = args.slice(process._eval !== undefined ? 1 : 2); + } const options = toParseArgsOptionsConfig(this.#configSet); const result = parseArgs({ args, @@ -385,9 +408,10 @@ export class Jack { for (const token of result.tokens) { if (token.kind === 'positional') { p.positionals.push(token.value); - if (this.#options.stopAtPositional) { + if (this.#options.stopAtPositional || + this.#options.stopAtPositionalTest?.(token.value)) { p.positionals.push(...args.slice(token.index + 1)); - return p; + break; } } else if (token.kind === 'option') { @@ -461,12 +485,6 @@ export class Jack { } } } - for (const [field, c] of Object.entries(this.#configSet)) { - if (c.default !== undefined && !(field in p.values)) { - //@ts-ignore - p.values[field] = c.default; - } - } for (const [field, value] of Object.entries(p.values)) { const valid = this.#configSet[field]?.validate; const validOptions = this.#configSet[field]?.validOptions; @@ -481,7 +499,6 @@ export class Jack { throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`, { cause }); } } - this.#writeEnv(p); return p; } /** @@ -549,7 +566,7 @@ export class Jack { } } } - #writeEnv(p) { + writeEnv(p) { if (!this.#env || !this.#envPrefix) return; for (const [field, value] of Object.entries(p.values)) { @@ -904,6 +921,7 @@ export class Jack { ...(def.validate ? { validate: def.validate } : {}), ...(def.validOptions ? { validOptions: def.validOptions } : {}), ...(def.default !== undefined ? { default: def.default } : {}), + ...(def.hint ? { hint: def.hint } : {}), }, ])); } @@ -916,22 +934,52 @@ export class Jack { } // Unwrap and un-indent, so we can wrap description // strings however makes them look nice in the code. -const normalize = (s, pre = false) => pre ? - // prepend a ZWSP to each line so cliui doesn't strip it. - s - .split('\n') - .map(l => `\u200b${l}`) - .join('\n') - : s - // remove single line breaks, except for lists - .replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`) - // normalize mid-line whitespace - .replace(/([^\n])[ \t]+([^\n])/g, '$1 $2') - // two line breaks are enough - .replace(/\n{3,}/g, '\n\n') - // remove any spaces at the start of a line - .replace(/\n[ \t]+/g, '\n') - .trim(); +const normalize = (s, pre = false) => { + if (pre) + // prepend a ZWSP to each line so cliui doesn't strip it. + return s + .split('\n') + .map(l => `\u200b${l}`) + .join('\n'); + return s + .split(/^\s*```\s*$/gm) + .map((s, i) => { + if (i % 2 === 1) { + if (!s.trim()) { + return `\`\`\`\n\`\`\`\n`; + } + // outdent the ``` blocks, but preserve whitespace otherwise. + const split = s.split('\n'); + // throw out the \n at the start and end + split.pop(); + split.shift(); + const si = split.reduce((shortest, l) => { + /* c8 ignore next */ + const ind = l.match(/^\s*/)?.[0] ?? ''; + if (ind.length) + return Math.min(ind.length, shortest); + else + return shortest; + }, Infinity); + /* c8 ignore next */ + const i = isFinite(si) ? si : 0; + return ('\n```\n' + + split.map(s => `\u200b${s.substring(i)}`).join('\n') + + '\n```\n'); + } + return (s + // remove single line breaks, except for lists + .replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`) + // normalize mid-line whitespace + .replace(/([^\n])[ \t]+([^\n])/g, '$1 $2') + // two line breaks are enough + .replace(/\n{3,}/g, '\n\n') + // remove any spaces at the start of a line + .replace(/\n[ \t]+/g, '\n') + .trim()); + }) + .join('\n'); +}; // normalize for markdown printing, remove leading spaces on lines const normalizeMarkdown = (s, pre = false) => { const n = normalize(s, pre).replace(/\\/g, '\\\\'); diff --git a/node_modules/jackspeak/dist/esm/parse-args.js b/node_modules/jackspeak/dist/esm/parse-args.js index 23389a5ddee00..a4be7153de1f1 100644 --- a/node_modules/jackspeak/dist/esm/parse-args.js +++ b/node_modules/jackspeak/dist/esm/parse-args.js @@ -1,8 +1,8 @@ import * as util from 'util'; -const pv = typeof process === 'object' && +const pv = (typeof process === 'object' && !!process && - typeof process.version === 'string' - ? process.version + typeof process.version === 'string') ? + process.version : 'v0.0.0'; const pvs = pv .replace(/^v/, '') diff --git a/node_modules/jackspeak/package.json b/node_modules/jackspeak/package.json index 1e2b441f688a2..f9f7430673311 100644 --- a/node_modules/jackspeak/package.json +++ b/node_modules/jackspeak/package.json @@ -1,6 +1,6 @@ { "name": "jackspeak", - "version": "3.1.2", + "version": "3.4.0", "description": "A very strict and proper argument parser.", "tshy": { "main": true, @@ -38,7 +38,7 @@ "presnap": "npm run prepare", "test": "tap", "snap": "tap", - "format": "prettier --write . --loglevel warn", + "format": "prettier --write . --log-level warn", "typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts" }, "license": "BlueOak-1.0.0", diff --git a/package-lock.json b/package-lock.json index e11a88399d6aa..31c7b7732df76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7340,9 +7340,9 @@ } }, "node_modules/jackspeak": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.1.2.tgz", - "integrity": "sha512-kWmLKn2tRtfYMF/BakihVVRzBKOxz4gJMiL2Rj91WnAB5TPZumSH99R/Yf1qE1u4uRimvCSJfm6hnxohXeEXjQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.0.tgz", + "integrity": "sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==", "inBundle": true, "license": "BlueOak-1.0.0", "dependencies": {