@marko/run 0.2.6 → 0.2.8

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.
@@ -19,6 +19,10 @@ var __copyProps = (to, from, except, desc) => {
19
19
  return to;
20
20
  };
21
21
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
26
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
27
  mod
24
28
  ));
@@ -68,14 +72,15 @@ var import_path2 = __toESM(require("path"), 1);
68
72
  var import_crypto = __toESM(require("crypto"), 1);
69
73
  var import_fs2 = __toESM(require("fs"), 1);
70
74
  var import_glob = __toESM(require("glob"), 1);
75
+ var import_url2 = require("url");
76
+ var import_browserslist = __toESM(require("browserslist"), 1);
77
+ var import_esbuild_plugin_browserslist = require("esbuild-plugin-browserslist");
71
78
  var import_vite = require("vite");
72
79
  var import_vite2 = __toESM(require("@marko/vite"), 1);
73
80
 
74
81
  // src/vite/constants.ts
75
82
  var markoRunFilePrefix = "__marko-run__";
76
83
  var virtualFilePrefix = "virtual:marko-run";
77
- var virtualRoutesPrefix = `${virtualFilePrefix}/routes`;
78
- var virtualRuntimePrefix = `${virtualFilePrefix}/internal`;
79
84
  var httpVerbs = ["get", "post", "put", "delete"];
80
85
  var serverEntryQuery = "?marko-server-entry";
81
86
  var RoutableFileTypes = {
@@ -90,7 +95,7 @@ var RoutableFileTypes = {
90
95
 
91
96
  // src/vite/routes/vdir.ts
92
97
  var _dirs, _pathlessDirs;
93
- var _VDir = class {
98
+ var _VDir = class _VDir {
94
99
  constructor(parent, segment, source) {
95
100
  __privateAdd(this, _dirs, void 0);
96
101
  __privateAdd(this, _pathlessDirs, void 0);
@@ -227,9 +232,9 @@ var _VDir = class {
227
232
  return dirs;
228
233
  }
229
234
  };
230
- var VDir = _VDir;
231
235
  _dirs = new WeakMap();
232
236
  _pathlessDirs = new WeakMap();
237
+ var VDir = _VDir;
233
238
 
234
239
  // src/vite/routes/parse.ts
235
240
  function parseFlatRoute(pattern) {
@@ -750,23 +755,35 @@ function renderRouteTemplate(route) {
750
755
  if (!route.page) {
751
756
  throw new Error(`Route ${route.key} has no page to render`);
752
757
  }
758
+ return renderEntryTemplate(
759
+ route.entryName,
760
+ [...route.layouts, route.page].map((file) => `./${file.importPath}`)
761
+ );
762
+ }
763
+ function renderEntryTemplate(name, files) {
764
+ if (!name) {
765
+ throw new Error(`Invalid argument - 'name' cannot be empty`);
766
+ }
767
+ if (!files.length) {
768
+ throw new Error(`Invalid argument - 'files' cannot be empty`);
769
+ }
753
770
  const writer = createStringWriter();
754
- writer.writeLines(`// ${virtualFilePrefix}/${route.entryName}.marko`);
771
+ writer.writeLines(`// ${virtualFilePrefix}/${name}.marko`);
755
772
  writer.branch("imports");
756
773
  writer.writeLines("");
757
- writeRouteTemplateTag(writer, [...route.layouts, route.page]);
774
+ writeEntryTemplateTag(writer, files);
758
775
  return writer.end();
759
776
  }
760
- function writeRouteTemplateTag(writer, [file, ...rest], index = 1) {
777
+ function writeEntryTemplateTag(writer, [file, ...rest], index = 1) {
761
778
  if (file) {
762
779
  const isLast = !rest.length;
763
780
  const tag = isLast ? "page" : `layout${index}`;
764
- writer.branch("imports").writeLines(`import ${tag} from './${file.importPath}';`);
781
+ writer.branch("imports").writeLines(`import ${tag} from '${file}';`);
765
782
  if (isLast) {
766
- writer.writeLines(`<${tag} ...input />`);
783
+ writer.writeLines(`<${tag} ...input/>`);
767
784
  } else {
768
785
  writer.writeBlockStart(`<${tag} ...input>`);
769
- writeRouteTemplateTag(writer, rest, index + 1);
786
+ writeEntryTemplateTag(writer, rest, index + 1);
770
787
  writer.writeBlockEnd(`</>`);
771
788
  }
772
789
  }
@@ -798,7 +815,9 @@ function renderRouteEntry(route) {
798
815
  }
799
816
  if (runtimeImports.length) {
800
817
  imports.writeLines(
801
- `import { ${runtimeImports.join(", ")} } from '${virtualRuntimePrefix}';`
818
+ `import { ${runtimeImports.join(
819
+ ", "
820
+ )} } from '${virtualFilePrefix}/runtime/internal';`
802
821
  );
803
822
  }
804
823
  if (middleware.length) {
@@ -912,6 +931,45 @@ function writeRouteEntryHandler(writer, route, verb) {
912
931
  continuations.join();
913
932
  writer.writeBlockEnd("}");
914
933
  }
934
+ function renderErrorRouter(error, options = {
935
+ trailingSlashes: "RedirectWithout"
936
+ }) {
937
+ const writer = createStringWriter();
938
+ writer.write(`
939
+ // @marko/run/router
940
+ import { createContext } from '${virtualFilePrefix}/runtime/internal';
941
+ import errorPage from '${virtualFilePrefix}/${markoRunFilePrefix}error.marko${serverEntryQuery}';
942
+
943
+ const error = new Error(\`${error.message}\`);
944
+ error.name = '${error.name}';`);
945
+ if (error.stack) {
946
+ writer.write(`
947
+ error.stack = \`${error.stack}\`;`);
948
+ }
949
+ writer.write(`
950
+
951
+ globalThis.__marko_run__ = { match, fetch, invoke };
952
+
953
+ export function match() {
954
+ return { handler: errorPage, params: {}, meta: {}, path: '/*' }; // /$$
955
+ }
956
+
957
+ export async function invoke(route, request, platform, url) {
958
+ const [context, buildInput] = createContext(route, request, platform, url);
959
+ if (context.request.headers.get('Accept')?.includes('text/html')) {
960
+ return new Response(errorPage.stream(buildInput({ error })), {
961
+ status: 500,
962
+ headers: { "content-type": "text/html;charset=UTF-8" },
963
+ });
964
+ }
965
+ return new Response(error, {
966
+ status: 500,
967
+ });
968
+ }
969
+ `);
970
+ renderFetch(writer, options);
971
+ return writer.end();
972
+ }
915
973
  function renderRouter(routes, options = {
916
974
  trailingSlashes: "RedirectWithout"
917
975
  }) {
@@ -919,7 +977,7 @@ function renderRouter(routes, options = {
919
977
  writer.writeLines(`// @marko/run/router`);
920
978
  const imports = writer.branch("imports");
921
979
  imports.writeLines(
922
- `import { NotHandled, NotMatched, createContext } from 'virtual:marko-run/internal';`
980
+ `import { NotHandled, NotMatched, createContext } from '${virtualFilePrefix}/runtime/internal';`
923
981
  );
924
982
  for (const route of routes.list) {
925
983
  const verbs = getVerbs(route);
@@ -955,24 +1013,24 @@ globalThis.__marko_run__ = { match, fetch, invoke };
955
1013
  }
956
1014
  }
957
1015
  writer.writeBlockEnd("}").writeLines("return null;").writeBlockEnd("}");
958
- writer.write(`
959
- export async function invoke(route, request, platform, url) {
960
- const [context, buildInput] = createContext(route, request, platform, url);
961
- try {
962
- if (route) {
963
- try {
964
- const response = await route.handler(context, buildInput);
965
- if (response) return response;
966
- } catch (error) {
967
- if (error === NotHandled) {
968
- return;
969
- } else if (error !== NotMatched) {
970
- throw error;
971
- }
972
- }
973
- `);
1016
+ writer.writeLines("").writeBlockStart(
1017
+ "export async function invoke(route, request, platform, url) {"
1018
+ ).writeLines(
1019
+ "const [context, buildInput] = createContext(route, request, platform, url);"
1020
+ );
1021
+ const hasErrorPage = Boolean(routes.special[RoutableFileTypes.Error]);
1022
+ if (hasErrorPage) {
1023
+ writer.writeBlockStart("try {");
1024
+ }
1025
+ writer.writeBlockStart("if (route) {").writeBlockStart("try {").writeLines(
1026
+ "const response = await route.handler(context, buildInput);",
1027
+ "if (response) return response;"
1028
+ ).indent--;
1029
+ writer.writeBlockStart("} catch (error) {").writeLines(
1030
+ "if (error === NotHandled) return;",
1031
+ "if (error !== NotMatched) throw error;"
1032
+ ).writeBlockEnd("}").writeBlockEnd("}");
974
1033
  if (routes.special[RoutableFileTypes.NotFound]) {
975
- writer.indent = 2;
976
1034
  imports.writeLines(
977
1035
  `
978
1036
  const page404ResponseInit = {
@@ -980,33 +1038,31 @@ const page404ResponseInit = {
980
1038
  headers: { "content-type": "text/html;charset=UTF-8" },
981
1039
  };`
982
1040
  );
983
- writer.write(
984
- ` } else {
985
- }
1041
+ writer.write(`
986
1042
  if (context.request.headers.get('Accept')?.includes('text/html')) {
987
1043
  return new Response(page404.stream(buildInput()), page404ResponseInit);
988
1044
  }
989
- `
990
- );
991
- } else {
992
- writer.indent = 3;
993
- writer.writeBlockEnd("}");
1045
+ `);
994
1046
  }
995
1047
  writer.indent--;
996
- writer.writeBlockStart(`} catch (error) {`);
997
- if (routes.special[RoutableFileTypes.Error]) {
1048
+ if (hasErrorPage) {
998
1049
  imports.writeLines(`
999
1050
  const page500ResponseInit = {
1000
1051
  status: 500,
1001
1052
  headers: { "content-type": "text/html;charset=UTF-8" },
1002
1053
  };`);
1003
- writer.writeBlockStart(
1054
+ writer.writeBlockStart(`} catch (error) {`).writeBlockStart(
1004
1055
  `if (context.request.headers.get('Accept')?.includes('text/html')) {`
1005
1056
  ).writeLines(
1006
1057
  `return new Response(page500.stream(buildInput({ error })), page500ResponseInit);`
1007
- ).writeBlockEnd("}");
1058
+ ).writeBlockEnd("}").writeLines("throw error;").writeBlockEnd("}");
1008
1059
  }
1009
- writer.writeLines(`throw error;`).writeBlockEnd("}").writeBlockEnd("}").write(`
1060
+ writer.writeBlockEnd("}");
1061
+ renderFetch(writer, options);
1062
+ return writer.end();
1063
+ }
1064
+ function renderFetch(writer, options) {
1065
+ writer.write(`
1010
1066
  export async function fetch(request, platform) {
1011
1067
  try {
1012
1068
  const url = new URL(request.url);
@@ -1044,15 +1100,22 @@ export async function fetch(request, platform) {
1044
1100
  const route = match(request.method, pathname);
1045
1101
  return await invoke(route, request, platform, url);
1046
1102
  } catch (error) {
1047
- const body = import.meta.env.DEV
1048
- ? error.stack || error.message || "Internal Server Error"
1049
- : null;
1050
- return new Response(body, {
1103
+ if (import.meta.env.DEV) {
1104
+ let body;
1105
+ if (error.cause) {
1106
+ body = error.cause.stack || error.cause.message || error.cause;
1107
+ } else {
1108
+ body = error.stack || error.message || "Internal Server Error";
1109
+ }
1110
+ return new Response(body, {
1111
+ status: 500
1112
+ });
1113
+ }
1114
+ return new Response(null, {
1051
1115
  status: 500
1052
1116
  });
1053
1117
  }
1054
1118
  }`);
1055
- return writer.end();
1056
1119
  }
1057
1120
  function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1058
1121
  const { route, dynamic, catchAll } = trie;
@@ -1174,7 +1237,12 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1174
1237
  }
1175
1238
  if (catchAll) {
1176
1239
  writer.writeLines(
1177
- `return ${renderMatch(verb, catchAll.route, catchAll.path, String(offset))}; // ${catchAll.path.path}`
1240
+ `return ${renderMatch(
1241
+ verb,
1242
+ catchAll.route,
1243
+ catchAll.path,
1244
+ String(offset)
1245
+ )}; // ${catchAll.path.path}`
1178
1246
  );
1179
1247
  } else if (level === 0) {
1180
1248
  writer.writeLines("return null;");
@@ -1216,7 +1284,9 @@ function renderMiddleware(middleware) {
1216
1284
  `// ${virtualFilePrefix}/${markoRunFilePrefix}middleware.js`
1217
1285
  );
1218
1286
  const imports = writer.branch("imports");
1219
- imports.writeLines(`import { normalize } from 'virtual:marko-run/internal';`);
1287
+ imports.writeLines(
1288
+ `import { normalize } from '${virtualFilePrefix}/runtime/internal';`
1289
+ );
1220
1290
  writer.writeLines("");
1221
1291
  for (const { id, importPath } of middleware) {
1222
1292
  const importName = `middleware${id}`;
@@ -1534,7 +1604,9 @@ function logRoutesTable(routes, bundle, options) {
1534
1604
  entryType.push(import_kleur.default.yellow("page"));
1535
1605
  size = prettySize(computeRouteSize(getRouteChunkName(route), bundle));
1536
1606
  }
1537
- const row = [import_kleur.default.bold(HttpVerbColors[verb](verb.toUpperCase()))];
1607
+ const row = [
1608
+ import_kleur.default.bold(HttpVerbColors[verb](verb.toUpperCase()))
1609
+ ];
1538
1610
  if (verbs.length === 1 || firstRow) {
1539
1611
  row.push({ rowSpan: verbs.length, content: prettyPath(path3.path) });
1540
1612
  firstRow = false;
@@ -1572,10 +1644,7 @@ function byteSize(source) {
1572
1644
  }
1573
1645
  function computeChunkSize(chunk, bundle, seen = /* @__PURE__ */ new Set()) {
1574
1646
  if (chunk.type === "asset") {
1575
- return [
1576
- byteSize(chunk.source),
1577
- gzipSize(chunk.source)
1578
- ];
1647
+ return [byteSize(chunk.source), gzipSize(chunk.source)];
1579
1648
  }
1580
1649
  const size = [byteSize(chunk.code), gzipSize(chunk.code)];
1581
1650
  for (const id of chunk.imports) {
@@ -1622,7 +1691,6 @@ var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, Plug
1622
1691
  var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
1623
1692
 
1624
1693
  // src/vite/plugin.ts
1625
- var import_url2 = require("url");
1626
1694
  var __dirname = import_path2.default.dirname((0, import_url2.fileURLToPath)(__importMetaURL));
1627
1695
  var PLUGIN_NAME_PREFIX = "marko-run-vite";
1628
1696
  var POSIX_SEP = "/";
@@ -1655,14 +1723,14 @@ function markoRun(opts = {}) {
1655
1723
  routesBuild: 0,
1656
1724
  routesRender: 0
1657
1725
  };
1658
- async function writeTypesFile() {
1659
- if (tsConfigExists ?? (tsConfigExists = await globFileExists(
1726
+ async function writeTypesFile(routes2) {
1727
+ if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
1660
1728
  root,
1661
1729
  "{.tsconfig*,tsconfig*.json}"
1662
- ))) {
1730
+ )))) {
1663
1731
  const filepath = import_path2.default.join(typesDir, "routes.d.ts");
1664
1732
  const data = await renderRouteTypeInfo(
1665
- routes,
1733
+ routes2,
1666
1734
  normalizePath(import_path2.default.relative(typesDir, resolvedRoutesDir)),
1667
1735
  adapter
1668
1736
  );
@@ -1672,65 +1740,93 @@ function markoRun(opts = {}) {
1672
1740
  }
1673
1741
  }
1674
1742
  }
1675
- async function setVirtualFiles(render = false) {
1676
- for (const route of routes.list) {
1677
- if (render && route.handler) {
1678
- route.handler.verbs = await extractVerbs(route.handler.filePath);
1679
- if (!route.handler.verbs.length) {
1680
- console.warn(
1681
- `Did not find any valid exports in middleware entry file:'${route.handler.filePath}' - expected to find any of 'GET', 'POST', 'PUT' or 'DELETE'`
1743
+ const buildVirtualFiles = single(async (render) => {
1744
+ var _a;
1745
+ const routerOptions = {
1746
+ trailingSlashes: opts.trailingSlashes || "RedirectWithout"
1747
+ };
1748
+ try {
1749
+ if (isStale) {
1750
+ virtualFiles.clear();
1751
+ isRendered = false;
1752
+ const buildStartTime = performance.now();
1753
+ routes = await buildRoutes(
1754
+ createFSWalker(resolvedRoutesDir),
1755
+ routesDir
1756
+ );
1757
+ times.routesBuild = performance.now() - buildStartTime;
1758
+ if (!routes.list.length) {
1759
+ throw new Error("No routes generated");
1760
+ }
1761
+ }
1762
+ const renderStartTime = performance.now();
1763
+ for (const route of routes.list) {
1764
+ if (render && route.handler) {
1765
+ route.handler.verbs = await extractVerbs(route.handler.filePath);
1766
+ if (!route.handler.verbs.length) {
1767
+ throw new Error(
1768
+ `Did not find any valid exports in middleware entry file:'${route.handler.filePath}' - expected to find any of 'GET', 'POST', 'PUT' or 'DELETE'`
1769
+ );
1770
+ }
1771
+ }
1772
+ if (route.page) {
1773
+ virtualFiles.set(
1774
+ import_path2.default.posix.join(root, `${route.entryName}.marko`),
1775
+ render ? renderRouteTemplate(route) : ""
1682
1776
  );
1683
1777
  }
1778
+ virtualFiles.set(
1779
+ import_path2.default.posix.join(root, `${route.entryName}.js`),
1780
+ render ? renderRouteEntry(route) : ""
1781
+ );
1684
1782
  }
1685
- if (route.page) {
1783
+ for (const route of Object.values(routes.special)) {
1686
1784
  virtualFiles.set(
1687
1785
  import_path2.default.posix.join(root, `${route.entryName}.marko`),
1688
1786
  render ? renderRouteTemplate(route) : ""
1689
1787
  );
1690
1788
  }
1789
+ if (routes.middleware.length) {
1790
+ virtualFiles.set(
1791
+ import_path2.default.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1792
+ render ? renderMiddleware(routes.middleware) : ""
1793
+ );
1794
+ }
1691
1795
  virtualFiles.set(
1692
- import_path2.default.posix.join(root, `${route.entryName}.js`),
1693
- render ? renderRouteEntry(route) : ""
1796
+ "@marko/run/router",
1797
+ render ? renderRouter(routes, routerOptions) : ""
1694
1798
  );
1695
- }
1696
- for (const route of Object.values(routes.special)) {
1799
+ times.routesRender = performance.now() - renderStartTime;
1800
+ if (render) {
1801
+ await writeTypesFile(routes);
1802
+ if (!isBuild) {
1803
+ await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
1804
+ }
1805
+ isRendered = true;
1806
+ }
1807
+ } catch (err) {
1808
+ if (isBuild) {
1809
+ throw err;
1810
+ }
1811
+ console.error(err);
1697
1812
  virtualFiles.set(
1698
- import_path2.default.posix.join(root, `${route.entryName}.marko`),
1699
- render ? renderRouteTemplate(route) : ""
1813
+ import_path2.default.posix.join(root, `${markoRunFilePrefix}error.marko`),
1814
+ renderEntryTemplate(`${markoRunFilePrefix}error`, ["<dev-error-page>"])
1700
1815
  );
1816
+ virtualFiles.set(
1817
+ "@marko/run/router",
1818
+ renderErrorRouter(err, routerOptions)
1819
+ );
1820
+ isRendered = true;
1701
1821
  }
1702
- virtualFiles.set(
1703
- "@marko/run/router",
1704
- render ? renderRouter(routes, {
1705
- trailingSlashes: opts.trailingSlashes || "RedirectWithout"
1706
- }) : ""
1707
- );
1708
- virtualFiles.set(
1709
- import_path2.default.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1710
- render ? renderMiddleware(routes.middleware) : ""
1711
- );
1712
- }
1713
- const buildVirtualFiles = single(async () => {
1714
- const startTime = performance.now();
1715
- routes = await buildRoutes(createFSWalker(resolvedRoutesDir), routesDir);
1716
- times.routesBuild = performance.now() - startTime;
1717
- await setVirtualFiles(false);
1718
1822
  isStale = false;
1719
- isRendered = false;
1720
- });
1721
- const renderVirtualFiles = single(async () => {
1722
- const startTime = performance.now();
1723
- await setVirtualFiles(true);
1724
- await writeTypesFile();
1725
- times.routesRender = performance.now() - startTime;
1726
- isRendered = true;
1727
1823
  });
1728
1824
  return [
1729
1825
  {
1730
1826
  name: `${PLUGIN_NAME_PREFIX}:pre`,
1731
1827
  enforce: "pre",
1732
1828
  async config(config2, env) {
1733
- var _a, _b, _c, _d, _e, _f;
1829
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1734
1830
  const externalPluginOptions = getExternalPluginOptions(config2);
1735
1831
  if (externalPluginOptions) {
1736
1832
  opts = (0, import_vite.mergeConfig)(opts, externalPluginOptions);
@@ -1756,6 +1852,11 @@ function markoRun(opts = {}) {
1756
1852
  }
1757
1853
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
1758
1854
  compiler.taglib.register("@marko/run", {
1855
+ "<dev-error-page>": {
1856
+ template: normalizePath(
1857
+ import_path2.default.resolve(__dirname, "../components/dev-error-page.marko")
1858
+ )
1859
+ },
1759
1860
  "<*>": {
1760
1861
  transform: import_path2.default.resolve(
1761
1862
  __dirname,
@@ -1820,11 +1921,26 @@ function markoRun(opts = {}) {
1820
1921
  noExternal: /@marko\/run/
1821
1922
  },
1822
1923
  build: {
1924
+ target: isBuild && !((_g = config2.build) == null ? void 0 : _g.target) ? (0, import_esbuild_plugin_browserslist.resolveToEsbuildTarget)(
1925
+ (0, import_browserslist.default)(void 0, {
1926
+ path: root
1927
+ }),
1928
+ { printUnknownTargets: false }
1929
+ ) : void 0,
1823
1930
  emptyOutDir: isSSRBuild,
1931
+ // Avoid server & client deleting files from each other.
1824
1932
  rollupOptions: {
1825
1933
  output: rollupOutputOptions
1826
1934
  }
1827
1935
  },
1936
+ optimizeDeps: {
1937
+ entries: !((_h = config2.optimizeDeps) == null ? void 0 : _h.entries) ? [
1938
+ "src/pages/**/*+{page,layout}.marko",
1939
+ "!**/__snapshots__/**",
1940
+ `!**/__tests__/**`,
1941
+ `!**/coverage/**`
1942
+ ] : void 0
1943
+ },
1828
1944
  resolve: isBuild ? {
1829
1945
  browserField: isSSRBuild ? false : void 0,
1830
1946
  conditions: [
@@ -1909,40 +2025,35 @@ function markoRun(opts = {}) {
1909
2025
  },
1910
2026
  async resolveId(importee, importer) {
1911
2027
  let resolved;
1912
- if (importee.startsWith(virtualRuntimePrefix)) {
1913
- return this.resolve(
1914
- import_path2.default.resolve(__dirname, "../runtime/internal"),
1915
- importer,
1916
- { skipSelf: true }
1917
- );
1918
- } else if (importee.startsWith(virtualFilePrefix)) {
1919
- importee = import_path2.default.resolve(
1920
- root,
1921
- importee.slice(virtualFilePrefix.length + 1)
1922
- );
2028
+ let virtualFilePath;
2029
+ if (importee.startsWith(virtualFilePrefix)) {
2030
+ virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
2031
+ importee = import_path2.default.resolve(root, virtualFilePath);
1923
2032
  } else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
1924
2033
  importee = import_path2.default.resolve(root, "." + importee);
1925
2034
  }
1926
2035
  importee = normalizePath(importee);
1927
2036
  if (isStale) {
1928
- await buildVirtualFiles();
2037
+ await buildVirtualFiles(false);
1929
2038
  }
1930
2039
  if (virtualFiles.has(importee)) {
1931
2040
  resolved = importee;
2041
+ } else if (virtualFilePath) {
2042
+ const filePath = import_path2.default.resolve(__dirname, "..", virtualFilePath);
2043
+ const resolution = await this.resolve(filePath, importer, {
2044
+ skipSelf: true
2045
+ });
2046
+ return resolution;
1932
2047
  }
1933
2048
  return resolved || null;
1934
2049
  },
1935
2050
  async load(id) {
1936
- var _a;
1937
2051
  if (id.endsWith(serverEntryQuery)) {
1938
2052
  id = id.slice(0, -serverEntryQuery.length);
1939
2053
  }
1940
2054
  if (virtualFiles.has(id)) {
1941
- if (!isRendered) {
1942
- await renderVirtualFiles();
1943
- if (!isBuild) {
1944
- await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
1945
- }
2055
+ if (isStale || !isRendered) {
2056
+ await buildVirtualFiles(true);
1946
2057
  }
1947
2058
  return virtualFiles.get(id);
1948
2059
  }
@@ -1985,12 +2096,12 @@ function markoRun(opts = {}) {
1985
2096
  }
1986
2097
  await store.set(routeDataFilename, JSON.stringify(routeData));
1987
2098
  await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
1988
- } else if (isBuild) {
2099
+ } else {
1989
2100
  logRoutesTable(routes, bundle, options);
1990
2101
  }
1991
2102
  },
1992
2103
  async closeBundle() {
1993
- if (isBuild && !isSSRBuild && (adapter == null ? void 0 : adapter.buildEnd)) {
2104
+ if (isBuild && !isSSRBuild && (adapter == null ? void 0 : adapter.buildEnd) && routes) {
1994
2105
  await adapter.buildEnd(
1995
2106
  resolvedConfig,
1996
2107
  routes.list,