@powerhousedao/shared 6.2.3-dev.13 → 6.2.3-dev.15
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/clis/args/{access-token-zW_7Brog.mjs → access-token-Bf1K1Fpc.mjs} +2 -2
- package/dist/clis/args/{access-token-zW_7Brog.mjs.map → access-token-Bf1K1Fpc.mjs.map} +1 -1
- package/dist/clis/args/access-token.mjs +1 -1
- package/dist/clis/args/{common-BT8ABM57.mjs → common-BpnFLR-_.mjs} +13 -5
- package/dist/clis/args/common-BpnFLR-_.mjs.map +1 -0
- package/dist/clis/args/{common-rEpM4Oqq.d.mts → common-yKU4B741.d.mts} +3 -3
- package/dist/clis/args/{common-rEpM4Oqq.d.mts.map → common-yKU4B741.d.mts.map} +1 -1
- package/dist/clis/args/common.d.mts +1 -1
- package/dist/clis/args/common.mjs +1 -1
- package/dist/clis/args/{connect-_FQWS7p3.d.mts → connect-BD-C5BkE.d.mts} +6 -6
- package/dist/clis/args/{connect-_FQWS7p3.d.mts.map → connect-BD-C5BkE.d.mts.map} +1 -1
- package/dist/clis/args/{connect-Du3Us5tQ.mjs → connect-ByiLv365.mjs} +2 -2
- package/dist/clis/args/{connect-Du3Us5tQ.mjs.map → connect-ByiLv365.mjs.map} +1 -1
- package/dist/clis/args/connect.d.mts +1 -1
- package/dist/clis/args/connect.mjs +1 -1
- package/dist/clis/args/{generate-DkFqeNX3.mjs → generate-0aR1N6J5.mjs} +2 -2
- package/dist/clis/args/{generate-DkFqeNX3.mjs.map → generate-0aR1N6J5.mjs.map} +1 -1
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-stFOz1hp.mjs → help-CEw7OZ9E.mjs} +15 -15
- package/dist/clis/args/{help-stFOz1hp.mjs.map → help-CEw7OZ9E.mjs.map} +1 -1
- package/dist/clis/args/help.mjs +1 -1
- package/dist/clis/args/index.d.mts +4 -4
- package/dist/clis/args/index.mjs +18 -18
- package/dist/clis/args/{init-Bu8-Ovk8.mjs → init-DBYYsV0Y.mjs} +2 -2
- package/dist/clis/args/{init-Bu8-Ovk8.mjs.map → init-DBYYsV0Y.mjs.map} +1 -1
- package/dist/clis/args/init.mjs +1 -1
- package/dist/clis/args/{inspect-GjiR0Qqd.mjs → inspect-BzBsZ0UO.mjs} +2 -2
- package/dist/clis/args/{inspect-GjiR0Qqd.mjs.map → inspect-BzBsZ0UO.mjs.map} +1 -1
- package/dist/clis/args/inspect.mjs +1 -1
- package/dist/clis/args/{install-B2hLryPk.mjs → install-D0jaysiP.mjs} +2 -2
- package/dist/clis/args/{install-B2hLryPk.mjs.map → install-D0jaysiP.mjs.map} +1 -1
- package/dist/clis/args/install.mjs +1 -1
- package/dist/clis/args/{list-O6VmV3Cw.mjs → list-BaO47Btz.mjs} +2 -2
- package/dist/clis/args/{list-O6VmV3Cw.mjs.map → list-BaO47Btz.mjs.map} +1 -1
- package/dist/clis/args/list.mjs +1 -1
- package/dist/clis/args/{login-BWXdMfMX.mjs → login-DM-qhiYI.mjs} +2 -2
- package/dist/clis/args/{login-BWXdMfMX.mjs.map → login-DM-qhiYI.mjs.map} +1 -1
- package/dist/clis/args/login.mjs +1 -1
- package/dist/clis/args/{migrate-3MTmDiXt.mjs → migrate-EitaI7jq.mjs} +2 -2
- package/dist/clis/args/{migrate-3MTmDiXt.mjs.map → migrate-EitaI7jq.mjs.map} +1 -1
- package/dist/clis/args/migrate.mjs +1 -1
- package/dist/clis/args/{publish--zdKYIOl.mjs → publish-DfMF3Nmc.mjs} +2 -2
- package/dist/clis/args/{publish--zdKYIOl.mjs.map → publish-DfMF3Nmc.mjs.map} +1 -1
- package/dist/clis/args/publish.mjs +1 -1
- package/dist/clis/args/{registry-BNVeE6qR.mjs → registry-Di1tZqbn.mjs} +2 -2
- package/dist/clis/args/{registry-BNVeE6qR.mjs.map → registry-Di1tZqbn.mjs.map} +1 -1
- package/dist/clis/args/registry.mjs +1 -1
- package/dist/clis/args/{service-Cou6l7l8.d.mts → service-DhIkf8-O.d.mts} +2 -2
- package/dist/clis/args/{service-Cou6l7l8.d.mts.map → service-DhIkf8-O.d.mts.map} +1 -1
- package/dist/clis/args/{service-x6wsNujS.mjs → service-jRX2qPul.mjs} +2 -2
- package/dist/clis/args/{service-x6wsNujS.mjs.map → service-jRX2qPul.mjs.map} +1 -1
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/args/service.mjs +1 -1
- package/dist/clis/args/{switchboard-Cryy_3Qc.mjs → switchboard-BhR-ZwGV.mjs} +2 -2
- package/dist/clis/args/{switchboard-Cryy_3Qc.mjs.map → switchboard-BhR-ZwGV.mjs.map} +1 -1
- package/dist/clis/args/switchboard.mjs +1 -1
- package/dist/clis/args/{uninstall-DQUsLzCG.mjs → uninstall-diefi70g.mjs} +2 -2
- package/dist/clis/args/{uninstall-DQUsLzCG.mjs.map → uninstall-diefi70g.mjs.map} +1 -1
- package/dist/clis/args/uninstall.mjs +1 -1
- package/dist/clis/args/{unpublish-CeDsvgMv.mjs → unpublish-C6eNRzsU.mjs} +2 -2
- package/dist/clis/args/{unpublish-CeDsvgMv.mjs.map → unpublish-C6eNRzsU.mjs.map} +1 -1
- package/dist/clis/args/unpublish.mjs +1 -1
- package/dist/clis/args/{vetra-DLQ6lhLl.d.mts → vetra-CoMvTJK7.d.mts} +2 -2
- package/dist/clis/args/{vetra-DLQ6lhLl.d.mts.map → vetra-CoMvTJK7.d.mts.map} +1 -1
- package/dist/clis/args/{vetra-pYJXVf_o.mjs → vetra-DV0zQzba.mjs} +2 -2
- package/dist/clis/args/{vetra-pYJXVf_o.mjs.map → vetra-DV0zQzba.mjs.map} +1 -1
- package/dist/clis/args/vetra-ports.test.mjs +4 -4
- package/dist/clis/args/vetra-ports.test.mjs.map +1 -1
- package/dist/clis/args/vetra.d.mts +1 -1
- package/dist/clis/args/vetra.mjs +1 -1
- package/dist/clis/build-config-BkfXtfV8.mjs +230 -0
- package/dist/clis/build-config-BkfXtfV8.mjs.map +1 -0
- package/dist/clis/build-config.d.mts +16 -10617
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/build-config.mjs +2 -208
- package/dist/clis/build-pieces.d.mts +95 -0
- package/dist/clis/build-pieces.d.mts.map +1 -0
- package/dist/clis/build-pieces.mjs +363 -0
- package/dist/clis/build-pieces.mjs.map +1 -0
- package/dist/clis/constants.d.mts +2 -479
- package/dist/clis/constants.mjs +14 -5
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/index-CyAv0ucZ.d.mts +10619 -0
- package/dist/clis/index-CyAv0ucZ.d.mts.map +1 -0
- package/dist/clis/index.d.mts +13 -2
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +14 -5
- package/dist/clis/index.mjs.map +1 -1
- package/dist/clis/types-D17YQuYG.d.mts +490 -0
- package/dist/clis/types-D17YQuYG.d.mts.map +1 -0
- package/dist/connect/config-loader.d.ts +1 -1
- package/dist/connect/index.d.ts +1 -1
- package/dist/document-drive/index.d.ts +2 -2
- package/dist/document-model/index.d.ts +3 -3
- package/dist/document-model/index.js +9 -2
- package/dist/document-model/index.js.map +1 -1
- package/dist/{index-DWS2M59v.d.ts → index-B6CAmhxM.d.ts} +2 -2
- package/dist/{index-DWS2M59v.d.ts.map → index-B6CAmhxM.d.ts.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/processors/index.d.ts +1 -1
- package/dist/registry/index.d.ts +2 -2
- package/dist/registry/index.js +12 -4
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest-slim.d.ts +1 -1
- package/dist/registry/manifest-slim.d.ts.map +1 -1
- package/dist/registry/manifest-slim.js +22 -2
- package/dist/registry/manifest-slim.js.map +1 -1
- package/dist/{types-KwFsKkFJ.d.ts → types-BRWMm6VM.d.ts} +2 -2
- package/dist/{types-KwFsKkFJ.d.ts.map → types-BRWMm6VM.d.ts.map} +1 -1
- package/dist/{types-DX5QXaOU.d.ts → types-CtCDvH7x.d.ts} +25 -2
- package/dist/types-CtCDvH7x.d.ts.map +1 -0
- package/package.json +5 -1
- package/dist/clis/args/common-BT8ABM57.mjs.map +0 -1
- package/dist/clis/build-config.mjs.map +0 -1
- package/dist/clis/constants.d.mts.map +0 -1
- package/dist/types-DX5QXaOU.d.ts.map +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { t as InlineConfig } from "./index-CyAv0ucZ.mjs";
|
|
2
|
+
import { t as Manifest } from "./types-D17YQuYG.mjs";
|
|
3
|
+
import * as node_fs0 from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region clis/build-pieces.d.mts
|
|
6
|
+
type PiecePlan = {
|
|
7
|
+
/** The directory under pieces/, and so under <outDir>/node/pieces. */dir: string; /** Source entry, relative to the project root: pieces/<dir>/index.ts. */
|
|
8
|
+
entry: string; /** Where the piece lands, relative to the project root. */
|
|
9
|
+
outDir: string;
|
|
10
|
+
};
|
|
11
|
+
type PieceBuildTarget = {
|
|
12
|
+
projectRoot: string;
|
|
13
|
+
outDir: string;
|
|
14
|
+
pieces: PiecePlan[];
|
|
15
|
+
};
|
|
16
|
+
type PackagePiece = {
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
entry?: string;
|
|
20
|
+
bundle?: string;
|
|
21
|
+
};
|
|
22
|
+
type PieceMetadata = Record<string, unknown> & {
|
|
23
|
+
displayName?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
actions?: Record<string, unknown>;
|
|
26
|
+
triggers?: Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
type DescribedPiece = {
|
|
29
|
+
name: string;
|
|
30
|
+
version: string;
|
|
31
|
+
metadata: PieceMetadata;
|
|
32
|
+
};
|
|
33
|
+
type DescribeResult = {
|
|
34
|
+
list: PackagePiece[];
|
|
35
|
+
pieces: DescribedPiece[];
|
|
36
|
+
errors: {
|
|
37
|
+
name: string;
|
|
38
|
+
message: string;
|
|
39
|
+
}[];
|
|
40
|
+
};
|
|
41
|
+
type BuiltPiece = {
|
|
42
|
+
name: string;
|
|
43
|
+
version: string;
|
|
44
|
+
displayName?: string;
|
|
45
|
+
description?: string; /** Piece directory, relative to the project root, `/` separated. */
|
|
46
|
+
bundle: string; /** The descriptor inside it, relative to the project root, `/` separated. */
|
|
47
|
+
descriptor: string;
|
|
48
|
+
};
|
|
49
|
+
type PackageIdentity = {
|
|
50
|
+
name: string;
|
|
51
|
+
version: string;
|
|
52
|
+
license?: string;
|
|
53
|
+
};
|
|
54
|
+
type PieceBuildOptions = {
|
|
55
|
+
/** The bundler: tsdown's `build`, handed in so this module never loads it. */bundle: (config: InlineConfig) => Promise<unknown>;
|
|
56
|
+
};
|
|
57
|
+
declare function statSafe(p: string): node_fs0.Stats | null;
|
|
58
|
+
declare function expandEntryGlobs(root: string, globs: string[]): string[];
|
|
59
|
+
declare function planPieces(projectRoot: string, outDir: string): PiecePlan[];
|
|
60
|
+
declare function createJsonReplacer(): (this: unknown, _key: string, value: unknown) => {} | null | undefined;
|
|
61
|
+
declare const DESCRIBE_HELPERS = "\nconst isRecord = (value) => typeof value === \"object\" && value !== null;\n\nfunction findPiece(mod) {\n const candidates = [\n ...Object.values(mod),\n ...(isRecord(mod.default) ? Object.values(mod.default) : []),\n mod.default,\n ];\n for (const candidate of candidates) {\n if (isRecord(candidate) && candidate.constructor?.name === \"Piece\") {\n return candidate;\n }\n }\n for (const candidate of candidates) {\n if (\n isRecord(candidate) &&\n typeof candidate.displayName === \"string\" &&\n (isRecord(candidate.actions) ||\n typeof candidate.actions === \"function\" ||\n typeof candidate.getAction === \"function\")\n ) {\n return candidate;\n }\n }\n return undefined;\n}\n\nfunction describePiece(piece) {\n if (typeof piece.metadata === \"function\") return piece.metadata();\n const call = (value) => (typeof value === \"function\" ? value.call(piece) : value);\n return {\n displayName: piece.displayName,\n logoUrl: piece.logoUrl,\n description: piece.description,\n authors: piece.authors,\n categories: piece.categories,\n auth: piece.auth,\n minimumSupportedRelease: piece.minimumSupportedRelease,\n maximumSupportedRelease: piece.maximumSupportedRelease,\n deprecated: piece.deprecated,\n actions: call(piece.actions) ?? {},\n triggers: call(piece.triggers) ?? {},\n };\n}\n\nfunction createJsonReplacer() {\n const ancestors = [];\n return function replace(_key, value) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n";
|
|
62
|
+
declare const DESCRIBE_SCRIPT = "\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nconst job = JSON.parse(readFileSync(process.argv[2], \"utf8\"));\n\nconst isRecord = (value) => typeof value === \"object\" && value !== null;\n\nfunction findPiece(mod) {\n const candidates = [\n ...Object.values(mod),\n ...(isRecord(mod.default) ? Object.values(mod.default) : []),\n mod.default,\n ];\n for (const candidate of candidates) {\n if (isRecord(candidate) && candidate.constructor?.name === \"Piece\") {\n return candidate;\n }\n }\n for (const candidate of candidates) {\n if (\n isRecord(candidate) &&\n typeof candidate.displayName === \"string\" &&\n (isRecord(candidate.actions) ||\n typeof candidate.actions === \"function\" ||\n typeof candidate.getAction === \"function\")\n ) {\n return candidate;\n }\n }\n return undefined;\n}\n\nfunction describePiece(piece) {\n if (typeof piece.metadata === \"function\") return piece.metadata();\n const call = (value) => (typeof value === \"function\" ? value.call(piece) : value);\n return {\n displayName: piece.displayName,\n logoUrl: piece.logoUrl,\n description: piece.description,\n authors: piece.authors,\n categories: piece.categories,\n auth: piece.auth,\n minimumSupportedRelease: piece.minimumSupportedRelease,\n maximumSupportedRelease: piece.maximumSupportedRelease,\n deprecated: piece.deprecated,\n actions: call(piece.actions) ?? {},\n triggers: call(piece.triggers) ?? {},\n };\n}\n\nfunction createJsonReplacer() {\n const ancestors = [];\n return function replace(_key, value) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n\n// Says why the child gave up in the one place the parent always reads, so a\n// failure reports the cause and never the text of this script.\nfunction fail(message) {\n writeFileSync(job.outFile, JSON.stringify({ fatal: message }));\n process.exit(1);\n}\n\n// The module to load for a list entry; a bundle names its own main.\nfunction entryFile(piece) {\n const declared = piece.entry ?? piece.bundle;\n if (typeof declared !== \"string\") return undefined;\n const path = isAbsolute(declared) ? declared : join(job.projectRoot, declared);\n if (piece.entry) return path;\n const pkgFile = join(path, \"package.json\");\n if (!existsSync(pkgFile)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgFile, \"utf8\"));\n return join(path, typeof pkg.main === \"string\" ? pkg.main : \"index.mjs\");\n}\n\nlet listModule;\ntry {\n listModule = await import(pathToFileURL(job.listPath).href);\n} catch (error) {\n fail(job.listPath + \" threw on import: \" + (error instanceof Error ? error.message : String(error)));\n}\nconst list = listModule.pieces ?? listModule.default;\nif (!Array.isArray(list)) {\n fail(job.listPath + ' exports no \"pieces\" array');\n}\n\nconst out = { list, pieces: [], errors: [] };\nfor (const piece of list) {\n const file = entryFile(piece);\n // A missing file is the parent's to report, with the message it owns.\n if (!file || !existsSync(file)) continue;\n try {\n const mod = await import(pathToFileURL(file).href);\n const found = findPiece(mod);\n if (!found) {\n throw new Error(\n \"no Piece export found in \" + file + \"; exports: \" + Object.keys(mod).join(\", \"),\n );\n }\n const metadata = JSON.parse(JSON.stringify(describePiece(found), createJsonReplacer()));\n out.pieces.push({ name: piece.name, version: piece.version, metadata });\n } catch (error) {\n out.errors.push({\n name: piece.name,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n}\nwriteFileSync(job.outFile, JSON.stringify(out, createJsonReplacer()));\n";
|
|
63
|
+
declare function describePieces(projectRoot: string, listPath: string): DescribeResult;
|
|
64
|
+
type PieceLocation = {
|
|
65
|
+
/** The piece directory, absolute. */dir: string; /** The module file, absolute; unset for a bundle, whose package.json names it. */
|
|
66
|
+
entryFile?: string;
|
|
67
|
+
form: "entry" | "bundle";
|
|
68
|
+
};
|
|
69
|
+
declare function resolvePieceLocation(piece: PackagePiece, projectRoot: string, outDir: string): PieceLocation;
|
|
70
|
+
declare function pieceListPath(target: {
|
|
71
|
+
projectRoot: string;
|
|
72
|
+
outDir: string;
|
|
73
|
+
}): string;
|
|
74
|
+
declare function assertPiecesOutDir(target: {
|
|
75
|
+
outDir: string;
|
|
76
|
+
pieces: PiecePlan[];
|
|
77
|
+
}): void;
|
|
78
|
+
declare function assertPieceVersion(piece: PackagePiece, pkg: PackageIdentity): void;
|
|
79
|
+
declare function piecePackageJson(options: {
|
|
80
|
+
name: string;
|
|
81
|
+
version: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
main: string;
|
|
84
|
+
license?: string;
|
|
85
|
+
}): Record<string, unknown>;
|
|
86
|
+
declare function pieceDescriptor(piece: PackagePiece, metadata: PieceMetadata): Record<string, unknown>;
|
|
87
|
+
declare function enrichManifestPieces(manifest: Manifest, built: BuiltPiece[]): {
|
|
88
|
+
manifest: Manifest;
|
|
89
|
+
unbuilt: string[];
|
|
90
|
+
};
|
|
91
|
+
declare function buildPieces(target: PieceBuildTarget, pkg: PackageIdentity, options: PieceBuildOptions): Promise<BuiltPiece[]>;
|
|
92
|
+
declare function syncDistManifest(target: PieceBuildTarget, built: BuiltPiece[]): string | undefined;
|
|
93
|
+
//#endregion
|
|
94
|
+
export { BuiltPiece, DESCRIBE_HELPERS, DESCRIBE_SCRIPT, DescribeResult, DescribedPiece, PackageIdentity, PackagePiece, PieceBuildOptions, PieceBuildTarget, PieceLocation, PieceMetadata, PiecePlan, assertPieceVersion, assertPiecesOutDir, buildPieces, createJsonReplacer, describePieces, enrichManifestPieces, expandEntryGlobs, pieceDescriptor, pieceListPath, piecePackageJson, planPieces, resolvePieceLocation, statSafe, syncDistManifest };
|
|
95
|
+
//# sourceMappingURL=build-pieces.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-pieces.d.mts","names":[],"sources":["../../clis/build-pieces.mts"],"mappings":";;;;;KA4BY,SAAA;wEAEV,GAAA,UAFU;EAIV,KAAA;EAEA,MAAA;AAAA;AAAA,KAKU,gBAAA;EACV,WAAA;EACA,MAAA;EACA,MAAA,EAAQ,SAAA;AAAA;AAAA,KAKE,YAAA;EACV,IAAA;EACA,OAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,KAKU,aAAA,GAAgB,MAAA;EAC1B,WAAA;EACA,WAAA;EACA,OAAA,GAAU,MAAA;EACV,QAAA,GAAW,MAAA;AAAA;AAAA,KAGD,cAAA;EACV,IAAA;EACA,OAAA;EACA,QAAA,EAAU,aAAA;AAAA;AAAA,KAGA,cAAA;EACV,IAAA,EAAM,YAAA;EACN,MAAA,EAAQ,cAAA;EACR,MAAA;IAAU,IAAA;IAAc,OAAA;EAAA;AAAA;AAAA,KAGd,UAAA;EACV,IAAA;EACA,OAAA;EACA,WAAA;EACA,WAAA,WApBA;EAsBA,MAAA,UArBA;EAuBA,UAAA;AAAA;AAAA,KAGU,eAAA;EACV,IAAA;EACA,OAAA;EACA,OAAA;AAAA;AAAA,KAGU,iBAAA;EA3BV,8EA6BA,MAAA,GAAS,MAAA,EAAQ,YAAA,KAAiB,OAAA;AAAA;AAAA,iBAKpB,QAAA,CAAS,CAAA,WAAD,QAAA,CAAU,KAAA;AAAA,iBAUlB,gBAAA,CAAiB,IAAA,UAAc,KAAA;AAAA,iBA4B/B,UAAA,CAAW,WAAA,UAAqB,MAAA,WAAiB,SAAA;AAAA,iBAejD,kBAAA,CAAA,IAEU,IAAA,WAAe,IAAA,UAAc,KAAA;AAAA,cAiB1C,gBAAA;AAAA,cAiEA,eAAA;AAAA,iBAsFG,cAAA,CACd,WAAA,UACA,QAAA,WACC,cAAA;AAAA,KA0BS,aAAA;EAxRV,qCA0RA,GAAA,UAzRA;EA2RA,SAAA;EACA,IAAA;AAAA;AAAA,iBAKc,oBAAA,CACd,KAAA,EAAO,YAAA,EACP,WAAA,UACA,MAAA,WACC,aAAA;AAAA,iBAmCa,aAAA,CAAc,MAAA;EAC5B,WAAA;EACA,MAAA;AAAA;AAAA,iBAac,kBAAA,CAAmB,MAAA;EACjC,MAAA;EACA,MAAA,EAAQ,SAAA;AAAA;AAAA,iBAWM,kBAAA,CACd,KAAA,EAAO,YAAA,EACP,GAAA,EAAK,eAAA;AAAA,iBAWS,gBAAA,CAAiB,OAAA;EAC/B,IAAA;EACA,OAAA;EACA,WAAA;EACA,IAAA;EACA,OAAA;AAAA,IACE,MAAA;AAAA,iBAgBY,eAAA,CACd,KAAA,EAAO,YAAA,EACP,QAAA,EAAU,aAAA,GACT,MAAA;AAAA,iBAUa,oBAAA,CACd,QAAA,EAAU,QAAA,EACV,KAAA,EAAO,UAAA;EACJ,QAAA,EAAU,QAAA;EAAU,OAAA;AAAA;AAAA,iBAkCH,WAAA,CACpB,MAAA,EAAQ,gBAAA,EACR,GAAA,EAAK,eAAA,EACL,OAAA,EAAS,iBAAA,GACR,OAAA,CAAQ,UAAA;AAAA,iBA4GK,gBAAA,CACd,MAAA,EAAQ,gBAAA,EACR,KAAA,EAAO,UAAA"}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { o as buildPieceBuildConfig, t as PIECE_ENTRY_GLOB } from "./build-config-BkfXtfV8.mjs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
//#region clis/build-pieces.mts
|
|
7
|
+
const toPosix = (p) => p.split(sep).join("/");
|
|
8
|
+
function statSafe(p) {
|
|
9
|
+
try {
|
|
10
|
+
return statSync(p);
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function expandEntryGlobs(root, globs) {
|
|
16
|
+
const files = /* @__PURE__ */ new Set();
|
|
17
|
+
for (const pattern of globs) {
|
|
18
|
+
const segments = pattern.split("/").filter(Boolean);
|
|
19
|
+
let dirs = [root];
|
|
20
|
+
for (const seg of segments) {
|
|
21
|
+
const next = [];
|
|
22
|
+
for (const d of dirs) {
|
|
23
|
+
if (!statSafe(d)?.isDirectory()) continue;
|
|
24
|
+
if (seg === "*") for (const e of readdirSync(d, { withFileTypes: true })) next.push(join(d, e.name));
|
|
25
|
+
else next.push(join(d, seg));
|
|
26
|
+
}
|
|
27
|
+
dirs = next;
|
|
28
|
+
}
|
|
29
|
+
for (const f of dirs) if (statSafe(f)?.isFile()) files.add(f);
|
|
30
|
+
}
|
|
31
|
+
return [...files];
|
|
32
|
+
}
|
|
33
|
+
function planPieces(projectRoot, outDir) {
|
|
34
|
+
return expandEntryGlobs(projectRoot, [PIECE_ENTRY_GLOB]).map((file) => {
|
|
35
|
+
const dir = basename(dirname(file));
|
|
36
|
+
return {
|
|
37
|
+
dir,
|
|
38
|
+
entry: relative(projectRoot, file),
|
|
39
|
+
outDir: join(outDir, "node", "pieces", dir)
|
|
40
|
+
};
|
|
41
|
+
}).sort((a, b) => a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0);
|
|
42
|
+
}
|
|
43
|
+
function createJsonReplacer() {
|
|
44
|
+
const ancestors = [];
|
|
45
|
+
return function replace(_key, value) {
|
|
46
|
+
if (typeof value === "function" || value === void 0) return void 0;
|
|
47
|
+
if (typeof value === "bigint") return value.toString();
|
|
48
|
+
if (typeof value !== "object" || value === null) return value;
|
|
49
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();
|
|
50
|
+
if (ancestors.includes(value)) return void 0;
|
|
51
|
+
ancestors.push(value);
|
|
52
|
+
return value;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const DESCRIBE_HELPERS = `
|
|
56
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
57
|
+
|
|
58
|
+
function findPiece(mod) {
|
|
59
|
+
const candidates = [
|
|
60
|
+
...Object.values(mod),
|
|
61
|
+
...(isRecord(mod.default) ? Object.values(mod.default) : []),
|
|
62
|
+
mod.default,
|
|
63
|
+
];
|
|
64
|
+
for (const candidate of candidates) {
|
|
65
|
+
if (isRecord(candidate) && candidate.constructor?.name === "Piece") {
|
|
66
|
+
return candidate;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const candidate of candidates) {
|
|
70
|
+
if (
|
|
71
|
+
isRecord(candidate) &&
|
|
72
|
+
typeof candidate.displayName === "string" &&
|
|
73
|
+
(isRecord(candidate.actions) ||
|
|
74
|
+
typeof candidate.actions === "function" ||
|
|
75
|
+
typeof candidate.getAction === "function")
|
|
76
|
+
) {
|
|
77
|
+
return candidate;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function describePiece(piece) {
|
|
84
|
+
if (typeof piece.metadata === "function") return piece.metadata();
|
|
85
|
+
const call = (value) => (typeof value === "function" ? value.call(piece) : value);
|
|
86
|
+
return {
|
|
87
|
+
displayName: piece.displayName,
|
|
88
|
+
logoUrl: piece.logoUrl,
|
|
89
|
+
description: piece.description,
|
|
90
|
+
authors: piece.authors,
|
|
91
|
+
categories: piece.categories,
|
|
92
|
+
auth: piece.auth,
|
|
93
|
+
minimumSupportedRelease: piece.minimumSupportedRelease,
|
|
94
|
+
maximumSupportedRelease: piece.maximumSupportedRelease,
|
|
95
|
+
deprecated: piece.deprecated,
|
|
96
|
+
actions: call(piece.actions) ?? {},
|
|
97
|
+
triggers: call(piece.triggers) ?? {},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function createJsonReplacer() {
|
|
102
|
+
const ancestors = [];
|
|
103
|
+
return function replace(_key, value) {
|
|
104
|
+
if (typeof value === "function" || value === undefined) return undefined;
|
|
105
|
+
if (typeof value === "bigint") return value.toString();
|
|
106
|
+
if (typeof value !== "object" || value === null) return value;
|
|
107
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();
|
|
108
|
+
if (ancestors.includes(value)) return undefined;
|
|
109
|
+
ancestors.push(value);
|
|
110
|
+
return value;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
const DESCRIBE_SCRIPT = `
|
|
115
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
116
|
+
import { isAbsolute, join } from "node:path";
|
|
117
|
+
import { pathToFileURL } from "node:url";
|
|
118
|
+
|
|
119
|
+
const job = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
120
|
+
${DESCRIBE_HELPERS}
|
|
121
|
+
// Says why the child gave up in the one place the parent always reads, so a
|
|
122
|
+
// failure reports the cause and never the text of this script.
|
|
123
|
+
function fail(message) {
|
|
124
|
+
writeFileSync(job.outFile, JSON.stringify({ fatal: message }));
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// The module to load for a list entry; a bundle names its own main.
|
|
129
|
+
function entryFile(piece) {
|
|
130
|
+
const declared = piece.entry ?? piece.bundle;
|
|
131
|
+
if (typeof declared !== "string") return undefined;
|
|
132
|
+
const path = isAbsolute(declared) ? declared : join(job.projectRoot, declared);
|
|
133
|
+
if (piece.entry) return path;
|
|
134
|
+
const pkgFile = join(path, "package.json");
|
|
135
|
+
if (!existsSync(pkgFile)) return undefined;
|
|
136
|
+
const pkg = JSON.parse(readFileSync(pkgFile, "utf8"));
|
|
137
|
+
return join(path, typeof pkg.main === "string" ? pkg.main : "index.mjs");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let listModule;
|
|
141
|
+
try {
|
|
142
|
+
listModule = await import(pathToFileURL(job.listPath).href);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
fail(job.listPath + " threw on import: " + (error instanceof Error ? error.message : String(error)));
|
|
145
|
+
}
|
|
146
|
+
const list = listModule.pieces ?? listModule.default;
|
|
147
|
+
if (!Array.isArray(list)) {
|
|
148
|
+
fail(job.listPath + ' exports no "pieces" array');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const out = { list, pieces: [], errors: [] };
|
|
152
|
+
for (const piece of list) {
|
|
153
|
+
const file = entryFile(piece);
|
|
154
|
+
// A missing file is the parent's to report, with the message it owns.
|
|
155
|
+
if (!file || !existsSync(file)) continue;
|
|
156
|
+
try {
|
|
157
|
+
const mod = await import(pathToFileURL(file).href);
|
|
158
|
+
const found = findPiece(mod);
|
|
159
|
+
if (!found) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
"no Piece export found in " + file + "; exports: " + Object.keys(mod).join(", "),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
const metadata = JSON.parse(JSON.stringify(describePiece(found), createJsonReplacer()));
|
|
165
|
+
out.pieces.push({ name: piece.name, version: piece.version, metadata });
|
|
166
|
+
} catch (error) {
|
|
167
|
+
out.errors.push({
|
|
168
|
+
name: piece.name,
|
|
169
|
+
message: error instanceof Error ? error.message : String(error),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
writeFileSync(job.outFile, JSON.stringify(out, createJsonReplacer()));
|
|
174
|
+
`;
|
|
175
|
+
function childFailure(error, outFile) {
|
|
176
|
+
try {
|
|
177
|
+
const answer = JSON.parse(readFileSync(outFile, "utf8"));
|
|
178
|
+
if (typeof answer.fatal === "string") return answer.fatal;
|
|
179
|
+
} catch {}
|
|
180
|
+
const { status, signal } = error;
|
|
181
|
+
if (signal) return `the describe child was killed by ${signal}`;
|
|
182
|
+
return `the describe child exited with code ${status ?? "unknown"}`;
|
|
183
|
+
}
|
|
184
|
+
function describePieces(projectRoot, listPath) {
|
|
185
|
+
const dir = mkdtempSync(join(tmpdir(), "ph-build-pieces-"));
|
|
186
|
+
const rel = toPosix(relative(projectRoot, listPath));
|
|
187
|
+
try {
|
|
188
|
+
const jobFile = join(dir, "job.json");
|
|
189
|
+
const scriptFile = join(dir, "describe.mjs");
|
|
190
|
+
const outFile = join(dir, "describe.json");
|
|
191
|
+
writeFileSync(scriptFile, DESCRIBE_SCRIPT);
|
|
192
|
+
writeFileSync(jobFile, JSON.stringify({
|
|
193
|
+
projectRoot,
|
|
194
|
+
listPath,
|
|
195
|
+
outFile
|
|
196
|
+
}));
|
|
197
|
+
try {
|
|
198
|
+
execFileSync(process.execPath, [scriptFile, jobFile], {
|
|
199
|
+
timeout: 6e4,
|
|
200
|
+
stdio: "inherit"
|
|
201
|
+
});
|
|
202
|
+
} catch (error) {
|
|
203
|
+
throw new Error(`pieces: could not load ${rel}: ${childFailure(error, outFile)}`, { cause: error });
|
|
204
|
+
}
|
|
205
|
+
return JSON.parse(readFileSync(outFile, "utf8"));
|
|
206
|
+
} finally {
|
|
207
|
+
rmSync(dir, {
|
|
208
|
+
recursive: true,
|
|
209
|
+
force: true
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function resolvePieceLocation(piece, projectRoot, outDir) {
|
|
214
|
+
const declared = piece.entry ?? piece.bundle;
|
|
215
|
+
if (typeof declared !== "string" || declared === "") throw new Error(`pieces: "${piece.name}" declares neither an entry nor a bundle`);
|
|
216
|
+
const path = isAbsolute(declared) ? declared : join(projectRoot, declared);
|
|
217
|
+
const form = piece.entry ? "entry" : "bundle";
|
|
218
|
+
if (!(form === "entry" ? statSafe(path)?.isFile() : statSafe(join(path, "package.json"))?.isFile())) throw new Error(`pieces: "${piece.name}" declares ${declared}, which is missing`);
|
|
219
|
+
const dir = form === "entry" ? dirname(path) : path;
|
|
220
|
+
const inside = relative(resolve(projectRoot, outDir, "node", "pieces"), dir);
|
|
221
|
+
if (inside === "" || inside.startsWith("..") || isAbsolute(inside)) {
|
|
222
|
+
const expected = toPosix(join(outDir, "node", "pieces"));
|
|
223
|
+
throw new Error(`pieces: "${piece.name}" declares ${declared}, which is outside ${expected}/; a piece is built to ${expected}/<dir>/index.mjs and its entry must point there`);
|
|
224
|
+
}
|
|
225
|
+
return form === "entry" ? {
|
|
226
|
+
dir,
|
|
227
|
+
entryFile: path,
|
|
228
|
+
form
|
|
229
|
+
} : {
|
|
230
|
+
dir,
|
|
231
|
+
form
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function pieceListPath(target) {
|
|
235
|
+
return resolve(target.projectRoot, target.outDir, "node", "pieces", "index.mjs");
|
|
236
|
+
}
|
|
237
|
+
function assertPiecesOutDir(target) {
|
|
238
|
+
if (target.pieces.length === 0 || target.outDir === "dist") return;
|
|
239
|
+
throw new Error(`pieces: --out-dir ${target.outDir} cannot hold pieces; a piece is loaded from dist/node/pieces/<name> by the host, so a package that ships pieces builds to dist`);
|
|
240
|
+
}
|
|
241
|
+
function assertPieceVersion(piece, pkg) {
|
|
242
|
+
if (piece.name === pkg.name && piece.version !== pkg.version) throw new Error(`pieces: "${piece.name}" declares version ${piece.version}, package.json says ${pkg.version}`);
|
|
243
|
+
}
|
|
244
|
+
function piecePackageJson(options) {
|
|
245
|
+
return {
|
|
246
|
+
name: options.name,
|
|
247
|
+
version: options.version,
|
|
248
|
+
description: options.description ?? "",
|
|
249
|
+
type: "module",
|
|
250
|
+
main: options.main,
|
|
251
|
+
...options.license ? { license: options.license } : {},
|
|
252
|
+
dependencies: {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function pieceDescriptor(piece, metadata) {
|
|
256
|
+
const { name: _name, version: _version, ...rest } = metadata;
|
|
257
|
+
return {
|
|
258
|
+
name: piece.name,
|
|
259
|
+
version: piece.version,
|
|
260
|
+
...rest
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function enrichManifestPieces(manifest, built) {
|
|
264
|
+
const byId = new Map(built.map((piece) => [piece.name, piece]));
|
|
265
|
+
const toModule = (piece) => ({
|
|
266
|
+
id: piece.name,
|
|
267
|
+
name: piece.displayName ?? piece.name,
|
|
268
|
+
version: piece.version,
|
|
269
|
+
...piece.description ? { description: piece.description } : {},
|
|
270
|
+
bundle: piece.bundle,
|
|
271
|
+
descriptor: piece.descriptor
|
|
272
|
+
});
|
|
273
|
+
const unbuilt = [];
|
|
274
|
+
const seen = /* @__PURE__ */ new Set();
|
|
275
|
+
const pieces = (manifest.pieces ?? []).map((entry) => {
|
|
276
|
+
const hit = byId.get(entry.id);
|
|
277
|
+
if (!hit) {
|
|
278
|
+
unbuilt.push(entry.id);
|
|
279
|
+
return entry;
|
|
280
|
+
}
|
|
281
|
+
seen.add(entry.id);
|
|
282
|
+
return toModule(hit);
|
|
283
|
+
});
|
|
284
|
+
for (const piece of built) if (!seen.has(piece.name)) pieces.push(toModule(piece));
|
|
285
|
+
return {
|
|
286
|
+
manifest: {
|
|
287
|
+
...manifest,
|
|
288
|
+
pieces
|
|
289
|
+
},
|
|
290
|
+
unbuilt
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const count = (record) => typeof record === "object" && record !== null ? Object.keys(record).length : 0;
|
|
294
|
+
async function buildPieces(target, pkg, options) {
|
|
295
|
+
const { projectRoot, outDir } = target;
|
|
296
|
+
assertPiecesOutDir(target);
|
|
297
|
+
for (const piece of target.pieces) {
|
|
298
|
+
console.log(`\n▶ Building piece ${piece.dir}...`);
|
|
299
|
+
await options.bundle(buildPieceBuildConfig({
|
|
300
|
+
entry: resolve(projectRoot, piece.entry),
|
|
301
|
+
outDir: resolve(projectRoot, piece.outDir)
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
const listPath = pieceListPath(target);
|
|
305
|
+
if (!existsSync(listPath)) throw new Error(`pieces: ${toPosix(relative(projectRoot, listPath))} was not built; pieces/index.ts must export the list of pieces this package ships`);
|
|
306
|
+
const described = describePieces(projectRoot, listPath);
|
|
307
|
+
const built = [];
|
|
308
|
+
const listedDirs = /* @__PURE__ */ new Set();
|
|
309
|
+
for (const piece of described.list) {
|
|
310
|
+
const location = resolvePieceLocation(piece, projectRoot, outDir);
|
|
311
|
+
assertPieceVersion(piece, pkg);
|
|
312
|
+
const failure = described.errors.find((e) => e.name === piece.name);
|
|
313
|
+
if (failure) throw new Error(`pieces: "${piece.name}" could not be described: ${failure.message}`);
|
|
314
|
+
const found = described.pieces.find((p) => p.name === piece.name);
|
|
315
|
+
if (!found) throw new Error(`pieces: "${piece.name}" was not described`);
|
|
316
|
+
const metadata = found.metadata;
|
|
317
|
+
const relDir = toPosix(relative(projectRoot, location.dir));
|
|
318
|
+
listedDirs.add(relDir);
|
|
319
|
+
writeFileSync(join(location.dir, "descriptor.json"), JSON.stringify(pieceDescriptor(piece, metadata), createJsonReplacer(), 2) + "\n");
|
|
320
|
+
if (location.form === "entry" && location.entryFile) writeFileSync(join(location.dir, "package.json"), JSON.stringify(piecePackageJson({
|
|
321
|
+
name: piece.name,
|
|
322
|
+
version: piece.version,
|
|
323
|
+
description: metadata.description,
|
|
324
|
+
main: relative(location.dir, location.entryFile),
|
|
325
|
+
license: pkg.license
|
|
326
|
+
}), null, 2) + "\n");
|
|
327
|
+
console.log(`piece: ${piece.name}@${piece.version} -> ${relDir} (${count(metadata.actions)} actions, ${count(metadata.triggers)} triggers)`);
|
|
328
|
+
built.push({
|
|
329
|
+
name: piece.name,
|
|
330
|
+
version: piece.version,
|
|
331
|
+
displayName: metadata.displayName,
|
|
332
|
+
description: metadata.description,
|
|
333
|
+
bundle: relDir,
|
|
334
|
+
descriptor: `${relDir}/descriptor.json`
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
warnUnlistedPieces(target.pieces, listedDirs);
|
|
338
|
+
return built;
|
|
339
|
+
}
|
|
340
|
+
function warnUnlistedPieces(planned, listedDirs) {
|
|
341
|
+
for (const piece of planned) if (!listedDirs.has(toPosix(piece.outDir))) console.warn(`⚠ pieces: pieces/${piece.dir} was built but pieces/index.ts does not list it; a host will not find it`);
|
|
342
|
+
}
|
|
343
|
+
function syncDistManifest(target, built) {
|
|
344
|
+
const { projectRoot, outDir } = target;
|
|
345
|
+
const source = join(projectRoot, "powerhouse.manifest.json");
|
|
346
|
+
const copy = resolve(projectRoot, outDir, "powerhouse.manifest.json");
|
|
347
|
+
const shipsPieces = existsSync(pieceListPath(target));
|
|
348
|
+
if (!existsSync(source)) {
|
|
349
|
+
if (shipsPieces) console.warn("⚠ no powerhouse.manifest.json; pieces will not be listed");
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
mkdirSync(dirname(copy), { recursive: true });
|
|
353
|
+
copyFileSync(source, copy);
|
|
354
|
+
if (!shipsPieces) return copy;
|
|
355
|
+
const enriched = enrichManifestPieces(JSON.parse(readFileSync(copy, "utf8")), built);
|
|
356
|
+
for (const id of enriched.unbuilt) console.warn(`⚠ manifest lists piece "${id}" but nothing built it`);
|
|
357
|
+
writeFileSync(copy, JSON.stringify(enriched.manifest, null, 2) + "\n");
|
|
358
|
+
return copy;
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
export { DESCRIBE_HELPERS, DESCRIBE_SCRIPT, assertPieceVersion, assertPiecesOutDir, buildPieces, createJsonReplacer, describePieces, enrichManifestPieces, expandEntryGlobs, pieceDescriptor, pieceListPath, piecePackageJson, planPieces, resolvePieceLocation, statSafe, syncDistManifest };
|
|
362
|
+
|
|
363
|
+
//# sourceMappingURL=build-pieces.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-pieces.mjs","names":[],"sources":["../../clis/build-pieces.mts"],"sourcesContent":["// The pieces half of a package build: find and bundle each piece whole, load\n// it once in a child process to learn what it is, and write what a host reads.\nimport { execFileSync } from \"node:child_process\";\nimport {\n copyFileSync,\n existsSync,\n mkdirSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport {\n basename,\n dirname,\n isAbsolute,\n join,\n relative,\n resolve,\n sep,\n} from \"node:path\";\nimport type { InlineConfig } from \"tsdown\";\nimport type { Manifest, PieceModule } from \"../document-model/types.js\";\nimport { buildPieceBuildConfig, PIECE_ENTRY_GLOB } from \"./build-config.mjs\";\n\nexport type PiecePlan = {\n /** The directory under pieces/, and so under <outDir>/node/pieces. */\n dir: string;\n /** Source entry, relative to the project root: pieces/<dir>/index.ts. */\n entry: string;\n /** Where the piece lands, relative to the project root. */\n outDir: string;\n};\n\n// What buildPieces needs to know about the package it works in: where it is,\n// where it builds to, and which pieces the plan found.\nexport type PieceBuildTarget = {\n projectRoot: string;\n outDir: string;\n pieces: PiecePlan[];\n};\n\n// One entry of pieces/index.ts, as @powerhousedao/pieces-framework declares it.\n// Declared here so the build needs no dependency on a package meant for pieces.\nexport type PackagePiece = {\n name: string;\n version: string;\n entry?: string;\n bundle?: string;\n};\n\n// What a piece says about itself, in the framework's PieceMetadata shape.\n// Read from the built piece, so nothing in the build has to know the framework.\nexport type PieceMetadata = Record<string, unknown> & {\n displayName?: string;\n description?: string;\n actions?: Record<string, unknown>;\n triggers?: Record<string, unknown>;\n};\n\nexport type DescribedPiece = {\n name: string;\n version: string;\n metadata: PieceMetadata;\n};\n\nexport type DescribeResult = {\n list: PackagePiece[];\n pieces: DescribedPiece[];\n errors: { name: string; message: string }[];\n};\n\nexport type BuiltPiece = {\n name: string;\n version: string;\n displayName?: string;\n description?: string;\n /** Piece directory, relative to the project root, `/` separated. */\n bundle: string;\n /** The descriptor inside it, relative to the project root, `/` separated. */\n descriptor: string;\n};\n\nexport type PackageIdentity = {\n name: string;\n version: string;\n license?: string;\n};\n\nexport type PieceBuildOptions = {\n /** The bundler: tsdown's `build`, handed in so this module never loads it. */\n bundle: (config: InlineConfig) => Promise<unknown>;\n};\n\nconst toPosix = (p: string) => p.split(sep).join(\"/\");\n\nexport function statSafe(p: string) {\n try {\n return statSync(p);\n } catch {\n return null;\n }\n}\n\n// Expand entry globs (single-`*` segments only — the shape `browserEntry`\n// uses) against files on disk, resolving against `root`.\nexport function expandEntryGlobs(root: string, globs: string[]): string[] {\n const files = new Set<string>();\n for (const pattern of globs) {\n const segments = pattern.split(\"/\").filter(Boolean);\n let dirs = [root];\n for (const seg of segments) {\n const next: string[] = [];\n for (const d of dirs) {\n if (!statSafe(d)?.isDirectory()) continue;\n if (seg === \"*\") {\n for (const e of readdirSync(d, { withFileTypes: true })) {\n next.push(join(d, e.name));\n }\n } else {\n next.push(join(d, seg));\n }\n }\n dirs = next;\n }\n for (const f of dirs) {\n if (statSafe(f)?.isFile()) files.add(f);\n }\n }\n return [...files];\n}\n\n// The pieces a project holds, one per pieces/<dir>/index.ts, sorted by dir so\n// a build log and a manifest read the same from one run to the next.\nexport function planPieces(projectRoot: string, outDir: string): PiecePlan[] {\n return expandEntryGlobs(projectRoot, [PIECE_ENTRY_GLOB])\n .map((file) => {\n const dir = basename(dirname(file));\n return {\n dir,\n entry: relative(projectRoot, file),\n outDir: join(outDir, \"node\", \"pieces\", dir),\n };\n })\n .sort((a, b) => (a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0));\n}\n\n// A JSON.stringify replacer that makes a piece's metadata serializable: props\n// carry resolvers, defaults may be class instances, and a schema may cycle.\nexport function createJsonReplacer() {\n const ancestors: object[] = [];\n return function replace(this: unknown, _key: string, value: unknown) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n // `this` is the holder, so popping back to it leaves the current path.\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n\n// The half of the child script that needs nothing from the job: a test\n// evaluates this text on its own, so neither copy can drift from the other.\n\n// `constructor?.name`: a module may export an Object.create(null), and the\n// real piece is usually beside it in the same module.\nexport const DESCRIBE_HELPERS = `\nconst isRecord = (value) => typeof value === \"object\" && value !== null;\n\nfunction findPiece(mod) {\n const candidates = [\n ...Object.values(mod),\n ...(isRecord(mod.default) ? Object.values(mod.default) : []),\n mod.default,\n ];\n for (const candidate of candidates) {\n if (isRecord(candidate) && candidate.constructor?.name === \"Piece\") {\n return candidate;\n }\n }\n for (const candidate of candidates) {\n if (\n isRecord(candidate) &&\n typeof candidate.displayName === \"string\" &&\n (isRecord(candidate.actions) ||\n typeof candidate.actions === \"function\" ||\n typeof candidate.getAction === \"function\")\n ) {\n return candidate;\n }\n }\n return undefined;\n}\n\nfunction describePiece(piece) {\n if (typeof piece.metadata === \"function\") return piece.metadata();\n const call = (value) => (typeof value === \"function\" ? value.call(piece) : value);\n return {\n displayName: piece.displayName,\n logoUrl: piece.logoUrl,\n description: piece.description,\n authors: piece.authors,\n categories: piece.categories,\n auth: piece.auth,\n minimumSupportedRelease: piece.minimumSupportedRelease,\n maximumSupportedRelease: piece.maximumSupportedRelease,\n deprecated: piece.deprecated,\n actions: call(piece.actions) ?? {},\n triggers: call(piece.triggers) ?? {},\n };\n}\n\nfunction createJsonReplacer() {\n const ancestors = [];\n return function replace(_key, value) {\n if (typeof value === \"function\" || value === undefined) return undefined;\n if (typeof value === \"bigint\") return value.toString();\n if (typeof value !== \"object\" || value === null) return value;\n while (ancestors.length > 0 && ancestors.at(-1) !== this) ancestors.pop();\n if (ancestors.includes(value)) return undefined;\n ancestors.push(value);\n return value;\n };\n}\n`;\n\n// Runs in a child node process: loading a piece runs piece-authored top-level\n// code, and the runtime describes pieces in a worker for the same reason.\n\n// A string so it works from `src` under bun or tsx as well as from `dist`. It\n// answers through a file, leaving both its streams to the piece.\nexport const DESCRIBE_SCRIPT = `\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\nconst job = JSON.parse(readFileSync(process.argv[2], \"utf8\"));\n${DESCRIBE_HELPERS}\n// Says why the child gave up in the one place the parent always reads, so a\n// failure reports the cause and never the text of this script.\nfunction fail(message) {\n writeFileSync(job.outFile, JSON.stringify({ fatal: message }));\n process.exit(1);\n}\n\n// The module to load for a list entry; a bundle names its own main.\nfunction entryFile(piece) {\n const declared = piece.entry ?? piece.bundle;\n if (typeof declared !== \"string\") return undefined;\n const path = isAbsolute(declared) ? declared : join(job.projectRoot, declared);\n if (piece.entry) return path;\n const pkgFile = join(path, \"package.json\");\n if (!existsSync(pkgFile)) return undefined;\n const pkg = JSON.parse(readFileSync(pkgFile, \"utf8\"));\n return join(path, typeof pkg.main === \"string\" ? pkg.main : \"index.mjs\");\n}\n\nlet listModule;\ntry {\n listModule = await import(pathToFileURL(job.listPath).href);\n} catch (error) {\n fail(job.listPath + \" threw on import: \" + (error instanceof Error ? error.message : String(error)));\n}\nconst list = listModule.pieces ?? listModule.default;\nif (!Array.isArray(list)) {\n fail(job.listPath + ' exports no \"pieces\" array');\n}\n\nconst out = { list, pieces: [], errors: [] };\nfor (const piece of list) {\n const file = entryFile(piece);\n // A missing file is the parent's to report, with the message it owns.\n if (!file || !existsSync(file)) continue;\n try {\n const mod = await import(pathToFileURL(file).href);\n const found = findPiece(mod);\n if (!found) {\n throw new Error(\n \"no Piece export found in \" + file + \"; exports: \" + Object.keys(mod).join(\", \"),\n );\n }\n const metadata = JSON.parse(JSON.stringify(describePiece(found), createJsonReplacer()));\n out.pieces.push({ name: piece.name, version: piece.version, metadata });\n } catch (error) {\n out.errors.push({\n name: piece.name,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n}\nwriteFileSync(job.outFile, JSON.stringify(out, createJsonReplacer()));\n`;\n\n// What the child said went wrong, if it got that far, and otherwise how it\n// died: an exit status, never the whole script an `Error.message` carries.\nfunction childFailure(error: unknown, outFile: string): string {\n try {\n const answer = JSON.parse(readFileSync(outFile, \"utf8\")) as {\n fatal?: unknown;\n };\n if (typeof answer.fatal === \"string\") return answer.fatal;\n } catch {\n // no answer on disk: fall through to the exit status\n }\n const { status, signal } = error as {\n status?: number | null;\n signal?: string | null;\n };\n if (signal) return `the describe child was killed by ${signal}`;\n return `the describe child exited with code ${status ?? \"unknown\"}`;\n}\n\n// Load the built list and every piece it names in a child process and return\n// what they say about themselves. Throws when the list itself cannot be read.\n\n// Both of the child's streams are the parent's, so a piece that prints at\n// import time is heard rather than mixed into the answer.\nexport function describePieces(\n projectRoot: string,\n listPath: string,\n): DescribeResult {\n const dir = mkdtempSync(join(tmpdir(), \"ph-build-pieces-\"));\n const rel = toPosix(relative(projectRoot, listPath));\n try {\n const jobFile = join(dir, \"job.json\");\n const scriptFile = join(dir, \"describe.mjs\");\n const outFile = join(dir, \"describe.json\");\n writeFileSync(scriptFile, DESCRIBE_SCRIPT);\n writeFileSync(jobFile, JSON.stringify({ projectRoot, listPath, outFile }));\n try {\n execFileSync(process.execPath, [scriptFile, jobFile], {\n timeout: 60_000,\n stdio: \"inherit\",\n });\n } catch (error) {\n throw new Error(\n `pieces: could not load ${rel}: ${childFailure(error, outFile)}`,\n { cause: error },\n );\n }\n return JSON.parse(readFileSync(outFile, \"utf8\")) as DescribeResult;\n } finally {\n rmSync(dir, { recursive: true, force: true });\n }\n}\n\nexport type PieceLocation = {\n /** The piece directory, absolute. */\n dir: string;\n /** The module file, absolute; unset for a bundle, whose package.json names it. */\n entryFile?: string;\n form: \"entry\" | \"bundle\";\n};\n\n// Where a list entry says its built piece is, checked against the disk: a\n// listed piece nobody built would otherwise fail much later, in a host.\nexport function resolvePieceLocation(\n piece: PackagePiece,\n projectRoot: string,\n outDir: string,\n): PieceLocation {\n const declared = piece.entry ?? piece.bundle;\n if (typeof declared !== \"string\" || declared === \"\") {\n throw new Error(\n `pieces: \"${piece.name}\" declares neither an entry nor a bundle`,\n );\n }\n const path = isAbsolute(declared) ? declared : join(projectRoot, declared);\n const form = piece.entry ? \"entry\" : \"bundle\";\n const present =\n form === \"entry\"\n ? statSafe(path)?.isFile()\n : statSafe(join(path, \"package.json\"))?.isFile();\n if (!present) {\n throw new Error(\n `pieces: \"${piece.name}\" declares ${declared}, which is missing`,\n );\n }\n const dir = form === \"entry\" ? dirname(path) : path;\n // Both forms, not just `entry`: a descriptor.json is written into this\n // directory, and outside outDir that lands in tracked source.\n const piecesRoot = resolve(projectRoot, outDir, \"node\", \"pieces\");\n const inside = relative(piecesRoot, dir);\n if (inside === \"\" || inside.startsWith(\"..\") || isAbsolute(inside)) {\n const expected = toPosix(join(outDir, \"node\", \"pieces\"));\n throw new Error(\n `pieces: \"${piece.name}\" declares ${declared}, which is outside ${expected}/; ` +\n `a piece is built to ${expected}/<dir>/index.mjs and its entry must point there`,\n );\n }\n return form === \"entry\" ? { dir, entryFile: path, form } : { dir, form };\n}\n\n// Where the node build leaves the list of pieces a package ships. Its presence\n// on disk, not a pieces/<dir> in the source, is what says a package has them.\nexport function pieceListPath(target: {\n projectRoot: string;\n outDir: string;\n}): string {\n return resolve(\n target.projectRoot,\n target.outDir,\n \"node\",\n \"pieces\",\n \"index.mjs\",\n );\n}\n\n// `dist` is not a default here but a contract: a host reads a piece from\n// dist/node/pieces/<name>, and a list entry names that path literally.\nexport function assertPiecesOutDir(target: {\n outDir: string;\n pieces: PiecePlan[];\n}): void {\n if (target.pieces.length === 0 || target.outDir === \"dist\") return;\n throw new Error(\n `pieces: --out-dir ${target.outDir} cannot hold pieces; a piece is loaded from ` +\n `dist/node/pieces/<name> by the host, so a package that ships pieces builds to dist`,\n );\n}\n\n// A piece named after its package must carry the package's version: once\n// published, a drifted version resolves to the wrong tarball.\nexport function assertPieceVersion(\n piece: PackagePiece,\n pkg: PackageIdentity,\n): void {\n if (piece.name === pkg.name && piece.version !== pkg.version) {\n throw new Error(\n `pieces: \"${piece.name}\" declares version ${piece.version}, package.json says ${pkg.version}`,\n );\n }\n}\n\n// The package.json written beside a piece built from an `entry`, giving the\n// directory npm-bundle shape so a registry can serve it on its own.\nexport function piecePackageJson(options: {\n name: string;\n version: string;\n description?: string;\n main: string;\n license?: string;\n}): Record<string, unknown> {\n return {\n name: options.name,\n version: options.version,\n description: options.description ?? \"\",\n type: \"module\",\n main: options.main,\n ...(options.license ? { license: options.license } : {}),\n // Empty on purpose: the runtime treats a bundle that declares dependencies\n // as not self-contained, and everything a piece needs is inlined already.\n dependencies: {},\n };\n}\n\n// The descriptor written beside a piece: the list's name and version, then\n// whatever the piece said about itself, in the framework's PieceMetadata shape.\nexport function pieceDescriptor(\n piece: PackagePiece,\n metadata: PieceMetadata,\n): Record<string, unknown> {\n const { name: _name, version: _version, ...rest } = metadata;\n return { name: piece.name, version: piece.version, ...rest };\n}\n\n// The manifest's `pieces` with what the build learned: a built piece replaces\n// the source entry with its id in place, or is appended at the end.\n\n// A source entry nothing built is kept as it is and returned as `unbuilt`,\n// for the caller to warn about.\nexport function enrichManifestPieces(\n manifest: Manifest,\n built: BuiltPiece[],\n): { manifest: Manifest; unbuilt: string[] } {\n const byId = new Map(built.map((piece) => [piece.name, piece]));\n const toModule = (piece: BuiltPiece): PieceModule => ({\n id: piece.name,\n name: piece.displayName ?? piece.name,\n version: piece.version,\n ...(piece.description ? { description: piece.description } : {}),\n bundle: piece.bundle,\n descriptor: piece.descriptor,\n });\n const unbuilt: string[] = [];\n const seen = new Set<string>();\n const pieces: PieceModule[] = (manifest.pieces ?? []).map((entry) => {\n const hit = byId.get(entry.id);\n if (!hit) {\n unbuilt.push(entry.id);\n return entry;\n }\n seen.add(entry.id);\n return toModule(hit);\n });\n for (const piece of built) {\n if (!seen.has(piece.name)) pieces.push(toModule(piece));\n }\n return { manifest: { ...manifest, pieces }, unbuilt };\n}\n\nconst count = (record: unknown) =>\n typeof record === \"object\" && record !== null\n ? Object.keys(record).length\n : 0;\n\n// Build every planned piece, then read the built list and describe what it\n// names. Returns what was built, for the manifest.\nexport async function buildPieces(\n target: PieceBuildTarget,\n pkg: PackageIdentity,\n options: PieceBuildOptions,\n): Promise<BuiltPiece[]> {\n const { projectRoot, outDir } = target;\n assertPiecesOutDir(target);\n // resolve, not join: an absolute --out-dir is what the browser and node\n // steps hand tsdown, and joining it onto the project root mangles it.\n for (const piece of target.pieces) {\n console.log(`\\n▶ Building piece ${piece.dir}...`);\n await options.bundle(\n buildPieceBuildConfig({\n entry: resolve(projectRoot, piece.entry),\n outDir: resolve(projectRoot, piece.outDir),\n }),\n );\n }\n\n // The list is the source of truth for names and versions; a package that\n // built pieces without a list has nothing a host could read.\n const listPath = pieceListPath(target);\n if (!existsSync(listPath)) {\n throw new Error(\n `pieces: ${toPosix(relative(projectRoot, listPath))} was not built; ` +\n `pieces/index.ts must export the list of pieces this package ships`,\n );\n }\n const described = describePieces(projectRoot, listPath);\n\n const built: BuiltPiece[] = [];\n const listedDirs = new Set<string>();\n for (const piece of described.list) {\n const location = resolvePieceLocation(piece, projectRoot, outDir);\n assertPieceVersion(piece, pkg);\n const failure = described.errors.find((e) => e.name === piece.name);\n if (failure) {\n throw new Error(\n `pieces: \"${piece.name}\" could not be described: ${failure.message}`,\n );\n }\n const found = described.pieces.find((p) => p.name === piece.name);\n if (!found) {\n throw new Error(`pieces: \"${piece.name}\" was not described`);\n }\n const metadata = found.metadata;\n const relDir = toPosix(relative(projectRoot, location.dir));\n listedDirs.add(relDir);\n\n writeFileSync(\n join(location.dir, \"descriptor.json\"),\n JSON.stringify(\n pieceDescriptor(piece, metadata),\n createJsonReplacer(),\n 2,\n ) + \"\\n\",\n );\n if (location.form === \"entry\" && location.entryFile) {\n writeFileSync(\n join(location.dir, \"package.json\"),\n JSON.stringify(\n piecePackageJson({\n name: piece.name,\n version: piece.version,\n description: metadata.description,\n main: relative(location.dir, location.entryFile),\n license: pkg.license,\n }),\n null,\n 2,\n ) + \"\\n\",\n );\n }\n console.log(\n `piece: ${piece.name}@${piece.version} -> ${relDir} ` +\n `(${count(metadata.actions)} actions, ${count(metadata.triggers)} triggers)`,\n );\n built.push({\n name: piece.name,\n version: piece.version,\n displayName: metadata.displayName,\n description: metadata.description,\n bundle: relDir,\n descriptor: `${relDir}/descriptor.json`,\n });\n }\n\n warnUnlistedPieces(target.pieces, listedDirs);\n return built;\n}\n\n// A built piece no list entry points into ships without a host ever finding it.\nfunction warnUnlistedPieces(\n planned: PiecePlan[],\n listedDirs: Set<string>,\n): void {\n for (const piece of planned) {\n if (!listedDirs.has(toPosix(piece.outDir))) {\n console.warn(\n `⚠ pieces: pieces/${piece.dir} was built but pieces/index.ts does not list it; a host will not find it`,\n );\n }\n }\n}\n\n// Make sure the manifest ships under outDir (tsdown copies it only in the\n// browser build) and, when pieces were built, list them in that copy.\n\n// Always copied afresh: only <outDir>/node is cleaned by the builds, so a copy\n// left by the last build would otherwise outlive an edit to the source.\n\n// The source file is never written. Returns the path of the copy, if any.\nexport function syncDistManifest(\n target: PieceBuildTarget,\n built: BuiltPiece[],\n): string | undefined {\n const { projectRoot, outDir } = target;\n const source = join(projectRoot, \"powerhouse.manifest.json\");\n // resolve, not join: an absolute --out-dir is a location, not a suffix.\n const copy = resolve(projectRoot, outDir, \"powerhouse.manifest.json\");\n // The built list, not the source plan: a package whose pieces are all\n // `bundle:` entries has no pieces/<dir> and still ships pieces.\n const shipsPieces = existsSync(pieceListPath(target));\n if (!existsSync(source)) {\n if (shipsPieces) {\n console.warn(\"⚠ no powerhouse.manifest.json; pieces will not be listed\");\n }\n return undefined;\n }\n mkdirSync(dirname(copy), { recursive: true });\n copyFileSync(source, copy);\n if (!shipsPieces) return copy;\n\n const manifest = JSON.parse(readFileSync(copy, \"utf8\")) as Manifest;\n const enriched = enrichManifestPieces(manifest, built);\n for (const id of enriched.unbuilt) {\n console.warn(`⚠ manifest lists piece \"${id}\" but nothing built it`);\n }\n writeFileSync(copy, JSON.stringify(enriched.manifest, null, 2) + \"\\n\");\n return copy;\n}\n"],"mappings":";;;;;;AAiGA,MAAM,WAAW,MAAc,EAAE,MAAM,IAAI,CAAC,KAAK,IAAI;AAErD,SAAgB,SAAS,GAAW;AAClC,KAAI;AACF,SAAO,SAAS,EAAE;SACZ;AACN,SAAO;;;AAMX,SAAgB,iBAAiB,MAAc,OAA2B;CACxE,MAAM,wBAAQ,IAAI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