@marko/run 0.7.2 → 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,6 +15,29 @@ process
14
15
  .send("ready");
15
16
 
16
17
  async function start(entry, config) {
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;
39
+ }
40
+
17
41
  globalThis.__marko_run_vite_config__ = config;
18
42
 
19
43
  let changed = false;
@@ -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";
@@ -671,14 +674,14 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
671
674
  if (useSwitch) {
672
675
  writer.writeBlockStart(`switch (${value}) {`);
673
676
  }
674
- for (const { key, path: path8, route: route2 } of terminal) {
677
+ for (const { key, path: path10, route: route2 } of terminal) {
675
678
  const decodedKey = decodeURIComponent(key);
676
679
  if (useSwitch) {
677
680
  writer.write(`case '${decodedKey}': `, true);
678
681
  } else {
679
682
  writer.write(`if (${value} === '${decodedKey}') `, true);
680
683
  }
681
- writer.write(`return ${renderMatch(verb, route2, path8)};
684
+ writer.write(`return ${renderMatch(verb, route2, path10)};
682
685
  `);
683
686
  }
684
687
  if (useSwitch) {
@@ -780,11 +783,11 @@ function renderParams(params, pathIndex) {
780
783
  }
781
784
  return result ? result + " }" : "{}";
782
785
  }
783
- function renderMatch(verb, route, path8, pathIndex) {
786
+ function renderMatch(verb, route, path10, pathIndex) {
784
787
  const handler = `${verb}${route.index}`;
785
- const params = path8.params ? renderParams(path8.params, pathIndex) : "{}";
788
+ const params = path10.params ? renderParams(path10.params, pathIndex) : "{}";
786
789
  const meta = route.meta ? `meta${route.index}` : "{}";
787
- return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path8.path}' }`;
790
+ return `{ handler: ${handler}, params: ${params}, meta: ${meta}, path: '${path10.path}' }`;
788
791
  }
789
792
  function renderMiddleware(middleware, rootDir) {
790
793
  const writer = createStringWriter();
@@ -806,18 +809,18 @@ function renderMiddleware(middleware, rootDir) {
806
809
  imports.join();
807
810
  return writer.end();
808
811
  }
809
- function stripTsExtension(path8) {
810
- const index = path8.lastIndexOf(".");
812
+ function stripTsExtension(path10) {
813
+ const index = path10.lastIndexOf(".");
811
814
  if (index !== -1) {
812
- const ext = path8.slice(index + 1);
815
+ const ext = path10.slice(index + 1);
813
816
  if (ext.toLowerCase() === "ts") {
814
- return path8.slice(0, index);
817
+ return path10.slice(0, index);
815
818
  }
816
819
  }
817
- return path8;
820
+ return path10;
818
821
  }
819
- function decodePath(path8) {
820
- return path8;
822
+ function decodePath(path10) {
823
+ return path10;
821
824
  }
822
825
  async function renderRouteTypeInfo(routes, outDir, adapter) {
823
826
  var _a, _b, _c, _d;
@@ -975,11 +978,11 @@ function createRouteTrie(routes) {
975
978
  const root = {
976
979
  key: ""
977
980
  };
978
- function insert(path8, route) {
981
+ function insert(path10, route) {
979
982
  let node = root;
980
- for (const segment of path8.segments) {
983
+ for (const segment of path10.segments) {
981
984
  if (segment === "$$") {
982
- node.catchAll ?? (node.catchAll = { route, path: path8 });
985
+ node.catchAll ?? (node.catchAll = { route, path: path10 });
983
986
  return;
984
987
  } else if (segment === "$") {
985
988
  node = node.dynamic ?? (node.dynamic = {
@@ -997,7 +1000,7 @@ function createRouteTrie(routes) {
997
1000
  node = next;
998
1001
  }
999
1002
  }
1000
- node.path ?? (node.path = path8);
1003
+ node.path ?? (node.path = path10);
1001
1004
  node.route ?? (node.route = route);
1002
1005
  }
1003
1006
  for (const route of routes) {
@@ -1047,9 +1050,9 @@ function parseFlatRoute(pattern) {
1047
1050
  } else if (charCode === 44 /* Alternate */) {
1048
1051
  if (!current) {
1049
1052
  segmentEnd(
1050
- basePaths.map((path8) => ({
1051
- ...path8,
1052
- segments: path8.segments.slice()
1053
+ basePaths.map((path10) => ({
1054
+ ...path10,
1055
+ segments: path10.segments.slice()
1053
1056
  })),
1054
1057
  escaped,
1055
1058
  "_",
@@ -1086,9 +1089,9 @@ function parseFlatRoute(pattern) {
1086
1089
  } else if (charCode === 36 /* Dynamic */) {
1087
1090
  type = pattern.charCodeAt(i + 1) === 36 ? "$$" : "$";
1088
1091
  }
1089
- current ?? (current = basePaths.map((path8) => ({
1090
- ...path8,
1091
- segments: path8.segments.slice()
1092
+ current ?? (current = basePaths.map((path10) => ({
1093
+ ...path10,
1094
+ segments: path10.segments.slice()
1092
1095
  })));
1093
1096
  i = len;
1094
1097
  for (const char of delimiters) {
@@ -1113,9 +1116,9 @@ function parseFlatRoute(pattern) {
1113
1116
  }
1114
1117
  if (!current) {
1115
1118
  segmentEnd(
1116
- basePaths.map((path8) => ({
1117
- ...path8,
1118
- segments: path8.segments.slice()
1119
+ basePaths.map((path10) => ({
1120
+ ...path10,
1121
+ segments: path10.segments.slice()
1119
1122
  })),
1120
1123
  escaped,
1121
1124
  void 0,
@@ -1144,9 +1147,9 @@ function parseFlatRoute(pattern) {
1144
1147
  segment.param = normalizeParam(raw.slice(type.length));
1145
1148
  }
1146
1149
  }
1147
- for (const path8 of paths) {
1150
+ for (const path10 of paths) {
1148
1151
  if (segment) {
1149
- if (path8.isCatchall) {
1152
+ if (path10.isCatchall) {
1150
1153
  throw new Error(
1151
1154
  `Invalid route pattern: nested segments are not allowed after a catch-all parameter. Found '.' following '${pattern.slice(
1152
1155
  0,
@@ -1154,22 +1157,22 @@ function parseFlatRoute(pattern) {
1154
1157
  )}' in '${pattern}'.`
1155
1158
  );
1156
1159
  }
1157
- path8.segments.push(segment);
1158
- path8.id += path8.id === "/" ? segment.name : `/${segment.name}`;
1160
+ path10.segments.push(segment);
1161
+ path10.id += path10.id === "/" ? segment.name : `/${segment.name}`;
1159
1162
  if (type === "$$") {
1160
- path8.isCatchall = true;
1163
+ path10.isCatchall = true;
1161
1164
  }
1162
1165
  }
1163
1166
  if (map) {
1164
- if (map.has(path8.id)) {
1165
- const existing = map.get(path8.id);
1167
+ if (map.has(path10.id)) {
1168
+ const existing = map.get(path10.id);
1166
1169
  const existingExpansion = existing.segments.map((s) => s.raw).join(".");
1167
- const currentExpansion = path8.segments.map((s) => s.raw).join(".");
1170
+ const currentExpansion = path10.segments.map((s) => s.raw).join(".");
1168
1171
  throw new Error(
1169
- `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}'.`
1170
1173
  );
1171
1174
  }
1172
- map.set(path8.id, path8);
1175
+ map.set(path10.id, path10);
1173
1176
  }
1174
1177
  }
1175
1178
  }
@@ -1244,11 +1247,11 @@ var _VDir = class _VDir {
1244
1247
  });
1245
1248
  return value;
1246
1249
  }
1247
- addDir(path8, segment) {
1250
+ addDir(path10, segment) {
1248
1251
  const map = segment.type === "_" ? __privateGet(this, _pathlessDirs) ?? __privateSet(this, _pathlessDirs, /* @__PURE__ */ new Map()) : __privateGet(this, _dirs) ?? __privateSet(this, _dirs, /* @__PURE__ */ new Map());
1249
1252
  const key = segment.type === "$" ? segment.raw : segment.name;
1250
1253
  if (!map.has(key)) {
1251
- const dir = new _VDir(this, segment, path8);
1254
+ const dir = new _VDir(this, segment, path10);
1252
1255
  map.set(key, dir);
1253
1256
  return dir;
1254
1257
  }
@@ -1294,10 +1297,10 @@ var _VDir = class _VDir {
1294
1297
  const dirs = [];
1295
1298
  const unique = /* @__PURE__ */ new Map();
1296
1299
  for (const root of roots) {
1297
- for (const path8 of paths) {
1300
+ for (const path10 of paths) {
1298
1301
  let dir = root;
1299
- for (const segment of path8.segments) {
1300
- dir = dir.addDir(path8, segment);
1302
+ for (const segment of path10.segments) {
1303
+ dir = dir.addDir(path10, segment);
1301
1304
  }
1302
1305
  const existing = unique.get(dir.path);
1303
1306
  if (existing) {
@@ -1310,7 +1313,7 @@ var _VDir = class _VDir {
1310
1313
  }
1311
1314
  }
1312
1315
  throw new Error(
1313
- `Ambiguous directory structure: ${sourcePath}${path8.source} defines ${dir.path} multiple times.`
1316
+ `Ambiguous directory structure: ${sourcePath}${path10.source} defines ${dir.path} multiple times.`
1314
1317
  );
1315
1318
  } else {
1316
1319
  unique.set(dir.path, dir);
@@ -1765,8 +1768,8 @@ function prettySize([bytes, compBytes]) {
1765
1768
  else str += kleur2.bold(kleur2.red(compSize));
1766
1769
  return str;
1767
1770
  }
1768
- function prettyPath(path8) {
1769
- return path8.replace(
1771
+ function prettyPath(path10) {
1772
+ return path10.replace(
1770
1773
  /\/(\$\$?)(`?)([^/`]+)\2/g,
1771
1774
  (_, type, tick, key) => "/" + type + tick + kleur2.bold(kleur2.dim(key)) + tick
1772
1775
  );
@@ -2467,8 +2470,60 @@ async function getAvailablePort(port) {
2467
2470
  });
2468
2471
  }
2469
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
+
2470
2525
  // src/cli/commands.ts
2471
- var __dirname2 = path7.dirname(fileURLToPath2(import.meta.url));
2526
+ var __dirname3 = path9.dirname(fileURLToPath3(import.meta.url));
2472
2527
  var defaultConfigFileBases = ["vite.config"];
2473
2528
  var defaultConfigFileExts = [".js", ".cjs", ".mjs", ".ts", ".mts"];
2474
2529
  async function preview(entry, distEntry, cwd, configFile, port, outDir, envFile, args = []) {
@@ -2497,10 +2552,10 @@ async function preview(entry, distEntry, cwd, configFile, port, outDir, envFile,
2497
2552
  if (!entry) {
2498
2553
  entry = await ((_a = adapter.getEntryFile) == null ? void 0 : _a.call(adapter));
2499
2554
  }
2500
- const dir = path7.resolve(cwd, resolvedConfig.build.outDir);
2501
- 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"]);
2502
2557
  if (envFile) {
2503
- envFile = path7.resolve(cwd, envFile);
2558
+ envFile = path9.resolve(cwd, envFile);
2504
2559
  }
2505
2560
  const options = {
2506
2561
  cwd,
@@ -2528,7 +2583,7 @@ async function dev(entry, cwd, configFile, port, envFile, args = []) {
2528
2583
  "serve"
2529
2584
  );
2530
2585
  if (envFile) {
2531
- envFile = path7.resolve(cwd, envFile);
2586
+ envFile = path9.resolve(cwd, envFile);
2532
2587
  }
2533
2588
  const [availablePort, adapter] = await Promise.all([
2534
2589
  getAvailablePort(
@@ -2586,7 +2641,7 @@ async function build(entry, cwd, configFile, outDir, envFile) {
2586
2641
  }
2587
2642
  }
2588
2643
  if (envFile) {
2589
- envFile = path7.resolve(cwd, envFile);
2644
+ envFile = path9.resolve(cwd, envFile);
2590
2645
  }
2591
2646
  let plugins = adapter.plugins && await adapter.plugins({ root, command: "build" });
2592
2647
  if (!isPluginIncluded(resolvedConfig)) {
@@ -2628,8 +2683,8 @@ async function build(entry, cwd, configFile, outDir, envFile) {
2628
2683
  }
2629
2684
  function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
2630
2685
  for (const ext of extensions) {
2631
- const filePath = path7.join(dir, base + ext);
2632
- if (fs5.existsSync(filePath)) {
2686
+ const filePath = path9.join(dir, base + ext);
2687
+ if (fs6.existsSync(filePath)) {
2633
2688
  return filePath;
2634
2689
  }
2635
2690
  }
@@ -2637,8 +2692,8 @@ function findFileWithExt(dir, base, extensions = defaultConfigFileExts) {
2637
2692
  }
2638
2693
  async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
2639
2694
  if (configFile) {
2640
- const configFilePath = path7.join(dir, configFile);
2641
- if (!fs5.existsSync(configFilePath)) {
2695
+ const configFilePath = path9.join(dir, configFile);
2696
+ if (!fs6.existsSync(configFilePath)) {
2642
2697
  throw new Error(`No config file found at '${configFilePath}'`);
2643
2698
  }
2644
2699
  return configFile;
@@ -2649,11 +2704,7 @@ async function getViteConfig(dir, configFile, bases = defaultConfigFileBases) {
2649
2704
  return configFile;
2650
2705
  }
2651
2706
  }
2652
- return path7.join(__dirname2, "default.config.mjs");
2653
- }
2654
- async function resolveAdapter2(config2) {
2655
- const options = getExternalPluginOptions(config2);
2656
- return resolveAdapter(config2.root, options);
2707
+ return path9.join(__dirname3, "default.config.mjs");
2657
2708
  }
2658
2709
 
2659
2710
  // src/cli/index.ts
@@ -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,
@@ -2594,6 +2595,7 @@ function sleep(ms) {
2594
2595
  }
2595
2596
  // Annotate the CommonJS export names for ESM import in node:
2596
2597
  0 && (module.exports = {
2598
+ defaultConfigPlugin,
2597
2599
  getAvailablePort,
2598
2600
  getPackageData,
2599
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";
@@ -2552,6 +2552,7 @@ function sleep(ms) {
2552
2552
  }
2553
2553
  export {
2554
2554
  markoRun as default,
2555
+ defaultConfigPlugin,
2555
2556
  getAvailablePort,
2556
2557
  getPackageData,
2557
2558
  isPortInUse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "The Marko application framework.",
5
5
  "keywords": [
6
6
  "marko"