@webpieces/pr-gate 0.4.779 → 0.4.780

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/pr-gate",
3
- "version": "0.4.779",
3
+ "version": "0.4.780",
4
4
  "description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@inversifyjs/binding-decorators": "1.1.5",
19
- "@webpieces/ai-hook-rules": "0.4.779",
20
- "@webpieces/rules-config": "0.4.779",
19
+ "@webpieces/ai-hook-rules": "0.4.780",
20
+ "@webpieces/rules-config": "0.4.780",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2"
23
23
  },
@@ -30,6 +30,7 @@ exports.FALLBACK_GENERATED_PATHS = [
30
30
  '**/design.html',
31
31
  'architecture/dependencies.json',
32
32
  'architecture/dependencies.html',
33
+ 'architecture/apis',
33
34
  'architecture/runtime-dependencies.json',
34
35
  ];
35
36
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"generated-artifact-registry.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/generated-artifact-registry.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAkD;AAClD,yCAA2D;AAE3D;;;GAGG;AACU,QAAA,kBAAkB,GAAG,qCAAqC,CAAC;AAC3D,QAAA,wBAAwB,GAAG,kDAAkD,CAAC;AAE3F;;;;;;;;;GASG;AACU,QAAA,wBAAwB,GAAsB;IACvD,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,gCAAgC;IAChC,gCAAgC;IAChC,wCAAwC;CAC3C,CAAC;AAEF;;;G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 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { toError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * Where the \"known generated\" answer came from, so a failure message can say whether it is speaking\n * from the workspace's own declarations or from the built-in fallback.\n */\nexport const ARTIFACT_SOURCE_NX = 'nx project graph (target `outputs`)';\nexport const ARTIFACT_SOURCE_FALLBACK = 'built-in fallback (nx project graph unavailable)';\n\n/**\n * The fallback \"known generated\" set, used ONLY when the nx project graph cannot be read (nx not\n * installed, `nx graph` failed, unparseable output). It deliberately mirrors what the webpieces nx\n * plugin declares as `outputs` today — `di-graph-generate` writes design.{json,md,html} per project\n * and the architecture targets write architecture/*.\n *\n * It is a fallback and not the primary source precisely because a hand-maintained list drifts: the\n * moment a repo adds a target that writes a new committed artifact, only the nx `outputs` declaration\n * knows about it. Data (a module-level table), not a list buried inside a function.\n */\nexport const FALLBACK_GENERATED_PATHS: readonly string[] = [\n '**/design.json',\n '**/design.md',\n '**/design.html',\n 'architecture/dependencies.json',\n 'architecture/dependencies.html',\n 'architecture/runtime-dependencies.json',\n];\n\n/**\n * The set of repo-relative paths/globs that a build is EXPECTED to rewrite, plus where the set came\n * from. Data-only (per CLAUDE.md) — the resolution logic lives in GeneratedArtifactRegistry.\n */\nexport class GeneratedArtifacts {\n paths: string[];\n source: string;\n\n constructor(paths: string[], source: string) {\n this.paths = paths;\n this.source = source;\n }\n}\n\n/**\n * Answers \"is this path something the build is SUPPOSED to rewrite?\" from the workspace's own nx\n * target `outputs` declarations rather than from a parallel list maintained by hand.\n *\n * Why nx `outputs`: every target that writes a checked-in artifact already has to declare it there or\n * nx caching corrupts the workspace, so the declaration is load-bearing and therefore maintained. A\n * second list in the PR gate would be maintained by nobody and would drift the first time a repo adds\n * a generator. One `nx graph --file=<tmp>` dumps the whole workspace (every project, every target,\n * every `outputs` entry) in one ~2s call, so this costs one subprocess per PR-gate run.\n *\n * Tokens: `{projectRoot}` and `{workspaceRoot}` are expanded; anything still holding a `{...}` token\n * (`{options.outputPath}`, `{options.outputFile}`) is DROPPED — it is only resolvable per-invocation,\n * and such targets write into `dist/`, which is gitignored and therefore invisible to this gate anyway.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GeneratedArtifactRegistry {\n // Resolved once per process: the graph does not change while one PR-gate command runs.\n private cached: GeneratedArtifacts | null = null;\n\n /** The declared build outputs for this repo, from nx when readable and the fallback table otherwise. */\n resolve(repoRoot: string): GeneratedArtifacts {\n if (this.cached !== null) return this.cached;\n const fromNx = this.readNxOutputs(repoRoot);\n this.cached = fromNx !== null\n ? new GeneratedArtifacts(fromNx, ARTIFACT_SOURCE_NX)\n : new GeneratedArtifacts(FALLBACK_GENERATED_PATHS.slice(), ARTIFACT_SOURCE_FALLBACK);\n return this.cached;\n }\n\n /** Test seam: pre-seed the resolved set so specs never shell out to nx. */\n seed(artifacts: GeneratedArtifacts): void {\n this.cached = artifacts;\n }\n\n /**\n * Dump the nx project graph to a temp file and collect every target's `outputs`. Returns null (not\n * an empty list) when nx is unavailable or unreadable, so the caller can tell \"no nx\" apart from\n * \"nx says this workspace declares nothing\".\n */\n private readNxOutputs(repoRoot: string): string[] | null {\n const nxBin = path.join(repoRoot, 'node_modules', '.bin', 'nx');\n if (!fs.existsSync(nxBin)) return null;\n const outFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'wp-nxgraph-')), 'graph.json');\n const run = spawnSync(nxBin, ['graph', '--file', outFile], { cwd: repoRoot, encoding: 'utf8', stdio: 'pipe' });\n if (run.status !== 0 || !fs.existsSync(outFile)) return null;\n return this.parseGraph(outFile);\n }\n\n /** Read + narrow the dumped graph. Null on anything unreadable, so the caller falls back. */\n private parseGraph(outFile: string): string[] | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable/corrupt graph dump must\n // fall back to the built-in table, never fail a PR flow over a cache artifact we only consult\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque nx JSON, narrowed field by field below\n const parsed = JSON.parse(fs.readFileSync(outFile, 'utf8')) as NxGraphFile;\n const nodes = parsed.graph?.nodes;\n if (nodes === undefined) return null;\n return this.collectOutputs(nodes);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // unreadable graph => fall back to the built-in table\n return null;\n }\n }\n\n /** Walk every project → every target → every `outputs` entry, expanding the nx path tokens. */\n private collectOutputs(nodes: Record<string, NxGraphNode>): string[] {\n const found = new Set<string>();\n for (const projectName of Object.keys(nodes)) {\n const data = nodes[projectName].data;\n const targets = data.targets;\n if (targets === undefined) continue;\n for (const targetName of Object.keys(targets)) {\n for (const raw of targets[targetName].outputs ?? []) {\n const expanded = this.expand(raw, data.root ?? '.');\n if (expanded !== null) found.add(expanded);\n }\n }\n }\n return Array.from(found).sort();\n }\n\n /** Expand `{projectRoot}` / `{workspaceRoot}`; drop anything still carrying an unresolved token. */\n private expand(raw: string, projectRoot: string): string | null {\n const replaced = raw\n .replace(/\\{projectRoot\\}/g, projectRoot)\n .replace(/\\{workspaceRoot\\}\\//g, '')\n .replace(/\\{workspaceRoot\\}/g, '.');\n if (replaced.includes('{')) return null;\n const normalized = replaced.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n return normalized === '' || normalized === '.' ? null : normalized;\n }\n}\n\n// Structural views of the `nx graph --file=<json>` payload. Interfaces (not classes) on purpose: these\n// describe a foreign JSON shape we narrow, never something this codebase constructs.\ninterface NxGraphFile {\n graph?: NxGraphBody;\n}\n\ninterface NxGraphBody {\n nodes?: Record<string, NxGraphNode>;\n}\n\ninterface NxGraphNode {\n data: NxProjectData;\n}\n\ninterface NxProjectData {\n root?: string;\n targets?: Record<string, NxTarget>;\n}\n\ninterface NxTarget {\n outputs?: string[];\n}\n"]}
1
+ {"version":3,"file":"generated-artifact-registry.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/generated-artifact-registry.ts"],"names":[],"mappings":";;;;AAAA,iDAA0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AO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACrE,OAAO,UAAU,KAAK,EAAE,IAAI,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;IACvE,CAAC;CACJ,CAAA;AA9EY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,yBAAyB,CA8ErC","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { toError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * Where the \"known generated\" answer came from, so a failure message can say whether it is speaking\n * from the workspace's own declarations or from the built-in fallback.\n */\nexport const ARTIFACT_SOURCE_NX = 'nx project graph (target `outputs`)';\nexport const ARTIFACT_SOURCE_FALLBACK = 'built-in fallback (nx project graph unavailable)';\n\n/**\n * The fallback \"known generated\" set, used ONLY when the nx project graph cannot be read (nx not\n * installed, `nx graph` failed, unparseable output). It deliberately mirrors what the webpieces nx\n * plugin declares as `outputs` today — `di-graph-generate` writes design.{json,md,html} per project\n * and the architecture targets write architecture/*.\n *\n * It is a fallback and not the primary source precisely because a hand-maintained list drifts: the\n * moment a repo adds a target that writes a new committed artifact, only the nx `outputs` declaration\n * knows about it. Data (a module-level table), not a list buried inside a function.\n */\nexport const FALLBACK_GENERATED_PATHS: readonly string[] = [\n '**/design.json',\n '**/design.md',\n '**/design.html',\n 'architecture/dependencies.json',\n 'architecture/dependencies.html',\n 'architecture/apis',\n 'architecture/runtime-dependencies.json',\n];\n\n/**\n * The set of repo-relative paths/globs that a build is EXPECTED to rewrite, plus where the set came\n * from. Data-only (per CLAUDE.md) — the resolution logic lives in GeneratedArtifactRegistry.\n */\nexport class GeneratedArtifacts {\n paths: string[];\n source: string;\n\n constructor(paths: string[], source: string) {\n this.paths = paths;\n this.source = source;\n }\n}\n\n/**\n * Answers \"is this path something the build is SUPPOSED to rewrite?\" from the workspace's own nx\n * target `outputs` declarations rather than from a parallel list maintained by hand.\n *\n * Why nx `outputs`: every target that writes a checked-in artifact already has to declare it there or\n * nx caching corrupts the workspace, so the declaration is load-bearing and therefore maintained. A\n * second list in the PR gate would be maintained by nobody and would drift the first time a repo adds\n * a generator. One `nx graph --file=<tmp>` dumps the whole workspace (every project, every target,\n * every `outputs` entry) in one ~2s call, so this costs one subprocess per PR-gate run.\n *\n * Tokens: `{projectRoot}` and `{workspaceRoot}` are expanded; anything still holding a `{...}` token\n * (`{options.outputPath}`, `{options.outputFile}`) is DROPPED — it is only resolvable per-invocation,\n * and such targets write into `dist/`, which is gitignored and therefore invisible to this gate anyway.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GeneratedArtifactRegistry {\n // Resolved once per process: the graph does not change while one PR-gate command runs.\n private cached: GeneratedArtifacts | null = null;\n\n /** The declared build outputs for this repo, from nx when readable and the fallback table otherwise. */\n resolve(repoRoot: string): GeneratedArtifacts {\n if (this.cached !== null) return this.cached;\n const fromNx = this.readNxOutputs(repoRoot);\n this.cached = fromNx !== null\n ? new GeneratedArtifacts(fromNx, ARTIFACT_SOURCE_NX)\n : new GeneratedArtifacts(FALLBACK_GENERATED_PATHS.slice(), ARTIFACT_SOURCE_FALLBACK);\n return this.cached;\n }\n\n /** Test seam: pre-seed the resolved set so specs never shell out to nx. */\n seed(artifacts: GeneratedArtifacts): void {\n this.cached = artifacts;\n }\n\n /**\n * Dump the nx project graph to a temp file and collect every target's `outputs`. Returns null (not\n * an empty list) when nx is unavailable or unreadable, so the caller can tell \"no nx\" apart from\n * \"nx says this workspace declares nothing\".\n */\n private readNxOutputs(repoRoot: string): string[] | null {\n const nxBin = path.join(repoRoot, 'node_modules', '.bin', 'nx');\n if (!fs.existsSync(nxBin)) return null;\n const outFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'wp-nxgraph-')), 'graph.json');\n const run = spawnSync(nxBin, ['graph', '--file', outFile], { cwd: repoRoot, encoding: 'utf8', stdio: 'pipe' });\n if (run.status !== 0 || !fs.existsSync(outFile)) return null;\n return this.parseGraph(outFile);\n }\n\n /** Read + narrow the dumped graph. Null on anything unreadable, so the caller falls back. */\n private parseGraph(outFile: string): string[] | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable/corrupt graph dump must\n // fall back to the built-in table, never fail a PR flow over a cache artifact we only consult\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque nx JSON, narrowed field by field below\n const parsed = JSON.parse(fs.readFileSync(outFile, 'utf8')) as NxGraphFile;\n const nodes = parsed.graph?.nodes;\n if (nodes === undefined) return null;\n return this.collectOutputs(nodes);\n } catch (err: unknown) {\n const error = toError(err);\n void error; // unreadable graph => fall back to the built-in table\n return null;\n }\n }\n\n /** Walk every project → every target → every `outputs` entry, expanding the nx path tokens. */\n private collectOutputs(nodes: Record<string, NxGraphNode>): string[] {\n const found = new Set<string>();\n for (const projectName of Object.keys(nodes)) {\n const data = nodes[projectName].data;\n const targets = data.targets;\n if (targets === undefined) continue;\n for (const targetName of Object.keys(targets)) {\n for (const raw of targets[targetName].outputs ?? []) {\n const expanded = this.expand(raw, data.root ?? '.');\n if (expanded !== null) found.add(expanded);\n }\n }\n }\n return Array.from(found).sort();\n }\n\n /** Expand `{projectRoot}` / `{workspaceRoot}`; drop anything still carrying an unresolved token. */\n private expand(raw: string, projectRoot: string): string | null {\n const replaced = raw\n .replace(/\\{projectRoot\\}/g, projectRoot)\n .replace(/\\{workspaceRoot\\}\\//g, '')\n .replace(/\\{workspaceRoot\\}/g, '.');\n if (replaced.includes('{')) return null;\n const normalized = replaced.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n return normalized === '' || normalized === '.' ? null : normalized;\n }\n}\n\n// Structural views of the `nx graph --file=<json>` payload. Interfaces (not classes) on purpose: these\n// describe a foreign JSON shape we narrow, never something this codebase constructs.\ninterface NxGraphFile {\n graph?: NxGraphBody;\n}\n\ninterface NxGraphBody {\n nodes?: Record<string, NxGraphNode>;\n}\n\ninterface NxGraphNode {\n data: NxProjectData;\n}\n\ninterface NxProjectData {\n root?: string;\n targets?: Record<string, NxTarget>;\n}\n\ninterface NxTarget {\n outputs?: string[];\n}\n"]}