@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.cjs +96 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -11
- package/dist/index.d.ts +19 -11
- package/dist/index.js +96 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -950,6 +950,7 @@ var PLATFORM_REACT_DEDUPE = [
|
|
|
950
950
|
var DEFAULT_OUT_DIR = "dist";
|
|
951
951
|
var DEFAULT_OUTPUT_PREFIX = "platform-react";
|
|
952
952
|
var DEFAULT_DEFINE_PLUGIN_PAGE = "@/app/definePluginPage";
|
|
953
|
+
var DEFAULT_DEFINE_PLUGIN_OVERLAY = "@/app/definePluginOverlay";
|
|
953
954
|
var DEFAULT_SRC_DIR = "src";
|
|
954
955
|
var DEFAULT_ALIAS_PREFIX = "@";
|
|
955
956
|
var SUMMARY_FILENAME = "platform-react-pages.json";
|
|
@@ -998,6 +999,31 @@ export default definePluginPage(Page, { ${names.join(", ")} });
|
|
|
998
999
|
}
|
|
999
1000
|
};
|
|
1000
1001
|
}
|
|
1002
|
+
function virtualOverlayEntry(overlay, config) {
|
|
1003
|
+
const VIRTUAL_ID = `\0virtual:surface/${overlay.id}`;
|
|
1004
|
+
const views = overlay.views ?? {};
|
|
1005
|
+
const names = Object.keys(views);
|
|
1006
|
+
const viewImports = names.map((n) => `import { ${n} } from ${JSON.stringify(config.toAlias(views[n]))};`).join("\n");
|
|
1007
|
+
const exportName = typeof overlay.exportName === "string" && overlay.exportName.length > 0 ? overlay.exportName : "default";
|
|
1008
|
+
const overlayModule = JSON.stringify(config.toAlias(overlay.moduleSpecifier));
|
|
1009
|
+
const overlayImport = exportName === "default" ? `import Overlay from ${overlayModule};` : `import { ${exportName} as Overlay } from ${overlayModule};`;
|
|
1010
|
+
const overlayExport = exportName === "default" ? `export default definePluginOverlay(Overlay, { ${names.join(", ")} });` : `const __ehxOverlay = definePluginOverlay(Overlay, { ${names.join(", ")} });
|
|
1011
|
+
export { __ehxOverlay as ${exportName} };
|
|
1012
|
+
export default __ehxOverlay;`;
|
|
1013
|
+
const src = `${overlayImport}
|
|
1014
|
+
${viewImports}
|
|
1015
|
+
import { definePluginOverlay } from ${JSON.stringify(config.definePluginOverlaySpecifier)};
|
|
1016
|
+
${overlayExport}
|
|
1017
|
+
`;
|
|
1018
|
+
return {
|
|
1019
|
+
id: VIRTUAL_ID,
|
|
1020
|
+
plugin: {
|
|
1021
|
+
name: `virtual-surface-${overlay.id}`,
|
|
1022
|
+
resolveId: (id) => id === VIRTUAL_ID ? VIRTUAL_ID : null,
|
|
1023
|
+
load: (id) => id === VIRTUAL_ID ? src : null
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1001
1027
|
function defaultWriteFile(path$1, contents) {
|
|
1002
1028
|
fs.mkdirSync(path.dirname(path$1), { recursive: true });
|
|
1003
1029
|
fs.writeFileSync(path$1, contents);
|
|
@@ -1068,13 +1094,19 @@ async function buildPlatformReactPages(options = {}) {
|
|
|
1068
1094
|
const root = options.root ?? process.cwd();
|
|
1069
1095
|
const logger = options.logger ?? console;
|
|
1070
1096
|
const manifest = readManifest(options, root);
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
|
|
1097
|
+
const ui = manifest?.ui;
|
|
1098
|
+
const declared = ui?.platformReactPages;
|
|
1099
|
+
const overlayDecl = ui?.platformReactOverlay;
|
|
1100
|
+
const hasPages = Array.isArray(declared) && declared.length > 0;
|
|
1101
|
+
const hasOverlay = overlayDecl !== void 0 && overlayDecl !== null;
|
|
1102
|
+
if (!hasPages && !hasOverlay) {
|
|
1103
|
+
logger.warn(
|
|
1104
|
+
"[build-pages] no platformReactPages or platformReactOverlay declared \u2014 nothing to build"
|
|
1105
|
+
);
|
|
1074
1106
|
return { pages: [], digests: [], summaryPath: null, digestMapPath: null };
|
|
1075
1107
|
}
|
|
1076
1108
|
const seen = /* @__PURE__ */ new Set();
|
|
1077
|
-
const pages = declared.map((raw, i) => {
|
|
1109
|
+
const pages = (hasPages ? declared : []).map((raw, i) => {
|
|
1078
1110
|
const decl = raw;
|
|
1079
1111
|
if (typeof decl?.id !== "string" || decl.id.length === 0) {
|
|
1080
1112
|
throw new Error(`[build-pages] ui.platformReactPages[${i}].id is required (non-empty string).`);
|
|
@@ -1088,6 +1120,22 @@ async function buildPlatformReactPages(options = {}) {
|
|
|
1088
1120
|
}
|
|
1089
1121
|
return decl;
|
|
1090
1122
|
});
|
|
1123
|
+
let overlay = null;
|
|
1124
|
+
if (hasOverlay) {
|
|
1125
|
+
const decl = overlayDecl;
|
|
1126
|
+
if (typeof decl?.id !== "string" || decl.id.length === 0) {
|
|
1127
|
+
throw new Error(`[build-pages] ui.platformReactOverlay.id is required (non-empty string).`);
|
|
1128
|
+
}
|
|
1129
|
+
if (seen.has(decl.id)) {
|
|
1130
|
+
throw new Error(
|
|
1131
|
+
`[build-pages] ui.platformReactOverlay.id "${decl.id}" collides with a page id \u2014 ids must be unique across pages and the overlay.`
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
if (typeof decl.moduleSpecifier !== "string" || decl.moduleSpecifier.length === 0) {
|
|
1135
|
+
throw new Error(`[build-pages] ui.platformReactOverlay "${decl.id}" has no moduleSpecifier in the manifest.`);
|
|
1136
|
+
}
|
|
1137
|
+
overlay = decl;
|
|
1138
|
+
}
|
|
1091
1139
|
const outDir = options.outDir ?? DEFAULT_OUT_DIR;
|
|
1092
1140
|
const outDirAbs = path.isAbsolute(outDir) ? outDir : path.resolve(root, outDir);
|
|
1093
1141
|
const outputPrefix = (options.outputPrefix ?? DEFAULT_OUTPUT_PREFIX).replace(/^\/+|\/+$/g, "");
|
|
@@ -1097,6 +1145,7 @@ async function buildPlatformReactPages(options = {}) {
|
|
|
1097
1145
|
const alias = options.alias ?? [];
|
|
1098
1146
|
const plugins = options.plugins ?? [];
|
|
1099
1147
|
const definePluginPageSpecifier = options.definePluginPageSpecifier ?? DEFAULT_DEFINE_PLUGIN_PAGE;
|
|
1148
|
+
const definePluginOverlaySpecifier = options.definePluginOverlaySpecifier ?? DEFAULT_DEFINE_PLUGIN_OVERLAY;
|
|
1100
1149
|
const srcDir = options.srcDir ?? DEFAULT_SRC_DIR;
|
|
1101
1150
|
const aliasPrefix = options.aliasPrefix ?? DEFAULT_ALIAS_PREFIX;
|
|
1102
1151
|
const srcRe = new RegExp(`^${escapeRegExp(srcDir)}/`);
|
|
@@ -1132,6 +1181,28 @@ async function buildPlatformReactPages(options = {}) {
|
|
|
1132
1181
|
sourcemap: options.sourcemap ?? true
|
|
1133
1182
|
});
|
|
1134
1183
|
}
|
|
1184
|
+
if (overlay) {
|
|
1185
|
+
const { id: entryId, plugin: surfacePlugin } = virtualOverlayEntry(overlay, {
|
|
1186
|
+
definePluginOverlaySpecifier,
|
|
1187
|
+
toAlias
|
|
1188
|
+
});
|
|
1189
|
+
logger.log(`[build-pages] ${overlay.id} \u2190 ${overlay.moduleSpecifier} (overlay)`);
|
|
1190
|
+
await runBuild({
|
|
1191
|
+
pageId: overlay.id,
|
|
1192
|
+
entryId,
|
|
1193
|
+
surfacePlugin,
|
|
1194
|
+
root,
|
|
1195
|
+
outDir: outDirAbs,
|
|
1196
|
+
outputPrefix,
|
|
1197
|
+
external,
|
|
1198
|
+
dedupe,
|
|
1199
|
+
alias,
|
|
1200
|
+
plugins,
|
|
1201
|
+
target: options.target ?? "es2022",
|
|
1202
|
+
minify: options.minify ?? false,
|
|
1203
|
+
sourcemap: options.sourcemap ?? true
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1135
1206
|
const summaryPages = pages.map((p) => ({
|
|
1136
1207
|
id: p.id,
|
|
1137
1208
|
exportName: p.exportName ?? "default",
|
|
@@ -1139,18 +1210,35 @@ async function buildPlatformReactPages(options = {}) {
|
|
|
1139
1210
|
bundlePath: `${outputPrefix}/${p.id}.js`,
|
|
1140
1211
|
source: p.moduleSpecifier
|
|
1141
1212
|
}));
|
|
1213
|
+
const summaryOverlay = overlay ? {
|
|
1214
|
+
id: overlay.id,
|
|
1215
|
+
exportName: overlay.exportName ?? "default",
|
|
1216
|
+
title: overlay.title ?? null,
|
|
1217
|
+
bundlePath: `${outputPrefix}/${overlay.id}.js`,
|
|
1218
|
+
source: overlay.moduleSpecifier
|
|
1219
|
+
} : void 0;
|
|
1142
1220
|
const summaryPath = path.resolve(outputPrefixDir, SUMMARY_FILENAME);
|
|
1143
|
-
write(
|
|
1144
|
-
|
|
1221
|
+
write(
|
|
1222
|
+
summaryPath,
|
|
1223
|
+
JSON.stringify(
|
|
1224
|
+
summaryOverlay ? { pages: summaryPages, overlay: summaryOverlay } : { pages: summaryPages },
|
|
1225
|
+
null,
|
|
1226
|
+
2
|
|
1227
|
+
)
|
|
1228
|
+
);
|
|
1229
|
+
const digests = [
|
|
1230
|
+
...pages.map((p) => `${outputPrefix}/${p.id}.js`),
|
|
1231
|
+
...overlay ? [`${outputPrefix}/${overlay.id}.js`] : []
|
|
1232
|
+
].sort().map((relPath) => {
|
|
1145
1233
|
const code = read(path.resolve(outDirAbs, relPath));
|
|
1146
1234
|
return { path: relPath, sha256: crypto.createHash("sha256").update(code, "utf8").digest("hex") };
|
|
1147
1235
|
});
|
|
1148
1236
|
const digestMapPath = path.resolve(outputPrefixDir, DIGEST_MAP_FILENAME);
|
|
1149
1237
|
write(digestMapPath, JSON.stringify({ digests }, null, 2));
|
|
1150
1238
|
logger.log(
|
|
1151
|
-
`[build-pages] emitted ${pages.length} page(s) + summary + digest map (${digests.length} digests)`
|
|
1239
|
+
`[build-pages] emitted ${pages.length} page(s)${overlay ? " + 1 overlay" : ""} + summary + digest map (${digests.length} digests)`
|
|
1152
1240
|
);
|
|
1153
|
-
return { pages: summaryPages, digests, summaryPath, digestMapPath };
|
|
1241
|
+
return { pages: summaryPages, overlay: summaryOverlay, digests, summaryPath, digestMapPath };
|
|
1154
1242
|
}
|
|
1155
1243
|
|
|
1156
1244
|
// src/platform-react/page-bundles.ts
|