@marko/run 0.5.11 → 0.5.13

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.
@@ -10,7 +10,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
 
12
12
  // src/vite/plugin.ts
13
- import path3 from "path";
13
+ import path4 from "path";
14
14
  import fs3 from "fs";
15
15
  import { glob } from "glob";
16
16
  import { fileURLToPath } from "url";
@@ -98,10 +98,10 @@ var _VDir = class _VDir {
98
98
  });
99
99
  return value;
100
100
  }
101
- addDir(path4, segment) {
101
+ addDir(path5, segment) {
102
102
  const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
103
103
  if (!map.has(segment.name)) {
104
- const dir = new _VDir(this, segment, path4);
104
+ const dir = new _VDir(this, segment, path5);
105
105
  map.set(segment.name, dir);
106
106
  return dir;
107
107
  }
@@ -147,10 +147,10 @@ var _VDir = class _VDir {
147
147
  const dirs = [];
148
148
  const unique = /* @__PURE__ */ new Set();
149
149
  for (const root of roots) {
150
- for (const path4 of paths) {
150
+ for (const path5 of paths) {
151
151
  let dir = root;
152
- for (const segment of path4.segments) {
153
- dir = dir.addDir(path4, segment);
152
+ for (const segment of path5.segments) {
153
+ dir = dir.addDir(path5, segment);
154
154
  }
155
155
  if (unique.has(dir.path)) {
156
156
  const sources = /* @__PURE__ */ new Set();
@@ -162,7 +162,7 @@ var _VDir = class _VDir {
162
162
  }
163
163
  }
164
164
  throw new Error(
165
- `Ambiguous directory structure: '${sourcePath}${path4.source}' defines '${dir.path}' multiple times.`
165
+ `Ambiguous directory structure: '${sourcePath}${path5.source}' defines '${dir.path}' multiple times.`
166
166
  );
167
167
  } else {
168
168
  unique.add(dir.path);
@@ -203,9 +203,9 @@ function parseFlatRoute(pattern) {
203
203
  } else if (charCode === 44) {
204
204
  if (!current) {
205
205
  segmentEnd(
206
- basePaths.map((path4) => ({
207
- ...path4,
208
- segments: path4.segments.slice()
206
+ basePaths.map((path5) => ({
207
+ ...path5,
208
+ segments: path5.segments.slice()
209
209
  })),
210
210
  "",
211
211
  "_",
@@ -235,9 +235,9 @@ function parseFlatRoute(pattern) {
235
235
  } else if (charCode === 36) {
236
236
  type = pattern.charCodeAt(i + 1) === 36 ? "$$" : "$";
237
237
  }
238
- current ?? (current = basePaths.map((path4) => ({
239
- ...path4,
240
- segments: path4.segments.slice()
238
+ current ?? (current = basePaths.map((path5) => ({
239
+ ...path5,
240
+ segments: path5.segments.slice()
241
241
  })));
242
242
  i = len;
243
243
  for (const char of delimiters) {
@@ -257,9 +257,9 @@ function parseFlatRoute(pattern) {
257
257
  }
258
258
  if (!current) {
259
259
  segmentEnd(
260
- basePaths.map((path4) => ({
261
- ...path4,
262
- segments: path4.segments.slice()
260
+ basePaths.map((path5) => ({
261
+ ...path5,
262
+ segments: path5.segments.slice()
263
263
  })),
264
264
  "",
265
265
  "_",
@@ -283,9 +283,9 @@ function parseFlatRoute(pattern) {
283
283
  segment.param = raw.slice(type.length);
284
284
  }
285
285
  }
286
- for (const path4 of paths) {
286
+ for (const path5 of paths) {
287
287
  if (segment) {
288
- if (path4.isCatchall) {
288
+ if (path5.isCatchall) {
289
289
  throw new Error(
290
290
  `Invalid route pattern: nested segments are not allowed after a catch-all parameter. Found '.' following '${pattern.slice(
291
291
  0,
@@ -293,22 +293,22 @@ function parseFlatRoute(pattern) {
293
293
  )}' in '${pattern}'.`
294
294
  );
295
295
  }
296
- path4.segments.push(segment);
297
- path4.id += path4.id === "/" ? segment.name : `/${segment.name}`;
296
+ path5.segments.push(segment);
297
+ path5.id += path5.id === "/" ? segment.name : `/${segment.name}`;
298
298
  if (type === "$$") {
299
- path4.isCatchall = true;
299
+ path5.isCatchall = true;
300
300
  }
301
301
  }
302
302
  if (map) {
303
- if (map.has(path4.id)) {
304
- const existing = map.get(path4.id);
303
+ if (map.has(path5.id)) {
304
+ const existing = map.get(path5.id);
305
305
  const existingExpansion = existing.segments.map((s) => s.raw).join(".");
306
- const currentExpansion = path4.segments.map((s) => s.raw).join(".");
306
+ const currentExpansion = path5.segments.map((s) => s.raw).join(".");
307
307
  throw new Error(
308
- `Invalid route pattern: route '${path4.id}' is ambiguous. Expansion '${currentExpansion}' collides with '${existingExpansion}' in '${pattern}'.`
308
+ `Invalid route pattern: route '${path5.id}' is ambiguous. Expansion '${currentExpansion}' collides with '${existingExpansion}' in '${pattern}'.`
309
309
  );
310
310
  }
311
- map.set(path4.id, path4);
311
+ map.set(path5.id, path5);
312
312
  }
313
313
  }
314
314
  }
@@ -364,7 +364,7 @@ async function buildRoutes(sources) {
364
364
  dirStack.length = prevDirStackLength;
365
365
  };
366
366
  },
367
- onFile({ name, path: path4 }) {
367
+ onFile({ name, path: path5 }) {
368
368
  const match = name.match(routeableFileRegex);
369
369
  if (!match) {
370
370
  return;
@@ -372,7 +372,7 @@ async function buildRoutes(sources) {
372
372
  const type = (match[1] || match[3]).toLowerCase();
373
373
  if (dirStack.length && isSpecialType(type)) {
374
374
  console.warn(
375
- `Special pages '${RoutableFileTypes.NotFound}' and '${RoutableFileTypes.Error}' are only considered in the root directory - ignoring ${path4}`
375
+ `Special pages '${RoutableFileTypes.NotFound}' and '${RoutableFileTypes.Error}' are only considered in the root directory - ignoring ${path5}`
376
376
  );
377
377
  return;
378
378
  }
@@ -387,7 +387,7 @@ async function buildRoutes(sources) {
387
387
  id: String(nextFileId++),
388
388
  name,
389
389
  type,
390
- filePath: path4,
390
+ filePath: path5,
391
391
  relativePath,
392
392
  importPath: `${importPrefix}/${relativePath}`,
393
393
  verbs: type === RoutableFileTypes.Page ? ["get"] : void 0
@@ -439,23 +439,23 @@ async function buildRoutes(sources) {
439
439
  }
440
440
  }
441
441
  if (page || handler) {
442
- const path4 = dir.pathInfo;
443
- if (uniqueRoutes.has(path4.id)) {
444
- const existing = uniqueRoutes.get(path4.id);
442
+ const path5 = dir.pathInfo;
443
+ if (uniqueRoutes.has(path5.id)) {
444
+ const existing = uniqueRoutes.get(path5.id);
445
445
  const route = routes[existing.index];
446
446
  const existingFiles = [route.handler, route.page].filter(Boolean).map((f) => f.filePath);
447
447
  const currentFiles = [handler, page].filter(Boolean).map((f) => f.filePath);
448
- throw new Error(`Duplicate routes for path '${path4.path}' were defined. A route established by:
448
+ throw new Error(`Duplicate routes for path '${path5.path}' were defined. A route established by:
449
449
  ${existingFiles.join(" and ")} via '${existing.dir.path}'
450
450
  collides with
451
451
  ${currentFiles.join(" and ")} via '${dir.path}'
452
452
  `);
453
453
  }
454
- uniqueRoutes.set(path4.id, { dir, index: routes.length });
454
+ uniqueRoutes.set(path5.id, { dir, index: routes.length });
455
455
  routes.push({
456
456
  index: nextRouteIndex++,
457
457
  key: dir.fullPath,
458
- paths: [path4],
458
+ paths: [path5],
459
459
  middleware: [...currentMiddleware],
460
460
  layouts: page ? [...currentLayouts] : [],
461
461
  meta: dir.files.get(RoutableFileTypes.Meta),
@@ -705,6 +705,7 @@ function hasVerb(route, verb) {
705
705
  }
706
706
 
707
707
  // src/vite/codegen/index.ts
708
+ import path2 from "path";
708
709
  function renderRouteTemplate(route, getRelativePath) {
709
710
  if (!route.page) {
710
711
  throw new Error(`Route ${route.key} has no page to render`);
@@ -799,7 +800,7 @@ function renderRouteEntry(route, entriesDir) {
799
800
  );
800
801
  }
801
802
  if (page) {
802
- const importPath = route.layouts.length ? `./${entriesDir}/${entryName}.marko` : `./${page.importPath}`;
803
+ const importPath = route.layouts.length ? `./${path2.posix.join(entriesDir, page.relativePath, "..", "route.marko")}` : `./${page.importPath}`;
803
804
  imports.writeLines(`import page from '${importPath}${serverEntryQuery}';`);
804
805
  }
805
806
  if (meta) {
@@ -906,7 +907,7 @@ function renderRouter(routes, entriesDir, options = {
906
907
  );
907
908
  }
908
909
  for (const route of Object.values(routes.special)) {
909
- const importPath = route.layouts.length ? `./${entriesDir}/${route.entryName}.marko` : `./${route.page.importPath}`;
910
+ const importPath = route.layouts.length ? `./${path2.posix.join(entriesDir, route.page.relativePath, "..", `route.${route.key}.marko`)}` : `./${route.page.importPath}`;
910
911
  imports.writeLines(
911
912
  `import page${route.key} from '${importPath}${serverEntryQuery}';`
912
913
  );
@@ -1077,7 +1078,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1077
1078
  if (useSwitch) {
1078
1079
  writer.writeBlockStart(`switch (${value}) {`);
1079
1080
  }
1080
- for (const { key, path: path4, route: route2 } of terminal) {
1081
+ for (const { key, path: path5, route: route2 } of terminal) {
1081
1082
  const decodedKey = decodeURIComponent(key);
1082
1083
  if (useSwitch) {
1083
1084
  writer.write(`case '${decodedKey}': `, true);
@@ -1085,7 +1086,7 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
1085
1086
  writer.write(`if (${value} === '${decodedKey}') `, true);
1086
1087
  }
1087
1088
  writer.write(
1088
- `return ${renderMatch(verb, route2, path4)}; // ${path4.path}
1089
+ `return ${renderMatch(verb, route2, path5)}; // ${path5.path}
1089
1090
  `
1090
1091
  );
1091
1092
  }
@@ -1188,11 +1189,11 @@ function renderParams(params, pathIndex) {
1188
1189
  }
1189
1190
  return result ? result + " }" : "{}";
1190
1191
  }
1191
- function renderMatch(verb, route, path4, pathIndex) {
1192
+ function renderMatch(verb, route, path5, pathIndex) {
1192
1193
  const handler = `${verb}${route.index}`;
1193
- const params = path4.params ? renderParams(path4.params, pathIndex) : "{}";
1194
+ const params = path5.params ? renderParams(path5.params, pathIndex) : "{}";
1194
1195
  const meta = route.meta ? `meta${route.index}` : "{}";
1195
- const pathPattern = pathToURLPatternString(path4.path);
1196
+ const pathPattern = pathToURLPatternString(path5.path);
1196
1197
  return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${pathPattern}' }`;
1197
1198
  }
1198
1199
  function renderMiddleware(middleware) {
@@ -1213,15 +1214,15 @@ function renderMiddleware(middleware) {
1213
1214
  imports.join();
1214
1215
  return writer.end();
1215
1216
  }
1216
- function stripTsExtension(path4) {
1217
- const index = path4.lastIndexOf(".");
1217
+ function stripTsExtension(path5) {
1218
+ const index = path5.lastIndexOf(".");
1218
1219
  if (index !== -1) {
1219
- const ext = path4.slice(index + 1);
1220
+ const ext = path5.slice(index + 1);
1220
1221
  if (ext.toLowerCase() === "ts") {
1221
- return path4.slice(0, index);
1222
+ return path5.slice(0, index);
1222
1223
  }
1223
1224
  }
1224
- return path4;
1225
+ return path5;
1225
1226
  }
1226
1227
  async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1227
1228
  var _a, _b;
@@ -1253,8 +1254,8 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1253
1254
  const routeTypes = /* @__PURE__ */ new Map();
1254
1255
  for (const route of routes.list) {
1255
1256
  let routeType = "";
1256
- for (const path4 of route.paths) {
1257
- const pathType = `"${pathToURLPatternString(path4.path)}"`;
1257
+ for (const path5 of route.paths) {
1258
+ const pathType = `"${pathToURLPatternString(path5.path)}"`;
1258
1259
  routeType += routeType ? " | " + pathType : pathType;
1259
1260
  routesWriter.writeLines(`${pathType}: Routes["${route.key}"];`);
1260
1261
  }
@@ -1290,22 +1291,22 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1290
1291
  const pageWriter = writer.branch("page");
1291
1292
  const layoutWriter = writer.branch("layout");
1292
1293
  for (const [file, types] of routeTypes) {
1293
- const path4 = `${pathPrefix}/${file.relativePath}`;
1294
+ const path5 = `${pathPrefix}/${file.relativePath}`;
1294
1295
  const routeType = `Run.Routes[${types.join(" | ")}]`;
1295
1296
  switch (file.type) {
1296
1297
  case RoutableFileTypes.Handler:
1297
- writeModuleDeclaration(handlerWriter, path4, routeType);
1298
+ writeModuleDeclaration(handlerWriter, path5, routeType);
1298
1299
  break;
1299
1300
  case RoutableFileTypes.Middleware:
1300
- writeModuleDeclaration(middlewareWriter, path4, routeType);
1301
+ writeModuleDeclaration(middlewareWriter, path5, routeType);
1301
1302
  break;
1302
1303
  case RoutableFileTypes.Page:
1303
- writeModuleDeclaration(pageWriter, path4, routeType);
1304
+ writeModuleDeclaration(pageWriter, path5, routeType);
1304
1305
  break;
1305
1306
  case RoutableFileTypes.Layout:
1306
1307
  writeModuleDeclaration(
1307
1308
  layoutWriter,
1308
- path4,
1309
+ path5,
1309
1310
  routeType,
1310
1311
  `
1311
1312
  export interface Input {
@@ -1316,7 +1317,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1316
1317
  case RoutableFileTypes.Error:
1317
1318
  writeModuleDeclaration(
1318
1319
  writer,
1319
- path4,
1320
+ path5,
1320
1321
  "globalThis.MarkoRun.Route",
1321
1322
  `
1322
1323
  export interface Input {
@@ -1325,7 +1326,7 @@ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
1325
1326
  );
1326
1327
  break;
1327
1328
  case RoutableFileTypes.NotFound:
1328
- writeModuleDeclaration(writer, path4, "Run.Route");
1329
+ writeModuleDeclaration(writer, path5, "Run.Route");
1329
1330
  break;
1330
1331
  }
1331
1332
  }
@@ -1349,7 +1350,7 @@ type Routes = {`);
1349
1350
  if (meta) {
1350
1351
  const metaPath = stripTsExtension(`${pathPrefix}/${meta.relativePath}`);
1351
1352
  let metaType = `typeof import("${metaPath}")`;
1352
- if (/\.(ts|js|mjs)$/.test(meta.relativePath)) {
1353
+ if (/\.(ts|js|mjs)$/.test(meta.name)) {
1353
1354
  metaType += `["default"]`;
1354
1355
  }
1355
1356
  routeType += ` meta: ${metaType};`;
@@ -1360,13 +1361,13 @@ type Routes = {`);
1360
1361
  writer.writeBlockEnd("}");
1361
1362
  return writer.end();
1362
1363
  }
1363
- function writeModuleDeclaration(writer, path4, routeType, moduleTypes) {
1364
- writer.writeLines("").write(`declare module "${stripTsExtension(path4)}" {`);
1364
+ function writeModuleDeclaration(writer, path5, routeType, moduleTypes) {
1365
+ writer.writeLines("").write(`declare module "${stripTsExtension(path5)}" {`);
1365
1366
  if (moduleTypes) {
1366
1367
  writer.write(moduleTypes);
1367
1368
  }
1368
1369
  if (routeType) {
1369
- const isMarko = path4.endsWith(".marko");
1370
+ const isMarko = path5.endsWith(".marko");
1370
1371
  writer.write(`
1371
1372
  namespace MarkoRun {
1372
1373
  export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
@@ -1380,8 +1381,8 @@ function writeModuleDeclaration(writer, path4, routeType, moduleTypes) {
1380
1381
  writer.writeLines(`
1381
1382
  }`);
1382
1383
  }
1383
- function pathToURLPatternString(path4) {
1384
- return path4.replace(/\/\$(\$?)([^\/]*)/g, (_, catchAll, name) => {
1384
+ function pathToURLPatternString(path5) {
1385
+ return path5.replace(/\/\$(\$?)([^\/]*)/g, (_, catchAll, name) => {
1385
1386
  name = decodeURIComponent(name);
1386
1387
  return catchAll ? `/:${name || "rest"}*` : `/:${name}`;
1387
1388
  });
@@ -1390,11 +1391,11 @@ function createRouteTrie(routes) {
1390
1391
  const root = {
1391
1392
  key: ""
1392
1393
  };
1393
- function insert(path4, route) {
1394
+ function insert(path5, route) {
1394
1395
  let node = root;
1395
- for (const segment of path4.segments) {
1396
+ for (const segment of path5.segments) {
1396
1397
  if (segment === "$$") {
1397
- node.catchAll ?? (node.catchAll = { route, path: path4 });
1398
+ node.catchAll ?? (node.catchAll = { route, path: path5 });
1398
1399
  return;
1399
1400
  } else if (segment === "$") {
1400
1401
  node = node.dynamic ?? (node.dynamic = {
@@ -1412,12 +1413,12 @@ function createRouteTrie(routes) {
1412
1413
  node = next;
1413
1414
  }
1414
1415
  }
1415
- node.path ?? (node.path = path4);
1416
+ node.path ?? (node.path = path5);
1416
1417
  node.route ?? (node.route = route);
1417
1418
  }
1418
1419
  for (const route of routes) {
1419
- for (const path4 of route.paths) {
1420
- insert(path4, route);
1420
+ for (const path5 of route.paths) {
1421
+ insert(path5, route);
1421
1422
  }
1422
1423
  }
1423
1424
  return root;
@@ -1523,7 +1524,7 @@ function logRoutesTable(routes, bundle, options) {
1523
1524
  style: { compact: true }
1524
1525
  });
1525
1526
  for (const route of routes.list) {
1526
- for (const path4 of route.paths) {
1527
+ for (const path5 of route.paths) {
1527
1528
  const verbs = getVerbs(route).sort(
1528
1529
  (a, b) => HttpVerbOrder[a] - HttpVerbOrder[b]
1529
1530
  );
@@ -1542,7 +1543,7 @@ function logRoutesTable(routes, bundle, options) {
1542
1543
  kleur.bold(HttpVerbColors[verb](verb.toUpperCase()))
1543
1544
  ];
1544
1545
  if (verbs.length === 1 || firstRow) {
1545
- row.push({ rowSpan: verbs.length, content: prettyPath(path4.path) });
1546
+ row.push({ rowSpan: verbs.length, content: prettyPath(path5.path) });
1546
1547
  firstRow = false;
1547
1548
  }
1548
1549
  row.push(entryType.join(" -> "));
@@ -1603,8 +1604,8 @@ function prettySize([bytes, compBytes]) {
1603
1604
  else str += kleur.bold(kleur.red(compSize));
1604
1605
  return str;
1605
1606
  }
1606
- function prettyPath(path4) {
1607
- return path4.replace(/\/\$\$(.*)$/, (_, p) => "/" + kleur.bold(kleur.dim(`*${p}`))).replace(/\/\$([^/]+)/g, (_, p) => "/" + kleur.bold(kleur.dim(`:${p}`)));
1607
+ function prettyPath(path5) {
1608
+ return path5.replace(/\/\$\$(.*)$/, (_, p) => "/" + kleur.bold(kleur.dim(`*${p}`))).replace(/\/\$([^/]+)/g, (_, p) => "/" + kleur.bold(kleur.dim(`:${p}`)));
1608
1609
  }
1609
1610
 
1610
1611
  // src/vite/utils/config.ts
@@ -1626,11 +1627,11 @@ import createDebug from "debug";
1626
1627
 
1627
1628
  // src/vite/utils/read-once-persisted-store.ts
1628
1629
  import os from "os";
1629
- import path2 from "path";
1630
+ import path3 from "path";
1630
1631
  import { promises as fs2 } from "fs";
1631
1632
  var noop = () => {
1632
1633
  };
1633
- var tmpFile = path2.join(os.tmpdir(), "marko-run-storage.json");
1634
+ var tmpFile = path3.join(os.tmpdir(), "marko-run-storage.json");
1634
1635
  var values = /* @__PURE__ */ new Map();
1635
1636
  var loadedFromDisk;
1636
1637
  var ReadOncePersistedStore = class {
@@ -1698,7 +1699,7 @@ function prepareError(err) {
1698
1699
  // src/vite/plugin.ts
1699
1700
  import { createHash } from "crypto";
1700
1701
  var debug = createDebug("@marko/run");
1701
- var __dirname = path3.dirname(fileURLToPath(import.meta.url));
1702
+ var __dirname = path4.dirname(fileURLToPath(import.meta.url));
1702
1703
  var PLUGIN_NAME_PREFIX = "marko-run-vite";
1703
1704
  var POSIX_SEP = "/";
1704
1705
  var WINDOWS_SEP = "\\";
@@ -1706,7 +1707,7 @@ var CLIENT_OUT_DIR = "public";
1706
1707
  var MIDDLEWARE_FILENAME = `${markoRunFilePrefix}middleware.js`;
1707
1708
  var ROUTER_FILENAME = `${markoRunFilePrefix}router.js`;
1708
1709
  var defaultPort = Number(process.env.PORT || 3e3);
1709
- var normalizePath = path3.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
1710
+ var normalizePath = path4.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
1710
1711
  function markoRun(opts = {}) {
1711
1712
  let { routesDir, adapter, ...markoVitePluginOptions } = opts;
1712
1713
  let store;
@@ -1734,18 +1735,15 @@ function markoRun(opts = {}) {
1734
1735
  routesBuild: 0,
1735
1736
  routesRender: 0
1736
1737
  };
1737
- function getEntryFileRelativePath(to) {
1738
- return normalizePath(path3.relative(entryFilesDir, to));
1739
- }
1740
1738
  async function writeTypesFile(routes2) {
1741
1739
  if (routes2 && (tsConfigExists ?? (tsConfigExists = await globFileExists(
1742
1740
  root,
1743
1741
  "{.tsconfig*,tsconfig*.json}"
1744
1742
  )))) {
1745
- const filepath = path3.join(typesDir, "routes.d.ts");
1743
+ const filepath = path4.join(typesDir, "routes.d.ts");
1746
1744
  const data = await renderRouteTypeInfo(
1747
1745
  routes2,
1748
- normalizePath(path3.relative(typesDir, resolvedRoutesDir)),
1746
+ normalizePath(path4.relative(typesDir, resolvedRoutesDir)),
1749
1747
  adapter
1750
1748
  );
1751
1749
  if (data !== typesFile || !fs3.existsSync(filepath)) {
@@ -1767,12 +1765,12 @@ function markoRun(opts = {}) {
1767
1765
  throw new Error("No routes generated");
1768
1766
  }
1769
1767
  for (const route of routes.list) {
1770
- virtualFiles.set(path3.posix.join(root, `${route.entryName}.js`), "");
1768
+ virtualFiles.set(path4.posix.join(root, `${route.entryName}.js`), "");
1771
1769
  }
1772
1770
  if (routes.middleware.length) {
1773
- virtualFiles.set(path3.posix.join(root, MIDDLEWARE_FILENAME), "");
1771
+ virtualFiles.set(path4.posix.join(root, MIDDLEWARE_FILENAME), "");
1774
1772
  }
1775
- virtualFiles.set(path3.posix.join(root, ROUTER_FILENAME), "");
1773
+ virtualFiles.set(path4.posix.join(root, ROUTER_FILENAME), "");
1776
1774
  resolve(routes);
1777
1775
  } catch (err) {
1778
1776
  reject(err);
@@ -1785,7 +1783,6 @@ function markoRun(opts = {}) {
1785
1783
  var _a;
1786
1784
  try {
1787
1785
  const routes2 = await buildVirtualFiles();
1788
- let entryFilesDirExists = false;
1789
1786
  if (fs3.existsSync(entryFilesDir)) {
1790
1787
  fs3.rmSync(entryFilesDir, { recursive: true });
1791
1788
  }
@@ -1804,32 +1801,34 @@ function markoRun(opts = {}) {
1804
1801
  }
1805
1802
  if (!route.handler.verbs.length) {
1806
1803
  context.warn(
1807
- `Did not find any http verb exports in handler '${path3.relative(root, route.handler.filePath)}' - expected ${httpVerbs.map((v) => v.toUpperCase()).join(", ")}`
1804
+ `Did not find any http verb exports in handler '${path4.relative(root, route.handler.filePath)}' - expected ${httpVerbs.map((v) => v.toUpperCase()).join(", ")}`
1808
1805
  );
1809
1806
  }
1810
1807
  }
1811
1808
  if (route.page && route.layouts.length) {
1812
- entryFilesDirExists || (entryFilesDirExists = !!fs3.mkdirSync(entryFilesDir, {
1813
- recursive: true
1814
- }));
1809
+ const relativePath = path4.relative(resolvedRoutesDir, route.page.filePath);
1810
+ const routeFileDir = path4.join(entryFilesDir, relativePath, "..");
1811
+ const routeFileRelativePathPosix = normalizePath(path4.relative(routeFileDir, root));
1812
+ fs3.mkdirSync(routeFileDir, { recursive: true });
1815
1813
  fs3.writeFileSync(
1816
- path3.join(entryFilesDir, `${route.entryName}.marko`),
1817
- renderRouteTemplate(route, getEntryFileRelativePath)
1814
+ path4.join(routeFileDir, "route.marko"),
1815
+ renderRouteTemplate(route, (to) => path4.posix.join(routeFileRelativePathPosix, to))
1818
1816
  );
1819
1817
  }
1820
1818
  virtualFiles.set(
1821
- path3.posix.join(root, `${route.entryName}.js`),
1819
+ path4.posix.join(root, `${route.entryName}.js`),
1822
1820
  renderRouteEntry(route, relativeEntryFilesDirPosix)
1823
1821
  );
1824
1822
  }
1825
1823
  for (const route of Object.values(routes2.special)) {
1826
- if (route.layouts.length) {
1827
- entryFilesDirExists || (entryFilesDirExists = !!fs3.mkdirSync(entryFilesDir, {
1828
- recursive: true
1829
- }));
1824
+ if (route.page && route.layouts.length) {
1825
+ const relativePath = path4.relative(resolvedRoutesDir, route.page.filePath);
1826
+ const routeFileDir = path4.join(entryFilesDir, relativePath, "..");
1827
+ const routeFileRelativePathPosix = normalizePath(path4.relative(routeFileDir, root));
1828
+ fs3.mkdirSync(routeFileDir, { recursive: true });
1830
1829
  fs3.writeFileSync(
1831
- path3.join(entryFilesDir, `${route.entryName}.marko`),
1832
- renderRouteTemplate(route, getEntryFileRelativePath)
1830
+ path4.join(routeFileDir, `route.${route.key}.marko`),
1831
+ renderRouteTemplate(route, (to) => path4.posix.join(routeFileRelativePathPosix, to))
1833
1832
  );
1834
1833
  }
1835
1834
  }
@@ -1837,17 +1836,17 @@ function markoRun(opts = {}) {
1837
1836
  for (const middleware of routes2.middleware) {
1838
1837
  if (!(await getExportsFromFile(context, middleware.filePath)).includes("default")) {
1839
1838
  context.warn(
1840
- `Did not find a default export in middleware '${path3.relative(root, middleware.filePath)}'`
1839
+ `Did not find a default export in middleware '${path4.relative(root, middleware.filePath)}'`
1841
1840
  );
1842
1841
  }
1843
1842
  }
1844
1843
  virtualFiles.set(
1845
- path3.posix.join(root, MIDDLEWARE_FILENAME),
1844
+ path4.posix.join(root, MIDDLEWARE_FILENAME),
1846
1845
  renderMiddleware(routes2.middleware)
1847
1846
  );
1848
1847
  }
1849
1848
  virtualFiles.set(
1850
- path3.posix.join(root, ROUTER_FILENAME),
1849
+ path4.posix.join(root, ROUTER_FILENAME),
1851
1850
  renderRouter(routes2, relativeEntryFilesDirPosix, {
1852
1851
  trailingSlashes: opts.trailingSlashes || "RedirectWithout"
1853
1852
  })
@@ -1871,7 +1870,7 @@ function markoRun(opts = {}) {
1871
1870
  throw err;
1872
1871
  }
1873
1872
  virtualFiles.set(
1874
- path3.posix.join(root, ROUTER_FILENAME),
1873
+ path4.posix.join(root, ROUTER_FILENAME),
1875
1874
  `throw ${JSON.stringify(prepareError(err))}`
1876
1875
  );
1877
1876
  }
@@ -1914,23 +1913,23 @@ function markoRun(opts = {}) {
1914
1913
  );
1915
1914
  markoVitePluginOptions.runtimeId = opts.runtimeId;
1916
1915
  markoVitePluginOptions.basePathVar = opts.basePathVar;
1917
- resolvedRoutesDir = path3.resolve(root, routesDir);
1918
- entryFilesDir = path3.join(
1916
+ resolvedRoutesDir = path4.resolve(root, routesDir);
1917
+ entryFilesDir = path4.join(
1919
1918
  getModulesDir(root),
1920
1919
  ".marko",
1921
1920
  createHash("shake256", { outputLength: 4 }).update(root).digest("hex")
1922
1921
  );
1923
1922
  entryFilesDirPosix = normalizePath(entryFilesDir);
1924
- relativeEntryFilesDirPosix = normalizePath(path3.relative(root, entryFilesDir));
1925
- typesDir = path3.join(root, ".marko-run");
1926
- devEntryFile = path3.join(root, "index.html");
1923
+ relativeEntryFilesDirPosix = normalizePath(path4.relative(root, entryFilesDir));
1924
+ typesDir = path4.join(root, ".marko-run");
1925
+ devEntryFile = path4.join(root, "index.html");
1927
1926
  devEntryFilePosix = normalizePath(devEntryFile);
1928
1927
  let outDir = ((_d = config2.build) == null ? void 0 : _d.outDir) || "dist";
1929
1928
  const assetsDir = ((_e = config2.build) == null ? void 0 : _e.assetsDir) || "assets";
1930
1929
  let rollupOutputOptions = (_g = (_f = config2.build) == null ? void 0 : _f.rollupOptions) == null ? void 0 : _g.output;
1931
1930
  if (isBuild) {
1932
1931
  if (!isSSRBuild) {
1933
- outDir = path3.join(outDir, CLIENT_OUT_DIR);
1932
+ outDir = path4.join(outDir, CLIENT_OUT_DIR);
1934
1933
  }
1935
1934
  const defaultRollupOutputOptions = {
1936
1935
  assetFileNames({ name }) {
@@ -2062,7 +2061,7 @@ function markoRun(opts = {}) {
2062
2061
  devServer.watcher.on("all", async (type, filename) => {
2063
2062
  seenErrors.clear();
2064
2063
  const routableFileType = matchRoutableFile(
2065
- path3.parse(filename).base
2064
+ path4.parse(filename).base
2066
2065
  );
2067
2066
  if (filename.startsWith(resolvedRoutesDir) && routableFileType) {
2068
2067
  if (type === "add" || type === "unlink" || type === "change" && (routableFileType === RoutableFileTypes.Handler || routableFileType === RoutableFileTypes.Middleware)) {
@@ -2107,19 +2106,19 @@ function markoRun(opts = {}) {
2107
2106
  },
2108
2107
  async resolveId(importee, importer) {
2109
2108
  if (importee === "@marko/run/router") {
2110
- return path3.resolve(root, ROUTER_FILENAME);
2109
+ return path4.resolve(root, ROUTER_FILENAME);
2111
2110
  } else if (importee.endsWith(".marko") && importee.includes(relativeEntryFilesDirPosix)) {
2112
2111
  if (!importee.startsWith(root)) {
2113
- importee = path3.resolve(root, "." + importee);
2112
+ importee = path4.resolve(root, "." + importee);
2114
2113
  }
2115
2114
  return normalizePath(importee);
2116
2115
  }
2117
2116
  let virtualFilePath;
2118
2117
  if (importee.startsWith(virtualFilePrefix)) {
2119
2118
  virtualFilePath = importee.slice(virtualFilePrefix.length + 1);
2120
- importee = path3.resolve(root, virtualFilePath);
2119
+ importee = path4.resolve(root, virtualFilePath);
2121
2120
  } else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
2122
- importee = path3.resolve(root, "." + importee);
2121
+ importee = path4.resolve(root, "." + importee);
2123
2122
  }
2124
2123
  importee = normalizePath(importee);
2125
2124
  if (!buildVirtualFilesResult) {
@@ -2128,7 +2127,7 @@ function markoRun(opts = {}) {
2128
2127
  if (virtualFiles.has(importee)) {
2129
2128
  return importee;
2130
2129
  } else if (virtualFilePath) {
2131
- const filePath = path3.resolve(__dirname, "..", virtualFilePath);
2130
+ const filePath = path4.resolve(__dirname, "..", virtualFilePath);
2132
2131
  return await this.resolve(filePath, importer, {
2133
2132
  skipSelf: true
2134
2133
  });
@@ -2167,7 +2166,7 @@ function markoRun(opts = {}) {
2167
2166
  const builtEntries = Object.values(bundle).reduce(
2168
2167
  (acc, item) => {
2169
2168
  if (item.type === "chunk" && item.isEntry) {
2170
- acc.push(path3.join(options.dir, item.fileName));
2169
+ acc.push(path4.join(options.dir, item.fileName));
2171
2170
  }
2172
2171
  return acc;
2173
2172
  },
@@ -2227,11 +2226,11 @@ async function ensureDir(dir) {
2227
2226
  }
2228
2227
  async function getPackageData(dir) {
2229
2228
  do {
2230
- const pkgPath = path3.join(dir, "package.json");
2229
+ const pkgPath = path4.join(dir, "package.json");
2231
2230
  if (fs3.existsSync(pkgPath)) {
2232
2231
  return JSON.parse(await fs3.promises.readFile(pkgPath, "utf-8"));
2233
2232
  }
2234
- } while (dir !== (dir = path3.dirname(dir)));
2233
+ } while (dir !== (dir = path4.dirname(dir)));
2235
2234
  return null;
2236
2235
  }
2237
2236
  async function resolveAdapter(root, options, log) {
@@ -2284,7 +2283,7 @@ function getModulesDir(root, dir = __dirname) {
2284
2283
  return dir.slice(0, index + 12);
2285
2284
  }
2286
2285
  }
2287
- return path3.join(root, "node_modules");
2286
+ return path4.join(root, "node_modules");
2288
2287
  }
2289
2288
  var defaultConfigPlugin = {
2290
2289
  name: `${PLUGIN_NAME_PREFIX}:defaults`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.5.11",
3
+ "version": "0.5.13",
4
4
  "description": "The Marko application framework.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/marko-js/run/tree/main/packages/run",