@marko/run 0.9.7 → 0.11.0-rc.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.
@@ -65,6 +65,7 @@ var import_esbuild_plugin_browserslist = require("esbuild-plugin-browserslist");
65
65
  var import_fs4 = __toESM(require("fs"), 1);
66
66
  var import_glob = require("glob");
67
67
  var import_path6 = __toESM(require("path"), 1);
68
+ var import_rolldown = require("rolldown");
68
69
  var import_url2 = require("url");
69
70
  var import_vite2 = require("vite");
70
71
 
@@ -110,10 +111,10 @@ var httpVerbs = [
110
111
  "options"
111
112
  ];
112
113
  var RoutableFileTypes = {
113
- Page: "page",
114
- Layout: "layout",
115
- Handler: "handler",
116
114
  Middleware: "middleware",
115
+ Handler: "handler",
116
+ Layout: "layout",
117
+ Page: "page",
117
118
  Meta: "meta",
118
119
  NotFound: "404",
119
120
  Error: "500"
@@ -302,19 +303,21 @@ function normalizedRelativePath(from, to) {
302
303
  const relativePath = normalizePath(import_path2.default.relative(from, to));
303
304
  return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
304
305
  }
305
- function renderRouteTemplate(route, markoApi) {
306
+ function renderRouteTemplate(route, markoApi, dev = false) {
306
307
  if (!route.page) {
307
308
  throw new Error(`Route ${route.key} has no page to render`);
308
309
  }
309
- if (!route.templateFilePath) {
310
- throw new Error(`Route ${route.key} has no template file path`);
311
- }
312
310
  const writer = createStringWriter();
313
311
  if (markoApi) {
314
312
  writer.writeLines(`<!-- use ${markoApi} -->
315
313
  `);
316
314
  }
317
- writer.branch("imports");
315
+ const importWriter = writer.branch("imports");
316
+ if (dev) {
317
+ importWriter.writeLines(
318
+ `client import "virtual:marko-run/runtime/client";`
319
+ );
320
+ }
318
321
  writer.writeLines("");
319
322
  writeEntryTemplateTag(
320
323
  writer,
@@ -362,7 +365,10 @@ function renderRouteEntry(route, rootDir) {
362
365
  runtimeImports.push("normalizeMeta");
363
366
  }
364
367
  if (handler || middleware.length) {
365
- runtimeImports.push("call");
368
+ runtimeImports.push("call", "mergeOptions");
369
+ }
370
+ if (page) {
371
+ runtimeImports.push("render");
366
372
  }
367
373
  if (!page || verbs.some((verb) => verb !== "get" && verb !== "head")) {
368
374
  runtimeImports.push("noContent");
@@ -401,7 +407,7 @@ function renderRouteEntry(route, rootDir) {
401
407
  }
402
408
  if (page) {
403
409
  imports.writeLines(
404
- `import page from "${normalizedRelativePath(rootDir, route.templateFilePath || page.filePath)}";`
410
+ `import page from "${normalizedRelativePath(rootDir, route.templateFilePath)}";`
405
411
  );
406
412
  }
407
413
  if (meta) {
@@ -419,11 +425,34 @@ function renderRouteEntry(route, rootDir) {
419
425
  `export const { ${metaVerbsExports} } = normalizeMeta(${metaName});`
420
426
  );
421
427
  }
428
+ const optionsWriter = writer.branch("options").writeLines("");
422
429
  for (const verb of verbs) {
430
+ writeRouteOptions(optionsWriter, route, verb);
423
431
  writeRouteEntryHandler(writer, route, verb);
424
432
  }
433
+ optionsWriter.join();
425
434
  return writer.end();
426
435
  }
436
+ function writeRouteOptions(writer, route, verb) {
437
+ var _a, _b;
438
+ const hasHandler = (_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb);
439
+ writer.write(`export const ${verb}${route.index}_options = `);
440
+ if (route.middleware.length || hasHandler) {
441
+ writer.write(`mergeOptions(`);
442
+ let sep = "";
443
+ for (const { id } of route.middleware) {
444
+ writer.write(`${sep}mware${id}`);
445
+ sep = ", ";
446
+ }
447
+ if (hasHandler) {
448
+ writer.write(`${sep}${verb}Handler`);
449
+ }
450
+ writer.write(");");
451
+ } else {
452
+ writer.write("{};");
453
+ }
454
+ writer.write("\n");
455
+ }
427
456
  function writeRouteEntryHandler(writer, route, verb) {
428
457
  var _a, _b, _c, _d;
429
458
  const { key, index, page, handler, middleware } = route;
@@ -443,13 +472,13 @@ function writeRouteEntryHandler(writer, route, verb) {
443
472
  if ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes(verb)) {
444
473
  const name = `${verb}Handler`;
445
474
  continuations.writeLines(
446
- `const ${currentName} = () => context.render(page, {});`
475
+ `const ${currentName} = (data) => render(context, page, {}, data);`
447
476
  );
448
477
  if (len) {
449
478
  nextName = currentName;
450
479
  currentName = `__${name}`;
451
480
  continuations.writeLines(
452
- `const ${currentName} = () => call(${name}, ${nextName}, context);`
481
+ `const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
453
482
  );
454
483
  } else {
455
484
  if (verb === "head") {
@@ -466,11 +495,10 @@ function writeRouteEntryHandler(writer, route, verb) {
466
495
  hasBody = true;
467
496
  } else if (len) {
468
497
  continuations.writeLines(
469
- `const ${currentName} = () => context.render(page, {});`
498
+ `const ${currentName} = (data) => render(context, page, {}, data);`
470
499
  );
471
- nextName = currentName;
472
500
  } else {
473
- writer.writeLines(`return context.render(page, {});`);
501
+ writer.writeLines(`return render(context, page, {});`);
474
502
  hasBody = true;
475
503
  }
476
504
  } else if ((_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes(verb)) {
@@ -479,7 +507,7 @@ function writeRouteEntryHandler(writer, route, verb) {
479
507
  nextName = "noContent";
480
508
  if (len) {
481
509
  continuations.writeLines(
482
- `const ${currentName} = () => call(${name}, ${nextName}, context);`
510
+ `const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
483
511
  );
484
512
  } else {
485
513
  if (verb === "head") {
@@ -506,7 +534,7 @@ function writeRouteEntryHandler(writer, route, verb) {
506
534
  currentName = i ? `__${name}` : "";
507
535
  if (currentName) {
508
536
  continuations.writeLines(
509
- `const ${currentName} = () => call(${name}, ${nextName}, context);`
537
+ `const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
510
538
  );
511
539
  } else if (verb === "head") {
512
540
  continuations.writeLines(
@@ -539,6 +567,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
539
567
  for (const verb of verbs) {
540
568
  const verbName = `${verb}${route.index}`;
541
569
  routeImports.push(verbName);
570
+ routeImports.push(`${verbName}_options`);
542
571
  if (route.meta) {
543
572
  routeImports.push(`${verbName}_meta`);
544
573
  }
@@ -549,7 +578,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
549
578
  }
550
579
  for (const route of Object.values(routes.special)) {
551
580
  imports.writeLines(
552
- `import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath || route.page.filePath)}";`
581
+ `import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath)}";`
553
582
  );
554
583
  }
555
584
  writer.writeLines(
@@ -834,10 +863,10 @@ function renderParams(params, pathIndex) {
834
863
  return result ? result + " }" : "{}";
835
864
  }
836
865
  function renderMatch(verb, route, path7, pathIndex) {
837
- const handler = `${verb}${route.index}`;
866
+ const name = `${verb}${route.index}`;
838
867
  const params = path7.params ? renderParams(path7.params, pathIndex) : "{}";
839
- const meta = route.meta ? `${verb}${route.index}_meta` : "{}";
840
- return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path7.path}' }`;
868
+ const meta = route.meta ? `${name}_meta` : "{}";
869
+ return `{ handler: ${name}, path: '${path7.path}', params: ${params}, options: ${name}_options, meta: ${meta} }`;
841
870
  }
842
871
  function renderMiddleware(middleware, rootDir) {
843
872
  const writer = createStringWriter();
@@ -868,8 +897,14 @@ function stripTsExtension(path7) {
868
897
  }
869
898
  return path7;
870
899
  }
900
+ function* routeFileIter(route) {
901
+ yield* route.middleware;
902
+ if (route.handler) yield route.handler;
903
+ yield* route.layouts;
904
+ if (route.page) yield route.page;
905
+ if (route.meta) yield route.meta;
906
+ }
871
907
  async function renderRouteTypeInfo(routes, outDir, adapter) {
872
- var _a, _b, _c, _d;
873
908
  const writer = createStringWriter();
874
909
  writer.writeLines(
875
910
  `/*
@@ -878,10 +913,11 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
878
913
  */
879
914
  `,
880
915
  `import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace";`,
881
- `import type * as Run from "@marko/run";`
916
+ `import type * as $ from "@marko/run";`,
917
+ ""
882
918
  );
883
919
  const headWriter = writer.branch("head");
884
- writer.writeLines("\n").writeBlockStart(`declare module "@marko/run" {`);
920
+ writer.writeLines("").writeBlockStart(`declare module "@marko/run" {`);
885
921
  if (adapter && adapter.typeInfo) {
886
922
  const platformType = await adapter.typeInfo(
887
923
  (data) => headWriter.write(data)
@@ -891,139 +927,120 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
891
927
  `);
892
928
  }
893
929
  }
894
- headWriter.join();
895
- writer.writeBlockStart(`interface AppData extends Run.DefineApp<{`).writeBlockStart("routes: {");
896
- const routesWriter = writer.branch("routes");
897
- writer.writeBlockEnd("}").writeBlockEnd(`}> {}`).writeBlockEnd(`}`);
898
- const routeTypes = /* @__PURE__ */ new Map();
899
- for (const route of routes.list) {
900
- let routeType = "";
901
- let routeDefinition = "";
902
- if (route.page || route.handler) {
903
- const verbs = [];
904
- if (route.page || ((_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes("get"))) {
905
- verbs.push(`"get"`);
906
- }
907
- if ((_d = (_c = route.handler) == null ? void 0 : _c.verbs) == null ? void 0 : _d.includes("post")) {
908
- verbs.push(`"post"`);
909
- }
910
- routeDefinition = `{ verb: ${verbs.join(" | ")};`;
911
- if (route.meta) {
912
- const metaPath = stripTsExtension(
913
- normalizedRelativePath(outDir, route.meta.filePath)
914
- );
915
- let metaType = `typeof import("${metaPath}")`;
916
- if (/\.(ts|js|mjs)$/.test(route.meta.name)) {
917
- metaType += `["default"]`;
918
- }
919
- routeDefinition += ` meta: ${metaType};`;
920
- }
921
- routeDefinition += " }";
922
- }
923
- const pathType = `"${route.path.path}"`;
924
- routeType += routeType ? " | " + pathType : pathType;
925
- routesWriter.writeLines(`${pathType}: ${routeDefinition};`);
926
- for (const file of [route.handler, route.page]) {
927
- if (file) {
928
- const existing = routeTypes.get(file);
929
- if (!existing) {
930
- routeTypes.set(file, [routeType]);
931
- } else {
932
- existing.push(routeType);
933
- }
930
+ const fileInfoByType = /* @__PURE__ */ new Map();
931
+ let fileIndex = 1;
932
+ function addFile(file) {
933
+ let group = fileInfoByType.get(file.type);
934
+ if (!group) {
935
+ fileInfoByType.set(file.type, group = /* @__PURE__ */ new Map());
936
+ }
937
+ let info = group.get(file);
938
+ if (!info) {
939
+ info = {
940
+ id: "",
941
+ typeName: null,
942
+ modulePath: stripTsExtension(
943
+ normalizedRelativePath(outDir, file.filePath)
944
+ ),
945
+ routes: /* @__PURE__ */ new Set()
946
+ };
947
+ switch (file.type) {
948
+ case RoutableFileTypes.Middleware:
949
+ info.id = `M${group.size + 1}`;
950
+ info.typeName = "Middleware";
951
+ break;
952
+ case RoutableFileTypes.Handler:
953
+ info.id = `H${group.size + 1}`;
954
+ info.typeName = "Handler";
955
+ break;
956
+ case RoutableFileTypes.Meta:
957
+ info.id = `D${group.size + 1}`;
958
+ info.typeName = "Meta";
959
+ break;
960
+ case RoutableFileTypes.Layout:
961
+ info.id = `L${group.size + 1}`;
962
+ info.typeName = "Template";
963
+ break;
964
+ case RoutableFileTypes.Page:
965
+ info.id = `P${group.size + 1}`;
966
+ info.typeName = "Template";
967
+ break;
968
+ default:
969
+ info.id = `F${fileIndex++}`;
970
+ break;
934
971
  }
972
+ group.set(file, info);
935
973
  }
936
- for (const files of [route.middleware, route.layouts]) {
937
- if (files) {
938
- for (const file of files) {
939
- const existing = routeTypes.get(file);
940
- if (!existing) {
941
- routeTypes.set(file, [routeType]);
942
- } else {
943
- existing.push(routeType);
944
- }
945
- }
974
+ return info;
975
+ }
976
+ writer.writeBlockStart(`interface App extends $.DefineRoutes<{`);
977
+ for (const route of routes.list) {
978
+ let routeDefFiles = "";
979
+ for (const file of routeFileIter(route)) {
980
+ const fileInfo = addFile(file);
981
+ fileInfo.routes.add(route);
982
+ if (routeDefFiles) {
983
+ routeDefFiles += ", ";
946
984
  }
985
+ routeDefFiles += fileInfo.id;
947
986
  }
987
+ writer.writeLines(`"${route.path.path}": [${routeDefFiles}];`);
948
988
  }
949
989
  for (const special of Object.values(routes.special)) {
950
- routeTypes.set(special.page, []);
951
- }
952
- routesWriter.join();
953
- const handlerWriter = writer.branch("handler");
954
- const middlewareWriter = writer.branch("middleware");
955
- const pageWriter = writer.branch("page");
956
- const layoutWriter = writer.branch("layout");
957
- for (const [file, types] of routeTypes) {
958
- const modulePath = stripTsExtension(
959
- normalizedRelativePath(outDir, file.filePath)
960
- );
961
- const routeType = `Run.Routes[${types.join(" | ")}]`;
962
- switch (file.type) {
963
- case RoutableFileTypes.Handler:
964
- writeModuleDeclaration(handlerWriter, modulePath, routeType);
965
- break;
966
- case RoutableFileTypes.Middleware:
967
- writeModuleDeclaration(middlewareWriter, modulePath, routeType);
968
- break;
969
- case RoutableFileTypes.Page:
970
- writeModuleDeclaration(pageWriter, modulePath, routeType);
971
- break;
972
- case RoutableFileTypes.Layout:
973
- writeModuleDeclaration(
974
- layoutWriter,
975
- modulePath,
976
- routeType,
977
- `
978
- export interface Input extends Run.LayoutInput<typeof import("${modulePath}")> {}`
990
+ addFile(special.page);
991
+ }
992
+ writer.writeBlockEnd(`}> {}`).writeBlockEnd(`}`);
993
+ for (const fileType of Object.values(RoutableFileTypes)) {
994
+ const fileGroup = fileInfoByType.get(fileType);
995
+ if (!fileGroup) continue;
996
+ for (const info of fileGroup.values()) {
997
+ writer.writeLines("");
998
+ if (info.typeName) {
999
+ writer.writeLines(
1000
+ `type ${info.id} = $.${info.typeName}<"${info.id}", typeof import("${info.modulePath}")>;`
979
1001
  );
980
- break;
981
- case RoutableFileTypes.Error:
982
- writeModuleDeclaration(
983
- writer,
984
- modulePath,
985
- "globalThis.MarkoRun.Route",
986
- `
1002
+ }
1003
+ if (fileType === RoutableFileTypes.Meta) continue;
1004
+ writer.write(`declare module "${info.modulePath}" {`);
1005
+ switch (fileType) {
1006
+ case RoutableFileTypes.Layout:
1007
+ writer.write(`
1008
+ interface Input extends $.LayoutInput<${info.id}> {}`);
1009
+ break;
1010
+ case RoutableFileTypes.Error:
1011
+ writer.write(`
987
1012
  export interface Input {
988
1013
  error: unknown;
989
- }`
990
- );
991
- break;
992
- case RoutableFileTypes.NotFound:
993
- writeModuleDeclaration(writer, modulePath, "Run.Route");
994
- break;
995
- }
996
- }
997
- handlerWriter.join();
998
- middlewareWriter.join();
999
- pageWriter.join();
1000
- layoutWriter.join();
1001
- return writer.end();
1002
- }
1003
- function writeModuleDeclaration(writer, name, routeType, moduleTypes) {
1004
- writer.writeLines("").write(`declare module "${name}" {`);
1005
- if (moduleTypes) {
1006
- writer.write(moduleTypes);
1014
+ }`);
1015
+ break;
1016
+ }
1017
+ if (info.typeName) {
1018
+ writer.write(`
1019
+ const Run: $.Namespace<${info.id}>;
1020
+ namespace Run {
1021
+ type Context = $.ContextForFile<${info.id}>${info.typeName === "Template" ? " & Marko.Global" : ""};
1007
1022
  }
1008
- if (routeType) {
1009
- const isMarko = name.endsWith(".marko");
1010
- writer.write(`
1023
+ `);
1024
+ }
1025
+ writer.write(`
1026
+ /** @deprecated use \`Run\` namespace instead */
1011
1027
  namespace MarkoRun {
1012
1028
  export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
1013
- export type Route = ${routeType};
1014
- export type Context = Run.MultiRouteContext<Route>${isMarko ? " & Marko.Global" : ""};
1015
- export type Handler = Run.HandlerLike<Route>;`);
1016
- for (const verb of httpVerbs) {
1029
+ export type Route = ${info.routes.size ? `$.Routes["${[...info.routes].map((route) => route.path.path).join('" | "')}"]` : "globalThis.MarkoRun.Route"};
1030
+ export type Context = ${info.modulePath.endsWith(".marko") ? "Run.Context" : "$.MultiRouteContext<Route>"};
1031
+ export type Handler = $.HandlerLike<Route>;`);
1032
+ for (const verb of httpVerbs) {
1033
+ writer.write(`
1034
+ export type ${verb.toUpperCase()} = $.HandlerLike<Route, "${verb.toUpperCase()}">;`);
1035
+ }
1017
1036
  writer.write(`
1018
- export type ${verb.toUpperCase()} = Run.HandlerLike<Route, "${verb.toUpperCase()}">;`);
1019
- }
1020
- writer.write(`
1021
- /** @deprecated use \`((context, next) => { ... }) satisfies MarkoRun.Handler\` instead */
1022
- export const route: Run.HandlerTypeFn<Route>;
1023
1037
  }`);
1024
- }
1025
- writer.writeLines(`
1038
+ writer.writeLines(`
1026
1039
  }`);
1040
+ }
1041
+ }
1042
+ headWriter.join();
1043
+ return writer.end();
1027
1044
  }
1028
1045
  function createRouteTrie(routes) {
1029
1046
  const root = {
@@ -1508,7 +1525,7 @@ async function buildRoutes(sources, outDir) {
1508
1525
  middleware: [],
1509
1526
  layouts: [...currentLayouts],
1510
1527
  page: file,
1511
- templateFilePath: currentLayouts.size ? import_path3.default.join(outDir, `${type}.marko`) : void 0
1528
+ templateFilePath: import_path3.default.join(outDir, `${type}.marko`)
1512
1529
  };
1513
1530
  layoutsUsed = true;
1514
1531
  }
@@ -1541,7 +1558,7 @@ async function buildRoutes(sources, outDir) {
1541
1558
  meta: dir.files.get(RoutableFileTypes.Meta),
1542
1559
  page,
1543
1560
  handler,
1544
- templateFilePath: page && currentLayouts.size ? import_path3.default.join(outDir, key + ".marko") : void 0
1561
+ templateFilePath: page && import_path3.default.join(outDir, key + ".marko")
1545
1562
  });
1546
1563
  layoutsUsed = !!page;
1547
1564
  for (const middleware2 of currentMiddleware) {
@@ -1580,7 +1597,7 @@ function createFSWalker(dir) {
1580
1597
  onDir,
1581
1598
  maxDepth = 50
1582
1599
  }) {
1583
- async function walk(dir2, depth) {
1600
+ async function walk2(dir2, depth) {
1584
1601
  const onExit = onEnter == null ? void 0 : onEnter(dir2);
1585
1602
  if (onExit !== false) {
1586
1603
  const dirs = [];
@@ -1601,13 +1618,13 @@ function createFSWalker(dir) {
1601
1618
  }
1602
1619
  if ((onDir == null ? void 0 : onDir()) !== false && --depth > 0) {
1603
1620
  for (const entry of dirs) {
1604
- await walk(entry, depth);
1621
+ await walk2(entry, depth);
1605
1622
  }
1606
1623
  }
1607
1624
  onExit == null ? void 0 : onExit();
1608
1625
  }
1609
1626
  }
1610
- await walk(
1627
+ await walk2(
1611
1628
  {
1612
1629
  path: dir,
1613
1630
  name: import_path4.default.basename(dir)
@@ -1664,6 +1681,304 @@ var getExternalPluginOptions = (viteConfig) => getConfig(viteConfig, PluginConfi
1664
1681
  var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, PluginConfigKey, value);
1665
1682
  var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
1666
1683
 
1684
+ // src/runtime/url-builder.ts
1685
+ var encode = encodeURIComponent;
1686
+ var pathParts = /* @__PURE__ */ new Map();
1687
+ function parsePathParts(path7) {
1688
+ let parts = pathParts.get(path7);
1689
+ if (!parts) {
1690
+ let lastEnd = 0;
1691
+ let paramStart;
1692
+ pathParts.set(path7, parts = [[]]);
1693
+ while (lastEnd >= 0 && (paramStart = path7.indexOf("/$", lastEnd) + 1)) {
1694
+ parts.push(path7.slice(lastEnd, paramStart++));
1695
+ if (path7.charAt(paramStart) === "$") {
1696
+ paramStart++;
1697
+ lastEnd = -1;
1698
+ } else {
1699
+ lastEnd = path7.indexOf("/", paramStart);
1700
+ }
1701
+ parts[0].push(path7.slice(paramStart, lastEnd < 0 ? void 0 : lastEnd));
1702
+ }
1703
+ parts.push(lastEnd >= 0 ? path7.slice(lastEnd) : "");
1704
+ }
1705
+ return parts;
1706
+ }
1707
+ function joinHref(path7, options) {
1708
+ let result = path7;
1709
+ if (options.search) {
1710
+ const query = "" + new URLSearchParams(options.search);
1711
+ if (query) result += "?" + query;
1712
+ }
1713
+ if (options.hash) result += "#" + encode(options.hash);
1714
+ return result;
1715
+ }
1716
+ function href(path7, ...[options]) {
1717
+ return options ? "params" in options ? ((parts) => href_keys(parts, options, ...parts[0]))(
1718
+ parsePathParts(path7)
1719
+ ) : joinHref(path7, options) : path7;
1720
+ }
1721
+ function href_path(strings, ...params) {
1722
+ let i = 0;
1723
+ let j = 0;
1724
+ let result = strings[i++];
1725
+ if (!result || Array.isArray(result)) result = strings[i++];
1726
+ while (i < strings.length) {
1727
+ const param = params[j++];
1728
+ result += (Array.isArray(param) ? param.map(encode).join("/") : encode(param)) + strings[i++];
1729
+ }
1730
+ return result;
1731
+ }
1732
+ function href_values(strings, options, ...params) {
1733
+ return joinHref(href_path(strings, ...params), options);
1734
+ }
1735
+ function href_keys(strings, options, ...keys) {
1736
+ return href_values(strings, options, ...keys.map((k) => options.params[k]));
1737
+ }
1738
+
1739
+ // src/vite/utils/href-replace.ts
1740
+ function findHrefReplacements(code, ast) {
1741
+ const replacements = [];
1742
+ walk(ast, (node) => {
1743
+ var _a, _b;
1744
+ if (node.type !== "CallExpression") return;
1745
+ const callee = node.callee;
1746
+ if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.object.name !== "Run" || callee.property.type !== "Identifier" || callee.property.name !== "href") {
1747
+ return;
1748
+ }
1749
+ const args = node.arguments;
1750
+ if (args.length === 0 || args.length > 2 || args.some((a) => a.type === "SpreadElement")) {
1751
+ return;
1752
+ }
1753
+ const pathString = (_a = tryStaticEval(args[0])) == null ? void 0 : _a.value;
1754
+ if (typeof pathString !== "string") {
1755
+ replacements.push({
1756
+ helper: "href",
1757
+ edits: [{ start: callee.start, end: callee.end, code: "href" }]
1758
+ });
1759
+ return;
1760
+ }
1761
+ if (args.length === 1) {
1762
+ replacements.push({
1763
+ helper: false,
1764
+ edits: [
1765
+ {
1766
+ start: node.start,
1767
+ end: node.end,
1768
+ code: JSON.stringify(pathString)
1769
+ }
1770
+ ]
1771
+ });
1772
+ return;
1773
+ }
1774
+ const optionsNode = args[1];
1775
+ const optionsObject = (_b = tryStaticEval(optionsNode)) == null ? void 0 : _b.value;
1776
+ if (optionsObject && typeof optionsObject === "object" && !Array.isArray(optionsObject)) {
1777
+ replacements.push({
1778
+ helper: false,
1779
+ edits: [
1780
+ {
1781
+ start: node.start,
1782
+ end: node.end,
1783
+ code: JSON.stringify(href(pathString, optionsObject))
1784
+ }
1785
+ ]
1786
+ });
1787
+ return;
1788
+ }
1789
+ const parsed = parsePathPattern(pathString);
1790
+ if (optionsNode.type === "ObjectExpression") {
1791
+ const params = tryExtractObjectProperty(optionsNode, "params");
1792
+ if (params && parsed.params.every((p) => params.map.has(p))) {
1793
+ const pathPart = buildPathTemplate(code, parsed, params.map);
1794
+ if (params.only) {
1795
+ replacements.push({
1796
+ helper: "href_path",
1797
+ edits: [
1798
+ {
1799
+ start: node.start,
1800
+ end: node.end,
1801
+ code: "href_path`" + pathPart + "`"
1802
+ }
1803
+ ]
1804
+ });
1805
+ } else {
1806
+ const props = optionsNode.properties;
1807
+ const remaining = props.filter((_, i) => i !== params.index);
1808
+ if (remaining.length === 1 && remaining[0].type === "SpreadElement") {
1809
+ replacements.push({
1810
+ helper: "href_values",
1811
+ edits: [
1812
+ {
1813
+ start: node.start,
1814
+ end: remaining[0].argument.start,
1815
+ code: "href_values`${"
1816
+ },
1817
+ {
1818
+ start: remaining[0].argument.end,
1819
+ end: node.end,
1820
+ code: "}" + pathPart + "`"
1821
+ }
1822
+ ]
1823
+ });
1824
+ } else {
1825
+ replacements.push({
1826
+ helper: "href_values",
1827
+ edits: [
1828
+ {
1829
+ start: node.start,
1830
+ end: optionsNode.start,
1831
+ code: "href_values`${"
1832
+ },
1833
+ {
1834
+ start: optionsNode.end,
1835
+ end: node.end,
1836
+ code: "}" + pathPart + "`"
1837
+ },
1838
+ params.index < props.length - 1 ? {
1839
+ start: props[params.index].start,
1840
+ end: props[params.index + 1].start,
1841
+ code: ""
1842
+ } : {
1843
+ start: props[params.index - 1].end,
1844
+ end: props[params.index].end,
1845
+ code: ""
1846
+ }
1847
+ ]
1848
+ });
1849
+ }
1850
+ }
1851
+ return;
1852
+ }
1853
+ }
1854
+ replacements.push({
1855
+ helper: "href_keys",
1856
+ edits: [
1857
+ { start: node.start, end: optionsNode.start, code: "href_keys`${" },
1858
+ {
1859
+ start: optionsNode.end,
1860
+ end: node.end,
1861
+ code: `}${buildPathTemplate(code, parsed)}\``
1862
+ }
1863
+ ]
1864
+ });
1865
+ });
1866
+ return replacements;
1867
+ }
1868
+ function walk(node, visitor) {
1869
+ if (!node || typeof node !== "object") return;
1870
+ if (node.type) {
1871
+ visitor(node);
1872
+ }
1873
+ for (const key of Object.keys(node)) {
1874
+ if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range") {
1875
+ continue;
1876
+ }
1877
+ const child = node[key];
1878
+ if (Array.isArray(child)) {
1879
+ for (const item of child) {
1880
+ if (item && typeof item === "object" && item.type) {
1881
+ walk(item, visitor);
1882
+ }
1883
+ }
1884
+ } else if (child && typeof child === "object" && child.type) {
1885
+ walk(child, visitor);
1886
+ }
1887
+ }
1888
+ }
1889
+ function parsePathPattern(path7) {
1890
+ const parts = parsePathParts(path7);
1891
+ return { segments: parts.slice(1), params: parts[0] };
1892
+ }
1893
+ function buildPathTemplate(code, parsed, paramsMap) {
1894
+ let template = "";
1895
+ for (let i = 0; i < parsed.params.length; i++) {
1896
+ template += parsed.segments[i];
1897
+ if (paramsMap) {
1898
+ const paramProp = paramsMap.get(parsed.params[i]);
1899
+ const valueNode = paramProp.shorthand ? paramProp.key : paramProp.value;
1900
+ template += "${" + code.slice(valueNode.start, valueNode.end) + "}";
1901
+ } else {
1902
+ template += '${"' + parsed.params[i] + '"}';
1903
+ }
1904
+ }
1905
+ if (parsed.segments.length > parsed.params.length) {
1906
+ template += parsed.segments[parsed.segments.length - 1];
1907
+ }
1908
+ return template;
1909
+ }
1910
+ function getStaticKey(prop) {
1911
+ if (prop.computed) return null;
1912
+ if (prop.key.type === "Identifier") return prop.key.name;
1913
+ if (prop.key.type === "Literal" && typeof prop.key.value === "string")
1914
+ return prop.key.value;
1915
+ return null;
1916
+ }
1917
+ function tryStaticEval(node) {
1918
+ switch (node.type) {
1919
+ case "Literal":
1920
+ return { value: node.value };
1921
+ case "TemplateLiteral":
1922
+ return node.expressions.length ? null : { value: node.quasis[0].value.cooked };
1923
+ case "ObjectExpression": {
1924
+ const value = {};
1925
+ for (const prop of node.properties) {
1926
+ if (prop.type === "SpreadElement" || prop.shorthand) return null;
1927
+ const key = getStaticKey(prop);
1928
+ if (!key) return null;
1929
+ const val = tryStaticEval(prop.value);
1930
+ if (!val) return null;
1931
+ value[key] = val.value;
1932
+ }
1933
+ return { value };
1934
+ }
1935
+ case "ArrayExpression": {
1936
+ const value = [];
1937
+ for (const elem of node.elements) {
1938
+ if (!elem || elem.type === "SpreadElement") return null;
1939
+ const val = tryStaticEval(elem);
1940
+ if (!val) return null;
1941
+ value.push(val.value);
1942
+ }
1943
+ return { value };
1944
+ }
1945
+ case "UnaryExpression":
1946
+ if (node.prefix && node.operator === "-") {
1947
+ const arg = tryStaticEval(node.argument);
1948
+ if (arg && typeof arg.value === "number") {
1949
+ return { value: -arg.value };
1950
+ }
1951
+ }
1952
+ return null;
1953
+ default:
1954
+ return null;
1955
+ }
1956
+ }
1957
+ function tryExtractObjectProperty(obj, propertyName) {
1958
+ const props = obj.properties;
1959
+ for (let i = props.length - 1; i >= 0; i--) {
1960
+ const prop = props[i];
1961
+ if (prop.type === "SpreadElement") return null;
1962
+ if (getStaticKey(prop) !== propertyName) continue;
1963
+ if (prop.value.type !== "ObjectExpression") return null;
1964
+ const map = /* @__PURE__ */ new Map();
1965
+ for (const paramProp of prop.value.properties) {
1966
+ if (paramProp.type === "SpreadElement") return null;
1967
+ const paramKey = getStaticKey(paramProp);
1968
+ if (!paramKey) return null;
1969
+ map.set(paramKey, paramProp);
1970
+ }
1971
+ let only = i === props.length - 1;
1972
+ let j = i;
1973
+ while (only && j--) {
1974
+ const prop2 = props[j];
1975
+ only = prop2.type === "Property" && getStaticKey(prop2) === propertyName;
1976
+ }
1977
+ return { map, index: i, only };
1978
+ }
1979
+ return null;
1980
+ }
1981
+
1667
1982
  // src/vite/utils/log.ts
1668
1983
  var import_node_zlib = __toESM(require("node:zlib"), 1);
1669
1984
  var import_cli_table3 = __toESM(require("cli-table3"), 1);
@@ -1848,6 +2163,7 @@ var ReadOncePersistedStore = class {
1848
2163
  constructor(uid) {
1849
2164
  this.uid = uid;
1850
2165
  }
2166
+ uid;
1851
2167
  write(value) {
1852
2168
  values.set(this.uid, value);
1853
2169
  }
@@ -1947,7 +2263,7 @@ function markoRun(opts = {}) {
1947
2263
  var _a, _b;
1948
2264
  routeMarkoApiCache ?? (routeMarkoApiCache = /* @__PURE__ */ new Map());
1949
2265
  if (!routeMarkoApiCache.has(route)) {
1950
- const markoAPI = route.templateFilePath && ((_b = (_a = await loadModule(context, normalizePath(route.layouts[0].filePath))) == null ? void 0 : _a.meta) == null ? void 0 : _b.markoAPI);
2266
+ const markoAPI = route.layouts.length ? (_b = (_a = await loadModule(context, normalizePath(route.layouts[0].filePath))) == null ? void 0 : _a.meta) == null ? void 0 : _b.markoAPI : void 0;
1951
2267
  routeMarkoApiCache.set(route, markoAPI);
1952
2268
  return markoAPI;
1953
2269
  }
@@ -1969,7 +2285,6 @@ function markoRun(opts = {}) {
1969
2285
  let buildVirtualFilesResult;
1970
2286
  function buildVirtualFiles() {
1971
2287
  return buildVirtualFilesResult ?? (buildVirtualFilesResult = (async () => {
1972
- var _a, _b;
1973
2288
  virtualFiles.clear();
1974
2289
  if (import_fs4.default.existsSync(resolvedRoutesDir)) {
1975
2290
  routes = await buildRoutes(
@@ -1994,9 +2309,8 @@ function markoRun(opts = {}) {
1994
2309
  entryTemplates = /* @__PURE__ */ new Set();
1995
2310
  entryTemplateImporters = /* @__PURE__ */ new Set();
1996
2311
  for (const route of routes.list) {
1997
- const routeEntryPath = route.templateFilePath || ((_a = route.page) == null ? void 0 : _a.filePath);
1998
- if (routeEntryPath) {
1999
- entryTemplates.add(normalizePath(routeEntryPath));
2312
+ if (route.templateFilePath) {
2313
+ entryTemplates.add(normalizePath(route.templateFilePath));
2000
2314
  }
2001
2315
  for (const middleware of route.middleware) {
2002
2316
  entryTemplateImporters.add(normalizePath(middleware.filePath));
@@ -2010,9 +2324,8 @@ function markoRun(opts = {}) {
2010
2324
  );
2011
2325
  }
2012
2326
  for (const route of Object.values(routes.special)) {
2013
- const routeEntryPath = route.templateFilePath || ((_b = route.page) == null ? void 0 : _b.filePath);
2014
- if (routeEntryPath) {
2015
- entryTemplates.add(normalizePath(routeEntryPath));
2327
+ if (route.templateFilePath) {
2328
+ entryTemplates.add(normalizePath(route.templateFilePath));
2016
2329
  }
2017
2330
  }
2018
2331
  if (routes.middleware.length) {
@@ -2067,7 +2380,8 @@ function markoRun(opts = {}) {
2067
2380
  route.templateFilePath,
2068
2381
  renderRouteTemplate(
2069
2382
  route,
2070
- await getMarkoApiForRoute(context, route)
2383
+ await getMarkoApiForRoute(context, route),
2384
+ !isBuild
2071
2385
  )
2072
2386
  );
2073
2387
  }
@@ -2077,18 +2391,17 @@ function markoRun(opts = {}) {
2077
2391
  );
2078
2392
  }
2079
2393
  for (const route of Object.values(routes2.special)) {
2080
- if (route.templateFilePath) {
2081
- import_fs4.default.mkdirSync(import_path6.default.dirname(route.templateFilePath), {
2082
- recursive: true
2083
- });
2084
- import_fs4.default.writeFileSync(
2085
- route.templateFilePath,
2086
- renderRouteTemplate(
2087
- route,
2088
- await getMarkoApiForRoute(context, route)
2089
- )
2090
- );
2091
- }
2394
+ import_fs4.default.mkdirSync(import_path6.default.dirname(route.templateFilePath), {
2395
+ recursive: true
2396
+ });
2397
+ import_fs4.default.writeFileSync(
2398
+ route.templateFilePath,
2399
+ renderRouteTemplate(
2400
+ route,
2401
+ await getMarkoApiForRoute(context, route),
2402
+ !isBuild
2403
+ )
2404
+ );
2092
2405
  }
2093
2406
  if (routes2.middleware.length) {
2094
2407
  for (const middleware of routes2.middleware) {
@@ -2149,7 +2462,7 @@ function markoRun(opts = {}) {
2149
2462
  }
2150
2463
  },
2151
2464
  async config(config2, env) {
2152
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A;
2465
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
2153
2466
  const externalPluginOptions = getExternalPluginOptions(config2);
2154
2467
  if (externalPluginOptions) {
2155
2468
  opts = (0, import_vite2.mergeConfig)(opts, externalPluginOptions);
@@ -2196,12 +2509,12 @@ function markoRun(opts = {}) {
2196
2509
  devEntryFilePosix = normalizePath(devEntryFile);
2197
2510
  let outDir = ((_e = config2.build) == null ? void 0 : _e.outDir) || "dist";
2198
2511
  const assetsDir = ((_f = config2.build) == null ? void 0 : _f.assetsDir) || "assets";
2199
- let rollupOutputOptions = (_h = (_g = config2.build) == null ? void 0 : _g.rollupOptions) == null ? void 0 : _h.output;
2512
+ let rolldownOutputOptions = (_h = (_g = config2.build) == null ? void 0 : _g.rolldownOptions) == null ? void 0 : _h.output;
2200
2513
  if (isBuild) {
2201
2514
  if (!isSSRBuild) {
2202
2515
  outDir = import_path6.default.join(outDir, CLIENT_OUT_DIR);
2203
2516
  }
2204
- rollupOutputOptions = mergeOutputOptions(
2517
+ rolldownOutputOptions = mergeOutputOptions(
2205
2518
  {
2206
2519
  assetFileNames(info) {
2207
2520
  var _a2;
@@ -2215,38 +2528,35 @@ function markoRun(opts = {}) {
2215
2528
  },
2216
2529
  chunkFileNames: isSSRBuild ? `_[hash].js` : `${assetsDir}/_[hash].js`
2217
2530
  },
2218
- rollupOutputOptions
2531
+ rolldownOutputOptions
2219
2532
  );
2220
2533
  }
2221
- const browserslistTarget = isBuild && !((_i = config2.build) == null ? void 0 : _i.target) ? (0, import_browserslist.default)(void 0, {
2222
- path: root
2223
- }) : void 0;
2224
- shouldEmptyOutDir = ((_j = config2.build) == null ? void 0 : _j.emptyOutDir) ?? true;
2225
- const pluginConfig = await ((_k = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _k.call(adapter, config2)) || {};
2534
+ shouldEmptyOutDir = ((_i = config2.build) == null ? void 0 : _i.emptyOutDir) ?? true;
2535
+ const pluginConfig = await ((_j = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _j.call(adapter, config2)) || {};
2226
2536
  pluginConfig.ssr ?? (pluginConfig.ssr = {});
2227
- (_l = pluginConfig.ssr).noExternal ?? (_l.noExternal = /@marko\/run($|\/)/);
2537
+ (_k = pluginConfig.ssr).noExternal ?? (_k.noExternal = /@marko\/run($|\/)/);
2228
2538
  pluginConfig.css ?? (pluginConfig.css = {});
2229
- (_m = pluginConfig.css).devSourcemap ?? (_m.devSourcemap = true);
2539
+ (_l = pluginConfig.css).devSourcemap ?? (_l.devSourcemap = true);
2230
2540
  pluginConfig.build ?? (pluginConfig.build = {});
2231
- (_n = pluginConfig.build).outDir ?? (_n.outDir = outDir);
2232
- (_o = pluginConfig.build).assetsDir ?? (_o.assetsDir = assetsDir);
2233
- (_p = pluginConfig.build).copyPublicDir ?? (_p.copyPublicDir = !isSSRBuild);
2234
- (_q = pluginConfig.build).ssrEmitAssets ?? (_q.ssrEmitAssets = false);
2235
- (_r = pluginConfig.build).emptyOutDir ?? (_r.emptyOutDir = false);
2236
- (_s = pluginConfig.build).rollupOptions ?? (_s.rollupOptions = {});
2237
- if (rollupOutputOptions) {
2238
- pluginConfig.build.rollupOptions.output = mergeOutputOptions(
2239
- rollupOutputOptions,
2240
- pluginConfig.build.rollupOptions.output
2541
+ (_m = pluginConfig.build).outDir ?? (_m.outDir = outDir);
2542
+ (_n = pluginConfig.build).assetsDir ?? (_n.assetsDir = assetsDir);
2543
+ (_o = pluginConfig.build).copyPublicDir ?? (_o.copyPublicDir = !isSSRBuild);
2544
+ (_p = pluginConfig.build).ssrEmitAssets ?? (_p.ssrEmitAssets = false);
2545
+ (_q = pluginConfig.build).emptyOutDir ?? (_q.emptyOutDir = false);
2546
+ (_r = pluginConfig.build).rolldownOptions ?? (_r.rolldownOptions = {});
2547
+ if (rolldownOutputOptions) {
2548
+ pluginConfig.build.rolldownOptions.output = mergeOutputOptions(
2549
+ rolldownOutputOptions,
2550
+ pluginConfig.build.rolldownOptions.output
2241
2551
  );
2242
2552
  }
2243
- (_u = pluginConfig.build).sourcemap ?? (_u.sourcemap = ((_t = config2.build) == null ? void 0 : _t.sourcemap) ?? (isBuild && !isSSRBuild));
2244
- (_v = pluginConfig.build).modulePreload ?? (_v.modulePreload = {});
2553
+ (_t = pluginConfig.build).sourcemap ?? (_t.sourcemap = ((_s = config2.build) == null ? void 0 : _s.sourcemap) ?? (isBuild && !isSSRBuild));
2554
+ (_u = pluginConfig.build).modulePreload ?? (_u.modulePreload = {});
2245
2555
  if (typeof pluginConfig.build.modulePreload !== "boolean") {
2246
2556
  pluginConfig.build.modulePreload.polyfill = false;
2247
2557
  }
2248
2558
  pluginConfig.optimizeDeps ?? (pluginConfig.optimizeDeps = {});
2249
- if (!((_w = config2.optimizeDeps) == null ? void 0 : _w.entries)) {
2559
+ if (!((_v = config2.optimizeDeps) == null ? void 0 : _v.entries)) {
2250
2560
  pluginConfig.optimizeDeps.entries = [
2251
2561
  `${normalizePath(import_path6.default.relative(root, routesDir))}/**/*+{page,layout}.marko`,
2252
2562
  "!**/__snapshots__/**",
@@ -2254,21 +2564,16 @@ function markoRun(opts = {}) {
2254
2564
  "!**/coverage/**"
2255
2565
  ];
2256
2566
  }
2257
- if (browserslistTarget == null ? void 0 : browserslistTarget.length) {
2258
- (_x = pluginConfig.build).target ?? (_x.target = (0, import_esbuild_plugin_browserslist.resolveToEsbuildTarget)(
2259
- browserslistTarget,
2260
- {
2261
- printUnknownTargets: false
2262
- }
2263
- ));
2567
+ if (isBuild && !((_w = config2.build) == null ? void 0 : _w.target)) {
2568
+ pluginConfig.build.target = getBrowserslistTargets(root);
2264
2569
  }
2265
2570
  if (isBuild) {
2266
2571
  pluginConfig.logLevel ?? (pluginConfig.logLevel = "warn");
2267
2572
  pluginConfig.define ?? (pluginConfig.define = {});
2268
- (_y = pluginConfig.define)["process.env.NODE_ENV"] ?? (_y["process.env.NODE_ENV"] = "'production'");
2573
+ (_x = pluginConfig.define)["process.env.NODE_ENV"] ?? (_x["process.env.NODE_ENV"] = "'production'");
2269
2574
  pluginConfig.resolve ?? (pluginConfig.resolve = {});
2270
- (_z = pluginConfig.resolve).mainFields ?? (_z.mainFields = (isSSRBuild ? [] : ["browser"]).concat(["module", "jsnext:main", "jsnext", "main"]));
2271
- (_A = pluginConfig.resolve).conditions ?? (_A.conditions = [
2575
+ (_y = pluginConfig.resolve).mainFields ?? (_y.mainFields = (isSSRBuild ? [] : ["browser"]).concat(["module", "jsnext:main", "jsnext", "main"]));
2576
+ (_z = pluginConfig.resolve).conditions ?? (_z.conditions = [
2272
2577
  isSSRBuild ? "node" : "browser",
2273
2578
  "import",
2274
2579
  "require",
@@ -2282,7 +2587,7 @@ function markoRun(opts = {}) {
2282
2587
  resolvedConfig = config2;
2283
2588
  const {
2284
2589
  ssr,
2285
- rollupOptions: { input }
2590
+ rolldownOptions: { input }
2286
2591
  } = config2.build;
2287
2592
  if (typeof ssr === "string") {
2288
2593
  ssrEntryFiles = [ssr];
@@ -2401,6 +2706,48 @@ function markoRun(opts = {}) {
2401
2706
  {
2402
2707
  name: `${PLUGIN_NAME_PREFIX}:post`,
2403
2708
  enforce: "post",
2709
+ async transform(code) {
2710
+ if (!isBuild || isSSRBuild || !code.includes("Run.href")) {
2711
+ return;
2712
+ }
2713
+ try {
2714
+ const replacements = findHrefReplacements(
2715
+ code,
2716
+ this.parse(code, { lang: "js" })
2717
+ );
2718
+ if (replacements.length) {
2719
+ const helpers = /* @__PURE__ */ new Set();
2720
+ const s = new import_rolldown.RolldownMagicString(code);
2721
+ for (const { helper, edits } of replacements) {
2722
+ for (const { start, end, code: code2 } of edits) {
2723
+ if (code2) {
2724
+ s.overwrite(start, end, code2);
2725
+ } else {
2726
+ s.remove(start, end);
2727
+ }
2728
+ }
2729
+ if (helper) {
2730
+ helpers.add(helper);
2731
+ }
2732
+ }
2733
+ if (helpers.size) {
2734
+ s.prepend(
2735
+ `import { ${[...helpers].join(", ")} } from "virtual:marko-run/runtime/url-builder";`
2736
+ );
2737
+ }
2738
+ return {
2739
+ code: s
2740
+ };
2741
+ }
2742
+ return null;
2743
+ } catch {
2744
+ return {
2745
+ code: new import_rolldown.RolldownMagicString(code).prepend(
2746
+ 'import "virtual:marko-run/runtime/client";'
2747
+ )
2748
+ };
2749
+ }
2750
+ },
2404
2751
  generateBundle(options, bundle) {
2405
2752
  if (options.sourcemap && options.sourcemap !== "inline") {
2406
2753
  for (const key of Object.keys(bundle)) {
@@ -2566,6 +2913,33 @@ var defaultConfigPlugin = {
2566
2913
  };
2567
2914
  }
2568
2915
  };
2916
+ function getBrowserslistTargets(path7) {
2917
+ var _a;
2918
+ const browserslistTarget = (0, import_browserslist.default)(void 0, { path: path7 });
2919
+ if (browserslistTarget.length) {
2920
+ const versions = /* @__PURE__ */ new Map();
2921
+ for (const target of (0, import_esbuild_plugin_browserslist.resolveToEsbuildTarget)(browserslistTarget, {
2922
+ printUnknownTargets: false
2923
+ })) {
2924
+ const index = (_a = /\d/.exec(target)) == null ? void 0 : _a.index;
2925
+ if (index) {
2926
+ const browser = target.slice(0, index);
2927
+ const version = Number(target.slice(index));
2928
+ const existingVersion = versions.get(browser);
2929
+ if (!existingVersion || version < existingVersion) {
2930
+ versions.set(browser, version);
2931
+ }
2932
+ }
2933
+ }
2934
+ if (versions.size) {
2935
+ const targets = [];
2936
+ for (const [browser, version] of versions) {
2937
+ targets.push(browser + version);
2938
+ }
2939
+ return targets;
2940
+ }
2941
+ }
2942
+ }
2569
2943
 
2570
2944
  // src/vite/utils/meta-data.ts
2571
2945
  var verbKeys = new Set(httpVerbs.map((v) => v.toUpperCase()));