@webpieces/code-rules 0.4.836 → 0.4.837

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.836",
3
+ "version": "0.4.837",
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,7 +16,7 @@
16
16
  "directory": "packages/tooling/code-rules"
17
17
  },
18
18
  "dependencies": {
19
- "@webpieces/rules-config": "0.4.836",
19
+ "@webpieces/rules-config": "0.4.837",
20
20
  "@inversifyjs/binding-decorators": "1.1.5",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2"
package/src/wp-ci.js CHANGED
@@ -110,7 +110,15 @@ async function main() {
110
110
  const gracePeriod = new wp_ci_survivors_1.GracePeriodResolver().resolve(process.env);
111
111
  const runner = new wp_ci_nx_runner_1.NxStepRunner(root, gracePeriod, new wp_ci_survivors_1.SurvivorWatchdog(new wp_ci_survivors_1.ProcessGroupScanner(), SURVIVOR_POLL_INTERVAL_MILLIS), new wp_ci_survivors_1.SurvivorReporter(), new wp_ci_survivors_1.ProcessGroupKiller());
112
112
  const hotfix = new rules_config_1.BranchIdentity().isHotfix();
113
- // Run the architecture + code validators first (this also runs the wiring guard,
113
+ // Validate the root policy exactly once. webpieces.config.json is deliberately NOT a
114
+ // sharedGlobal Nx input: making every project hash depend on it turned a policy-only edit into
115
+ // a workspace-wide compile/lint/test. The scoped rules project preserves the gate without that
116
+ // fan-out.
117
+ const rules = await runner.run(['run', 'rules:check'], 'rules:check');
118
+ // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary
119
+ if (rules !== 0)
120
+ process.exit(rules);
121
+ // Run the architecture + code validators next (this also runs the wiring guard,
114
122
  // which fails loudly if nx.json no longer wires validators into the build).
115
123
  if (!hotfix && fs.existsSync(path.join(root, 'architecture'))) {
116
124
  const validateCode = await runner.run(['run', 'architecture:validate-complete'], 'architecture:validate-complete');
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":";;AACA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,+CAAyB;AACzB,mDAA6B;AAE7B,4BAA0B;AAC1B,yCAAsC;AACtC,0DAAyK;AACzK,qDAAgD;AAChD,6DAAuE;AACvE,uEAA4D;AAC5D,uDAAiD;AACjD,uDAAqI;AAErI,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,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAoB;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,KAAK,cAAc,CAAC;IAC/D,OAAO,KAAK,CAAC,MAAM,KAAK,cAAc,CAAC;AAC3C,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC1C,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAChD,wHAAwH;IACxH,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,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,4BAAa,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 * 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 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { loadAndValidate, InformAiError, RuleFailError, renderRuleFailForHuman, toError, RepoRootFinder, BaseRuleConfig, BranchIdentity } from '@webpieces/rules-config';\nimport { CodeRulesApp } from './code-rules-app';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS } from './code-rules-config-table';\nimport { NxStepRunner } from './wp-ci-nx-runner';\nimport { GracePeriodResolver, ProcessGroupKiller, ProcessGroupScanner, SurvivorReporter, SurvivorWatchdog } 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 } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`nx.json has invalid JSON — fix the file, then retry.\\nParse error: ${error.message}\\nFile: ${nxJsonPath}`);\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 // Composition root: bind runtime values, then resolve the app so inversify builds the whole DAG.\n // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(workspaceRoot));\n container.bind(MatchRulesHolder).toConstantValue(new MatchRulesHolder(loaded.matchRules));\n for (const binding of CONFIG_BINDINGS) {\n const ConfigClass = binding[0];\n const configured = loaded.rulesConfig[binding[1]] as BaseRuleConfig | undefined;\n container.bind(ConfigClass).toConstantValue(configured ?? new ConfigClass());\n }\n\n const app = container.get(CodeRulesApp);\n const result = await app.run();\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(root, gracePeriod, new SurvivorWatchdog(new ProcessGroupScanner(), SURVIVOR_POLL_INTERVAL_MILLIS), new SurvivorReporter(), new ProcessGroupKiller());\n const hotfix = new BranchIdentity().isHotfix();\n\n // Run the architecture + code validators first (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(['run', 'architecture:validate-complete'], 'architecture:validate-complete');\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(['affected', `--target=${target}`, ...passthrough], `nx affected --target=${target}`);\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(ciCode);\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":";;AACA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,+CAAyB;AACzB,mDAA6B;AAE7B,4BAA0B;AAC1B,yCAAsC;AACtC,0DAAyK;AACzK,qDAAgD;AAChD,6DAAuE;AACvE,uEAA4D;AAC5D,uDAAiD;AACjD,uDAAqI;AAErI,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,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) 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 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { loadAndValidate, InformAiError, RuleFailError, renderRuleFailForHuman, toError, RepoRootFinder, BaseRuleConfig, BranchIdentity } from '@webpieces/rules-config';\nimport { CodeRulesApp } from './code-rules-app';\nimport { WorkspaceRoot, MatchRulesHolder } from './code-rules-context';\nimport { CONFIG_BINDINGS } from './code-rules-config-table';\nimport { NxStepRunner } from './wp-ci-nx-runner';\nimport { GracePeriodResolver, ProcessGroupKiller, ProcessGroupScanner, SurvivorReporter, SurvivorWatchdog } 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 } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`nx.json has invalid JSON — fix the file, then retry.\\nParse error: ${error.message}\\nFile: ${nxJsonPath}`);\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 // Composition root: bind runtime values, then resolve the app so inversify builds the whole DAG.\n // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n container.bind(WorkspaceRoot).toConstantValue(new WorkspaceRoot(workspaceRoot));\n container.bind(MatchRulesHolder).toConstantValue(new MatchRulesHolder(loaded.matchRules));\n for (const binding of CONFIG_BINDINGS) {\n const ConfigClass = binding[0];\n const configured = loaded.rulesConfig[binding[1]] as BaseRuleConfig | undefined;\n container.bind(ConfigClass).toConstantValue(configured ?? new ConfigClass());\n }\n\n const app = container.get(CodeRulesApp);\n const result = await app.run();\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(root, gracePeriod, new SurvivorWatchdog(new ProcessGroupScanner(), SURVIVOR_POLL_INTERVAL_MILLIS), new SurvivorReporter(), new ProcessGroupKiller());\n const hotfix = new BranchIdentity().isHotfix();\n\n // Validate the root policy exactly once. webpieces.config.json is deliberately NOT a\n // sharedGlobal Nx input: making every project hash depend on it turned a policy-only edit into\n // a workspace-wide compile/lint/test. The scoped rules project preserves the gate without that\n // fan-out.\n const rules = await runner.run(['run', 'rules:check'], 'rules:check');\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n if (rules !== 0) process.exit(rules);\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(['run', 'architecture:validate-complete'], 'architecture:validate-complete');\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(['affected', `--target=${target}`, ...passthrough], `nx affected --target=${target}`);\n // webpieces-disable no-process-exit-outside-main -- this file's main() is the wp-ci bin boundary\n process.exit(ciCode);\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"]}