@powerhousedao/builder-tools 6.2.3-dev.2 → 6.2.3-dev.20

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/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { DYNAMIC_BASE_PLACEHOLDER } from "@powerhousedao/shared/connect";
1
2
  import { CommonServerOptions, HtmlTagDescriptor, InlineConfig, Plugin } from "vite";
2
3
  import { PowerhouseConfig, PowerhousePackage } from "@powerhousedao/config";
3
4
  import { PHConnectRuntimeConfig } from "@powerhousedao/shared/clis";
@@ -61,9 +62,9 @@ declare function connectBuildHashPlugin(buildHash: string): Plugin;
61
62
  //#endregion
62
63
  //#region connect-utils/externalize-vendor.d.ts
63
64
  interface VendorPrebuildOptions {
64
- /** Project root (the reactor-project dir). */
65
+ /** Project root the vendor deps resolve from. */
65
66
  dirname: string;
66
- /** Bare specifiers to bundle into the vendor (defaults to the heavy libs). */
67
+ /** Specifiers to prebuild into the vendor (defaults to the dev set). */
67
68
  include?: string[];
68
69
  /** Specifiers left external to the build (defaults to the React family). */
69
70
  external?: string[];
@@ -73,6 +74,18 @@ interface VendorPrebuildOptions {
73
74
  errorRef?: {
74
75
  message?: string;
75
76
  };
77
+ /**
78
+ * The APP's base — the same string the app build uses (the dynamic-base
79
+ * placeholder, or a normalized deploy base like "/app/"). The vendor's own
80
+ * build base is this plus the vendor segment, so emitted asset URLs land
81
+ * under <app-base>__vendor__/. Default: the dynamic placeholder + segment
82
+ * (dev behavior). Import-map values stay base-relative; the production
83
+ * build strips the leading slash (values then resolve against the page URL
84
+ * under any deploy base), the dev flow prefixes its own base.
85
+ */
86
+ base?: string;
87
+ /** NODE_ENV define for the vendor build (default "development"). */
88
+ nodeEnv?: "development" | "production";
76
89
  }
77
90
  /**
78
91
  * The stable Connect libraries worth prebuilding. The React family is NOT here —
@@ -88,8 +101,10 @@ declare const DEFAULT_VENDOR_INCLUDE: string[];
88
101
  declare const VENDOR_EXTERNAL: string[];
89
102
  interface PrebuiltVendor {
90
103
  vendorDir: string;
91
- /** import map: bare specifier -> "/__vendor__/<entry>.js". */
104
+ /** import map: bare specifier -> "/__vendor__/<entry>.js" (base-relative). */
92
105
  imports: Record<string, string>;
106
+ /** Resolved versions of every included + external package. */
107
+ versions: Record<string, string>;
93
108
  }
94
109
  /** URL prefix the vendor bundle is served under by the dev middleware. */
95
110
  declare const VENDOR_URL_PREFIX = "/__vendor__/";
@@ -99,6 +114,25 @@ declare const VENDOR_URL_PREFIX = "/__vendor__/";
99
114
  * Returns null on any failure (caller falls back to a normal dev server).
100
115
  */
101
116
  declare function prebuildConnectVendor(options: VendorPrebuildOptions): Promise<PrebuiltVendor | null>;
117
+ /**
118
+ * The published specifiers whose entry file the vendor build never emitted.
119
+ * URLs are base-less (`/__vendor__/x.js`) and resolve inside `vendorDir`.
120
+ */
121
+ declare function missingVendorEntries(vendorDir: string, imports: Record<string, string>): {
122
+ spec: string;
123
+ url: string;
124
+ }[];
125
+ /**
126
+ * Rebase the vendor's base-less entry URLs (`/__vendor__/x.js`) onto the
127
+ * deploy base, so a consumer that resolves them against the page origin lands
128
+ * under that base rather than the server root. A dynamic-base build keeps its
129
+ * placeholder, which the runtime substitutes.
130
+ *
131
+ * `base` is the app base from `prebuildConnectVendor` callers, but the
132
+ * VENDOR_DYNAMIC_BASE default already carries the vendor segment — that
133
+ * trailing segment is dropped first so it is never doubled.
134
+ */
135
+ declare function withVendorBase(imports: Record<string, string>, base: string): Record<string, string>;
102
136
  //#endregion
103
137
  //#region connect-utils/types.d.ts
104
138
  type IConnectOptions = {
@@ -127,6 +161,16 @@ type IConnectOptions = {
127
161
  cliPackageRegistryUrl?: string;
128
162
  dynamicBase?: boolean;
129
163
  favicon?: string;
164
+ /**
165
+ * Production vendor: the prebuilt shared-dependency bundle's import map and
166
+ * version table (from `prebuildConnectVendor`). When set on a production
167
+ * build, the shared specifiers are externalized from the app bundle and
168
+ * merged into the page import map. Build input only.
169
+ */
170
+ vendor?: {
171
+ imports: Record<string, string>;
172
+ versions: Record<string, string>;
173
+ };
130
174
  };
131
175
  type ConnectCommonOptions = {
132
176
  base?: string;
@@ -315,6 +359,11 @@ declare const runtimeConfigSchema: {
315
359
  readonly description: "Studio mode. Enables builder-only capabilities: Connect loads the vetra package and exposes DocumentModel (and vetra spec types) as creatable documents. Forced on by `ph vetra` / `ph connect studio`; false by default.";
316
360
  readonly default: false;
317
361
  };
362
+ readonly workflowsEnabled: {
363
+ readonly type: "boolean";
364
+ readonly description: "Powerhouse workflows in Connect. When true the tab loads the @powerhousedao/workflow package (workflow + connection documents, their editors and Workflow Studio) and the reactor worker registers its document models. Connect's counterpart to the reactor-side `workflows.enabled` / PH_WORKFLOWS_ENABLED; independent of studioMode. False by default.";
365
+ readonly default: false;
366
+ };
318
367
  };
319
368
  };
320
369
  readonly ai: {
@@ -939,16 +988,6 @@ declare function getConnectHtmlTags(options?: {
939
988
  declare function getConnectBaseViteConfig(options: IConnectOptions): InlineConfig;
940
989
  //#endregion
941
990
  //#region connect-utils/vite-plugins/dynamic-base.d.ts
942
- /**
943
- * Placeholder base used when Connect is built in dynamic-base mode. The Vite
944
- * `base` option is set to this token; this plugin rewrites it in the emitted
945
- * output so the effective base is resolved at serve time from a global instead
946
- * of being baked at build time.
947
- *
948
- * Trailing slash matches `normalizeBasePath` output, so the token sits in the
949
- * same syntactic position as a concrete base would.
950
- */
951
- declare const DYNAMIC_BASE_PLACEHOLDER = "/__PH_DYNAMIC_BASE__/";
952
991
  /**
953
992
  * Rewrites the placeholder base in emitted JS chunks to a runtime expression so
954
993
  * one built `dist/connect` serves under any subpath. Rolldown-native: per-match
@@ -1018,5 +1057,11 @@ declare const THEME_BOOT_MARKER = "data-ph-theme-boot";
1018
1057
  */
1019
1058
  declare function connectThemeBootPlugin(): Plugin;
1020
1059
  //#endregion
1021
- export { BUILD_HASH_FILE, BuildHashInput, ConnectBuildOptions, ConnectCommonOptions, ConnectPreviewOptions, ConnectStudioOptions, DEFAULT_CONNECT_OUTDIR, DEFAULT_VENDOR_INCLUDE, DYNAMIC_BASE_PLACEHOLDER, EXTERNAL_PACKAGES_IMPORT, IConnectOptions, IMPORT_SCRIPT_FILE, LOCAL_PACKAGE_ID, PH_DIR_NAME, PhConfigPluginOptions, PrebuiltVendor, RUNTIME_CONFIG_SCHEMA_ID, RUNTIME_CONFIG_SCHEMA_URL, THEME_BOOT_MARKER, VENDOR_EXTERNAL, VENDOR_URL_PREFIX, VendorPrebuildOptions, ViteDevOptions, appendToHtmlHead, backupIndexHtml, buildHashFromBuildOptions, computeBuildHash, connectBuildHashPlugin, connectDynamicBasePlugin, connectThemeBootPlugin, copyConnect, ensureNodeVersion, escapeForRegExp, getConnectBaseViteConfig, getConnectHtmlTags, makeImportScriptFromPackages, phConfigPlugin, prebuildConnectVendor, prependToHtmlHead, readJsonFile, removeBase64EnvValues, resolveConnectBundle, resolveConnectPackageJson, resolveConnectPublicDir, resolvePackage, resolveViteConfigPath, runShellScriptPlugin, runTsc, runtimeConfigSchema, stripVersionFromPackage };
1060
+ //#region connect-utils/vite-plugins/vendor-import-map.d.ts
1061
+ type VendorImportMapOptions = {
1062
+ /** bare specifier -> URL (already base-prefixed by the caller). */imports: Record<string, string>;
1063
+ };
1064
+ declare function vendorImportMapPlugin(options: VendorImportMapOptions): Plugin;
1065
+ //#endregion
1066
+ export { BUILD_HASH_FILE, BuildHashInput, ConnectBuildOptions, ConnectCommonOptions, ConnectPreviewOptions, ConnectStudioOptions, DEFAULT_CONNECT_OUTDIR, DEFAULT_VENDOR_INCLUDE, DYNAMIC_BASE_PLACEHOLDER, EXTERNAL_PACKAGES_IMPORT, IConnectOptions, IMPORT_SCRIPT_FILE, LOCAL_PACKAGE_ID, PH_DIR_NAME, PhConfigPluginOptions, PrebuiltVendor, RUNTIME_CONFIG_SCHEMA_ID, RUNTIME_CONFIG_SCHEMA_URL, THEME_BOOT_MARKER, VENDOR_EXTERNAL, VENDOR_URL_PREFIX, VendorImportMapOptions, VendorPrebuildOptions, ViteDevOptions, appendToHtmlHead, backupIndexHtml, buildHashFromBuildOptions, computeBuildHash, connectBuildHashPlugin, connectDynamicBasePlugin, connectThemeBootPlugin, copyConnect, ensureNodeVersion, escapeForRegExp, getConnectBaseViteConfig, getConnectHtmlTags, makeImportScriptFromPackages, missingVendorEntries, phConfigPlugin, prebuildConnectVendor, prependToHtmlHead, readJsonFile, removeBase64EnvValues, resolveConnectBundle, resolveConnectPackageJson, resolveConnectPublicDir, resolvePackage, resolveViteConfigPath, runShellScriptPlugin, runTsc, runtimeConfigSchema, stripVersionFromPackage, vendorImportMapPlugin, withVendorBase };
1022
1067
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../connect-utils/constants.ts","../connect-utils/vite-plugins/build-hash.ts","../connect-utils/externalize-vendor.ts","../connect-utils/types.ts","../connect-utils/helpers.ts","../connect-utils/runtime-config-schema.ts","../connect-utils/vite-config.ts","../connect-utils/vite-plugins/dynamic-base.ts","../connect-utils/vite-plugins/ph-config.ts","../connect-utils/vite-plugins/theme-boot.ts"],"mappings":";;;;;cAAa,wBAAA;AAAA,cACA,kBAAA;AAAA,cACA,gBAAA;AAAA,cACA,WAAA;;;;cCGA,eAAA;AAAA,UAEI,cAAA;;EAEf,eAAA;EDVmC;ECYnC,gBAAA;EDZmC;;ECenC,qBAAA;EDd6B;ECgB7B,aAAA;EDhB6B;ECkB7B,QAAA;EDjBW;ECmBX,eAAA;;EAEA,cAAA;EDrB2B;ECuB3B,kBAAA;AAAA;;;;;;;AAnBF;;iBA8BgB,gBAAA,CAAiB,KAAA,EAAO,cAAA;AAAA,iBAyCxB,yBAAA,CAA0B,OAAA;EACxC,OAAA;EACA,QAAA;EACA,QAAA,EAAU,aAAA;IACR,WAAA;IACA,OAAA;IACA,QAAA;EAAA;EAEF,eAAA;EACA,cAAA;EACA,kBAAA;AAAA;;;;;AAnDF;;iBAyEgB,sBAAA,CA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCqBG,kBAAA,CACd,OAAA;EACE,WAAA;EACA,QAAA,GAAW,iBAAA;AAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiJC,wBAAA,CAAyB,OAAA,EAAS,eAAA,GAAe,YAAA;;;;;;;ANjMjE;;;;;cOYa,wBAAA;;;;;APVb;;;;;AACA;;;;;;;;ACGA;;;;;AAEA;;;;;;iBMsEgB,wBAAA,CACd,OAAA;EAAW,SAAA;EAAqB,iBAAA;AAAA,IAC/B,MAAA;AAAA,iBAuDa,eAAA,CAAgB,CAAA;;;KC3HpB,qBAAA;EACV,QAAA,EAAU,iBAAA;EACV,WAAA;EACA,OAAA,GAAU,sBAAA;;;;ARdZ;;;EQqBE,kBAAA;ERrB6B;AAC/B;;;;EQ0BE,kBAAA,GAAqB,sBAAA;AAAA;AAAA,iBAsBP,cAAA,CAAe,OAAA,EAAS,qBAAA,GAAwB,MAAA;;;;;;;ARlDhE;cSOa,iBAAA;;;;ATNb;;iBS6BgB,sBAAA,CAAA,GAA0B,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../connect-utils/constants.ts","../connect-utils/vite-plugins/build-hash.ts","../connect-utils/externalize-vendor.ts","../connect-utils/types.ts","../connect-utils/helpers.ts","../connect-utils/runtime-config-schema.ts","../connect-utils/vite-config.ts","../connect-utils/vite-plugins/dynamic-base.ts","../connect-utils/vite-plugins/ph-config.ts","../connect-utils/vite-plugins/theme-boot.ts","../connect-utils/vite-plugins/vendor-import-map.ts"],"mappings":";;;;;;cAAa,wBAAA;AAAA,cACA,kBAAA;AAAA,cACA,gBAAA;AAAA,cACA,WAAA;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gB,wBAAA,CACd,OAAA;EAAW,SAAA;EAAqB,iBAAA;AAAA,IAC/B,MAAA;AAAA,iBAuDa,eAAA,CAAgB,CAAA;;;KChIpB,qBAAA;EACV,QAAA,EAAU,iBAAA;EACV,WAAA;EACA,OAAA,GAAU,sBAAA;ERfyB;;;;AACrC;;EQqBE,kBAAA;ERrB6B;;AAC/B;;;EQ0BE,kBAAA,GAAqB,sBAAA;AAAA;AAAA,iBAsBP,cAAA,CAAe,OAAA,EAAS,qBAAA,GAAwB,MAAA;;;;;;;;cC3CnD,iBAAA;;;;;ATNb;iBS6BgB,sBAAA,CAAA,GAA0B,MAAA;;;KCnB9B,sBAAA;qEAEV,OAAA,EAAS,MAAA;AAAA;AAAA,iBA4BK,qBAAA,CAAsB,OAAA,EAAS,sBAAA,GAAyB,MAAA"}
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { createHash, randomUUID } from "node:crypto";
3
- import fs, { createReadStream, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import fs, { chmodSync, createReadStream, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
4
4
  import path, { dirname, extname, isAbsolute, join, resolve } from "node:path";
5
5
  import { exec, execSync, spawn } from "node:child_process";
6
6
  import { fileURLToPath } from "node:url";
7
+ import { DEFAULT_CONNECT_CONFIG, DYNAMIC_BASE_PLACEHOLDER, PWA_FILE_HANDLER_ACTION, buildRuntimeConfig, deepMerge, loadConnectEnv, mergeManifest, mergePwaConfig, normalizeBasePath, phConnectRuntimeConfigSchema, powerhousePackageSchema, setConnectEnv, unionStrings, withInferredCategory } from "@powerhousedao/shared/connect";
7
8
  import MagicString from "magic-string";
8
9
  import { readFile, writeFile } from "node:fs/promises";
9
10
  import { cwd } from "node:process";
10
- import { DEFAULT_CONNECT_CONFIG, PWA_FILE_HANDLER_ACTION, buildRuntimeConfig, deepMerge, loadConnectEnv, mergeManifest, mergePwaConfig, normalizeBasePath, phConnectRuntimeConfigSchema, powerhousePackageSchema, setConnectEnv, unionStrings, withInferredCategory } from "@powerhousedao/shared/connect";
11
11
  import { getConfig } from "@powerhousedao/config/node";
12
12
  import tailwind from "@tailwindcss/vite";
13
13
  import react from "@vitejs/plugin-react";
@@ -91,16 +91,6 @@ function connectBuildHashPlugin(buildHash) {
91
91
  //#endregion
92
92
  //#region connect-utils/vite-plugins/dynamic-base.ts
93
93
  /**
94
- * Placeholder base used when Connect is built in dynamic-base mode. The Vite
95
- * `base` option is set to this token; this plugin rewrites it in the emitted
96
- * output so the effective base is resolved at serve time from a global instead
97
- * of being baked at build time.
98
- *
99
- * Trailing slash matches `normalizeBasePath` output, so the token sits in the
100
- * same syntactic position as a concrete base would.
101
- */
102
- const DYNAMIC_BASE_PLACEHOLDER = "/__PH_DYNAMIC_BASE__/";
103
- /**
104
94
  * Global the runtime (ph-clint proxy) must set before the entry bundle loads.
105
95
  * Value is the normalized deploy base, e.g. "/myagent/" or "/". The JS rewrite
106
96
  * below resolves all asset / lazy-chunk / BASE_URL references against it.
@@ -144,7 +134,7 @@ function connectDynamicBasePlugin(options = {}) {
144
134
  name: "ph-connect-dynamic-base",
145
135
  enforce: "post",
146
136
  renderChunk(code, chunk) {
147
- if (!code.includes("/__PH_DYNAMIC_BASE__/")) return null;
137
+ if (!code.includes(DYNAMIC_BASE_PLACEHOLDER)) return null;
148
138
  const s = new MagicString(code);
149
139
  for (const match of code.matchAll(PLACEHOLDER_LITERAL)) {
150
140
  const rest = match[2];
@@ -161,7 +151,7 @@ function connectDynamicBasePlugin(options = {}) {
161
151
  };
162
152
  },
163
153
  generateBundle(_options, bundle) {
164
- for (const file of Object.values(bundle)) if ((file.type === "chunk" ? file.code : file.fileName.endsWith(".css") && typeof file.source === "string" ? file.source : void 0)?.includes("/__PH_DYNAMIC_BASE__/")) this.error(`dynamic-base: unrewritten placeholder ${DYNAMIC_BASE_PLACEHOLDER} remains in ${file.fileName}`);
154
+ for (const file of Object.values(bundle)) if ((file.type === "chunk" ? file.code : file.fileName.endsWith(".css") && typeof file.source === "string" ? file.source : void 0)?.includes(DYNAMIC_BASE_PLACEHOLDER)) this.error(`dynamic-base: unrewritten placeholder ${DYNAMIC_BASE_PLACEHOLDER} remains in ${file.fileName}`);
165
155
  }
166
156
  };
167
157
  }
@@ -241,31 +231,34 @@ async function prebuildConnectVendor(options) {
241
231
  const vendorDir = options.vendorDir ?? join(options.dirname, "node_modules/.ph-vendor");
242
232
  const importMapPath = join(vendorDir, "import-map.json");
243
233
  const versionDigest = resolveVersionDigest(options.dirname, [...include, ...external]);
234
+ const versions = resolveDepVersions(options.dirname, [...include, ...external]);
235
+ const base = options.base ?? VENDOR_DYNAMIC_BASE;
236
+ const nodeEnv = options.nodeEnv ?? "development";
244
237
  try {
245
238
  const hit = readCacheHit(importMapPath, include, external, versionDigest);
246
239
  if (hit) return {
247
240
  vendorDir,
248
- imports: hit
241
+ ...hit
249
242
  };
250
243
  const lockDir = `${vendorDir}.lock`;
251
244
  const lock = acquireLock(lockDir);
252
245
  if (!lock) {
253
- const imports = await waitForCacheHit(importMapPath, include, external, versionDigest, lockDir);
254
- return imports ? {
246
+ const hit = await waitForCacheHit(importMapPath, include, external, versionDigest, lockDir);
247
+ return hit ? {
255
248
  vendorDir,
256
- imports
249
+ ...hit
257
250
  } : null;
258
251
  }
259
252
  try {
260
253
  const raced = readCacheHit(importMapPath, include, external, versionDigest);
261
254
  if (raced) return {
262
255
  vendorDir,
263
- imports: raced
256
+ ...raced
264
257
  };
265
- const imports = await buildVendorAtomic(options.dirname, vendorDir, include, external, versionDigest);
266
- return imports ? {
258
+ const result = await buildVendorAtomic(options.dirname, vendorDir, include, external, versionDigest, versions, base, nodeEnv);
259
+ return result ? {
267
260
  vendorDir,
268
- imports
261
+ ...result
269
262
  } : null;
270
263
  } finally {
271
264
  releaseLock(lock);
@@ -279,27 +272,72 @@ function readCacheHit(importMapPath, include, external, versionDigest) {
279
272
  if (!existsSync(importMapPath)) return null;
280
273
  try {
281
274
  const cached = JSON.parse(readFileSync(importMapPath, "utf8"));
282
- if (sameSet(cached.include, include) && sameSet(cached.external, external) && cached.versionDigest === versionDigest) return cached.imports;
275
+ if (sameSet(cached.include, include) && sameSet(cached.external, external) && cached.versionDigest === versionDigest) return {
276
+ imports: cached.imports,
277
+ versions: cached.versions ?? {}
278
+ };
283
279
  } catch {}
284
280
  return null;
285
281
  }
286
- function resolveVersionDigest(dirname, specs) {
287
- const seen = /* @__PURE__ */ new Map();
282
+ /**
283
+ * Resolve the installed version of each spec's owning package, deduped by
284
+ * package name. Resolution order per spec:
285
+ * 1. the project itself, when it IS the owning package (a self-vendoring
286
+ * app has no node_modules self-link);
287
+ * 2. the project's own node_modules link (works for pnpm-strict and
288
+ * hoisted layouts alike, and — unlike `require.resolve` — for
289
+ * ESM-only packages whose exports map has no CJS condition);
290
+ * 3. Node's own module resolution (covers transitive installs), walking
291
+ * the entry up to the owning package's package.json.
292
+ * Unresolvable specs contribute a "missing" sentinel, unknown versions
293
+ * "unknown".
294
+ */
295
+ function resolveDepVersions(dirname$2, specs) {
296
+ const req = createRequire(join(dirname$2, "noop.js"));
297
+ const seen = {};
298
+ let selfMeta = null;
288
299
  for (const spec of specs) {
289
300
  const { pkg } = parsePkg(spec);
290
- if (seen.has(pkg)) continue;
291
- let version = "missing";
292
- try {
293
- const pkgRoot = realpathSync(join(dirname, "node_modules", pkg));
294
- const meta = JSON.parse(readFileSync(join(pkgRoot, "package.json"), "utf8"));
295
- version = String(meta.version ?? "unknown");
296
- } catch {}
297
- seen.set(pkg, version);
301
+ if (pkg in seen) continue;
302
+ if (selfMeta === null) try {
303
+ selfMeta = JSON.parse(readFileSync(join(dirname$2, "package.json"), "utf8"));
304
+ } catch {
305
+ selfMeta = {};
306
+ }
307
+ let version;
308
+ if (typeof selfMeta.name === "string" && selfMeta.name === pkg && typeof selfMeta.version === "string") version = selfMeta.version;
309
+ else {
310
+ version = "missing";
311
+ try {
312
+ const pkgRoot = realpathSync(join(dirname$2, "node_modules", pkg));
313
+ const meta = JSON.parse(readFileSync(join(pkgRoot, "package.json"), "utf8"));
314
+ version = String(meta.version ?? "unknown");
315
+ } catch {
316
+ try {
317
+ let dir = dirname(req.resolve(spec));
318
+ for (let depth = 0; depth < 8; depth++) {
319
+ if (existsSync(join(dir, "package.json"))) {
320
+ const meta = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
321
+ version = String(meta.version ?? "unknown");
322
+ break;
323
+ }
324
+ const parent = dirname(dir);
325
+ if (parent === dir) break;
326
+ dir = parent;
327
+ }
328
+ } catch {}
329
+ }
330
+ }
331
+ seen[pkg] = version;
298
332
  }
333
+ return seen;
334
+ }
335
+ function resolveVersionDigest(dirname, specs) {
336
+ const versions = resolveDepVersions(dirname, specs);
299
337
  const h = createHash("sha256");
300
338
  const workerHash = createHash("sha256").update(VENDOR_BUILD_WORKER).digest("hex");
301
339
  h.update(`worker:${workerHash}\n`);
302
- for (const pkg of [...seen.keys()].sort()) h.update(`${pkg}@${seen.get(pkg)}\n`);
340
+ for (const pkg of Object.keys(versions).sort()) h.update(`${pkg}@${versions[pkg]}\n`);
303
341
  return h.digest("hex").slice(0, 16);
304
342
  }
305
343
  function sameSet(a, b) {
@@ -406,11 +444,16 @@ function parsePkg(spec) {
406
444
  * `@powerhousedao/design-system/connect/toast`, `zod/v4/core`). Those bare
407
445
  * imports need their own import-map entry, so expand each listed spec to its
408
446
  * package's concrete (non-wildcard, JS) subpath exports that share the spec's
409
- * prefix. Unresolvable / CSS / JSON targets are skipped. Failures leave the
410
- * original spec untouched.
447
+ * prefix. Unresolvable / CSS / JSON targets are skipped.
448
+ *
449
+ * A spec whose package isn't installed in `dirname` is dropped entirely
450
+ * rather than kept for the worker: the worker cannot build an entry for a
451
+ * missing package (its `await import` and the vite resolution both fail),
452
+ * and a bare re-export entry would fail the whole vendor build. The
453
+ * importer of a missing shared dep simply bundles its own copy.
411
454
  */
412
455
  function expandIncludeSubpaths(dirname, include) {
413
- const out = new Set(include);
456
+ const out = /* @__PURE__ */ new Set();
414
457
  for (const spec of include) {
415
458
  const { pkg, sub } = parsePkg(spec);
416
459
  let exp;
@@ -421,6 +464,7 @@ function expandIncludeSubpaths(dirname, include) {
421
464
  } catch {
422
465
  continue;
423
466
  }
467
+ out.add(sub ? spec : pkg);
424
468
  if (!exp || typeof exp !== "object") continue;
425
469
  const expMap = exp;
426
470
  const prefixKey = sub ? `./${sub}` : ".";
@@ -437,34 +481,71 @@ function expandIncludeSubpaths(dirname, include) {
437
481
  return [...out];
438
482
  }
439
483
  /**
484
+ * The published specifiers whose entry file the vendor build never emitted.
485
+ * URLs are base-less (`/__vendor__/x.js`) and resolve inside `vendorDir`.
486
+ */
487
+ function missingVendorEntries(vendorDir, imports) {
488
+ const prefix = VENDOR_URL_PREFIX;
489
+ return Object.entries(imports).filter(([, url]) => {
490
+ return !existsSync(join(vendorDir, url.startsWith(prefix) ? url.slice(12) : url));
491
+ }).map(([spec, url]) => ({
492
+ spec,
493
+ url
494
+ }));
495
+ }
496
+ /**
497
+ * Rebase the vendor's base-less entry URLs (`/__vendor__/x.js`) onto the
498
+ * deploy base, so a consumer that resolves them against the page origin lands
499
+ * under that base rather than the server root. A dynamic-base build keeps its
500
+ * placeholder, which the runtime substitutes.
501
+ *
502
+ * `base` is the app base from `prebuildConnectVendor` callers, but the
503
+ * VENDOR_DYNAMIC_BASE default already carries the vendor segment — that
504
+ * trailing segment is dropped first so it is never doubled.
505
+ */
506
+ function withVendorBase(imports, base) {
507
+ const segment = VENDOR_URL_PREFIX.replace(/^\/+/, "");
508
+ const appBase = base.endsWith(segment) ? base.slice(0, base.length - segment.length) : base;
509
+ return Object.fromEntries(Object.entries(imports).map(([spec, url]) => [spec, `${appBase}/${url}`.replace(/([^:])\/{2,}/g, "$1/").replace(/^\/{2,}/, "/")]));
510
+ }
511
+ /**
440
512
  * Build the vendor into a unique temp dir, then atomically swap it into place,
441
513
  * so a concurrent reader never sees a partial bundle or import-map.json. Runs
442
514
  * the build in a throwaway subprocess (its peak memory is reclaimed on exit);
443
- * the parent augments the import map with the version digest and does the swap.
444
- * Returns the published import map, or null on failure.
515
+ * the parent augments the import map with the version digest + the version
516
+ * table, writes the runtime shared-deps module, and does the swap.
517
+ * Returns the published import map + versions, or null on failure.
445
518
  */
446
- async function buildVendorAtomic(dirname$2, vendorDir, include, external, versionDigest) {
519
+ async function buildVendorAtomic(dirname$3, vendorDir, include, external, versionDigest, versions, base, nodeEnv) {
447
520
  const parent = dirname(vendorDir);
448
521
  mkdirSync(parent, { recursive: true });
449
522
  const tmpDir = mkdtempSync(join(parent, ".ph-vendor.tmp-"));
450
523
  try {
451
- const { ok, stderr } = await runBuildWorker(dirname$2, tmpDir, include, external);
524
+ const { ok, stderr } = await runBuildWorker(dirname$3, tmpDir, include, external, base, nodeEnv);
452
525
  const tmpMap = join(tmpDir, "import-map.json");
453
526
  if (!ok || !existsSync(tmpMap)) {
454
527
  const detail = stderr.trim();
455
528
  throw new Error(`vendor build failed${detail ? `:\n${detail}` : " (no output captured)"}`);
456
529
  }
457
530
  const meta = JSON.parse(readFileSync(tmpMap, "utf8"));
531
+ const unbacked = missingVendorEntries(tmpDir, meta.imports);
532
+ if (unbacked.length > 0) throw new Error(`vendor build published ${unbacked.length} import-map ${unbacked.length === 1 ? "entry" : "entries"} with no file behind ${unbacked.length === 1 ? "it" : "them"}:\n` + unbacked.map((e) => ` ${e.spec} -> ${e.url}`).join("\n"));
458
533
  meta.versionDigest = versionDigest;
534
+ meta.versions = versions;
459
535
  writeFileSync(tmpMap, JSON.stringify(meta, null, 2));
536
+ writeFileSync(join(tmpDir, "shared-deps.js"), `export const imports = ${JSON.stringify(withVendorBase(meta.imports, base))};\nexport const versions = ${JSON.stringify(versions)};\n`);
460
537
  const oldDir = `${vendorDir}.old-${process.pid}-${Date.now()}`;
461
538
  if (existsSync(vendorDir)) renameSync(vendorDir, oldDir);
462
539
  renameSync(tmpDir, vendorDir);
540
+ chmodSync(vendorDir, 493);
463
541
  rmSync(oldDir, {
464
542
  recursive: true,
465
543
  force: true
466
544
  });
467
- return meta.imports;
545
+ return {
546
+ imports: meta.imports,
547
+ versions
548
+ };
468
549
  } catch (err) {
469
550
  rmSync(tmpDir, {
470
551
  recursive: true,
@@ -473,16 +554,29 @@ async function buildVendorAtomic(dirname$2, vendorDir, include, external, versio
473
554
  throw err;
474
555
  }
475
556
  }
557
+ function resolveSelfModulePath() {
558
+ const selfPath = fileURLToPath(import.meta.url);
559
+ if (!selfPath.endsWith(".ts")) return selfPath;
560
+ let dir = dirname(selfPath);
561
+ for (let depth = 0; depth < 4; depth++) {
562
+ const candidate = join(dir, "dist", "index.mjs");
563
+ if (existsSync(candidate)) return candidate;
564
+ const parent = dirname(dir);
565
+ if (parent === dir) break;
566
+ dir = parent;
567
+ }
568
+ throw new Error("vendor build needs the built builder-tools bundle (dist/index.mjs); build the package first");
569
+ }
476
570
  /**
477
571
  * Spawn a throwaway worker that generates one entry per specifier (CJS deps get
478
572
  * explicit named re-exports, ESM deps `export *`), `vite build`s them into the
479
573
  * given out dir, and writes the import map. Captures stdout/stderr so a failure
480
574
  * is debuggable; the normal path stays quiet.
481
575
  */
482
- function runBuildWorker(dirname, outDir, include, external) {
576
+ function runBuildWorker(dirname, outDir, include, external, base, nodeEnv) {
483
577
  const workerPath = join(outDir, "build-worker.mjs");
484
578
  writeFileSync(workerPath, VENDOR_BUILD_WORKER);
485
- const selfModulePath = fileURLToPath(import.meta.url);
579
+ const selfModulePath = resolveSelfModulePath();
486
580
  return new Promise((resolve) => {
487
581
  const child = spawn(process.execPath, [
488
582
  workerPath,
@@ -492,7 +586,9 @@ function runBuildWorker(dirname, outDir, include, external) {
492
586
  VENDOR_URL_PREFIX,
493
587
  JSON.stringify(external),
494
588
  VENDOR_DYNAMIC_BASE,
495
- selfModulePath
589
+ selfModulePath,
590
+ base,
591
+ nodeEnv
496
592
  ], {
497
593
  cwd: dirname,
498
594
  stdio: [
@@ -522,14 +618,22 @@ function runBuildWorker(dirname, outDir, include, external) {
522
618
  * The vendor build worker, written to disk and run as a subprocess. Loads
523
619
  * `vite` from the project and `connectDynamicBasePlugin` from builder-tools' own
524
620
  * built bundle (selfModulePath). argv: dirname, vendorDir, includeJSON,
525
- * urlPrefix, externalJSON, dynamicBase, selfModulePath.
621
+ * urlPrefix, externalJSON, dynamicBase, selfModulePath, base (app base),
622
+ * nodeEnv.
526
623
  */
527
624
  const VENDOR_BUILD_WORKER = `
528
625
  import { createRequire } from 'node:module';
529
626
  import { mkdirSync, writeFileSync, rmSync } from 'node:fs';
530
627
  import { join, isAbsolute } from 'node:path';
531
628
  import { fileURLToPath, pathToFileURL } from 'node:url';
532
- const [dirname, vendorDir, includeJSON, urlPrefix, externalJSON, dynamicBase, selfModulePath] = process.argv.slice(2);
629
+ const [dirname, vendorDir, includeJSON, urlPrefix, externalJSON, dynamicBase, selfModulePath, baseArg, nodeEnvArg] = process.argv.slice(2);
630
+ // Trailing argv are optional (older callers): base defaults to the dynamic
631
+ // placeholder behavior, nodeEnv to development. baseArg is the APP base —
632
+ // the same string the app build uses; the build base appends the vendor
633
+ // segment so emitted asset URLs land under <app-base>__vendor__/.
634
+ const segment = urlPrefix.replace(/^\\/+/, '');
635
+ const base = baseArg ? baseArg + segment : dynamicBase;
636
+ const nodeEnv = nodeEnvArg ?? 'development';
533
637
  const include = JSON.parse(includeJSON);
534
638
  const external = JSON.parse(externalJSON ?? '[]');
535
639
  const externalSet = new Set(external);
@@ -602,14 +706,17 @@ const phVendorResolve = {
602
706
  };
603
707
  await build({
604
708
  root: dirname, configFile: false, logLevel: 'error',
605
- // Dynamic-base placeholder + vendor segment: connectDynamicBasePlugin rewrites
606
- // emitted chunk/asset URLs to resolve against the deploy base at serve time.
607
- base: dynamicBase,
709
+ // Caller-provided build base (or the dynamic placeholder default):
710
+ // connectDynamicBasePlugin rewrites emitted chunk/asset URLs to resolve
711
+ // against the deploy base at serve time.
712
+ base,
608
713
  define: {
609
- 'process.env.NODE_ENV': '"development"',
714
+ 'process.env.NODE_ENV': JSON.stringify(nodeEnv),
610
715
  // BASE_URL resolves to the deploy base (not the vendor prefix) so vendored
611
716
  // Connect's router basename + BASE_URL-relative fetches use the right path.
612
- 'import.meta.env.BASE_URL': JSON.stringify(DYNAMIC_BASE_PLACEHOLDER),
717
+ // The app base when provided (concrete or placeholder), the placeholder
718
+ // otherwise (dev flow — rewritten at serve time by the dynamic-base plugin).
719
+ 'import.meta.env.BASE_URL': JSON.stringify(baseArg ?? DYNAMIC_BASE_PLACEHOLDER),
613
720
  },
614
721
  // phVendorResolve (pre) resolves bares from the worker; esmExternalRequirePlugin owns
615
722
  // react/virtual externalization; connectDynamicBasePlugin (post) rewrites the placeholder base.
@@ -618,7 +725,9 @@ await build({
618
725
  // segment so the worker recovers the deploy base, not the vendor prefix.
619
726
  worker: { format: 'es', plugins: () => [connectDynamicBasePlugin({ forWorker: true, workerStripPrefix: urlPrefix.replace(/^\\/+/, '') })] },
620
727
  build: {
621
- outDir: vendorDir, emptyOutDir: false, minify: false, target: 'esnext', cssCodeSplit: true,
728
+ // Production ships this to every visitor, so minify it like the app's own
729
+ // chunks; dev keeps readable output and the faster build.
730
+ outDir: vendorDir, emptyOutDir: false, minify: nodeEnv === 'production', target: 'esnext', cssCodeSplit: true,
622
731
  rollupOptions: {
623
732
  input, preserveEntrySignatures: 'strict',
624
733
  output: { format: 'es', entryFileNames: '[name].js', chunkFileNames: 'chunks/[name]-[hash].js', assetFileNames: 'assets/[name]-[hash][extname]' },
@@ -1776,6 +1885,48 @@ function connectThemeBootPlugin() {
1776
1885
  };
1777
1886
  }
1778
1887
  //#endregion
1888
+ //#region connect-utils/vite-plugins/vendor-import-map.ts
1889
+ function extractImports(raw) {
1890
+ if (typeof raw !== "object" || raw === null) return {};
1891
+ const imports = "imports" in raw ? raw.imports : void 0;
1892
+ if (typeof imports !== "object" || imports === null) return {};
1893
+ const out = {};
1894
+ for (const [key, value] of Object.entries(imports)) if (typeof value === "string") out[key] = value;
1895
+ return out;
1896
+ }
1897
+ function parseImportMap(raw) {
1898
+ try {
1899
+ return extractImports(JSON.parse(raw));
1900
+ } catch {
1901
+ return {};
1902
+ }
1903
+ }
1904
+ const INLINE_IMPORTMAP = /<script type="importmap">([\s\S]*?)<\/script>/;
1905
+ function vendorImportMapPlugin(options) {
1906
+ const vendorEntries = Object.keys(options.imports).length;
1907
+ return {
1908
+ name: "ph-vendor-import-map",
1909
+ apply: "build",
1910
+ transformIndexHtml(html) {
1911
+ if (!vendorEntries) return;
1912
+ const match = INLINE_IMPORTMAP.exec(html);
1913
+ if (match) {
1914
+ const merged = { imports: {
1915
+ ...parseImportMap(match[1]),
1916
+ ...options.imports
1917
+ } };
1918
+ return html.replace(INLINE_IMPORTMAP, `<script type="importmap">${JSON.stringify(merged)}<\/script>`);
1919
+ }
1920
+ return [{
1921
+ tag: "script",
1922
+ attrs: { type: "importmap" },
1923
+ children: JSON.stringify({ imports: options.imports }),
1924
+ injectTo: "head-prepend"
1925
+ }];
1926
+ }
1927
+ };
1928
+ }
1929
+ //#endregion
1779
1930
  //#region connect-utils/vite-config.ts
1780
1931
  function getConnectHtmlTags(options = {}) {
1781
1932
  const { registryUrl, injectTo = "head" } = options;
@@ -2032,11 +2183,12 @@ function getConnectBaseViteConfig(options) {
2032
2183
  }),
2033
2184
  devReactImportmapPlugin(options.dirname),
2034
2185
  ...plugins,
2035
- esmExternalRequirePlugin({ external: reactExternal }),
2186
+ esmExternalRequirePlugin({ external: [...reactExternal, ...options.vendor && mode === "production" ? Object.keys(options.vendor.imports) : []] }),
2036
2187
  reactSelfHostPlugin({
2037
2188
  dirname: options.dirname,
2038
2189
  dev: mode !== "production" || isDebug
2039
2190
  }),
2191
+ ...options.vendor && mode === "production" ? [vendorImportMapPlugin({ imports: options.vendor.imports })] : [],
2040
2192
  connectFaviconPlugin({ faviconPath: options.favicon }),
2041
2193
  connectThemeBootPlugin(),
2042
2194
  connectBuildHashPlugin(buildHash),
@@ -2051,6 +2203,6 @@ function getConnectBaseViteConfig(options) {
2051
2203
  };
2052
2204
  }
2053
2205
  //#endregion
2054
- export { BUILD_HASH_FILE, DEFAULT_CONNECT_OUTDIR, DEFAULT_VENDOR_INCLUDE, DYNAMIC_BASE_PLACEHOLDER, EXTERNAL_PACKAGES_IMPORT, IMPORT_SCRIPT_FILE, LOCAL_PACKAGE_ID, PH_DIR_NAME, RUNTIME_CONFIG_SCHEMA_ID, RUNTIME_CONFIG_SCHEMA_URL, THEME_BOOT_MARKER, VENDOR_EXTERNAL, VENDOR_URL_PREFIX, appendToHtmlHead, backupIndexHtml, buildHashFromBuildOptions, computeBuildHash, connectBuildHashPlugin, connectDynamicBasePlugin, connectThemeBootPlugin, copyConnect, ensureNodeVersion, escapeForRegExp, getConnectBaseViteConfig, getConnectHtmlTags, makeImportScriptFromPackages, phConfigPlugin, prebuildConnectVendor, prependToHtmlHead, readJsonFile, removeBase64EnvValues, resolveConnectBundle, resolveConnectPackageJson, resolveConnectPublicDir, resolvePackage, resolveViteConfigPath, runShellScriptPlugin, runTsc, runtimeConfigSchema, stripVersionFromPackage };
2206
+ export { BUILD_HASH_FILE, DEFAULT_CONNECT_OUTDIR, DEFAULT_VENDOR_INCLUDE, DYNAMIC_BASE_PLACEHOLDER, EXTERNAL_PACKAGES_IMPORT, IMPORT_SCRIPT_FILE, LOCAL_PACKAGE_ID, PH_DIR_NAME, RUNTIME_CONFIG_SCHEMA_ID, RUNTIME_CONFIG_SCHEMA_URL, THEME_BOOT_MARKER, VENDOR_EXTERNAL, VENDOR_URL_PREFIX, appendToHtmlHead, backupIndexHtml, buildHashFromBuildOptions, computeBuildHash, connectBuildHashPlugin, connectDynamicBasePlugin, connectThemeBootPlugin, copyConnect, ensureNodeVersion, escapeForRegExp, getConnectBaseViteConfig, getConnectHtmlTags, makeImportScriptFromPackages, missingVendorEntries, phConfigPlugin, prebuildConnectVendor, prependToHtmlHead, readJsonFile, removeBase64EnvValues, resolveConnectBundle, resolveConnectPackageJson, resolveConnectPublicDir, resolvePackage, resolveViteConfigPath, runShellScriptPlugin, runTsc, runtimeConfigSchema, stripVersionFromPackage, vendorImportMapPlugin, withVendorBase };
2055
2207
 
2056
2208
  //# sourceMappingURL=index.mjs.map