@webpieces/rules-config 0.4.834 → 0.4.835

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/rules-config",
3
- "version": "0.4.834",
3
+ "version": "0.4.835",
4
4
  "description": "Shared webpieces.config.json loader. Single source of truth for validation rule configuration consumed by @webpieces/ai-hook-rules, @webpieces/code-rules, and @webpieces/nx-webpieces-rules.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
package/src/cli-args.d.ts CHANGED
@@ -82,6 +82,8 @@ export declare class CliArgs {
82
82
  * git.
83
83
  */
84
84
  parse(usage: CliUsage): CliArgSet;
85
+ /** Parse explicitly supplied argv without mutating process.argv. */
86
+ parseArgs(args: string[], usage: CliUsage): CliArgSet;
85
87
  /**
86
88
  * Call it as the FIRST thing inside `runMain`, BEFORE the app touches git — a bogus flag must
87
89
  * never start a mutation flow (the `wp-start-upsert-pr --help` incident: an ignored flag silently
package/src/cli-args.js CHANGED
@@ -177,7 +177,10 @@ let CliArgs = class CliArgs {
177
177
  * git.
178
178
  */
179
179
  parse(usage) {
180
- const args = process.argv.slice(2);
180
+ return this.parseArgs(process.argv.slice(2), usage);
181
+ }
182
+ /** Parse explicitly supplied argv without mutating process.argv. */
183
+ parseArgs(args, usage) {
181
184
  const check = this.classify(args, usage);
182
185
  if (!check.ok)
183
186
  throw new cli_exit_error_1.CliExitError(check.exitCode, check.message);
@@ -1 +1 @@
1
- {"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/cli-args.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,qDAAgD;AAEhD;;;GAGG;AACH,MAAa,OAAO;IAChB,IAAI,CAAS,CAAQ,iDAAiD;IACtE,WAAW,CAAS;IACpB;;;;;;;OAOG;IACH,UAAU,CAAU;IAEpB,YAAY,IAAY,EAAE,WAAmB,EAAE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AAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAe;QACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,EAAE;YAAE,MAAM,IAAI,6BAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACrE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACpC,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,CAAC,KAAe;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAC1D,IAAI,KAAK,CAAC,EAAE;YAAE,OAAO;QACrB,MAAM,IAAI,6BAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;CACJ,CAAA;AAtGY,0BAAO;kBAAP,OAAO;IADnB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,OAAO,CAsGnB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { CliExitError } from './cli-exit-error';\n\n/**\n * One optional `--flag` a command accepts. Data-only. The description is printed in `--help`, so it is\n * written for the reader who has to DECIDE whether to pass it, not as a restatement of the name.\n */\nexport class CliFlag {\n name: string; // including the leading dashes, e.g. '--dry-run'\n description: string;\n /**\n * The flag MAY carry a value: `--resolve dean/ONE-2275` or `--resolve=dean/ONE-2275`.\n *\n * \"May\", not \"must\". The one flag that needs this (`wp-push-dev --resolve`) is meaningful both bare\n * (queue every other copy) and with an argument (queue just that one), and a `valueRequired` variant\n * would be a second concept for a case nothing has. A following token is consumed as the value only\n * when it does not itself start with `-`, so `--resolve --force` still reads as two flags.\n */\n takesValue: boolean;\n\n constructor(name: string, description: string, takesValue = false) {\n this.name = name;\n this.description = description;\n this.takesValue = takesValue;\n }\n}\n\n/**\n * Usage descriptor for a `wp-*` bin. Data-only (classes-over-interfaces): a command name, its one-line\n * summary, and the flags it accepts. `CliArgs.classify` turns it into the `--help` / unknown-arg message.\n *\n * `flags` defaults to [] — the no-argument case stays a two-arg construction, which is what MOST `wp-*`\n * bins are. (Deliberately not a count: the last one written down went stale the next time a bin grew a\n * flag, which is exactly the drift the corollary in `.claude/rules/no-backwards-compat.md` is about.)\n *\n * A flag a command does not DECLARE here is still rejected with exit 2: that guard is\n * the reason this class exists (`wp-start-upsert-pr --help` once launched a squash-merge), and making it\n * flag-aware must not soften it.\n */\nexport class CliUsage {\n command: string;\n summary: string;\n flags: CliFlag[];\n\n constructor(command: string, summary: string, flags: CliFlag[] = []) {\n this.command = command;\n this.summary = summary;\n this.flags = flags;\n }\n}\n\n/**\n * Which declared flags argv actually carried. Data-only (a class, per CLAUDE.md), with a `has()` accessor\n * so every consumer asks the question the same way instead of open-coding `includes` against a raw array.\n */\nexport class CliArgSet {\n present: string[];\n // Values for the value-taking flags that carried one, keyed by flag name. A flag passed bare is in\n // `present` but absent here, which is exactly the distinction `--resolve` (bare) vs\n // `--resolve <branch>` needs.\n values: Map<string, string>;\n\n constructor(present: string[] = [], values: Map<string, string> = new Map<string, string>()) {\n this.present = present;\n this.values = values;\n }\n\n has(flag: string): boolean {\n return this.present.includes(flag);\n }\n\n /** The value passed with `flag`, or '' when the flag was absent or passed bare. */\n value(flag: string): string {\n return this.values.get(flag) ?? '';\n }\n}\n\n/**\n * Data-only outcome of checking argv against a no-argument command. `ok` true → run normally; else\n * `exitCode`/`message` are what the bin should exit with (help = 0, unknown arg = 2). Kept a pure\n * value so it can be asserted directly in tests without provoking a throw.\n */\nexport class CliArgsCheck {\n ok: boolean;\n exitCode: number;\n message: string;\n\n constructor(ok: boolean, exitCode: number, message: string) {\n this.ok = ok;\n this.exitCode = exitCode;\n this.message = message;\n }\n}\n\n/** One argv walk's result: which declared flags were seen, their values, and every unrecognized token. */\nclass CliScan {\n present: string[] = [];\n values: Map<string, string> = new Map<string, string>();\n unknown: string[] = [];\n}\n\n/** Argument guard for the no-argument `wp-*` bins. */\n@injectable(bindingScopeValues.Singleton)\nexport class CliArgs {\n // The help/usage block shown for `--help` and appended to an unknown-arg error. A command with no\n // declared flags says so outright, because \"takes no arguments\" is the whole usage for most of them.\n private usageText(usage: CliUsage): string {\n const head = `${usage.command} — ${usage.summary}\\n\\n`;\n if (usage.flags.length === 0) {\n return head + `Usage: pnpm ${usage.command}\\nThis command takes no arguments.`;\n }\n const label = (f: CliFlag): string => (f.takesValue ? `${f.name} [<value>]` : f.name);\n const width = Math.max(...usage.flags.map((f: CliFlag): number => label(f).length));\n const rows = usage.flags.map((f: CliFlag): string => ` ${label(f).padEnd(width)} ${f.description}`);\n return head + `Usage: pnpm ${usage.command} [flags]\\n\\nFlags:\\n${rows.join('\\n')}`;\n }\n\n /**\n * Pure argv classifier. No args → ok. `--help`/`-h` → not-ok, exit 0 with the usage block. Any token\n * the command did not DECLARE → not-ok, exit 2 naming the offending one(s). Split out from\n * `assertNoArgs`/`parse` so the decision is unit-testable without a thrown exception.\n *\n * An undeclared token is still fatal even for a command that accepts flags — a mistyped `--no-optionl`\n * must never be silently ignored and then run the flow WITH the reviews the caller meant to skip.\n */\n classify(args: string[], usage: CliUsage): CliArgsCheck {\n if (args.length === 0) return new CliArgsCheck(true, 0, '');\n if (args.includes('--help') || args.includes('-h')) {\n return new CliArgsCheck(false, 0, this.usageText(usage));\n }\n const scan = this.scan(args, usage);\n if (scan.unknown.length > 0) {\n return new CliArgsCheck(false, 2, `❌ Unknown argument(s): ${scan.unknown.join(' ')}\\n\\n` + this.usageText(usage));\n }\n return new CliArgsCheck(true, 0, '');\n }\n\n /**\n * Walk argv once, classifying every token as a declared flag, a value belonging to the\n * value-taking flag before it, or unknown. ONE walk backs both `classify` and `parse` so the set of\n * tokens the guard accepts and the set `parse` reports can never diverge — an accepted-but-unreported\n * flag would silently run the flow without the behaviour the caller asked for.\n */\n private scan(args: string[], usage: CliUsage): CliScan {\n const byName = new Map<string, CliFlag>();\n for (const flag of usage.flags) byName.set(flag.name, flag);\n const scan = new CliScan();\n for (let i = 0; i < args.length; i += 1) {\n const token = args[i];\n const eq = token.indexOf('=');\n // `--flag=value` — split before lookup so the name is what gets matched, not the whole token.\n const name = eq > 0 ? token.slice(0, eq) : token;\n const flag = byName.get(name);\n if (flag === undefined) {\n scan.unknown.push(token);\n continue;\n }\n scan.present.push(name);\n if (!flag.takesValue) {\n // `--dry-run=x` is a typo, not an accepted flag: the value would be silently dropped.\n if (eq > 0) scan.unknown.push(token);\n continue;\n }\n if (eq > 0) {\n scan.values.set(name, token.slice(eq + 1));\n continue;\n }\n // OPTIONAL value: only a following token that is not itself a flag. `--resolve --force`\n // therefore reads as two flags, not as a resolve of a branch literally named `--force`.\n const next = i + 1 < args.length ? args[i + 1] : '';\n if (next !== '' && !next.startsWith('-')) {\n scan.values.set(name, next);\n i += 1;\n }\n }\n return scan;\n }\n\n /**\n * The flag-accepting sibling of {@link assertNoArgs}: same guard, but it RETURNS which declared flags\n * were passed. Call it in exactly the same place — first thing inside `runMain`, before the app touches\n * git.\n */\n parse(usage: CliUsage): CliArgSet {\n const args = process.argv.slice(2);\n const check = this.classify(args, usage);\n if (!check.ok) throw new CliExitError(check.exitCode, check.message);\n const scan = this.scan(args, usage);\n return new CliArgSet(scan.present, scan.values);\n }\n\n /**\n * Call it as the FIRST thing inside `runMain`, BEFORE the app touches git — a bogus flag must\n * never start a mutation flow (the `wp-start-upsert-pr --help` incident: an ignored flag silently\n * launched the squash-merge and stranded the checkout on a `…PreMerge<n>` branch).\n *\n * Throws `CliExitError` (never `process.exit`) so `runMain` stays the single sanctioned exit site\n * (`no-process-exit-outside-main`): help exits 0, an unknown arg exits 2, and in both cases the\n * flow never begins.\n */\n assertNoArgs(usage: CliUsage): void {\n const check = this.classify(process.argv.slice(2), usage);\n if (check.ok) return;\n throw new CliExitError(check.exitCode, check.message);\n }\n}\n"]}
1
+ {"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/cli-args.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,qDAAgD;AAEhD;;;GAGG;AACH,MAAa,OAAO;IAChB,IAAI,CAAS,CAAQ,iDAAiD;IACtE,WAAW,CAAS;IACpB;;;;;;;OAOG;IACH,UAAU,CAAU;IAEpB,YAAY,IAAY,EAAE,WAAmB,EAAE,UAAU,GAAG,KAAK;QAC7D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;CACJ;AAlBD,0BAkBC;AAED;;;;;;;;;;;GAWG;AACH,MAAa,QAAQ;IACjB,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,KAAK,CAAY;IAEjB,YAAY,OAAe,EAAE,OAAe,EAAE,QAAmB,EAAE;QAC/D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAVD,4BAUC;AAED;;;GAGG;AACH,MAAa,SAAS;IAClB,OAAO,CAAW;IAClB,mGAAmG;IACnG,oFAAoF;IACpF,8BAA8B;IAC9B,MAAM,CAAsB;IAE5B,YAAY,UAAoB,EAAE,EAAE,SAA8B,IAAI,GAAG,EAAkB;QACvF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,C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AC;QAC1D,IAAI,KAAK,CAAC,EAAE;YAAE,OAAO;QACrB,MAAM,IAAI,6BAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;CACJ,CAAA;AA1GY,0BAAO;kBAAP,OAAO;IADnB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,OAAO,CA0GnB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { CliExitError } from './cli-exit-error';\n\n/**\n * One optional `--flag` a command accepts. Data-only. The description is printed in `--help`, so it is\n * written for the reader who has to DECIDE whether to pass it, not as a restatement of the name.\n */\nexport class CliFlag {\n name: string; // including the leading dashes, e.g. '--dry-run'\n description: string;\n /**\n * The flag MAY carry a value: `--resolve dean/ONE-2275` or `--resolve=dean/ONE-2275`.\n *\n * \"May\", not \"must\". The one flag that needs this (`wp-push-dev --resolve`) is meaningful both bare\n * (queue every other copy) and with an argument (queue just that one), and a `valueRequired` variant\n * would be a second concept for a case nothing has. A following token is consumed as the value only\n * when it does not itself start with `-`, so `--resolve --force` still reads as two flags.\n */\n takesValue: boolean;\n\n constructor(name: string, description: string, takesValue = false) {\n this.name = name;\n this.description = description;\n this.takesValue = takesValue;\n }\n}\n\n/**\n * Usage descriptor for a `wp-*` bin. Data-only (classes-over-interfaces): a command name, its one-line\n * summary, and the flags it accepts. `CliArgs.classify` turns it into the `--help` / unknown-arg message.\n *\n * `flags` defaults to [] — the no-argument case stays a two-arg construction, which is what MOST `wp-*`\n * bins are. (Deliberately not a count: the last one written down went stale the next time a bin grew a\n * flag, which is exactly the drift the corollary in `.claude/rules/no-backwards-compat.md` is about.)\n *\n * A flag a command does not DECLARE here is still rejected with exit 2: that guard is\n * the reason this class exists (`wp-start-upsert-pr --help` once launched a squash-merge), and making it\n * flag-aware must not soften it.\n */\nexport class CliUsage {\n command: string;\n summary: string;\n flags: CliFlag[];\n\n constructor(command: string, summary: string, flags: CliFlag[] = []) {\n this.command = command;\n this.summary = summary;\n this.flags = flags;\n }\n}\n\n/**\n * Which declared flags argv actually carried. Data-only (a class, per CLAUDE.md), with a `has()` accessor\n * so every consumer asks the question the same way instead of open-coding `includes` against a raw array.\n */\nexport class CliArgSet {\n present: string[];\n // Values for the value-taking flags that carried one, keyed by flag name. A flag passed bare is in\n // `present` but absent here, which is exactly the distinction `--resolve` (bare) vs\n // `--resolve <branch>` needs.\n values: Map<string, string>;\n\n constructor(present: string[] = [], values: Map<string, string> = new Map<string, string>()) {\n this.present = present;\n this.values = values;\n }\n\n has(flag: string): boolean {\n return this.present.includes(flag);\n }\n\n /** The value passed with `flag`, or '' when the flag was absent or passed bare. */\n value(flag: string): string {\n return this.values.get(flag) ?? '';\n }\n}\n\n/**\n * Data-only outcome of checking argv against a no-argument command. `ok` true → run normally; else\n * `exitCode`/`message` are what the bin should exit with (help = 0, unknown arg = 2). Kept a pure\n * value so it can be asserted directly in tests without provoking a throw.\n */\nexport class CliArgsCheck {\n ok: boolean;\n exitCode: number;\n message: string;\n\n constructor(ok: boolean, exitCode: number, message: string) {\n this.ok = ok;\n this.exitCode = exitCode;\n this.message = message;\n }\n}\n\n/** One argv walk's result: which declared flags were seen, their values, and every unrecognized token. */\nclass CliScan {\n present: string[] = [];\n values: Map<string, string> = new Map<string, string>();\n unknown: string[] = [];\n}\n\n/** Argument guard for the no-argument `wp-*` bins. */\n@injectable(bindingScopeValues.Singleton)\nexport class CliArgs {\n // The help/usage block shown for `--help` and appended to an unknown-arg error. A command with no\n // declared flags says so outright, because \"takes no arguments\" is the whole usage for most of them.\n private usageText(usage: CliUsage): string {\n const head = `${usage.command} — ${usage.summary}\\n\\n`;\n if (usage.flags.length === 0) {\n return head + `Usage: pnpm ${usage.command}\\nThis command takes no arguments.`;\n }\n const label = (f: CliFlag): string => (f.takesValue ? `${f.name} [<value>]` : f.name);\n const width = Math.max(...usage.flags.map((f: CliFlag): number => label(f).length));\n const rows = usage.flags.map((f: CliFlag): string => ` ${label(f).padEnd(width)} ${f.description}`);\n return head + `Usage: pnpm ${usage.command} [flags]\\n\\nFlags:\\n${rows.join('\\n')}`;\n }\n\n /**\n * Pure argv classifier. No args → ok. `--help`/`-h` → not-ok, exit 0 with the usage block. Any token\n * the command did not DECLARE → not-ok, exit 2 naming the offending one(s). Split out from\n * `assertNoArgs`/`parse` so the decision is unit-testable without a thrown exception.\n *\n * An undeclared token is still fatal even for a command that accepts flags — a mistyped `--no-optionl`\n * must never be silently ignored and then run the flow WITH the reviews the caller meant to skip.\n */\n classify(args: string[], usage: CliUsage): CliArgsCheck {\n if (args.length === 0) return new CliArgsCheck(true, 0, '');\n if (args.includes('--help') || args.includes('-h')) {\n return new CliArgsCheck(false, 0, this.usageText(usage));\n }\n const scan = this.scan(args, usage);\n if (scan.unknown.length > 0) {\n return new CliArgsCheck(false, 2, `❌ Unknown argument(s): ${scan.unknown.join(' ')}\\n\\n` + this.usageText(usage));\n }\n return new CliArgsCheck(true, 0, '');\n }\n\n /**\n * Walk argv once, classifying every token as a declared flag, a value belonging to the\n * value-taking flag before it, or unknown. ONE walk backs both `classify` and `parse` so the set of\n * tokens the guard accepts and the set `parse` reports can never diverge — an accepted-but-unreported\n * flag would silently run the flow without the behaviour the caller asked for.\n */\n private scan(args: string[], usage: CliUsage): CliScan {\n const byName = new Map<string, CliFlag>();\n for (const flag of usage.flags) byName.set(flag.name, flag);\n const scan = new CliScan();\n for (let i = 0; i < args.length; i += 1) {\n const token = args[i];\n const eq = token.indexOf('=');\n // `--flag=value` — split before lookup so the name is what gets matched, not the whole token.\n const name = eq > 0 ? token.slice(0, eq) : token;\n const flag = byName.get(name);\n if (flag === undefined) {\n scan.unknown.push(token);\n continue;\n }\n scan.present.push(name);\n if (!flag.takesValue) {\n // `--dry-run=x` is a typo, not an accepted flag: the value would be silently dropped.\n if (eq > 0) scan.unknown.push(token);\n continue;\n }\n if (eq > 0) {\n scan.values.set(name, token.slice(eq + 1));\n continue;\n }\n // OPTIONAL value: only a following token that is not itself a flag. `--resolve --force`\n // therefore reads as two flags, not as a resolve of a branch literally named `--force`.\n const next = i + 1 < args.length ? args[i + 1] : '';\n if (next !== '' && !next.startsWith('-')) {\n scan.values.set(name, next);\n i += 1;\n }\n }\n return scan;\n }\n\n /**\n * The flag-accepting sibling of {@link assertNoArgs}: same guard, but it RETURNS which declared flags\n * were passed. Call it in exactly the same place — first thing inside `runMain`, before the app touches\n * git.\n */\n parse(usage: CliUsage): CliArgSet {\n return this.parseArgs(process.argv.slice(2), usage);\n }\n\n /** Parse explicitly supplied argv without mutating process.argv. */\n parseArgs(args: string[], usage: CliUsage): CliArgSet {\n const check = this.classify(args, usage);\n if (!check.ok) throw new CliExitError(check.exitCode, check.message);\n const scan = this.scan(args, usage);\n return new CliArgSet(scan.present, scan.values);\n }\n\n /**\n * Call it as the FIRST thing inside `runMain`, BEFORE the app touches git — a bogus flag must\n * never start a mutation flow (the `wp-start-upsert-pr --help` incident: an ignored flag silently\n * launched the squash-merge and stranded the checkout on a `…PreMerge<n>` branch).\n *\n * Throws `CliExitError` (never `process.exit`) so `runMain` stays the single sanctioned exit site\n * (`no-process-exit-outside-main`): help exits 0, an unknown arg exits 2, and in both cases the\n * flow never begins.\n */\n assertNoArgs(usage: CliUsage): void {\n const check = this.classify(process.argv.slice(2), usage);\n if (check.ok) return;\n throw new CliExitError(check.exitCode, check.message);\n }\n}\n"]}