@ethisyscore/vite-plugin 1.74.0 → 1.76.0

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.cts CHANGED
@@ -468,6 +468,8 @@ interface BuildPlatformReactPagesOptions {
468
468
  external?: readonly string[];
469
469
  /** Module specifier the generated entry imports `definePluginPage` from. */
470
470
  definePluginPageSpecifier?: string;
471
+ /** Module specifier the generated overlay entry imports `definePluginOverlay` from. */
472
+ definePluginOverlaySpecifier?: string;
471
473
  /** Source dir stripped when rewriting manifest paths to the alias. Default `src`. */
472
474
  srcDir?: string;
473
475
  /** Alias prefix manifest `src/…` paths are rewritten to. Default `@` (→ `@/…`). */
@@ -491,18 +493,24 @@ interface BuildPlatformReactPagesOptions {
491
493
  /** Injectable file writer. Default `fs.writeFileSync` (creating dirs). */
492
494
  writeFile?: (path: string, contents: string) => void;
493
495
  }
496
+ /** One built surface (a page, or the singular overlay) as recorded in the companion summary. */
497
+ interface PlatformReactSurfaceSummary {
498
+ id: string;
499
+ exportName: string;
500
+ title: string | null;
501
+ bundlePath: string;
502
+ source: string;
503
+ }
504
+ /** One emitted bundle's SHA-256, keyed by its dist-relative path. */
505
+ interface PlatformReactDigest {
506
+ path: string;
507
+ sha256: string;
508
+ }
494
509
  interface PlatformReactBuildSummary {
495
- pages: Array<{
496
- id: string;
497
- exportName: string;
498
- title: string | null;
499
- bundlePath: string;
500
- source: string;
501
- }>;
502
- digests: Array<{
503
- path: string;
504
- sha256: string;
505
- }>;
510
+ pages: PlatformReactSurfaceSummary[];
511
+ /** The singular overlay, when the manifest declares `ui.platformReactOverlay`. */
512
+ overlay?: PlatformReactSurfaceSummary;
513
+ digests: PlatformReactDigest[];
506
514
  summaryPath: string | null;
507
515
  digestMapPath: string | null;
508
516
  }
package/dist/index.d.ts CHANGED
@@ -468,6 +468,8 @@ interface BuildPlatformReactPagesOptions {
468
468
  external?: readonly string[];
469
469
  /** Module specifier the generated entry imports `definePluginPage` from. */
470
470
  definePluginPageSpecifier?: string;
471
+ /** Module specifier the generated overlay entry imports `definePluginOverlay` from. */
472
+ definePluginOverlaySpecifier?: string;
471
473
  /** Source dir stripped when rewriting manifest paths to the alias. Default `src`. */
472
474
  srcDir?: string;
473
475
  /** Alias prefix manifest `src/…` paths are rewritten to. Default `@` (→ `@/…`). */
@@ -491,18 +493,24 @@ interface BuildPlatformReactPagesOptions {
491
493
  /** Injectable file writer. Default `fs.writeFileSync` (creating dirs). */
492
494
  writeFile?: (path: string, contents: string) => void;
493
495
  }
496
+ /** One built surface (a page, or the singular overlay) as recorded in the companion summary. */
497
+ interface PlatformReactSurfaceSummary {
498
+ id: string;
499
+ exportName: string;
500
+ title: string | null;
501
+ bundlePath: string;
502
+ source: string;
503
+ }
504
+ /** One emitted bundle's SHA-256, keyed by its dist-relative path. */
505
+ interface PlatformReactDigest {
506
+ path: string;
507
+ sha256: string;
508
+ }
494
509
  interface PlatformReactBuildSummary {
495
- pages: Array<{
496
- id: string;
497
- exportName: string;
498
- title: string | null;
499
- bundlePath: string;
500
- source: string;
501
- }>;
502
- digests: Array<{
503
- path: string;
504
- sha256: string;
505
- }>;
510
+ pages: PlatformReactSurfaceSummary[];
511
+ /** The singular overlay, when the manifest declares `ui.platformReactOverlay`. */
512
+ overlay?: PlatformReactSurfaceSummary;
513
+ digests: PlatformReactDigest[];
506
514
  summaryPath: string | null;
507
515
  digestMapPath: string | null;
508
516
  }
package/dist/index.js CHANGED
@@ -948,6 +948,7 @@ var PLATFORM_REACT_DEDUPE = [
948
948
  var DEFAULT_OUT_DIR = "dist";
949
949
  var DEFAULT_OUTPUT_PREFIX = "platform-react";
950
950
  var DEFAULT_DEFINE_PLUGIN_PAGE = "@/app/definePluginPage";
951
+ var DEFAULT_DEFINE_PLUGIN_OVERLAY = "@/app/definePluginOverlay";
951
952
  var DEFAULT_SRC_DIR = "src";
952
953
  var DEFAULT_ALIAS_PREFIX = "@";
953
954
  var SUMMARY_FILENAME = "platform-react-pages.json";
@@ -996,6 +997,31 @@ export default definePluginPage(Page, { ${names.join(", ")} });
996
997
  }
997
998
  };
998
999
  }
1000
+ function virtualOverlayEntry(overlay, config) {
1001
+ const VIRTUAL_ID = `\0virtual:surface/${overlay.id}`;
1002
+ const views = overlay.views ?? {};
1003
+ const names = Object.keys(views);
1004
+ const viewImports = names.map((n) => `import { ${n} } from ${JSON.stringify(config.toAlias(views[n]))};`).join("\n");
1005
+ const exportName = typeof overlay.exportName === "string" && overlay.exportName.length > 0 ? overlay.exportName : "default";
1006
+ const overlayModule = JSON.stringify(config.toAlias(overlay.moduleSpecifier));
1007
+ const overlayImport = exportName === "default" ? `import Overlay from ${overlayModule};` : `import { ${exportName} as Overlay } from ${overlayModule};`;
1008
+ const overlayExport = exportName === "default" ? `export default definePluginOverlay(Overlay, { ${names.join(", ")} });` : `const __ehxOverlay = definePluginOverlay(Overlay, { ${names.join(", ")} });
1009
+ export { __ehxOverlay as ${exportName} };
1010
+ export default __ehxOverlay;`;
1011
+ const src = `${overlayImport}
1012
+ ${viewImports}
1013
+ import { definePluginOverlay } from ${JSON.stringify(config.definePluginOverlaySpecifier)};
1014
+ ${overlayExport}
1015
+ `;
1016
+ return {
1017
+ id: VIRTUAL_ID,
1018
+ plugin: {
1019
+ name: `virtual-surface-${overlay.id}`,
1020
+ resolveId: (id) => id === VIRTUAL_ID ? VIRTUAL_ID : null,
1021
+ load: (id) => id === VIRTUAL_ID ? src : null
1022
+ }
1023
+ };
1024
+ }
999
1025
  function defaultWriteFile(path, contents) {
1000
1026
  mkdirSync(dirname(path), { recursive: true });
1001
1027
  writeFileSync(path, contents);
@@ -1066,13 +1092,19 @@ async function buildPlatformReactPages(options = {}) {
1066
1092
  const root = options.root ?? process.cwd();
1067
1093
  const logger = options.logger ?? console;
1068
1094
  const manifest = readManifest(options, root);
1069
- const declared = manifest?.ui?.platformReactPages;
1070
- if (!Array.isArray(declared) || declared.length === 0) {
1071
- logger.warn("[build-pages] no platformReactPages declared \u2014 nothing to build");
1095
+ const ui = manifest?.ui;
1096
+ const declared = ui?.platformReactPages;
1097
+ const overlayDecl = ui?.platformReactOverlay;
1098
+ const hasPages = Array.isArray(declared) && declared.length > 0;
1099
+ const hasOverlay = overlayDecl !== void 0 && overlayDecl !== null;
1100
+ if (!hasPages && !hasOverlay) {
1101
+ logger.warn(
1102
+ "[build-pages] no platformReactPages or platformReactOverlay declared \u2014 nothing to build"
1103
+ );
1072
1104
  return { pages: [], digests: [], summaryPath: null, digestMapPath: null };
1073
1105
  }
1074
1106
  const seen = /* @__PURE__ */ new Set();
1075
- const pages = declared.map((raw, i) => {
1107
+ const pages = (hasPages ? declared : []).map((raw, i) => {
1076
1108
  const decl = raw;
1077
1109
  if (typeof decl?.id !== "string" || decl.id.length === 0) {
1078
1110
  throw new Error(`[build-pages] ui.platformReactPages[${i}].id is required (non-empty string).`);
@@ -1086,6 +1118,22 @@ async function buildPlatformReactPages(options = {}) {
1086
1118
  }
1087
1119
  return decl;
1088
1120
  });
1121
+ let overlay = null;
1122
+ if (hasOverlay) {
1123
+ const decl = overlayDecl;
1124
+ if (typeof decl?.id !== "string" || decl.id.length === 0) {
1125
+ throw new Error(`[build-pages] ui.platformReactOverlay.id is required (non-empty string).`);
1126
+ }
1127
+ if (seen.has(decl.id)) {
1128
+ throw new Error(
1129
+ `[build-pages] ui.platformReactOverlay.id "${decl.id}" collides with a page id \u2014 ids must be unique across pages and the overlay.`
1130
+ );
1131
+ }
1132
+ if (typeof decl.moduleSpecifier !== "string" || decl.moduleSpecifier.length === 0) {
1133
+ throw new Error(`[build-pages] ui.platformReactOverlay "${decl.id}" has no moduleSpecifier in the manifest.`);
1134
+ }
1135
+ overlay = decl;
1136
+ }
1089
1137
  const outDir = options.outDir ?? DEFAULT_OUT_DIR;
1090
1138
  const outDirAbs = isAbsolute(outDir) ? outDir : resolve(root, outDir);
1091
1139
  const outputPrefix = (options.outputPrefix ?? DEFAULT_OUTPUT_PREFIX).replace(/^\/+|\/+$/g, "");
@@ -1095,6 +1143,7 @@ async function buildPlatformReactPages(options = {}) {
1095
1143
  const alias = options.alias ?? [];
1096
1144
  const plugins = options.plugins ?? [];
1097
1145
  const definePluginPageSpecifier = options.definePluginPageSpecifier ?? DEFAULT_DEFINE_PLUGIN_PAGE;
1146
+ const definePluginOverlaySpecifier = options.definePluginOverlaySpecifier ?? DEFAULT_DEFINE_PLUGIN_OVERLAY;
1098
1147
  const srcDir = options.srcDir ?? DEFAULT_SRC_DIR;
1099
1148
  const aliasPrefix = options.aliasPrefix ?? DEFAULT_ALIAS_PREFIX;
1100
1149
  const srcRe = new RegExp(`^${escapeRegExp(srcDir)}/`);
@@ -1130,6 +1179,28 @@ async function buildPlatformReactPages(options = {}) {
1130
1179
  sourcemap: options.sourcemap ?? true
1131
1180
  });
1132
1181
  }
1182
+ if (overlay) {
1183
+ const { id: entryId, plugin: surfacePlugin } = virtualOverlayEntry(overlay, {
1184
+ definePluginOverlaySpecifier,
1185
+ toAlias
1186
+ });
1187
+ logger.log(`[build-pages] ${overlay.id} \u2190 ${overlay.moduleSpecifier} (overlay)`);
1188
+ await runBuild({
1189
+ pageId: overlay.id,
1190
+ entryId,
1191
+ surfacePlugin,
1192
+ root,
1193
+ outDir: outDirAbs,
1194
+ outputPrefix,
1195
+ external,
1196
+ dedupe,
1197
+ alias,
1198
+ plugins,
1199
+ target: options.target ?? "es2022",
1200
+ minify: options.minify ?? false,
1201
+ sourcemap: options.sourcemap ?? true
1202
+ });
1203
+ }
1133
1204
  const summaryPages = pages.map((p) => ({
1134
1205
  id: p.id,
1135
1206
  exportName: p.exportName ?? "default",
@@ -1137,18 +1208,35 @@ async function buildPlatformReactPages(options = {}) {
1137
1208
  bundlePath: `${outputPrefix}/${p.id}.js`,
1138
1209
  source: p.moduleSpecifier
1139
1210
  }));
1211
+ const summaryOverlay = overlay ? {
1212
+ id: overlay.id,
1213
+ exportName: overlay.exportName ?? "default",
1214
+ title: overlay.title ?? null,
1215
+ bundlePath: `${outputPrefix}/${overlay.id}.js`,
1216
+ source: overlay.moduleSpecifier
1217
+ } : void 0;
1140
1218
  const summaryPath = resolve(outputPrefixDir, SUMMARY_FILENAME);
1141
- write(summaryPath, JSON.stringify({ pages: summaryPages }, null, 2));
1142
- const digests = pages.map((p) => `${outputPrefix}/${p.id}.js`).sort().map((relPath) => {
1219
+ write(
1220
+ summaryPath,
1221
+ JSON.stringify(
1222
+ summaryOverlay ? { pages: summaryPages, overlay: summaryOverlay } : { pages: summaryPages },
1223
+ null,
1224
+ 2
1225
+ )
1226
+ );
1227
+ const digests = [
1228
+ ...pages.map((p) => `${outputPrefix}/${p.id}.js`),
1229
+ ...overlay ? [`${outputPrefix}/${overlay.id}.js`] : []
1230
+ ].sort().map((relPath) => {
1143
1231
  const code = read(resolve(outDirAbs, relPath));
1144
1232
  return { path: relPath, sha256: createHash("sha256").update(code, "utf8").digest("hex") };
1145
1233
  });
1146
1234
  const digestMapPath = resolve(outputPrefixDir, DIGEST_MAP_FILENAME);
1147
1235
  write(digestMapPath, JSON.stringify({ digests }, null, 2));
1148
1236
  logger.log(
1149
- `[build-pages] emitted ${pages.length} page(s) + summary + digest map (${digests.length} digests)`
1237
+ `[build-pages] emitted ${pages.length} page(s)${overlay ? " + 1 overlay" : ""} + summary + digest map (${digests.length} digests)`
1150
1238
  );
1151
- return { pages: summaryPages, digests, summaryPath, digestMapPath };
1239
+ return { pages: summaryPages, overlay: summaryOverlay, digests, summaryPath, digestMapPath };
1152
1240
  }
1153
1241
 
1154
1242
  // src/platform-react/page-bundles.ts