@powerhousedao/ph-cli 6.2.3-dev.100 → 6.2.3-dev.102
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/dist/{build-C1mmZvlb.mjs → build-D9Zjxsfj.mjs} +63 -11
- package/dist/build-D9Zjxsfj.mjs.map +1 -0
- package/dist/build-DkPj-Gz1.mjs +4 -0
- package/dist/{check-CjFMilhk.mjs → check-NJ07yjW8.mjs} +3 -3
- package/dist/{check-DvG9Xy4c.mjs → check-S29MtxQp.mjs} +32 -11
- package/dist/check-S29MtxQp.mjs.map +1 -0
- package/dist/cli.mjs +3 -3
- package/dist/{connect-build-COdexcA8.mjs → connect-build-DvFdfDP-.mjs} +4 -4
- package/dist/{connect-build-COdexcA8.mjs.map → connect-build-DvFdfDP-.mjs.map} +1 -1
- package/dist/definitions-worker.d.mts.map +1 -1
- package/dist/definitions-worker.mjs +5 -5
- package/dist/definitions-worker.mjs.map +1 -1
- package/dist/{evidence-Dchpoogs.mjs → evidence-CavwC5YV.mjs} +23 -9
- package/dist/evidence-CavwC5YV.mjs.map +1 -0
- package/dist/{generate-all-_7S0Iii2.mjs → generate-all-cgygbYEX.mjs} +5 -5
- package/dist/generate-all-cgygbYEX.mjs.map +1 -0
- package/dist/{generate-document-model-DCjzz3Sa.mjs → generate-document-model-OQPfeHs-.mjs} +25 -21
- package/dist/generate-document-model-OQPfeHs-.mjs.map +1 -0
- package/dist/{generate-editor-DdoapkEK.mjs → generate-editor-DBj_Pxwa.mjs} +7 -7
- package/dist/generate-editor-DBj_Pxwa.mjs.map +1 -0
- package/dist/{generate-subgraph-CrHbYK91.mjs → generate-subgraph-DJZCr0Tk.mjs} +34 -12
- package/dist/generate-subgraph-DJZCr0Tk.mjs.map +1 -0
- package/dist/{get-version-BBiGShxz.mjs → get-version-CeMBGufv.mjs} +4 -4
- package/dist/{get-version-BBiGShxz.mjs.map → get-version-CeMBGufv.mjs.map} +1 -1
- package/dist/{inspect-BpVHe9vz.mjs → inspect-CulIpVsF.mjs} +13 -7
- package/dist/inspect-CulIpVsF.mjs.map +1 -0
- package/dist/{mcp-BK-qb1ZS.mjs → mcp-HSikd5iv.mjs} +4 -4
- package/dist/{mcp-BK-qb1ZS.mjs.map → mcp-HSikd5iv.mjs.map} +1 -1
- package/dist/migrate-subgraphs-Cm7DDcDd.mjs +214 -0
- package/dist/migrate-subgraphs-Cm7DDcDd.mjs.map +1 -0
- package/dist/module-dir-1avCXsBi.mjs +2 -2
- package/dist/module-dir-1avCXsBi.mjs.map +1 -1
- package/dist/{ph-cli-commands-DwSp4Sbq.mjs → ph-cli-commands-CX927REY.mjs} +43 -22
- package/dist/ph-cli-commands-CX927REY.mjs.map +1 -0
- package/dist/ph-cli-commands-SrvFNgNF.mjs +4 -0
- package/dist/render-3M3DwFzO.mjs +4 -0
- package/dist/{render-BO-Nwn2H.mjs → render-SVfj3m8A.mjs} +19 -13
- package/dist/render-SVfj3m8A.mjs.map +1 -0
- package/dist/{run-DEKE4MJY.mjs → run--de_-WAz.mjs} +5 -4
- package/dist/run--de_-WAz.mjs.map +1 -0
- package/dist/{run-DP3fNgPv.mjs → run-LRGy7zGo.mjs} +3 -3
- package/dist/runners/connect.mjs +1 -1
- package/dist/runners/switchboard.mjs +1 -1
- package/dist/subgraph-gate-BJ2PWXVY.mjs +26 -0
- package/dist/subgraph-gate-BJ2PWXVY.mjs.map +1 -0
- package/dist/subgraph-gate-j9ywj6KA.mjs +4 -0
- package/dist/subgraphs-7OYWwP-C.mjs +134 -0
- package/dist/subgraphs-7OYWwP-C.mjs.map +1 -0
- package/dist/{switchboard-migrate-Docb8Cjv.mjs → switchboard-migrate-BqSdKJ7u.mjs} +3 -4
- package/dist/switchboard-migrate-BqSdKJ7u.mjs.map +1 -0
- package/dist/{verify-l5f7BDmy.mjs → verify-BrMeKdLA.mjs} +4 -4
- package/dist/{verify-l5f7BDmy.mjs.map → verify-BrMeKdLA.mjs.map} +1 -1
- package/dist/{vetra-DSFzAl_1.mjs → vetra-DjNt0-L6.mjs} +4 -4
- package/dist/{vetra-DSFzAl_1.mjs.map → vetra-DjNt0-L6.mjs.map} +1 -1
- package/package.json +16 -16
- package/dist/authoring-mode-DWbbsuWh.mjs +0 -23
- package/dist/authoring-mode-DWbbsuWh.mjs.map +0 -1
- package/dist/build-C1mmZvlb.mjs.map +0 -1
- package/dist/build-Ws5hhqol.mjs +0 -4
- package/dist/check-DvG9Xy4c.mjs.map +0 -1
- package/dist/evidence-Dchpoogs.mjs.map +0 -1
- package/dist/generate-all-_7S0Iii2.mjs.map +0 -1
- package/dist/generate-document-model-DCjzz3Sa.mjs.map +0 -1
- package/dist/generate-editor-DdoapkEK.mjs.map +0 -1
- package/dist/generate-subgraph-CrHbYK91.mjs.map +0 -1
- package/dist/inspect-BpVHe9vz.mjs.map +0 -1
- package/dist/ph-cli-commands-DwSp4Sbq.mjs.map +0 -1
- package/dist/ph-cli-commands-HLM5KIpd.mjs +0 -4
- package/dist/render-BO-Nwn2H.mjs.map +0 -1
- package/dist/render-DdieUjtg.mjs +0 -4
- package/dist/run-DEKE4MJY.mjs.map +0 -1
- package/dist/switchboard-migrate-Docb8Cjv.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as runModelCheck, t as definitionChecks } from "./check-
|
|
1
|
+
import { n as runModelCheck, t as definitionChecks } from "./check-S29MtxQp.mjs";
|
|
2
2
|
export { definitionChecks, runModelCheck };
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
4
|
-
//# debugId=
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="afccc113-5afe-59de-a8b2-b4bafaf78b21")}catch(e){}}();
|
|
4
|
+
//# debugId=afccc113-5afe-59de-a8b2-b4bafaf78b21
|
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8fb4b6b2-d822-5ae0-8ab3-d3dd570c1ef3")}catch(e){}}();
|
|
3
|
+
import { t as readProjectSubgraphs } from "./subgraphs-7OYWwP-C.mjs";
|
|
4
|
+
import { n as processStreams, r as runModelCommand } from "./run--de_-WAz.mjs";
|
|
5
|
+
import { t as renderCheckReport } from "./render-SVfj3m8A.mjs";
|
|
6
|
+
import { checkProjectDefinitions, documentModelChecks, subgraphChecks } from "document-model/tooling";
|
|
6
7
|
//#region src/services/model/check.ts
|
|
8
|
+
async function subgraphContributions(project, modules) {
|
|
9
|
+
const subgraphs = await readProjectSubgraphs(project, modules);
|
|
10
|
+
if (subgraphs === void 0) return void 0;
|
|
11
|
+
return {
|
|
12
|
+
checks: subgraphChecks,
|
|
13
|
+
input: { subgraphs: subgraphs.input },
|
|
14
|
+
inventory: subgraphs.inventory
|
|
15
|
+
};
|
|
16
|
+
}
|
|
7
17
|
/**
|
|
8
18
|
* The edit and the release profile of the definition check, as `ph model
|
|
9
19
|
* check` runs them and the definitions worker runs them for `ph build`.
|
|
10
20
|
*/
|
|
11
21
|
const definitionChecks = {
|
|
12
|
-
edit: (project) =>
|
|
22
|
+
edit: async (project, modules) => {
|
|
23
|
+
const contributions = await subgraphContributions(project, modules);
|
|
24
|
+
if (contributions === void 0) return checkProjectDefinitions(project);
|
|
25
|
+
return checkProjectDefinitions({
|
|
26
|
+
...project,
|
|
27
|
+
...contributions.input
|
|
28
|
+
}, {
|
|
29
|
+
checks: [...documentModelChecks, ...contributions.checks],
|
|
30
|
+
definitions: contributions.inventory
|
|
31
|
+
});
|
|
32
|
+
},
|
|
13
33
|
release: async (project, modules) => {
|
|
14
|
-
const
|
|
15
|
-
|
|
34
|
+
const contributions = await subgraphContributions(project, modules);
|
|
35
|
+
const { checkForRelease } = await import("./evidence-CavwC5YV.mjs");
|
|
36
|
+
return await checkForRelease(project, modules, contributions === void 0 ? {} : { contributions });
|
|
16
37
|
}
|
|
17
38
|
};
|
|
18
39
|
/** `ph model check`. Returns the exit code. */
|
|
@@ -27,7 +48,7 @@ async function runModelCheck(args, options = {}) {
|
|
|
27
48
|
return await runModelCommand({
|
|
28
49
|
name: "ph model check",
|
|
29
50
|
json: args.json,
|
|
30
|
-
read: async (project, modules) => args.release ? (await definitionChecks.release(project, modules)).report : await definitionChecks.edit(project),
|
|
51
|
+
read: async (project, modules) => args.release ? (await definitionChecks.release(project, modules)).report : await definitionChecks.edit(project, modules),
|
|
31
52
|
render: renderCheckReport
|
|
32
53
|
}, options);
|
|
33
54
|
}
|
|
@@ -38,7 +59,7 @@ async function runModelCheck(args, options = {}) {
|
|
|
38
59
|
*/
|
|
39
60
|
async function runPrepackCheck(json, options) {
|
|
40
61
|
const streams = options.streams ?? processStreams;
|
|
41
|
-
const { renderReleaseDecision, verifyRelease } = await import("./verify-
|
|
62
|
+
const { renderReleaseDecision, verifyRelease } = await import("./verify-BrMeKdLA.mjs");
|
|
42
63
|
let decision;
|
|
43
64
|
try {
|
|
44
65
|
decision = verifyRelease(options.projectRoot ?? process.cwd());
|
|
@@ -56,5 +77,5 @@ async function runPrepackCheck(json, options) {
|
|
|
56
77
|
//#endregion
|
|
57
78
|
export { runModelCheck as n, definitionChecks as t };
|
|
58
79
|
|
|
59
|
-
//# sourceMappingURL=check-
|
|
60
|
-
//# debugId=
|
|
80
|
+
//# sourceMappingURL=check-S29MtxQp.mjs.map
|
|
81
|
+
//# debugId=8fb4b6b2-d822-5ae0-8ab3-d3dd570c1ef3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-S29MtxQp.mjs","sources":["../src/services/model/check.ts"],"sourcesContent":["import type { DefinitionCheckReport } from \"@powerhousedao/shared/document-model\";\nimport {\n checkProjectDefinitions,\n documentModelChecks,\n type ProjectDefinitions,\n subgraphChecks,\n} from \"document-model/tooling\";\nimport type { ReleaseDecision } from \"../release/approval.js\";\nimport type { ReleaseCheck } from \"../release/evidence.js\";\nimport type { ProjectModules } from \"./project.js\";\nimport { readProjectSubgraphs } from \"./subgraphs.js\";\nimport {\n type ModelRunOptions,\n processStreams,\n runModelCommand,\n} from \"./run.js\";\nimport { renderCheckReport } from \"./render.js\";\n\nasync function subgraphContributions(\n project: ProjectDefinitions,\n modules: ProjectModules,\n) {\n const subgraphs = await readProjectSubgraphs(project, modules);\n if (subgraphs === undefined) return undefined;\n return {\n checks: subgraphChecks,\n input: { subgraphs: subgraphs.input },\n inventory: subgraphs.inventory,\n };\n}\n\n/**\n * The edit and the release profile of the definition check, as `ph model\n * check` runs them and the definitions worker runs them for `ph build`.\n */\nexport const definitionChecks = {\n edit: async (\n project: ProjectDefinitions,\n modules: ProjectModules,\n ): Promise<DefinitionCheckReport> => {\n const contributions = await subgraphContributions(project, modules);\n if (contributions === undefined) return checkProjectDefinitions(project);\n return checkProjectDefinitions(\n { ...project, ...contributions.input },\n {\n checks: [...documentModelChecks, ...contributions.checks],\n definitions: contributions.inventory,\n },\n );\n },\n release: async (\n project: ProjectDefinitions,\n modules: ProjectModules,\n ): Promise<ReleaseCheck> => {\n const contributions = await subgraphContributions(project, modules);\n const { checkForRelease } = await import(\"../release/evidence.js\");\n return await checkForRelease(\n project,\n modules,\n contributions === undefined ? {} : { contributions },\n );\n },\n};\n\n/** `ph model check`. Returns the exit code. */\nexport async function runModelCheck(\n args: {\n readonly json: boolean;\n readonly release?: boolean;\n readonly prepack?: boolean;\n },\n options: ModelRunOptions = {},\n): Promise<number> {\n if (args.prepack) {\n if (args.release) {\n (options.streams ?? processStreams).err(\n \"ph model check could not run: --prepack and --release cannot be combined.\\n\",\n );\n return 2;\n }\n return await runPrepackCheck(args.json, options);\n }\n return await runModelCommand(\n {\n name: \"ph model check\",\n json: args.json,\n read: async (project, modules) =>\n args.release\n ? (await definitionChecks.release(project, modules)).report\n : await definitionChecks.edit(project, modules),\n render: renderCheckReport,\n },\n options,\n );\n}\n\n/**\n * `ph model check --prepack`: 0 when the release approval matches the\n * package, 1 when it does not, 2 when it cannot be checked. Loads none of\n * the package's modules.\n */\nasync function runPrepackCheck(\n json: boolean,\n options: ModelRunOptions,\n): Promise<number> {\n const streams = options.streams ?? processStreams;\n const { renderReleaseDecision, verifyRelease } =\n await import(\"../release/verify.js\");\n let decision: ReleaseDecision;\n try {\n decision = verifyRelease(options.projectRoot ?? process.cwd());\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n streams.err(`ph model check --prepack could not run: ${message}\\n`);\n return 2;\n }\n streams.out(\n `${json ? JSON.stringify({ decision: decision.decision, reasons: decision.reasons }) : renderReleaseDecision(decision)}\\n`,\n );\n return decision.decision === \"approved\" ? 0 : 1;\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,eAAe,sBACb,SACA,SACA;CACA,MAAM,YAAY,MAAM,qBAAqB,SAAS,OAAO;CAC7D,IAAI,cAAc,KAAA,GAAW,OAAO,KAAA;CACpC,OAAO;EACL,QAAQ;EACR,OAAO,EAAE,WAAW,UAAU,MAAM;EACpC,WAAW,UAAU;CACvB;AACF;;;;;AAMA,MAAa,mBAAmB;CAC9B,MAAM,OACJ,SACA,YACmC;EACnC,MAAM,gBAAgB,MAAM,sBAAsB,SAAS,OAAO;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AAI,sBAAsB,QAAQ,EAAE,GACzH;CACA,OAAO,SAAS,aAAa,aAAa,IAAI;AAChD","debug_id":"8fb4b6b2-d822-5ae0-8ab3-d3dd570c1ef3"}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f8c851b2-11a4-56a6-9335-596d5f292b59")}catch(e){}}();
|
|
4
|
-
import { t as getVersion } from "./get-version-
|
|
5
|
-
import { n as phCliCommands } from "./ph-cli-commands-
|
|
4
|
+
import { t as getVersion } from "./get-version-CeMBGufv.mjs";
|
|
5
|
+
import { n as phCliCommands } from "./ph-cli-commands-CX927REY.mjs";
|
|
6
6
|
import { t as isUniformRunnersEnabled } from "./feature-flags-xwqcHEWC.mjs";
|
|
7
7
|
import { initCliTelemetry } from "@powerhousedao/shared/clis/telemetry";
|
|
8
8
|
import { assertNodeVersion } from "@powerhousedao/shared/clis/utils";
|
|
@@ -112,7 +112,7 @@ async function main() {
|
|
|
112
112
|
let args = process.argv.slice(2);
|
|
113
113
|
if (isUniformRunnersEnabled()) {
|
|
114
114
|
const { applyRunSugar } = await import("./run-sugar-D9lIzhAx.mjs");
|
|
115
|
-
const { phCliCommands } = await import("./ph-cli-commands-
|
|
115
|
+
const { phCliCommands } = await import("./ph-cli-commands-SrvFNgNF.mjs");
|
|
116
116
|
const sugar = applyRunSugar(args, new Set(Object.keys(phCliCommands)), process.cwd());
|
|
117
117
|
if (sugar.warning) console.warn(sugar.warning);
|
|
118
118
|
args = sugar.args;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import { t as runBuild } from "./build-
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3e1a6e83-3f3f-51f4-b952-285f5fe9f028")}catch(e){}}();
|
|
3
|
+
import { t as runBuild } from "./build-D9Zjxsfj.mjs";
|
|
4
4
|
import { t as buildCliConnectOverride } from "./cli-connect-override-D3N3gbp_.mjs";
|
|
5
5
|
import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
@@ -318,5 +318,5 @@ function assertLocalPackagesInstalled(projectPath) {
|
|
|
318
318
|
//#endregion
|
|
319
319
|
export { runConnectBuild };
|
|
320
320
|
|
|
321
|
-
//# sourceMappingURL=connect-build-
|
|
322
|
-
//# debugId=
|
|
321
|
+
//# sourceMappingURL=connect-build-DvFdfDP-.mjs.map
|
|
322
|
+
//# debugId=3e1a6e83-3f3f-51f4-b952-285f5fe9f028
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-build-COdexcA8.mjs","sources":["../src/utils/precompress.ts","../src/services/connect-build.ts"],"sourcesContent":["import { PRECOMPRESS_EXTENSIONS } from \"@powerhousedao/ph-run/connect-serve\";\nimport { createHash } from \"node:crypto\";\nimport { readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { gzip } from \"node:zlib\";\n\nconst gzipAsync = promisify(gzip);\n\nexport { PRECOMPRESS_EXTENSIONS };\n\n/** A sibling is written only when it is at most this fraction of the source. */\nconst MAX_RATIO = 0.9;\n\nexport type PrecompressResult = {\n files: number;\n written: number;\n skipped: number;\n inputBytes: number;\n outputBytes: number;\n ms: number;\n};\n\nasync function findTargets(dir: string): Promise<string[]> {\n const entries = await readdir(dir, { recursive: true, withFileTypes: true });\n return entries\n .filter(\n (e) =>\n e.isFile() &&\n PRECOMPRESS_EXTENSIONS.some((ext) => e.name.endsWith(ext)),\n )\n .map((e) => join(e.parentPath, e.name));\n}\n\nasync function isFresh(source: string, sibling: string): Promise<boolean> {\n try {\n const [s, c] = await Promise.all([stat(source), stat(sibling)]);\n return c.mtimeMs >= s.mtimeMs;\n } catch {\n return false;\n }\n}\n\n/** Write gzip siblings for every `.wasm`/`.data` under `dir`. */\nexport async function precompressAssets(\n dir: string,\n): Promise<PrecompressResult> {\n const start = performance.now();\n const targets = await findTargets(dir);\n const result: PrecompressResult = {\n files: targets.length,\n written: 0,\n skipped: 0,\n inputBytes: 0,\n outputBytes: 0,\n ms: 0,\n };\n // Vendor and worker copies share content: compress each distinct file once.\n const byHash = new Map<string, Promise<Buffer | null>>();\n\n await Promise.all(\n targets.map(async (file) => {\n const sibling = file + \".gz\";\n if (await isFresh(file, sibling)) {\n result.skipped += 1;\n return;\n }\n const source = await readFile(file);\n result.inputBytes += source.length;\n const hash = createHash(\"sha256\").update(source).digest(\"hex\");\n let compressed = byHash.get(hash);\n if (!compressed) {\n compressed = gzipAsync(source, { level: 9 }).then((out) =>\n out.length <= source.length * MAX_RATIO ? out : null,\n );\n byHash.set(hash, compressed);\n }\n const out = await compressed;\n if (!out) {\n await rm(sibling, { force: true });\n result.skipped += 1;\n return;\n }\n await writeFile(sibling, out);\n result.written += 1;\n result.outputBytes += out.length;\n }),\n );\n\n result.ms = Math.round(performance.now() - start);\n return result;\n}\n\n/** On by default; PH_CONNECT_PRECOMPRESS=0|false disables it. */\nexport function isPrecompressEnabled(\n env: NodeJS.ProcessEnv = process.env,\n): boolean {\n const raw = env.PH_CONNECT_PRECOMPRESS ?? \"1\";\n return raw !== \"0\" && raw !== \"false\";\n}\n","import {\n DEFAULT_VENDOR_INCLUDE,\n DYNAMIC_BASE_PLACEHOLDER,\n directoryContentDigest,\n findPackageRoot,\n getConnectBaseViteConfig,\n missingVendorEntries,\n prebuildConnectVendor,\n ownProjectPackage,\n prebuildReactorWorker,\n prebuildWorkerPackages,\n resolveReactorWorkerSource,\n type PrebuiltReactorWorker,\n type PrebuiltVendor,\n} from \"@powerhousedao/builder-tools\";\nimport { getConfig } from \"@powerhousedao/shared/clis\";\nimport type { PHConnectRuntimeConfig } from \"@powerhousedao/shared/clis\";\nimport {\n deepMerge,\n normalizeBasePath,\n SHARED_DEP_SPECIFIERS,\n SHARED_SUBPATHS,\n} from \"@powerhousedao/shared/connect\";\nimport { existsSync, mkdirSync, readdirSync, rmSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport type { InlineConfig } from \"vite\";\nimport { build, mergeConfig } from \"vite\";\nimport type { ConnectBuildArgs } from \"../types.js\";\nimport { buildCliConnectOverride } from \"../utils/cli-connect-override.js\";\nimport {\n isPrecompressEnabled,\n precompressAssets,\n} from \"../utils/precompress.js\";\nimport { runBuild } from \"./build.js\";\n\nexport async function runConnectBuild(\n args: ConnectBuildArgs,\n callerOverride?: PHConnectRuntimeConfig,\n { routes }: { routes?: string | false } = {},\n) {\n const { outDir, debug, dynamicBase, favicon } = args;\n\n const mode = \"production\";\n const dirname = process.cwd();\n\n // Build has no read mode; a bare positional `<key>` is a user error. The\n // 2-positional `<key> <value>` form is handled inside buildCliConnectOverride\n // so it layers on top of --json + flags like any other override input.\n if (args.keyPositional !== undefined && args.valuePositional === undefined) {\n throw new Error(\n \"ph connect build: positional override requires both <key> and <value> (e.g. `ph connect build connect.renown.url https://renown.staging`). To read a value, use `ph connect config <key>`.\",\n );\n }\n\n // Fail fast if any package marked as provider: \"local\" is missing from\n // node_modules — the Vite plugin that bundles them needs them on disk.\n assertLocalPackagesInstalled(dirname);\n\n // Build the CLI override layers (--json + individual flags + positional)\n // once here so a bad payload fails before we waste a build.\n // `--packages-registry` lands at the top-level `packageRegistryUrl`\n // (mirrors source-config shape); every other flag feeds the connect-block\n // precedence ladder.\n const cli = buildCliConnectOverride(args);\n const { packageRegistryUrl } = cli;\n // A runner's host config sits under the CLI's flags.\n const connectOverride = callerOverride\n ? deepMerge(callerOverride, cli.connectOverride ?? {})\n : cli.connectOverride;\n\n await runBuild({\n outDir: \"dist\",\n debug,\n // Local packages built for Connect share deps with the app vendor, same\n // as a plain `ph build`.\n noSharedDeps: false,\n ignoreTypeErrors: false,\n release: false,\n });\n\n // Production shared-dependency vendor: prebuilt into <outDir>/__vendor__\n // before the app build. On by default; PH_CONNECT_VENDOR=0|false disables\n // it. A failed prebuild fails the build — production must not ship import\n // map entries pointing at a vendor that was never built (the dev server\n // keeps its own soft fallback in the dev plugin).\n const outDirAbs = resolve(dirname, outDir);\n let vendor: PrebuiltVendor | null = null;\n // The deploy base the vendor's import-map addresses are written against.\n // Only meaningful when the vendor is built; \"/\" is the inert default.\n let appBase = \"/\";\n // The prebuild out dirs' parent must exist before the prebuilds: their\n // build locks are siblings of the out dirs, and the package build\n // (runBuild) writes to a different out dir, so nothing else creates it yet.\n mkdirSync(outDirAbs, { recursive: true });\n if (isVendorEnabled()) {\n const errorRef: { message?: string } = {};\n // The same base string the app build uses below: the dynamic-base\n // placeholder, or the normalized deploy base (CLI override wins over the\n // source config). The vendor worker appends its own segment.\n const phConfig = getConfig(join(dirname, \"powerhouse.config.json\"));\n const connectBasePath =\n connectOverride?.app?.basePath ?? phConfig.connect?.app?.basePath;\n appBase = dynamicBase\n ? DYNAMIC_BASE_PLACEHOLDER\n : connectBasePath\n ? normalizeBasePath(connectBasePath)\n : \"/\";\n vendor = await prebuildConnectVendor({\n dirname,\n include: productionVendorInclude(),\n vendorDir: join(outDirAbs, \"__vendor__\"),\n base: appBase,\n nodeEnv: \"production\",\n errorRef,\n ...connectOwnVendorDeps(dirname),\n });\n if (!vendor) {\n console.error(\n `ph connect build: the shared-dependency vendor failed to build${\n errorRef.message ? `:\\n${errorRef.message}` : \"\"\n }`,\n );\n throw new Error(\"shared-dependency vendor prebuild failed\");\n }\n }\n\n // Reactor SharedWorker bundle: the dist worker is a library artifact whose\n // bare imports no worker can resolve (import maps do not apply to workers),\n // so the deployable form is prebuilt here. With a vendor, its shared deps\n // are externalized onto ../__vendor__/ so page and worker share one cache\n // entry per dep; without one it is fully self-contained.\n const reactorWorker = await prebuildReactorWorkerBundle(\n dirname,\n outDirAbs,\n vendor,\n connectOverride,\n );\n\n // Local project models the worker cannot get from the registry, built into\n // the worker bundle's own directory so they share its vendor.\n if (reactorWorker) {\n await prebuildLocalWorkerPackages(\n dirname,\n outDirAbs,\n vendor,\n reactorWorker.vendorImports,\n );\n }\n\n const keepDirs = [\n ...(vendor ? [\"__vendor__\"] : []),\n ...(reactorWorker ? [\"__reactor_worker__\"] : []),\n ];\n // Stale top-level output goes, the prebuilt dirs stay: the app build below\n // runs with emptyOutDir: false and must not wipe them.\n if (keepDirs.length > 0) {\n cleanDistExcept(outDirAbs, keepDirs);\n }\n\n const baseConfig = getConnectBaseViteConfig({\n mode,\n dirname,\n cliConnectOverride: connectOverride,\n cliPackageRegistryUrl: packageRegistryUrl,\n dynamicBase,\n favicon,\n routes,\n // Vendor import-map entries are relative (leading slash stripped) so\n // they resolve against the page URL under any deploy base — root or\n // subpath, dynamic or concrete.\n vendor: vendor\n ? {\n imports: vendorImportMapEntries(vendor.imports, appBase),\n versions: vendor.versions,\n sharedDeps: vendorImportMapEntries(\n { sharedDeps: vendor.sharedDeps },\n appBase,\n ).sharedDeps,\n }\n : undefined,\n reactorWorkerVersion: reactorWorker\n ? directoryContentDigest(join(outDirAbs, \"__reactor_worker__\"))\n : undefined,\n });\n\n const buildConfig: InlineConfig = {\n build: {\n outDir,\n // The vendor / worker dirs were prebuilt into the out dir above; the\n // build must not empty them.\n ...(keepDirs.length > 0 ? { emptyOutDir: false } : {}),\n },\n };\n\n const config = mergeConfig(baseConfig, buildConfig);\n\n await build(config);\n\n // Last word on the shipped artifact: every specifier the page's import map\n // publishes must have a file next to it. The prebuild verifies its own\n // output, but it can return a cache hit it never rebuilt, and both the\n // stale-output clean and the app build run afterwards. An entry with no\n // file behind it ships as a URL that 404s, and a SPA answers that with\n // index.html — so the browser reports only an opaque MIME-type error with\n // no filename. Fail here instead, naming the entries.\n if (vendor) {\n const unbacked = missingVendorEntries(\n join(outDirAbs, \"__vendor__\"),\n vendor.imports,\n );\n if (unbacked.length > 0) {\n throw new Error(\n `ph connect build: the shared-dependency vendor is missing ` +\n `${unbacked.length} of the ${Object.keys(vendor.imports).length} ` +\n `entries its import map publishes:\\n` +\n unbacked.map((e) => ` ${e.spec} -> ${e.url}`).join(\"\\n\"),\n );\n }\n }\n\n // Runs after the PWA plugin, so the siblings never enter the precache list.\n if (isPrecompressEnabled()) {\n const r = await precompressAssets(outDirAbs);\n console.log(\n `ph connect build: precompressed ${r.files} wasm/data files ` +\n `(${r.written} .gz written, ${(r.outputBytes / 1e6).toFixed(1)} MB) in ${(r.ms / 1000).toFixed(1)}s`,\n );\n }\n}\n\n/**\n * The specifier set the production vendor bundles: the dev-proven heavy set\n * ∪ the package-shared set — everything the app and loaded packages\n * externalize onto the vendor.\n *\n * Two specifiers are deliberately dropped:\n *\n * - `@powerhousedao/connect`. It is in DEFAULT_VENDOR_INCLUDE because the dev\n * server vendors the app to keep rebuilds cheap, but in a production build\n * the app *is* Connect: `SHARED_DEP_SPECIFIERS` omits it, so the app build\n * never externalizes it and nothing would ever resolve its import-map\n * entry. Vendoring it is not merely dead weight — bundling Connect's dist\n * for the browser pulls in its node-only `@powerhousedao/config/node`\n * import, and so `read-pkg` -> `unicorn-magic`, whose browser entry has no\n * `toPath`. That fails the vendor build, and a failed prebuild fails\n * `ph connect build`.\n * - the bare `@powerhousedao/shared` root, whose barrel likewise reaches\n * node-only modules. Its browser-safe subpaths (SHARED_SUBPATHS) are\n * listed instead; a package importing the bare root bundles its own copy.\n */\nexport function productionVendorInclude(): string[] {\n return [\n ...new Set([\n ...DEFAULT_VENDOR_INCLUDE.filter((s) => s !== \"@powerhousedao/connect\"),\n ...SHARED_DEP_SPECIFIERS.filter((s) => s !== \"@powerhousedao/shared\"),\n ...SHARED_SUBPATHS.map((s) => `@powerhousedao/shared/${s}`),\n // Connect imports these roots too; unvendored, the app re-bundles their shared chunks.\n \"@powerhousedao/design-system\",\n \"@powerhousedao/reactor\",\n ]),\n ];\n}\n\n/** Connect's own deps that vendored packages also bundle; projects don't install them. */\nexport const CONNECT_OWN_VENDOR_DEPS = [\n \"kysely\",\n \"tailwind-merge\",\n \"@renown/sdk\",\n \"@renown/sdk/crypto\",\n \"@renown/sdk/trust\",\n \"@powerhousedao/reactor-attachments/client\",\n // One core and router for Connect and packages; the route tree, config and\n // embedded subpaths stay with the app.\n \"@powerhousedao/connect-core\",\n \"@powerhousedao/connect-core/router\",\n \"@powerhousedao/connect-core/plugins\",\n \"@powerhousedao/connect-core/runtime\",\n \"@powerhousedao/connect-core/views\",\n \"@tanstack/react-router\",\n];\n\nexport function connectOwnVendorDeps(dirname: string): {\n ownDeps?: { specs: string[]; from: string };\n} {\n const from = findPackageRoot(dirname, \"@powerhousedao/connect\");\n return from ? { ownDeps: { specs: CONNECT_OWN_VENDOR_DEPS, from } } : {};\n}\n\n/**\n * Turn the vendor's base-less URLs (`/__vendor__/x.js`) into the addresses\n * the page's import map ships, by prefixing the deploy base.\n *\n * An import map *address* must be a URL or begin with `/`, `./` or `../`;\n * anything else is a bare specifier, which the browser rejects — it drops the\n * entry, resolves the specifier to null, and every shared import then fails\n * with \"blocked by a null value\". So the base is applied rather than the\n * leading slash stripped: a root-relative address is both valid and correct\n * under a subpath deploy, and a dynamic-base build keeps its placeholder for\n * the serving proxy to substitute (the dynamic-base plugin leaves HTML\n * tokens alone by design).\n */\nexport function vendorImportMapEntries(\n imports: Record<string, string>,\n appBase: string,\n): Record<string, string> {\n return Object.fromEntries(\n Object.entries(imports).map(([spec, url]) => [\n spec,\n `${appBase}/${url}`.replace(/\\/{2,}/g, \"/\"),\n ]),\n );\n}\n\n/**\n * The production vendor prebuild runs on every `ph connect build` unless\n * disabled with PH_CONNECT_VENDOR=0 or false.\n */\nexport function isVendorEnabled(env: NodeJS.ProcessEnv = process.env): boolean {\n const raw = env.PH_CONNECT_VENDOR ?? \"1\";\n return raw !== \"0\" && raw !== \"false\";\n}\n\n/**\n * The reactor worker bundle prebuild runs on every `ph connect build` unless\n * disabled with PH_CONNECT_REACTOR_WORKER=0 or false. It is built even when\n * `connect.instance.reactorWorker` is off, because the `?reactorWorker=true`\n * runtime override can enable the feature on a flag-off deployment.\n */\nexport function isReactorWorkerBundleEnabled(\n env: NodeJS.ProcessEnv = process.env,\n): boolean {\n const raw = env.PH_CONNECT_REACTOR_WORKER ?? \"1\";\n return raw !== \"0\" && raw !== \"false\";\n}\n\n/**\n * Prebuild the reactor SharedWorker bundle into `<dist>/__reactor_worker__`.\n * Returns null when the prebuild is disabled, the installed Connect ships no\n * worker entry, or the build fails. A failure only fails `ph connect build`\n * when the project explicitly enables `connect.instance.reactorWorker` —\n * otherwise the feature degrades to unavailable and the build goes on.\n */\nasync function prebuildReactorWorkerBundle(\n dirname: string,\n outDirAbs: string,\n vendor: PrebuiltVendor | null,\n connectOverride: PHConnectRuntimeConfig | undefined,\n): Promise<PrebuiltReactorWorker | null> {\n if (!isReactorWorkerBundleEnabled()) return null;\n if (!resolveReactorWorkerSource(dirname)) return null;\n\n const errorRef: { message?: string } = {};\n const bundle = await prebuildReactorWorker({\n dirname,\n outDir: join(outDirAbs, \"__reactor_worker__\"),\n vendor: vendor\n ? { imports: vendor.imports, dir: join(outDirAbs, \"__vendor__\") }\n : undefined,\n nodeEnv: \"production\",\n errorRef,\n });\n if (bundle) return bundle;\n\n const message = `ph connect build: the reactor worker bundle failed to build${\n errorRef.message ? `:\\n${errorRef.message}` : \"\"\n }`;\n const phConfig = getConfig(join(dirname, \"powerhouse.config.json\"));\n const required =\n connectOverride?.instance?.reactorWorker ??\n phConfig.connect?.instance?.reactorWorker ??\n false;\n if (required) {\n throw new Error(message);\n }\n console.warn(\n `${message}\\nThe reactorWorker feature will be unavailable in this build.`,\n );\n return null;\n}\n\n/**\n * Build the project's `provider: \"local\"` packages into worker-loadable model\n * bundles beside the worker. A failure is a warning, not a build failure: the\n * worker still runs, and documents of registry types still work - only the\n * project's own types would be unavailable in worker mode.\n */\nasync function prebuildLocalWorkerPackages(\n dirname: string,\n outDirAbs: string,\n vendor: PrebuiltVendor | null,\n safeVendorImports: Record<string, string>,\n): Promise<void> {\n const config = getConfig(join(dirname, \"powerhouse.config.json\"));\n const configured = (config.packages ?? [])\n .filter((p) => p.provider === \"local\")\n .map((p) => p.packageName);\n // The project itself is a local package in all but name: a vetra project\n // declares no entry for itself, and its models are the ones the worker\n // cannot otherwise get.\n const own = ownProjectPackage(dirname);\n const localPackages = [...new Set([...configured, ...(own ? [own] : [])])];\n\n const errorRef: { message?: string } = {};\n const built = await prebuildWorkerPackages({\n dirname,\n packages: localPackages,\n outDir: join(outDirAbs, \"__reactor_worker__\", \"packages\"),\n vendor: vendor\n ? { imports: vendor.imports, dir: join(outDirAbs, \"__vendor__\") }\n : undefined,\n safeVendorImports,\n nodeEnv: \"production\",\n errorRef,\n });\n if (!built) {\n console.warn(\n `ph connect build: the reactor worker's local package bundles failed to build${\n errorRef.message ? `:\\n${errorRef.message}` : \"\"\n }\\nDocuments of this project's own types will not load in worker mode.`,\n );\n }\n}\n\n/**\n * Remove every top-level entry of `dist` except the kept names. Used between\n * the vendor prebuild and the app build so stale app output goes but the\n * just-built vendor stays (the build then runs with emptyOutDir: false).\n * Returns the number of entries removed.\n */\nexport function cleanDistExcept(dist: string, keep: string[] = []): number {\n if (!existsSync(dist)) return 0;\n let removed = 0;\n for (const entry of readdirSync(dist)) {\n if (keep.includes(entry)) continue;\n rmSync(join(dist, entry), { recursive: true, force: true });\n removed += 1;\n }\n return removed;\n}\n\nfunction assertLocalPackagesInstalled(projectPath: string) {\n const config = getConfig(join(projectPath, \"powerhouse.config.json\"));\n const localPackages = (config.packages ?? []).filter(\n (p) => p.provider === \"local\",\n );\n if (localPackages.length === 0) return;\n\n const missing = localPackages.filter(\n (p) =>\n !existsSync(\n join(projectPath, \"node_modules\", p.packageName, \"package.json\"),\n ),\n );\n if (missing.length === 0) return;\n\n const names = missing.map((p) => p.packageName);\n throw new Error(\n `ph connect build requires these packages to be installed in node_modules (they are declared with provider: \"local\" in powerhouse.config.json):\\n` +\n names.map((n) => ` - ${n}`).join(\"\\n\") +\n `\\n\\nInstall them with:\\n ph install --local ${names.join(\" \")}`,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAOA,MAAM,YAAY,UAAU,IAAI;;AAKhC,MAAM,YAAY;AAWlB,eAAe,YAAY,KAAgC;CAEzD,QAAO,MADe,QAAQ,KAAK;EAAE,WAAW;EAAM,eAAe;CAAK,CAAC,EAAA,CAExE,QACE,MACC,EAAE,OAAO,KACT,uBAAuB,MAAM,QAAQ,EAAE,KAAK,SAAS,GAAG,CAAC,CAC7D,CAAC,CACA,KAAK,MAAM,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;AAC1C;AAEA,eAAe,QAAQ,QAAgB,SAAmC;CACxE,IAAI;EACF,MAAM,CAAC,GAAG,KAAK,MAAM,QAAQ,IAAI,CAAC,KAAK,MAAM,GAAG,KAAK,OAAO,CAAC,CAAC;EAC9D,OAAO,EAAE,WAAW,EAAE;CACxB,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,eAAsB,kBACpB,KAC4B;CAC5B,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,UAAU,MAAM,YAAY,GAAG;CACrC,MAAM,SAA4B;EAChC,OAAO,QAAQ;EACf,SAAS;EACT,SAAS;EACT,YAAY;EACZ,aAAa;EACb,IAAI;CACN;CAEA,MAAM,yBAAS,IAAI,IAAoC;CAEvD,MAAM,QAAQ,IACZ,QAAQ,IAAI,OAAO,SAAS;EAC1B,MAAM,UAAU,OAAO;EACvB,IAAI,MAAM,QAA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K,GAAG,GAClE;AACF","debug_id":"4827d890-457d-5072-916f-00c987caa50d"}
|
|
1
|
+
{"version":3,"file":"connect-build-DvFdfDP-.mjs","sources":["../src/utils/precompress.ts","../src/services/connect-build.ts"],"sourcesContent":["import { PRECOMPRESS_EXTENSIONS } from \"@powerhousedao/ph-run/connect-serve\";\nimport { createHash } from \"node:crypto\";\nimport { readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { gzip } from \"node:zlib\";\n\nconst gzipAsync = promisify(gzip);\n\nexport { PRECOMPRESS_EXTENSIONS };\n\n/** A sibling is written only when it is at most this fraction of the source. */\nconst MAX_RATIO = 0.9;\n\nexport type PrecompressResult = {\n files: number;\n written: number;\n skipped: number;\n inputBytes: number;\n outputBytes: number;\n ms: number;\n};\n\nasync function findTargets(dir: string): Promise<string[]> {\n const entries = await readdir(dir, { recursive: true, withFileTypes: true });\n return entries\n .filter(\n (e) =>\n e.isFile() &&\n PRECOMPRESS_EXTENSIONS.some((ext) => e.name.endsWith(ext)),\n )\n .map((e) => join(e.parentPath, e.name));\n}\n\nasync function isFresh(source: string, sibling: string): Promise<boolean> {\n try {\n const [s, c] = await Promise.all([stat(source), stat(sibling)]);\n return c.mtimeMs >= s.mtimeMs;\n } catch {\n return false;\n }\n}\n\n/** Write gzip siblings for every `.wasm`/`.data` under `dir`. */\nexport async function precompressAssets(\n dir: string,\n): Promise<PrecompressResult> {\n const start = performance.now();\n const targets = await findTargets(dir);\n const result: PrecompressResult = {\n files: targets.length,\n written: 0,\n skipped: 0,\n inputBytes: 0,\n outputBytes: 0,\n ms: 0,\n };\n // Vendor and worker copies share content: compress each distinct file once.\n const byHash = new Map<string, Promise<Buffer | null>>();\n\n await Promise.all(\n targets.map(async (file) => {\n const sibling = file + \".gz\";\n if (await isFresh(file, sibling)) {\n result.skipped += 1;\n return;\n }\n const source = await readFile(file);\n result.inputBytes += source.length;\n const hash = createHash(\"sha256\").update(source).digest(\"hex\");\n let compressed = byHash.get(hash);\n if (!compressed) {\n compressed = gzipAsync(source, { level: 9 }).then((out) =>\n out.length <= source.length * MAX_RATIO ? out : null,\n );\n byHash.set(hash, compressed);\n }\n const out = await compressed;\n if (!out) {\n await rm(sibling, { force: true });\n result.skipped += 1;\n return;\n }\n await writeFile(sibling, out);\n result.written += 1;\n result.outputBytes += out.length;\n }),\n );\n\n result.ms = Math.round(performance.now() - start);\n return result;\n}\n\n/** On by default; PH_CONNECT_PRECOMPRESS=0|false disables it. */\nexport function isPrecompressEnabled(\n env: NodeJS.ProcessEnv = process.env,\n): boolean {\n const raw = env.PH_CONNECT_PRECOMPRESS ?? \"1\";\n return raw !== \"0\" && raw !== \"false\";\n}\n","import {\n DEFAULT_VENDOR_INCLUDE,\n DYNAMIC_BASE_PLACEHOLDER,\n directoryContentDigest,\n findPackageRoot,\n getConnectBaseViteConfig,\n missingVendorEntries,\n prebuildConnectVendor,\n ownProjectPackage,\n prebuildReactorWorker,\n prebuildWorkerPackages,\n resolveReactorWorkerSource,\n type PrebuiltReactorWorker,\n type PrebuiltVendor,\n} from \"@powerhousedao/builder-tools\";\nimport { getConfig } from \"@powerhousedao/shared/clis\";\nimport type { PHConnectRuntimeConfig } from \"@powerhousedao/shared/clis\";\nimport {\n deepMerge,\n normalizeBasePath,\n SHARED_DEP_SPECIFIERS,\n SHARED_SUBPATHS,\n} from \"@powerhousedao/shared/connect\";\nimport { existsSync, mkdirSync, readdirSync, rmSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport type { InlineConfig } from \"vite\";\nimport { build, mergeConfig } from \"vite\";\nimport type { ConnectBuildArgs } from \"../types.js\";\nimport { buildCliConnectOverride } from \"../utils/cli-connect-override.js\";\nimport {\n isPrecompressEnabled,\n precompressAssets,\n} from \"../utils/precompress.js\";\nimport { runBuild } from \"./build.js\";\n\nexport async function runConnectBuild(\n args: ConnectBuildArgs,\n callerOverride?: PHConnectRuntimeConfig,\n { routes }: { routes?: string | false } = {},\n) {\n const { outDir, debug, dynamicBase, favicon } = args;\n\n const mode = \"production\";\n const dirname = process.cwd();\n\n // Build has no read mode; a bare positional `<key>` is a user error. The\n // 2-positional `<key> <value>` form is handled inside buildCliConnectOverride\n // so it layers on top of --json + flags like any other override input.\n if (args.keyPositional !== undefined && args.valuePositional === undefined) {\n throw new Error(\n \"ph connect build: positional override requires both <key> and <value> (e.g. `ph connect build connect.renown.url https://renown.staging`). To read a value, use `ph connect config <key>`.\",\n );\n }\n\n // Fail fast if any package marked as provider: \"local\" is missing from\n // node_modules — the Vite plugin that bundles them needs them on disk.\n assertLocalPackagesInstalled(dirname);\n\n // Build the CLI override layers (--json + individual flags + positional)\n // once here so a bad payload fails before we waste a build.\n // `--packages-registry` lands at the top-level `packageRegistryUrl`\n // (mirrors source-config shape); every other flag feeds the connect-block\n // precedence ladder.\n const cli = buildCliConnectOverride(args);\n const { packageRegistryUrl } = cli;\n // A runner's host config sits under the CLI's flags.\n const connectOverride = callerOverride\n ? deepMerge(callerOverride, cli.connectOverride ?? {})\n : cli.connectOverride;\n\n await runBuild({\n outDir: \"dist\",\n debug,\n // Local packages built for Connect share deps with the app vendor, same\n // as a plain `ph build`.\n noSharedDeps: false,\n ignoreTypeErrors: false,\n release: false,\n });\n\n // Production shared-dependency vendor: prebuilt into <outDir>/__vendor__\n // before the app build. On by default; PH_CONNECT_VENDOR=0|false disables\n // it. A failed prebuild fails the build — production must not ship import\n // map entries pointing at a vendor that was never built (the dev server\n // keeps its own soft fallback in the dev plugin).\n const outDirAbs = resolve(dirname, outDir);\n let vendor: PrebuiltVendor | null = null;\n // The deploy base the vendor's import-map addresses are written against.\n // Only meaningful when the vendor is built; \"/\" is the inert default.\n let appBase = \"/\";\n // The prebuild out dirs' parent must exist before the prebuilds: their\n // build locks are siblings of the out dirs, and the package build\n // (runBuild) writes to a different out dir, so nothing else creates it yet.\n mkdirSync(outDirAbs, { recursive: true });\n if (isVendorEnabled()) {\n const errorRef: { message?: string } = {};\n // The same base string the app build uses below: the dynamic-base\n // placeholder, or the normalized deploy base (CLI override wins over the\n // source config). The vendor worker appends its own segment.\n const phConfig = getConfig(join(dirname, \"powerhouse.config.json\"));\n const connectBasePath =\n connectOverride?.app?.basePath ?? phConfig.connect?.app?.basePath;\n appBase = dynamicBase\n ? DYNAMIC_BASE_PLACEHOLDER\n : connectBasePath\n ? normalizeBasePath(connectBasePath)\n : \"/\";\n vendor = await prebuildConnectVendor({\n dirname,\n include: productionVendorInclude(),\n vendorDir: join(outDirAbs, \"__vendor__\"),\n base: appBase,\n nodeEnv: \"production\",\n errorRef,\n ...connectOwnVendorDeps(dirname),\n });\n if (!vendor) {\n console.error(\n `ph connect build: the shared-dependency vendor failed to build${\n errorRef.message ? `:\\n${errorRef.message}` : \"\"\n }`,\n );\n throw new Error(\"shared-dependency vendor prebuild failed\");\n }\n }\n\n // Reactor SharedWorker bundle: the dist worker is a library artifact whose\n // bare imports no worker can resolve (import maps do not apply to workers),\n // so the deployable form is prebuilt here. With a vendor, its shared deps\n // are externalized onto ../__vendor__/ so page and worker share one cache\n // entry per dep; without one it is fully self-contained.\n const reactorWorker = await prebuildReactorWorkerBundle(\n dirname,\n outDirAbs,\n vendor,\n connectOverride,\n );\n\n // Local project models the worker cannot get from the registry, built into\n // the worker bundle's own directory so they share its vendor.\n if (reactorWorker) {\n await prebuildLocalWorkerPackages(\n dirname,\n outDirAbs,\n vendor,\n reactorWorker.vendorImports,\n );\n }\n\n const keepDirs = [\n ...(vendor ? [\"__vendor__\"] : []),\n ...(reactorWorker ? [\"__reactor_worker__\"] : []),\n ];\n // Stale top-level output goes, the prebuilt dirs stay: the app build below\n // runs with emptyOutDir: false and must not wipe them.\n if (keepDirs.length > 0) {\n cleanDistExcept(outDirAbs, keepDirs);\n }\n\n const baseConfig = getConnectBaseViteConfig({\n mode,\n dirname,\n cliConnectOverride: connectOverride,\n cliPackageRegistryUrl: packageRegistryUrl,\n dynamicBase,\n favicon,\n routes,\n // Vendor import-map entries are relative (leading slash stripped) so\n // they resolve against the page URL under any deploy base — root or\n // subpath, dynamic or concrete.\n vendor: vendor\n ? {\n imports: vendorImportMapEntries(vendor.imports, appBase),\n versions: vendor.versions,\n sharedDeps: vendorImportMapEntries(\n { sharedDeps: vendor.sharedDeps },\n appBase,\n ).sharedDeps,\n }\n : undefined,\n reactorWorkerVersion: reactorWorker\n ? directoryContentDigest(join(outDirAbs, \"__reactor_worker__\"))\n : undefined,\n });\n\n const buildConfig: InlineConfig = {\n build: {\n outDir,\n // The vendor / worker dirs were prebuilt into the out dir above; the\n // build must not empty them.\n ...(keepDirs.length > 0 ? { emptyOutDir: false } : {}),\n },\n };\n\n const config = mergeConfig(baseConfig, buildConfig);\n\n await build(config);\n\n // Last word on the shipped artifact: every specifier the page's import map\n // publishes must have a file next to it. The prebuild verifies its own\n // output, but it can return a cache hit it never rebuilt, and both the\n // stale-output clean and the app build run afterwards. An entry with no\n // file behind it ships as a URL that 404s, and a SPA answers that with\n // index.html — so the browser reports only an opaque MIME-type error with\n // no filename. Fail here instead, naming the entries.\n if (vendor) {\n const unbacked = missingVendorEntries(\n join(outDirAbs, \"__vendor__\"),\n vendor.imports,\n );\n if (unbacked.length > 0) {\n throw new Error(\n `ph connect build: the shared-dependency vendor is missing ` +\n `${unbacked.length} of the ${Object.keys(vendor.imports).length} ` +\n `entries its import map publishes:\\n` +\n unbacked.map((e) => ` ${e.spec} -> ${e.url}`).join(\"\\n\"),\n );\n }\n }\n\n // Runs after the PWA plugin, so the siblings never enter the precache list.\n if (isPrecompressEnabled()) {\n const r = await precompressAssets(outDirAbs);\n console.log(\n `ph connect build: precompressed ${r.files} wasm/data files ` +\n `(${r.written} .gz written, ${(r.outputBytes / 1e6).toFixed(1)} MB) in ${(r.ms / 1000).toFixed(1)}s`,\n );\n }\n}\n\n/**\n * The specifier set the production vendor bundles: the dev-proven heavy set\n * ∪ the package-shared set — everything the app and loaded packages\n * externalize onto the vendor.\n *\n * Two specifiers are deliberately dropped:\n *\n * - `@powerhousedao/connect`. It is in DEFAULT_VENDOR_INCLUDE because the dev\n * server vendors the app to keep rebuilds cheap, but in a production build\n * the app *is* Connect: `SHARED_DEP_SPECIFIERS` omits it, so the app build\n * never externalizes it and nothing would ever resolve its import-map\n * entry. Vendoring it is not merely dead weight — bundling Connect's dist\n * for the browser pulls in its node-only `@powerhousedao/config/node`\n * import, and so `read-pkg` -> `unicorn-magic`, whose browser entry has no\n * `toPath`. That fails the vendor build, and a failed prebuild fails\n * `ph connect build`.\n * - the bare `@powerhousedao/shared` root, whose barrel likewise reaches\n * node-only modules. Its browser-safe subpaths (SHARED_SUBPATHS) are\n * listed instead; a package importing the bare root bundles its own copy.\n */\nexport function productionVendorInclude(): string[] {\n return [\n ...new Set([\n ...DEFAULT_VENDOR_INCLUDE.filter((s) => s !== \"@powerhousedao/connect\"),\n ...SHARED_DEP_SPECIFIERS.filter((s) => s !== \"@powerhousedao/shared\"),\n ...SHARED_SUBPATHS.map((s) => `@powerhousedao/shared/${s}`),\n // Connect imports these roots too; unvendored, the app re-bundles their shared chunks.\n \"@powerhousedao/design-system\",\n \"@powerhousedao/reactor\",\n ]),\n ];\n}\n\n/** Connect's own deps that vendored packages also bundle; projects don't install them. */\nexport const CONNECT_OWN_VENDOR_DEPS = [\n \"kysely\",\n \"tailwind-merge\",\n \"@renown/sdk\",\n \"@renown/sdk/crypto\",\n \"@renown/sdk/trust\",\n \"@powerhousedao/reactor-attachments/client\",\n // One core and router for Connect and packages; the route tree, config and\n // embedded subpaths stay with the app.\n \"@powerhousedao/connect-core\",\n \"@powerhousedao/connect-core/router\",\n \"@powerhousedao/connect-core/plugins\",\n \"@powerhousedao/connect-core/runtime\",\n \"@powerhousedao/connect-core/views\",\n \"@tanstack/react-router\",\n];\n\nexport function connectOwnVendorDeps(dirname: string): {\n ownDeps?: { specs: string[]; from: string };\n} {\n const from = findPackageRoot(dirname, \"@powerhousedao/connect\");\n return from ? { ownDeps: { specs: CONNECT_OWN_VENDOR_DEPS, from } } : {};\n}\n\n/**\n * Turn the vendor's base-less URLs (`/__vendor__/x.js`) into the addresses\n * the page's import map ships, by prefixing the deploy base.\n *\n * An import map *address* must be a URL or begin with `/`, `./` or `../`;\n * anything else is a bare specifier, which the browser rejects — it drops the\n * entry, resolves the specifier to null, and every shared import then fails\n * with \"blocked by a null value\". So the base is applied rather than the\n * leading slash stripped: a root-relative address is both valid and correct\n * under a subpath deploy, and a dynamic-base build keeps its placeholder for\n * the serving proxy to substitute (the dynamic-base plugin leaves HTML\n * tokens alone by design).\n */\nexport function vendorImportMapEntries(\n imports: Record<string, string>,\n appBase: string,\n): Record<string, string> {\n return Object.fromEntries(\n Object.entries(imports).map(([spec, url]) => [\n spec,\n `${appBase}/${url}`.replace(/\\/{2,}/g, \"/\"),\n ]),\n );\n}\n\n/**\n * The production vendor prebuild runs on every `ph connect build` unless\n * disabled with PH_CONNECT_VENDOR=0 or false.\n */\nexport function isVendorEnabled(env: NodeJS.ProcessEnv = process.env): boolean {\n const raw = env.PH_CONNECT_VENDOR ?? \"1\";\n return raw !== \"0\" && raw !== \"false\";\n}\n\n/**\n * The reactor worker bundle prebuild runs on every `ph connect build` unless\n * disabled with PH_CONNECT_REACTOR_WORKER=0 or false. It is built even when\n * `connect.instance.reactorWorker` is off, because the `?reactorWorker=true`\n * runtime override can enable the feature on a flag-off deployment.\n */\nexport function isReactorWorkerBundleEnabled(\n env: NodeJS.ProcessEnv = process.env,\n): boolean {\n const raw = env.PH_CONNECT_REACTOR_WORKER ?? \"1\";\n return raw !== \"0\" && raw !== \"false\";\n}\n\n/**\n * Prebuild the reactor SharedWorker bundle into `<dist>/__reactor_worker__`.\n * Returns null when the prebuild is disabled, the installed Connect ships no\n * worker entry, or the build fails. A failure only fails `ph connect build`\n * when the project explicitly enables `connect.instance.reactorWorker` —\n * otherwise the feature degrades to unavailable and the build goes on.\n */\nasync function prebuildReactorWorkerBundle(\n dirname: string,\n outDirAbs: string,\n vendor: PrebuiltVendor | null,\n connectOverride: PHConnectRuntimeConfig | undefined,\n): Promise<PrebuiltReactorWorker | null> {\n if (!isReactorWorkerBundleEnabled()) return null;\n if (!resolveReactorWorkerSource(dirname)) return null;\n\n const errorRef: { message?: string } = {};\n const bundle = await prebuildReactorWorker({\n dirname,\n outDir: join(outDirAbs, \"__reactor_worker__\"),\n vendor: vendor\n ? { imports: vendor.imports, dir: join(outDirAbs, \"__vendor__\") }\n : undefined,\n nodeEnv: \"production\",\n errorRef,\n });\n if (bundle) return bundle;\n\n const message = `ph connect build: the reactor worker bundle failed to build${\n errorRef.message ? `:\\n${errorRef.message}` : \"\"\n }`;\n const phConfig = getConfig(join(dirname, \"powerhouse.config.json\"));\n const required =\n connectOverride?.instance?.reactorWorker ??\n phConfig.connect?.instance?.reactorWorker ??\n false;\n if (required) {\n throw new Error(message);\n }\n console.warn(\n `${message}\\nThe reactorWorker feature will be unavailable in this build.`,\n );\n return null;\n}\n\n/**\n * Build the project's `provider: \"local\"` packages into worker-loadable model\n * bundles beside the worker. A failure is a warning, not a build failure: the\n * worker still runs, and documents of registry types still work - only the\n * project's own types would be unavailable in worker mode.\n */\nasync function prebuildLocalWorkerPackages(\n dirname: string,\n outDirAbs: string,\n vendor: PrebuiltVendor | null,\n safeVendorImports: Record<string, string>,\n): Promise<void> {\n const config = getConfig(join(dirname, \"powerhouse.config.json\"));\n const configured = (config.packages ?? [])\n .filter((p) => p.provider === \"local\")\n .map((p) => p.packageName);\n // The project itself is a local package in all but name: a vetra project\n // declares no entry for itself, and its models are the ones the worker\n // cannot otherwise get.\n const own = ownProjectPackage(dirname);\n const localPackages = [...new Set([...configured, ...(own ? [own] : [])])];\n\n const errorRef: { message?: string } = {};\n const built = await prebuildWorkerPackages({\n dirname,\n packages: localPackages,\n outDir: join(outDirAbs, \"__reactor_worker__\", \"packages\"),\n vendor: vendor\n ? { imports: vendor.imports, dir: join(outDirAbs, \"__vendor__\") }\n : undefined,\n safeVendorImports,\n nodeEnv: \"production\",\n errorRef,\n });\n if (!built) {\n console.warn(\n `ph connect build: the reactor worker's local package bundles failed to build${\n errorRef.message ? `:\\n${errorRef.message}` : \"\"\n }\\nDocuments of this project's own types will not load in worker mode.`,\n );\n }\n}\n\n/**\n * Remove every top-level entry of `dist` except the kept names. Used between\n * the vendor prebuild and the app build so stale app output goes but the\n * just-built vendor stays (the build then runs with emptyOutDir: false).\n * Returns the number of entries removed.\n */\nexport function cleanDistExcept(dist: string, keep: string[] = []): number {\n if (!existsSync(dist)) return 0;\n let removed = 0;\n for (const entry of readdirSync(dist)) {\n if (keep.includes(entry)) continue;\n rmSync(join(dist, entry), { recursive: true, force: true });\n removed += 1;\n }\n return removed;\n}\n\nfunction assertLocalPackagesInstalled(projectPath: string) {\n const config = getConfig(join(projectPath, \"powerhouse.config.json\"));\n const localPackages = (config.packages ?? []).filter(\n (p) => p.provider === \"local\",\n );\n if (localPackages.length === 0) return;\n\n const missing = localPackages.filter(\n (p) =>\n !existsSync(\n join(projectPath, \"node_modules\", p.packageName, \"package.json\"),\n ),\n );\n if (missing.length === 0) return;\n\n const names = missing.map((p) => p.packageName);\n throw new Error(\n `ph connect build requires these packages to be installed in node_modules (they are declared with provider: \"local\" in powerhouse.config.json):\\n` +\n names.map((n) => ` - ${n}`).join(\"\\n\") +\n `\\n\\nInstall them with:\\n ph install --local ${names.join(\" \")}`,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAOA,MAAM,YAAY,UAAU,IAAI;;AAKhC,MAAM,YAAY;AAWlB,eAAe,YAAY,KAAgC;CAEzD,QAAO,MADe,QAAQ,KAAK;EAAE,WAAW;EAAM,eAAe;CAAK,CAAC,EAAA,CAExE,QACE,MACC,EAAE,OAAO,KACT,uBAAuB,MAAM,QAAQ,EAAE,KAAK,SAAS,GAAG,CAAC,CAC7D,CAAC,CACA,KAAK,MAAM,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;AAC1C;AAEA,eAAe,QAAQ,QAAgB,SAAmC;CACxE,IAAI;EACF,MAA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;CACA,OAAO;AACT;AAEA,SAAS,6BAA6B,aAAqB;CAEzD,MAAM,iBADS,UAAU,KAAK,aAAa,wBAAwB,CACvC,CAAC,CAAC,YAAY,CAAC,EAAA,CAAG,QAC3C,MAAM,EAAE,aAAa,OACxB;CACA,IAAI,cAAc,WAAW,GAAG;CAEhC,MAAM,UAAU,cAAc,QAC3B,MACC,CAAC,WACC,KAAK,aAAa,gBAAgB,EAAE,aAAa,cAAc,CACjE,CACJ;CACA,IAAI,QAAQ,WAAW,GAAG;CAE1B,MAAM,QAAQ,QAAQ,KAAK,MAAM,EAAE,WAAW;CAC9C,MAAM,IAAI,MACR,qJACE,MAAM,KAAK,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI,IACtC,gDAAgD,MAAM,KAAK,GAAG,GAClE;AACF","debug_id":"3e1a6e83-3f3f-51f4-b952-285f5fe9f028"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions-worker.d.mts","names":[],"sources":["../src/services/release/approval.ts","../src/services/release/evidence.ts","../src/services/model/definitions-worker.ts"],"mappings":";;;;cA0BM,gBAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwClB;;KAGU,kBAAkB,cAAe;;KAGjC,gBAAgB;;;;
|
|
1
|
+
{"version":3,"file":"definitions-worker.d.mts","names":[],"sources":["../src/services/release/approval.ts","../src/services/release/evidence.ts","../src/services/model/definitions-worker.ts"],"mappings":";;;;cA0BM,gBAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwClB;;KAGU,kBAAkB,cAAe;;KAGjC,gBAAgB;;;;KC7ChB;WACD,QAAQ;WACR,MAAM;WACN,kBAAkB;;;;;;;;YCrBjB;WACD,MAAM;WACN,SAAS;;YAGR,2BAA2B;;YAG3B,iBAAiB,UAAU;WACxB;WAAmB,QAAQ,mBAAmB;;WAC9C;WAAoB"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import { i as readProjectDefinitions } from "./run-
|
|
4
|
-
import { t as definitionChecks } from "./check-
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="edf7b6f1-f92c-5c1c-a38c-826e30b54557")}catch(e){}}();
|
|
3
|
+
import { i as readProjectDefinitions } from "./run--de_-WAz.mjs";
|
|
4
|
+
import { t as definitionChecks } from "./check-S29MtxQp.mjs";
|
|
5
5
|
//#region src/services/model/definitions-worker.ts
|
|
6
6
|
async function check(projectRoot, profile) {
|
|
7
7
|
const read = definitionChecks[profile];
|
|
8
8
|
try {
|
|
9
9
|
return {
|
|
10
10
|
ok: true,
|
|
11
|
-
result: await readProjectDefinitions(projectRoot, read)
|
|
11
|
+
result: await readProjectDefinitions(projectRoot, read, { allowMissingConfig: true })
|
|
12
12
|
};
|
|
13
13
|
} catch (error) {
|
|
14
14
|
return {
|
|
@@ -25,4 +25,4 @@ process.send(reply, () => process.exit(0));
|
|
|
25
25
|
export {};
|
|
26
26
|
|
|
27
27
|
//# sourceMappingURL=definitions-worker.mjs.map
|
|
28
|
-
//# debugId=
|
|
28
|
+
//# debugId=edf7b6f1-f92c-5c1c-a38c-826e30b54557
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions-worker.mjs","sources":["../src/services/model/definitions-worker.ts"],"sourcesContent":["import type { DefinitionCheckReport } from \"@powerhousedao/shared/document-model\";\nimport type { ReleaseCheck } from \"../release/evidence.js\";\nimport { definitionChecks } from \"./check.js\";\nimport { readProjectDefinitions } from \"./project.js\";\n\n/**\n * What the definitions worker reports for each profile. `ph build` forks the\n * worker so the package's own modules never run in the build process.\n */\nexport type DefinitionsResults = {\n readonly edit: DefinitionCheckReport;\n readonly release: ReleaseCheck;\n};\n\nexport type DefinitionsProfile = keyof DefinitionsResults;\n\n/** The worker's one IPC message: the check's result, or why it could not run. */\nexport type DefinitionsReply<P extends DefinitionsProfile> =\n | { readonly ok: true; readonly result: DefinitionsResults[P] }\n | { readonly ok: false; readonly message: string };\n\nasync function check(\n projectRoot: string,\n profile: DefinitionsProfile,\n): Promise<DefinitionsReply<DefinitionsProfile>> {\n const read: (\n ...args: Parameters<typeof definitionChecks.release>\n ) => Promise<DefinitionsResults[DefinitionsProfile]> =\n definitionChecks[profile];\n try {\n return {\n ok: true,\n result: await readProjectDefinitions(projectRoot, read),\n };\n } catch (error) {\n return {\n ok: false,\n message: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\n// The build that forked this worker has gone: nothing is left to report to.\nprocess.on(\"disconnect\", () => process.exit(1));\nconst [projectRoot, profile] = process.argv.slice(2) as [\n string,\n DefinitionsProfile,\n];\nconst reply = await check(projectRoot, profile);\n// Exit once the reply is sent: a module's timer must not keep the worker alive.\nprocess.send!(reply, () => process.exit(0));\n"],"names":[],"mappings":";;;;;AAqBA,eAAe,MACb,aACA,SAC+C;CAC/C,MAAM,OAGJ,iBAAiB;CACnB,IAAI;EACF,OAAO;GACL,IAAI;GACJ,QAAQ,MAAM,uBAAuB,aAAa,
|
|
1
|
+
{"version":3,"file":"definitions-worker.mjs","sources":["../src/services/model/definitions-worker.ts"],"sourcesContent":["import type { DefinitionCheckReport } from \"@powerhousedao/shared/document-model\";\nimport type { ReleaseCheck } from \"../release/evidence.js\";\nimport { definitionChecks } from \"./check.js\";\nimport { readProjectDefinitions } from \"./project.js\";\n\n/**\n * What the definitions worker reports for each profile. `ph build` forks the\n * worker so the package's own modules never run in the build process.\n */\nexport type DefinitionsResults = {\n readonly edit: DefinitionCheckReport;\n readonly release: ReleaseCheck;\n};\n\nexport type DefinitionsProfile = keyof DefinitionsResults;\n\n/** The worker's one IPC message: the check's result, or why it could not run. */\nexport type DefinitionsReply<P extends DefinitionsProfile> =\n | { readonly ok: true; readonly result: DefinitionsResults[P] }\n | { readonly ok: false; readonly message: string };\n\nasync function check(\n projectRoot: string,\n profile: DefinitionsProfile,\n): Promise<DefinitionsReply<DefinitionsProfile>> {\n const read: (\n ...args: Parameters<typeof definitionChecks.release>\n ) => Promise<DefinitionsResults[DefinitionsProfile]> =\n definitionChecks[profile];\n try {\n return {\n ok: true,\n result: await readProjectDefinitions(projectRoot, read, {\n allowMissingConfig: true,\n }),\n };\n } catch (error) {\n return {\n ok: false,\n message: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\n// The build that forked this worker has gone: nothing is left to report to.\nprocess.on(\"disconnect\", () => process.exit(1));\nconst [projectRoot, profile] = process.argv.slice(2) as [\n string,\n DefinitionsProfile,\n];\nconst reply = await check(projectRoot, profile);\n// Exit once the reply is sent: a module's timer must not keep the worker alive.\nprocess.send!(reply, () => process.exit(0));\n"],"names":[],"mappings":";;;;;AAqBA,eAAe,MACb,aACA,SAC+C;CAC/C,MAAM,OAGJ,iBAAiB;CACnB,IAAI;EACF,OAAO;GACL,IAAI;GACJ,QAAQ,MAAM,uBAAuB,aAAa,MAAM,EACtD,oBAAoB,KACtB,CAAC;EACH;CACF,SAAS,OAAO;EACd,OAAO;GACL,IAAI;GACJ,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAChE;CACF;AACF;AAGA,QAAQ,GAAG,oBAAoB,QAAQ,KAAK,CAAC,CAAC;AAC9C,MAAM,CAAC,aAAa,WAAW,QAAQ,KAAK,MAAM,CAAC;AAInD,MAAM,QAAQ,MAAM,MAAM,aAAa,OAAO;AAE9C,QAAQ,KAAM,aAAa,QAAQ,KAAK,CAAC,CAAC","debug_id":"edf7b6f1-f92c-5c1c-a38c-826e30b54557"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="31bc77e4-82c3-5778-8047-9e8545ded30f")}catch(e){}}();
|
|
3
3
|
import { l as looseObject, m as string } from "./schemas-DzgKfQIx.mjs";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
@@ -96,18 +96,32 @@ async function validateForHost(project, modules, identity) {
|
|
|
96
96
|
/**
|
|
97
97
|
* The release profile: the edit checks plus the release checks, over every
|
|
98
98
|
* artifact, stored models included, with host validation as evidence.
|
|
99
|
-
*
|
|
99
|
+
* `contributions` adds another layer's checks to the one report the
|
|
100
|
+
* approval records. Writes nothing.
|
|
100
101
|
*/
|
|
101
|
-
async function checkForRelease(project, modules) {
|
|
102
|
+
async function checkForRelease(project, modules, options = {}) {
|
|
102
103
|
const identity = packageIdentity(project.packageRoot);
|
|
103
104
|
const host = await validateForHost(project, modules, identity);
|
|
105
|
+
const { contributions } = options;
|
|
106
|
+
const input = {
|
|
107
|
+
...project,
|
|
108
|
+
release: { host }
|
|
109
|
+
};
|
|
104
110
|
return {
|
|
105
|
-
report: await checkProjectDefinitions({
|
|
106
|
-
...project,
|
|
107
|
-
release: { host }
|
|
108
|
-
}, {
|
|
111
|
+
report: contributions === void 0 ? await checkProjectDefinitions(input, {
|
|
109
112
|
checks: [...documentModelChecks, ...releaseChecks],
|
|
110
113
|
profile: "release"
|
|
114
|
+
}) : await checkProjectDefinitions({
|
|
115
|
+
...input,
|
|
116
|
+
...contributions.input
|
|
117
|
+
}, {
|
|
118
|
+
checks: [
|
|
119
|
+
...documentModelChecks,
|
|
120
|
+
...releaseChecks,
|
|
121
|
+
...contributions.checks
|
|
122
|
+
],
|
|
123
|
+
definitions: contributions.inventory,
|
|
124
|
+
profile: "release"
|
|
111
125
|
}),
|
|
112
126
|
host,
|
|
113
127
|
scalars: scalarBindings(project.artifacts, identity, installedDocumentModelVersion(project.packageRoot))
|
|
@@ -116,5 +130,5 @@ async function checkForRelease(project, modules) {
|
|
|
116
130
|
//#endregion
|
|
117
131
|
export { checkForRelease };
|
|
118
132
|
|
|
119
|
-
//# sourceMappingURL=evidence-
|
|
120
|
-
//# debugId=
|
|
133
|
+
//# sourceMappingURL=evidence-CavwC5YV.mjs.map
|
|
134
|
+
//# debugId=31bc77e4-82c3-5778-8047-9e8545ded30f
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence-CavwC5YV.mjs","sources":["../src/services/release/scalar-bindings.ts","../src/services/release/evidence.ts"],"sourcesContent":["import type { ScalarBinding } from \"./approval.js\";\n\n/** What a binding reads of an artifact: the version it serves and the scalars each version uses. */\ntype ServedArtifact = {\n readonly version: number;\n readonly definition: {\n readonly specifications: readonly {\n readonly version: number;\n readonly scalars: readonly {\n readonly name: string;\n readonly implementation: string;\n }[];\n }[];\n };\n};\n\n/** The package's name and version, as its package.json gives them. */\nexport type PackageIdentity = {\n readonly name: string | undefined;\n readonly version: string | undefined;\n};\n\n/**\n * The scalars the served versions use, by name: a catalog scalar comes with\n * the installed document-model, at `catalogVersion`, a package scalar with\n * this package.\n */\nexport function scalarBindings(\n artifacts: readonly ServedArtifact[],\n identity: PackageIdentity,\n catalogVersion: string | null,\n): ScalarBinding[] {\n const bindings = new Map<string, ScalarBinding>();\n for (const artifact of artifacts) {\n const served = artifact.definition.specifications.find(\n ({ version }) => version === artifact.version,\n );\n for (const { name, implementation } of served?.scalars ?? []) {\n bindings.set(\n name,\n implementation.startsWith(\"powerhouse.catalog#\")\n ? {\n scalar: name,\n packageName: \"document-model\",\n version: catalogVersion,\n }\n : {\n scalar: name,\n packageName: identity.name ?? \"\",\n version: identity.version ?? null,\n },\n );\n }\n }\n return [...bindings.values()].sort((left, right) =>\n left.scalar < right.scalar ? -1 : left.scalar > right.scalar ? 1 : 0,\n );\n}\n","import type { DefinitionCheckReport } from \"@powerhousedao/shared/document-model\";\nimport {\n checkProjectDefinitions,\n type DefinitionCheck,\n documentModelChecks,\n type HostValidationEvidence,\n type ProjectDefinitions,\n type ReleaseCheckInput,\n releaseChecks,\n} from \"document-model/tooling\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { z } from \"zod\";\nimport type { ScalarBinding } from \"./approval.js\";\nimport { type PackageIdentity, scalarBindings } from \"./scalar-bindings.js\";\n\n/** Imports a package module through the loader that loaded its definitions. */\ntype PackageModules = {\n readonly importModule: (\n specifier: `./${string}`,\n ) => Promise<Readonly<Record<string, unknown>>>;\n};\n\n/** The package's scalars entry, as `ph build` bundles it and a host loads it. */\nconst SCALARS_ENTRY = \"./scalars/index.ts\";\n\n/** What the release profile found: the report, and the evidence an approval records. */\nexport type ReleaseCheck = {\n readonly report: DefinitionCheckReport;\n readonly host: HostValidationEvidence;\n readonly scalars: readonly ScalarBinding[];\n};\n\n/**\n * Checks another layer adds to the release profile, with the input they\n * read and the inventory entries they cover. The command boundary passes\n * them in, so release code imports no module of that layer.\n */\nexport type ReleaseContributions<TInput extends object> = {\n readonly checks: readonly DefinitionCheck<ReleaseCheckInput & TInput>[];\n readonly input: TInput;\n readonly inventory: DefinitionCheckReport[\"definitions\"];\n};\n\nconst errorMessage = (error: unknown) =>\n error instanceof Error ? error.message : String(error);\n\nconst packageJson = z.looseObject({\n name: z.string().min(1).optional(),\n version: z.string().min(1).optional(),\n});\n\nfunction readPackageJson(path: string): z.infer<typeof packageJson> {\n try {\n const parsed = packageJson.safeParse(\n JSON.parse(readFileSync(path, \"utf8\")),\n );\n return parsed.success ? parsed.data : {};\n } catch {\n return {};\n }\n}\n\nfunction packageIdentity(packageRoot: string): PackageIdentity {\n const { name, version } = readPackageJson(join(packageRoot, \"package.json\"));\n return { name, version };\n}\n\n/** The version of document-model the package resolves, as Node finds a bare import. */\nfunction installedDocumentModelVersion(packageRoot: string): string | null {\n for (let directory = packageRoot; ; directory = dirname(directory)) {\n const json = readPackageJson(\n join(directory, \"node_modules\", \"document-model\", \"package.json\"),\n );\n if (json.version !== undefined) return json.version;\n if (dirname(directory) === directory) return null;\n }\n}\n\n/** Tool and Node messages can quote the machine path the package lives at. */\nconst packageRelative = (text: string, packageRoot: string) =>\n text.replaceAll(packageRoot, \".\");\n\n/**\n * Validates the models as a host that installed this package would: its\n * scalars entry builds the registry the way the host builds it, and each\n * artifact supplies the module's documentModel, definition and version.\n */\nasync function validateForHost(\n project: ProjectDefinitions,\n modules: PackageModules,\n identity: PackageIdentity,\n): Promise<HostValidationEvidence> {\n if (identity.name === undefined) {\n return {\n completed: false,\n reason:\n \"package.json has no name, and a host registers package scalars by package name\",\n findings: [],\n };\n }\n let scalars: Readonly<Record<string, unknown>> = {};\n if (existsSync(join(project.packageRoot, SCALARS_ENTRY))) {\n try {\n scalars = await modules.importModule(SCALARS_ENTRY);\n } catch (error) {\n return {\n completed: false,\n reason: packageRelative(\n `${SCALARS_ENTRY} could not be loaded: ${errorMessage(error)}`,\n project.packageRoot,\n ),\n findings: [],\n };\n }\n }\n const {\n buildScalarRegistry,\n scalarExportsOf,\n validateDocumentModelsForHost,\n } = await import(\"@powerhousedao/reactor-api\");\n const { registry } = buildScalarRegistry(\n new Map([[identity.name, scalarExportsOf(scalars)]]),\n );\n const { findings } = validateDocumentModelsForHost(\n project.artifacts.map(({ documentModel, definition, version }) => ({\n documentModel,\n definition,\n version,\n })),\n registry,\n );\n return { completed: true, findings };\n}\n\n/**\n * The release profile: the edit checks plus the release checks, over every\n * artifact, stored models included, with host validation as evidence.\n * `contributions` adds another layer's checks to the one report the\n * approval records. Writes nothing.\n */\nexport async function checkForRelease<TInput extends object>(\n project: ProjectDefinitions,\n modules: PackageModules,\n options: { readonly contributions?: ReleaseContributions<TInput> } = {},\n): Promise<ReleaseCheck> {\n const identity = packageIdentity(project.packageRoot);\n const host = await validateForHost(project, modules, identity);\n const { contributions } = options;\n const input = { ...project, release: { host } };\n const report =\n contributions === undefined\n ? await checkProjectDefinitions(input, {\n checks: [...documentModelChecks, ...releaseChecks],\n profile: \"release\",\n })\n : await checkProjectDefinitions<ReleaseCheckInput & TInput>(\n { ...input, ...contributions.input },\n {\n checks: [\n ...documentModelChecks,\n ...releaseChecks,\n ...contributions.checks,\n ],\n definitions: contributions.inventory,\n profile: \"release\",\n },\n );\n return {\n report,\n host,\n scalars: scalarBindings(\n project.artifacts,\n identity,\n installedDocumentModelVersion(project.packageRoot),\n ),\n };\n}\n"],"names":["z.looseObject","z.string"],"mappings":";;;;;;;;;;;;AA2BA,SAAgB,eACd,WACA,UACA,gBACiB;CACjB,MAAM,2BAAW,IAAI,IAA2B;CAChD,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,SAAS,SAAS,WAAW,eAAe,MAC/C,EAAE,cAAc,YAAY,SAAS,OACxC;EACA,KAAK,MAAM,EAAE,MAAM,oBAAoB,QAAQ,WAAW,CAAC,GACzD,SAAS,IACP,MACA,eAAe,WAAW,qBAAqB,IAC3C;GACE,QAAQ;GACR,aAAa;GACb,SAAS;EACX,IACA;GACE,QAAQ;GACR,aAAa,SAAS,QAAQ;GAC9B,SAAS,SAAS,WAAW;EAC/B,CACN;CAEJ;CACA,OAAO,CAAC,GAAG,SAAS,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,UACxC,KAAK,SAAS,MAAM,SAAS,KAAK,KAAK,SAAS,MAAM,SAAS,IAAI,CACrE;AACF;;;;ACjCA,MAAM,gBAAgB;AAoBtB,MAAM,gBAAgB,UACpB,iBAAiB,QAAQ,MAAM,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AM,OAAO;CACjB,MAAM,EAAE,aAAa,oCACnB,IAAI,IAAI,CAAC,CAAC,SAAS,MAAM,gBAAgB,OAAO,CAAC,CAAC,CAAC,CACrD;CACA,MAAM,EAAE,aAAa,8BACnB,QAAQ,UAAU,KAAK,EAAE,eAAe,YAAY,eAAe;EACjE;EACA;EACA;CACF,EAAE,GACF,QACF;CACA,OAAO;EAAE,WAAW;EAAM;CAAS;AACrC;;;;;;;AAQA,eAAsB,gBACpB,SACA,SACA,UAAqE,CAAC,GAC/C;CACvB,MAAM,WAAW,gBAAgB,QAAQ,WAAW;CACpD,MAAM,OAAO,MAAM,gBAAgB,SAAS,SAAS,QAAQ;CAC7D,MAAM,EAAE,kBAAkB;CAC1B,MAAM,QAAQ;EAAE,GAAG;EAAS,SAAS,EAAE,KAAK;CAAE;CAmB9C,OAAO;EACL,QAlBA,kBAAkB,KAAA,IACd,MAAM,wBAAwB,OAAO;GACnC,QAAQ,CAAC,GAAG,qBAAqB,GAAG,aAAa;GACjD,SAAS;EACX,CAAC,IACD,MAAM,wBACJ;GAAE,GAAG;GAAO,GAAG,cAAc;EAAM,GACnC;GACE,QAAQ;IACN,GAAG;IACH,GAAG;IACH,GAAG,cAAc;GACnB;GACA,aAAa,cAAc;GAC3B,SAAS;EACX,CACF;EAGJ;EACA,SAAS,eACP,QAAQ,WACR,UACA,8BAA8B,QAAQ,WAAW,CACnD;CACF;AACF","debug_id":"31bc77e4-82c3-5778-8047-9e8545ded30f"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="89143b8c-2c2f-5fb8-8fd9-e4c9624bfdd9")}catch(e){}}();
|
|
3
3
|
import { t as isUniformRunnersEnabled } from "./feature-flags-xwqcHEWC.mjs";
|
|
4
4
|
import { M as probeHostsFolder } from "./compound-DO_mvh0O-Dp1YPhR0.mjs";
|
|
5
5
|
import { t as warnSubgraphTypeConflicts } from "./warn-subgraph-type-conflicts-BOHBmThq.mjs";
|
|
6
|
-
import { n as selectProjectModelGeneration } from "./authoring-mode-DWbbsuWh.mjs";
|
|
7
6
|
import { t as startGenerateHosts } from "./generate-hosts-BFmPIW2X.mjs";
|
|
7
|
+
import { modelGeneration } from "@powerhousedao/codegen";
|
|
8
8
|
import { buildTsMorphProject } from "@powerhousedao/codegen/utils";
|
|
9
9
|
import { extractAllDocuments, saveSpec } from "@powerhousedao/vetra/codegen";
|
|
10
10
|
//#region src/services/generate-all.ts
|
|
@@ -24,7 +24,7 @@ async function startGenerateAll(args, projectDir) {
|
|
|
24
24
|
}
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
await
|
|
27
|
+
await modelGeneration.generateAll(project);
|
|
28
28
|
await project.save();
|
|
29
29
|
await warnSubgraphTypeConflicts(projectDir);
|
|
30
30
|
if (isUniformRunnersEnabled() && probeHostsFolder(projectDir).kind === "present" && !await startGenerateHosts(projectDir)) process.exitCode = 1;
|
|
@@ -32,5 +32,5 @@ async function startGenerateAll(args, projectDir) {
|
|
|
32
32
|
//#endregion
|
|
33
33
|
export { startGenerateAll };
|
|
34
34
|
|
|
35
|
-
//# sourceMappingURL=generate-all-
|
|
36
|
-
//# debugId=
|
|
35
|
+
//# sourceMappingURL=generate-all-cgygbYEX.mjs.map
|
|
36
|
+
//# debugId=89143b8c-2c2f-5fb8-8fd9-e4c9624bfdd9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-all-cgygbYEX.mjs","sources":["../src/services/generate-all.ts"],"sourcesContent":["import { modelGeneration } from \"@powerhousedao/codegen\";\nimport { buildTsMorphProject } from \"@powerhousedao/codegen/utils\";\nimport { extractAllDocuments, saveSpec } from \"@powerhousedao/vetra/codegen\";\nimport { probeHostsFolder } from \"@powerhousedao/host-core\";\nimport { isUniformRunnersEnabled } from \"../utils/feature-flags.js\";\nimport { warnSubgraphTypeConflicts } from \"../utils/warn-subgraph-type-conflicts.js\";\nimport { startGenerateHosts } from \"./generate-hosts.js\";\n\nexport async function startGenerateAll(\n args: { extract?: boolean },\n projectDir: string,\n) {\n const project = buildTsMorphProject(projectDir);\n if (args.extract) {\n const all = extractAllDocuments(project);\n for (const doc of [\n ...all.documentModels,\n ...all.editors,\n ...all.processors,\n ...all.subgraphs,\n ...all.apps,\n ]) {\n const path = await saveSpec(doc, projectDir);\n console.log(`Wrote ${path}`);\n }\n return;\n }\n await modelGeneration.generateAll(project);\n await project.save();\n await warnSubgraphTypeConflicts(projectDir);\n if (\n isUniformRunnersEnabled() &&\n probeHostsFolder(projectDir).kind === \"present\" &&\n !(await startGenerateHosts(projectDir))\n ) {\n process.exitCode = 1;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAQA,eAAsB,iBACpB,MACA,YACA;CACA,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,KAAK,SAAS;EAChB,MAAM,MAAM,oBAAoB,OAAO;EACvC,KAAK,MAAM,OAAO;GAChB,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;EACT,GAAG;GACD,MAAM,OAAO,MAAM,SAAS,KAAK,UAAU;GAC3C,QAAQ,IAAI,SAAS,MAAM;EAC7B;EACA;CACF;CACA,MAAM,gBAAgB,YAAY,OAAO;CACzC,MAAM,QAAQ,KAAK;CACnB,MAAM,0BAA0B,UAAU;CAC1C,IACE,wBAAwB,KACxB,iBAAiB,UAAU,CAAC,CAAC,SAAS,aACtC,CAAE,MAAM,mBAAmB,UAAU,GAErC,QAAQ,WAAW;AAEvB","debug_id":"89143b8c-2c2f-5fb8-8fd9-e4c9624bfdd9"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9abb9264-65d9-577b-a83a-145383e907f3")}catch(e){}}();
|
|
3
3
|
import { t as warnSubgraphTypeConflicts } from "./warn-subgraph-type-conflicts-BOHBmThq.mjs";
|
|
4
|
-
import { r as selectScaffoldGeneration, t as selectDocumentModelGeneration } from "./authoring-mode-DWbbsuWh.mjs";
|
|
5
4
|
import { t as resolveModuleDirName } from "./module-dir-1avCXsBi.mjs";
|
|
6
5
|
import { existsSync } from "node:fs";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { loadDocumentModel } from "@powerhousedao/codegen";
|
|
6
|
+
import { join, relative } from "node:path";
|
|
7
|
+
import { loadDocumentModel, modelGeneration } from "@powerhousedao/codegen";
|
|
9
8
|
import { handleMutuallyExclusiveOptions } from "@powerhousedao/shared/clis";
|
|
10
|
-
import { buildTsMorphProject } from "@powerhousedao/codegen/utils";
|
|
9
|
+
import { buildTsMorphProject, documentModelsDirOf } from "@powerhousedao/codegen/utils";
|
|
11
10
|
import { readPackage } from "read-pkg";
|
|
12
11
|
import { extractDocumentModelDocuments, getDocument, saveSpec } from "@powerhousedao/vetra/codegen";
|
|
13
12
|
import { capitalCase, kebabCase } from "change-case";
|
|
@@ -29,7 +28,6 @@ async function scaffoldCodeFirstDocumentModel(generation, name, projectDir, proj
|
|
|
29
28
|
}
|
|
30
29
|
}, project);
|
|
31
30
|
for (const path of result.written) console.log(`Wrote ${path}`);
|
|
32
|
-
console.log(result.registration === "unchanged" ? "powerhouse.config.json definitionSources already lists this model" : `Registered ${documentType} in powerhouse.config.json definitionSources (${result.registration})`);
|
|
33
31
|
await generation.generateEditor({
|
|
34
32
|
editorName,
|
|
35
33
|
documentTypes: [documentType],
|
|
@@ -49,9 +47,15 @@ async function documentTypeNamespace(projectDir) {
|
|
|
49
47
|
}
|
|
50
48
|
//#endregion
|
|
51
49
|
//#region src/services/generate-document-model.ts
|
|
50
|
+
/** The configured documentModelsDir, package-relative, for messages and paths. */
|
|
51
|
+
function modelsDirOf(projectDir) {
|
|
52
|
+
return relative(projectDir, documentModelsDirOf(projectDir).path).replaceAll("\\", "/");
|
|
53
|
+
}
|
|
52
54
|
async function startGenerateDocumentModel(args, projectDir) {
|
|
53
|
-
const { document, dir, all, extract, name, debug } = args;
|
|
55
|
+
const { document, dir, all, extract, name, codeFirst, debug } = args;
|
|
54
56
|
if (debug) console.log({ args });
|
|
57
|
+
if (name !== void 0 && !codeFirst) throw new Error("--name creates a code-first document model. Pass --code-first.");
|
|
58
|
+
if (codeFirst && name === void 0) throw new Error("--code-first only chooses how --name creates a model. Existing models of both styles are discovered without it; drop --code-first.");
|
|
55
59
|
const project = buildTsMorphProject(projectDir);
|
|
56
60
|
if (name !== void 0) {
|
|
57
61
|
handleMutuallyExclusiveOptions({
|
|
@@ -61,7 +65,7 @@ async function startGenerateDocumentModel(args, projectDir) {
|
|
|
61
65
|
"--all": all || void 0,
|
|
62
66
|
"--extract": extract || void 0
|
|
63
67
|
}, "generation mode");
|
|
64
|
-
await scaffoldCodeFirstDocumentModel(
|
|
68
|
+
await scaffoldCodeFirstDocumentModel(modelGeneration, name, projectDir, project);
|
|
65
69
|
return;
|
|
66
70
|
}
|
|
67
71
|
if (extract) {
|
|
@@ -73,31 +77,31 @@ async function startGenerateDocumentModel(args, projectDir) {
|
|
|
73
77
|
return;
|
|
74
78
|
}
|
|
75
79
|
if (all) {
|
|
76
|
-
const { documentModels, unreadableDirs, codeFirstDocumentModels } = await
|
|
80
|
+
const { documentModels, unreadableDirs, codeFirstDocumentModels } = await modelGeneration.generateAllDocumentModels(project);
|
|
77
81
|
await project.save();
|
|
78
|
-
if (documentModels.length === 0 && unreadableDirs.length === 0 && codeFirstDocumentModels.length === 0) console.log(
|
|
82
|
+
if (documentModels.length === 0 && unreadableDirs.length === 0 && codeFirstDocumentModels.length === 0) console.log(`No document models found in ${modelsDirOf(projectDir)}/.`);
|
|
79
83
|
for (const { name } of documentModels) console.log(`Regenerated document model "${name}"`);
|
|
80
84
|
for (const { name } of codeFirstDocumentModels) console.log(`Updated the exports of code-first document model "${name}"`);
|
|
81
|
-
for (const dirName of unreadableDirs) console.warn(`Skipped
|
|
85
|
+
for (const dirName of unreadableDirs) console.warn(`Skipped ${modelsDirOf(projectDir)}/${dirName}: it has no readable ${dirName}.json, and no index.ts in it exports a code-first model. Kept the manifest's document models.`);
|
|
82
86
|
await warnSubgraphTypeConflicts(projectDir);
|
|
83
87
|
return;
|
|
84
88
|
} else if (document) {
|
|
85
|
-
const generation = selectDocumentModelGeneration(args, projectDir);
|
|
86
89
|
if (document.endsWith(".phd")) {
|
|
87
90
|
const doc = await getDocument(document);
|
|
88
|
-
await
|
|
91
|
+
await modelGeneration.generateDocumentModel(doc.state.global, project);
|
|
89
92
|
} else {
|
|
90
93
|
const state = await loadDocumentModel(document);
|
|
91
|
-
await
|
|
94
|
+
await modelGeneration.generateDocumentModel(state, project);
|
|
92
95
|
}
|
|
93
96
|
} else if (dir) {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
+
const modelsDir = modelsDirOf(projectDir);
|
|
98
|
+
const dirName = resolveModuleDirName(projectDir, modelsDir, dir, "my-document-model");
|
|
99
|
+
const specPath = join(projectDir, modelsDir, dirName, `${dirName}.json`);
|
|
100
|
+
if (!existsSync(specPath)) throw new Error(`${modelsDir}/${dirName} has no ${dirName}.json.`);
|
|
97
101
|
const state = await loadDocumentModel(specPath);
|
|
98
|
-
await
|
|
102
|
+
await modelGeneration.generateDocumentModel(state, project);
|
|
99
103
|
await project.save();
|
|
100
|
-
console.log(`Regenerated document model "${state.name}" in
|
|
104
|
+
console.log(`Regenerated document model "${state.name}" in ${modelsDir}/${dirName}`);
|
|
101
105
|
await warnSubgraphTypeConflicts(projectDir);
|
|
102
106
|
return;
|
|
103
107
|
} else {
|
|
@@ -110,5 +114,5 @@ async function startGenerateDocumentModel(args, projectDir) {
|
|
|
110
114
|
//#endregion
|
|
111
115
|
export { startGenerateDocumentModel };
|
|
112
116
|
|
|
113
|
-
//# sourceMappingURL=generate-document-model-
|
|
114
|
-
//# debugId=
|
|
117
|
+
//# sourceMappingURL=generate-document-model-OQPfeHs-.mjs.map
|
|
118
|
+
//# debugId=9abb9264-65d9-577b-a83a-145383e907f3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-document-model-OQPfeHs-.mjs","sources":["../src/services/definitions/code-first-scaffold.ts","../src/services/generate-document-model.ts"],"sourcesContent":["import type { ModelGeneration } from \"@powerhousedao/codegen\";\nimport { capitalCase, kebabCase } from \"change-case\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { readPackage } from \"read-pkg\";\nimport type { Project } from \"ts-morph\";\n\nexport async function scaffoldCodeFirstDocumentModel(\n generation: ModelGeneration,\n name: string,\n projectDir: string,\n project: Project,\n) {\n const modelName = name.trim();\n if (modelName === \"\") {\n throw new Error(\"--name needs a document model name.\");\n }\n const namespace = await documentTypeNamespace(projectDir);\n const documentType = `${namespace}/${kebabCase(modelName)}`;\n const editorName = `${capitalCase(modelName)} Editor`;\n const editorDirName = kebabCase(editorName);\n if (existsSync(join(projectDir, \"editors\", editorDirName))) {\n throw new Error(\n `editors/${editorDirName} already exists. Choose another --name, or move that editor first.`,\n );\n }\n\n const result = await generation.scaffoldDocumentModel(\n {\n name: modelName,\n documentType,\n author: { name: namespace, website: null },\n },\n project,\n );\n for (const path of result.written) {\n console.log(`Wrote ${path}`);\n }\n\n await generation.generateEditor(\n {\n editorName,\n documentTypes: [documentType],\n editorId: editorDirName,\n editorDirName,\n },\n project,\n );\n await project.save();\n console.log(`Generated editor \"${editorName}\" in editors/${editorDirName}`);\n}\n\nasync function documentTypeNamespace(projectDir: string) {\n const { name } = await readPackage({ cwd: projectDir, normalize: false });\n if (!name) {\n throw new Error(\n \"--name puts the document type under the package name. Add a name to package.json.\",\n );\n }\n return name.replace(/^@/, \"\").replaceAll(\"/\", \"-\");\n}\n","import { loadDocumentModel, modelGeneration } from \"@powerhousedao/codegen\";\nimport {\n buildTsMorphProject,\n documentModelsDirOf,\n} from \"@powerhousedao/codegen/utils\";\nimport {\n extractDocumentModelDocuments,\n getDocument,\n saveSpec,\n} from \"@powerhousedao/vetra/codegen\";\nimport { handleMutuallyExclusiveOptions } from \"@powerhousedao/shared/clis\";\nimport type { DocumentModelDocument } from \"@powerhousedao/shared/document-model\";\nimport { existsSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport type { GenerateDocumentModelArgs } from \"../types.js\";\nimport { resolveModuleDirName } from \"../utils/module-dir.js\";\nimport { warnSubgraphTypeConflicts } from \"../utils/warn-subgraph-type-conflicts.js\";\nimport { scaffoldCodeFirstDocumentModel } from \"./definitions/code-first-scaffold.js\";\n\n/** The configured documentModelsDir, package-relative, for messages and paths. */\nfunction modelsDirOf(projectDir: string) {\n return relative(projectDir, documentModelsDirOf(projectDir).path).replaceAll(\n \"\\\\\",\n \"/\",\n );\n}\n\nexport async function startGenerateDocumentModel(\n args: GenerateDocumentModelArgs,\n projectDir: string,\n) {\n const { document, dir, all, extract, name, codeFirst, debug } = args;\n if (debug) {\n console.log({ args });\n }\n if (name !== undefined && !codeFirst) {\n throw new Error(\n \"--name creates a code-first document model. Pass --code-first.\",\n );\n }\n if (codeFirst && name === undefined) {\n throw new Error(\n \"--code-first only chooses how --name creates a model. Existing models of both styles are discovered without it; drop --code-first.\",\n );\n }\n const project = buildTsMorphProject(projectDir);\n if (name !== undefined) {\n handleMutuallyExclusiveOptions(\n {\n \"--name\": name,\n \"--document\": document,\n \"--dir\": dir,\n \"--all\": all || undefined,\n \"--extract\": extract || undefined,\n },\n \"generation mode\",\n );\n await scaffoldCodeFirstDocumentModel(\n modelGeneration,\n name,\n projectDir,\n project,\n );\n return;\n }\n if (extract) {\n const docs = extractDocumentModelDocuments(project);\n for (const doc of docs) {\n const path = await saveSpec(doc, projectDir);\n console.log(`Wrote ${path}`);\n }\n return;\n }\n if (all) {\n const { documentModels, unreadableDirs, codeFirstDocumentModels } =\n await modelGeneration.generateAllDocumentModels(project);\n await project.save();\n if (\n documentModels.length === 0 &&\n unreadableDirs.length === 0 &&\n codeFirstDocumentModels.length === 0\n ) {\n console.log(`No document models found in ${modelsDirOf(projectDir)}/.`);\n }\n for (const { name } of documentModels) {\n console.log(`Regenerated document model \"${name}\"`);\n }\n for (const { name } of codeFirstDocumentModels) {\n console.log(`Updated the exports of code-first document model \"${name}\"`);\n }\n for (const dirName of unreadableDirs) {\n console.warn(\n `Skipped ${modelsDirOf(projectDir)}/${dirName}: it has no readable ${dirName}.json, and no index.ts in it exports a code-first model. Kept the manifest's document models.`,\n );\n }\n await warnSubgraphTypeConflicts(projectDir);\n return;\n } else if (document) {\n if (document.endsWith(\".phd\")) {\n const doc = (await getDocument(document)) as DocumentModelDocument;\n await modelGeneration.generateDocumentModel(doc.state.global, project);\n } else {\n const state = await loadDocumentModel(document);\n await modelGeneration.generateDocumentModel(state, project);\n }\n } else if (dir) {\n const modelsDir = modelsDirOf(projectDir);\n const dirName = resolveModuleDirName(\n projectDir,\n modelsDir,\n dir,\n \"my-document-model\",\n );\n const specPath = join(projectDir, modelsDir, dirName, `${dirName}.json`);\n if (!existsSync(specPath)) {\n throw new Error(`${modelsDir}/${dirName} has no ${dirName}.json.`);\n }\n const state = await loadDocumentModel(specPath);\n await modelGeneration.generateDocumentModel(state, project);\n await project.save();\n console.log(\n `Regenerated document model \"${state.name}\" in ${modelsDir}/${dirName}`,\n );\n await warnSubgraphTypeConflicts(projectDir);\n return;\n } else {\n console.log(\n \"Please specify one of `document`, `dir`, `all`, or `extract`.\",\n );\n return;\n }\n await project.save();\n await warnSubgraphTypeConflicts(projectDir);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAOA,eAAsB,+BACpB,YACA,MACA,YACA,SACA;CACA,MAAM,YAAY,KAAK,KAAK;CAC5B,IAAI,cAAc,IAChB,MAAM,IAAI,MAAM,qCAAqC;CAEvD,MAAM,YAAY,MAAM,sBAAsB,UAAU;CACxD,MAAM,eAAe,GAAG,UAAU,GAAG,UAAU,SAAS;CACxD,MAAM,aAAa,GAAG,YAAY,SAAS,EAAE;CAC7C,MAAM,gBAAgB,UAAU,UAAU;CAC1C,IAAI,WAAW,KAAK,YAAY,WAAW,aAAa,CAAC,GACvD,MAAM,IAAI,MACR,WAAW,cAAc,mEAC3B;CAGF,MAAM,SAAS,MAAM,WAAW,sBAC9B;EACE,MAAM;EACN;EACA,QAAQ;GAAE,MAAM;GAAW,SAAS;EAAK;CAC3C,GACA,OACF;CACA,KAAK,MAAM,QAAQ,OAAO,SACxB,QAAQ,IAAI,SAAS,MAAM;CAG7B,MAAM,WAAW,eACf;EACE;EACA,eAAe,CAAC,YAAY;EAC5B,UAAU;EACV;CACF,GACA,OACF;CACA,MAAM,QAAQ,KAAK;CACnB,QAAQ,IAAI,qBAAqB,WAAW,eAAe,eAAe;AAC5E;AAEA,eAAe,sBAAsB,YAAoB;CACvD,MAAM,EAAE,SAAS,MAAM,YAAY;EAAE,KAAK;EAAY,WAAW;CAAM,CAAC;CACxE,IAAI,CAAC,MACH,MAAM,IAAI,MACR,mFACF;CAEF,OAAO,KAAK,QAAQ,MAAM,EAAE,CAAC,CAAC,WAAW,KAAK,GAAG;AACnD;;;;ACxCA,SAAS,YAAY,YAAoB;CACvC,OAAO,SAAS,YA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