@open-mercato/cli 0.6.6-develop.6290.1.4bb5a8ba3f → 0.6.6-develop.6296.1.5e8bdfee17

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.
@@ -981,8 +981,6 @@ async function loadPageMetadataForManifest(options) {
981
981
  }
982
982
  async function processPageFiles(options) {
983
983
  const { files, type, modId, appDir, pkgDir, appImportBase, pkgImportBase, eagerImports, runtimeImports, manifestImports, importIdRef } = options;
984
- const prefix = type === "frontend" ? "C" : "B";
985
- const modPrefix = type === "frontend" ? "CM" : "BM";
986
984
  const metaPrefix = type === "frontend" ? "M" : "BM";
987
985
  const eagerRoutes = [];
988
986
  const runtimeRoutes = [];
@@ -991,8 +989,8 @@ async function processPageFiles(options) {
991
989
  const segs = relPath.split("/");
992
990
  const pageFile = segs.pop();
993
991
  const pageBaseName = stripModuleCodeExtension(pageFile);
994
- const importName = `${prefix}${importIdRef.value++}_${toVar(modId)}_${toVar(segs.join("_") || "index")}`;
995
- const pageModName = `${modPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(segs.join("_") || "index")}`;
992
+ importIdRef.value++;
993
+ importIdRef.value++;
996
994
  const runtimeMetaName = `${metaPrefix}Runtime${importIdRef.value++}_${toVar(modId)}_${toVar(segs.join("_") || "index")}`;
997
995
  const sub = segs.length ? `${segs.join("/")}/${pageBaseName}` : pageBaseName;
998
996
  const importPath = sanitizeGeneratedModuleSpecifier(`${fromApp ? appImportBase : pkgImportBase}/${type}/${sub}`);
@@ -1025,10 +1023,14 @@ async function processPageFiles(options) {
1025
1023
  if (manifestMetadata.requiresRuntimeImport) {
1026
1024
  manifestImportStatement = buildImportStatement(`* as ${manifestMetaImportName}`, metaImportPath);
1027
1025
  }
1028
- eagerImports.push(buildImportStatement(importName, importPath));
1029
1026
  } else {
1030
- metaExpr = `(${pageModName} as any).metadata`;
1031
1027
  runtimeMetaExpr = `(((${runtimeMetaName} as any).metadata) as any)`;
1028
+ const staticMetadata = await loadPageMetadataForManifest({
1029
+ sourceFile,
1030
+ runtimeExpr: "(undefined as any)",
1031
+ allowRuntimeFallback: false
1032
+ });
1033
+ metaExpr = staticMetadata.manifestExpr;
1032
1034
  const manifestMetaImportName = `${metaPrefix}Manifest${importIdRef.value++}_${toVar(modId)}_${toVar(segs.join("_") || "index")}`;
1033
1035
  const manifestMetadata = await loadPageMetadataForManifest({
1034
1036
  sourceFile,
@@ -1039,7 +1041,6 @@ async function processPageFiles(options) {
1039
1041
  if (manifestMetadata.requiresRuntimeImport) {
1040
1042
  manifestImportStatement = buildImportStatement(`* as ${manifestMetaImportName}`, importPath);
1041
1043
  }
1042
- eagerImports.push(buildImportStatement(`${importName}, * as ${pageModName}`, importPath));
1043
1044
  runtimeImports.push(buildImportStatement(`* as ${runtimeMetaName}`, importPath));
1044
1045
  }
1045
1046
  if (manifestImportStatement) {
@@ -1048,8 +1049,8 @@ async function processPageFiles(options) {
1048
1049
  const baseProps = buildPageRouteProps(metaExpr, routePath);
1049
1050
  const runtimeBaseProps = buildPageRouteProps(runtimeMetaExpr, routePath);
1050
1051
  const manifestBaseProps = buildPageRouteProps(manifestMetaExpr, routePath);
1051
- eagerRoutes.push(`{ ${baseProps}, Component: ${importName} }`);
1052
- runtimeRoutes.push(`{ ${runtimeBaseProps}, Component: async (props: any) => { const mod = await ${buildDynamicImportExpression(importPath)}; const Component = (mod.default ?? mod) as any; return createElement(Component, props) } }`);
1052
+ eagerRoutes.push(`{ ${baseProps}, Component: ${buildLazyRouteComponentExpression(importPath)} }`);
1053
+ runtimeRoutes.push(`{ ${runtimeBaseProps}, Component: ${buildLazyRouteComponentExpression(importPath)} }`);
1053
1054
  manifestRoutes.push(`{ moduleId: ${toLiteral(modId)}, ${manifestBaseProps}, load: async () => { const mod = await ${buildDynamicImportExpression(importPath)}; return (mod.default ?? mod) as any } }`);
1054
1055
  }
1055
1056
  for (const { relPath, fromApp } of files.filter(({ relPath: f }) => !isModulePageFile(path.basename(f)))) {
@@ -1057,8 +1058,8 @@ async function processPageFiles(options) {
1057
1058
  const file = segs.pop();
1058
1059
  const name = stripModuleCodeExtension(file);
1059
1060
  const routeSegs = [...segs, name].filter(Boolean);
1060
- const importName = `${prefix}${importIdRef.value++}_${toVar(modId)}_${toVar(routeSegs.join("_") || "index")}`;
1061
- const pageModName = `${modPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(routeSegs.join("_") || "index")}`;
1061
+ importIdRef.value++;
1062
+ importIdRef.value++;
1062
1063
  const runtimeMetaName = `${metaPrefix}Runtime${importIdRef.value++}_${toVar(modId)}_${toVar(routeSegs.join("_") || "index")}`;
1063
1064
  const importPath = sanitizeGeneratedModuleSpecifier(
1064
1065
  `${fromApp ? appImportBase : pkgImportBase}/${type}/${[...segs, name].join("/")}`
@@ -1094,10 +1095,14 @@ async function processPageFiles(options) {
1094
1095
  if (manifestMetadata.requiresRuntimeImport) {
1095
1096
  manifestImportStatement = buildImportStatement(`* as ${manifestMetaImportName}`, metaImportPath);
1096
1097
  }
1097
- eagerImports.push(buildImportStatement(importName, importPath));
1098
1098
  } else {
1099
- metaExpr = `(${pageModName} as any).metadata`;
1100
1099
  runtimeMetaExpr = `(((${runtimeMetaName} as any).metadata) as any)`;
1100
+ const staticMetadata = await loadPageMetadataForManifest({
1101
+ sourceFile,
1102
+ runtimeExpr: "(undefined as any)",
1103
+ allowRuntimeFallback: false
1104
+ });
1105
+ metaExpr = staticMetadata.manifestExpr;
1101
1106
  const manifestMetaImportName = `${metaPrefix}Manifest${importIdRef.value++}_${toVar(modId)}_${toVar(routeSegs.join("_") || "index")}`;
1102
1107
  const manifestMetadata = await loadPageMetadataForManifest({
1103
1108
  sourceFile,
@@ -1108,7 +1113,6 @@ async function processPageFiles(options) {
1108
1113
  if (manifestMetadata.requiresRuntimeImport) {
1109
1114
  manifestImportStatement = buildImportStatement(`* as ${manifestMetaImportName}`, importPath);
1110
1115
  }
1111
- eagerImports.push(buildImportStatement(`${importName}, * as ${pageModName}`, importPath));
1112
1116
  runtimeImports.push(buildImportStatement(`* as ${runtimeMetaName}`, importPath));
1113
1117
  }
1114
1118
  if (manifestImportStatement) {
@@ -1117,8 +1121,8 @@ async function processPageFiles(options) {
1117
1121
  const baseProps = buildPageRouteProps(metaExpr, routePath);
1118
1122
  const runtimeBaseProps = buildPageRouteProps(runtimeMetaExpr, routePath);
1119
1123
  const manifestBaseProps = buildPageRouteProps(manifestMetaExpr, routePath);
1120
- eagerRoutes.push(`{ ${baseProps}, Component: ${importName} }`);
1121
- runtimeRoutes.push(`{ ${runtimeBaseProps}, Component: async (props: any) => { const mod = await ${buildDynamicImportExpression(importPath)}; const Component = (mod.default ?? mod) as any; return createElement(Component, props) } }`);
1124
+ eagerRoutes.push(`{ ${baseProps}, Component: ${buildLazyRouteComponentExpression(importPath)} }`);
1125
+ runtimeRoutes.push(`{ ${runtimeBaseProps}, Component: ${buildLazyRouteComponentExpression(importPath)} }`);
1122
1126
  manifestRoutes.push(`{ moduleId: ${toLiteral(modId)}, ${manifestBaseProps}, load: async () => { const mod = await ${buildDynamicImportExpression(importPath)}; return (mod.default ?? mod) as any } }`);
1123
1127
  }
1124
1128
  return {
@@ -1594,6 +1598,9 @@ function renderLegacyCompatibleArray(entries) {
1594
1598
  ${entries.join(",\n ")}
1595
1599
  ]`;
1596
1600
  }
1601
+ function buildLazyRouteComponentExpression(importPath) {
1602
+ return `async (props: any) => { const mod = await ${buildDynamicImportExpression(importPath)}; const Component = (mod.default ?? mod) as any; return createElement(Component, props) }`;
1603
+ }
1597
1604
  function renderAstLegacyModuleRegistryOutput(options) {
1598
1605
  const importSection = [
1599
1606
  ...options.includeCreateElementImport ? ["import { createElement } from 'react'"] : [],
@@ -1652,6 +1659,9 @@ function buildRuntimeRouteComponent(importPath) {
1652
1659
  })
1653
1660
  });
1654
1661
  }
1662
+ function rawExpression(source) {
1663
+ return (writer) => writer.write(source);
1664
+ }
1655
1665
  function buildPageRouteEntries(metaExpr, routePath) {
1656
1666
  const meta = parenthesized(metaExpr);
1657
1667
  return [
@@ -1750,30 +1760,30 @@ async function processPageFilesAst(options) {
1750
1760
  if (!sourceFile || !hasDefaultExport(sourceFile)) continue;
1751
1761
  const metaPath = findExistingModuleFileByBaseNames(moduleBaseDir, ["page.meta", "meta"]);
1752
1762
  if (metaPath) {
1753
- const metaImportName2 = `${metaPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(segs.join("_") || "index")}`;
1763
+ const metaImportName = `${metaPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(segs.join("_") || "index")}`;
1754
1764
  const metaImportPath = sanitizeGeneratedModuleSpecifier(
1755
1765
  `${fromApp ? appImportBase : pkgImportBase}/${type}/${toModuleImportSubpath(metaPath, fromApp ? appDir : pkgDir)}`
1756
1766
  );
1757
- imports.push(buildImportStatement(`* as ${metaImportName2}`, metaImportPath));
1767
+ imports.push(buildImportStatement(`* as ${metaImportName}`, metaImportPath));
1758
1768
  addRoute({
1759
1769
  importPath,
1760
1770
  routePath,
1761
1771
  metaExpr: asExpression(
1762
- propertyAccess(asExpression(identifier(metaImportName2), "any"), "metadata"),
1772
+ propertyAccess(asExpression(identifier(metaImportName), "any"), "metadata"),
1763
1773
  "any"
1764
1774
  )
1765
1775
  });
1766
1776
  continue;
1767
1777
  }
1768
- const metaImportName = `${metaPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(segs.join("_") || "index")}`;
1769
- imports.push(buildImportStatement(`* as ${metaImportName}`, importPath));
1778
+ const staticMetadata = await loadPageMetadataForManifest({
1779
+ sourceFile,
1780
+ runtimeExpr: "(undefined as any)",
1781
+ allowRuntimeFallback: false
1782
+ });
1770
1783
  addRoute({
1771
1784
  importPath,
1772
1785
  routePath,
1773
- metaExpr: asExpression(
1774
- propertyAccess(asExpression(identifier(metaImportName), "any"), "metadata"),
1775
- "any"
1776
- )
1786
+ metaExpr: rawExpression(staticMetadata.manifestExpr)
1777
1787
  });
1778
1788
  }
1779
1789
  for (const { relPath, fromApp } of files.filter(({ relPath: filePath }) => !isModulePageFile(path.basename(filePath)))) {
@@ -1790,32 +1800,32 @@ async function processPageFilesAst(options) {
1790
1800
  if (!sourceFile || !hasDefaultExport(sourceFile)) continue;
1791
1801
  const metaPath = findExistingModuleFileByBaseNames(moduleBaseDir, [`${name}.meta`, "meta"]);
1792
1802
  if (metaPath) {
1793
- const metaImportName2 = `${metaPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(routeSegs.join("_") || "index")}`;
1803
+ const metaImportName = `${metaPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(routeSegs.join("_") || "index")}`;
1794
1804
  const metaBase = path.basename(metaPath);
1795
1805
  const metaImportSub = stripModuleCodeExtension(metaBase) === "meta" ? "meta" : `${name}.meta`;
1796
1806
  const metaImportPath = sanitizeGeneratedModuleSpecifier(
1797
1807
  `${fromApp ? appImportBase : pkgImportBase}/${type}/${[...segs, metaImportSub].join("/")}`
1798
1808
  );
1799
- imports.push(buildImportStatement(`* as ${metaImportName2}`, metaImportPath));
1809
+ imports.push(buildImportStatement(`* as ${metaImportName}`, metaImportPath));
1800
1810
  addRoute({
1801
1811
  importPath,
1802
1812
  routePath,
1803
1813
  metaExpr: asExpression(
1804
- propertyAccess(asExpression(identifier(metaImportName2), "any"), "metadata"),
1814
+ propertyAccess(asExpression(identifier(metaImportName), "any"), "metadata"),
1805
1815
  "any"
1806
1816
  )
1807
1817
  });
1808
1818
  continue;
1809
1819
  }
1810
- const metaImportName = `${metaPrefix}${importIdRef.value++}_${toVar(modId)}_${toVar(routeSegs.join("_") || "index")}`;
1811
- imports.push(buildImportStatement(`* as ${metaImportName}`, importPath));
1820
+ const staticMetadata = await loadPageMetadataForManifest({
1821
+ sourceFile,
1822
+ runtimeExpr: "(undefined as any)",
1823
+ allowRuntimeFallback: false
1824
+ });
1812
1825
  addRoute({
1813
1826
  importPath,
1814
1827
  routePath,
1815
- metaExpr: asExpression(
1816
- propertyAccess(asExpression(identifier(metaImportName), "any"), "metadata"),
1817
- "any"
1818
- )
1828
+ metaExpr: rawExpression(staticMetadata.manifestExpr)
1819
1829
  });
1820
1830
  }
1821
1831
  return routes;
@@ -2023,6 +2033,7 @@ async function generateModuleRegistry(options) {
2023
2033
  const importIdRef = { value: 0 };
2024
2034
  const trackedRoots = /* @__PURE__ */ new Set();
2025
2035
  const requiresByModule = /* @__PURE__ */ new Map();
2036
+ let hasRouteComponents = false;
2026
2037
  const umesConflictSources = [];
2027
2038
  for (const entry of enabled) {
2028
2039
  const modId = entry.id;
@@ -2087,6 +2098,7 @@ async function generateModuleRegistry(options) {
2087
2098
  frontendRoutes.push(...generatedFrontendRoutes.eagerRoutes);
2088
2099
  runtimeFrontendRoutes.push(...generatedFrontendRoutes.runtimeRoutes);
2089
2100
  frontendRouteManifestDecls.push(...generatedFrontendRoutes.manifestRoutes);
2101
+ hasRouteComponents = true;
2090
2102
  }
2091
2103
  }
2092
2104
  {
@@ -2187,6 +2199,7 @@ async function generateModuleRegistry(options) {
2187
2199
  backendRoutes.push(...generatedBackendRoutes.eagerRoutes);
2188
2200
  runtimeBackendRoutes.push(...generatedBackendRoutes.runtimeRoutes);
2189
2201
  backendRouteManifestDecls.push(...generatedBackendRoutes.manifestRoutes);
2202
+ hasRouteComponents = true;
2190
2203
  }
2191
2204
  }
2192
2205
  {
@@ -2386,7 +2399,8 @@ async function generateModuleRegistry(options) {
2386
2399
  const output = renderAstLegacyModuleRegistryOutput({
2387
2400
  fileName: "modules.generated.ts",
2388
2401
  imports,
2389
- moduleEntries: moduleDecls
2402
+ moduleEntries: moduleDecls,
2403
+ includeCreateElementImport: hasRouteComponents
2390
2404
  });
2391
2405
  const runtimeOutput = renderAstLegacyModuleRegistryOutput({
2392
2406
  fileName: "modules.runtime.generated.ts",