@webpieces/code-rules 0.4.965 → 0.4.966

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/code-rules",
3
- "version": "0.4.965",
3
+ "version": "0.4.966",
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.965",
19
+ "@webpieces/rules-config": "0.4.966",
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.965",
24
- "@webpieces/repo-workflow-core": "0.4.965",
25
- "@webpieces/rules-sdk": "0.4.965"
23
+ "@webpieces/tooling-common": "0.4.966",
24
+ "@webpieces/repo-workflow-core": "0.4.966",
25
+ "@webpieces/rules-sdk": "0.4.966"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
30
  "devDependencies": {
31
- "@webpieces/tooling-testkit": "0.4.965"
31
+ "@webpieces/tooling-testkit": "0.4.966"
32
32
  },
33
33
  "exports": {
34
34
  ".": "./src/index.js",
package/src/wp-ci.js CHANGED
@@ -72,6 +72,7 @@ async function runStandalone(cwd) {
72
72
  console.log('ℹ️ Not an Nx repo and no webpieces.config.json found — nothing to validate.');
73
73
  return 0;
74
74
  }
75
+ (0, rules_config_1.assertPolicyTracked)(workspaceRoot);
75
76
  console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\n');
76
77
  const result = await new code_rules_bootstrap_1.CodeRulesBootstrap().run(workspaceRoot, new code_rules_run_request_1.CodeRulesRunRequest(undefined, undefined, undefined));
77
78
  return result.success ? 0 : 1;
@@ -106,6 +107,11 @@ async function main() {
106
107
  // a RuleFailError / InformAiError to the handler below, which exits non-zero.
107
108
  (0, rules_config_1.loadAndValidate)(root);
108
109
  console.log('✅ webpieces.config.json is valid');
110
+ // Policy is shared through the git index, so it is checked HERE, where work is shared (the PR
111
+ // gate's build command and CI both invoke `pnpm wp-ci`) — never on config load, which every
112
+ // guard-hook call does (#1355).
113
+ (0, rules_config_1.assertPolicyTracked)(root);
114
+ console.log('✅ webpieces policy files are tracked by git');
109
115
  // Run the architecture + code validators next (this also runs the wiring guard,
110
116
  // which fails loudly if nx.json no longer wires validators into the build).
111
117
  if (!hotfix && fs.existsSync(path.join(root, 'architecture'))) {
package/src/wp-ci.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"wp-ci.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/wp-ci.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,+CAAyB;AACzB,mDAA6B;AAE7B,0DAKiC;AACjC,8DAA0D;AAC1D,iEAA6D;AAC7D,sEAA+D;AAC/D,iEAA4D;AAC5D,qEAA+D;AAC/D,uDAAiD;AACjD,uDAM2B;AAE3B,sGAAsG;AACtG,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAE3C,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAYvD,SAAS,MAAM,CAAC,QAAgB,EAAE,QAAgB;IAC9C,IAAI,GAAG,GAAG,QAAQ,CAAC;IACnB,OAAO,IAAI,EAAE,CAAC;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC3C,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAChC,GAAG,GAAG,MAAM,CAAC;IACjB,CAA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,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;aAAM,IAAI,GAAG,YAAY,8BAAa,EAAE,CAAC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,iGAAiG;QACjG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,KAAK,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * wp-ci — the universal webpieces CI entrypoint.\n *\n * Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of\n * \"are we even in Nx?\" cannot live inside an Nx executor (by the time an executor runs,\n * Nx is already running). Dispatch:\n *\n * - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.\n * - nx.json present, plugin NOT in it -> fail with the exact install command.\n * - nx.json present, plugin registered -> normal branch: validators + affected `ci`;\n * `/hotfix/` branch: affected `hotfix-ci` (build + test only).\n *\n * Repos reference this as a bin (`\"webpieces:ci\": \"wp-ci\"`) so the logic is versioned in\n * the npm package instead of copy-pasted into each repo's package.json (which drifts).\n *\n * Every nx step goes through NxStepRunner, which spawns it into its own process group and refuses\n * to return until that group has drained — a step whose workers outlive it holds the CI step's\n * stdout open and hangs the job forever with all work already green. See wp-ci-survivors.ts.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport {\n loadAndValidate,\n RuleFailError,\n renderRuleFailForHuman,\n RepoRootFinder,\n} from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { CodeRulesBootstrap } from './code-rules-bootstrap';\nimport { CodeRulesRunRequest } from './code-rules-run-request';\nimport { NxStepRunner } from './wp-ci-nx-runner';\nimport {\n GracePeriodResolver,\n ProcessGroupKiller,\n ProcessGroupScanner,\n SurvivorReporter,\n SurvivorWatchdog,\n} from './wp-ci-survivors';\n\n/** How often the watchdog re-runs `ps` while waiting for a finished step's process group to drain. */\nconst SURVIVOR_POLL_INTERVAL_MILLIS = 1000;\n\nconst NX_PLUGIN_NAME = '@webpieces/nx-webpieces-rules';\n\ninterface NxPluginObject {\n plugin?: string;\n}\n\ntype NxPluginEntry = string | NxPluginObject;\n\ninterface RawNxJson {\n plugins?: NxPluginEntry[];\n}\n\nfunction findUp(filename: string, startDir: string): string | null {\n let dir = startDir;\n while (true) {\n const candidate = path.join(dir, filename);\n if (fs.existsSync(candidate)) return candidate;\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\nfunction pluginEntryMatches(entry: NxPluginEntry): boolean {\n if (typeof entry === 'string') return entry === NX_PLUGIN_NAME;\n return entry.plugin === NX_PLUGIN_NAME;\n}\n\nfunction isPluginRegistered(nxJsonPath: string): boolean {\n const raw = fs.readFileSync(nxJsonPath, 'utf8');\n // webpieces-disable no-unmanaged-exceptions -- rethrow as InformAiError so global catch surfaces readable message to AI\n try {\n const parsed = JSON.parse(raw) as RawNxJson;\n const plugins = parsed.plugins ?? [];\n return plugins.some((entry: NxPluginEntry) => pluginEntryMatches(entry));\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `nx.json has invalid JSON — fix the file, then retry.\\nParse error: ${error.message}\\nFile: ${nxJsonPath}`,\n );\n }\n}\n\nasync function runStandalone(cwd: string): Promise<number> {\n const workspaceRoot = new RepoRootFinder().resolveRepoRoot(cwd);\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n console.log('ℹ️ Not an Nx repo and no webpieces.config.json found — nothing to validate.');\n return 0;\n }\n console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\\n');\n\n const result = await new CodeRulesBootstrap().run(\n workspaceRoot,\n new CodeRulesRunRequest(undefined, undefined, undefined),\n );\n return result.success ? 0 : 1;\n}\n\nfunction reportPluginMissing(): void {\n console.error('\\n❌ This is an Nx monorepo but the webpieces Nx plugin is not installed.\\n');\n console.error(' Install it so the validators run during CI:\\n');\n console.error(` nx add ${NX_PLUGIN_NAME}\\n`);\n console.error(' (or add it manually to the \"plugins\" array in nx.json).\\n');\n}\n\n// webpieces-disable no-unmanaged-exceptions -- global entry point for wp-ci CLI\nasync function main(): Promise<void> {\n try {\n const cwd = process.cwd();\n const passthrough = process.argv.slice(2);\n\n const nxJsonPath = findUp('nx.json', cwd);\n if (!nxJsonPath) {\n const code = await runStandalone(cwd);\n process.exit(code);\n }\n\n const root = path.dirname(nxJsonPath);\n if (!isPluginRegistered(nxJsonPath)) {\n reportPluginMissing();\n process.exit(1);\n }\n\n const gracePeriod = new GracePeriodResolver().resolve(process.env);\n const runner = new NxStepRunner(\n root,\n gracePeriod,\n new SurvivorWatchdog(new ProcessGroupScanner(), SURVIVOR_POLL_INTERVAL_MILLIS),\n new SurvivorReporter(),\n new ProcessGroupKiller(),\n );\n const hotfix = new BranchIdentity().isHotfix();\n\n // Validate the root policy exactly once, in-process, before any nx step. webpieces.config.json\n // is deliberately NOT an Nx input of any project (#1075): making project hashes depend on it\n // turned a policy-only edit into a workspace-wide compile/lint/test. An invalid config throws\n // a RuleFailError / InformAiError to the handler below, which exits non-zero.\n loadAndValidate(root);\n console.log('✅ webpieces.config.json is valid');\n\n // Run the architecture + code validators next (this also runs the wiring guard,\n // which fails loudly if nx.json no longer wires validators into the build).\n if (!hotfix && fs.existsSync(path.join(root, 'architecture'))) {\n const validateCode = await runner.run(\n ['run', 'architecture:validate-complete'],\n 'architecture:validate-complete',\n );\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n if (validateCode !== 0) process.exit(validateCode);\n }\n\n // Hotfix deliberately schedules only compile/typecheck + tests. The shared branch resolver makes\n // this the same decision the local PR gate makes, including detached GitHub checkouts.\n const target = hotfix ? 'hotfix-ci' : 'ci';\n const ciCode = await runner.run(\n ['affected', `--target=${target}`, ...passthrough],\n `nx affected --target=${target}`,\n );\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(ciCode);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) {\n console.error(renderRuleFailForHuman(error));\n } else if (err instanceof InformAiError) {\n console.error(error.message);\n } else {\n console.error(`[wp-ci] unexpected error: ${error.message}`);\n }\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(1);\n }\n}\n\nvoid main();\n"]}
1
+ {"version":3,"file":"wp-ci.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/wp-ci.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,+CAAyB;AACzB,mDAA6B;AAE7B,0DAMiC;AACjC,8DAA0D;AAC1D,iEAA6D;AAC7D,sEAA+D;AAC/D,iEAA4D;AAC5D,qEAA+D;AAC/D,uDAAiD;AACjD,uDAM2B;AAE3B,sGAAsG;AACtG,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAE3C,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAYvD,SAAS,MAAM,CAAC,QAAgB,EAAE,QAAgB;IAC9C,IAAI,GAAG,GAAG,QAAQ,CAAC;IACnB,OAAO,IAAI,EAAE,CAAC;QACV,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC3C,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;QAChC,GAAG,GAAG,MAAM,C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G;IAC7G,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,YAAY,4BAAa,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,IAAA,qCAAsB,EAAC,KAAK,CAAC,CAAC,CAAC;QACjD,CAAC;aAAM,IAAI,GAAG,YAAY,8BAAa,EAAE,CAAC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,iGAAiG;QACjG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AAED,KAAK,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * wp-ci — the universal webpieces CI entrypoint.\n *\n * Works in BOTH an Nx monorepo and a plain (non-Nx) repo, because the detection of\n * \"are we even in Nx?\" cannot live inside an Nx executor (by the time an executor runs,\n * Nx is already running). Dispatch:\n *\n * - no nx.json (non-Nx repo) -> run the standalone code validators, succeed.\n * - nx.json present, plugin NOT in it -> fail with the exact install command.\n * - nx.json present, plugin registered -> normal branch: validators + affected `ci`;\n * `/hotfix/` branch: affected `hotfix-ci` (build + test only).\n *\n * Repos reference this as a bin (`\"webpieces:ci\": \"wp-ci\"`) so the logic is versioned in\n * the npm package instead of copy-pasted into each repo's package.json (which drifts).\n *\n * Every nx step goes through NxStepRunner, which spawns it into its own process group and refuses\n * to return until that group has drained — a step whose workers outlive it holds the CI step's\n * stdout open and hangs the job forever with all work already green. See wp-ci-survivors.ts.\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nimport {\n assertPolicyTracked,\n loadAndValidate,\n RuleFailError,\n renderRuleFailForHuman,\n RepoRootFinder,\n} from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { CodeRulesBootstrap } from './code-rules-bootstrap';\nimport { CodeRulesRunRequest } from './code-rules-run-request';\nimport { NxStepRunner } from './wp-ci-nx-runner';\nimport {\n GracePeriodResolver,\n ProcessGroupKiller,\n ProcessGroupScanner,\n SurvivorReporter,\n SurvivorWatchdog,\n} from './wp-ci-survivors';\n\n/** How often the watchdog re-runs `ps` while waiting for a finished step's process group to drain. */\nconst SURVIVOR_POLL_INTERVAL_MILLIS = 1000;\n\nconst NX_PLUGIN_NAME = '@webpieces/nx-webpieces-rules';\n\ninterface NxPluginObject {\n plugin?: string;\n}\n\ntype NxPluginEntry = string | NxPluginObject;\n\ninterface RawNxJson {\n plugins?: NxPluginEntry[];\n}\n\nfunction findUp(filename: string, startDir: string): string | null {\n let dir = startDir;\n while (true) {\n const candidate = path.join(dir, filename);\n if (fs.existsSync(candidate)) return candidate;\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\nfunction pluginEntryMatches(entry: NxPluginEntry): boolean {\n if (typeof entry === 'string') return entry === NX_PLUGIN_NAME;\n return entry.plugin === NX_PLUGIN_NAME;\n}\n\nfunction isPluginRegistered(nxJsonPath: string): boolean {\n const raw = fs.readFileSync(nxJsonPath, 'utf8');\n // webpieces-disable no-unmanaged-exceptions -- rethrow as InformAiError so global catch surfaces readable message to AI\n try {\n const parsed = JSON.parse(raw) as RawNxJson;\n const plugins = parsed.plugins ?? [];\n return plugins.some((entry: NxPluginEntry) => pluginEntryMatches(entry));\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `nx.json has invalid JSON — fix the file, then retry.\\nParse error: ${error.message}\\nFile: ${nxJsonPath}`,\n );\n }\n}\n\nasync function runStandalone(cwd: string): Promise<number> {\n const workspaceRoot = new RepoRootFinder().resolveRepoRoot(cwd);\n const loaded = loadAndValidate(workspaceRoot);\n if (loaded.configPath === null) {\n console.log('ℹ️ Not an Nx repo and no webpieces.config.json found — nothing to validate.');\n return 0;\n }\n assertPolicyTracked(workspaceRoot);\n console.log('ℹ️ Not an Nx repo — running standalone webpieces code validators.\\n');\n\n const result = await new CodeRulesBootstrap().run(\n workspaceRoot,\n new CodeRulesRunRequest(undefined, undefined, undefined),\n );\n return result.success ? 0 : 1;\n}\n\nfunction reportPluginMissing(): void {\n console.error('\\n❌ This is an Nx monorepo but the webpieces Nx plugin is not installed.\\n');\n console.error(' Install it so the validators run during CI:\\n');\n console.error(` nx add ${NX_PLUGIN_NAME}\\n`);\n console.error(' (or add it manually to the \"plugins\" array in nx.json).\\n');\n}\n\n// webpieces-disable no-unmanaged-exceptions -- global entry point for wp-ci CLI\nasync function main(): Promise<void> {\n try {\n const cwd = process.cwd();\n const passthrough = process.argv.slice(2);\n\n const nxJsonPath = findUp('nx.json', cwd);\n if (!nxJsonPath) {\n const code = await runStandalone(cwd);\n process.exit(code);\n }\n\n const root = path.dirname(nxJsonPath);\n if (!isPluginRegistered(nxJsonPath)) {\n reportPluginMissing();\n process.exit(1);\n }\n\n const gracePeriod = new GracePeriodResolver().resolve(process.env);\n const runner = new NxStepRunner(\n root,\n gracePeriod,\n new SurvivorWatchdog(new ProcessGroupScanner(), SURVIVOR_POLL_INTERVAL_MILLIS),\n new SurvivorReporter(),\n new ProcessGroupKiller(),\n );\n const hotfix = new BranchIdentity().isHotfix();\n\n // Validate the root policy exactly once, in-process, before any nx step. webpieces.config.json\n // is deliberately NOT an Nx input of any project (#1075): making project hashes depend on it\n // turned a policy-only edit into a workspace-wide compile/lint/test. An invalid config throws\n // a RuleFailError / InformAiError to the handler below, which exits non-zero.\n loadAndValidate(root);\n console.log('✅ webpieces.config.json is valid');\n // Policy is shared through the git index, so it is checked HERE, where work is shared (the PR\n // gate's build command and CI both invoke `pnpm wp-ci`) — never on config load, which every\n // guard-hook call does (#1355).\n assertPolicyTracked(root);\n console.log('✅ webpieces policy files are tracked by git');\n\n // Run the architecture + code validators next (this also runs the wiring guard,\n // which fails loudly if nx.json no longer wires validators into the build).\n if (!hotfix && fs.existsSync(path.join(root, 'architecture'))) {\n const validateCode = await runner.run(\n ['run', 'architecture:validate-complete'],\n 'architecture:validate-complete',\n );\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n if (validateCode !== 0) process.exit(validateCode);\n }\n\n // Hotfix deliberately schedules only compile/typecheck + tests. The shared branch resolver makes\n // this the same decision the local PR gate makes, including detached GitHub checkouts.\n const target = hotfix ? 'hotfix-ci' : 'ci';\n const ciCode = await runner.run(\n ['affected', `--target=${target}`, ...passthrough],\n `nx affected --target=${target}`,\n );\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(ciCode);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) {\n console.error(renderRuleFailForHuman(error));\n } else if (err instanceof InformAiError) {\n console.error(error.message);\n } else {\n console.error(`[wp-ci] unexpected error: ${error.message}`);\n }\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(1);\n }\n}\n\nvoid main();\n"]}