@marko/run 0.7.1 → 0.7.3

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.
@@ -1,6 +1,7 @@
1
- import { getDevGlobal } from "@marko/run/adapter";
1
+ import { getDevGlobal, resolveAdapter } from "@marko/run/adapter";
2
+ import plugin, { defaultConfigPlugin } from "@marko/run/vite";
2
3
  import net from "net";
3
- import { createServer } from "vite";
4
+ import { createServer, resolveConfig } from "vite";
4
5
 
5
6
  process
6
7
  .on("message", (message) => {
@@ -14,9 +15,27 @@ process
14
15
  .send("ready");
15
16
 
16
17
  async function start(entry, config) {
17
- if (config.plugins) {
18
- const plugin = await import("@marko/run/vite");
19
- config.plugins = plugin.default();
18
+ if (config.plugins?.length) {
19
+ const resolvedConfig = await resolveConfig(
20
+ {
21
+ root: config.root,
22
+ configFile: config.configFile,
23
+ logLevel: "silent",
24
+ plugins: [defaultConfigPlugin],
25
+ },
26
+ "serve",
27
+ );
28
+ const adapter = await resolveAdapter(resolvedConfig);
29
+ const plugins =
30
+ (adapter.plugins &&
31
+ (await adapter.plugins({ root: config.root, command: "dev" }))) ||
32
+ [];
33
+
34
+ if (plugins.some((plugin) => plugin.name === "marko-run-vite:pre")) {
35
+ plugins.push(...plugin());
36
+ }
37
+
38
+ config.plugins = plugins;
20
39
  }
21
40
 
22
41
  globalThis.__marko_run_vite_config__ = config;
@@ -14,13 +14,16 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
14
14
  import sade from "sade";
15
15
 
16
16
  // src/cli/commands.ts
17
+ import fs6 from "fs";
18
+ import path9 from "path";
19
+ import { fileURLToPath as fileURLToPath3 } from "url";
20
+ import { build as viteBuild, resolveConfig } from "vite";
21
+
22
+ // src/adapter/index.ts
17
23
  import fs5 from "fs";
18
- import path7 from "path";
24
+ import inspector from "inspector";
25
+ import path8 from "path";
19
26
  import { fileURLToPath as fileURLToPath2 } from "url";
20
- import {
21
- build as viteBuild,
22
- resolveConfig
23
- } from "vite";
24
27
 
25
28
  // src/vite/plugin.ts
26
29
  import markoVitePlugin from "@marko/vite";
@@ -472,7 +475,7 @@ function writeRouteEntryHandler(writer, route, verb) {
472
475
  continuations.join();
473
476
  writer.writeBlockEnd("}");
474
477
  }
475
- function renderRouter(routes, rootDir, options = {
478
+ function renderRouter(routes, rootDir, runtimeInclude, options = {
476
479
  trailingSlashes: "RedirectWithout"
477
480
  }) {
478
481
  const writer = createStringWriter();
@@ -480,6 +483,9 @@ function renderRouter(routes, rootDir, options = {
480
483
  const hasNotFoundPage = Boolean(routes.special[RoutableFileTypes.NotFound]);
481
484
  writer.writeLines(`// @marko/run/router`);
482
485
  const imports = writer.branch("imports");
486
+ if (runtimeInclude) {
487
+ imports.writeLines(`import "${normalizePath(runtimeInclude)}";`);
488
+ }
483
489
  imports.writeLines(
484
490
  `import { NotHandled, NotMatched, createContext } from "${virtualFilePrefix}/runtime/internal";`
485
491
  );
@@ -668,14 +674,14 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
668
674
  if (useSwitch) {
669
675
  writer.writeBlockStart(`switch (${value}) {`);
670
676
  }
671
- for (const { key, path: path8, route: route2 } of terminal) {
677
+ for (const { key, path: path10, route: route2 } of terminal) {
672
678
  const decodedKey = decodeURIComponent(key);
673
679
  if (useSwitch) {
674
680
  writer.write(`case '${decodedKey}': `, true);
675
681
  } else {
676
682
  writer.write(`if (${value} === '${decodedKey}') `, true);
677
683
  }
678
- writer.write(`return ${renderMatch(verb, route2, path8)};
684
+ writer.write(`return ${renderMatch(verb, route2, path10)};
679
685
  `);
680
686
  }
681
687
  if (useSwitch) {
@@ -777,11 +783,11 @@ function renderParams(params, pathIndex) {
777
783
  }
778
784
  return result ? result + " }" : "{}";
779
785
  }
780
- function renderMatch(verb, route, path8, pathIndex) {
786
+ function renderMatch(verb, route, path10, pathIndex) {
781
787
  const handler = `${verb}${route.index}`;
782
- const params = path8.params ? renderParams(path8.params, pathIndex) : "{}";
788
+ const params = path10.params ? renderParams(path10.params, pathIndex) : "{}";
783
789
  const meta = route.meta ? `meta${route.index}` : "{}";
784
- return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path8.path}' }`;
790
+ return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path10.path}' }`;
785
791
  }
786
792
  function renderMiddleware(middleware, rootDir) {
787
793
  const writer = createStringWriter();
@@ -803,18 +809,18 @@ function renderMiddleware(middleware, rootDir) {
803
809
  imports.join();
804
810
  return writer.end();
805
811
  }
806
- function stripTsExtension(path8) {
807
- const index = path8.lastIndexOf(".");
812
+ function stripTsExtension(path10) {
813
+ const index = path10.lastIndexOf(".");
808
814
  if (index !== -1) {
809
- const ext = path8.slice(index + 1);
815
+ const ext = path10.slice(index + 1);
810
816
  if (ext.toLowerCase() === "ts") {
811
- return path8.slice(0, index);
817
+ return path10.slice(0, index);
812
818
  }
813
819
  }
814
- return path8;
820
+ return path10;
815
821
  }
816
- function decodePath(path8) {
817
- return path8;
822
+ function decodePath(path10) {
823
+ return path10;
818
824
  }
819
825
  async function renderRouteTypeInfo(routes, outDir, adapter) {
820
826
  var _a, _b, _c, _d;
@@ -972,11 +978,11 @@ function createRouteTrie(routes) {
972
978
  const root = {
973
979
  key: ""
974
980
  };
975
- function insert(path8, route) {
981
+ function insert(path10, route) {
976
982
  let node = root;
977
- for (const segment of path8.segments) {
983
+ for (const segment of path10.segments) {
978
984
  if (segment === "$$") {
979
- node.catchAll ?? (node.catchAll = { route, path: path8 });
985
+ node.catchAll ?? (node.catchAll = { route, path: path10 });
980
986
  return;
981
987
  } else if (segment === "$") {
982
988
  node = node.dynamic ?? (node.dynamic = {
@@ -994,7 +1000,7 @@ function createRouteTrie(routes) {
994
1000
  node = next;
995
1001
  }
996
1002
  }
997
- node.path ?? (node.path = path8);
1003
+ node.path ?? (node.path = path10);
998
1004
  node.route ?? (node.route = route);
999
1005
  }
1000
1006
  for (const route of routes) {
@@ -1044,9 +1050,9 @@ function parseFlatRoute(pattern) {
1044
1050
  } else if (charCode === 44 /* Alternate */) {
1045
1051
  if (!current) {
1046
1052
  segmentEnd(
1047
- basePaths.map((path8) => ({
1048
- ...path8,
1049
- segments: path8.segments.slice()
1053
+ basePaths.map((path10) => ({
1054
+ ...path10,
1055
+ segments: path10.segments.slice()
1050
1056
  })),
1051
1057
  escaped,
1052
1058
  "_",
@@ -1083,9 +1089,9 @@ function parseFlatRoute(pattern) {
1083
1089
  } else if (charCode === 36 /* Dynamic */) {
1084
1090
  type = pattern.charCodeAt(i + 1) === 36 ? "$$" : "$";
1085
1091
  }
1086
- current ?? (current = basePaths.map((path8) => ({
1087
- ...path8,
1088
- segments: path8.segments.slice()
1092
+ current ?? (current = basePaths.map((path10) => ({
1093
+ ...path10,
1094
+ segments: path10.segments.slice()
1089
1095
  })));
1090
1096
  i = len;
1091
1097
  for (const char of delimiters) {
@@ -1110,9 +1116,9 @@ function parseFlatRoute(pattern) {
1110
1116
  }
1111
1117
  if (!current) {
1112
1118
  segmentEnd(
1113
- basePaths.map((path8) => ({
1114
- ...path8,
1115
- segments: path8.segments.slice()
1119
+ basePaths.map((path10) => ({
1120
+ ...path10,
1121
+ segments: path10.segments.slice()
1116
1122
  })),
1117
1123
  escaped,
1118
1124
  void 0,
@@ -1141,9 +1147,9 @@ function parseFlatRoute(pattern) {
1141
1147
  segment.param = normalizeParam(raw.slice(type.length));
1142
1148
  }
1143
1149
  }
1144
- for (const path8 of paths) {
1150
+ for (const path10 of paths) {
1145
1151
  if (segment) {
1146
- if (path8.isCatchall) {
1152
+ if (path10.isCatchall) {
1147
1153
  throw new Error(
1148
1154
  `Invalid route pattern: nested segments are not allowed after a catch-all parameter. Found '.' following '${pattern.slice(
1149
1155
  0,
@@ -1151,22 +1157,22 @@ function parseFlatRoute(pattern) {
1151
1157
  )}' in '${pattern}'.`
1152
1158
  );
1153
1159
  }
1154
- path8.segments.push(segment);
1155
- path8.id += path8.id === "/" ? segment.name : `/${segment.name}`;
1160
+ path10.segments.push(segment);
1161
+ path10.id += path10.id === "/" ? segment.name : `/${segment.name}`;
1156
1162
  if (type === "$$") {
1157
- path8.isCatchall = true;
1163
+ path10.isCatchall = true;
1158
1164
  }
1159
1165
  }
1160
1166
  if (map) {
1161
- if (map.has(path8.id)) {
1162
- const existing = map.get(path8.id);
1167
+ if (map.has(path10.id)) {
1168
+ const existing = map.get(path10.id);
1163
1169
  const existingExpansion = existing.segments.map((s) => s.raw).join(".");
1164
- const currentExpansion = path8.segments.map((s) => s.raw).join(".");
1170
+ const currentExpansion = path10.segments.map((s) => s.raw).join(".");
1165
1171
  throw new Error(
1166
- `Invalid route pattern: route '${path8.id}' is ambiguous. Expansion '${currentExpansion}' collides with '${existingExpansion}' in '${pattern}'.`
1172
+ `Invalid route pattern: route '${path10.id}' is ambiguous. Expansion '${currentExpansion}' collides with '${existingExpansion}' in '${pattern}'.`
1167
1173
  );
1168
1174
  }
1169
- map.set(path8.id, path8);
1175
+ map.set(path10.id, path10);
1170
1176
  }
1171
1177
  }
1172
1178
  }
@@ -1241,11 +1247,11 @@ var _VDir = class _VDir {
1241
1247
  });
1242
1248
  return value;
1243
1249
  }
1244
- addDir(path8, segment) {
1250
+ addDir(path10, segment) {
1245
1251
  const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
1246
1252
  const key = segment.type === "$" ? segment.raw : segment.name;
1247
1253
  if (!map.has(key)) {
1248
- const dir = new _VDir(this, segment, path8);
1254
+ const dir = new _VDir(this, segment, path10);
1249
1255
  map.set(key, dir);
1250
1256
  return dir;
1251
1257
  }
@@ -1291,10 +1297,10 @@ var _VDir = class _VDir {
1291
1297
  const dirs = [];
1292
1298
  const unique = /* @__PURE__ */ new Map();
1293
1299
  for (const root of roots) {
1294
- for (const path8 of paths) {
1300
+ for (const path10 of paths) {
1295
1301
  let dir = root;
1296
- for (const segment of path8.segments) {
1297
- dir = dir.addDir(path8, segment);
1302
+ for (const segment of path10.segments) {
1303
+ dir = dir.addDir(path10, segment);
1298
1304
  }
1299
1305
  const existing = unique.get(dir.path);
1300
1306
  if (existing) {
@@ -1307,7 +1313,7 @@ var _VDir = class _VDir {
1307
1313
  }
1308
1314
  }
1309
1315
  throw new Error(
1310
- `Ambiguous directory structure: ${sourcePath}${path8.source} defines ${dir.path} multiple times.`
1316
+ `Ambiguous directory structure: ${sourcePath}${path10.source} defines ${dir.path} multiple times.`
1311
1317
  );
1312
1318
  } else {
1313
1319
  unique.set(dir.path, dir);
@@ -1762,8 +1768,8 @@ function prettySize([bytes, compBytes]) {
1762
1768
  else str += kleur2.bold(kleur2.red(compSize));
1763
1769
  return str;
1764
1770
  }
1765
- function prettyPath(path8) {
1766
- return path8.replace(
1771
+ function prettyPath(path10) {
1772
+ return path10.replace(
1767
1773
  /\/(\$\$?)(`?)([^/`]+)\2/g,
1768
1774
  (_, type, tick, key) => "/" + type + tick + kleur2.bold(kleur2.dim(key)) + tick
1769
1775
  );
@@ -1908,7 +1914,7 @@ function markoRun(opts = {}) {
1908
1914
  let renderVirtualFilesResult;
1909
1915
  function renderVirtualFiles(context) {
1910
1916
  return renderVirtualFilesResult ?? (renderVirtualFilesResult = (async () => {
1911
- var _a;
1917
+ var _a, _b;
1912
1918
  try {
1913
1919
  const routes2 = await buildVirtualFiles();
1914
1920
  if (fs3.existsSync(entryFilesDir)) {
@@ -1971,9 +1977,10 @@ function markoRun(opts = {}) {
1971
1977
  renderMiddleware(routes2.middleware, root)
1972
1978
  );
1973
1979
  }
1980
+ const runtimeInclude = await ((_a = adapter == null ? void 0 : adapter.runtimeInclude) == null ? void 0 : _a.call(adapter));
1974
1981
  virtualFiles.set(
1975
1982
  path6.posix.join(root, ROUTER_FILENAME),
1976
- renderRouter(routes2, root, {
1983
+ renderRouter(routes2, root, runtimeInclude, {
1977
1984
  trailingSlashes
1978
1985
  })
1979
1986
  );
@@ -1988,7 +1995,7 @@ function markoRun(opts = {}) {
1988
1995
  }
1989
1996
  });
1990
1997
  if (!isBuild) {
1991
- await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes2.list));
1998
+ await ((_b = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _b.call(opts, routes2.list));
1992
1999
  }
1993
2000
  }
1994
2001
  } catch (err) {
@@ -2463,8 +2470,60 @@ async function getAvailablePort(port) {
2463
2470
  });
2464
2471
  }
2465
2472
 
2473
+ // src/adapter/dev-server.ts
2474
+ import path7 from "path";
2475
+ import {
2476
+ buildErrorMessage as buildErrorMessage2,
2477
+ createServer
2478
+ } from "vite";
2479
+
2480
+ // src/adapter/logger.ts
2481
+ import DraftLog from "draftlog";
2482
+ import format2 from "human-format";
2483
+ import inpspector from "inspector";
2484
+ import kleur3 from "kleur";
2485
+ if (!inpspector.url()) {
2486
+ DraftLog.into(console);
2487
+ DraftLog.defaults.canReWrite = false;
2488
+ }
2489
+ var IdChars = [
2490
+ "",
2491
+ kleur3.cyan("\xB9"),
2492
+ kleur3.magenta("\xB2"),
2493
+ kleur3.green("\xB3"),
2494
+ kleur3.red("\u2074"),
2495
+ kleur3.cyan("\u2075"),
2496
+ kleur3.magenta("\u2076"),
2497
+ kleur3.green("\u2077"),
2498
+ kleur3.red("\u2078"),
2499
+ kleur3.cyan("\u2079"),
2500
+ kleur3.red("\u207A")
2501
+ ];
2502
+
2503
+ // src/adapter/middleware.ts
2504
+ import { Readable } from "node:stream";
2505
+ var bodyConsumedErrorStream = new ReadableStream({
2506
+ pull(controller) {
2507
+ controller.error(
2508
+ new Error(
2509
+ "The request body stream has been destroyed or consumed by something before Marko Run."
2510
+ )
2511
+ );
2512
+ }
2513
+ });
2514
+
2515
+ // src/adapter/index.ts
2516
+ import parseNodeArgs from "parse-node-args";
2517
+ var __dirname2 = path8.dirname(fileURLToPath2(import.meta.url));
2518
+ var defaultEntry = path8.join(__dirname2, "default-entry");
2519
+ var loadDevWorker = path8.join(__dirname2, "load-dev-worker.mjs");
2520
+ async function resolveAdapter2(config2) {
2521
+ const options = getExternalPluginOptions(config2);
2522
+ return resolveAdapter(config2.root, options);
2523
+ }
2524
+
2466
2525
  // src/cli/commands.ts
2467
- var __dirname2 = path7.dirname(fileURLToPath2(import.meta.url));
2526
+ var __dirname3 = path9.dirname(fileURLToPath3(import.meta.url));
2468
2527
  var defaultConfigFileBases = ["vite.config"];
2469
2528
  var defaultConfigFileExts = [".js", ".cjs", ".mjs", ".ts", ".mts"];
2470
2529
  async function preview(entry, distEntry, cwd, configFile, port, outDir, envFile, args = []) {
@@ -2493,10 +2552,10 @@ async function preview(entry, distEntry, cwd, configFile, port, outDir, envFile,
2493
2552
  if (!entry) {
2494
2553
  entry = await ((_a = adapter.getEntryFile) == null ? void 0 : _a.call(adapter));
2495
2554
  }
2496
- const dir = path7.resolve(cwd, resolvedConfig.build.outDir);
2497
- const entryFile = distEntry ? path7.join(dir, distEntry) : findFileWithExt(dir, "index", [".mjs", ".js"]);
2555
+ const dir = path9.resolve(cwd, resolvedConfig.build.outDir);
2556
+ const entryFile = distEntry ? path9.join(dir, distEntry) : findFileWithExt(dir, "index", [".mjs", ".js"]);
2498
2557
  if (envFile) {
2499
- envFile = path7.resolve(cwd, envFile);
2558
+ envFile = path9.resolve(cwd, envFile);
2500
2559
  }
2501
2560
  const options = {
2502
2561
  cwd,
@@ -2524,7 +2583,7 @@ async function dev(entry, cwd, configFile, port, envFile, args = []) {
2524
2583
  "serve"
2525
2584
  );
2526
2585
  if (envFile) {
2527
- envFile = path7.resolve(cwd, envFile);
2586
+ envFile = path9.resolve(cwd, envFile);
2528
2587
  }
2529
2588
  const [availablePort, adapter] = await Promise.all([
2530
2589
  getAvailablePort(
@@ -2582,7 +2641,7 @@ async function build(entry, cwd, configFile, outDir, envFile) {
2582
2641
  }
2583
2642
  }
2584
2643
  if (envFile) {
2585
- envFile = path7.resolve(cwd, envFile);
2644
+ envFile = path9.resolve(cwd, envFile);
2586
2645
  }
2587
2646
  let plugins = adapter.plugins && await adapter.plugins({ root, command: "build" });
2588
2647
  if (!isPluginIncluded(resolvedConfig)) {
@@ -2624,8 +2683,8 @@ async function build(entry, cwd, configFile, outDir, envFile) {
2624
2683
  }
2625
2684
  function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
2626
2685
  for (const ext of extensions) {
2627
- const filePath = path7.join(dir, base + ext);
2628
- if (fs5.existsSync(filePath)) {
2686
+ const filePath = path9.join(dir, base + ext);
2687
+ if (fs6.existsSync(filePath)) {
2629
2688
  return filePath;
2630
2689
  }
2631
2690
  }
@@ -2633,8 +2692,8 @@ function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
2633
2692
  }
2634
2693
  async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
2635
2694
  if (configFile) {
2636
- const configFilePath = path7.join(dir, configFile);
2637
- if (!fs5.existsSync(configFilePath)) {
2695
+ const configFilePath = path9.join(dir, configFile);
2696
+ if (!fs6.existsSync(configFilePath)) {
2638
2697
  throw new Error(`No config file found at '${configFilePath}'`);
2639
2698
  }
2640
2699
  return configFile;
@@ -2645,11 +2704,7 @@ async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
2645
2704
  return configFile;
2646
2705
  }
2647
2706
  }
2648
- return path7.join(__dirname2, "default.config.mjs");
2649
- }
2650
- async function resolveAdapter2(config2) {
2651
- const options = getExternalPluginOptions(config2);
2652
- return resolveAdapter(config2.root, options);
2707
+ return path9.join(__dirname3, "default.config.mjs");
2653
2708
  }
2654
2709
 
2655
2710
  // src/cli/index.ts
@@ -1,6 +1,6 @@
1
1
  import type { Adapter, BuiltRoutes, RoutableFile, Route, RouterOptions } from "../types";
2
2
  export declare function renderRouteTemplate(route: Route, rootDir: string): string;
3
3
  export declare function renderRouteEntry(route: Route, rootDir: string): string;
4
- export declare function renderRouter(routes: BuiltRoutes, rootDir: string, options?: RouterOptions): string;
4
+ export declare function renderRouter(routes: BuiltRoutes, rootDir: string, runtimeInclude: string | undefined, options?: RouterOptions): string;
5
5
  export declare function renderMiddleware(middleware: RoutableFile[], rootDir: string): string;
6
6
  export declare function renderRouteTypeInfo(routes: BuiltRoutes, outDir: string, adapter?: Adapter | null): Promise<string>;
@@ -40,6 +40,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
40
40
  var vite_exports = {};
41
41
  __export(vite_exports, {
42
42
  default: () => markoRun,
43
+ defaultConfigPlugin: () => defaultConfigPlugin,
43
44
  getAvailablePort: () => getAvailablePort,
44
45
  getPackageData: () => getPackageData,
45
46
  isPortInUse: () => isPortInUse,
@@ -501,7 +502,7 @@ function writeRouteEntryHandler(writer, route, verb) {
501
502
  continuations.join();
502
503
  writer.writeBlockEnd("}");
503
504
  }
504
- function renderRouter(routes, rootDir, options = {
505
+ function renderRouter(routes, rootDir, runtimeInclude, options = {
505
506
  trailingSlashes: "RedirectWithout"
506
507
  }) {
507
508
  const writer = createStringWriter();
@@ -509,6 +510,9 @@ function renderRouter(routes, rootDir, options = {
509
510
  const hasNotFoundPage = Boolean(routes.special[RoutableFileTypes.NotFound]);
510
511
  writer.writeLines(`// @marko/run/router`);
511
512
  const imports = writer.branch("imports");
513
+ if (runtimeInclude) {
514
+ imports.writeLines(`import "${normalizePath(runtimeInclude)}";`);
515
+ }
512
516
  imports.writeLines(
513
517
  `import { NotHandled, NotMatched, createContext } from "${virtualFilePrefix}/runtime/internal";`
514
518
  );
@@ -1936,7 +1940,7 @@ function markoRun(opts = {}) {
1936
1940
  let renderVirtualFilesResult;
1937
1941
  function renderVirtualFiles(context) {
1938
1942
  return renderVirtualFilesResult ?? (renderVirtualFilesResult = (async () => {
1939
- var _a;
1943
+ var _a, _b;
1940
1944
  try {
1941
1945
  const routes2 = await buildVirtualFiles();
1942
1946
  if (import_fs4.default.existsSync(entryFilesDir)) {
@@ -1999,9 +2003,10 @@ function markoRun(opts = {}) {
1999
2003
  renderMiddleware(routes2.middleware, root)
2000
2004
  );
2001
2005
  }
2006
+ const runtimeInclude = await ((_a = adapter == null ? void 0 : adapter.runtimeInclude) == null ? void 0 : _a.call(adapter));
2002
2007
  virtualFiles.set(
2003
2008
  import_path6.default.posix.join(root, ROUTER_FILENAME),
2004
- renderRouter(routes2, root, {
2009
+ renderRouter(routes2, root, runtimeInclude, {
2005
2010
  trailingSlashes
2006
2011
  })
2007
2012
  );
@@ -2016,7 +2021,7 @@ function markoRun(opts = {}) {
2016
2021
  }
2017
2022
  });
2018
2023
  if (!isBuild) {
2019
- await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes2.list));
2024
+ await ((_b = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _b.call(opts, routes2.list));
2020
2025
  }
2021
2026
  }
2022
2027
  } catch (err) {
@@ -2590,6 +2595,7 @@ function sleep(ms) {
2590
2595
  }
2591
2596
  // Annotate the CommonJS export names for ESM import in node:
2592
2597
  0 && (module.exports = {
2598
+ defaultConfigPlugin,
2593
2599
  getAvailablePort,
2594
2600
  getPackageData,
2595
2601
  isPortInUse,
@@ -1,4 +1,4 @@
1
- export { default, getPackageData } from "./plugin";
1
+ export { default, defaultConfigPlugin, getPackageData } from "./plugin";
2
2
  export type { Adapter, AdapterConfig, BuiltRoutes, ExplorerData, HttpVerb, Options, PackageData, PathInfo, RoutableFile, RoutableFileType, Route, RouteGenerationData, } from "./types";
3
3
  export type { SpawnedServer } from "./utils/server";
4
4
  export { getAvailablePort, isPortInUse, loadEnv, parseEnv, spawnServer, spawnServerWorker, } from "./utils/server";
@@ -459,7 +459,7 @@ function writeRouteEntryHandler(writer, route, verb) {
459
459
  continuations.join();
460
460
  writer.writeBlockEnd("}");
461
461
  }
462
- function renderRouter(routes, rootDir, options = {
462
+ function renderRouter(routes, rootDir, runtimeInclude, options = {
463
463
  trailingSlashes: "RedirectWithout"
464
464
  }) {
465
465
  const writer = createStringWriter();
@@ -467,6 +467,9 @@ function renderRouter(routes, rootDir, options = {
467
467
  const hasNotFoundPage = Boolean(routes.special[RoutableFileTypes.NotFound]);
468
468
  writer.writeLines(`// @marko/run/router`);
469
469
  const imports = writer.branch("imports");
470
+ if (runtimeInclude) {
471
+ imports.writeLines(`import "${normalizePath(runtimeInclude)}";`);
472
+ }
470
473
  imports.writeLines(
471
474
  `import { NotHandled, NotMatched, createContext } from "${virtualFilePrefix}/runtime/internal";`
472
475
  );
@@ -1894,7 +1897,7 @@ function markoRun(opts = {}) {
1894
1897
  let renderVirtualFilesResult;
1895
1898
  function renderVirtualFiles(context) {
1896
1899
  return renderVirtualFilesResult ?? (renderVirtualFilesResult = (async () => {
1897
- var _a;
1900
+ var _a, _b;
1898
1901
  try {
1899
1902
  const routes2 = await buildVirtualFiles();
1900
1903
  if (fs3.existsSync(entryFilesDir)) {
@@ -1957,9 +1960,10 @@ function markoRun(opts = {}) {
1957
1960
  renderMiddleware(routes2.middleware, root)
1958
1961
  );
1959
1962
  }
1963
+ const runtimeInclude = await ((_a = adapter == null ? void 0 : adapter.runtimeInclude) == null ? void 0 : _a.call(adapter));
1960
1964
  virtualFiles.set(
1961
1965
  path6.posix.join(root, ROUTER_FILENAME),
1962
- renderRouter(routes2, root, {
1966
+ renderRouter(routes2, root, runtimeInclude, {
1963
1967
  trailingSlashes
1964
1968
  })
1965
1969
  );
@@ -1974,7 +1978,7 @@ function markoRun(opts = {}) {
1974
1978
  }
1975
1979
  });
1976
1980
  if (!isBuild) {
1977
- await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes2.list));
1981
+ await ((_b = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _b.call(opts, routes2.list));
1978
1982
  }
1979
1983
  }
1980
1984
  } catch (err) {
@@ -2548,6 +2552,7 @@ function sleep(ms) {
2548
2552
  }
2549
2553
  export {
2550
2554
  markoRun as default,
2555
+ defaultConfigPlugin,
2551
2556
  getAvailablePort,
2552
2557
  getPackageData,
2553
2558
  isPortInUse,
@@ -26,7 +26,7 @@ export interface Adapter {
26
26
  plugins?(event: {
27
27
  root: string;
28
28
  command: "dev" | "build";
29
- }): Promise<Plugin[]> | Plugin[] | undefined;
29
+ }): Promise<Plugin[] | undefined> | Plugin[] | undefined;
30
30
  configure?(config: AdapterConfig): void;
31
31
  pluginOptions?(options: Options): Promise<Options> | Options | undefined;
32
32
  viteConfig?(config: UserConfig): Promise<UserConfig> | UserConfig | undefined;
@@ -47,6 +47,7 @@ export interface Adapter {
47
47
  sourceEntries: string[];
48
48
  }): Promise<void> | void;
49
49
  typeInfo?(writer: (data: string) => void): Promise<string> | string;
50
+ runtimeInclude?(): Promise<string | undefined> | string | undefined;
50
51
  routesGenerated?(event: {
51
52
  routes: BuiltRoutes;
52
53
  virtualFiles: Map<string, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "The Marko application framework.",
5
5
  "keywords": [
6
6
  "marko"