@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.
@@ -28,14 +28,15 @@ import path2 from "path";
28
28
  import crypto from "crypto";
29
29
  import fs2 from "fs";
30
30
  import glob from "glob";
31
+ import { fileURLToPath } from "url";
32
+ import browserslist from "browserslist";
33
+ import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
31
34
  import { mergeConfig } from "vite";
32
35
  import markoVitePlugin, { FileStore } from "@marko/vite";
33
36
 
34
37
  // src/vite/constants.ts
35
38
  var markoRunFilePrefix = "__marko-run__";
36
39
  var virtualFilePrefix = "virtual:marko-run";
37
- var virtualRoutesPrefix = `${virtualFilePrefix}/routes`;
38
- var virtualRuntimePrefix = `${virtualFilePrefix}/internal`;
39
40
  var httpVerbs = ["get", "post", "put", "delete"];
40
41
  var serverEntryQuery = "?marko-server-entry";
41
42
  var RoutableFileTypes = {
@@ -50,7 +51,7 @@ var RoutableFileTypes = {
50
51
 
51
52
  // src/vite/routes/vdir.ts
52
53
  var _dirs, _pathlessDirs;
53
- var _VDir = class {
54
+ var _VDir = class _VDir {
54
55
  constructor(parent, segment, source) {
55
56
  __privateAdd(this, _dirs, void 0);
56
57
  __privateAdd(this, _pathlessDirs, void 0);
@@ -187,9 +188,9 @@ var _VDir = class {
187
188
  return dirs;
188
189
  }
189
190
  };
190
- var VDir = _VDir;
191
191
  _dirs = new WeakMap();
192
192
  _pathlessDirs = new WeakMap();
193
+ var VDir = _VDir;
193
194
 
194
195
  // src/vite/routes/parse.ts
195
196
  function parseFlatRoute(pattern) {
@@ -710,23 +711,35 @@ function renderRouteTemplate(route) {
710
711
  if (!route.page) {
711
712
  throw new Error(`Route ${route.key} has no page to render`);
712
713
  }
714
+ return renderEntryTemplate(
715
+ route.entryName,
716
+ [...route.layouts, route.page].map((file) => `./${file.importPath}`)
717
+ );
718
+ }
719
+ function renderEntryTemplate(name, files) {
720
+ if (!name) {
721
+ throw new Error(`Invalid argument - 'name' cannot be empty`);
722
+ }
723
+ if (!files.length) {
724
+ throw new Error(`Invalid argument - 'files' cannot be empty`);
725
+ }
713
726
  const writer = createStringWriter();
714
- writer.writeLines(`// ${virtualFilePrefix}/${route.entryName}.marko`);
727
+ writer.writeLines(`// ${virtualFilePrefix}/${name}.marko`);
715
728
  writer.branch("imports");
716
729
  writer.writeLines("");
717
- writeRouteTemplateTag(writer, [...route.layouts, route.page]);
730
+ writeEntryTemplateTag(writer, files);
718
731
  return writer.end();
719
732
  }
720
- function writeRouteTemplateTag(writer, [file, ...rest], index = 1) {
733
+ function writeEntryTemplateTag(writer, [file, ...rest], index = 1) {
721
734
  if (file) {
722
735
  const isLast = !rest.length;
723
736
  const tag = isLast ? "page" : `layout${index}`;
724
- writer.branch("imports").writeLines(`import ${tag} from './${file.importPath}';`);
737
+ writer.branch("imports").writeLines(`import ${tag} from '${file}';`);
725
738
  if (isLast) {
726
- writer.writeLines(`<${tag} ...input />`);
739
+ writer.writeLines(`<${tag} ...input/>`);
727
740
  } else {
728
741
  writer.writeBlockStart(`<${tag} ...input>`);
729
- writeRouteTemplateTag(writer, rest, index + 1);
742
+ writeEntryTemplateTag(writer, rest, index + 1);
730
743
  writer.writeBlockEnd(`</>`);
731
744
  }
732
745
  }
@@ -758,7 +771,9 @@ function renderRouteEntry(route) {
758
771
  }
759
772
  if (runtimeImports.length) {
760
773
  imports.writeLines(
761
- `import { ${runtimeImports.join(", ")} } from '${virtualRuntimePrefix}';`
774
+ `import { ${runtimeImports.join(
775
+ ", "
776
+ )} } from '${virtualFilePrefix}/runtime/internal';`
762
777
  );
763
778
  }
764
779
  if (middleware.length) {
@@ -872,6 +887,45 @@ function writeRouteEntryHandler(writer, route, verb) {
872
887
  continuations.join();
873
888
  writer.writeBlockEnd("}");
874
889
  }
890
+ function renderErrorRouter(error, options = {
891
+ trailingSlashes: "RedirectWithout"
892
+ }) {
893
+ const writer = createStringWriter();
894
+ writer.write(`
895
+ // @marko/run/router
896
+ import { createContext } from '${virtualFilePrefix}/runtime/internal';
897
+ import errorPage from '${virtualFilePrefix}/${markoRunFilePrefix}error.marko${serverEntryQuery}';
898
+
899
+ const error = new Error(\`${error.message}\`);
900
+ error.name = '${error.name}';`);
901
+ if (error.stack) {
902
+ writer.write(`
903
+ error.stack = \`${error.stack}\`;`);
904
+ }
905
+ writer.write(`
906
+
907
+ globalThis.__marko_run__ = { match, fetch, invoke };
908
+
909
+ export function match() {
910
+ return { handler: errorPage, params: {}, meta: {}, path: '/*' }; // /$$
911
+ }
912
+
913
+ export async function invoke(route, request, platform, url) {
914
+ const [context, buildInput] = createContext(route, request, platform, url);
915
+ if (context.request.headers.get('Accept')?.includes('text/html')) {
916
+ return new Response(errorPage.stream(buildInput({ error })), {
917
+ status: 500,
918
+ headers: { "content-type": "text/html;charset=UTF-8" },
919
+ });
920
+ }
921
+ return new Response(error, {
922
+ status: 500,
923
+ });
924
+ }
925
+ `);
926
+ renderFetch(writer, options);
927
+ return writer.end();
928
+ }
875
929
  function renderRouter(routes, options = {
876
930
  trailingSlashes: "RedirectWithout"
877
931
  }) {
@@ -879,7 +933,7 @@ function renderRouter(routes, options = {
879
933
  writer.writeLines(`// @marko/run/router`);
880
934
  const imports = writer.branch("imports");
881
935
  imports.writeLines(
882
- `import { NotHandled, NotMatched, createContext } from 'virtual:marko-run/internal';`
936
+ `import { NotHandled, NotMatched, createContext } from '${virtualFilePrefix}/runtime/internal';`
883
937
  );
884
938
  for (const route of routes.list) {
885
939
  const verbs = getVerbs(route);
@@ -915,24 +969,24 @@ globalThis.__marko_run__ = { match, fetch, invoke };
915
969
  }
916
970
  }
917
971
  writer.writeBlockEnd("}").writeLines("return null;").writeBlockEnd("}");
918
- writer.write(`
919
- export async function invoke(route, request, platform, url) {
920
- const [context, buildInput] = createContext(route, request, platform, url);
921
- try {
922
- if (route) {
923
- try {
924
- const response = await route.handler(context, buildInput);
925
- if (response) return response;
926
- } catch (error) {
927
- if (error === NotHandled) {
928
- return;
929
- } else if (error !== NotMatched) {
930
- throw error;
931
- }
932
- }
933
- `);
972
+ writer.writeLines("").writeBlockStart(
973
+ "export async function invoke(route, request, platform, url) {"
974
+ ).writeLines(
975
+ "const [context, buildInput] = createContext(route, request, platform, url);"
976
+ );
977
+ const hasErrorPage = Boolean(routes.special[RoutableFileTypes.Error]);
978
+ if (hasErrorPage) {
979
+ writer.writeBlockStart("try {");
980
+ }
981
+ writer.writeBlockStart("if (route) {").writeBlockStart("try {").writeLines(
982
+ "const response = await route.handler(context, buildInput);",
983
+ "if (response) return response;"
984
+ ).indent--;
985
+ writer.writeBlockStart("} catch (error) {").writeLines(
986
+ "if (error === NotHandled) return;",
987
+ "if (error !== NotMatched) throw error;"
988
+ ).writeBlockEnd("}").writeBlockEnd("}");
934
989
  if (routes.special[RoutableFileTypes.NotFound]) {
935
- writer.indent = 2;
936
990
  imports.writeLines(
937
991
  `
938
992
  const page404ResponseInit = {
@@ -940,33 +994,31 @@ const page404ResponseInit = {
940
994
  headers: { "content-type": "text/html;charset=UTF-8" },
941
995
  };`
942
996
  );
943
- writer.write(
944
- ` } else {
945
- }
997
+ writer.write(`
946
998
  if (context.request.headers.get('Accept')?.includes('text/html')) {
947
999
  return new Response(page404.stream(buildInput()), page404ResponseInit);
948
1000
  }
949
- `
950
- );
951
- } else {
952
- writer.indent = 3;
953
- writer.writeBlockEnd("}");
1001
+ `);
954
1002
  }
955
1003
  writer.indent--;
956
- writer.writeBlockStart(`} catch (error) {`);
957
- if (routes.special[RoutableFileTypes.Error]) {
1004
+ if (hasErrorPage) {
958
1005
  imports.writeLines(`
959
1006
  const page500ResponseInit = {
960
1007
  status: 500,
961
1008
  headers: { "content-type": "text/html;charset=UTF-8" },
962
1009
  };`);
963
- writer.writeBlockStart(
1010
+ writer.writeBlockStart(`} catch (error) {`).writeBlockStart(
964
1011
  `if (context.request.headers.get('Accept')?.includes('text/html')) {`
965
1012
  ).writeLines(
966
1013
  `return new Response(page500.stream(buildInput({ error })), page500ResponseInit);`
967
- ).writeBlockEnd("}");
1014
+ ).writeBlockEnd("}").writeLines("throw error;").writeBlockEnd("}");
968
1015
  }
969
- writer.writeLines(`throw error;`).writeBlockEnd("}").writeBlockEnd("}").write(`
1016
+ writer.writeBlockEnd("}");
1017
+ renderFetch(writer, options);
1018
+ return writer.end();
1019
+ }
1020
+ function renderFetch(writer, options) {
1021
+ writer.write(`
970
1022
  export async function fetch(request, platform) {
971
1023
  try {
972
1024
  const url = new URL(request.url);
@@ -1004,15 +1056,22 @@ export async function fetch(request, platform) {
1004
1056
  const route = match(request.method, pathname);
1005
1057
  return await invoke(route, request, platform, url);
1006
1058
  } catch (error) {
1007
- const body = import.meta.env.DEV
1008
- ? error.stack || error.message || "Internal Server Error"
1009
- : null;
1010
- return new Response(body, {
1059
+ if (import.meta.env.DEV) {
1060
+ let body;
1061
+ if (error.cause) {
1062
+ body = error.cause.stack || error.cause.message || error.cause;
1063
+ } else {
1064
+ body = error.stack || error.message || "Internal Server Error";
1065
+ }
1066
+ return new Response(body, {
1067
+ status: 500
1068
+ });
1069
+ }
1070
+ return new Response(null, {
1011
1071
  status: 500
1012
1072
  });
1013
1073
  }
1014
1074
  }`);
1015
- return writer.end();
1016
1075
  }
1017
1076
  function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1018
1077
  const { route, dynamic, catchAll } = trie;
@@ -1134,7 +1193,12 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1134
1193
  }
1135
1194
  if (catchAll) {
1136
1195
  writer.writeLines(
1137
- `return ${renderMatch(verb, catchAll.route, catchAll.path, String(offset))}; // ${catchAll.path.path}`
1196
+ `return ${renderMatch(
1197
+ verb,
1198
+ catchAll.route,
1199
+ catchAll.path,
1200
+ String(offset)
1201
+ )}; // ${catchAll.path.path}`
1138
1202
  );
1139
1203
  } else if (level === 0) {
1140
1204
  writer.writeLines("return null;");
@@ -1176,7 +1240,9 @@ function renderMiddleware(middleware) {
1176
1240
  `// ${virtualFilePrefix}/${markoRunFilePrefix}middleware.js`
1177
1241
  );
1178
1242
  const imports = writer.branch("imports");
1179
- imports.writeLines(`import { normalize } from 'virtual:marko-run/internal';`);
1243
+ imports.writeLines(
1244
+ `import { normalize } from '${virtualFilePrefix}/runtime/internal';`
1245
+ );
1180
1246
  writer.writeLines("");
1181
1247
  for (const { id, importPath } of middleware) {
1182
1248
  const importName = `middleware${id}`;
@@ -1494,7 +1560,9 @@ function logRoutesTable(routes, bundle, options) {
1494
1560
  entryType.push(kleur.yellow("page"));
1495
1561
  size = prettySize(computeRouteSize(getRouteChunkName(route), bundle));
1496
1562
  }
1497
- const row = [kleur.bold(HttpVerbColors[verb](verb.toUpperCase()))];
1563
+ const row = [
1564
+ kleur.bold(HttpVerbColors[verb](verb.toUpperCase()))
1565
+ ];
1498
1566
  if (verbs.length === 1 || firstRow) {
1499
1567
  row.push({ rowSpan: verbs.length, content: prettyPath(path3.path) });
1500
1568
  firstRow = false;
@@ -1532,10 +1600,7 @@ function byteSize(source) {
1532
1600
  }
1533
1601
  function computeChunkSize(chunk, bundle, seen = /* @__PURE__ */ new Set()) {
1534
1602
  if (chunk.type === "asset") {
1535
- return [
1536
- byteSize(chunk.source),
1537
- gzipSize(chunk.source)
1538
- ];
1603
+ return [byteSize(chunk.source), gzipSize(chunk.source)];
1539
1604
  }
1540
1605
  const size = [byteSize(chunk.code), gzipSize(chunk.code)];
1541
1606
  for (const id of chunk.imports) {
@@ -1582,7 +1647,6 @@ var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, Plug
1582
1647
  var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
1583
1648
 
1584
1649
  // src/vite/plugin.ts
1585
- import { fileURLToPath } from "url";
1586
1650
  var __dirname = path2.dirname(fileURLToPath(import.meta.url));
1587
1651
  var PLUGIN_NAME_PREFIX = "marko-run-vite";
1588
1652
  var POSIX_SEP = "/";
@@ -1615,14 +1679,14 @@ function markoRun(opts = {}) {
1615
1679
  routesBuild: 0,
1616
1680
  routesRender: 0
1617
1681
  };
1618
- async function writeTypesFile() {
1619
- if (tsConfigExists ?? (tsConfigExists = await globFileExists(
1682
+ async function writeTypesFile(routes2) {
1683
+ if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
1620
1684
  root,
1621
1685
  "{.tsconfig*,tsconfig*.json}"
1622
- ))) {
1686
+ )))) {
1623
1687
  const filepath = path2.join(typesDir, "routes.d.ts");
1624
1688
  const data = await renderRouteTypeInfo(
1625
- routes,
1689
+ routes2,
1626
1690
  normalizePath(path2.relative(typesDir, resolvedRoutesDir)),
1627
1691
  adapter
1628
1692
  );
@@ -1632,65 +1696,93 @@ function markoRun(opts = {}) {
1632
1696
  }
1633
1697
  }
1634
1698
  }
1635
- async function setVirtualFiles(render = false) {
1636
- for (const route of routes.list) {
1637
- if (render && route.handler) {
1638
- route.handler.verbs = await extractVerbs(route.handler.filePath);
1639
- if (!route.handler.verbs.length) {
1640
- console.warn(
1641
- `Did not find any valid exports in middleware entry file:'${route.handler.filePath}' - expected to find any of 'GET', 'POST', 'PUT' or 'DELETE'`
1699
+ const buildVirtualFiles = single(async (render) => {
1700
+ var _a;
1701
+ const routerOptions = {
1702
+ trailingSlashes: opts.trailingSlashes || "RedirectWithout"
1703
+ };
1704
+ try {
1705
+ if (isStale) {
1706
+ virtualFiles.clear();
1707
+ isRendered = false;
1708
+ const buildStartTime = performance.now();
1709
+ routes = await buildRoutes(
1710
+ createFSWalker(resolvedRoutesDir),
1711
+ routesDir
1712
+ );
1713
+ times.routesBuild = performance.now() - buildStartTime;
1714
+ if (!routes.list.length) {
1715
+ throw new Error("No routes generated");
1716
+ }
1717
+ }
1718
+ const renderStartTime = performance.now();
1719
+ for (const route of routes.list) {
1720
+ if (render && route.handler) {
1721
+ route.handler.verbs = await extractVerbs(route.handler.filePath);
1722
+ if (!route.handler.verbs.length) {
1723
+ throw new Error(
1724
+ `Did not find any valid exports in middleware entry file:'${route.handler.filePath}' - expected to find any of 'GET', 'POST', 'PUT' or 'DELETE'`
1725
+ );
1726
+ }
1727
+ }
1728
+ if (route.page) {
1729
+ virtualFiles.set(
1730
+ path2.posix.join(root, `${route.entryName}.marko`),
1731
+ render ? renderRouteTemplate(route) : ""
1642
1732
  );
1643
1733
  }
1734
+ virtualFiles.set(
1735
+ path2.posix.join(root, `${route.entryName}.js`),
1736
+ render ? renderRouteEntry(route) : ""
1737
+ );
1644
1738
  }
1645
- if (route.page) {
1739
+ for (const route of Object.values(routes.special)) {
1646
1740
  virtualFiles.set(
1647
1741
  path2.posix.join(root, `${route.entryName}.marko`),
1648
1742
  render ? renderRouteTemplate(route) : ""
1649
1743
  );
1650
1744
  }
1745
+ if (routes.middleware.length) {
1746
+ virtualFiles.set(
1747
+ path2.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1748
+ render ? renderMiddleware(routes.middleware) : ""
1749
+ );
1750
+ }
1651
1751
  virtualFiles.set(
1652
- path2.posix.join(root, `${route.entryName}.js`),
1653
- render ? renderRouteEntry(route) : ""
1752
+ "@marko/run/router",
1753
+ render ? renderRouter(routes, routerOptions) : ""
1654
1754
  );
1655
- }
1656
- for (const route of Object.values(routes.special)) {
1755
+ times.routesRender = performance.now() - renderStartTime;
1756
+ if (render) {
1757
+ await writeTypesFile(routes);
1758
+ if (!isBuild) {
1759
+ await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
1760
+ }
1761
+ isRendered = true;
1762
+ }
1763
+ } catch (err) {
1764
+ if (isBuild) {
1765
+ throw err;
1766
+ }
1767
+ console.error(err);
1657
1768
  virtualFiles.set(
1658
- path2.posix.join(root, `${route.entryName}.marko`),
1659
- render ? renderRouteTemplate(route) : ""
1769
+ path2.posix.join(root, `${markoRunFilePrefix}error.marko`),
1770
+ renderEntryTemplate(`${markoRunFilePrefix}error`, ["<dev-error-page>"])
1660
1771
  );
1772
+ virtualFiles.set(
1773
+ "@marko/run/router",
1774
+ renderErrorRouter(err, routerOptions)
1775
+ );
1776
+ isRendered = true;
1661
1777
  }
1662
- virtualFiles.set(
1663
- "@marko/run/router",
1664
- render ? renderRouter(routes, {
1665
- trailingSlashes: opts.trailingSlashes || "RedirectWithout"
1666
- }) : ""
1667
- );
1668
- virtualFiles.set(
1669
- path2.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1670
- render ? renderMiddleware(routes.middleware) : ""
1671
- );
1672
- }
1673
- const buildVirtualFiles = single(async () => {
1674
- const startTime = performance.now();
1675
- routes = await buildRoutes(createFSWalker(resolvedRoutesDir), routesDir);
1676
- times.routesBuild = performance.now() - startTime;
1677
- await setVirtualFiles(false);
1678
1778
  isStale = false;
1679
- isRendered = false;
1680
- });
1681
- const renderVirtualFiles = single(async () => {
1682
- const startTime = performance.now();
1683
- await setVirtualFiles(true);
1684
- await writeTypesFile();
1685
- times.routesRender = performance.now() - startTime;
1686
- isRendered = true;
1687
1779
  });
1688
1780
  return [
1689
1781
  {
1690
1782
  name: `${PLUGIN_NAME_PREFIX}:pre`,
1691
1783
  enforce: "pre",
1692
1784
  async config(config2, env) {
1693
- var _a, _b, _c, _d, _e, _f;
1785
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1694
1786
  const externalPluginOptions = getExternalPluginOptions(config2);
1695
1787
  if (externalPluginOptions) {
1696
1788
  opts = mergeConfig(opts, externalPluginOptions);
@@ -1716,6 +1808,11 @@ function markoRun(opts = {}) {
1716
1808
  }
1717
1809
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
1718
1810
  compiler.taglib.register("@marko/run", {
1811
+ "<dev-error-page>": {
1812
+ template: normalizePath(
1813
+ path2.resolve(__dirname, "../components/dev-error-page.marko")
1814
+ )
1815
+ },
1719
1816
  "<*>": {
1720
1817
  transform: path2.resolve(
1721
1818
  __dirname,
@@ -1780,11 +1877,26 @@ function markoRun(opts = {}) {
1780
1877
  noExternal: /@marko\/run/
1781
1878
  },
1782
1879
  build: {
1880
+ target: isBuild && !((_g = config2.build) == null ? void 0 : _g.target) ? resolveToEsbuildTarget(
1881
+ browserslist(void 0, {
1882
+ path: root
1883
+ }),
1884
+ { printUnknownTargets: false }
1885
+ ) : void 0,
1783
1886
  emptyOutDir: isSSRBuild,
1887
+ // Avoid server & client deleting files from each other.
1784
1888
  rollupOptions: {
1785
1889
  output: rollupOutputOptions
1786
1890
  }
1787
1891
  },
1892
+ optimizeDeps: {
1893
+ entries: !((_h = config2.optimizeDeps) == null ? void 0 : _h.entries) ? [
1894
+ "src/pages/**/*+{page,layout}.marko",
1895
+ "!**/__snapshots__/**",
1896
+ `!**/__tests__/**`,
1897
+ `!**/coverage/**`
1898
+ ] : void 0
1899
+ },
1788
1900
  resolve: isBuild ? {
1789
1901
  browserField: isSSRBuild ? false : void 0,
1790
1902
  conditions: [
@@ -1869,40 +1981,35 @@ function markoRun(opts = {}) {
1869
1981
  },
1870
1982
  async resolveId(importee, importer) {
1871
1983
  let resolved;
1872
- if (importee.startsWith(virtualRuntimePrefix)) {
1873
- return this.resolve(
1874
- path2.resolve(__dirname, "../runtime/internal"),
1875
- importer,
1876
- { skipSelf: true }
1877
- );
1878
- } else if (importee.startsWith(virtualFilePrefix)) {
1879
- importee = path2.resolve(
1880
- root,
1881
- importee.slice(virtualFilePrefix.length + 1)
1882
- );
1984
+ let virtualFilePath;
1985
+ if (importee.startsWith(virtualFilePrefix)) {
1986
+ virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
1987
+ importee = path2.resolve(root, virtualFilePath);
1883
1988
  } else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
1884
1989
  importee = path2.resolve(root, "." + importee);
1885
1990
  }
1886
1991
  importee = normalizePath(importee);
1887
1992
  if (isStale) {
1888
- await buildVirtualFiles();
1993
+ await buildVirtualFiles(false);
1889
1994
  }
1890
1995
  if (virtualFiles.has(importee)) {
1891
1996
  resolved = importee;
1997
+ } else if (virtualFilePath) {
1998
+ const filePath = path2.resolve(__dirname, "..", virtualFilePath);
1999
+ const resolution = await this.resolve(filePath, importer, {
2000
+ skipSelf: true
2001
+ });
2002
+ return resolution;
1892
2003
  }
1893
2004
  return resolved || null;
1894
2005
  },
1895
2006
  async load(id) {
1896
- var _a;
1897
2007
  if (id.endsWith(serverEntryQuery)) {
1898
2008
  id = id.slice(0, -serverEntryQuery.length);
1899
2009
  }
1900
2010
  if (virtualFiles.has(id)) {
1901
- if (!isRendered) {
1902
- await renderVirtualFiles();
1903
- if (!isBuild) {
1904
- await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
1905
- }
2011
+ if (isStale || !isRendered) {
2012
+ await buildVirtualFiles(true);
1906
2013
  }
1907
2014
  return virtualFiles.get(id);
1908
2015
  }
@@ -1945,12 +2052,12 @@ function markoRun(opts = {}) {
1945
2052
  }
1946
2053
  await store.set(routeDataFilename, JSON.stringify(routeData));
1947
2054
  await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
1948
- } else if (isBuild) {
2055
+ } else {
1949
2056
  logRoutesTable(routes, bundle, options);
1950
2057
  }
1951
2058
  },
1952
2059
  async closeBundle() {
1953
- if (isBuild && !isSSRBuild && (adapter == null ? void 0 : adapter.buildEnd)) {
2060
+ if (isBuild && !isSSRBuild && (adapter == null ? void 0 : adapter.buildEnd) && routes) {
1954
2061
  await adapter.buildEnd(
1955
2062
  resolvedConfig,
1956
2063
  routes.list,
@@ -19,6 +19,7 @@ export interface StartDevOptions extends StartOptions {
19
19
  }
20
20
  export interface StartPreviewOptions extends StartOptions {
21
21
  dir: string;
22
+ sourceEntry?: string;
22
23
  }
23
24
  export interface Adapter {
24
25
  readonly name: string;
@@ -71,11 +72,11 @@ export interface RoutableFile {
71
72
  importPath: string;
72
73
  verbs?: HttpVerb[];
73
74
  }
74
- export interface BuiltRoutes {
75
+ export type BuiltRoutes = {
75
76
  list: Route[];
76
77
  special: SpecialRoutes;
77
78
  middleware: RoutableFile[];
78
- }
79
+ };
79
80
  export interface PackageData {
80
81
  name?: string;
81
82
  version?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "The Marko application framework.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/marko-js/run/tree/main/packages/run",
@@ -54,7 +54,8 @@
54
54
  "types": "./dist/adapter/index.d.ts",
55
55
  "import": "./dist/adapter/index.js",
56
56
  "require": "./dist/adapter/index.cjs"
57
- }
57
+ },
58
+ "./dist/components/dev-error-page.marko": "./dist/components/dev-error-page.marko"
58
59
  },
59
60
  "typesVersions": {
60
61
  "*": {
@@ -91,40 +92,45 @@
91
92
  "@marko/fixture-snapshots": "^2.1.7",
92
93
  "@marko/testing-library": "^6.1.2",
93
94
  "@types/glob": "^8.0.1",
94
- "@types/human-format": "^1.0.0",
95
- "@types/jsdom": "^21.1.0",
95
+ "@types/human-format": "^1.0.2",
96
+ "@types/jsdom": "^21.1.4",
96
97
  "@types/mocha": "^9.1.1",
97
- "@types/node": "^20.3.1",
98
+ "@types/node": "^20.8.7",
98
99
  "acorn": "^8.8.0",
100
+ "body-parser": "^1.20.2",
99
101
  "cross-env": "^7.0.3",
100
- "esbuild": "^0.15.7",
102
+ "esbuild": "^0.19.5",
103
+ "express": "^4.18.2",
101
104
  "jsdom": "^21.1.1",
102
- "marko": "^5.23.0",
105
+ "marko": "^5.31.12",
103
106
  "mocha": "^10.2.0",
104
107
  "mocha-snap": "^4.3.0",
105
- "playwright": "^1.29.1",
108
+ "playwright": "^1.39.0",
106
109
  "prettier": "^2.7.1",
107
110
  "ts-mocha": "^10.0.0",
108
111
  "ts-node": "^10.9.1",
109
112
  "tslib": "^2.5.0",
110
113
  "tsm": "^2.3.0",
111
- "tsx": "^3.9.0",
114
+ "tsx": "^3.14.0",
112
115
  "typescript": "^4.7.4"
113
116
  },
114
117
  "dependencies": {
115
- "@marko/vite": "^3",
118
+ "@marko/vite": "^3.1.4",
119
+ "browserslist": "^4.22.1",
116
120
  "cli-table3": "^0.6.3",
117
121
  "compression": "^1.7.4",
118
122
  "dotenv": "^16.0.3",
123
+ "esbuild-plugin-browserslist": "^0.9.1",
119
124
  "glob": "^8.1.0",
120
- "human-format": "^1.0.0",
125
+ "human-format": "^1.0.2",
121
126
  "kleur": "^4.1.5",
122
127
  "parse-node-args": "^1.1.2",
123
128
  "sade": "^1.8.1",
124
129
  "serve-static": "^1.15.0",
125
130
  "strip-ansi": "^7.0.1",
126
- "undici": "^5.20.0",
127
- "vite": "^4.1.4",
131
+ "supports-color": "^9.4.0",
132
+ "undici": "^5.26.3",
133
+ "vite": "^4.5.0",
128
134
  "warp10": "^2.1.0"
129
135
  }
130
136
  }
@@ -1,2 +0,0 @@
1
- import type { Route, RouteTrie } from "../types";
2
- export declare function createRouteTrie(routes: Route[]): RouteTrie;