@webpieces/nx-webpieces-rules 0.4.870 → 0.4.872
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/README.md +36 -0
- package/package.json +7 -7
- package/src/executors/generate/executor.d.ts +3 -1
- package/src/executors/generate/executor.js +9 -1
- package/src/executors/generate/executor.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -1
- package/src/index.js.map +1 -1
- package/src/lib/di-graph/runtime-client-bindings.d.ts +5 -1
- package/src/lib/di-graph/runtime-client-bindings.js +21 -5
- package/src/lib/di-graph/runtime-client-bindings.js.map +1 -1
- package/src/lib/dot-syntax.d.ts +9 -0
- package/src/lib/dot-syntax.js +17 -0
- package/src/lib/dot-syntax.js.map +1 -1
- package/src/lib/graph-color-modes.d.ts +136 -0
- package/src/lib/graph-color-modes.js +299 -0
- package/src/lib/graph-color-modes.js.map +1 -0
- package/src/lib/graph-filter.client.d.ts +11 -1
- package/src/lib/graph-filter.client.js +25 -4
- package/src/lib/graph-filter.client.js.map +1 -1
- package/src/lib/graph-impact.d.ts +119 -0
- package/src/lib/graph-impact.js +295 -0
- package/src/lib/graph-impact.js.map +1 -0
- package/src/lib/graph-legend.d.ts +34 -0
- package/src/lib/graph-legend.js +116 -0
- package/src/lib/graph-legend.js.map +1 -0
- package/src/lib/graph-names.d.ts +2 -2
- package/src/lib/graph-names.js +2 -2
- package/src/lib/graph-names.js.map +1 -1
- package/src/lib/graph-navigation.d.ts +10 -0
- package/src/lib/graph-navigation.js +47 -12
- package/src/lib/graph-navigation.js.map +1 -1
- package/src/lib/graph-node-menu.d.ts +4 -3
- package/src/lib/graph-node-menu.js +137 -20
- package/src/lib/graph-node-menu.js.map +1 -1
- package/src/lib/graph-page-shell.d.ts +34 -0
- package/src/lib/graph-page-shell.js +121 -0
- package/src/lib/graph-page-shell.js.map +1 -0
- package/src/lib/graph-page-styles.d.ts +20 -0
- package/src/lib/graph-page-styles.js +144 -0
- package/src/lib/graph-page-styles.js.map +1 -0
- package/src/lib/graph-render-model.d.ts +14 -2
- package/src/lib/graph-render-model.js +19 -3
- package/src/lib/graph-render-model.js.map +1 -1
- package/src/lib/graph-responsibilities.js +1 -1
- package/src/lib/graph-responsibilities.js.map +1 -1
- package/src/lib/graph-visualizer.client.d.ts +65 -0
- package/src/lib/graph-visualizer.client.js +311 -7
- package/src/lib/graph-visualizer.client.js.map +1 -1
- package/src/lib/graph-visualizer.d.ts +19 -31
- package/src/lib/graph-visualizer.js +50 -286
- package/src/lib/graph-visualizer.js.map +1 -1
- package/src/lib/runtime-html-page.js +2 -2
- package/src/lib/runtime-html-page.js.map +1 -1
- package/src/lib/runtime-wiring/source-extractor.d.ts +2 -1
- package/src/lib/runtime-wiring/source-extractor.js +3 -2
- package/src/lib/runtime-wiring/source-extractor.js.map +1 -1
- package/src/lib/runtime-wiring/wiring-format.js +2 -2
- package/src/lib/runtime-wiring/wiring-format.js.map +1 -1
- package/src/rule-help.js +1 -1
- package/src/rule-help.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-filter.client.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/graph-filter.client.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,MAAM,YAAY;IAIe;IAHpB,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzC,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEnD,YAA6B,KAAsB;QAAtB,UAAK,GAAL,KAAK,CAAiB;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,I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,CAAC,2BAA2B,GAAG,CAAC,OAAO,2CAA2C,CAAC;IAChG,CAAC;CACJ","sourcesContent":["/** Plain browser helpers shared by architecture and runtime; no CommonJS imports. */\nclass WpGraphChain {\n readonly inNodes = new Map<string, Set<string>>();\n readonly outNodes = new Map<string, Set<string>>();\n\n constructor(private readonly model: RenderModelJson) {\n const ids = new Set(model.nodes.map((node) => node.id));\n for (const edge of model.edges) {\n if (!ids.has(edge.from) || !ids.has(edge.to)) continue;\n this.add(this.outNodes, edge.from, edge.to);\n this.add(this.inNodes, edge.to, edge.from);\n }\n }\n\n private add(map: Map<string, Set<string>>, from: string, to: string): void {\n if (!map.has(from)) map.set(from, new Set());\n map.get(from)?.add(to);\n }\n\n nodes(anchor: string): Set<string> {\n const retained = new Set<string>();\n if (!this.model.nodes.some((node) => node.id === anchor)) return retained;\n for (const direction of [this.inNodes, this.outNodes]) {\n const visited = new Set([anchor]);\n const stack = [anchor];\n while (stack.length > 0) {\n const id = stack.pop() as string;\n retained.add(id);\n for (const next of direction.get(id) ?? []) {\n if (visited.has(next)) continue;\n visited.add(next);\n stack.push(next);\n }\n }\n }\n return retained;\n }\n}\n\nclass WpRenderBand {\n constructor(\n readonly level: number,\n readonly nodeNames: string[],\n ) {}\n}\n\n/** Original records plus fresh ranks: removed nodes cannot reappear via a rank/edge. */\nclass WpFilteredDot {\n constructor(private readonly model: RenderModelJson) {}\n\n render(retained: Set<string>): string {\n const nodes = this.model.nodes.filter((node) => retained.has(node.id));\n const edges = this.model.edges.filter(\n (edge) => retained.has(edge.from) && retained.has(edge.to),\n );\n const bands = this.model.bands\n .map(\n (band) =>\n new WpRenderBand(\n band.level,\n band.nodeNames.filter((id) => retained.has(id)),\n ),\n )\n .filter((band) => band.nodeNames.length > 0);\n return (\n this.model.header +\n nodes.map((node) => node.dot).join('') +\n this.bandDot(bands) +\n edges.map((edge) => edge.dot).join('') +\n this.model.footer\n );\n }\n\n private bandDot(bands: WpRenderBand[]): string {\n const nodeAttrs =\n '[style=invis, shape=point, width=0.01, height=0.01, label=\"\", class=\"wp-layout\"]';\n const edgeAttrs = '[style=invis, class=\"wp-layout\"]';\n let dot = '';\n for (const band of bands) {\n const anchor = `__wp_layout_L${band.level}`;\n dot += ` \"${anchor}\" ${nodeAttrs};\\n { rank=same; \"${anchor}\"; `;\n dot += band.nodeNames.map((id) => `${JSON.stringify(id)}; `).join('') + '}\\n';\n }\n for (let i = 0; i + 1 < bands.length; i++) {\n const upper = bands[i];\n const lower = bands[i + 1];\n const from = `__wp_layout_L${upper.level}`;\n const to = `__wp_layout_L${lower.level}`;\n if (upper.nodeNames.length <= 10 && lower.nodeNames.length <= 10) {\n dot += ` \"${from}\" -> \"${to}\" ${edgeAttrs};\\n`;\n continue;\n }\n const spacer = `__wp_layout_spacer_L${upper.level}_L${lower.level}`;\n dot += ` \"${spacer}\" ${nodeAttrs};\\n { rank=same; \"${spacer}\"; }\\n`;\n dot += ` \"${from}\" -> \"${spacer}\" ${edgeAttrs};\\n \"${spacer}\" -> \"${to}\" ${edgeAttrs};\\n`;\n }\n return dot;\n }\n}\n\n/** Page-owned state survives replacements; rendering failures leave the usable SVG intact. */\nabstract class WpFilterPage {\n protected readonly chain: WpGraphChain;\n protected locked: string | null = null;\n protected anchor: string | null = null;\n protected retained: Set<string>;\n private viz: VizInstance | null = null;\n\n constructor(protected readonly model: RenderModelJson) {\n this.chain = new WpGraphChain(model);\n this.retained = new Set(model.nodes.map((node) => node.id));\n }\n\n render(): void {\n document\n .getElementById('wp-filter-off')\n ?.addEventListener('click', () => this.filter(null));\n this.wireControls();\n Viz.instance()\n .then((viz) => {\n this.viz = viz;\n this.filter(null);\n })\n // webpieces-disable no-any-unknown -- promise rejections may carry any JavaScript value\n .catch((err: unknown): void =>\n this.error(err instanceof Error ? err : new Error(String(err))),\n );\n }\n\n protected captureBinding(_svg: SVGSVGElement | null): () => void {\n return (): void => {};\n }\n protected wireControls(): void {}\n protected abstract wireSvg(svg: SVGSVGElement): void;\n protected prepareSvg(_svg: SVGSVGElement): void {}\n\n filterItem(name: string): WpNodeMenuItem {\n return new WpNodeMenuItem(\n this.anchor === null ? 'Filter Unconnected' : 'Turn off Filter',\n () => this.filter(this.anchor === null ? name : null),\n );\n }\n\n filter(anchor: string | null): void {\n if (this.viz === null) return;\n const host = document.getElementById('graph');\n if (host === null) return;\n const retained =\n anchor === null\n ? new Set(this.model.nodes.map((node) => node.id))\n : this.chain.nodes(anchor);\n const previousAnchor = this.anchor;\n const previousRetained = this.retained;\n const previousSvg = host.querySelector('svg');\n const focusName = WpNodeMenu.focusedName(previousSvg);\n const rollback = this.captureBinding(previousSvg);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- browser transaction restores the previous usable graph on failure\n try {\n const dot =\n anchor === null\n ? this.model.fullDot\n : new WpFilteredDot(this.model).render(retained);\n const svg = this.viz.renderSVGElement(dot);\n this.prepareSvg(svg);\n WpNodeMenu.close();\n this.anchor = anchor;\n this.retained = retained;\n host.replaceChildren(svg);\n this.wireSvg(svg);\n this.indicator();\n WpNodeMenu.restoreFocus(svg, focusName);\n this.error(null);\n // webpieces-disable no-any-unknown -- JavaScript may throw any value at this browser boundary\n } catch (err: unknown) {\n //const error = toError(err);\n this.anchor = previousAnchor;\n this.retained = previousRetained;\n if (previousSvg !== null) host.replaceChildren(previousSvg);\n else host.replaceChildren();\n rollback();\n if (previousSvg !== null) WpNodeMenu.restoreFocus(previousSvg, focusName);\n this.error(err instanceof Error ? err : new Error(String(err)));\n }\n }\n\n private indicator(): void {\n const status = document.getElementById('wp-filter-status');\n const label = document.getElementById('wp-filter-anchor');\n if (status !== null) status.hidden = this.anchor === null;\n if (label !== null) label.textContent = this.anchor;\n if (this.anchor !== null) document.getElementById('wp-filter-off')?.focus();\n else document.querySelector<SVGGElement>('#graph g.wp-node-clickable')?.focus();\n }\n\n private error(err: Error | null): void {\n const el = document.getElementById('wp-graph-error');\n if (el === null) return;\n el.hidden = err === null;\n el.textContent =\n err === null\n ? ''\n : `Graph rendering failed: ${err.message}. Try Turn off Filter or reload the page.`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"graph-filter.client.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/graph-filter.client.ts"],"names":[],"mappings":";AAAA,qFAAqF;AACrF,MAAM,YAAY;IAIe;IAHpB,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzC,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEnD,YAA6B,KAAsB;QAAtB,UAAK,GAAL,KAAK,CAAiB;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACxD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,SAAS;YACvD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC;IACL,CAAC;IAEO,GAAG,CAAC,GAA6B,EAAE,IAAY,EAAE,EAAU;QAC/D,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAC7C,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,MAAc;QA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;QACrD,IAAI,EAAE,KAAK,IAAI;YAAE,OAAO;QACxB,EAAE,CAAC,MAAM,GAAG,GAAG,KAAK,IAAI,CAAC;QACzB,EAAE,CAAC,WAAW;YACV,GAAG,KAAK,IAAI;gBACR,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,2BAA2B,GAAG,CAAC,OAAO,2CAA2C,CAAC;IAChG,CAAC;CACJ","sourcesContent":["/** Plain browser helpers shared by architecture and runtime; no CommonJS imports. */\nclass WpGraphChain {\n readonly inNodes = new Map<string, Set<string>>();\n readonly outNodes = new Map<string, Set<string>>();\n\n constructor(private readonly model: RenderModelJson) {\n const ids = new Set(model.nodes.map((node) => node.id));\n for (const edge of model.edges) {\n if (!ids.has(edge.from) || !ids.has(edge.to)) continue;\n this.add(this.outNodes, edge.from, edge.to);\n this.add(this.inNodes, edge.to, edge.from);\n }\n }\n\n private add(map: Map<string, Set<string>>, from: string, to: string): void {\n if (!map.has(from)) map.set(from, new Set());\n map.get(from)?.add(to);\n }\n\n nodes(anchor: string): Set<string> {\n const retained = new Set<string>();\n if (!this.model.nodes.some((node) => node.id === anchor)) return retained;\n for (const direction of [this.inNodes, this.outNodes]) {\n const visited = new Set([anchor]);\n const stack = [anchor];\n while (stack.length > 0) {\n const id = stack.pop() as string;\n retained.add(id);\n for (const next of direction.get(id) ?? []) {\n if (visited.has(next)) continue;\n visited.add(next);\n stack.push(next);\n }\n }\n }\n return retained;\n }\n}\n\nclass WpRenderBand {\n constructor(\n readonly level: number,\n readonly nodeNames: string[],\n ) {}\n}\n\n/** Original records plus fresh ranks: removed nodes cannot reappear via a rank/edge. */\nclass WpFilteredDot {\n constructor(private readonly model: RenderModelJson) {}\n\n /** `nodeDot` picks each box's statement — the architecture page passes its current color mode's. */\n render(\n retained: Set<string>,\n nodeDot: (node: RenderNodeJson) => string = (node: RenderNodeJson): string => node.dot,\n ): string {\n const nodes = this.model.nodes.filter((node: RenderNodeJson): boolean => retained.has(node.id));\n const edges = this.model.edges.filter(\n (edge) => retained.has(edge.from) && retained.has(edge.to),\n );\n const bands = this.model.bands\n .map(\n (band) =>\n new WpRenderBand(\n band.level,\n band.nodeNames.filter((id) => retained.has(id)),\n ),\n )\n .filter((band) => band.nodeNames.length > 0);\n return (\n this.model.header +\n nodes.map((node: RenderNodeJson): string => nodeDot(node)).join('') +\n this.bandDot(bands) +\n edges.map((edge) => edge.dot).join('') +\n this.model.footer\n );\n }\n\n private bandDot(bands: WpRenderBand[]): string {\n const nodeAttrs =\n '[style=invis, shape=point, width=0.01, height=0.01, label=\"\", class=\"wp-layout\"]';\n const edgeAttrs = '[style=invis, class=\"wp-layout\"]';\n let dot = '';\n for (const band of bands) {\n const anchor = `__wp_layout_L${band.level}`;\n dot += ` \"${anchor}\" ${nodeAttrs};\\n { rank=same; \"${anchor}\"; `;\n dot += band.nodeNames.map((id) => `${JSON.stringify(id)}; `).join('') + '}\\n';\n }\n for (let i = 0; i + 1 < bands.length; i++) {\n const upper = bands[i];\n const lower = bands[i + 1];\n const from = `__wp_layout_L${upper.level}`;\n const to = `__wp_layout_L${lower.level}`;\n if (upper.nodeNames.length <= 10 && lower.nodeNames.length <= 10) {\n dot += ` \"${from}\" -> \"${to}\" ${edgeAttrs};\\n`;\n continue;\n }\n const spacer = `__wp_layout_spacer_L${upper.level}_L${lower.level}`;\n dot += ` \"${spacer}\" ${nodeAttrs};\\n { rank=same; \"${spacer}\"; }\\n`;\n dot += ` \"${from}\" -> \"${spacer}\" ${edgeAttrs};\\n \"${spacer}\" -> \"${to}\" ${edgeAttrs};\\n`;\n }\n return dot;\n }\n}\n\n/** Page-owned state survives replacements; rendering failures leave the usable SVG intact. */\nabstract class WpFilterPage {\n protected readonly chain: WpGraphChain;\n protected locked: string | null = null;\n protected anchor: string | null = null;\n protected retained: Set<string>;\n private viz: VizInstance | null = null;\n\n constructor(protected readonly model: RenderModelJson) {\n this.chain = new WpGraphChain(model);\n this.retained = new Set(model.nodes.map((node) => node.id));\n }\n\n render(): void {\n document\n .getElementById('wp-filter-off')\n ?.addEventListener('click', () => this.filter(null));\n this.wireControls();\n Viz.instance()\n .then((viz) => {\n this.viz = viz;\n this.filter(null);\n })\n // webpieces-disable no-any-unknown -- promise rejections may carry any JavaScript value\n .catch((err: unknown): void =>\n this.error(err instanceof Error ? err : new Error(String(err))),\n );\n }\n\n protected captureBinding(_svg: SVGSVGElement | null): () => void {\n return (): void => {};\n }\n protected wireControls(): void {}\n protected abstract wireSvg(svg: SVGSVGElement): void;\n protected prepareSvg(_svg: SVGSVGElement): void {}\n /** The statement drawn for one box. The architecture page answers with its color mode's. */\n protected nodeDot(node: RenderNodeJson): string {\n return node.dot;\n }\n /** Whether an unfiltered draw may use the model's precomputed `fullDot` verbatim. */\n protected usesFullDot(): boolean {\n return true;\n }\n\n /**\n * Draw again with the current filter — after a color-mode switch. A control outside the graph\n * (a drawer button) keeps keyboard focus; the redraw would otherwise move it into the graph.\n */\n redraw(): void {\n const active = document.activeElement;\n const host = document.getElementById('graph');\n const outside = active instanceof HTMLElement && host !== null && !host.contains(active);\n this.filter(this.anchor);\n if (outside && active.isConnected) active.focus({ preventScroll: true });\n }\n\n filterItem(name: string): WpNodeMenuItem {\n return new WpNodeMenuItem(\n this.anchor === null ? 'Filter Unconnected' : 'Turn off Filter',\n () => this.filter(this.anchor === null ? name : null),\n );\n }\n\n filter(anchor: string | null): void {\n if (this.viz === null) return;\n const host = document.getElementById('graph');\n if (host === null) return;\n const retained =\n anchor === null\n ? new Set(this.model.nodes.map((node) => node.id))\n : this.chain.nodes(anchor);\n const previousAnchor = this.anchor;\n const previousRetained = this.retained;\n const previousSvg = host.querySelector('svg');\n const focusName = WpNodeMenu.focusedName(previousSvg);\n const rollback = this.captureBinding(previousSvg);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- browser transaction restores the previous usable graph on failure\n try {\n const dot =\n anchor === null && this.usesFullDot()\n ? this.model.fullDot\n : new WpFilteredDot(this.model).render(retained, (node: RenderNodeJson): string =>\n this.nodeDot(node),\n );\n const svg = this.viz.renderSVGElement(dot);\n this.prepareSvg(svg);\n WpNodeMenu.close();\n this.anchor = anchor;\n this.retained = retained;\n host.replaceChildren(svg);\n this.wireSvg(svg);\n this.indicator();\n WpNodeMenu.restoreFocus(svg, focusName);\n this.error(null);\n // webpieces-disable no-any-unknown -- JavaScript may throw any value at this browser boundary\n } catch (err: unknown) {\n //const error = toError(err);\n this.anchor = previousAnchor;\n this.retained = previousRetained;\n if (previousSvg !== null) host.replaceChildren(previousSvg);\n else host.replaceChildren();\n rollback();\n if (previousSvg !== null) WpNodeMenu.restoreFocus(previousSvg, focusName);\n this.error(err instanceof Error ? err : new Error(String(err)));\n }\n }\n\n private indicator(): void {\n const status = document.getElementById('wp-filter-status');\n const label = document.getElementById('wp-filter-anchor');\n if (status !== null) status.hidden = this.anchor === null;\n if (label !== null) label.textContent = this.anchor;\n if (this.anchor !== null) document.getElementById('wp-filter-off')?.focus();\n else document.querySelector<SVGGElement>('#graph g.wp-node-clickable')?.focus();\n }\n\n private error(err: Error | null): void {\n const el = document.getElementById('wp-graph-error');\n if (el === null) return;\n el.hidden = err === null;\n el.textContent =\n err === null\n ? ''\n : `Graph rendering failed: ${err.message}. Try Turn off Filter or reload the page.`;\n }\n}\n"]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Impact mode's data: what THIS BRANCH's build looks like, in three shades (plus untouched grey).
|
|
3
|
+
*
|
|
4
|
+
* - BUILD INPUT is every transitive dependency of the affected set that is not itself affected:
|
|
5
|
+
* `ci` dependsOn `^build`, so they must exist as build output though their inputs did not change.
|
|
6
|
+
* nx restores them from cache when it has them and compiles them otherwise — which one happens is
|
|
7
|
+
* not knowable here, so nothing claims it. A pure downward walk over the graph's own edges.
|
|
8
|
+
*
|
|
9
|
+
* - AFFECTED is `nx show projects --affected --base=<fork point> --json`, with NO `--head`, so
|
|
10
|
+
* uncommitted and untracked work counts. nx already gets right everything a hand-rolled diff gets
|
|
11
|
+
* wrong: lockfile and package.json changes resolved per project, root/global inputs, namedInputs,
|
|
12
|
+
* implicitDependencies, nested roots and deleted files. This uses its public CLI surface only, never
|
|
13
|
+
* nx internals.
|
|
14
|
+
* - TOUCHED is the subset of that set which OWNS a changed file, by nx's own file-to-project
|
|
15
|
+
* ownership (the project file map from `createProjectFileMapUsingProjectGraph`, public devkit API)
|
|
16
|
+
* — never a path-prefix guess. A project whose only change is a DELETED file is not in that map
|
|
17
|
+
* (the file is gone), so it shows as affected rather than touched.
|
|
18
|
+
*
|
|
19
|
+
* The base is the repo's existing merge-base computation (`DiffScope.detectBase` in rules-config:
|
|
20
|
+
* `git merge-base HEAD origin/main`, falling back to `main`) — never NX_BASE/NX_HEAD, whose value
|
|
21
|
+
* depends on whoever launched the process. The changed-file list is `DiffScope.getChangedFiles`, the
|
|
22
|
+
* same base→working-tree diff (with untracked files) every code rule uses.
|
|
23
|
+
*
|
|
24
|
+
* The answer changes per branch, so it never goes into the committed dependencies.html or
|
|
25
|
+
* dependencies.json (both stay byte-stable across branches). It goes into a SIDECAR,
|
|
26
|
+
* `architecture/.impact/dependencies.impact.js`: a plain script setting one window global, loaded
|
|
27
|
+
* with `<script src>` — the one way a page opened straight from disk (file://) can read a
|
|
28
|
+
* neighbouring file. The directory carries its own `.gitignore` containing `*`, which ignores the
|
|
29
|
+
* directory and everything in it, so a consumer repo needs no gitignore edit and the PR gate's
|
|
30
|
+
* "build left nothing uncommitted" check never sees it.
|
|
31
|
+
*
|
|
32
|
+
* Impact is a convenience. When nx or git cannot answer, NO sidecar is written (a stale one is
|
|
33
|
+
* removed) and the page disables Impact with a one-line reason. It never fails generation.
|
|
34
|
+
*/
|
|
35
|
+
import { DiffScope } from '@webpieces/rules-config';
|
|
36
|
+
import type { EnhancedGraph } from './graph-sorter';
|
|
37
|
+
/** Relative to the architecture/ directory the page lives in; the page's `<script src>`. */
|
|
38
|
+
export declare const IMPACT_SIDECAR_DIR = ".impact";
|
|
39
|
+
export declare const IMPACT_SIDECAR_FILE = "dependencies.impact.js";
|
|
40
|
+
export declare const IMPACT_SIDECAR_SRC = ".impact/dependencies.impact.js";
|
|
41
|
+
/** What the sidecar carries; the page reads it as `window.__WP_IMPACT__`. */
|
|
42
|
+
export declare class ImpactReport {
|
|
43
|
+
readonly available: boolean;
|
|
44
|
+
readonly reason: string;
|
|
45
|
+
readonly base: string;
|
|
46
|
+
/** Affected AND owning a changed file (node ids). */
|
|
47
|
+
readonly touched: string[];
|
|
48
|
+
/** Affected but owning no changed file (node ids): their ci re-runs. */
|
|
49
|
+
readonly affected: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Transitive dependencies of the affected set that are NOT affected (node ids). `ci` dependsOn
|
|
52
|
+
* `^build`, so they must exist as build output although their inputs did not change: nx
|
|
53
|
+
* restores them from cache when it has them and compiles them otherwise. Which of the two
|
|
54
|
+
* happens is not knowable here, so the page claims neither.
|
|
55
|
+
*/
|
|
56
|
+
readonly buildInputs: string[];
|
|
57
|
+
readonly changedFiles: number;
|
|
58
|
+
constructor(available: boolean, reason: string, base: string,
|
|
59
|
+
/** Affected AND owning a changed file (node ids). */
|
|
60
|
+
touched: string[],
|
|
61
|
+
/** Affected but owning no changed file (node ids): their ci re-runs. */
|
|
62
|
+
affected: string[],
|
|
63
|
+
/**
|
|
64
|
+
* Transitive dependencies of the affected set that are NOT affected (node ids). `ci` dependsOn
|
|
65
|
+
* `^build`, so they must exist as build output although their inputs did not change: nx
|
|
66
|
+
* restores them from cache when it has them and compiles them otherwise. Which of the two
|
|
67
|
+
* happens is not knowable here, so the page claims neither.
|
|
68
|
+
*/
|
|
69
|
+
buildInputs: string[], changedFiles: number);
|
|
70
|
+
}
|
|
71
|
+
/** A scan that could not produce an answer: no sidecar is written, only this reason printed. */
|
|
72
|
+
export declare class ImpactUnavailable {
|
|
73
|
+
readonly reason: string;
|
|
74
|
+
constructor(reason: string);
|
|
75
|
+
}
|
|
76
|
+
/** Runs the workspace's own nx CLI. Injected so specs never spawn nx. */
|
|
77
|
+
export declare class NxCli {
|
|
78
|
+
/** stdout, or null when nx cannot be found, exits non-zero or exceeds the timeout. */
|
|
79
|
+
run(workspaceRoot: string, args: string[], timeoutMs: number): string | null;
|
|
80
|
+
/** Resolved the way node would from the workspace, so a linked worktree finds its main tree's nx. */
|
|
81
|
+
private binary;
|
|
82
|
+
}
|
|
83
|
+
/** nx's own file → project ownership, from the public devkit file map. Injected for specs. */
|
|
84
|
+
export declare class ProjectFileOwners {
|
|
85
|
+
owners(): Promise<Map<string, string>>;
|
|
86
|
+
}
|
|
87
|
+
export declare class NxImpactScanner {
|
|
88
|
+
private readonly diffScope;
|
|
89
|
+
private readonly nx;
|
|
90
|
+
private readonly ownership;
|
|
91
|
+
private readonly names;
|
|
92
|
+
constructor(diffScope?: DiffScope, nx?: NxCli, ownership?: ProjectFileOwners);
|
|
93
|
+
scan(workspaceRoot: string, graph: EnhancedGraph): Promise<ImpactReport | ImpactUnavailable>;
|
|
94
|
+
/** A pure downward walk over the graph's own dependsOn edges: no nx call. */
|
|
95
|
+
buildInputs(affected: string[], graph: EnhancedGraph): string[];
|
|
96
|
+
/** Affected projects that own one of the changed files, by nx's own ownership. */
|
|
97
|
+
touched(affected: string[], files: string[], owners: Map<string, string>): string[];
|
|
98
|
+
/** The JSON list, narrowed to projects the graph draws; null when it is not a list of names. */
|
|
99
|
+
parse(json: string, graph: EnhancedGraph): string[] | null;
|
|
100
|
+
/** Ownership failing is not fatal: the set then shows in one shade, all "affected". */
|
|
101
|
+
private owners;
|
|
102
|
+
private ids;
|
|
103
|
+
}
|
|
104
|
+
/** Writes (or removes) the sidecar, self-ignored, beside architecture/dependencies.html. */
|
|
105
|
+
export declare class ImpactSidecar {
|
|
106
|
+
/** Never throws: a sidecar that cannot be written just leaves Impact disabled on the page. */
|
|
107
|
+
write(architectureDir: string, report: ImpactReport): string | null;
|
|
108
|
+
/** A stale sidecar from an earlier branch must never be shown as this branch's impact. */
|
|
109
|
+
remove(architectureDir: string): void;
|
|
110
|
+
script(report: ImpactReport): string;
|
|
111
|
+
}
|
|
112
|
+
/** The generator's one call: scan, write, and report the result and its cost in one line. */
|
|
113
|
+
export declare class ImpactRefresh {
|
|
114
|
+
private readonly scanner;
|
|
115
|
+
private readonly sidecar;
|
|
116
|
+
constructor(scanner?: NxImpactScanner, sidecar?: ImpactSidecar);
|
|
117
|
+
/** Never throws — Impact is optional, generation is not. */
|
|
118
|
+
run(architectureDir: string, workspaceRoot: string, graph: EnhancedGraph): Promise<string>;
|
|
119
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Impact mode's data: what THIS BRANCH's build looks like, in three shades (plus untouched grey).
|
|
4
|
+
*
|
|
5
|
+
* - BUILD INPUT is every transitive dependency of the affected set that is not itself affected:
|
|
6
|
+
* `ci` dependsOn `^build`, so they must exist as build output though their inputs did not change.
|
|
7
|
+
* nx restores them from cache when it has them and compiles them otherwise — which one happens is
|
|
8
|
+
* not knowable here, so nothing claims it. A pure downward walk over the graph's own edges.
|
|
9
|
+
*
|
|
10
|
+
* - AFFECTED is `nx show projects --affected --base=<fork point> --json`, with NO `--head`, so
|
|
11
|
+
* uncommitted and untracked work counts. nx already gets right everything a hand-rolled diff gets
|
|
12
|
+
* wrong: lockfile and package.json changes resolved per project, root/global inputs, namedInputs,
|
|
13
|
+
* implicitDependencies, nested roots and deleted files. This uses its public CLI surface only, never
|
|
14
|
+
* nx internals.
|
|
15
|
+
* - TOUCHED is the subset of that set which OWNS a changed file, by nx's own file-to-project
|
|
16
|
+
* ownership (the project file map from `createProjectFileMapUsingProjectGraph`, public devkit API)
|
|
17
|
+
* — never a path-prefix guess. A project whose only change is a DELETED file is not in that map
|
|
18
|
+
* (the file is gone), so it shows as affected rather than touched.
|
|
19
|
+
*
|
|
20
|
+
* The base is the repo's existing merge-base computation (`DiffScope.detectBase` in rules-config:
|
|
21
|
+
* `git merge-base HEAD origin/main`, falling back to `main`) — never NX_BASE/NX_HEAD, whose value
|
|
22
|
+
* depends on whoever launched the process. The changed-file list is `DiffScope.getChangedFiles`, the
|
|
23
|
+
* same base→working-tree diff (with untracked files) every code rule uses.
|
|
24
|
+
*
|
|
25
|
+
* The answer changes per branch, so it never goes into the committed dependencies.html or
|
|
26
|
+
* dependencies.json (both stay byte-stable across branches). It goes into a SIDECAR,
|
|
27
|
+
* `architecture/.impact/dependencies.impact.js`: a plain script setting one window global, loaded
|
|
28
|
+
* with `<script src>` — the one way a page opened straight from disk (file://) can read a
|
|
29
|
+
* neighbouring file. The directory carries its own `.gitignore` containing `*`, which ignores the
|
|
30
|
+
* directory and everything in it, so a consumer repo needs no gitignore edit and the PR gate's
|
|
31
|
+
* "build left nothing uncommitted" check never sees it.
|
|
32
|
+
*
|
|
33
|
+
* Impact is a convenience. When nx or git cannot answer, NO sidecar is written (a stale one is
|
|
34
|
+
* removed) and the page disables Impact with a one-line reason. It never fails generation.
|
|
35
|
+
*/
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.ImpactRefresh = exports.ImpactSidecar = exports.NxImpactScanner = exports.ProjectFileOwners = exports.NxCli = exports.ImpactUnavailable = exports.ImpactReport = exports.IMPACT_SIDECAR_SRC = exports.IMPACT_SIDECAR_FILE = exports.IMPACT_SIDECAR_DIR = void 0;
|
|
38
|
+
const tslib_1 = require("tslib");
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
40
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
41
|
+
const path = tslib_1.__importStar(require("path"));
|
|
42
|
+
const devkit_1 = require("@nx/devkit");
|
|
43
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
44
|
+
const graph_names_1 = require("./graph-names");
|
|
45
|
+
const toError_1 = require("../toError");
|
|
46
|
+
/** Relative to the architecture/ directory the page lives in; the page's `<script src>`. */
|
|
47
|
+
exports.IMPACT_SIDECAR_DIR = '.impact';
|
|
48
|
+
exports.IMPACT_SIDECAR_FILE = 'dependencies.impact.js';
|
|
49
|
+
exports.IMPACT_SIDECAR_SRC = `${exports.IMPACT_SIDECAR_DIR}/${exports.IMPACT_SIDECAR_FILE}`;
|
|
50
|
+
/** The nx call is capped; a slow or wedged nx disables Impact instead of stalling generation. */
|
|
51
|
+
const NX_TIMEOUT_MS = 15000;
|
|
52
|
+
/** What the sidecar carries; the page reads it as `window.__WP_IMPACT__`. */
|
|
53
|
+
class ImpactReport {
|
|
54
|
+
available;
|
|
55
|
+
reason;
|
|
56
|
+
base;
|
|
57
|
+
touched;
|
|
58
|
+
affected;
|
|
59
|
+
buildInputs;
|
|
60
|
+
changedFiles;
|
|
61
|
+
constructor(available, reason, base,
|
|
62
|
+
/** Affected AND owning a changed file (node ids). */
|
|
63
|
+
touched,
|
|
64
|
+
/** Affected but owning no changed file (node ids): their ci re-runs. */
|
|
65
|
+
affected,
|
|
66
|
+
/**
|
|
67
|
+
* Transitive dependencies of the affected set that are NOT affected (node ids). `ci` dependsOn
|
|
68
|
+
* `^build`, so they must exist as build output although their inputs did not change: nx
|
|
69
|
+
* restores them from cache when it has them and compiles them otherwise. Which of the two
|
|
70
|
+
* happens is not knowable here, so the page claims neither.
|
|
71
|
+
*/
|
|
72
|
+
buildInputs, changedFiles) {
|
|
73
|
+
this.available = available;
|
|
74
|
+
this.reason = reason;
|
|
75
|
+
this.base = base;
|
|
76
|
+
this.touched = touched;
|
|
77
|
+
this.affected = affected;
|
|
78
|
+
this.buildInputs = buildInputs;
|
|
79
|
+
this.changedFiles = changedFiles;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ImpactReport = ImpactReport;
|
|
83
|
+
/** A scan that could not produce an answer: no sidecar is written, only this reason printed. */
|
|
84
|
+
class ImpactUnavailable {
|
|
85
|
+
reason;
|
|
86
|
+
constructor(reason) {
|
|
87
|
+
this.reason = reason;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.ImpactUnavailable = ImpactUnavailable;
|
|
91
|
+
/** Runs the workspace's own nx CLI. Injected so specs never spawn nx. */
|
|
92
|
+
class NxCli {
|
|
93
|
+
/** stdout, or null when nx cannot be found, exits non-zero or exceeds the timeout. */
|
|
94
|
+
run(workspaceRoot, args, timeoutMs) {
|
|
95
|
+
const bin = this.binary(workspaceRoot);
|
|
96
|
+
if (bin === null)
|
|
97
|
+
return null;
|
|
98
|
+
const result = (0, child_process_1.spawnSync)(process.execPath, [bin, ...args], {
|
|
99
|
+
cwd: workspaceRoot,
|
|
100
|
+
encoding: 'utf8',
|
|
101
|
+
timeout: timeoutMs,
|
|
102
|
+
stdio: 'pipe',
|
|
103
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
104
|
+
});
|
|
105
|
+
if (result.error !== undefined || result.status !== 0)
|
|
106
|
+
return null;
|
|
107
|
+
return result.stdout;
|
|
108
|
+
}
|
|
109
|
+
/** Resolved the way node would from the workspace, so a linked worktree finds its main tree's nx. */
|
|
110
|
+
binary(workspaceRoot) {
|
|
111
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- a workspace without nx resolves nothing; that is an answer, not an error
|
|
112
|
+
try {
|
|
113
|
+
return require.resolve('nx/bin/nx.js', { paths: [workspaceRoot] });
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
const error = (0, toError_1.toError)(err);
|
|
117
|
+
void error; // no nx installed here — Impact is simply unavailable
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.NxCli = NxCli;
|
|
123
|
+
/** nx's own file → project ownership, from the public devkit file map. Injected for specs. */
|
|
124
|
+
class ProjectFileOwners {
|
|
125
|
+
async owners() {
|
|
126
|
+
const fileMap = await (0, devkit_1.createProjectFileMapUsingProjectGraph)(await (0, devkit_1.createProjectGraphAsync)());
|
|
127
|
+
const owners = new Map();
|
|
128
|
+
for (const project of Object.keys(fileMap)) {
|
|
129
|
+
for (const data of fileMap[project])
|
|
130
|
+
owners.set(data.file, project);
|
|
131
|
+
}
|
|
132
|
+
return owners;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.ProjectFileOwners = ProjectFileOwners;
|
|
136
|
+
class NxImpactScanner {
|
|
137
|
+
diffScope;
|
|
138
|
+
nx;
|
|
139
|
+
ownership;
|
|
140
|
+
names = new graph_names_1.GraphNames();
|
|
141
|
+
constructor(diffScope = new rules_config_1.DiffScope(), nx = new NxCli(), ownership = new ProjectFileOwners()) {
|
|
142
|
+
this.diffScope = diffScope;
|
|
143
|
+
this.nx = nx;
|
|
144
|
+
this.ownership = ownership;
|
|
145
|
+
}
|
|
146
|
+
async scan(workspaceRoot, graph) {
|
|
147
|
+
const base = this.diffScope.detectBase(workspaceRoot);
|
|
148
|
+
if (base === null)
|
|
149
|
+
return new ImpactUnavailable('no fork point: neither origin/main nor main resolves (or git is unavailable)');
|
|
150
|
+
const json = this.nx.run(workspaceRoot, ['show', 'projects', '--affected', `--base=${base}`, '--json'], NX_TIMEOUT_MS);
|
|
151
|
+
if (json === null)
|
|
152
|
+
return new ImpactUnavailable(`nx show projects --affected failed or took over ${NX_TIMEOUT_MS / 1000}s`);
|
|
153
|
+
const affectedSet = this.parse(json, graph);
|
|
154
|
+
if (affectedSet === null)
|
|
155
|
+
return new ImpactUnavailable('nx show projects --affected printed something other than a JSON list');
|
|
156
|
+
const options = new rules_config_1.ChangedFilesOptions();
|
|
157
|
+
options.tsOnly = false;
|
|
158
|
+
options.includeDeletions = true;
|
|
159
|
+
const files = this.diffScope.getChangedFiles(workspaceRoot, base, undefined, options);
|
|
160
|
+
const short = base.slice(0, 7);
|
|
161
|
+
if (affectedSet.length === 0)
|
|
162
|
+
return new ImpactReport(false, `nothing affected since the fork point ${short}`, short, [], [], [], files.length);
|
|
163
|
+
const touched = this.touched(affectedSet, files, await this.owners());
|
|
164
|
+
const rest = affectedSet.filter((project) => !touched.includes(project));
|
|
165
|
+
const inputs = this.buildInputs(affectedSet, graph);
|
|
166
|
+
return new ImpactReport(true, '', short, this.ids(touched), this.ids(rest), this.ids(inputs), files.length);
|
|
167
|
+
}
|
|
168
|
+
/** A pure downward walk over the graph's own dependsOn edges: no nx call. */
|
|
169
|
+
buildInputs(affected, graph) {
|
|
170
|
+
const inSet = new Set(affected);
|
|
171
|
+
const seen = new Set(affected);
|
|
172
|
+
const stack = [...affected];
|
|
173
|
+
const inputs = [];
|
|
174
|
+
while (stack.length > 0) {
|
|
175
|
+
const project = stack.pop();
|
|
176
|
+
for (const dep of graph[project]?.dependsOn ?? []) {
|
|
177
|
+
if (seen.has(dep))
|
|
178
|
+
continue;
|
|
179
|
+
seen.add(dep);
|
|
180
|
+
stack.push(dep);
|
|
181
|
+
if (!inSet.has(dep) && graph[dep] !== undefined)
|
|
182
|
+
inputs.push(dep);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return inputs.sort();
|
|
186
|
+
}
|
|
187
|
+
/** Affected projects that own one of the changed files, by nx's own ownership. */
|
|
188
|
+
touched(affected, files, owners) {
|
|
189
|
+
const owning = new Set();
|
|
190
|
+
for (const file of files) {
|
|
191
|
+
const owner = owners.get(file);
|
|
192
|
+
if (owner !== undefined)
|
|
193
|
+
owning.add(owner);
|
|
194
|
+
}
|
|
195
|
+
return affected.filter((project) => owning.has(project));
|
|
196
|
+
}
|
|
197
|
+
/** The JSON list, narrowed to projects the graph draws; null when it is not a list of names. */
|
|
198
|
+
parse(json, graph) {
|
|
199
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- untrusted CLI output; anything unparseable is reported as a reason
|
|
200
|
+
try {
|
|
201
|
+
// webpieces-disable no-any-unknown -- CLI JSON is untrusted until narrowed below
|
|
202
|
+
const parsed = JSON.parse(json);
|
|
203
|
+
if (!Array.isArray(parsed))
|
|
204
|
+
return null;
|
|
205
|
+
return parsed
|
|
206
|
+
.filter((name) => typeof name === 'string' && graph[name] !== undefined)
|
|
207
|
+
.sort();
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
const error = (0, toError_1.toError)(err);
|
|
211
|
+
void error; // not JSON — the caller reports it
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** Ownership failing is not fatal: the set then shows in one shade, all "affected". */
|
|
216
|
+
async owners() {
|
|
217
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- the second shade is optional
|
|
218
|
+
try {
|
|
219
|
+
return await this.ownership.owners();
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
const error = (0, toError_1.toError)(err);
|
|
223
|
+
console.warn(`⚠️ Impact: nx file ownership unavailable (${error.message}); showing one shade`);
|
|
224
|
+
return new Map();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
ids(projects) {
|
|
228
|
+
return projects.map((project) => this.names.getNodeId(project));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.NxImpactScanner = NxImpactScanner;
|
|
232
|
+
/** Writes (or removes) the sidecar, self-ignored, beside architecture/dependencies.html. */
|
|
233
|
+
class ImpactSidecar {
|
|
234
|
+
/** Never throws: a sidecar that cannot be written just leaves Impact disabled on the page. */
|
|
235
|
+
write(architectureDir, report) {
|
|
236
|
+
const dir = path.join(architectureDir, exports.IMPACT_SIDECAR_DIR);
|
|
237
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- impact is optional; a write failure must never fail generation
|
|
238
|
+
try {
|
|
239
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
240
|
+
fs.writeFileSync(path.join(dir, '.gitignore'), '# Written by architecture:generate. Per-branch data: never commit it.\n*\n', 'utf-8');
|
|
241
|
+
const file = path.join(dir, exports.IMPACT_SIDECAR_FILE);
|
|
242
|
+
fs.writeFileSync(file, this.script(report), 'utf-8');
|
|
243
|
+
return file;
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
const error = (0, toError_1.toError)(err);
|
|
247
|
+
console.warn(`⚠️ Could not write the impact sidecar: ${error.message}`);
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** A stale sidecar from an earlier branch must never be shown as this branch's impact. */
|
|
252
|
+
remove(architectureDir) {
|
|
253
|
+
fs.rmSync(path.join(architectureDir, exports.IMPACT_SIDECAR_DIR, exports.IMPACT_SIDECAR_FILE), { force: true });
|
|
254
|
+
}
|
|
255
|
+
script(report) {
|
|
256
|
+
const json = JSON.stringify(report).replace(/</g, '\\u003c');
|
|
257
|
+
return `// Generated by architecture:generate for one branch. Gitignored; do not commit.\nwindow.__WP_IMPACT__ = ${json};\n`;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
exports.ImpactSidecar = ImpactSidecar;
|
|
261
|
+
/** The generator's one call: scan, write, and report the result and its cost in one line. */
|
|
262
|
+
class ImpactRefresh {
|
|
263
|
+
scanner;
|
|
264
|
+
sidecar;
|
|
265
|
+
constructor(scanner = new NxImpactScanner(), sidecar = new ImpactSidecar()) {
|
|
266
|
+
this.scanner = scanner;
|
|
267
|
+
this.sidecar = sidecar;
|
|
268
|
+
}
|
|
269
|
+
/** Never throws — Impact is optional, generation is not. */
|
|
270
|
+
async run(architectureDir, workspaceRoot, graph) {
|
|
271
|
+
const started = Date.now();
|
|
272
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- impact is optional; any failure becomes a reason, never a failed generation
|
|
273
|
+
try {
|
|
274
|
+
const report = await this.scanner.scan(workspaceRoot, graph);
|
|
275
|
+
const cost = `${Date.now() - started} ms`;
|
|
276
|
+
if (report instanceof ImpactUnavailable) {
|
|
277
|
+
this.sidecar.remove(architectureDir);
|
|
278
|
+
return `ℹ️ Impact disabled, no sidecar written: ${report.reason} (${cost})`;
|
|
279
|
+
}
|
|
280
|
+
const file = this.sidecar.write(architectureDir, report);
|
|
281
|
+
if (file === null)
|
|
282
|
+
return `⚠️ Impact sidecar not written (${cost})`;
|
|
283
|
+
if (!report.available)
|
|
284
|
+
return `ℹ️ Impact disabled on the page: ${report.reason} (${cost})`;
|
|
285
|
+
return (`✅ Impact vs ${report.base}: ${report.touched.length} touched · ${report.affected.length} affected · ` +
|
|
286
|
+
`${report.buildInputs.length} build inputs, from ${report.changedFiles} changed file(s) (${cost}) → ${file}`);
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
const error = (0, toError_1.toError)(err);
|
|
290
|
+
return `⚠️ Impact skipped: ${error.message}`;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
exports.ImpactRefresh = ImpactRefresh;
|
|
295
|
+
//# sourceMappingURL=graph-impact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-impact.js","sourceRoot":"","sources":["../../../../../../packages/tooling/nx-webpieces-rules/src/lib/graph-impact.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;;;AAEH,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,uCAA4F;AAC5F,0DAAyE;AAEzE,+CAA2C;AAC3C,wCAAqC;AAErC,4FAA4F;AAC/E,QAAA,kBAAkB,GAAG,SAAS,CAAC;AAC/B,QAAA,mBAAmB,GAAG,wBAAwB,CAAC;AAC/C,QAAA,kBAAkB,GAAG,GAAG,0BAAkB,IAAI,2BAAmB,EAAE,CAAC;AACjF,iGAAiG;AACjG,MAAM,aAAa,GAAG,KAAK,CAAC;AAE5B,6EAA6E;AAC7E,MAAa,YAAY;IAED;IACA;IACA;IAEA;IAEA;IAOA;IACA;IAfpB,YACoB,SAAkB,EAClB,MAAc,EACd,IAAY;IAC5B,qDAAqD;IACrC,OAAiB;IACjC,wEAAwE;IACxD,QAAkB;IAClC;;;;;OAKG;IACa,WAAqB,EACrB,YAAoB;QAdpB,cAAS,GAAT,SAAS,CAAS;QAClB,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QAEZ,YAAO,GAAP,OAAO,CAAU;QAEjB,aAA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YAAY,qBAAqB,IAAI,OAAO,IAAI,EAAE,CAC/G,CAAC;QACN,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,OAAO,uBAAuB,KAAK,CAAC,OAAO,EAAE,CAAC;QAClD,CAAC;IACL,CAAC;CACJ;AA7BD,sCA6BC","sourcesContent":["/**\n * Impact mode's data: what THIS BRANCH's build looks like, in three shades (plus untouched grey).\n *\n * - BUILD INPUT is every transitive dependency of the affected set that is not itself affected:\n * `ci` dependsOn `^build`, so they must exist as build output though their inputs did not change.\n * nx restores them from cache when it has them and compiles them otherwise — which one happens is\n * not knowable here, so nothing claims it. A pure downward walk over the graph's own edges.\n *\n * - AFFECTED is `nx show projects --affected --base=<fork point> --json`, with NO `--head`, so\n * uncommitted and untracked work counts. nx already gets right everything a hand-rolled diff gets\n * wrong: lockfile and package.json changes resolved per project, root/global inputs, namedInputs,\n * implicitDependencies, nested roots and deleted files. This uses its public CLI surface only, never\n * nx internals.\n * - TOUCHED is the subset of that set which OWNS a changed file, by nx's own file-to-project\n * ownership (the project file map from `createProjectFileMapUsingProjectGraph`, public devkit API)\n * — never a path-prefix guess. A project whose only change is a DELETED file is not in that map\n * (the file is gone), so it shows as affected rather than touched.\n *\n * The base is the repo's existing merge-base computation (`DiffScope.detectBase` in rules-config:\n * `git merge-base HEAD origin/main`, falling back to `main`) — never NX_BASE/NX_HEAD, whose value\n * depends on whoever launched the process. The changed-file list is `DiffScope.getChangedFiles`, the\n * same base→working-tree diff (with untracked files) every code rule uses.\n *\n * The answer changes per branch, so it never goes into the committed dependencies.html or\n * dependencies.json (both stay byte-stable across branches). It goes into a SIDECAR,\n * `architecture/.impact/dependencies.impact.js`: a plain script setting one window global, loaded\n * with `<script src>` — the one way a page opened straight from disk (file://) can read a\n * neighbouring file. The directory carries its own `.gitignore` containing `*`, which ignores the\n * directory and everything in it, so a consumer repo needs no gitignore edit and the PR gate's\n * \"build left nothing uncommitted\" check never sees it.\n *\n * Impact is a convenience. When nx or git cannot answer, NO sidecar is written (a stale one is\n * removed) and the page disables Impact with a one-line reason. It never fails generation.\n */\n\nimport { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { createProjectFileMapUsingProjectGraph, createProjectGraphAsync } from '@nx/devkit';\nimport { DiffScope, ChangedFilesOptions } from '@webpieces/rules-config';\nimport type { EnhancedGraph } from './graph-sorter';\nimport { GraphNames } from './graph-names';\nimport { toError } from '../toError';\n\n/** Relative to the architecture/ directory the page lives in; the page's `<script src>`. */\nexport const IMPACT_SIDECAR_DIR = '.impact';\nexport const IMPACT_SIDECAR_FILE = 'dependencies.impact.js';\nexport const IMPACT_SIDECAR_SRC = `${IMPACT_SIDECAR_DIR}/${IMPACT_SIDECAR_FILE}`;\n/** The nx call is capped; a slow or wedged nx disables Impact instead of stalling generation. */\nconst NX_TIMEOUT_MS = 15000;\n\n/** What the sidecar carries; the page reads it as `window.__WP_IMPACT__`. */\nexport class ImpactReport {\n constructor(\n public readonly available: boolean,\n public readonly reason: string,\n public readonly base: string,\n /** Affected AND owning a changed file (node ids). */\n public readonly touched: string[],\n /** Affected but owning no changed file (node ids): their ci re-runs. */\n public readonly affected: string[],\n /**\n * Transitive dependencies of the affected set that are NOT affected (node ids). `ci` dependsOn\n * `^build`, so they must exist as build output although their inputs did not change: nx\n * restores them from cache when it has them and compiles them otherwise. Which of the two\n * happens is not knowable here, so the page claims neither.\n */\n public readonly buildInputs: string[],\n public readonly changedFiles: number,\n ) {}\n}\n\n/** A scan that could not produce an answer: no sidecar is written, only this reason printed. */\nexport class ImpactUnavailable {\n constructor(public readonly reason: string) {}\n}\n\n/** Runs the workspace's own nx CLI. Injected so specs never spawn nx. */\nexport class NxCli {\n /** stdout, or null when nx cannot be found, exits non-zero or exceeds the timeout. */\n run(workspaceRoot: string, args: string[], timeoutMs: number): string | null {\n const bin = this.binary(workspaceRoot);\n if (bin === null) return null;\n const result = spawnSync(process.execPath, [bin, ...args], {\n cwd: workspaceRoot,\n encoding: 'utf8',\n timeout: timeoutMs,\n stdio: 'pipe',\n maxBuffer: 16 * 1024 * 1024,\n });\n if (result.error !== undefined || result.status !== 0) return null;\n return result.stdout;\n }\n\n /** Resolved the way node would from the workspace, so a linked worktree finds its main tree's nx. */\n private binary(workspaceRoot: string): string | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- a workspace without nx resolves nothing; that is an answer, not an error\n try {\n return require.resolve('nx/bin/nx.js', { paths: [workspaceRoot] });\n } catch (err: unknown) {\n const error = toError(err);\n void error; // no nx installed here — Impact is simply unavailable\n return null;\n }\n }\n}\n\n/** nx's own file → project ownership, from the public devkit file map. Injected for specs. */\nexport class ProjectFileOwners {\n async owners(): Promise<Map<string, string>> {\n const fileMap = await createProjectFileMapUsingProjectGraph(await createProjectGraphAsync());\n const owners = new Map<string, string>();\n for (const project of Object.keys(fileMap)) {\n for (const data of fileMap[project]) owners.set(data.file, project);\n }\n return owners;\n }\n}\n\nexport class NxImpactScanner {\n private readonly names = new GraphNames();\n\n constructor(\n private readonly diffScope: DiffScope = new DiffScope(),\n private readonly nx: NxCli = new NxCli(),\n private readonly ownership: ProjectFileOwners = new ProjectFileOwners(),\n ) {}\n\n async scan(workspaceRoot: string, graph: EnhancedGraph): Promise<ImpactReport | ImpactUnavailable> {\n const base = this.diffScope.detectBase(workspaceRoot);\n if (base === null) return new ImpactUnavailable('no fork point: neither origin/main nor main resolves (or git is unavailable)');\n const json = this.nx.run(workspaceRoot, ['show', 'projects', '--affected', `--base=${base}`, '--json'], NX_TIMEOUT_MS);\n if (json === null) return new ImpactUnavailable(`nx show projects --affected failed or took over ${NX_TIMEOUT_MS / 1000}s`);\n const affectedSet = this.parse(json, graph);\n if (affectedSet === null) return new ImpactUnavailable('nx show projects --affected printed something other than a JSON list');\n const options = new ChangedFilesOptions();\n options.tsOnly = false;\n options.includeDeletions = true;\n const files = this.diffScope.getChangedFiles(workspaceRoot, base, undefined, options);\n const short = base.slice(0, 7);\n if (affectedSet.length === 0)\n return new ImpactReport(false, `nothing affected since the fork point ${short}`, short, [], [], [], files.length);\n const touched = this.touched(affectedSet, files, await this.owners());\n const rest = affectedSet.filter((project: string): boolean => !touched.includes(project));\n const inputs = this.buildInputs(affectedSet, graph);\n return new ImpactReport(true, '', short, this.ids(touched), this.ids(rest), this.ids(inputs), files.length);\n }\n\n /** A pure downward walk over the graph's own dependsOn edges: no nx call. */\n buildInputs(affected: string[], graph: EnhancedGraph): string[] {\n const inSet = new Set<string>(affected);\n const seen = new Set<string>(affected);\n const stack = [...affected];\n const inputs: string[] = [];\n while (stack.length > 0) {\n const project = stack.pop() as string;\n for (const dep of graph[project]?.dependsOn ?? []) {\n if (seen.has(dep)) continue;\n seen.add(dep);\n stack.push(dep);\n if (!inSet.has(dep) && graph[dep] !== undefined) inputs.push(dep);\n }\n }\n return inputs.sort();\n }\n\n /** Affected projects that own one of the changed files, by nx's own ownership. */\n touched(affected: string[], files: string[], owners: Map<string, string>): string[] {\n const owning = new Set<string>();\n for (const file of files) {\n const owner = owners.get(file);\n if (owner !== undefined) owning.add(owner);\n }\n return affected.filter((project: string): boolean => owning.has(project));\n }\n\n /** The JSON list, narrowed to projects the graph draws; null when it is not a list of names. */\n parse(json: string, graph: EnhancedGraph): string[] | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- untrusted CLI output; anything unparseable is reported as a reason\n try {\n // webpieces-disable no-any-unknown -- CLI JSON is untrusted until narrowed below\n const parsed: unknown = JSON.parse(json);\n if (!Array.isArray(parsed)) return null;\n return parsed\n .filter((name: unknown): name is string => typeof name === 'string' && graph[name] !== undefined)\n .sort();\n } catch (err: unknown) {\n const error = toError(err);\n void error; // not JSON — the caller reports it\n return null;\n }\n }\n\n /** Ownership failing is not fatal: the set then shows in one shade, all \"affected\". */\n private async owners(): Promise<Map<string, string>> {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- the second shade is optional\n try {\n return await this.ownership.owners();\n } catch (err: unknown) {\n const error = toError(err);\n console.warn(`⚠️ Impact: nx file ownership unavailable (${error.message}); showing one shade`);\n return new Map<string, string>();\n }\n }\n\n private ids(projects: string[]): string[] {\n return projects.map((project: string): string => this.names.getNodeId(project));\n }\n}\n\n/** Writes (or removes) the sidecar, self-ignored, beside architecture/dependencies.html. */\nexport class ImpactSidecar {\n /** Never throws: a sidecar that cannot be written just leaves Impact disabled on the page. */\n write(architectureDir: string, report: ImpactReport): string | null {\n const dir = path.join(architectureDir, IMPACT_SIDECAR_DIR);\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- impact is optional; a write failure must never fail generation\n try {\n fs.mkdirSync(dir, { recursive: true });\n fs.writeFileSync(\n path.join(dir, '.gitignore'),\n '# Written by architecture:generate. Per-branch data: never commit it.\\n*\\n',\n 'utf-8',\n );\n const file = path.join(dir, IMPACT_SIDECAR_FILE);\n fs.writeFileSync(file, this.script(report), 'utf-8');\n return file;\n } catch (err: unknown) {\n const error = toError(err);\n console.warn(`⚠️ Could not write the impact sidecar: ${error.message}`);\n return null;\n }\n }\n\n /** A stale sidecar from an earlier branch must never be shown as this branch's impact. */\n remove(architectureDir: string): void {\n fs.rmSync(path.join(architectureDir, IMPACT_SIDECAR_DIR, IMPACT_SIDECAR_FILE), { force: true });\n }\n\n script(report: ImpactReport): string {\n const json = JSON.stringify(report).replace(/</g, '\\\\u003c');\n return `// Generated by architecture:generate for one branch. Gitignored; do not commit.\\nwindow.__WP_IMPACT__ = ${json};\\n`;\n }\n}\n\n/** The generator's one call: scan, write, and report the result and its cost in one line. */\nexport class ImpactRefresh {\n constructor(\n private readonly scanner: NxImpactScanner = new NxImpactScanner(),\n private readonly sidecar: ImpactSidecar = new ImpactSidecar(),\n ) {}\n\n /** Never throws — Impact is optional, generation is not. */\n async run(architectureDir: string, workspaceRoot: string, graph: EnhancedGraph): Promise<string> {\n const started = Date.now();\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- impact is optional; any failure becomes a reason, never a failed generation\n try {\n const report = await this.scanner.scan(workspaceRoot, graph);\n const cost = `${Date.now() - started} ms`;\n if (report instanceof ImpactUnavailable) {\n this.sidecar.remove(architectureDir);\n return `ℹ️ Impact disabled, no sidecar written: ${report.reason} (${cost})`;\n }\n const file = this.sidecar.write(architectureDir, report);\n if (file === null) return `⚠️ Impact sidecar not written (${cost})`;\n if (!report.available) return `ℹ️ Impact disabled on the page: ${report.reason} (${cost})`;\n return (\n `✅ Impact vs ${report.base}: ${report.touched.length} touched · ${report.affected.length} affected · ` +\n `${report.buildInputs.length} build inputs, from ${report.changedFiles} changed file(s) (${cost}) → ${file}`\n );\n } catch (err: unknown) {\n const error = toError(err);\n return `⚠️ Impact skipped: ${error.message}`;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The architecture graph's legend, generated per color mode FROM THE PROJECTS ACTUALLY DRAWN.
|
|
3
|
+
*
|
|
4
|
+
* The hand-written legend this replaces listed five frameworks when six existed and never mentioned
|
|
5
|
+
* the `app` and `bundle` borders the renderer drew (#1155). Generating the rows from the same tables
|
|
6
|
+
* the renderer colors with (graph-color-modes.ts) means a color in use always has a row, and a color
|
|
7
|
+
* nothing uses never does.
|
|
8
|
+
*
|
|
9
|
+
* Swatches are inline SVG drawn with presentation attributes, never `style=`, so the page carries
|
|
10
|
+
* no inline CSS.
|
|
11
|
+
*/
|
|
12
|
+
import { LegendFacts } from './graph-color-modes';
|
|
13
|
+
export declare class GraphLegend {
|
|
14
|
+
/** One section per mode; the page shows the section of the current mode and hides the rest. */
|
|
15
|
+
sections(facts: LegendFacts): string;
|
|
16
|
+
/** The edge key: why a line exists. Static — every graph can carry every edge kind. */
|
|
17
|
+
edgeKey(): string;
|
|
18
|
+
private section;
|
|
19
|
+
/** Base runtimes first (stripe order), then specializations, in the shared vocabulary's order. */
|
|
20
|
+
runtimeRows(facts: LegendFacts): string;
|
|
21
|
+
architectureRows(facts: LegendFacts): string;
|
|
22
|
+
/** Which box is which is only known from the branch's sidecar, so all four rows always show. */
|
|
23
|
+
private impactRows;
|
|
24
|
+
private row;
|
|
25
|
+
private open;
|
|
26
|
+
private frame;
|
|
27
|
+
/** A base runtime is solid; a specialization is its inset on the base color. */
|
|
28
|
+
private envSwatch;
|
|
29
|
+
private stripesSwatch;
|
|
30
|
+
private roleSwatch;
|
|
31
|
+
/** A filled swatch, optionally with an inner ring (dashed when `dash` is set). */
|
|
32
|
+
private solid;
|
|
33
|
+
private edgeRow;
|
|
34
|
+
}
|