@marko/run 0.4.12 → 0.5.1

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.
@@ -705,16 +705,19 @@ function hasVerb(route, verb) {
705
705
  }
706
706
 
707
707
  // src/vite/codegen/index.ts
708
- function renderRouteTemplate(route) {
708
+ function renderRouteTemplate(route, getRelativePath) {
709
709
  if (!route.page) {
710
710
  throw new Error(`Route ${route.key} has no page to render`);
711
711
  }
712
712
  return renderEntryTemplate(
713
713
  route.entryName,
714
- [...route.layouts, route.page].map((file) => `./${file.importPath}`)
714
+ [...route.layouts, route.page].map(
715
+ (file) => getRelativePath(file.importPath)
716
+ ),
717
+ route.key === RoutableFileTypes.Error ? ["error"] : []
715
718
  );
716
719
  }
717
- function renderEntryTemplate(name, files) {
720
+ function renderEntryTemplate(name, files, pageInputs = []) {
718
721
  if (!name) {
719
722
  throw new Error(`Invalid argument - 'name' cannot be empty`);
720
723
  }
@@ -722,27 +725,28 @@ function renderEntryTemplate(name, files) {
722
725
  throw new Error(`Invalid argument - 'files' cannot be empty`);
723
726
  }
724
727
  const writer = createStringWriter();
725
- writer.writeLines(`// ${virtualFilePrefix}/${name}.marko`);
728
+ writer.writeLines(`// ${name}.marko`);
726
729
  writer.branch("imports");
727
730
  writer.writeLines("");
728
- writeEntryTemplateTag(writer, files);
731
+ writeEntryTemplateTag(writer, files, pageInputs);
729
732
  return writer.end();
730
733
  }
731
- function writeEntryTemplateTag(writer, [file, ...rest], index = 1) {
734
+ function writeEntryTemplateTag(writer, [file, ...rest], pageInputs, index = 1) {
732
735
  if (file) {
733
736
  const isLast = !rest.length;
734
- const tag = isLast ? "page" : `layout${index}`;
737
+ const tag = isLast ? "Page" : `Layout${index}`;
735
738
  writer.branch("imports").writeLines(`import ${tag} from '${file}';`);
736
739
  if (isLast) {
737
- writer.writeLines(`<${tag} ...input/>`);
740
+ const attributes = pageInputs.length ? " " + pageInputs.map((name) => `${name}=input.${name}`).join(" ") : "";
741
+ writer.writeLines(`<${tag}${attributes}/>`);
738
742
  } else {
739
- writer.writeBlockStart(`<${tag} ...input>`);
740
- writeEntryTemplateTag(writer, rest, index + 1);
743
+ writer.writeBlockStart(`<${tag}>`);
744
+ writeEntryTemplateTag(writer, rest, pageInputs, index + 1);
741
745
  writer.writeBlockEnd(`</>`);
742
746
  }
743
747
  }
744
748
  }
745
- function renderRouteEntry(route) {
749
+ function renderRouteEntry(route, entriesDir) {
746
750
  var _a;
747
751
  const { key, index, handler, page, middleware, meta, entryName } = route;
748
752
  const verbs = getVerbs(route);
@@ -795,9 +799,8 @@ function renderRouteEntry(route) {
795
799
  );
796
800
  }
797
801
  if (page) {
798
- imports.writeLines(
799
- `import page from '${virtualFilePrefix}/${entryName}.marko${serverEntryQuery}';`
800
- );
802
+ const importPath = route.layouts.length ? `./${entriesDir}/${entryName}.marko` : `./${page.importPath}`;
803
+ imports.writeLines(`import page from '${importPath}${serverEntryQuery}';`);
801
804
  }
802
805
  if (meta) {
803
806
  imports.writeLines(
@@ -885,7 +888,7 @@ function writeRouteEntryHandler(writer, route, verb) {
885
888
  continuations.join();
886
889
  writer.writeBlockEnd("}");
887
890
  }
888
- function renderRouter(routes, options = {
891
+ function renderRouter(routes, entriesDir, options = {
889
892
  trailingSlashes: "RedirectWithout"
890
893
  }) {
891
894
  const writer = createStringWriter();
@@ -902,9 +905,10 @@ function renderRouter(routes, options = {
902
905
  `import { ${names.join(", ")} } from '${virtualFilePrefix}/${route.entryName}.js';`
903
906
  );
904
907
  }
905
- for (const { key, entryName } of Object.values(routes.special)) {
908
+ for (const page of Object.values(routes.special)) {
909
+ const importPath = page.layouts.length ? `./${entriesDir}/${page.entryName}.marko` : `./${page.importPath}`;
906
910
  imports.writeLines(
907
- `import page${key} from '${virtualFilePrefix}/${entryName}.marko${serverEntryQuery}';`
911
+ `import page${page.key} from '${importPath}${serverEntryQuery}';`
908
912
  );
909
913
  }
910
914
  writer.writeLines(
@@ -1692,18 +1696,23 @@ function prepareError(err) {
1692
1696
  }
1693
1697
 
1694
1698
  // src/vite/plugin.ts
1699
+ import { createHash } from "crypto";
1695
1700
  var debug = createDebug("@marko/run");
1696
1701
  var __dirname = path3.dirname(fileURLToPath(import.meta.url));
1697
1702
  var PLUGIN_NAME_PREFIX = "marko-run-vite";
1698
1703
  var POSIX_SEP = "/";
1699
1704
  var WINDOWS_SEP = "\\";
1705
+ var CLIENT_OUT_DIR = "public";
1706
+ var MIDDLEWARE_FILENAME = `${markoRunFilePrefix}middleware.js`;
1707
+ var ROUTER_FILENAME = `${markoRunFilePrefix}router.js`;
1700
1708
  var normalizePath = path3.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
1701
1709
  function markoRun(opts = {}) {
1702
1710
  let { routesDir, adapter, ...markoVitePluginOptions } = opts;
1703
- let compiler;
1704
1711
  let store;
1705
1712
  let root;
1706
1713
  let resolvedRoutesDir;
1714
+ let entryFilesDir;
1715
+ let relativeEntryFilesDir;
1707
1716
  let typesDir;
1708
1717
  let isBuild = false;
1709
1718
  let isSSRBuild = false;
@@ -1723,6 +1732,9 @@ function markoRun(opts = {}) {
1723
1732
  routesBuild: 0,
1724
1733
  routesRender: 0
1725
1734
  };
1735
+ function getEntryFileRelativePath(to) {
1736
+ return path3.relative(entryFilesDir, to);
1737
+ }
1726
1738
  async function writeTypesFile(routes2) {
1727
1739
  if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
1728
1740
  root,
@@ -1753,27 +1765,12 @@ function markoRun(opts = {}) {
1753
1765
  throw new Error("No routes generated");
1754
1766
  }
1755
1767
  for (const route of routes.list) {
1756
- if (route.page) {
1757
- virtualFiles.set(
1758
- path3.posix.join(root, `${route.entryName}.marko`),
1759
- ""
1760
- );
1761
- }
1762
1768
  virtualFiles.set(path3.posix.join(root, `${route.entryName}.js`), "");
1763
1769
  }
1764
- for (const route of Object.values(routes.special)) {
1765
- virtualFiles.set(
1766
- path3.posix.join(root, `${route.entryName}.marko`),
1767
- ""
1768
- );
1769
- }
1770
1770
  if (routes.middleware.length) {
1771
- virtualFiles.set(
1772
- path3.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1773
- ""
1774
- );
1771
+ virtualFiles.set(path3.posix.join(root, MIDDLEWARE_FILENAME), "");
1775
1772
  }
1776
- virtualFiles.set("@marko/run/router", "");
1773
+ virtualFiles.set(path3.posix.join(root, ROUTER_FILENAME), "");
1777
1774
  resolve(routes);
1778
1775
  } catch (err) {
1779
1776
  reject(err);
@@ -1784,11 +1781,12 @@ function markoRun(opts = {}) {
1784
1781
  function renderVirtualFiles(context) {
1785
1782
  return renderVirtualFilesResult ?? (renderVirtualFilesResult = new Promise(async (resolve) => {
1786
1783
  var _a;
1787
- const routerOptions = {
1788
- trailingSlashes: opts.trailingSlashes || "RedirectWithout"
1789
- };
1790
1784
  try {
1791
1785
  const routes2 = await buildVirtualFiles();
1786
+ let entryFilesDirExists = false;
1787
+ if (fs3.existsSync(entryFilesDir)) {
1788
+ fs3.rmSync(entryFilesDir, { recursive: true });
1789
+ }
1792
1790
  for (const route of routes2.list) {
1793
1791
  if (route.handler) {
1794
1792
  const exports = await getExportsFromFile(
@@ -1808,22 +1806,30 @@ function markoRun(opts = {}) {
1808
1806
  );
1809
1807
  }
1810
1808
  }
1811
- if (route.page) {
1812
- virtualFiles.set(
1813
- path3.posix.join(root, `${route.entryName}.marko`),
1814
- renderRouteTemplate(route)
1809
+ if (route.page && route.layouts.length) {
1810
+ entryFilesDirExists || (entryFilesDirExists = !!fs3.mkdirSync(entryFilesDir, {
1811
+ recursive: true
1812
+ }));
1813
+ fs3.writeFileSync(
1814
+ path3.posix.join(entryFilesDir, `${route.entryName}.marko`),
1815
+ renderRouteTemplate(route, getEntryFileRelativePath)
1815
1816
  );
1816
1817
  }
1817
1818
  virtualFiles.set(
1818
1819
  path3.posix.join(root, `${route.entryName}.js`),
1819
- renderRouteEntry(route)
1820
+ renderRouteEntry(route, relativeEntryFilesDir)
1820
1821
  );
1821
1822
  }
1822
1823
  for (const route of Object.values(routes2.special)) {
1823
- virtualFiles.set(
1824
- path3.posix.join(root, `${route.entryName}.marko`),
1825
- renderRouteTemplate(route)
1826
- );
1824
+ if (route.layouts.length) {
1825
+ entryFilesDirExists || (entryFilesDirExists = !!fs3.mkdirSync(entryFilesDir, {
1826
+ recursive: true
1827
+ }));
1828
+ fs3.writeFileSync(
1829
+ path3.posix.join(entryFilesDir, `${route.entryName}.marko`),
1830
+ renderRouteTemplate(route, getEntryFileRelativePath)
1831
+ );
1832
+ }
1827
1833
  }
1828
1834
  if (routes2.middleware.length) {
1829
1835
  for (const middleware of routes2.middleware) {
@@ -1834,13 +1840,15 @@ function markoRun(opts = {}) {
1834
1840
  }
1835
1841
  }
1836
1842
  virtualFiles.set(
1837
- path3.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1843
+ path3.posix.join(root, MIDDLEWARE_FILENAME),
1838
1844
  renderMiddleware(routes2.middleware)
1839
1845
  );
1840
1846
  }
1841
1847
  virtualFiles.set(
1842
- "@marko/run/router",
1843
- renderRouter(routes2, routerOptions)
1848
+ path3.posix.join(root, ROUTER_FILENAME),
1849
+ renderRouter(routes2, relativeEntryFilesDir, {
1850
+ trailingSlashes: opts.trailingSlashes || "RedirectWithout"
1851
+ })
1844
1852
  );
1845
1853
  await writeTypesFile(routes2);
1846
1854
  if (adapter == null ? void 0 : adapter.routesGenerated) {
@@ -1861,7 +1869,7 @@ function markoRun(opts = {}) {
1861
1869
  throw err;
1862
1870
  }
1863
1871
  virtualFiles.set(
1864
- "@marko/run/router",
1872
+ path3.posix.join(root, ROUTER_FILENAME),
1865
1873
  `throw ${JSON.stringify(prepareError(err))}`
1866
1874
  );
1867
1875
  }
@@ -1873,7 +1881,7 @@ function markoRun(opts = {}) {
1873
1881
  name: `${PLUGIN_NAME_PREFIX}:pre`,
1874
1882
  enforce: "pre",
1875
1883
  async config(config2, env) {
1876
- var _a, _b, _c, _d, _e, _f, _g, _h;
1884
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1877
1885
  const externalPluginOptions = getExternalPluginOptions(config2);
1878
1886
  if (externalPluginOptions) {
1879
1887
  opts = mergeConfig(opts, externalPluginOptions);
@@ -1897,14 +1905,6 @@ function markoRun(opts = {}) {
1897
1905
  opts = mergeConfig(opts, adapterOptions);
1898
1906
  }
1899
1907
  }
1900
- compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
1901
- compiler.taglib.register("@marko/run", {
1902
- "<dev-error-page>": {
1903
- template: normalizePath(
1904
- path3.resolve(__dirname, "../components/dev-error-page.marko")
1905
- )
1906
- }
1907
- });
1908
1908
  routesDir = opts.routesDir || "src/routes";
1909
1909
  store = new ReadOncePersistedStore(
1910
1910
  `vite-marko-run${opts.runtimeId ? `-${opts.runtimeId}` : ""}`
@@ -1912,12 +1912,23 @@ function markoRun(opts = {}) {
1912
1912
  markoVitePluginOptions.runtimeId = opts.runtimeId;
1913
1913
  markoVitePluginOptions.basePathVar = opts.basePathVar;
1914
1914
  resolvedRoutesDir = path3.resolve(root, routesDir);
1915
+ const modulesDir = getModulesDir() || path3.join(root, "node_modules");
1916
+ entryFilesDir = path3.join(
1917
+ modulesDir,
1918
+ ".marko",
1919
+ createHash("shake256", { outputLength: 4 }).update(root).digest("hex")
1920
+ );
1921
+ relativeEntryFilesDir = path3.relative(root, entryFilesDir);
1915
1922
  typesDir = path3.join(root, ".marko-run");
1916
1923
  devEntryFile = path3.join(root, "index.html");
1917
1924
  devEntryFilePosix = normalizePath(devEntryFile);
1918
- const assetsDir = ((_d = config2.build) == null ? void 0 : _d.assetsDir) || "assets";
1919
- let rollupOutputOptions = (_f = (_e = config2.build) == null ? void 0 : _e.rollupOptions) == null ? void 0 : _f.output;
1925
+ let outDir = ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist";
1926
+ const assetsDir = ((_e = config2.build) == null ? void 0 : _e.assetsDir) || "assets";
1927
+ let rollupOutputOptions = (_g = (_f = config2.build) == null ? void 0 : _f.rollupOptions) == null ? void 0 : _g.output;
1920
1928
  if (isBuild) {
1929
+ if (!isSSRBuild) {
1930
+ outDir = path3.join(outDir, CLIENT_OUT_DIR);
1931
+ }
1921
1932
  const defaultRollupOutputOptions = {
1922
1933
  assetFileNames({ name }) {
1923
1934
  if (name && name.indexOf("_marko-virtual_id_") < 0) {
@@ -1953,7 +1964,7 @@ function markoRun(opts = {}) {
1953
1964
  }));
1954
1965
  }
1955
1966
  }
1956
- const browserslistTarget = isBuild && !((_g = config2.build) == null ? void 0 : _g.target) ? browserslist(void 0, {
1967
+ const browserslistTarget = isBuild && !((_h = config2.build) == null ? void 0 : _h.target) ? browserslist(void 0, {
1957
1968
  path: root
1958
1969
  }) : void 0;
1959
1970
  let pluginConfig = {
@@ -1968,19 +1979,22 @@ function markoRun(opts = {}) {
1968
1979
  devSourcemap: true
1969
1980
  },
1970
1981
  build: {
1982
+ outDir,
1983
+ assetsDir,
1971
1984
  target: (browserslistTarget == null ? void 0 : browserslistTarget.length) ? resolveToEsbuildTarget(browserslistTarget, {
1972
1985
  printUnknownTargets: false
1973
1986
  }) : void 0,
1974
1987
  emptyOutDir: isSSRBuild,
1975
1988
  // Avoid server & client deleting files from each other.
1976
- ssrEmitAssets: isSSRBuild,
1989
+ copyPublicDir: !isSSRBuild,
1990
+ ssrEmitAssets: false,
1977
1991
  rollupOptions: {
1978
1992
  output: rollupOutputOptions
1979
1993
  },
1980
1994
  modulePreload: { polyfill: false }
1981
1995
  },
1982
1996
  optimizeDeps: {
1983
- entries: !((_h = config2.optimizeDeps) == null ? void 0 : _h.entries) ? [
1997
+ entries: !((_i = config2.optimizeDeps) == null ? void 0 : _i.entries) ? [
1984
1998
  "src/pages/**/*+{page,layout}.marko",
1985
1999
  "!**/__snapshots__/**",
1986
2000
  `!**/__tests__/**`,
@@ -2090,7 +2104,9 @@ function markoRun(opts = {}) {
2090
2104
  async resolveId(importee, importer) {
2091
2105
  let resolved;
2092
2106
  let virtualFilePath;
2093
- if (importee.startsWith(virtualFilePrefix)) {
2107
+ if (importee === "@marko/run/router") {
2108
+ importee = path3.resolve(root, ROUTER_FILENAME);
2109
+ } else if (importee.startsWith(virtualFilePrefix)) {
2094
2110
  virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
2095
2111
  importee = path3.resolve(root, virtualFilePath);
2096
2112
  } else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
@@ -2120,7 +2136,7 @@ function markoRun(opts = {}) {
2120
2136
  }
2121
2137
  if (virtualFiles.has(id)) {
2122
2138
  return virtualFiles.get(id);
2123
- } else if (/[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
2139
+ } else if (!id.startsWith(entryFilesDir) && /[/\\]__marko-run__[^?/\\]+\.(js|marko)$/.exec(id)) {
2124
2140
  return "";
2125
2141
  }
2126
2142
  }
@@ -2254,6 +2270,12 @@ function getImporters(module, fileName, seen = /* @__PURE__ */ new Set()) {
2254
2270
  }
2255
2271
  return seen;
2256
2272
  }
2273
+ function getModulesDir(dir = __dirname) {
2274
+ const index = dir.indexOf("node_modules");
2275
+ if (index >= 0) {
2276
+ return dir.slice(0, index + 12);
2277
+ }
2278
+ }
2257
2279
 
2258
2280
  // src/vite/utils/server.ts
2259
2281
  import net from "net";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.4.12",
3
+ "version": "0.5.1",
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,8 +54,7 @@
54
54
  "types": "./dist/adapter/index.d.ts",
55
55
  "import": "./dist/adapter/index.js",
56
56
  "require": "./dist/adapter/index.cjs"
57
- },
58
- "./dist/components/dev-error-page.marko": "./dist/components/dev-error-page.marko"
57
+ }
59
58
  },
60
59
  "typesVersions": {
61
60
  "*": {
@@ -88,51 +87,51 @@
88
87
  "marko": "^5"
89
88
  },
90
89
  "devDependencies": {
91
- "@babel/types": "^7.25.6",
90
+ "@babel/types": "^7.26.0",
92
91
  "@marko/fixture-snapshots": "^2.2.1",
93
92
  "@marko/testing-library": "^6.2.0",
94
93
  "@types/glob": "^8.1.0",
95
94
  "@types/human-format": "^1.0.3",
96
95
  "@types/jsdom": "^21.1.7",
97
- "@types/mocha": "^10.0.8",
98
- "@types/node": "^22.7.0",
99
- "acorn": "^8.12.1",
96
+ "@types/mocha": "^10.0.10",
97
+ "@types/node": "^22.9.1",
98
+ "acorn": "^8.14.0",
100
99
  "body-parser": "^1.20.3",
101
100
  "cross-env": "^7.0.3",
101
+ "diff": "^7.0.0",
102
102
  "esbuild": "^0.24.0",
103
- "express": "^4.21.0",
103
+ "express": "^4.21.1",
104
104
  "jsdom": "^25.0.1",
105
- "mocha": "^10.7.3",
105
+ "mocha": "^10.8.2",
106
106
  "mocha-snap": "^5.0.0",
107
- "playwright": "^1.47.2",
107
+ "playwright": "^1.49.0",
108
108
  "prettier": "^3.3.3",
109
109
  "ts-mocha": "^10.0.0",
110
110
  "ts-node": "^10.9.2",
111
- "tslib": "^2.7.0",
112
- "tsx": "^4.19.1",
113
- "typescript": "^5.6.2"
111
+ "tslib": "^2.8.1",
112
+ "tsx": "^4.19.2",
113
+ "typescript": "^5.7.2"
114
114
  },
115
115
  "dependencies": {
116
- "@marko/compiler": "^5.37.13",
117
116
  "@marko/run-explorer": "^0.1.2",
118
- "@marko/vite": "^4.1.19",
119
- "browserslist": "^4.24.0",
117
+ "@marko/vite": "^5.0.5",
118
+ "browserslist": "^4.24.2",
120
119
  "cli-table3": "^0.6.5",
121
- "compression": "^1.7.4",
120
+ "compression": "^1.7.5",
122
121
  "debug": "^4.3.7",
123
122
  "dotenv": "^16.4.5",
124
123
  "draftlog": "^1.0.13",
125
- "esbuild-plugin-browserslist": "^0.14.0",
124
+ "esbuild-plugin-browserslist": "^0.15.0",
126
125
  "glob": "^11.0.0",
127
- "human-format": "^1.2.0",
126
+ "human-format": "^1.2.1",
128
127
  "kleur": "^4.1.5",
129
128
  "marko": "^5",
130
129
  "parse-node-args": "^1.1.2",
131
130
  "sade": "^1.8.1",
132
131
  "serve-static": "^1.16.2",
133
132
  "supports-color": "^9.4.0",
134
- "undici": "^6.19.8",
135
- "vite": "^5.4.8",
133
+ "undici": "^6.21.0",
134
+ "vite": "^5.4.11",
136
135
  "warp10": "^2.1.0"
137
136
  }
138
137
  }
@@ -1,14 +0,0 @@
1
- export interface Input {
2
- error: Error
3
- }
4
-
5
- <!doctype html>
6
- <html lang="en">
7
- <head>
8
- <meta charset="UTF-8">
9
- <title>${input.error.message}</title>
10
- </head>
11
- <body>
12
- <pre>${input.error.stack || (input.error.name + ': ' + input.error.message)}</pre>
13
- </body>
14
- </html>