@marko/run 0.2.17 → 0.3.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.
@@ -24,15 +24,14 @@ var __privateSet = (obj, member, value, setter) => {
24
24
  };
25
25
 
26
26
  // src/vite/plugin.ts
27
- import path2 from "path";
28
- import crypto from "crypto";
29
- import fs2 from "fs";
27
+ import path3 from "path";
28
+ import fs3 from "fs";
30
29
  import { glob } from "glob";
31
30
  import { fileURLToPath } from "url";
32
31
  import browserslist from "browserslist";
33
32
  import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
34
33
  import { mergeConfig } from "vite";
35
- import markoVitePlugin, { FileStore } from "@marko/vite";
34
+ import markoVitePlugin from "@marko/vite";
36
35
 
37
36
  // src/vite/constants.ts
38
37
  var markoRunFilePrefix = "__marko-run__";
@@ -113,10 +112,10 @@ var _VDir = class _VDir {
113
112
  });
114
113
  return value;
115
114
  }
116
- addDir(path3, segment) {
115
+ addDir(path4, segment) {
117
116
  const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
118
117
  if (!map.has(segment.name)) {
119
- const dir = new _VDir(this, segment, path3);
118
+ const dir = new _VDir(this, segment, path4);
120
119
  map.set(segment.name, dir);
121
120
  return dir;
122
121
  }
@@ -162,10 +161,10 @@ var _VDir = class _VDir {
162
161
  const dirs = [];
163
162
  const unique = /* @__PURE__ */ new Set();
164
163
  for (const root of roots) {
165
- for (const path3 of paths) {
164
+ for (const path4 of paths) {
166
165
  let dir = root;
167
- for (const segment of path3.segments) {
168
- dir = dir.addDir(path3, segment);
166
+ for (const segment of path4.segments) {
167
+ dir = dir.addDir(path4, segment);
169
168
  }
170
169
  if (unique.has(dir.path)) {
171
170
  const sources = /* @__PURE__ */ new Set();
@@ -177,7 +176,7 @@ var _VDir = class _VDir {
177
176
  }
178
177
  }
179
178
  throw new Error(
180
- `Ambiguous directory structure: '${sourcePath}${path3.source}' defines '${dir.path}' multiple times.`
179
+ `Ambiguous directory structure: '${sourcePath}${path4.source}' defines '${dir.path}' multiple times.`
181
180
  );
182
181
  } else {
183
182
  unique.add(dir.path);
@@ -219,9 +218,9 @@ function parseFlatRoute(pattern) {
219
218
  } else if (charCode === 44) {
220
219
  if (!current) {
221
220
  segmentEnd(
222
- basePaths.map((path3) => ({
223
- ...path3,
224
- segments: path3.segments.slice()
221
+ basePaths.map((path4) => ({
222
+ ...path4,
223
+ segments: path4.segments.slice()
225
224
  })),
226
225
  "",
227
226
  "_",
@@ -251,9 +250,9 @@ function parseFlatRoute(pattern) {
251
250
  } else if (charCode === 36) {
252
251
  type = pattern.charCodeAt(i + 1) === 36 ? "$$" : "$";
253
252
  }
254
- current ?? (current = basePaths.map((path3) => ({
255
- ...path3,
256
- segments: path3.segments.slice()
253
+ current ?? (current = basePaths.map((path4) => ({
254
+ ...path4,
255
+ segments: path4.segments.slice()
257
256
  })));
258
257
  i = len;
259
258
  for (const char of delimiters) {
@@ -273,9 +272,9 @@ function parseFlatRoute(pattern) {
273
272
  }
274
273
  if (!current) {
275
274
  segmentEnd(
276
- basePaths.map((path3) => ({
277
- ...path3,
278
- segments: path3.segments.slice()
275
+ basePaths.map((path4) => ({
276
+ ...path4,
277
+ segments: path4.segments.slice()
279
278
  })),
280
279
  "",
281
280
  "_",
@@ -299,9 +298,9 @@ function parseFlatRoute(pattern) {
299
298
  segment.param = raw.slice(type.length);
300
299
  }
301
300
  }
302
- for (const path3 of paths) {
301
+ for (const path4 of paths) {
303
302
  if (segment) {
304
- if (path3.isCatchall) {
303
+ if (path4.isCatchall) {
305
304
  throw new Error(
306
305
  `Invalid route pattern: nested segments are not allowed after a catch-all parameter. Found '.' following '${pattern.slice(
307
306
  0,
@@ -309,22 +308,22 @@ function parseFlatRoute(pattern) {
309
308
  )}' in '${pattern}'.`
310
309
  );
311
310
  }
312
- path3.segments.push(segment);
313
- path3.id += path3.id === "/" ? segment.name : `/${segment.name}`;
311
+ path4.segments.push(segment);
312
+ path4.id += path4.id === "/" ? segment.name : `/${segment.name}`;
314
313
  if (type === "$$") {
315
- path3.isCatchall = true;
314
+ path4.isCatchall = true;
316
315
  }
317
316
  }
318
317
  if (map) {
319
- if (map.has(path3.id)) {
320
- const existing = map.get(path3.id);
318
+ if (map.has(path4.id)) {
319
+ const existing = map.get(path4.id);
321
320
  const existingExpansion = existing.segments.map((s) => s.raw).join(".");
322
- const currentExpansion = path3.segments.map((s) => s.raw).join(".");
321
+ const currentExpansion = path4.segments.map((s) => s.raw).join(".");
323
322
  throw new Error(
324
- `Invalid route pattern: route '${path3.id}' is ambiguous. Expansion '${currentExpansion}' collides with '${existingExpansion}' in '${pattern}'.`
323
+ `Invalid route pattern: route '${path4.id}' is ambiguous. Expansion '${currentExpansion}' collides with '${existingExpansion}' in '${pattern}'.`
325
324
  );
326
325
  }
327
- map.set(path3.id, path3);
326
+ map.set(path4.id, path4);
328
327
  }
329
328
  }
330
329
  }
@@ -380,7 +379,7 @@ async function buildRoutes(sources) {
380
379
  dirStack.length = prevDirStackLength;
381
380
  };
382
381
  },
383
- onFile({ name, path: path3 }) {
382
+ onFile({ name, path: path4 }) {
384
383
  const match = name.match(routeableFileRegex);
385
384
  if (!match) {
386
385
  return;
@@ -388,7 +387,7 @@ async function buildRoutes(sources) {
388
387
  const type = (match[1] || match[3]).toLowerCase();
389
388
  if (dirStack.length && isSpecialType(type)) {
390
389
  console.warn(
391
- `Special pages '${RoutableFileTypes.NotFound}' and '${RoutableFileTypes.Error}' are only considered in the root directory - ignoring ${path3}`
390
+ `Special pages '${RoutableFileTypes.NotFound}' and '${RoutableFileTypes.Error}' are only considered in the root directory - ignoring ${path4}`
392
391
  );
393
392
  return;
394
393
  }
@@ -403,7 +402,7 @@ async function buildRoutes(sources) {
403
402
  id: String(nextFileId++),
404
403
  name,
405
404
  type,
406
- filePath: path3,
405
+ filePath: path4,
407
406
  relativePath,
408
407
  importPath: `${importPrefix}/${relativePath}`,
409
408
  verbs: type === RoutableFileTypes.Page ? ["get"] : void 0
@@ -455,23 +454,23 @@ async function buildRoutes(sources) {
455
454
  }
456
455
  }
457
456
  if (page || handler) {
458
- const path3 = dir.pathInfo;
459
- if (uniqueRoutes.has(path3.id)) {
460
- const existing = uniqueRoutes.get(path3.id);
457
+ const path4 = dir.pathInfo;
458
+ if (uniqueRoutes.has(path4.id)) {
459
+ const existing = uniqueRoutes.get(path4.id);
461
460
  const route = routes[existing.index];
462
461
  const existingFiles = [route.handler, route.page].filter(Boolean).map((f) => f.filePath);
463
462
  const currentFiles = [handler, page].filter(Boolean).map((f) => f.filePath);
464
- throw new Error(`Duplicate routes for path '${path3.path}' were defined. A route established by:
463
+ throw new Error(`Duplicate routes for path '${path4.path}' were defined. A route established by:
465
464
  ${existingFiles.join(" and ")} via '${existing.dir.path}'
466
465
  collides with
467
466
  ${currentFiles.join(" and ")} via '${dir.path}'
468
467
  `);
469
468
  }
470
- uniqueRoutes.set(path3.id, { dir, index: routes.length });
469
+ uniqueRoutes.set(path4.id, { dir, index: routes.length });
471
470
  routes.push({
472
471
  index: nextRouteIndex++,
473
472
  key: dir.fullPath,
474
- paths: [path3],
473
+ paths: [path4],
475
474
  middleware: [...currentMiddleware],
476
475
  layouts: page ? [...currentLayouts] : [],
477
476
  meta: dir.files.get(RoutableFileTypes.Meta),
@@ -1134,7 +1133,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1134
1133
  if (useSwitch) {
1135
1134
  writer.writeBlockStart(`switch (${value}) {`);
1136
1135
  }
1137
- for (const { key, path: path3, route: route2 } of terminal) {
1136
+ for (const { key, path: path4, route: route2 } of terminal) {
1138
1137
  const decodedKey = decodeURIComponent(key);
1139
1138
  if (useSwitch) {
1140
1139
  writer.write(`case '${decodedKey}': `, true);
@@ -1142,7 +1141,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1142
1141
  writer.write(`if (${value} === '${decodedKey}') `, true);
1143
1142
  }
1144
1143
  writer.write(
1145
- `return ${renderMatch(verb, route2, path3)}; // ${path3.path}
1144
+ `return ${renderMatch(verb, route2, path4)}; // ${path4.path}
1146
1145
  `
1147
1146
  );
1148
1147
  }
@@ -1247,11 +1246,11 @@ function renderParams(params, pathIndex) {
1247
1246
  }
1248
1247
  return result ? result + " }" : "{}";
1249
1248
  }
1250
- function renderMatch(verb, route, path3, pathIndex) {
1249
+ function renderMatch(verb, route, path4, pathIndex) {
1251
1250
  const handler = `${verb}${route.index}`;
1252
- const params = path3.params ? renderParams(path3.params, pathIndex) : "{}";
1251
+ const params = path4.params ? renderParams(path4.params, pathIndex) : "{}";
1253
1252
  const meta = route.meta ? `meta${route.index}` : "{}";
1254
- const pathPattern = pathToURLPatternString(path3.path);
1253
+ const pathPattern = pathToURLPatternString(path4.path);
1255
1254
  return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${pathPattern}' }`;
1256
1255
  }
1257
1256
  function renderMiddleware(middleware) {
@@ -1272,15 +1271,15 @@ function renderMiddleware(middleware) {
1272
1271
  imports.join();
1273
1272
  return writer.end();
1274
1273
  }
1275
- function stripTsExtension(path3) {
1276
- const index = path3.lastIndexOf(".");
1274
+ function stripTsExtension(path4) {
1275
+ const index = path4.lastIndexOf(".");
1277
1276
  if (index !== -1) {
1278
- const ext = path3.slice(index + 1);
1277
+ const ext = path4.slice(index + 1);
1279
1278
  if (ext.toLowerCase() === "ts") {
1280
- return path3.slice(0, index);
1279
+ return path4.slice(0, index);
1281
1280
  }
1282
1281
  }
1283
- return path3;
1282
+ return path4;
1284
1283
  }
1285
1284
  async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1286
1285
  var _a, _b;
@@ -1312,8 +1311,8 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1312
1311
  const routeTypes = /* @__PURE__ */ new Map();
1313
1312
  for (const route of routes.list) {
1314
1313
  let routeType = "";
1315
- for (const path3 of route.paths) {
1316
- const pathType = `"${pathToURLPatternString(path3.path)}"`;
1314
+ for (const path4 of route.paths) {
1315
+ const pathType = `"${pathToURLPatternString(path4.path)}"`;
1317
1316
  routeType += routeType ? " | " + pathType : pathType;
1318
1317
  routesWriter.writeLines(`${pathType}: Routes["${route.key}"];`);
1319
1318
  }
@@ -1349,22 +1348,22 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1349
1348
  const pageWriter = writer.branch("page");
1350
1349
  const layoutWriter = writer.branch("layout");
1351
1350
  for (const [file, types] of routeTypes) {
1352
- const path3 = `${pathPrefix}/${file.relativePath}`;
1351
+ const path4 = `${pathPrefix}/${file.relativePath}`;
1353
1352
  const routeType = `Run.Routes[${types.join(" | ")}]`;
1354
1353
  switch (file.type) {
1355
1354
  case RoutableFileTypes.Handler:
1356
- writeModuleDeclaration(handlerWriter, path3, routeType);
1355
+ writeModuleDeclaration(handlerWriter, path4, routeType);
1357
1356
  break;
1358
1357
  case RoutableFileTypes.Middleware:
1359
- writeModuleDeclaration(middlewareWriter, path3, routeType);
1358
+ writeModuleDeclaration(middlewareWriter, path4, routeType);
1360
1359
  break;
1361
1360
  case RoutableFileTypes.Page:
1362
- writeModuleDeclaration(pageWriter, path3, routeType);
1361
+ writeModuleDeclaration(pageWriter, path4, routeType);
1363
1362
  break;
1364
1363
  case RoutableFileTypes.Layout:
1365
1364
  writeModuleDeclaration(
1366
1365
  layoutWriter,
1367
- path3,
1366
+ path4,
1368
1367
  routeType,
1369
1368
  `
1370
1369
  export interface Input {
@@ -1375,7 +1374,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1375
1374
  case RoutableFileTypes.Error:
1376
1375
  writeModuleDeclaration(
1377
1376
  writer,
1378
- path3,
1377
+ path4,
1379
1378
  "globalThis.MarkoRun.Route",
1380
1379
  `
1381
1380
  export interface Input {
@@ -1384,7 +1383,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1384
1383
  );
1385
1384
  break;
1386
1385
  case RoutableFileTypes.NotFound:
1387
- writeModuleDeclaration(writer, path3, "Run.Route");
1386
+ writeModuleDeclaration(writer, path4, "Run.Route");
1388
1387
  break;
1389
1388
  }
1390
1389
  }
@@ -1419,13 +1418,13 @@ type Routes = {`);
1419
1418
  writer.writeBlockEnd("}");
1420
1419
  return writer.end();
1421
1420
  }
1422
- function writeModuleDeclaration(writer, path3, routeType, moduleTypes) {
1423
- writer.writeLines("").write(`declare module "${stripTsExtension(path3)}" {`);
1421
+ function writeModuleDeclaration(writer, path4, routeType, moduleTypes) {
1422
+ writer.writeLines("").write(`declare module "${stripTsExtension(path4)}" {`);
1424
1423
  if (moduleTypes) {
1425
1424
  writer.write(moduleTypes);
1426
1425
  }
1427
1426
  if (routeType) {
1428
- const isMarko = path3.endsWith(".marko");
1427
+ const isMarko = path4.endsWith(".marko");
1429
1428
  writer.write(`
1430
1429
  namespace MarkoRun {
1431
1430
  export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
@@ -1438,8 +1437,8 @@ function writeModuleDeclaration(writer, path3, routeType, moduleTypes) {
1438
1437
  writer.writeLines(`
1439
1438
  }`);
1440
1439
  }
1441
- function pathToURLPatternString(path3) {
1442
- return path3.replace(/\/\$(\$?)([^\/]*)/g, (_, catchAll, name) => {
1440
+ function pathToURLPatternString(path4) {
1441
+ return path4.replace(/\/\$(\$?)([^\/]*)/g, (_, catchAll, name) => {
1443
1442
  name = decodeURIComponent(name);
1444
1443
  return catchAll ? `/:${name || "rest"}*` : `/:${name}`;
1445
1444
  });
@@ -1448,11 +1447,11 @@ function createRouteTrie(routes) {
1448
1447
  const root = {
1449
1448
  key: ""
1450
1449
  };
1451
- function insert(path3, route) {
1450
+ function insert(path4, route) {
1452
1451
  let node = root;
1453
- for (const segment of path3.segments) {
1452
+ for (const segment of path4.segments) {
1454
1453
  if (segment === "$$") {
1455
- node.catchAll ?? (node.catchAll = { route, path: path3 });
1454
+ node.catchAll ?? (node.catchAll = { route, path: path4 });
1456
1455
  return;
1457
1456
  } else if (segment === "$") {
1458
1457
  node = node.dynamic ?? (node.dynamic = {
@@ -1470,12 +1469,12 @@ function createRouteTrie(routes) {
1470
1469
  node = next;
1471
1470
  }
1472
1471
  }
1473
- node.path ?? (node.path = path3);
1472
+ node.path ?? (node.path = path4);
1474
1473
  node.route ?? (node.route = route);
1475
1474
  }
1476
1475
  for (const route of routes) {
1477
- for (const path3 of route.paths) {
1478
- insert(path3, route);
1476
+ for (const path4 of route.paths) {
1477
+ insert(path4, route);
1479
1478
  }
1480
1479
  }
1481
1480
  return root;
@@ -1565,7 +1564,7 @@ function logRoutesTable(routes, bundle, options) {
1565
1564
  style: { compact: true }
1566
1565
  });
1567
1566
  for (const route of routes.list) {
1568
- for (const path3 of route.paths) {
1567
+ for (const path4 of route.paths) {
1569
1568
  const verbs = getVerbs(route).sort(
1570
1569
  (a, b) => HttpVerbOrder[a] - HttpVerbOrder[b]
1571
1570
  );
@@ -1584,7 +1583,7 @@ function logRoutesTable(routes, bundle, options) {
1584
1583
  kleur.bold(HttpVerbColors[verb](verb.toUpperCase()))
1585
1584
  ];
1586
1585
  if (verbs.length === 1 || firstRow) {
1587
- row.push({ rowSpan: verbs.length, content: prettyPath(path3.path) });
1586
+ row.push({ rowSpan: verbs.length, content: prettyPath(path4.path) });
1588
1587
  firstRow = false;
1589
1588
  }
1590
1589
  row.push(entryType.join(" -> "));
@@ -1648,8 +1647,8 @@ function prettySize([bytes, compBytes]) {
1648
1647
  str += kleur.bold(kleur.red(compSize));
1649
1648
  return str;
1650
1649
  }
1651
- function prettyPath(path3) {
1652
- return path3.replace(/\/\$\$(.*)$/, (_, p) => "/" + kleur.bold(kleur.dim(`*${p}`))).replace(/\/\$([^/]+)/g, (_, p) => "/" + kleur.bold(kleur.dim(`:${p}`)));
1650
+ function prettyPath(path4) {
1651
+ return path4.replace(/\/\$\$(.*)$/, (_, p) => "/" + kleur.bold(kleur.dim(`*${p}`))).replace(/\/\$([^/]+)/g, (_, p) => "/" + kleur.bold(kleur.dim(`:${p}`)));
1653
1652
  }
1654
1653
 
1655
1654
  // src/vite/utils/config.ts
@@ -1668,12 +1667,60 @@ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterCon
1668
1667
 
1669
1668
  // src/vite/plugin.ts
1670
1669
  import createDebug from "debug";
1670
+
1671
+ // src/vite/utils/read-once-persisted-store.ts
1672
+ import os from "os";
1673
+ import path2 from "path";
1674
+ import { promises as fs2 } from "fs";
1675
+ var noop = () => {
1676
+ };
1677
+ var tmpFile = path2.join(os.tmpdir(), "marko-run-storage.json");
1678
+ var values = /* @__PURE__ */ new Map();
1679
+ var loadedFromDisk;
1680
+ var ReadOncePersistedStore = class {
1681
+ constructor(uid) {
1682
+ this.uid = uid;
1683
+ }
1684
+ write(value) {
1685
+ values.set(this.uid, value);
1686
+ }
1687
+ async read() {
1688
+ const { uid } = this;
1689
+ if (values.has(uid)) {
1690
+ const value = values.get(uid);
1691
+ values.delete(uid);
1692
+ return value;
1693
+ }
1694
+ if (loadedFromDisk === true) {
1695
+ throw new Error(`Value for ${uid} could not be loaded.`);
1696
+ }
1697
+ await (loadedFromDisk || (loadedFromDisk = fs2.readFile(tmpFile, "utf-8").then(syncDataFromDisk).catch(finishLoadFromDisk)));
1698
+ return this.read();
1699
+ }
1700
+ };
1701
+ function syncDataFromDisk(data) {
1702
+ finishLoadFromDisk();
1703
+ fs2.unlink(tmpFile).catch(noop);
1704
+ for (const [k, v] of JSON.parse(data)) {
1705
+ values.set(k, v);
1706
+ }
1707
+ }
1708
+ function finishLoadFromDisk() {
1709
+ loadedFromDisk = true;
1710
+ }
1711
+ process.once("beforeExit", (code) => {
1712
+ if (code === 0 && values.size) {
1713
+ fs2.writeFile(tmpFile, JSON.stringify([...values])).catch(noop);
1714
+ }
1715
+ });
1716
+
1717
+ // src/vite/plugin.ts
1671
1718
  var debug = createDebug("@marko/run");
1672
- var __dirname = path2.dirname(fileURLToPath(import.meta.url));
1719
+ var __dirname = path3.dirname(fileURLToPath(import.meta.url));
1673
1720
  var PLUGIN_NAME_PREFIX = "marko-run-vite";
1674
1721
  var POSIX_SEP = "/";
1675
1722
  var WINDOWS_SEP = "\\";
1676
- var normalizePath = path2.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
1723
+ var normalizePath = path3.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
1677
1724
  function markoRun(opts = {}) {
1678
1725
  let { routesDir, adapter, ...markoVitePluginOptions } = opts;
1679
1726
  let compiler;
@@ -1690,7 +1737,6 @@ function markoRun(opts = {}) {
1690
1737
  let devServer;
1691
1738
  let routes;
1692
1739
  let routeData;
1693
- let routeDataFilename = "routes.json";
1694
1740
  let extractVerbs;
1695
1741
  let resolvedConfig;
1696
1742
  let typesFile;
@@ -1706,15 +1752,15 @@ function markoRun(opts = {}) {
1706
1752
  root,
1707
1753
  "{.tsconfig*,tsconfig*.json}"
1708
1754
  )))) {
1709
- const filepath = path2.join(typesDir, "routes.d.ts");
1755
+ const filepath = path3.join(typesDir, "routes.d.ts");
1710
1756
  const data = await renderRouteTypeInfo(
1711
1757
  routes2,
1712
- normalizePath(path2.relative(typesDir, resolvedRoutesDir)),
1758
+ normalizePath(path3.relative(typesDir, resolvedRoutesDir)),
1713
1759
  adapter
1714
1760
  );
1715
- if (data !== typesFile || !fs2.existsSync(filepath)) {
1761
+ if (data !== typesFile || !fs3.existsSync(filepath)) {
1716
1762
  await ensureDir(typesDir);
1717
- await fs2.promises.writeFile(filepath, typesFile = data);
1763
+ await fs3.promises.writeFile(filepath, typesFile = data);
1718
1764
  }
1719
1765
  }
1720
1766
  }
@@ -1749,24 +1795,24 @@ function markoRun(opts = {}) {
1749
1795
  }
1750
1796
  if (route.page) {
1751
1797
  virtualFiles.set(
1752
- path2.posix.join(root, `${route.entryName}.marko`),
1798
+ path3.posix.join(root, `${route.entryName}.marko`),
1753
1799
  render ? renderRouteTemplate(route) : ""
1754
1800
  );
1755
1801
  }
1756
1802
  virtualFiles.set(
1757
- path2.posix.join(root, `${route.entryName}.js`),
1803
+ path3.posix.join(root, `${route.entryName}.js`),
1758
1804
  render ? renderRouteEntry(route) : ""
1759
1805
  );
1760
1806
  }
1761
1807
  for (const route of Object.values(routes.special)) {
1762
1808
  virtualFiles.set(
1763
- path2.posix.join(root, `${route.entryName}.marko`),
1809
+ path3.posix.join(root, `${route.entryName}.marko`),
1764
1810
  render ? renderRouteTemplate(route) : ""
1765
1811
  );
1766
1812
  }
1767
1813
  if (routes.middleware.length) {
1768
1814
  virtualFiles.set(
1769
- path2.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1815
+ path3.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1770
1816
  render ? renderMiddleware(routes.middleware) : ""
1771
1817
  );
1772
1818
  }
@@ -1798,7 +1844,7 @@ function markoRun(opts = {}) {
1798
1844
  }
1799
1845
  console.error(err);
1800
1846
  virtualFiles.set(
1801
- path2.posix.join(root, `${markoRunFilePrefix}error.marko`),
1847
+ path3.posix.join(root, `${markoRunFilePrefix}error.marko`),
1802
1848
  renderEntryTemplate(`${markoRunFilePrefix}error`, ["<dev-error-page>"])
1803
1849
  );
1804
1850
  virtualFiles.set(
@@ -1842,25 +1888,25 @@ function markoRun(opts = {}) {
1842
1888
  compiler.taglib.register("@marko/run", {
1843
1889
  "<dev-error-page>": {
1844
1890
  template: normalizePath(
1845
- path2.resolve(__dirname, "../components/dev-error-page.marko")
1891
+ path3.resolve(__dirname, "../components/dev-error-page.marko")
1846
1892
  )
1847
1893
  },
1848
1894
  "<*>": {
1849
- transform: path2.resolve(
1895
+ transform: path3.resolve(
1850
1896
  __dirname,
1851
1897
  "../components/src-attributes-transformer.cjs"
1852
1898
  )
1853
1899
  }
1854
1900
  });
1855
1901
  routesDir = opts.routesDir || "src/routes";
1856
- markoVitePluginOptions.store = store = opts.store || new FileStore(
1857
- `marko-serve-vite-${crypto.createHash("SHA1").update(root).digest("hex")}`
1902
+ store = new ReadOncePersistedStore(
1903
+ `vite-marko-run${opts.runtimeId ? `-${opts.runtimeId}` : ""}`
1858
1904
  );
1859
1905
  markoVitePluginOptions.runtimeId = opts.runtimeId;
1860
1906
  markoVitePluginOptions.basePathVar = opts.basePathVar;
1861
- resolvedRoutesDir = path2.resolve(root, routesDir);
1862
- typesDir = path2.join(root, ".marko-run");
1863
- devEntryFile = path2.join(root, "index.html");
1907
+ resolvedRoutesDir = path3.resolve(root, routesDir);
1908
+ typesDir = path3.join(root, ".marko-run");
1909
+ devEntryFile = path3.join(root, "index.html");
1864
1910
  devEntryFilePosix = normalizePath(devEntryFile);
1865
1911
  const assetsDir = ((_d = config2.build) == null ? void 0 : _d.assetsDir) || "assets";
1866
1912
  let rollupOutputOptions = (_f = (_e = config2.build) == null ? void 0 : _e.rollupOptions) == null ? void 0 : _f.output;
@@ -1919,7 +1965,8 @@ function markoRun(opts = {}) {
1919
1965
  // Avoid server & client deleting files from each other.
1920
1966
  rollupOptions: {
1921
1967
  output: rollupOutputOptions
1922
- }
1968
+ },
1969
+ modulePreload: { polyfill: false }
1923
1970
  },
1924
1971
  optimizeDeps: {
1925
1972
  entries: !((_h = config2.optimizeDeps) == null ? void 0 : _h.entries) ? [
@@ -1969,7 +2016,7 @@ function markoRun(opts = {}) {
1969
2016
  configureServer(_server) {
1970
2017
  devServer = _server;
1971
2018
  devServer.watcher.on("all", async (type, filename) => {
1972
- const routableFileType = matchRoutableFile(path2.parse(filename).base);
2019
+ const routableFileType = matchRoutableFile(path3.parse(filename).base);
1973
2020
  if (filename.startsWith(resolvedRoutesDir) && routableFileType) {
1974
2021
  if (type === "add") {
1975
2022
  isStale = true;
@@ -1992,9 +2039,7 @@ function markoRun(opts = {}) {
1992
2039
  async buildStart(_options) {
1993
2040
  if (isBuild && !isSSRBuild) {
1994
2041
  try {
1995
- routeData = JSON.parse(
1996
- await store.get(routeDataFilename)
1997
- );
2042
+ routeData = await store.read();
1998
2043
  } catch {
1999
2044
  this.error(
2000
2045
  `You must run the "ssr" build before the "browser" build.`
@@ -2016,9 +2061,9 @@ function markoRun(opts = {}) {
2016
2061
  let virtualFilePath;
2017
2062
  if (importee.startsWith(virtualFilePrefix)) {
2018
2063
  virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
2019
- importee = path2.resolve(root, virtualFilePath);
2064
+ importee = path3.resolve(root, virtualFilePath);
2020
2065
  } else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
2021
- importee = path2.resolve(root, "." + importee);
2066
+ importee = path3.resolve(root, "." + importee);
2022
2067
  }
2023
2068
  importee = normalizePath(importee);
2024
2069
  if (isStale) {
@@ -2027,7 +2072,7 @@ function markoRun(opts = {}) {
2027
2072
  if (virtualFiles.has(importee)) {
2028
2073
  resolved = importee;
2029
2074
  } else if (virtualFilePath) {
2030
- const filePath = path2.resolve(__dirname, "..", virtualFilePath);
2075
+ const filePath = path3.resolve(__dirname, "..", virtualFilePath);
2031
2076
  const resolution = await this.resolve(filePath, importer, {
2032
2077
  skipSelf: true
2033
2078
  });
@@ -2066,7 +2111,7 @@ function markoRun(opts = {}) {
2066
2111
  const builtEntries = Object.values(bundle).reduce(
2067
2112
  (acc, item) => {
2068
2113
  if (item.type === "chunk" && item.isEntry) {
2069
- acc.push(path2.join(options.dir, item.fileName));
2114
+ acc.push(path3.join(options.dir, item.fileName));
2070
2115
  }
2071
2116
  return acc;
2072
2117
  },
@@ -2082,7 +2127,7 @@ function markoRun(opts = {}) {
2082
2127
  for (const [key, code] of virtualFiles) {
2083
2128
  routeData.files.push({ key, code });
2084
2129
  }
2085
- await store.set(routeDataFilename, JSON.stringify(routeData));
2130
+ store.write(routeData);
2086
2131
  await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
2087
2132
  } else if (process.env.MR_EXPLORER !== "true") {
2088
2133
  logRoutesTable(routes, bundle, options);
@@ -2157,17 +2202,17 @@ async function globFileExists(root, pattern) {
2157
2202
  return (await glob(pattern, { root })).length > 0;
2158
2203
  }
2159
2204
  async function ensureDir(dir) {
2160
- if (!fs2.existsSync(dir)) {
2161
- await fs2.promises.mkdir(dir, { recursive: true });
2205
+ if (!fs3.existsSync(dir)) {
2206
+ await fs3.promises.mkdir(dir, { recursive: true });
2162
2207
  }
2163
2208
  }
2164
2209
  async function getPackageData(dir) {
2165
2210
  do {
2166
- const pkgPath = path2.join(dir, "package.json");
2167
- if (fs2.existsSync(pkgPath)) {
2168
- return JSON.parse(await fs2.promises.readFile(pkgPath, "utf-8"));
2211
+ const pkgPath = path3.join(dir, "package.json");
2212
+ if (fs3.existsSync(pkgPath)) {
2213
+ return JSON.parse(await fs3.promises.readFile(pkgPath, "utf-8"));
2169
2214
  }
2170
- } while (dir !== (dir = path2.dirname(dir)));
2215
+ } while (dir !== (dir = path3.dirname(dir)));
2171
2216
  return null;
2172
2217
  }
2173
2218
  async function resolveAdapter(root, options, log) {
@@ -2209,11 +2254,11 @@ function getEntryFileName(file) {
2209
2254
  import net from "net";
2210
2255
  import cp from "child_process";
2211
2256
  import { parse, config } from "dotenv";
2212
- import fs3 from "fs";
2257
+ import fs4 from "fs";
2213
2258
  import cluster from "cluster";
2214
2259
  async function parseEnv(envFile) {
2215
- if (fs3.existsSync(envFile)) {
2216
- const content = await fs3.promises.readFile(envFile, "utf8");
2260
+ if (fs4.existsSync(envFile)) {
2261
+ const content = await fs4.promises.readFile(envFile, "utf8");
2217
2262
  return parse(content);
2218
2263
  }
2219
2264
  }
@@ -36,12 +36,12 @@ export interface Adapter {
36
36
  export interface RouterOptions {
37
37
  trailingSlashes: "Ignore" | "RedirectWithout" | "RedirectWith" | "RewriteWithout" | "RewriteWith";
38
38
  }
39
- export interface MarkoServeOptions extends Partial<RouterOptions> {
39
+ export interface MarkoRunOptions extends Partial<RouterOptions> {
40
40
  routesDir?: string;
41
41
  emitRoutes?(routes: Route[]): void | Promise<void>;
42
42
  adapter?: Adapter | null;
43
43
  }
44
- export type Options = MarkoServeOptions & MarkoViteOptions;
44
+ export type Options = MarkoRunOptions & MarkoViteOptions;
45
45
  export interface Route {
46
46
  key: string;
47
47
  index: number;
@@ -0,0 +1,6 @@
1
+ export declare class ReadOncePersistedStore<T> {
2
+ private uid;
3
+ constructor(uid: string);
4
+ write(value: T): void;
5
+ read(): Promise<T>;
6
+ }