@webpieces/code-rules 0.4.975 → 0.4.977

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.
Files changed (70) hide show
  1. package/package.json +6 -6
  2. package/src/api-lib-source-rule.js +5 -5
  3. package/src/api-lib-source-rule.js.map +1 -1
  4. package/src/code-policy-composition.js +2 -0
  5. package/src/code-policy-composition.js.map +1 -1
  6. package/src/code-rules-bootstrap.js +3 -3
  7. package/src/code-rules-bootstrap.js.map +1 -1
  8. package/src/project-scan-targets.d.ts +1 -1
  9. package/src/project-scan-targets.js +7 -7
  10. package/src/project-scan-targets.js.map +1 -1
  11. package/src/rule-debug-run.d.ts +2 -2
  12. package/src/rule-debug-run.js +7 -7
  13. package/src/rule-debug-run.js.map +1 -1
  14. package/src/scan-scope.d.ts +4 -4
  15. package/src/scan-scope.js +28 -23
  16. package/src/scan-scope.js.map +1 -1
  17. package/src/tag-rule.js +2 -2
  18. package/src/tag-rule.js.map +1 -1
  19. package/src/validate-catch-error-pattern.js +6 -5
  20. package/src/validate-catch-error-pattern.js.map +1 -1
  21. package/src/validate-catch-must-propagate.js +3 -3
  22. package/src/validate-catch-must-propagate.js.map +1 -1
  23. package/src/validate-dtos.js +15 -12
  24. package/src/validate-dtos.js.map +1 -1
  25. package/src/validate-ensure-we-are-secure.js +2 -2
  26. package/src/validate-ensure-we-are-secure.js.map +1 -1
  27. package/src/validate-framework-packages.js +2 -2
  28. package/src/validate-framework-packages.js.map +1 -1
  29. package/src/validate-framework-tsconfig.js +2 -2
  30. package/src/validate-framework-tsconfig.js.map +1 -1
  31. package/src/validate-inject-annotation-not-needed-for-concrete-class.js +5 -5
  32. package/src/validate-inject-annotation-not-needed-for-concrete-class.js.map +1 -1
  33. package/src/validate-match-rules.js +5 -5
  34. package/src/validate-match-rules.js.map +1 -1
  35. package/src/validate-modified-files.js +2 -2
  36. package/src/validate-modified-files.js.map +1 -1
  37. package/src/validate-modified-methods.js +6 -5
  38. package/src/validate-modified-methods.js.map +1 -1
  39. package/src/validate-new-methods.js +6 -5
  40. package/src/validate-new-methods.js.map +1 -1
  41. package/src/validate-no-any-unknown.js +6 -6
  42. package/src/validate-no-any-unknown.js.map +1 -1
  43. package/src/validate-no-client-creation-outside-server-or-client.js +7 -7
  44. package/src/validate-no-client-creation-outside-server-or-client.js.map +1 -1
  45. package/src/validate-no-custom-css.js +5 -5
  46. package/src/validate-no-custom-css.js.map +1 -1
  47. package/src/validate-no-destructure.js +6 -6
  48. package/src/validate-no-destructure.js.map +1 -1
  49. package/src/validate-no-direct-api-resolver.js +10 -10
  50. package/src/validate-no-direct-api-resolver.js.map +1 -1
  51. package/src/validate-no-function-outside-class.js +5 -5
  52. package/src/validate-no-function-outside-class.js.map +1 -1
  53. package/src/validate-no-implicit-any.js +6 -5
  54. package/src/validate-no-implicit-any.js.map +1 -1
  55. package/src/validate-no-inline-types.js +10 -10
  56. package/src/validate-no-inline-types.js.map +1 -1
  57. package/src/validate-no-process-exit-outside-main.js +6 -5
  58. package/src/validate-no-process-exit-outside-main.js.map +1 -1
  59. package/src/validate-no-state-paths-in-templates.js +5 -5
  60. package/src/validate-no-state-paths-in-templates.js.map +1 -1
  61. package/src/validate-no-symbol-di-tokens.js +6 -5
  62. package/src/validate-no-symbol-di-tokens.js.map +1 -1
  63. package/src/validate-no-unmanaged-exceptions.js +6 -5
  64. package/src/validate-no-unmanaged-exceptions.js.map +1 -1
  65. package/src/validate-prisma-converters.js +13 -11
  66. package/src/validate-prisma-converters.js.map +1 -1
  67. package/src/validate-return-types.js +10 -10
  68. package/src/validate-return-types.js.map +1 -1
  69. package/src/wp-ci.js +2 -2
  70. package/src/wp-ci.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/code-rules",
3
- "version": "0.4.975",
3
+ "version": "0.4.977",
4
4
  "description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,19 +16,19 @@
16
16
  "directory": "packages/tooling/code-rules"
17
17
  },
18
18
  "dependencies": {
19
- "@webpieces/rules-config": "0.4.975",
19
+ "@webpieces/rules-config": "0.4.977",
20
20
  "@inversifyjs/binding-decorators": "1.1.5",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2",
23
- "@webpieces/tooling-common": "0.4.975",
24
- "@webpieces/repo-workflow-core": "0.4.975",
25
- "@webpieces/rules-sdk": "0.4.975"
23
+ "@webpieces/tooling-common": "0.4.977",
24
+ "@webpieces/repo-workflow-core": "0.4.977",
25
+ "@webpieces/rules-sdk": "0.4.977"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
30
  "devDependencies": {
31
- "@webpieces/tooling-testkit": "0.4.975"
31
+ "@webpieces/tooling-testkit": "0.4.977"
32
32
  },
33
33
  "exports": {
34
34
  ".": "./src/index.js",
@@ -93,15 +93,15 @@ class ApiLibSourceRule extends code_validator_1.CodeValidator {
93
93
  if (mode === undefined || mode === 'OFF')
94
94
  return { success: true };
95
95
  // NX_BASE / NX_HEAD when nx set them, else the merge-base with main.
96
- const range = this.diffScope.resolveBase(workspaceRoot);
96
+ const range = await this.diffScope.resolveBase(workspaceRoot);
97
97
  const base = range.base;
98
98
  if (base === undefined) {
99
99
  console.log(`\n⏭️ Skipping ${this.name} validation (could not detect base branch)\n`);
100
100
  return { success: true };
101
101
  }
102
102
  const found = [];
103
- for (const relFile of this.scanScope.files(workspaceRoot, mode, base, range.head)) {
104
- found.push(...this.judge(workspaceRoot, relFile, mode, base, range.head));
103
+ for (const relFile of await this.scanScope.files(workspaceRoot, mode, base, range.head)) {
104
+ found.push(...await this.judge(workspaceRoot, relFile, mode, base, range.head));
105
105
  }
106
106
  if (found.length === 0)
107
107
  return { success: true };
@@ -109,11 +109,11 @@ class ApiLibSourceRule extends code_validator_1.CodeValidator {
109
109
  throw this.failure(found);
110
110
  }
111
111
  /** The unexempt, in-scope violating sites of one changed file. */
112
- judge(workspaceRoot, relFile, mode, base, head) {
112
+ async judge(workspaceRoot, relFile, mode, base, head) {
113
113
  if (!this.inScope(workspaceRoot, relFile))
114
114
  return [];
115
115
  const changedLines = this.scanScope.isLineScoped(mode)
116
- ? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))
116
+ ? this.diffScope.getChangedLineNumbers(await this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))
117
117
  : undefined;
118
118
  if (changedLines !== undefined && changedLines.size === 0)
119
119
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"api-lib-source-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/api-lib-source-rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAuF;AAKvF,qDAAiE;AAIjE,kCAAkC;AAClC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,uFAAuF;AACvF,MAAa,UAAU;IAGN;IAEA;IACA;IACA;IANb;IACI,kDAAkD;IACzC,IAAY;IACrB,sDAAsD;IAC7C,OAAe,EACf,IAAY,EACZ,IAAY;QAJZ,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AATD,gCASC;AAED,+FAA+F;AAC/F,MAAa,UAAU;IAGN;IACA;IAEA;IALb;IACI,0BAA0B;IACjB,OAAe,EACf,MAAqB;IAC9B,sFAAsF;IAC7E,UAAkB;QAHlB,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAe;QAErB,eAAU,GAAV,UAAU,CAAQ;IAC5B,CAAC;IAEJ,yCAAyC;IACzC,MAAM,CAAC,IAAa;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,6BAA6B,CAA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A2B;QACvC,MAAM,OAAO,GACT,GAAG,KAAK,CAAC,MAAM,eAAe,IAAI,CAAC,UAAU,EAAE,KAAK,IAAI,CAAC,GAAG,EAAE,IAAI;YAClE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAChI,mDAAmD,IAAI,CAAC,IAAI,cAAc,CAAC;QAC/E,OAAO,IAAI,4BAAa,CACpB,IAAI,CAAC,IAAI,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,qBAAM,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAC3G,CAAC;IACN,CAAC;CACJ;AAzGD,4CAyGC","sourcesContent":["/**\n * The shared half of the api-library source rules: the two `role:api-lib` spelling rules (#1023),\n * `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, `no-utility-types-in-api-lib`\n * (#1026), which scopes itself by its configured `paths` globs instead of the role tag, and\n * `required-type-suffix` (#1037), which scopes itself by its configured entries' `paths` globs.\n *\n * Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP\n * generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the\n * changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES\n * judges every site in a changed file, and the whole-scope modes (#1027) judge every site of every\n * file in a touched project (MODIFIED_PROJECTS) or in the repo (RUN_EVERY_TIME) — see ScanScope. This class owns that scoping, the api-lib test, the escape\n * hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which\n * `RuleReporter` renders. A subclass only says what a violating site IS.\n *\n * Parser-only on purpose (no `ts.Program`): each rule reads the syntax as written, which is exactly\n * what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { DiffScope, Option, RuleFailError, hasDisable } from \"@webpieces/rules-config\";\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from \"./configs/api-lib-spelling-configs\";\nimport { NoUtilityTypesInApiLibConfig } from \"./configs/no-utility-types-config\";\nimport { RequiredTypeSuffixConfig } from \"./configs/required-type-suffix-config\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The role these rules judge. */\nconst API_LIB_ROLE = 'api-lib';\n\n/** One violating site: where, what it is, and the edit that replaces it. Data-only. */\nexport class ApiLibSite {\n constructor(\n /** 1-based line of the site's first character. */\n readonly line: number,\n /** The offending source text, trimmed to one line. */\n readonly snippet: string,\n readonly what: string,\n readonly cure: string,\n ) {}\n}\n\n/** One api-library source file, parsed, with the project directory that owns it. Data-only. */\nexport class ApiLibFile {\n constructor(\n /** Workspace-relative. */\n readonly relFile: string,\n readonly source: ts.SourceFile,\n /** Absolute path of the owning project's directory (the one holding project.json). */\n readonly projectDir: string,\n ) {}\n\n /** The 1-based line a node starts on. */\n lineOf(node: ts.Node): number {\n return this.source.getLineAndCharacterOfPosition(node.getStart(this.source)).line + 1;\n }\n\n /** A site at `node`, its text collapsed to one line. */\n site(node: ts.Node, what: string, cure: string): ApiLibSite {\n const text = node.getText(this.source).replace(/\\s+/g, ' ').trim();\n return new ApiLibSite(this.lineOf(node), text, what, cure);\n }\n}\n\n/** A located site, for the failure message. Data-only. */\nclass FoundSite {\n constructor(\n readonly relFile: string,\n readonly site: ApiLibSite,\n ) {}\n}\n\ntype ApiLibConfig =\n | NoInlineImportInApiLibConfig\n | OneEnumSpellingInApiLibConfig\n | NoUtilityTypesInApiLibConfig\n | RequiredTypeSuffixConfig;\n\nexport abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {\n constructor(\n config: C,\n ruleName: string,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly diffScope: DiffScope,\n private readonly scanScope: ScanScope,\n ) {\n super(config, ruleName, ruleName);\n }\n\n /** Every violating site in one api-library file. */\n protected abstract sitesIn(file: ApiLibFile): ApiLibSite[];\n\n /** The one-sentence WHY printed above the sites. */\n protected abstract why(): string;\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode | undefined = this.config.mode;\n if (mode === undefined || mode === 'OFF') return { success: true };\n // NX_BASE / NX_HEAD when nx set them, else the merge-base with main.\n const range = this.diffScope.resolveBase(workspaceRoot);\n const base = range.base;\n if (base === undefined) {\n console.log(`\\n⏭️ Skipping ${this.name} validation (could not detect base branch)\\n`);\n return { success: true };\n }\n const found: FoundSite[] = [];\n for (const relFile of this.scanScope.files(workspaceRoot, mode, base, range.head)) {\n found.push(...this.judge(workspaceRoot, relFile, mode, base, range.head));\n }\n if (found.length === 0) return { success: true };\n this.scanScope.recordSites(this.name, found.map((each: FoundSite) => each.relFile));\n throw this.failure(found);\n }\n\n /** The unexempt, in-scope violating sites of one changed file. */\n private judge(\n workspaceRoot: string,\n relFile: string,\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): FoundSite[] {\n if (!this.inScope(workspaceRoot, relFile)) return [];\n const changedLines = this.scanScope.isLineScoped(mode)\n ? this.diffScope.getChangedLineNumbers(this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))\n : undefined;\n if (changedLines !== undefined && changedLines.size === 0) return [];\n const absFile = path.join(workspaceRoot, relFile);\n const text = fs.readFileSync(absFile, 'utf8');\n const lines = text.split('\\n');\n const source = ts.createSourceFile(absFile, text, ts.ScriptTarget.Latest, true);\n const file = new ApiLibFile(relFile, source, this.projectDirOf(workspaceRoot, relFile));\n return this.sitesIn(file)\n .filter((site: ApiLibSite) => changedLines === undefined || changedLines.has(site.line))\n .filter((site: ApiLibSite) => !this.disabled(lines, site.line))\n .map((site: ApiLibSite) => new FoundSite(relFile, site));\n }\n\n /** A non-test `.ts` file that {@link isApiLibrarySource} claims (`excludePaths` is applied upstream). */\n private inScope(workspaceRoot: string, relFile: string): boolean {\n if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts')) return false;\n if (/\\.(spec|test)\\.ts$/.test(relFile) || relFile.includes('__tests__/')) return false;\n if (!fs.existsSync(path.join(workspaceRoot, relFile))) return false;\n return this.isApiLibrarySource(workspaceRoot, relFile);\n }\n\n /** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */\n protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean {\n return this.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;\n }\n\n /** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */\n protected scopeLabel(): string {\n return 'a role:api-lib project';\n }\n\n /** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */\n private disabled(lines: readonly string[], line: number): boolean {\n return hasDisable(lines[line - 1] ?? '', this.name) || hasDisable(lines[line - 2] ?? '', this.name);\n }\n\n /** The nearest ancestor of `relFile` holding a project.json, absolute. */\n private projectDirOf(workspaceRoot: string, relFile: string): string {\n let dir = path.dirname(path.join(workspaceRoot, relFile));\n while (!fs.existsSync(path.join(dir, 'project.json')) && path.dirname(dir) !== dir) {\n dir = path.dirname(dir);\n }\n return dir;\n }\n\n private failure(found: readonly FoundSite[]): RuleFailError {\n const message =\n `${found.length} site(s) in ${this.scopeLabel()}: ${this.why()}\\n` +\n found.map((each: FoundSite) => ` ${each.relFile}:${each.site.line} — ${each.site.what}\\n ${each.site.snippet}`).join('\\n') +\n `\\n Last resort, per site: // webpieces-disable ${this.name} -- <reason>`;\n return new RuleFailError(\n this.name,\n message,\n undefined,\n undefined,\n found.map((each: FoundSite) => new Option(`${each.relFile}:${each.site.line}: ${each.site.cure}`, true)),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"api-lib-source-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/api-lib-source-rule.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAAuF;AAKvF,qDAAiE;AAIjE,kCAAkC;AAClC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,uFAAuF;AACvF,MAAa,UAAU;IAGN;IAEA;IACA;IACA;IANb;IACI,kDAAkD;IACzC,IAAY;IACrB,sDAAsD;IAC7C,OAAe,EACf,IAAY,EACZ,IAAY;QAJZ,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;CACP;AATD,gCASC;AAED,+FAA+F;AAC/F,MAAa,UAAU;IAGN;IACA;IAEA;IALb;IACI,0BAA0B;IACjB,OAAe,EACf,MAAqB;IAC9B,sFAAsF;IAC7E,UAAkB;QAHlB,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAe;QAErB,eAAU,GAAV,UAAU,CAAQ;IAC5B,CAAC;IAEJ,yCAAyC;IACzC,MAAM,CAAC,IAAa;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;IAC1F,CAAC;IAED,wDAAwD;IACxD,IAAI,CAAC,IAAa,EAAE,IAAY,EAAE,IAAY;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAA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IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAChI,mDAAmD,IAAI,CAAC,IAAI,cAAc,CAAC;QAC/E,OAAO,IAAI,4BAAa,CACpB,IAAI,CAAC,IAAI,EACT,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,CAAC,GAAG,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAI,qBAAM,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAC3G,CAAC;IACN,CAAC;CACJ;AAzGD,4CAyGC","sourcesContent":["/**\n * The shared half of the api-library source rules: the two `role:api-lib` spelling rules (#1023),\n * `no-inline-import-in-api-lib` and `one-enum-spelling-in-api-lib`, `no-utility-types-in-api-lib`\n * (#1026), which scopes itself by its configured `paths` globs instead of the role tag, and\n * `required-type-suffix` (#1037), which scopes itself by its configured entries' `paths` globs.\n *\n * Both judge the SOURCE of an api library — the contract every consumer and the OpenAPI / MCP\n * generator read — and both have the same rollout shape: `mode` NEW_AND_MODIFIED_CODE judges only the\n * changed lines (so existing code is grandfathered until someone touches it), NEW_AND_MODIFIED_FILES\n * judges every site in a changed file, and the whole-scope modes (#1027) judge every site of every\n * file in a touched project (MODIFIED_PROJECTS) or in the repo (RUN_EVERY_TIME) — see ScanScope. This class owns that scoping, the api-lib test, the escape\n * hatches, and the ONE failure spelling: a thrown `RuleFailError` with one `Option` per site, which\n * `RuleReporter` renders. A subclass only says what a violating site IS.\n *\n * Parser-only on purpose (no `ts.Program`): each rule reads the syntax as written, which is exactly\n * what it refuses, and a parse cannot be diverted to a `.d.ts` by module resolution.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { DiffScope, Option, RuleFailError, hasDisable } from \"@webpieces/rules-config\";\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from \"./configs/api-lib-spelling-configs\";\nimport { NoUtilityTypesInApiLibConfig } from \"./configs/no-utility-types-config\";\nimport { RequiredTypeSuffixConfig } from \"./configs/required-type-suffix-config\";\nimport { ModifiedCodeMode } from '@webpieces/rules-sdk';\nimport { CodeValidator, ExecutorResult } from './code-validator';\nimport { ProjectRoleResolver } from './project-role-resolver';\nimport { ScanScope } from './scan-scope';\n\n/** The role these rules judge. */\nconst API_LIB_ROLE = 'api-lib';\n\n/** One violating site: where, what it is, and the edit that replaces it. Data-only. */\nexport class ApiLibSite {\n constructor(\n /** 1-based line of the site's first character. */\n readonly line: number,\n /** The offending source text, trimmed to one line. */\n readonly snippet: string,\n readonly what: string,\n readonly cure: string,\n ) {}\n}\n\n/** One api-library source file, parsed, with the project directory that owns it. Data-only. */\nexport class ApiLibFile {\n constructor(\n /** Workspace-relative. */\n readonly relFile: string,\n readonly source: ts.SourceFile,\n /** Absolute path of the owning project's directory (the one holding project.json). */\n readonly projectDir: string,\n ) {}\n\n /** The 1-based line a node starts on. */\n lineOf(node: ts.Node): number {\n return this.source.getLineAndCharacterOfPosition(node.getStart(this.source)).line + 1;\n }\n\n /** A site at `node`, its text collapsed to one line. */\n site(node: ts.Node, what: string, cure: string): ApiLibSite {\n const text = node.getText(this.source).replace(/\\s+/g, ' ').trim();\n return new ApiLibSite(this.lineOf(node), text, what, cure);\n }\n}\n\n/** A located site, for the failure message. Data-only. */\nclass FoundSite {\n constructor(\n readonly relFile: string,\n readonly site: ApiLibSite,\n ) {}\n}\n\ntype ApiLibConfig =\n | NoInlineImportInApiLibConfig\n | OneEnumSpellingInApiLibConfig\n | NoUtilityTypesInApiLibConfig\n | RequiredTypeSuffixConfig;\n\nexport abstract class ApiLibSourceRule<C extends ApiLibConfig> extends CodeValidator<C> {\n constructor(\n config: C,\n ruleName: string,\n private readonly roleResolver: ProjectRoleResolver,\n private readonly diffScope: DiffScope,\n private readonly scanScope: ScanScope,\n ) {\n super(config, ruleName, ruleName);\n }\n\n /** Every violating site in one api-library file. */\n protected abstract sitesIn(file: ApiLibFile): ApiLibSite[];\n\n /** The one-sentence WHY printed above the sites. */\n protected abstract why(): string;\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n const mode: ModifiedCodeMode | undefined = this.config.mode;\n if (mode === undefined || mode === 'OFF') return { success: true };\n // NX_BASE / NX_HEAD when nx set them, else the merge-base with main.\n const range = await this.diffScope.resolveBase(workspaceRoot);\n const base = range.base;\n if (base === undefined) {\n console.log(`\\n⏭️ Skipping ${this.name} validation (could not detect base branch)\\n`);\n return { success: true };\n }\n const found: FoundSite[] = [];\n for (const relFile of await this.scanScope.files(workspaceRoot, mode, base, range.head)) {\n found.push(...await this.judge(workspaceRoot, relFile, mode, base, range.head));\n }\n if (found.length === 0) return { success: true };\n this.scanScope.recordSites(this.name, found.map((each: FoundSite) => each.relFile));\n throw this.failure(found);\n }\n\n /** The unexempt, in-scope violating sites of one changed file. */\n private async judge(\n workspaceRoot: string,\n relFile: string,\n mode: ModifiedCodeMode,\n base: string,\n head: string | undefined,\n ): Promise<FoundSite[]> {\n if (!this.inScope(workspaceRoot, relFile)) return [];\n const changedLines = this.scanScope.isLineScoped(mode)\n ? this.diffScope.getChangedLineNumbers(await this.diffScope.getFileDiff(workspaceRoot, relFile, base, head))\n : undefined;\n if (changedLines !== undefined && changedLines.size === 0) return [];\n const absFile = path.join(workspaceRoot, relFile);\n const text = fs.readFileSync(absFile, 'utf8');\n const lines = text.split('\\n');\n const source = ts.createSourceFile(absFile, text, ts.ScriptTarget.Latest, true);\n const file = new ApiLibFile(relFile, source, this.projectDirOf(workspaceRoot, relFile));\n return this.sitesIn(file)\n .filter((site: ApiLibSite) => changedLines === undefined || changedLines.has(site.line))\n .filter((site: ApiLibSite) => !this.disabled(lines, site.line))\n .map((site: ApiLibSite) => new FoundSite(relFile, site));\n }\n\n /** A non-test `.ts` file that {@link isApiLibrarySource} claims (`excludePaths` is applied upstream). */\n private inScope(workspaceRoot: string, relFile: string): boolean {\n if (!relFile.endsWith('.ts') || relFile.endsWith('.d.ts')) return false;\n if (/\\.(spec|test)\\.ts$/.test(relFile) || relFile.includes('__tests__/')) return false;\n if (!fs.existsSync(path.join(workspaceRoot, relFile))) return false;\n return this.isApiLibrarySource(workspaceRoot, relFile);\n }\n\n /** Is `relFile` part of an api library? By default: its owning project is tagged `role:api-lib`. */\n protected isApiLibrarySource(workspaceRoot: string, relFile: string): boolean {\n return this.roleResolver.roleOf(workspaceRoot, relFile) === API_LIB_ROLE;\n }\n\n /** How the failure names where the sites are — must agree with {@link isApiLibrarySource}. */\n protected scopeLabel(): string {\n return 'a role:api-lib project';\n }\n\n /** `// webpieces-disable <rule> -- <reason>` on the site's line or the line above. */\n private disabled(lines: readonly string[], line: number): boolean {\n return hasDisable(lines[line - 1] ?? '', this.name) || hasDisable(lines[line - 2] ?? '', this.name);\n }\n\n /** The nearest ancestor of `relFile` holding a project.json, absolute. */\n private projectDirOf(workspaceRoot: string, relFile: string): string {\n let dir = path.dirname(path.join(workspaceRoot, relFile));\n while (!fs.existsSync(path.join(dir, 'project.json')) && path.dirname(dir) !== dir) {\n dir = path.dirname(dir);\n }\n return dir;\n }\n\n private failure(found: readonly FoundSite[]): RuleFailError {\n const message =\n `${found.length} site(s) in ${this.scopeLabel()}: ${this.why()}\\n` +\n found.map((each: FoundSite) => ` ${each.relFile}:${each.site.line} — ${each.site.what}\\n ${each.site.snippet}`).join('\\n') +\n `\\n Last resort, per site: // webpieces-disable ${this.name} -- <reason>`;\n return new RuleFailError(\n this.name,\n message,\n undefined,\n undefined,\n found.map((each: FoundSite) => new Option(`${each.relFile}:${each.site.line}: ${each.site.cure}`, true)),\n );\n }\n}\n"]}
@@ -16,6 +16,8 @@ class CodeRuleRuntime {
16
16
  }
17
17
  async compose(request, projects) {
18
18
  const container = new inversify_1.Container({ autobind: true });
19
+ // The process edges (git, every other program, the clock): DiffScope reaches git through them (#1381).
20
+ new tooling_common_1.ProcessBindings().bind(container);
19
21
  container.bind(code_rules_context_1.WorkspaceRoot).toConstantValue(new code_rules_context_1.WorkspaceRoot(request.workspaceRoot));
20
22
  container.bind(scan_scope_1.ScanRestriction).toConstantValue(new scan_scope_1.ScanRestriction(projects));
21
23
  const global = new rule_dispatch_1.GlobalExcludePaths(request.excludePaths);
@@ -1 +1 @@
1
- {"version":3,"file":"code-policy-composition.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-policy-composition.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,yCAAsC;AAUtC,8DAA0D;AAC1D,iEAAmE;AACnE,6DAAqD;AACrD,6CAA+C;AAC/C,2DAAqD;AACrD,mDAAmG;AAEnG,2FAA2F;AAC3F,MAAa,eAAe;IACxB,KAAK,CAAC,MAAM,CAAC,OAA6B;QACtC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,kCAAc,CAAC,CAAC,QAAQ,CAAC;IACjF,CAAC;IAED,KAAK,CAAC,OAAO,CACT,OAA6B,EAC7B,QAAuC;QAEvC,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,SAAS,CAAC,IAAI,CAAC,kCAAa,CAAC,CAAC,eAAe,CAAC,IAAI,kCAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QACxF,SAAS,CAAC,IAAI,CAAC,4BAAe,CAAC,CAAC,eAAe,CAAC,IAAI,4BAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,IAAI,kCAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5D,SAAS,CAAC,IAAI,CAAC,kCAAkB,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3D,MAA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M,KAAK,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,KAAK;YACN,MAAM,IAAI,8BAAa,CACnB,yCAAyC,EAAE,oCAAoC,CAClF,CAAC;QACN,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA5CD,0CA4CC","sourcesContent":["import 'reflect-metadata';\nimport { Container } from 'inversify';\nimport {\n BaseRuleConfig,\n BuildPolicy,\n BuildRuleRuntime,\n PolicyRuntimeRequest,\n BuildDebugRequest,\n BuildDebugRuntime,\n BuildPolicyResult,\n} from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { WorkspaceRoot } from './code-rules-context';\nimport { ScanRestriction } from './scan-scope';\nimport { BuildPolicySet } from './code-rules-engine';\nimport { ExclusionScopedPolicy, GlobalExcludePaths, RuleExclusionsFactory } from './rule-dispatch';\n\n/** Composition stays with the code owner; the public manifest never imports validators. */\nexport class CodeRuleRuntime implements BuildRuleRuntime {\n async create(request: PolicyRuntimeRequest): Promise<readonly BuildPolicy[]> {\n return (await this.compose(request, undefined)).get(BuildPolicySet).policies;\n }\n\n async compose(\n request: PolicyRuntimeRequest,\n projects: readonly string[] | undefined,\n ): Promise<Container> {\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(request.workspaceRoot));\n container.bind(ScanRestriction).toConstantValue(new ScanRestriction(projects));\n const global = new GlobalExcludePaths(request.excludePaths);\n container.bind(GlobalExcludePaths).toConstantValue(global);\n const policies = request.ruleIds.map((id: string) => this.entry(id));\n for (const policy of policies) {\n const config = request.configs[policy.ruleId];\n if (!config)\n throw new InformAiError(\n `Missing explicit config for ${policy.ruleId}. Repair its declared owner file.`,\n );\n container.bind(policy.configClass).toConstantValue(config);\n }\n // Every validator runs inside its framework-owned path exclusions (#1253) — see ExclusionScopedPolicy.\n const exclusions = new RuleExclusionsFactory();\n const checks = await Promise.all(\n policies.map(async (policy: CodePolicy) => {\n const check = container.get(await policy.loadValidator());\n const config = request.configs[policy.ruleId] as BaseRuleConfig;\n return new ExclusionScopedPolicy(check, exclusions.forRule(check.name, global, config));\n }),\n );\n container.bind(BuildPolicySet).toConstantValue(new BuildPolicySet(checks));\n return container;\n }\n\n private entry(id: string): CodePolicy {\n const entry = CODE_POLICIES.find((policy: CodePolicy) => policy.ruleId === id);\n if (!entry)\n throw new InformAiError(\n `Code runtime has no implementation of ${id}. Repair the owner's contribution.`,\n );\n return entry;\n }\n}\n\n"]}
1
+ {"version":3,"file":"code-policy-composition.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-policy-composition.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,yCAAsC;AAUtC,8DAA2E;AAC3E,iEAAmE;AACnE,6DAAqD;AACrD,6CAA+C;AAC/C,2DAAqD;AACrD,mDAAmG;AAEnG,2FAA2F;AAC3F,MAAa,eAAe;IACxB,KAAK,CAAC,MAAM,CAAC,OAA6B;QACtC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,kCAAc,CAAC,CAAC,QAAQ,CAAC;IACjF,CAAC;IAED,KAAK,CAAC,OAAO,CACT,OAA6B,EAC7B,QAAuC;QAEvC,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,uGAAuG;QACvG,IAAI,gCAAe,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,SAAS,CAAC,IAAI,CAAC,kCAAa,CAAC,CAAC,eAAe,CAAC,IAAI,kCAAa,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QACxF,SAAS,CAAC,IAAI,CAAC,4BAAe,CAAC,CAAC,eAAe,CAAC,IAAI,4BAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,IAAI,kCAAk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ACrB,CAAC;IAEO,KAAK,CAAC,EAAU;QACpB,MAAM,KAAK,GAAG,oCAAa,CAAC,IAAI,CAAC,CAAC,MAAkB,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,KAAK;YACN,MAAM,IAAI,8BAAa,CACnB,yCAAyC,EAAE,oCAAoC,CAClF,CAAC;QACN,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA9CD,0CA8CC","sourcesContent":["import 'reflect-metadata';\nimport { Container } from 'inversify';\nimport {\n BaseRuleConfig,\n BuildPolicy,\n BuildRuleRuntime,\n PolicyRuntimeRequest,\n BuildDebugRequest,\n BuildDebugRuntime,\n BuildPolicyResult,\n} from '@webpieces/rules-sdk';\nimport { InformAiError, ProcessBindings } from '@webpieces/tooling-common';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { WorkspaceRoot } from './code-rules-context';\nimport { ScanRestriction } from './scan-scope';\nimport { BuildPolicySet } from './code-rules-engine';\nimport { ExclusionScopedPolicy, GlobalExcludePaths, RuleExclusionsFactory } from './rule-dispatch';\n\n/** Composition stays with the code owner; the public manifest never imports validators. */\nexport class CodeRuleRuntime implements BuildRuleRuntime {\n async create(request: PolicyRuntimeRequest): Promise<readonly BuildPolicy[]> {\n return (await this.compose(request, undefined)).get(BuildPolicySet).policies;\n }\n\n async compose(\n request: PolicyRuntimeRequest,\n projects: readonly string[] | undefined,\n ): Promise<Container> {\n const container = new Container({ autobind: true });\n // The process edges (git, every other program, the clock): DiffScope reaches git through them (#1381).\n new ProcessBindings().bind(container);\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(request.workspaceRoot));\n container.bind(ScanRestriction).toConstantValue(new ScanRestriction(projects));\n const global = new GlobalExcludePaths(request.excludePaths);\n container.bind(GlobalExcludePaths).toConstantValue(global);\n const policies = request.ruleIds.map((id: string) => this.entry(id));\n for (const policy of policies) {\n const config = request.configs[policy.ruleId];\n if (!config)\n throw new InformAiError(\n `Missing explicit config for ${policy.ruleId}. Repair its declared owner file.`,\n );\n container.bind(policy.configClass).toConstantValue(config);\n }\n // Every validator runs inside its framework-owned path exclusions (#1253) — see ExclusionScopedPolicy.\n const exclusions = new RuleExclusionsFactory();\n const checks = await Promise.all(\n policies.map(async (policy: CodePolicy) => {\n const check = container.get(await policy.loadValidator());\n const config = request.configs[policy.ruleId] as BaseRuleConfig;\n return new ExclusionScopedPolicy(check, exclusions.forRule(check.name, global, config));\n }),\n );\n container.bind(BuildPolicySet).toConstantValue(new BuildPolicySet(checks));\n return container;\n }\n\n private entry(id: string): CodePolicy {\n const entry = CODE_POLICIES.find((policy: CodePolicy) => policy.ruleId === id);\n if (!entry)\n throw new InformAiError(\n `Code runtime has no implementation of ${id}. Repair the owner's contribution.`,\n );\n return entry;\n }\n}\n\n"]}
@@ -46,7 +46,7 @@ class CodeRulesBootstrap {
46
46
  : this.packProvider(request.rule, loaded);
47
47
  if (provider !== undefined)
48
48
  return this.runPackDebug(workspaceRoot, loaded, provider, request);
49
- const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;
49
+ const plan = request.isDebug() ? await this.plan(workspaceRoot, loaded, request) : undefined;
50
50
  if (plan !== undefined)
51
51
  this.debug.printBanner(plan);
52
52
  const configs = {};
@@ -65,11 +65,11 @@ class CodeRulesBootstrap {
65
65
  return result;
66
66
  // A debug run FAILS whenever a site exists — including a rule that only warns at the gate
67
67
  // (no-client-creation-outside-server-or-client at severity "warn") — so it can gate a loop.
68
- const sites = this.debug.printCounts(workspaceRoot, plan, container.get(scan_scope_1.ScanScope), result.success);
68
+ const sites = await this.debug.printCounts(workspaceRoot, plan, container.get(scan_scope_1.ScanScope), result.success);
69
69
  return { success: result.success && sites === 0 };
70
70
  }
71
71
  /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */
72
- plan(workspaceRoot, loaded, request) {
72
+ async plan(workspaceRoot, loaded, request) {
73
73
  const rule = request.rule;
74
74
  if (rule === undefined)
75
75
  throw this.debug.refusal('--mode and --projects need --rule=<name>: a debug run judges exactly one rule.');
@@ -1 +1 @@
1
- {"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,oDAM8B;AAC9B,4BAA0B;AAC1B,uEAA4D;AAC5D,0DAOiC;AACjC,oDAA2D;AAC3D,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAwD;AACxD,iEAAmE;AACnE,qEAA8E;AAC9E,6CAAyC;AACzC,qDAAqE;AACrE,2CAA+C;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,kBAAkB;IACV,KAAK,GAAG,IAAI,6BAAY,EAAE,CAAC;IAE5C,KAAK,CAAC,GAAG,CAAC,aAAqB,EAAE,OAA4B;QACzD,MAAM,MAAM,GAAG,IAAA,8BAAe,EAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,8BAAa,CACnB,qEAAqE,CACxE,CAAC;QACN,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAExD,MAAM,QAAQ,GACV,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;YAC9D,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE/F,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,E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MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;aACrC,OAAO,CAAC,CAAC,KAA+B,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;aAChE,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC;QAC7E,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IAC9B,CAAC;IAEO,eAAe,CAAC,IAAY,EAAE,MAAoB;QACtD,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAmB,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAChF,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC;QAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,IAAuC,CAE9D,CAAC;QAChB,OAAO,UAAU,EAAE,IAAI,CAAC;IAC5B,CAAC;IAED,iFAAiF;IACzE,UAAU,CAAC,MAAoB,EAAE,IAA2B;QAChE,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAmB,EAAE,EAAE,CACjD,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAChE,CAAC;IACN,CAAC;CACJ;AAhKD,gDAgKC","sourcesContent":["import {\n BaseRuleConfig,\n BuildDebugRequest,\n ConfigObject,\n PolicyDebugSelection,\n PolicyRuntimeRequest,\n} from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { CodeRuleRuntime } from './code-policy-composition';\nimport {\n LoadedConfig,\n MatchRuleConfig,\n NodeRuleRuntimeModuleLoader,\n RuleRuntimeModules,\n RuntimeContributionGroup,\n loadAndValidate,\n} from '@webpieces/rules-config';\nimport { MODIFIED_CODE_MODES } from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ExecutorResult } from './code-validator';\nimport { CodeRulesApp } from './code-rules-app';\nimport { MatchRulesHolder } from './code-rules-context';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ScanScope } from './scan-scope';\nimport { DebugAsk, DebugPlan, RuleDebugRun } from './rule-debug-run';\nimport { rulePackManifest } from './rule-pack';\n\n/**\n * The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the\n * `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,\n * then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.\n *\n * A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four\n * ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two\n * escape hatches are cleared (the question asked is \"what is left?\", which a time-boxed OFF must not\n * hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing\n * is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It\n * prints the rule's own failure text, then one count per project, and fails when any site exists.\n *\n * A rule another rule pack contributes to the build — a repo-local rule (#1330) — is not run here: the\n * debug request is handed to that pack's own `buildDebugRuntime`, which shares {@link RuleDebugRun} so\n * its refusals, banner and counts are identical.\n *\n * A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an\n * {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.\n */\nexport class CodeRulesBootstrap {\n private readonly debug = new RuleDebugRun();\n\n async run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult> {\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n throw new InformAiError(\n 'No webpieces.config.json found at workspace root (or any ancestor).',\n );\n }\n console.log(`\\n📄 Loaded config: ${loaded.configPath}`);\n\n const provider =\n request.rule === undefined || this.isOwnRule(request.rule, loaded)\n ? undefined\n : this.packProvider(request.rule, loaded);\n if (provider !== undefined) return this.runPackDebug(workspaceRoot, loaded, provider, request);\n\n const plan = request.isDebug() ? this.plan(workspaceRoot, loaded, request) : undefined;\n if (plan !== undefined) this.debug.printBanner(plan);\n\n const configs: Record<string, ConfigObject> = {};\n for (const policy of CODE_POLICIES) {\n const config = loaded.rulesConfig[policy.ruleId] as BaseRuleConfig;\n configs[policy.ruleId] = (\n plan?.rule === policy.ruleId ? this.debug.overridden(config, plan) : config\n ) as ConfigObject;\n }\n const runtimeRequest = new PolicyRuntimeRequest(\n workspaceRoot,\n configs,\n CODE_POLICIES.map((policy: CodePolicy) => policy.ruleId),\n loaded.excludePaths.paths,\n );\n const container = await new CodeRuleRuntime().compose(runtimeRequest, plan?.projects);\n container\n .bind(MatchRulesHolder)\n .toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n\n const result = await container.get(CodeRulesApp).run();\n if (plan === undefined) return result;\n // A debug run FAILS whenever a site exists — including a rule that only warns at the gate\n // (no-client-creation-outside-server-or-client at severity \"warn\") — so it can gate a loop.\n const sites = this.debug.printCounts(workspaceRoot, plan, container.get(ScanScope), result.success);\n return { success: result.success && sites === 0 };\n }\n\n /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */\n private plan(\n workspaceRoot: string,\n loaded: LoadedConfig,\n request: CodeRulesRunRequest,\n ): DebugPlan {\n const rule = request.rule;\n if (rule === undefined)\n throw this.debug.refusal(\n '--mode and --projects need --rule=<name>: a debug run judges exactly one rule.',\n );\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.debug.refusal(\n `--rule=${rule} is not a rule that supports a debug run. Rules that do (they offer ` +\n `MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`,\n );\n }\n return this.debug.plan(\n workspaceRoot,\n new DebugAsk(rule, request.mode, this.committedModeOf(rule, loaded) ?? 'OFF', modes, request.projects),\n );\n }\n\n /** True for a rule THIS pack runs: a built-in code rule or a match-rule. */\n private isOwnRule(rule: string, loaded: LoadedConfig): boolean {\n return (\n CODE_POLICIES.some((binding: CodePolicy) => binding.ruleId === rule) ||\n loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule)\n );\n }\n\n /**\n * The build contribution of ANOTHER rule pack (a repo-local pack, #1330) that runs `rule`, when the\n * rule's modes support a debug run; undefined otherwise.\n */\n private packProvider(rule: string, loaded: LoadedConfig): RuntimeContributionGroup | undefined {\n return this.packBuildGroups(loaded).find(\n (group: RuntimeContributionGroup) =>\n group.ruleIds.includes(rule) && this.debug.supports(this.schemaModesOf(rule, loaded)),\n );\n }\n\n private packBuildGroups(loaded: LoadedConfig): readonly RuntimeContributionGroup[] {\n return new RuleRuntimeModules()\n .groups(loaded.ruleRegistry, 'build')\n .filter((group: RuntimeContributionGroup) => group.providerPack !== rulePackManifest.packageName);\n }\n\n private schemaModesOf(rule: string, loaded: LoadedConfig): readonly string[] {\n return loaded.ruleRegistry.schemaFor(rule)['mode']?.enumValues ?? [];\n }\n\n /** Hand the debug request to the pack that owns the rule; it refuses, prints and counts as this runner does. */\n private async runPackDebug(\n workspaceRoot: string,\n loaded: LoadedConfig,\n group: RuntimeContributionGroup,\n request: CodeRulesRunRequest,\n ): Promise<ExecutorResult> {\n const modules = new RuleRuntimeModules();\n const exports = modules.load(\n group,\n loaded.ruleRegistry.manifestModules,\n new NodeRuleRuntimeModuleLoader(workspaceRoot),\n );\n const result = await modules.runBuildDebug(\n exports,\n new BuildDebugRequest(\n workspaceRoot,\n new PolicyDebugSelection(request.rule!, request.mode, request.projects),\n ),\n );\n return { success: result.success };\n }\n\n /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */\n private wholeScopeModesOf(rule: string, loaded: LoadedConfig): readonly string[] | undefined {\n if (loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule))\n return MODIFIED_CODE_MODES;\n const binding = CODE_POLICIES.find((each: CodePolicy) => each.ruleId === rule);\n if (binding === undefined) return undefined;\n const modes = binding.schema['mode']?.enumValues ?? [];\n return this.debug.supports(modes) ? modes : undefined;\n }\n\n /** Every rule a debug run accepts: built-in code rules, match-rules, and other packs' rules (#1330). */\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CODE_POLICIES.map((binding: CodePolicy) => binding.ruleId as string);\n const names = [...builtIns, ...loaded.matchRules.map((mr: MatchRuleConfig) => mr.name)];\n const own = names.filter((name: string) => this.wholeScopeModesOf(name, loaded) !== undefined);\n const packs = this.packBuildGroups(loaded)\n .flatMap((group: RuntimeContributionGroup) => [...group.ruleIds])\n .filter((name: string) => this.packProvider(name, loaded) !== undefined);\n return [...own, ...packs];\n }\n\n private committedModeOf(rule: string, loaded: LoadedConfig): string | undefined {\n const match = loaded.matchRules.find((mr: MatchRuleConfig) => mr.name === rule);\n if (match !== undefined) return match.mode;\n const configured = loaded.rulesConfig[rule as keyof typeof loaded.rulesConfig] as\n | BaseRuleConfig\n | undefined;\n return configured?.mode;\n }\n\n /** The match-rules, with the debugged one (if it is a match rule) overridden. */\n private matchRules(loaded: LoadedConfig, plan: DebugPlan | undefined): MatchRuleConfig[] {\n return loaded.matchRules.map((mr: MatchRuleConfig) =>\n plan?.rule === mr.name ? this.debug.overridden(mr, plan) : mr,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"code-rules-bootstrap.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/code-rules-bootstrap.ts"],"names":[],"mappings":";;;AAAA,oDAM8B;AAC9B,4BAA0B;AAC1B,uEAA4D;AAC5D,0DAOiC;AACjC,oDAA2D;AAC3D,8DAA0D;AAG1D,qDAAgD;AAChD,6DAAwD;AACxD,iEAAmE;AACnE,qEAA8E;AAC9E,6CAAyC;AACzC,qDAAqE;AACrE,2CAA+C;AAE/C;;;;;;;;;;;;;;;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QACtD,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAmB,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAChF,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,IAAI,CAAC;QAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,IAAuC,CAE9D,CAAC;QAChB,OAAO,UAAU,EAAE,IAAI,CAAC;IAC5B,CAAC;IAED,iFAAiF;IACzE,UAAU,CAAC,MAAoB,EAAE,IAA2B;QAChE,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAmB,EAAE,EAAE,CACjD,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAChE,CAAC;IACN,CAAC;CACJ;AAhKD,gDAgKC","sourcesContent":["import {\n BaseRuleConfig,\n BuildDebugRequest,\n ConfigObject,\n PolicyDebugSelection,\n PolicyRuntimeRequest,\n} from '@webpieces/rules-sdk';\nimport 'reflect-metadata';\nimport { CodeRuleRuntime } from './code-policy-composition';\nimport {\n LoadedConfig,\n MatchRuleConfig,\n NodeRuleRuntimeModuleLoader,\n RuleRuntimeModules,\n RuntimeContributionGroup,\n loadAndValidate,\n} from '@webpieces/rules-config';\nimport { MODIFIED_CODE_MODES } from '@webpieces/rules-sdk';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ExecutorResult } from './code-validator';\nimport { CodeRulesApp } from './code-rules-app';\nimport { MatchRulesHolder } from './code-rules-context';\nimport { CODE_POLICIES, CodePolicy } from './code-policy-registry';\nimport { CodeRulesRunRequest, RuleSelection } from './code-rules-run-request';\nimport { ScanScope } from './scan-scope';\nimport { DebugAsk, DebugPlan, RuleDebugRun } from './rule-debug-run';\nimport { rulePackManifest } from './rule-pack';\n\n/**\n * The ONE composition root of a code-rules run, shared by the `validate-code` nx executor and the\n * `wp-validate-code` bin so the two cannot drift. It binds the workspace root and every rule's config,\n * then resolves {@link CodeRulesApp} so inversify builds the whole validator DAG.\n *\n * A DEBUG run (#1027 — any of `--rule` / `--mode` / `--projects`) differs from the gate in exactly four\n * ways, all in memory: only the named rule runs; its mode is replaced when `--mode` is given; its two\n * escape hatches are cleared (the question asked is \"what is left?\", which a time-boxed OFF must not\n * hide); and every rule reads its files through a {@link ScanRestriction} naming the projects. Nothing\n * is written — webpieces.config.json is untouched, so the gate keeps honouring the committed mode. It\n * prints the rule's own failure text, then one count per project, and fails when any site exists.\n *\n * A rule another rule pack contributes to the build — a repo-local rule (#1330) — is not run here: the\n * debug request is handed to that pack's own `buildDebugRuntime`, which shares {@link RuleDebugRun} so\n * its refusals, banner and counts are identical.\n *\n * A request it cannot run (no config, an unknown rule or project, --mode without --rule) THROWS an\n * {@link InformAiError} naming the cure; the bin's and the executor's top-level handlers print it.\n */\nexport class CodeRulesBootstrap {\n private readonly debug = new RuleDebugRun();\n\n async run(workspaceRoot: string, request: CodeRulesRunRequest): Promise<ExecutorResult> {\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n throw new InformAiError(\n 'No webpieces.config.json found at workspace root (or any ancestor).',\n );\n }\n console.log(`\\n📄 Loaded config: ${loaded.configPath}`);\n\n const provider =\n request.rule === undefined || this.isOwnRule(request.rule, loaded)\n ? undefined\n : this.packProvider(request.rule, loaded);\n if (provider !== undefined) return this.runPackDebug(workspaceRoot, loaded, provider, request);\n\n const plan = request.isDebug() ? await this.plan(workspaceRoot, loaded, request) : undefined;\n if (plan !== undefined) this.debug.printBanner(plan);\n\n const configs: Record<string, ConfigObject> = {};\n for (const policy of CODE_POLICIES) {\n const config = loaded.rulesConfig[policy.ruleId] as BaseRuleConfig;\n configs[policy.ruleId] = (\n plan?.rule === policy.ruleId ? this.debug.overridden(config, plan) : config\n ) as ConfigObject;\n }\n const runtimeRequest = new PolicyRuntimeRequest(\n workspaceRoot,\n configs,\n CODE_POLICIES.map((policy: CodePolicy) => policy.ruleId),\n loaded.excludePaths.paths,\n );\n const container = await new CodeRuleRuntime().compose(runtimeRequest, plan?.projects);\n container\n .bind(MatchRulesHolder)\n .toConstantValue(new MatchRulesHolder(this.matchRules(loaded, plan)));\n container.bind(RuleSelection).toConstantValue(new RuleSelection(plan?.rule));\n\n const result = await container.get(CodeRulesApp).run();\n if (plan === undefined) return result;\n // A debug run FAILS whenever a site exists — including a rule that only warns at the gate\n // (no-client-creation-outside-server-or-client at severity \"warn\") — so it can gate a loop.\n const sites = await this.debug.printCounts(workspaceRoot, plan, container.get(ScanScope), result.success);\n return { success: result.success && sites === 0 };\n }\n\n /** Validate a debug request against the loaded config and the repo's projects; throws on a refusal. */\n private async plan(\n workspaceRoot: string,\n loaded: LoadedConfig,\n request: CodeRulesRunRequest,\n ): Promise<DebugPlan> {\n const rule = request.rule;\n if (rule === undefined)\n throw this.debug.refusal(\n '--mode and --projects need --rule=<name>: a debug run judges exactly one rule.',\n );\n const modes = this.wholeScopeModesOf(rule, loaded);\n if (modes === undefined) {\n throw this.debug.refusal(\n `--rule=${rule} is not a rule that supports a debug run. Rules that do (they offer ` +\n `MODIFIED_PROJECTS and RUN_EVERY_TIME): ${this.debuggableRules(loaded).join(', ')}.`,\n );\n }\n return this.debug.plan(\n workspaceRoot,\n new DebugAsk(rule, request.mode, this.committedModeOf(rule, loaded) ?? 'OFF', modes, request.projects),\n );\n }\n\n /** True for a rule THIS pack runs: a built-in code rule or a match-rule. */\n private isOwnRule(rule: string, loaded: LoadedConfig): boolean {\n return (\n CODE_POLICIES.some((binding: CodePolicy) => binding.ruleId === rule) ||\n loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule)\n );\n }\n\n /**\n * The build contribution of ANOTHER rule pack (a repo-local pack, #1330) that runs `rule`, when the\n * rule's modes support a debug run; undefined otherwise.\n */\n private packProvider(rule: string, loaded: LoadedConfig): RuntimeContributionGroup | undefined {\n return this.packBuildGroups(loaded).find(\n (group: RuntimeContributionGroup) =>\n group.ruleIds.includes(rule) && this.debug.supports(this.schemaModesOf(rule, loaded)),\n );\n }\n\n private packBuildGroups(loaded: LoadedConfig): readonly RuntimeContributionGroup[] {\n return new RuleRuntimeModules()\n .groups(loaded.ruleRegistry, 'build')\n .filter((group: RuntimeContributionGroup) => group.providerPack !== rulePackManifest.packageName);\n }\n\n private schemaModesOf(rule: string, loaded: LoadedConfig): readonly string[] {\n return loaded.ruleRegistry.schemaFor(rule)['mode']?.enumValues ?? [];\n }\n\n /** Hand the debug request to the pack that owns the rule; it refuses, prints and counts as this runner does. */\n private async runPackDebug(\n workspaceRoot: string,\n loaded: LoadedConfig,\n group: RuntimeContributionGroup,\n request: CodeRulesRunRequest,\n ): Promise<ExecutorResult> {\n const modules = new RuleRuntimeModules();\n const exports = modules.load(\n group,\n loaded.ruleRegistry.manifestModules,\n new NodeRuleRuntimeModuleLoader(workspaceRoot),\n );\n const result = await modules.runBuildDebug(\n exports,\n new BuildDebugRequest(\n workspaceRoot,\n new PolicyDebugSelection(request.rule!, request.mode, request.projects),\n ),\n );\n return { success: result.success };\n }\n\n /** The mode set of a rule that reads its files through ScanScope, or undefined for any other rule. */\n private wholeScopeModesOf(rule: string, loaded: LoadedConfig): readonly string[] | undefined {\n if (loaded.matchRules.some((mr: MatchRuleConfig) => mr.name === rule))\n return MODIFIED_CODE_MODES;\n const binding = CODE_POLICIES.find((each: CodePolicy) => each.ruleId === rule);\n if (binding === undefined) return undefined;\n const modes = binding.schema['mode']?.enumValues ?? [];\n return this.debug.supports(modes) ? modes : undefined;\n }\n\n /** Every rule a debug run accepts: built-in code rules, match-rules, and other packs' rules (#1330). */\n private debuggableRules(loaded: LoadedConfig): string[] {\n const builtIns = CODE_POLICIES.map((binding: CodePolicy) => binding.ruleId as string);\n const names = [...builtIns, ...loaded.matchRules.map((mr: MatchRuleConfig) => mr.name)];\n const own = names.filter((name: string) => this.wholeScopeModesOf(name, loaded) !== undefined);\n const packs = this.packBuildGroups(loaded)\n .flatMap((group: RuntimeContributionGroup) => [...group.ruleIds])\n .filter((name: string) => this.packProvider(name, loaded) !== undefined);\n return [...own, ...packs];\n }\n\n private committedModeOf(rule: string, loaded: LoadedConfig): string | undefined {\n const match = loaded.matchRules.find((mr: MatchRuleConfig) => mr.name === rule);\n if (match !== undefined) return match.mode;\n const configured = loaded.rulesConfig[rule as keyof typeof loaded.rulesConfig] as\n | BaseRuleConfig\n | undefined;\n return configured?.mode;\n }\n\n /** The match-rules, with the debugged one (if it is a match rule) overridden. */\n private matchRules(loaded: LoadedConfig, plan: DebugPlan | undefined): MatchRuleConfig[] {\n return loaded.matchRules.map((mr: MatchRuleConfig) =>\n plan?.rule === mr.name ? this.debug.overridden(mr, plan) : mr,\n );\n }\n}\n"]}
@@ -30,7 +30,7 @@ export declare class ProjectScanTargets {
30
30
  private readonly restriction;
31
31
  constructor(diffScope: DiffScope, catalog: ProjectCatalog, restriction: ScanRestriction);
32
32
  /** The projects `mode` judges, root project excluded. `mode` must not be OFF. */
33
- projects(workspaceRoot: string, mode: ProjectScanMode, ruleName: string): ScannedProject[];
33
+ projects(workspaceRoot: string, mode: ProjectScanMode, ruleName: string): Promise<ScannedProject[]>;
34
34
  private touched;
35
35
  /** The `framework:` values of a project.json. Unreadable JSON is the plumbing error it is. */
36
36
  private frameworksOf;
@@ -46,24 +46,24 @@ let ProjectScanTargets = class ProjectScanTargets {
46
46
  this.restriction = restriction;
47
47
  }
48
48
  /** The projects `mode` judges, root project excluded. `mode` must not be OFF. */
49
- projects(workspaceRoot, mode, ruleName) {
50
- const all = this.catalog.all(workspaceRoot).filter((p) => p.dir !== '');
51
- const chosen = mode === 'RUN_EVERY_TIME' ? all : this.touched(workspaceRoot, all, ruleName);
49
+ async projects(workspaceRoot, mode, ruleName) {
50
+ const all = (await this.catalog.all(workspaceRoot)).filter((p) => p.dir !== '');
51
+ const chosen = mode === 'RUN_EVERY_TIME' ? all : await this.touched(workspaceRoot, all, ruleName);
52
52
  const names = this.restriction.projectNames;
53
53
  const restricted = names === undefined ? chosen : chosen.filter((p) => names.includes(p.name));
54
54
  return restricted
55
55
  .map((p) => new ScannedProject(p.name, p.dir, this.frameworksOf(workspaceRoot, p.dir)))
56
56
  .sort((a, b) => a.dir.localeCompare(b.dir));
57
57
  }
58
- touched(workspaceRoot, all, ruleName) {
59
- const range = this.diffScope.resolveBase(workspaceRoot);
58
+ async touched(workspaceRoot, all, ruleName) {
59
+ const range = await this.diffScope.resolveBase(workspaceRoot);
60
60
  if (range.base === undefined) {
61
61
  throw new tooling_common_1.InformAiError(`${ruleName} could not determine the comparison base for MODIFIED_PROJECTS. Set NX_BASE to the ` +
62
62
  'base branch or commit and retry.');
63
63
  }
64
64
  const dirs = new Set();
65
- for (const file of this.diffScope.getChangedFiles(workspaceRoot, range.base, range.head, { tsOnly: false })) {
66
- const owner = this.catalog.ownerOf(workspaceRoot, file);
65
+ for (const file of await this.diffScope.getChangedFiles(workspaceRoot, range.base, range.head, { tsOnly: false })) {
66
+ const owner = await this.catalog.ownerOf(workspaceRoot, file);
67
67
  if (owner !== undefined)
68
68
  dirs.add(owner.dir);
69
69
  }
@@ -1 +1 @@
1
- {"version":3,"file":"project-scan-targets.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/project-scan-targets.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAoD;AAEpD,8DAA0D;AAC1D,iEAA6D;AAC7D,yCAA2D;AAC3D,6CAA6E;AAE7E,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAK1C,iEAAiE;AACjE,MAAa,cAAc;IAEV;IAEA;IAEA;IALb,YACa,IAAY;IACrB,uDAAuD;IAC9C,GAAW;IACpB,6FAA6F;IACpF,UAA6B;QAJ7B,SAAI,GAAJ,IAAI,CAAQ;QAEZ,QAAG,GAAH,GAAG,C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M,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,MAAM,MAAM,GAAG,IAAI;iBACd,MAAM,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;iBACxF,GAAG,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;iBACnE,MAAM,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACjD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,IAAI,8BAAa,CAAC,mCAAmC,IAAI,gCAAgC,EAAE;gBAC7F,KAAK,EAAE,KAAK;aACf,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ,CAAA;AAtDY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGL,wBAAS;QACX,2BAAc;QACV,4BAAe;GAJxC,kBAAkB,CAsD9B","sourcesContent":["/**\n * Which PROJECTS a project-scoped rule judges — the two tag-truth code rules (#1064),\n * `framework-tsconfig` and `framework-packages` — and the `framework:` tags each carries.\n *\n * MODIFIED_PROJECTS — every project owning a changed file (any file, not only .ts: a project.json or\n * tsconfig edit is exactly what these rules judge)\n * RUN_EVERY_TIME — every project in the repo, every run (the migration sweep)\n *\n * The per-run `--projects` restriction of the debug run (#1027) narrows both.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { DiffScope } from \"@webpieces/rules-config\";\nimport { ProjectScanMode } from \"./configs/tag-truth-configs\";\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ProjectCatalog, ProjectEntry, ScanRestriction } from './scan-scope';\n\nconst FRAMEWORK_TAG_PREFIX = 'framework:';\n\n/** The only field of a project.json this reads. */\ntype RawProjectTags = { tags?: string[] };\n\n/** One project to judge and its framework env set. Data-only. */\nexport class ScannedProject {\n constructor(\n readonly name: string,\n /** Repo-relative, '/'-separated, no trailing slash. */\n readonly dir: string,\n /** The `framework:` tag values, in declaration order, de-duplicated. Empty when untagged. */\n readonly frameworks: readonly string[],\n ) {}\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class ProjectScanTargets {\n constructor(\n private readonly diffScope: DiffScope,\n private readonly catalog: ProjectCatalog,\n private readonly restriction: ScanRestriction,\n ) {}\n\n /** The projects `mode` judges, root project excluded. `mode` must not be OFF. */\n projects(workspaceRoot: string, mode: ProjectScanMode, ruleName: string): ScannedProject[] {\n const all = this.catalog.all(workspaceRoot).filter((p: ProjectEntry) => p.dir !== '');\n const chosen = mode === 'RUN_EVERY_TIME' ? all : this.touched(workspaceRoot, all, ruleName);\n const names = this.restriction.projectNames;\n const restricted = names === undefined ? chosen : chosen.filter((p: ProjectEntry) => names.includes(p.name));\n return restricted\n .map((p: ProjectEntry) => new ScannedProject(p.name, p.dir, this.frameworksOf(workspaceRoot, p.dir)))\n .sort((a: ScannedProject, b: ScannedProject) => a.dir.localeCompare(b.dir));\n }\n\n private touched(workspaceRoot: string, all: ProjectEntry[], ruleName: string): ProjectEntry[] {\n const range = this.diffScope.resolveBase(workspaceRoot);\n if (range.base === undefined) {\n throw new InformAiError(\n `${ruleName} could not determine the comparison base for MODIFIED_PROJECTS. Set NX_BASE to the ` +\n 'base branch or commit and retry.',\n );\n }\n const dirs = new Set<string>();\n for (const file of this.diffScope.getChangedFiles(workspaceRoot, range.base, range.head, { tsOnly: false })) {\n const owner = this.catalog.ownerOf(workspaceRoot, file);\n if (owner !== undefined) dirs.add(owner.dir);\n }\n return all.filter((p: ProjectEntry) => dirs.has(p.dir));\n }\n\n /** The `framework:` values of a project.json. Unreadable JSON is the plumbing error it is. */\n private frameworksOf(workspaceRoot: string, dir: string): string[] {\n const file = path.join(workspaceRoot, dir, 'project.json');\n // webpieces-disable no-unmanaged-exceptions -- add the exact project.json path while preserving the parse/read failure as cause\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const parsed = JSON.parse(fs.readFileSync(file, 'utf-8')) as RawProjectTags;\n const tags = Array.isArray(parsed.tags) ? parsed.tags : [];\n const values = tags\n .filter((tag: string) => typeof tag === 'string' && tag.startsWith(FRAMEWORK_TAG_PREFIX))\n .map((tag: string) => tag.slice(FRAMEWORK_TAG_PREFIX.length).trim())\n .filter((value: string) => value.length > 0);\n return Array.from(new Set(values));\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`Cannot read framework tags from ${file} — fix project.json and retry.`, {\n cause: error,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"project-scan-targets.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/project-scan-targets.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAoD;AAEpD,8DAA0D;AAC1D,iEAA6D;AAC7D,yCAA2D;AAC3D,6CAA6E;AAE7E,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAK1C,iEAAiE;AACjE,MAAa,cAAc;IAEV;IAEA;IAEA;IALb,YACa,IAAY;IACrB,uDAAuD;IAC9C,GAAW;IACpB,6FAA6F;IACpF,UAA6B;QAJ7B,SAAI,GAAJ,IAAI,CAAQ;QAEZ,QAAG,GAAH,GAAG,CAAQ;QAEX,eAAU,GAAV,UAAU,CAAmB;IACvC,CAAC;CACP;AARD,wCAQC;AAGM,IAAM,kBAAkB,GAAxB,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,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,MAAM,MAAM,GAAG,IAAI;iBACd,MAAM,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;iBACxF,GAAG,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;iBACnE,MAAM,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACjD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,MAAM,IAAI,8BAAa,CAAC,mCAAmC,IAAI,gCAAgC,EAAE;gBAC7F,KAAK,EAAE,KAAK;aACf,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ,CAAA;AAtDY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGL,wBAAS;QACX,2BAAc;QACV,4BAAe;GAJxC,kBAAkB,CAsD9B","sourcesContent":["/**\n * Which PROJECTS a project-scoped rule judges — the two tag-truth code rules (#1064),\n * `framework-tsconfig` and `framework-packages` — and the `framework:` tags each carries.\n *\n * MODIFIED_PROJECTS — every project owning a changed file (any file, not only .ts: a project.json or\n * tsconfig edit is exactly what these rules judge)\n * RUN_EVERY_TIME — every project in the repo, every run (the migration sweep)\n *\n * The per-run `--projects` restriction of the debug run (#1027) narrows both.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { DiffScope } from \"@webpieces/rules-config\";\nimport { ProjectScanMode } from \"./configs/tag-truth-configs\";\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ProjectCatalog, ProjectEntry, ScanRestriction } from './scan-scope';\n\nconst FRAMEWORK_TAG_PREFIX = 'framework:';\n\n/** The only field of a project.json this reads. */\ntype RawProjectTags = { tags?: string[] };\n\n/** One project to judge and its framework env set. Data-only. */\nexport class ScannedProject {\n constructor(\n readonly name: string,\n /** Repo-relative, '/'-separated, no trailing slash. */\n readonly dir: string,\n /** The `framework:` tag values, in declaration order, de-duplicated. Empty when untagged. */\n readonly frameworks: readonly string[],\n ) {}\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class ProjectScanTargets {\n constructor(\n private readonly diffScope: DiffScope,\n private readonly catalog: ProjectCatalog,\n private readonly restriction: ScanRestriction,\n ) {}\n\n /** The projects `mode` judges, root project excluded. `mode` must not be OFF. */\n async projects(workspaceRoot: string, mode: ProjectScanMode, ruleName: string): Promise<ScannedProject[]> {\n const all = (await this.catalog.all(workspaceRoot)).filter((p: ProjectEntry) => p.dir !== '');\n const chosen = mode === 'RUN_EVERY_TIME' ? all : await this.touched(workspaceRoot, all, ruleName);\n const names = this.restriction.projectNames;\n const restricted = names === undefined ? chosen : chosen.filter((p: ProjectEntry) => names.includes(p.name));\n return restricted\n .map((p: ProjectEntry) => new ScannedProject(p.name, p.dir, this.frameworksOf(workspaceRoot, p.dir)))\n .sort((a: ScannedProject, b: ScannedProject) => a.dir.localeCompare(b.dir));\n }\n\n private async touched(workspaceRoot: string, all: ProjectEntry[], ruleName: string): Promise<ProjectEntry[]> {\n const range = await this.diffScope.resolveBase(workspaceRoot);\n if (range.base === undefined) {\n throw new InformAiError(\n `${ruleName} could not determine the comparison base for MODIFIED_PROJECTS. Set NX_BASE to the ` +\n 'base branch or commit and retry.',\n );\n }\n const dirs = new Set<string>();\n for (const file of await this.diffScope.getChangedFiles(workspaceRoot, range.base, range.head, { tsOnly: false })) {\n const owner = await this.catalog.ownerOf(workspaceRoot, file);\n if (owner !== undefined) dirs.add(owner.dir);\n }\n return all.filter((p: ProjectEntry) => dirs.has(p.dir));\n }\n\n /** The `framework:` values of a project.json. Unreadable JSON is the plumbing error it is. */\n private frameworksOf(workspaceRoot: string, dir: string): string[] {\n const file = path.join(workspaceRoot, dir, 'project.json');\n // webpieces-disable no-unmanaged-exceptions -- add the exact project.json path while preserving the parse/read failure as cause\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const parsed = JSON.parse(fs.readFileSync(file, 'utf-8')) as RawProjectTags;\n const tags = Array.isArray(parsed.tags) ? parsed.tags : [];\n const values = tags\n .filter((tag: string) => typeof tag === 'string' && tag.startsWith(FRAMEWORK_TAG_PREFIX))\n .map((tag: string) => tag.slice(FRAMEWORK_TAG_PREFIX.length).trim())\n .filter((value: string) => value.length > 0);\n return Array.from(new Set(values));\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`Cannot read framework tags from ${file} — fix project.json and retry.`, {\n cause: error,\n });\n }\n }\n}\n"]}
@@ -35,12 +35,12 @@ export declare class RuleDebugRun {
35
35
  /** True when a rule offering `modes` can be debug-run: it judges whole projects and the whole repo. */
36
36
  supports(modes: readonly string[]): boolean;
37
37
  /** Validate `ask` against the rule's modes and the repo's projects; throws a refusal naming the cure. */
38
- plan(workspaceRoot: string, ask: DebugAsk): DebugPlan;
38
+ plan(workspaceRoot: string, ask: DebugAsk): Promise<DebugPlan>;
39
39
  refusal(reason: string): InformAiError;
40
40
  /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */
41
41
  overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C;
42
42
  printBanner(plan: DebugPlan): void;
43
43
  /** Print one count per project from the sites recorded in `scan`, and return the total. */
44
- printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, ruleSucceeded: boolean): number;
44
+ printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, ruleSucceeded: boolean): Promise<number>;
45
45
  private projectNames;
46
46
  }
@@ -51,7 +51,7 @@ class RuleDebugRun {
51
51
  return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME');
52
52
  }
53
53
  /** Validate `ask` against the rule's modes and the repo's projects; throws a refusal naming the cure. */
54
- plan(workspaceRoot, ask) {
54
+ async plan(workspaceRoot, ask) {
55
55
  const mode = ask.mode ?? ask.committedMode;
56
56
  if (!ask.modes.includes(mode) || mode === 'OFF') {
57
57
  const why = ask.mode === undefined
@@ -59,7 +59,7 @@ class RuleDebugRun {
59
59
  : `--mode=${mode} is not one of its modes`;
60
60
  throw this.refusal(`${ask.rule} cannot run: ${why}. Pass --mode=<one of ${ask.modes.filter((m) => m !== 'OFF').join(', ')}>.`);
61
61
  }
62
- const known = this.projectNames(workspaceRoot);
62
+ const known = await this.projectNames(workspaceRoot);
63
63
  const unknown = (ask.projects ?? []).filter((name) => !known.includes(name));
64
64
  if (unknown.length > 0) {
65
65
  throw this.refusal(`--projects names no such nx project: ${unknown.join(', ')}. Known projects: ${known.join(', ')}.`);
@@ -85,8 +85,8 @@ class RuleDebugRun {
85
85
  ' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run');
86
86
  }
87
87
  /** Print one count per project from the sites recorded in `scan`, and return the total. */
88
- printCounts(workspaceRoot, plan, scan, ruleSucceeded) {
89
- const counts = scan.countsByProject(workspaceRoot);
88
+ async printCounts(workspaceRoot, plan, scan, ruleSucceeded) {
89
+ const counts = await scan.countsByProject(workspaceRoot);
90
90
  const names = plan.projects ?? Array.from(counts.keys()).sort();
91
91
  const total = Array.from(counts.values()).reduce((sum, n) => sum + n, 0);
92
92
  console.log('');
@@ -99,9 +99,9 @@ class RuleDebugRun {
99
99
  console.log('');
100
100
  return total;
101
101
  }
102
- projectNames(workspaceRoot) {
103
- return new scan_scope_1.ProjectCatalog(new rules_config_1.DiffScope())
104
- .all(workspaceRoot)
102
+ async projectNames(workspaceRoot) {
103
+ return (await new scan_scope_1.ProjectCatalog(new rules_config_1.DiffScope())
104
+ .all(workspaceRoot))
105
105
  .map((p) => p.name)
106
106
  .sort();
107
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rule-debug-run.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-debug-run.ts"],"names":[],"mappings":";;;AACA,0DAAoD;AACpD,8DAA0D;AAE1D,6CAAuE;AAEvE,0GAA0G;AAC1G,MAAa,SAAS;IAEL;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,aAAqB,EACrB,QAAuC;QAHvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;QACrB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP;AAPD,8BAOC;AAED,2GAA2G;AAC3G,MAAa,QAAQ;IAEJ;IAEA;IACA;IAEA;IACA;IAPb,YACa,IAAY;IACrB,2DAA2D;IAClD,IAAwB,EACxB,aAAqB;IAC9B,yGAAyG;IAChG,KAAwB,EACxB,QAAuC;QANvC,SAAI,GAAJ,IAAI,CAAQ;QAEZ,SAAI,GAAJ,IAAI,CAAoB;QACxB,kBAAa,GAAb,aAAa,CAAQ;QAErB,UAAK,GAAL,KAAK,CAAmB;QACxB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP;AAVD,4BAUC;AAED;;;;;;GAMG;AACH,MAAa,YAAY;IACrB,uGAAuG;IACvG,QAAQ,CAAC,KAAwB;QAC7B,OAAO,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACnF,CAAC;IAED,yGAAyG;IACzG,IAAI,CAAC,aAAqB,EAAE,GAAa;QACrC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,aAAa,CAAC;QAC3C,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AC,MAAM,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,eAAe,CAAC,CAAC;QACtE,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,aAAa,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,GAAG,CAAC,sEAAsE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,OAAO,KAAK,CAAC;IACjB,CAAC;IAEO,YAAY,CAAC,aAAqB;QACtC,OAAO,IAAI,2BAAc,CAAC,IAAI,wBAAS,EAAE,CAAC;aACrC,GAAG,CAAC,aAAa,CAAC;aAClB,GAAG,CAAC,CAAC,CAAe,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aAChC,IAAI,EAAE,CAAC;IAChB,CAAC;CACJ;AA7ED,oCA6EC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\nimport { DiffScope } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ProjectCatalog, ProjectEntry, ScanScope } from './scan-scope';\n\n/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */\nexport class DebugPlan {\n constructor(\n readonly rule: string,\n readonly mode: string,\n readonly committedMode: string,\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/** What a debug run was asked, before it is validated against the rule's modes and the repo. Data-only. */\nexport class DebugAsk {\n constructor(\n readonly rule: string,\n /** `--mode`, or undefined to run at the committed mode. */\n readonly mode: string | undefined,\n readonly committedMode: string,\n /** Every mode the rule offers (OFF included); a debug run needs MODIFIED_PROJECTS and RUN_EVERY_TIME. */\n readonly modes: readonly string[],\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/**\n * The parts of a one-rule DEBUG run (#1027) every runner shares, so a built-in code rule and a repo-local\n * rule (#1330) refuse, announce, override and count identically: the same refusals, the same banner, the\n * same in-memory override (mode replaced, both escape hatches cleared) and the same per-project count.\n * The runner owns only the part between banner and count — running the rule through a {@link ScanScope}\n * restricted to the plan's projects and recording each site there.\n */\nexport class RuleDebugRun {\n /** True when a rule offering `modes` can be debug-run: it judges whole projects and the whole repo. */\n supports(modes: readonly string[]): boolean {\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME');\n }\n\n /** Validate `ask` against the rule's modes and the repo's projects; throws a refusal naming the cure. */\n plan(workspaceRoot: string, ask: DebugAsk): DebugPlan {\n const mode = ask.mode ?? ask.committedMode;\n if (!ask.modes.includes(mode) || mode === 'OFF') {\n const why =\n ask.mode === undefined\n ? `its committed mode is ${ask.committedMode}`\n : `--mode=${mode} is not one of its modes`;\n throw this.refusal(\n `${ask.rule} cannot run: ${why}. Pass --mode=<one of ${ask.modes.filter((m: string) => m !== 'OFF').join(', ')}>.`,\n );\n }\n const known = this.projectNames(workspaceRoot);\n const unknown = (ask.projects ?? []).filter((name: string) => !known.includes(name));\n if (unknown.length > 0) {\n throw this.refusal(\n `--projects names no such nx project: ${unknown.join(', ')}. Known projects: ${known.join(', ')}.`,\n );\n }\n return new DebugPlan(ask.rule, mode, ask.committedMode, ask.projects);\n }\n\n refusal(reason: string): InformAiError {\n return new InformAiError(`[debug run] ${reason}`);\n }\n\n /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */\n overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C {\n const copy = Object.assign(\n Object.create(Object.getPrototypeOf(config) as object) as C,\n config,\n );\n copy.mode = plan.mode;\n copy.turnOffRuleUntilEpoch = 0;\n copy.turnOffRuleWhileOnBranch = null;\n return copy;\n }\n\n printBanner(plan: DebugPlan): void {\n console.log('');\n console.log(\n `🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`,\n );\n console.log(\n ` Mode: ${plan.mode} (committed: ${plan.committedMode})` +\n ` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +\n ' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run',\n );\n }\n\n /** Print one count per project from the sites recorded in `scan`, and return the total. */\n printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, ruleSucceeded: boolean): number {\n const counts = scan.countsByProject(workspaceRoot);\n const names = plan.projects ?? Array.from(counts.keys()).sort();\n const total = Array.from(counts.values()).reduce((sum: number, n: number) => sum + n, 0);\n console.log('');\n console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);\n for (const name of names) console.log(` ${name}: ${counts.get(name) ?? 0}`);\n if (!ruleSucceeded && total === 0) {\n console.log(' (the rule failed without reporting sites — read its output above)');\n }\n console.log('');\n return total;\n }\n\n private projectNames(workspaceRoot: string): string[] {\n return new ProjectCatalog(new DiffScope())\n .all(workspaceRoot)\n .map((p: ProjectEntry) => p.name)\n .sort();\n }\n}\n"]}
1
+ {"version":3,"file":"rule-debug-run.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-debug-run.ts"],"names":[],"mappings":";;;AACA,0DAAoD;AACpD,8DAA0D;AAE1D,6CAAuE;AAEvE,0GAA0G;AAC1G,MAAa,SAAS;IAEL;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,aAAqB,EACrB,QAAuC;QAHvC,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,kBAAa,GAAb,aAAa,CAAQ;QACrB,aAAQ,GAAR,QAAQ,CAA+B;IACjD,CAAC;CACP;AAPD,8BAOC;AAED,2GAA2G;AAC3G,MAAa,QAAQ;IAEJ;IAEA;IACA;IAEA;IACA;IAPb,YACa,IAAY;IACrB,2DAA2D;IAClD,IAAwB,EACxB,aAAqB;IAC9B,yGAAyG;IAChG,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C,IAAI,EAAE,CAAC;IAChB,CAAC;CACJ;AA7ED,oCA6EC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\nimport { DiffScope } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\n\nimport { ProjectCatalog, ProjectEntry, ScanScope } from './scan-scope';\n\n/** A validated debug run (#1027): the one rule, the mode it runs at, and the projects it is scoped to. */\nexport class DebugPlan {\n constructor(\n readonly rule: string,\n readonly mode: string,\n readonly committedMode: string,\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/** What a debug run was asked, before it is validated against the rule's modes and the repo. Data-only. */\nexport class DebugAsk {\n constructor(\n readonly rule: string,\n /** `--mode`, or undefined to run at the committed mode. */\n readonly mode: string | undefined,\n readonly committedMode: string,\n /** Every mode the rule offers (OFF included); a debug run needs MODIFIED_PROJECTS and RUN_EVERY_TIME. */\n readonly modes: readonly string[],\n readonly projects: readonly string[] | undefined,\n ) {}\n}\n\n/**\n * The parts of a one-rule DEBUG run (#1027) every runner shares, so a built-in code rule and a repo-local\n * rule (#1330) refuse, announce, override and count identically: the same refusals, the same banner, the\n * same in-memory override (mode replaced, both escape hatches cleared) and the same per-project count.\n * The runner owns only the part between banner and count — running the rule through a {@link ScanScope}\n * restricted to the plan's projects and recording each site there.\n */\nexport class RuleDebugRun {\n /** True when a rule offering `modes` can be debug-run: it judges whole projects and the whole repo. */\n supports(modes: readonly string[]): boolean {\n return modes.includes('MODIFIED_PROJECTS') && modes.includes('RUN_EVERY_TIME');\n }\n\n /** Validate `ask` against the rule's modes and the repo's projects; throws a refusal naming the cure. */\n async plan(workspaceRoot: string, ask: DebugAsk): Promise<DebugPlan> {\n const mode = ask.mode ?? ask.committedMode;\n if (!ask.modes.includes(mode) || mode === 'OFF') {\n const why =\n ask.mode === undefined\n ? `its committed mode is ${ask.committedMode}`\n : `--mode=${mode} is not one of its modes`;\n throw this.refusal(\n `${ask.rule} cannot run: ${why}. Pass --mode=<one of ${ask.modes.filter((m: string) => m !== 'OFF').join(', ')}>.`,\n );\n }\n const known = await this.projectNames(workspaceRoot);\n const unknown = (ask.projects ?? []).filter((name: string) => !known.includes(name));\n if (unknown.length > 0) {\n throw this.refusal(\n `--projects names no such nx project: ${unknown.join(', ')}. Known projects: ${known.join(', ')}.`,\n );\n }\n return new DebugPlan(ask.rule, mode, ask.committedMode, ask.projects);\n }\n\n refusal(reason: string): InformAiError {\n return new InformAiError(`[debug run] ${reason}`);\n }\n\n /** A copy of `config` at the plan's mode with both escape hatches cleared. The original is untouched. */\n overridden<C extends BaseRuleConfig>(config: C, plan: DebugPlan): C {\n const copy = Object.assign(\n Object.create(Object.getPrototypeOf(config) as object) as C,\n config,\n );\n copy.mode = plan.mode;\n copy.turnOffRuleUntilEpoch = 0;\n copy.turnOffRuleWhileOnBranch = null;\n return copy;\n }\n\n printBanner(plan: DebugPlan): void {\n console.log('');\n console.log(\n `🔍 DEBUG RUN of ${plan.rule} — NOT the gate. webpieces.config.json is unchanged and nothing is written.`,\n );\n console.log(\n ` Mode: ${plan.mode} (committed: ${plan.committedMode})` +\n ` · Projects: ${plan.projects === undefined ? 'every project' : plan.projects.join(', ')}` +\n ' · escape hatches (turnOffRuleUntilEpoch / turnOffRuleWhileOnBranch) ignored for this run',\n );\n }\n\n /** Print one count per project from the sites recorded in `scan`, and return the total. */\n async printCounts(workspaceRoot: string, plan: DebugPlan, scan: ScanScope, ruleSucceeded: boolean): Promise<number> {\n const counts = await scan.countsByProject(workspaceRoot);\n const names = plan.projects ?? Array.from(counts.keys()).sort();\n const total = Array.from(counts.values()).reduce((sum: number, n: number) => sum + n, 0);\n console.log('');\n console.log(`🔍 ${plan.rule} at ${plan.mode}: ${total} site(s) left`);\n for (const name of names) console.log(` ${name}: ${counts.get(name) ?? 0}`);\n if (!ruleSucceeded && total === 0) {\n console.log(' (the rule failed without reporting sites — read its output above)');\n }\n console.log('');\n return total;\n }\n\n private async projectNames(workspaceRoot: string): Promise<string[]> {\n return (await new ProjectCatalog(new DiffScope())\n .all(workspaceRoot))\n .map((p: ProjectEntry) => p.name)\n .sort();\n }\n}\n"]}
@@ -34,9 +34,9 @@ export declare class ProjectCatalog {
34
34
  private cachedRoot;
35
35
  private cached;
36
36
  constructor(diffScope: DiffScope);
37
- all(workspaceRoot: string): ProjectEntry[];
37
+ all(workspaceRoot: string): Promise<ProjectEntry[]>;
38
38
  /** The project owning `relFile`, or undefined when no project directory contains it. */
39
- ownerOf(workspaceRoot: string, relFile: string): ProjectEntry | undefined;
39
+ ownerOf(workspaceRoot: string, relFile: string): Promise<ProjectEntry | undefined>;
40
40
  private load;
41
41
  private readName;
42
42
  }
@@ -66,11 +66,11 @@ export declare class ScanScope {
66
66
  * The files a rule in `mode` judges, restricted to the debug run's `--projects` when there is one.
67
67
  * `opts` is passed through to the git listing (`tsOnly: false` for a rule that reads templates/CSS).
68
68
  */
69
- files(workspaceRoot: string, mode: ModifiedCodeMode, base: string, head: string | undefined, opts?: ChangedFilesOptions): string[];
69
+ files(workspaceRoot: string, mode: ModifiedCodeMode, base: string, head: string | undefined, opts?: ChangedFilesOptions): Promise<string[]>;
70
70
  /** Record every violating site a rule found, for the debug run's per-project count. */
71
71
  recordSites(ruleName: string, relFiles: readonly string[]): void;
72
72
  /** Sites recorded so far, counted per owning project name (`(no project)` for a file outside one). */
73
- countsByProject(workspaceRoot: string): Map<string, number>;
73
+ countsByProject(workspaceRoot: string): Promise<Map<string, number>>;
74
74
  private unrestricted;
75
75
  private restrict;
76
76
  }