@ethisyscore/vite-plugin 1.24.0 → 1.26.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 CHANGED
@@ -593,6 +593,22 @@ function ethisysContractBPlugin(options = {}) {
593
593
  }
594
594
  };
595
595
  }
596
+
597
+ // src/utils/strings.ts
598
+ function slash2(p) {
599
+ return p.replace(/\\/g, "/");
600
+ }
601
+ function kebab(s) {
602
+ return s.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/_/g, "-").toLowerCase();
603
+ }
604
+ function titleCase(s) {
605
+ return s.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/^./, (c) => c.toUpperCase());
606
+ }
607
+ function escapeRegExp(s) {
608
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
609
+ }
610
+
611
+ // src/platform-react/page-bundles.ts
596
612
  var ID_REGEX = /^[a-z0-9]+(?:[-_][a-z0-9]+)*$/i;
597
613
  function assertHostOriginRelativePath2(value, label) {
598
614
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
@@ -617,9 +633,6 @@ function assertHostOriginRelativePath2(value, label) {
617
633
  );
618
634
  }
619
635
  }
620
- function slash2(p) {
621
- return path.sep === "\\" ? p.replace(/\\/g, "/") : p;
622
- }
623
636
  function ethisysPlatformReactPlugin(options = {}) {
624
637
  const explicitRoot = options.root;
625
638
  const manifestRel = options.manifestPath ?? "feature.manifest.json";
@@ -990,9 +1003,6 @@ function defaultWriteFile(path$1, contents) {
990
1003
  fs.mkdirSync(path.dirname(path$1), { recursive: true });
991
1004
  fs.writeFileSync(path$1, contents);
992
1005
  }
993
- function escapeRegExp(s) {
994
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
995
- }
996
1006
  function readManifest(options, root) {
997
1007
  if (options.manifest !== void 0) {
998
1008
  return options.manifest;
@@ -1134,6 +1144,126 @@ async function buildPlatformReactPages(options = {}) {
1134
1144
  );
1135
1145
  return { pages: summaryPages, digests, summaryPath, digestMapPath };
1136
1146
  }
1147
+ var DEFAULT_SCHEMA = "https://ethisys.dev/schemas/feature-manifest.json";
1148
+ function computePlatformReactPages(input) {
1149
+ const routePrefix = `/extensions/${input.slug}/`;
1150
+ const routeRoot = `/extensions/${input.slug}`;
1151
+ const pageRouteById = Object.fromEntries(
1152
+ input.routeMeta.filter((e) => e.pageId && (e.pattern.startsWith(routePrefix) || e.pattern === routeRoot)).map((e) => [e.pageId, e.pattern === routeRoot ? "" : e.pattern.slice(routePrefix.length)])
1153
+ );
1154
+ const useViewRe = new RegExp(
1155
+ `useView\\(\\s*["']${escapeRegExp(input.module)}["']\\s*,\\s*["']([A-Za-z0-9_]+)["']\\s*\\)`,
1156
+ "g"
1157
+ );
1158
+ const entries = [];
1159
+ const missingViews = [];
1160
+ for (const { file, content } of input.pages) {
1161
+ const name = path.basename(file, ".tsx");
1162
+ const override = input.pageOverrides?.[file] ?? {};
1163
+ const views = {};
1164
+ useViewRe.lastIndex = 0;
1165
+ let m;
1166
+ while ((m = useViewRe.exec(content)) !== null) {
1167
+ const v = m[1];
1168
+ if (input.viewFiles[v] !== void 0) {
1169
+ views[v] = input.viewFiles[v];
1170
+ } else {
1171
+ missingViews.push(`${file}: view "${v}" has no adapter file`);
1172
+ }
1173
+ }
1174
+ const id = override.id ?? kebab(name);
1175
+ const route = override.route ?? pageRouteById[id];
1176
+ entries.push({
1177
+ id,
1178
+ moduleSpecifier: `${input.pagesDirRel}/${file}`,
1179
+ exportName: "default",
1180
+ ...route !== void 0 ? { route } : {},
1181
+ title: override.title ?? titleCase(name),
1182
+ views
1183
+ });
1184
+ }
1185
+ return { entries, missingViews };
1186
+ }
1187
+ function walk(dir) {
1188
+ const out = [];
1189
+ for (const n of fs.readdirSync(dir)) {
1190
+ const p = path.resolve(dir, n);
1191
+ if (fs.statSync(p).isDirectory()) {
1192
+ out.push(...walk(p));
1193
+ } else {
1194
+ out.push(p);
1195
+ }
1196
+ }
1197
+ return out;
1198
+ }
1199
+ function generatePlatformReactManifest(config) {
1200
+ const { root, module } = config;
1201
+ const slug = config.slug ?? module;
1202
+ const src = config.paths?.src ?? "src";
1203
+ const pagesDir = path.resolve(root, config.paths?.pages ?? `${src}/pages/${module}`);
1204
+ const adapterDir = path.resolve(root, config.paths?.adapter ?? `${src}/adapter/${module}`);
1205
+ const routeMetaPath = path.resolve(root, config.paths?.routeMeta ?? `${src}/config/routeMeta.json`);
1206
+ const featureManifestRel = config.paths?.featureManifest ?? "feature.manifest.json";
1207
+ const overlayRel = config.paths?.overlay ?? "../extension.manifest.json";
1208
+ const routeMeta = fs.existsSync(routeMetaPath) ? JSON.parse(fs.readFileSync(routeMetaPath, "utf8")) : [];
1209
+ const pagesDirRel = slash2(path.relative(root, pagesDir));
1210
+ const viewFiles = {};
1211
+ if (fs.existsSync(adapterDir)) {
1212
+ for (const f of walk(adapterDir)) {
1213
+ if (f.endsWith(".tsx")) {
1214
+ viewFiles[path.basename(f, ".tsx")] = slash2(path.relative(root, f));
1215
+ }
1216
+ }
1217
+ }
1218
+ const pageFiles = fs.readdirSync(pagesDir).filter((f) => f.endsWith(".tsx")).sort();
1219
+ const pages = pageFiles.map((file) => ({
1220
+ file,
1221
+ content: fs.readFileSync(path.resolve(pagesDir, file), "utf8")
1222
+ }));
1223
+ const { entries, missingViews } = computePlatformReactPages({
1224
+ module,
1225
+ slug,
1226
+ routeMeta,
1227
+ pages,
1228
+ viewFiles,
1229
+ pagesDirRel,
1230
+ pageOverrides: config.pageOverrides
1231
+ });
1232
+ const schema = config.manifest.schema ?? DEFAULT_SCHEMA;
1233
+ const renderMode = config.manifest.renderMode ?? "platform-react";
1234
+ const featureManifest = {
1235
+ $schema: schema,
1236
+ id: config.manifest.id,
1237
+ name: config.manifest.name,
1238
+ version: config.manifest.version,
1239
+ renderMode,
1240
+ ui: { platformReactPages: entries }
1241
+ };
1242
+ const featureManifestPath = path.resolve(root, featureManifestRel);
1243
+ fs.writeFileSync(featureManifestPath, JSON.stringify(featureManifest, null, 2) + "\n");
1244
+ const overlay = {
1245
+ $schema: schema,
1246
+ ui: {
1247
+ platformReactPages: entries.map(({ id, moduleSpecifier, exportName, route, title }) => ({
1248
+ id,
1249
+ moduleSpecifier,
1250
+ exportName,
1251
+ ...route !== void 0 ? { route } : {},
1252
+ title
1253
+ }))
1254
+ }
1255
+ };
1256
+ const overlayPath = path.resolve(root, overlayRel);
1257
+ fs.writeFileSync(overlayPath, JSON.stringify(overlay, null, 2) + "\n");
1258
+ const pagesWithoutView = entries.filter((e) => Object.keys(e.views).length === 0).map((e) => e.id);
1259
+ return {
1260
+ pageCount: entries.length,
1261
+ pagesWithoutView,
1262
+ missingViews,
1263
+ featureManifestPath,
1264
+ overlayPath
1265
+ };
1266
+ }
1137
1267
  var DEFAULT_MANIFEST = "feature.manifest.json";
1138
1268
  var DEFAULT_OUTPUT_DIR = "dist/iframe-sandbox";
1139
1269
  var DIGEST_MAP_FILENAME2 = "iframe-sandbox-digest-map.json";
@@ -1479,11 +1609,13 @@ exports.PLATFORM_REACT_DEDUPE = PLATFORM_REACT_DEDUPE;
1479
1609
  exports.PLATFORM_REACT_EXTERNALS = PLATFORM_REACT_EXTERNALS;
1480
1610
  exports.buildIframeSandboxPages = buildIframeSandboxPages;
1481
1611
  exports.buildPlatformReactPages = buildPlatformReactPages;
1612
+ exports.computePlatformReactPages = computePlatformReactPages;
1482
1613
  exports.ethisysContractAPlugin = ethisysContractAPlugin;
1483
1614
  exports.ethisysContractBPlugin = ethisysContractBPlugin;
1484
1615
  exports.ethisysIframeSandboxPlugin = ethisysIframeSandboxPlugin;
1485
1616
  exports.ethisysManifestPlugin = ethisysManifestPlugin;
1486
1617
  exports.ethisysPlatformReactPlugin = ethisysPlatformReactPlugin;
1618
+ exports.generatePlatformReactManifest = generatePlatformReactManifest;
1487
1619
  exports.parsePlatformReactPages = parsePlatformReactPages;
1488
1620
  exports.rewriteAliasedExternalImports = rewriteAliasedExternalImports;
1489
1621
  exports.validateDeclarativeResource = validateDeclarativeResource;