@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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as resolveSwitchboardPortDefault, r as vetraArgs, t as resolveConnectPortDefault } from "./vetra-
|
|
1
|
+
import { n as resolveSwitchboardPortDefault, r as vetraArgs, t as resolveConnectPortDefault } from "./vetra-CoMvTJK7.mjs";
|
|
2
2
|
export { resolveConnectPortDefault, resolveSwitchboardPortDefault, vetraArgs };
|
package/dist/clis/args/vetra.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as resolveSwitchboardPortDefault, r as vetraArgs, t as resolveConnectPortDefault } from "./vetra-
|
|
1
|
+
import { n as resolveSwitchboardPortDefault, r as vetraArgs, t as resolveConnectPortDefault } from "./vetra-DV0zQzba.mjs";
|
|
2
2
|
export { resolveConnectPortDefault, resolveSwitchboardPortDefault, vetraArgs };
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { esmExternalRequirePlugin } from "rolldown/plugins";
|
|
2
|
+
import "semver";
|
|
3
|
+
const SHARED_DEP_SPECIFIERS = [
|
|
4
|
+
{
|
|
5
|
+
specifier: "document-model",
|
|
6
|
+
package: "document-model"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
specifier: "@powerhousedao/document-engineering",
|
|
10
|
+
package: "@powerhousedao/document-engineering"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
specifier: "@powerhousedao/shared",
|
|
14
|
+
package: "@powerhousedao/shared"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
specifier: "@powerhousedao/shared/registry/urls",
|
|
18
|
+
package: "@powerhousedao/shared"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
specifier: "@powerhousedao/design-system/connect",
|
|
22
|
+
package: "@powerhousedao/design-system"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
specifier: "@powerhousedao/reactor-browser",
|
|
26
|
+
package: "@powerhousedao/reactor-browser"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
specifier: "zod",
|
|
30
|
+
package: "zod"
|
|
31
|
+
}
|
|
32
|
+
].map((d) => d.specifier);
|
|
33
|
+
/**
|
|
34
|
+
* The `@powerhousedao/shared` subpaths the production vendor bundles. The
|
|
35
|
+
* bare root is deliberately absent: its type barrel references node-only
|
|
36
|
+
* modules (`clis/`), which the current vite/rolldown cannot bundle for the
|
|
37
|
+
* browser — vendoring the root fails the build (a pre-existing latent
|
|
38
|
+
* issue). A package that imports the bare root is simply not shared; it
|
|
39
|
+
* bundles its own copy.
|
|
40
|
+
*/
|
|
41
|
+
const SHARED_SUBPATHS = [
|
|
42
|
+
"connect",
|
|
43
|
+
"document-model",
|
|
44
|
+
"processors",
|
|
45
|
+
"document-drive",
|
|
46
|
+
"registry",
|
|
47
|
+
"registry/urls",
|
|
48
|
+
"registry/manifest-slim"
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* The specifiers a package build may safely externalize onto the host's
|
|
52
|
+
* import map — i.e. the ones the vendor actually publishes an entry for.
|
|
53
|
+
*
|
|
54
|
+
* `@powerhousedao/shared` is narrowed to SHARED_SUBPATHS rather than taken as
|
|
55
|
+
* a prefix: the bare root is never vendored (see SHARED_SUBPATHS), and
|
|
56
|
+
* neither are its other subpaths (`analytics`, `constants`, `clis`, ...).
|
|
57
|
+
* Externalizing those would leave a bare specifier in the package's output
|
|
58
|
+
* that nothing in the import map resolves, so the package would fail to load
|
|
59
|
+
* at runtime instead of simply bundling its own copy.
|
|
60
|
+
*/
|
|
61
|
+
const EXTERNALIZABLE_SHARED_SPECIFIERS = [...new Set([...SHARED_DEP_SPECIFIERS.filter((s) => s !== "@powerhousedao/shared"), ...SHARED_SUBPATHS.map((s) => `@powerhousedao/shared/${s}`)])];
|
|
62
|
+
function isSharedSpecifier(spec, specs) {
|
|
63
|
+
return specs.some((s) => spec === s || spec.startsWith(s + "/"));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Return the import/export specifiers in `source` that are a shared
|
|
67
|
+
* specifier (or a subpath of one), sorted. Heuristic: only statement
|
|
68
|
+
* positions are scanned (`from "x"`, `import "x"`, `import("x")`;
|
|
69
|
+
* `export … from "x"` is covered by the `from` pattern), so import-like
|
|
70
|
+
* text inside comments or strings can be reported too. That errs toward
|
|
71
|
+
* over-reporting, which is the safe direction for the advisory build
|
|
72
|
+
* warning.
|
|
73
|
+
*/
|
|
74
|
+
function findSharedImports(source, specs = SHARED_DEP_SPECIFIERS) {
|
|
75
|
+
const found = /* @__PURE__ */ new Set();
|
|
76
|
+
for (const re of [
|
|
77
|
+
/\bfrom\s+["']([^"'\\]+)["']/g,
|
|
78
|
+
/\bimport\s+["']([^"'\\]+)["']/g,
|
|
79
|
+
/\bimport\s*\(\s*["']([^"'\\]+)["']\s*\)/g
|
|
80
|
+
]) for (const m of source.matchAll(re)) {
|
|
81
|
+
const spec = m[1];
|
|
82
|
+
if (isSharedSpecifier(spec, specs)) found.add(spec);
|
|
83
|
+
}
|
|
84
|
+
return [...found].sort();
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region clis/build-config.mts
|
|
88
|
+
const entry = [
|
|
89
|
+
"index.ts",
|
|
90
|
+
"document-models/index.ts",
|
|
91
|
+
"document-models/*/index.ts",
|
|
92
|
+
"document-models/*/module.ts",
|
|
93
|
+
"editors/index.ts",
|
|
94
|
+
"editors/*/index.ts",
|
|
95
|
+
"editors/*/module.ts",
|
|
96
|
+
"subgraphs/index.ts",
|
|
97
|
+
"subgraphs/*/index.ts",
|
|
98
|
+
"processors/index.ts",
|
|
99
|
+
"processors/*/index.ts"
|
|
100
|
+
];
|
|
101
|
+
const nodeEntry = [...entry, "pieces/index.ts"];
|
|
102
|
+
const PIECE_ENTRY_GLOB = "pieces/*/index.ts";
|
|
103
|
+
const browserEntry = [...entry, "reactor/index.ts"];
|
|
104
|
+
const alwaysBundle = ["**"];
|
|
105
|
+
const reactExternals = [
|
|
106
|
+
"react",
|
|
107
|
+
"react-dom",
|
|
108
|
+
"react/jsx-runtime",
|
|
109
|
+
"react-dom/client"
|
|
110
|
+
];
|
|
111
|
+
const nodeNeverBundle = [
|
|
112
|
+
"@powerhousedao/connect",
|
|
113
|
+
"@powerhousedao/ph-cli",
|
|
114
|
+
"@powerhousedao/reactor-api",
|
|
115
|
+
"react",
|
|
116
|
+
"react-dom",
|
|
117
|
+
"react/jsx-runtime",
|
|
118
|
+
"react-dom/client",
|
|
119
|
+
"tailwindcss",
|
|
120
|
+
"vitest",
|
|
121
|
+
"tsdown",
|
|
122
|
+
"@tailwindcss/cli",
|
|
123
|
+
"@vitejs/plugin-react",
|
|
124
|
+
"@testing-library/jest-dom",
|
|
125
|
+
"@testing-library/react",
|
|
126
|
+
"@testing-library/user-event",
|
|
127
|
+
"@types/node",
|
|
128
|
+
"@types/react",
|
|
129
|
+
"@types/react-dom",
|
|
130
|
+
"@electric-sql/pglite",
|
|
131
|
+
"@electric-sql/pglite-tools"
|
|
132
|
+
];
|
|
133
|
+
const browserNeverBundle = nodeNeverBundle.filter((spec) => typeof spec !== "string" || !reactExternals.includes(spec));
|
|
134
|
+
const copy = [{
|
|
135
|
+
from: "powerhouse.manifest.json",
|
|
136
|
+
to: "dist"
|
|
137
|
+
}];
|
|
138
|
+
const config = false;
|
|
139
|
+
const clean = true;
|
|
140
|
+
const dts = false;
|
|
141
|
+
const sourcemap = true;
|
|
142
|
+
const sharedNeverBundle = EXTERNALIZABLE_SHARED_SPECIFIERS.map((s) => new RegExp(`^${s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(/.*)?$`));
|
|
143
|
+
const baseBrowserConfig = {
|
|
144
|
+
entry: browserEntry,
|
|
145
|
+
platform: "browser",
|
|
146
|
+
copy,
|
|
147
|
+
config,
|
|
148
|
+
clean,
|
|
149
|
+
dts,
|
|
150
|
+
sourcemap,
|
|
151
|
+
plugins: [esmExternalRequirePlugin({
|
|
152
|
+
external: reactExternals,
|
|
153
|
+
skipDuplicateCheck: true
|
|
154
|
+
})],
|
|
155
|
+
inputOptions: { experimental: { resolveNewUrlToAsset: true } }
|
|
156
|
+
};
|
|
157
|
+
function buildBrowserBuildConfig(options = {}) {
|
|
158
|
+
const sharedDeps = options.sharedDeps ?? true;
|
|
159
|
+
return {
|
|
160
|
+
...baseBrowserConfig,
|
|
161
|
+
deps: {
|
|
162
|
+
alwaysBundle,
|
|
163
|
+
neverBundle: [...browserNeverBundle, ...sharedDeps ? sharedNeverBundle : []]
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const browserBuildConfig = buildBrowserBuildConfig();
|
|
168
|
+
/**
|
|
169
|
+
* Shared specs a source imports but the built output no longer references as
|
|
170
|
+
* bare imports — the bundler inlined them, which is exactly what the
|
|
171
|
+
* external set is meant to prevent.
|
|
172
|
+
*/
|
|
173
|
+
function findBundledSharedDeps(importedSpecs, outputs) {
|
|
174
|
+
return importedSpecs.filter((spec) => !outputs.some((f) => findSharedImports(f.content, [spec]).includes(spec)));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The node build externalizes the same shared set as the browser build, for
|
|
178
|
+
* the same reason the `@powerhousedao/reactor-api` entry in `nodeNeverBundle`
|
|
179
|
+
* already gives: the host provides these, and a package carrying its own copy
|
|
180
|
+
* is a second class identity as well as dead weight. What differs is only how
|
|
181
|
+
* the import is resolved at runtime -- Connect's import map in the browser,
|
|
182
|
+
* ordinary node resolution here, which works because these are declared for
|
|
183
|
+
* the consumer to provide (`document-model`, `@powerhousedao/reactor-browser`
|
|
184
|
+
* and `zod` are peerDependencies of every generated project).
|
|
185
|
+
*/
|
|
186
|
+
function buildNodeBuildConfig(options = {}) {
|
|
187
|
+
const sharedDeps = options.sharedDeps ?? true;
|
|
188
|
+
return {
|
|
189
|
+
entry: nodeEntry,
|
|
190
|
+
deps: {
|
|
191
|
+
alwaysBundle,
|
|
192
|
+
neverBundle: [...nodeNeverBundle, ...sharedDeps ? sharedNeverBundle : []]
|
|
193
|
+
},
|
|
194
|
+
platform: "node",
|
|
195
|
+
config,
|
|
196
|
+
clean,
|
|
197
|
+
dts,
|
|
198
|
+
sourcemap
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const nodeBuildConfig = buildNodeBuildConfig();
|
|
202
|
+
/**
|
|
203
|
+
* One piece, bundled whole. A piece runs in a forked worker with no
|
|
204
|
+
* node_modules beside it, so nothing the piece imports can be left to the
|
|
205
|
+
* host: the framework, its dependencies and the shared set that every other
|
|
206
|
+
* module kind externalizes are all inlined here, and only node built-ins stay
|
|
207
|
+
* external. Code splitting is off for the same reason, so a dynamic import is
|
|
208
|
+
* inlined too and the piece directory holds exactly one module.
|
|
209
|
+
*/
|
|
210
|
+
function buildPieceBuildConfig(options) {
|
|
211
|
+
return {
|
|
212
|
+
entry: { index: options.entry },
|
|
213
|
+
outDir: options.outDir,
|
|
214
|
+
platform: "node",
|
|
215
|
+
deps: {
|
|
216
|
+
alwaysBundle,
|
|
217
|
+
neverBundle: [],
|
|
218
|
+
onlyAllowBundle: false
|
|
219
|
+
},
|
|
220
|
+
outputOptions: { codeSplitting: false },
|
|
221
|
+
config,
|
|
222
|
+
clean,
|
|
223
|
+
dts,
|
|
224
|
+
sourcemap
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { buildNodeBuildConfig as a, nodeBuildConfig as c, buildBrowserBuildConfig as i, browserBuildConfig as n, buildPieceBuildConfig as o, browserEntry as r, findBundledSharedDeps as s, PIECE_ENTRY_GLOB as t };
|
|
229
|
+
|
|
230
|
+
//# sourceMappingURL=build-config-BkfXtfV8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-config-BkfXtfV8.mjs","names":[],"sources":["../../connect/shared-deps.ts","../../clis/build-config.mts"],"sourcesContent":["import { satisfies, validRange } from \"semver\";\n\nexport type SharedDep = { specifier: string; package: string };\n\n/**\n * The dependency set Connect and loaded packages share via the import map.\n * `@powerhousedao/connect` is deliberately absent: it is the Connect app\n * itself (no importable exports), so there is nothing to share.\n */\nexport const SHARED_DEPS: readonly SharedDep[] = [\n { specifier: \"document-model\", package: \"document-model\" },\n {\n specifier: \"@powerhousedao/document-engineering\",\n package: \"@powerhousedao/document-engineering\",\n },\n { specifier: \"@powerhousedao/shared\", package: \"@powerhousedao/shared\" },\n {\n specifier: \"@powerhousedao/shared/registry/urls\",\n package: \"@powerhousedao/shared\",\n },\n {\n specifier: \"@powerhousedao/design-system/connect\",\n package: \"@powerhousedao/design-system\",\n },\n {\n specifier: \"@powerhousedao/reactor-browser\",\n package: \"@powerhousedao/reactor-browser\",\n },\n // Connect already vendors zod (it is in DEFAULT_VENDOR_INCLUDE, so the\n // import map publishes an entry for it) and every generated project already\n // declares it as a peerDependency -- yet it was missing from this set, so\n // each package inlined a private copy anyway. It is the single biggest\n // dependency left in a minimal package.\n { specifier: \"zod\", package: \"zod\" },\n];\n\nexport const SHARED_DEP_SPECIFIERS: readonly string[] = SHARED_DEPS.map(\n (d) => d.specifier,\n);\n\n/**\n * The `@powerhousedao/shared` subpaths the production vendor bundles. The\n * bare root is deliberately absent: its type barrel references node-only\n * modules (`clis/`), which the current vite/rolldown cannot bundle for the\n * browser — vendoring the root fails the build (a pre-existing latent\n * issue). A package that imports the bare root is simply not shared; it\n * bundles its own copy.\n */\nexport const SHARED_SUBPATHS: readonly string[] = [\n \"connect\",\n \"document-model\",\n \"processors\",\n \"document-drive\",\n \"registry\",\n \"registry/urls\",\n \"registry/manifest-slim\",\n];\n\n/**\n * The specifiers a package build may safely externalize onto the host's\n * import map — i.e. the ones the vendor actually publishes an entry for.\n *\n * `@powerhousedao/shared` is narrowed to SHARED_SUBPATHS rather than taken as\n * a prefix: the bare root is never vendored (see SHARED_SUBPATHS), and\n * neither are its other subpaths (`analytics`, `constants`, `clis`, ...).\n * Externalizing those would leave a bare specifier in the package's output\n * that nothing in the import map resolves, so the package would fail to load\n * at runtime instead of simply bundling its own copy.\n */\nexport const EXTERNALIZABLE_SHARED_SPECIFIERS: readonly string[] = [\n ...new Set([\n ...SHARED_DEP_SPECIFIERS.filter((s) => s !== \"@powerhousedao/shared\"),\n ...SHARED_SUBPATHS.map((s) => `@powerhousedao/shared/${s}`),\n ]),\n];\n\n/** Split a specifier into its package name and subpath (\"\" for a root). */\nexport function parseDepSpec(spec: string): { pkg: string; sub: string } {\n if (spec.startsWith(\"@\")) {\n const parts = spec.split(\"/\");\n return { pkg: parts.slice(0, 2).join(\"/\"), sub: parts.slice(2).join(\"/\") };\n }\n const i = spec.indexOf(\"/\");\n return i === -1\n ? { pkg: spec, sub: \"\" }\n : { pkg: spec.slice(0, i), sub: spec.slice(i + 1) };\n}\n\nfunction isSharedSpecifier(spec: string, specs: readonly string[]): boolean {\n return specs.some((s) => spec === s || spec.startsWith(s + \"/\"));\n}\n\n/**\n * Return the import/export specifiers in `source` that are a shared\n * specifier (or a subpath of one), sorted. Heuristic: only statement\n * positions are scanned (`from \"x\"`, `import \"x\"`, `import(\"x\")`;\n * `export … from \"x\"` is covered by the `from` pattern), so import-like\n * text inside comments or strings can be reported too. That errs toward\n * over-reporting, which is the safe direction for the advisory build\n * warning.\n */\nexport function findSharedImports(\n source: string,\n specs: readonly string[] = SHARED_DEP_SPECIFIERS,\n): string[] {\n const found = new Set<string>();\n const patterns = [\n /\\bfrom\\s+[\"']([^\"'\\\\]+)[\"']/g,\n /\\bimport\\s+[\"']([^\"'\\\\]+)[\"']/g,\n /\\bimport\\s*\\(\\s*[\"']([^\"'\\\\]+)[\"']\\s*\\)/g,\n ];\n for (const re of patterns) {\n for (const m of source.matchAll(re)) {\n const spec = m[1];\n if (isSharedSpecifier(spec, specs)) found.add(spec);\n }\n }\n return [...found].sort();\n}\n\n/**\n * Rewrite a package source for blob import in a worker context (import maps\n * don't apply there): shared specifiers become their mapped URLs, and\n * relative (`./`, `../`) specifiers become absolute against `sourceUrl`\n * (a blob URL has no directory to resolve against). `#` subpath imports are\n * deliberately left alone: they resolve via the package's own\n * `package.json` \"imports\" field, which the rewrite cannot reproduce.\n * Returns the input unchanged when nothing matched.\n */\nexport function rewritePackageSource(\n source: string,\n sourceUrl: string,\n imports: Record<string, string>,\n): string {\n if (!Object.keys(imports).length) return source;\n const base = new URL(sourceUrl);\n const map = (spec: string): string | null => {\n const mapped = imports[spec];\n if (mapped) return mapped;\n if (spec.startsWith(\"./\") || spec.startsWith(\"../\")) {\n return new URL(spec, base).href;\n }\n return null;\n };\n let out = source;\n // The quote character is captured and reused: a source that quotes its\n // specifiers with ' would otherwise never match the replacement and be\n // left un-rewritten — silently, since the specifier still maps.\n for (const re of [\n /\\bfrom\\s+([\"'])([^\"'\\\\]+)\\1/g,\n /\\bimport\\s+([\"'])([^\"'\\\\]+)\\1/g,\n /\\bimport\\s*\\(\\s*([\"'])([^\"'\\\\]+)\\1\\s*\\)/g,\n ]) {\n out = out.replace(re, (match, quote: string, spec: string) => {\n // The match contains the quoted specifier exactly once and the\n // captured group has no quotes/backslashes ([^\"'\\\\]), so a literal\n // replace is safe.\n const mapped = map(spec);\n return mapped\n ? match.replace(`${quote}${spec}${quote}`, `${quote}${mapped}${quote}`)\n : match;\n });\n }\n return out;\n}\n\nexport type SharedDepMismatch = {\n package: string;\n required: string;\n provided: string;\n};\n\nexport type PackageDeps = {\n dependencies?: Record<string, unknown>;\n peerDependencies?: Record<string, unknown>;\n};\n\n/**\n * Compare a package's declared ranges against the host's version table.\n * `hostVersions` defines the checked set (only deps present in it are\n * checked). `*`, non-semver protocols (workspace:, file:, git:, npm:, URLs)\n * and unparseable ranges never mismatch.\n */\nexport function checkSharedDeps(\n pkgJson: PackageDeps,\n hostVersions: Record<string, string>,\n): SharedDepMismatch[] {\n const out: SharedDepMismatch[] = [];\n const entries = [\n ...Object.entries(pkgJson.dependencies ?? {}),\n ...Object.entries(pkgJson.peerDependencies ?? {}),\n ];\n for (const [dep, range] of entries) {\n const provided = hostVersions[dep];\n if (provided === undefined || typeof range !== \"string\") continue;\n if (range === \"*\" || /^[a-z]+:/i.test(range)) continue;\n if (!validRange(range)) continue;\n if (!satisfies(provided, range, { includePrerelease: true })) {\n out.push({ package: dep, required: range, provided });\n }\n }\n return out;\n}\n\nexport function formatSharedDepWarnings(\n mismatches: SharedDepMismatch[],\n): string[] {\n return mismatches.map(\n (m) =>\n `${m.package}: requires ${m.required}, Connect provides ${m.provided}`,\n );\n}\n","import { esmExternalRequirePlugin } from \"rolldown/plugins\";\nimport type { InlineConfig } from \"tsdown\";\nimport {\n EXTERNALIZABLE_SHARED_SPECIFIERS,\n findSharedImports,\n} from \"../connect/shared-deps.js\";\n\nconst entry = [\n \"index.ts\",\n \"document-models/index.ts\",\n \"document-models/*/index.ts\",\n \"document-models/*/module.ts\",\n \"editors/index.ts\",\n \"editors/*/index.ts\",\n \"editors/*/module.ts\",\n \"subgraphs/index.ts\",\n \"subgraphs/*/index.ts\",\n \"processors/index.ts\",\n \"processors/*/index.ts\",\n];\n\n// ./pieces is node-only for the same reason ./reactor is browser-only: a piece\n// is loaded and run by a host process, never by the browser. Only the list of\n// pieces builds here; each piece is its own build (buildPieceBuildConfig), so\n// two pieces never share a chunk and each ships as one self-contained module.\nconst nodeEntry = [...entry, \"pieces/index.ts\"];\n\n// Where a package's pieces live, one directory per piece, as the node entry\n// glob spells it; `ph build` expands it against the project to find them.\nexport const PIECE_ENTRY_GLOB = \"pieces/*/index.ts\";\n\n// ./reactor is browser-only: the SharedWorker needs it, the node build does not.\nexport const browserEntry = [...entry, \"reactor/index.ts\"];\n\nconst alwaysBundle = [\"**\"];\n\n// React must be external so `import ... from \"react\"` stays a bare import and\n// resolves to the host's React at runtime; bundled, a chunk would carry a second\n// React. In the browser build the externals below belong to esmExternalRequirePlugin\n// alone: rolldown converts a CommonJS `require(\"react\")` into an import only for\n// externals the plugin owns, and listed in neverBundle too the top-level external\n// wins, leaving a browser bundle with a require it cannot serve. use-sync-external-store\n// under zustand, and so under @xyflow/react, is the case that found this.\nconst reactExternals = [\n \"react\",\n \"react-dom\",\n \"react/jsx-runtime\",\n \"react-dom/client\",\n];\n\nconst nodeNeverBundle = [\n // we know that we don't want connect inside connect\n \"@powerhousedao/connect\",\n // published code would never need the cli\n \"@powerhousedao/ph-cli\",\n // the reactor-api host must provide a single class identity for\n // BaseSubgraph/BaseProcessor — inlining a copy here breaks the\n // prototype-chain check the package loader uses to detect subgraphs.\n \"@powerhousedao/reactor-api\",\n // react is resolved from esm.sh\n \"react\",\n \"react-dom\",\n \"react/jsx-runtime\",\n \"react-dom/client\",\n // build tools\n \"tailwindcss\",\n \"vitest\",\n \"tsdown\",\n \"@tailwindcss/cli\",\n \"@vitejs/plugin-react\",\n // testing tools\n \"@testing-library/jest-dom\",\n \"@testing-library/react\",\n \"@testing-library/user-event\",\n // types\n \"@types/node\",\n \"@types/react\",\n \"@types/react-dom\",\n // exclude pglite wasm/data chunks\n \"@electric-sql/pglite\",\n \"@electric-sql/pglite-tools\",\n];\n\n// The node build keeps React in neverBundle: node has createRequire, so a\n// CommonJS require of an external resolves there without the plugin.\nconst browserNeverBundle = nodeNeverBundle.filter(\n (spec) => typeof spec !== \"string\" || !reactExternals.includes(spec),\n);\n\nconst copy = [{ from: \"powerhouse.manifest.json\", to: \"dist\" }];\n\nconst config = false;\nconst clean = true;\n// types are emitted via a separate tsc command\nconst dts = false;\nconst sourcemap = true;\n\n// Shared deps are externalized from every package build: the host (Connect)\n// resolves them to one bundled copy via the import map, so a package must\n// not inline its own copy (two instances of the same dep break identity\n// checks and double the download). One regexp per specifier covers the root\n// and every subpath (rolldown `external` accepts strings and regexps, not\n// function matchers, in this toolchain).\n//\n// Only the specifiers the vendor publishes are externalized — see\n// EXTERNALIZABLE_SHARED_SPECIFIERS. Externalizing one the import map has no\n// entry for would leave an unresolvable bare specifier in the output.\nconst sharedNeverBundle = EXTERNALIZABLE_SHARED_SPECIFIERS.map(\n (s) => new RegExp(`^${s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}(/.*)?$`),\n);\n\nconst baseBrowserConfig = {\n entry: browserEntry,\n platform: \"browser\" as const,\n copy,\n config,\n clean,\n dts,\n sourcemap,\n plugins: [\n esmExternalRequirePlugin({\n external: reactExternals,\n skipDuplicateCheck: true,\n }),\n ],\n inputOptions: {\n experimental: { resolveNewUrlToAsset: true },\n },\n};\n\nexport type BrowserBuildConfigOptions = {\n /** Externalize the shared dependency set (default: true). */\n sharedDeps?: boolean;\n};\n\nexport function buildBrowserBuildConfig(\n options: BrowserBuildConfigOptions = {},\n): InlineConfig {\n const sharedDeps = options.sharedDeps ?? true;\n return {\n ...baseBrowserConfig,\n deps: {\n alwaysBundle,\n neverBundle: [\n ...browserNeverBundle,\n ...(sharedDeps ? sharedNeverBundle : []),\n ],\n },\n };\n}\n\n// Kept for existing callers: the default (shared deps externalized).\nexport const browserBuildConfig = buildBrowserBuildConfig();\n\n/**\n * Shared specs a source imports but the built output no longer references as\n * bare imports — the bundler inlined them, which is exactly what the\n * external set is meant to prevent.\n */\nexport function findBundledSharedDeps(\n importedSpecs: string[],\n outputs: readonly { path: string; content: string }[],\n): string[] {\n return importedSpecs.filter(\n (spec) =>\n !outputs.some((f) => findSharedImports(f.content, [spec]).includes(spec)),\n );\n}\n\nexport type NodeBuildConfigOptions = {\n /** Externalize the shared dependency set (default: true). */\n sharedDeps?: boolean;\n};\n\n/**\n * The node build externalizes the same shared set as the browser build, for\n * the same reason the `@powerhousedao/reactor-api` entry in `nodeNeverBundle`\n * already gives: the host provides these, and a package carrying its own copy\n * is a second class identity as well as dead weight. What differs is only how\n * the import is resolved at runtime -- Connect's import map in the browser,\n * ordinary node resolution here, which works because these are declared for\n * the consumer to provide (`document-model`, `@powerhousedao/reactor-browser`\n * and `zod` are peerDependencies of every generated project).\n */\nexport function buildNodeBuildConfig(\n options: NodeBuildConfigOptions = {},\n): InlineConfig {\n const sharedDeps = options.sharedDeps ?? true;\n return {\n entry: nodeEntry,\n deps: {\n alwaysBundle,\n neverBundle: [\n ...nodeNeverBundle,\n ...(sharedDeps ? sharedNeverBundle : []),\n ],\n },\n platform: \"node\",\n config,\n clean,\n dts,\n sourcemap,\n };\n}\n\n// Kept for existing callers: the default (shared deps externalized).\nexport const nodeBuildConfig: InlineConfig = buildNodeBuildConfig();\n\nexport type PieceBuildConfigOptions = {\n /** The piece's source entry, relative to the project: `pieces/<dir>/index.ts`. */\n entry: string;\n /** Where the piece lands: `<outDir>/node/pieces/<dir>`. */\n outDir: string;\n};\n\n/**\n * One piece, bundled whole. A piece runs in a forked worker with no\n * node_modules beside it, so nothing the piece imports can be left to the\n * host: the framework, its dependencies and the shared set that every other\n * module kind externalizes are all inlined here, and only node built-ins stay\n * external. Code splitting is off for the same reason, so a dynamic import is\n * inlined too and the piece directory holds exactly one module.\n */\nexport function buildPieceBuildConfig(\n options: PieceBuildConfigOptions,\n): InlineConfig {\n return {\n entry: { index: options.entry },\n outDir: options.outDir,\n platform: \"node\",\n deps: {\n alwaysBundle,\n neverBundle: [],\n // Inlining dependencies is the point here, so tsdown's hint about it\n // would only be noise on every piece.\n onlyAllowBundle: false,\n },\n outputOptions: { codeSplitting: false },\n config,\n clean,\n dts,\n sourcemap,\n };\n}\n"],"mappings":";;AAoCA,MAAa,wBA3BoC;CAC/C;EAAE,WAAW;EAAkB,SAAS;EAAkB;CAC1D;EACE,WAAW;EACX,SAAS;EACV;CACD;EAAE,WAAW;EAAyB,SAAS;EAAyB;CACxE;EACE,WAAW;EACX,SAAS;EACV;CACD;EACE,WAAW;EACX,SAAS;EACV;CACD;EACE,WAAW;EACX,SAAS;EACV;CAMD;EAAE,WAAW;EAAO,SAAS;EAAO;CACrC,CAEmE,KACjE,MAAM,EAAE,UACV;;;;;;;;;AAUD,MAAa,kBAAqC;CAChD;CACA;CACA;CACA;CACA;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