@marko/run 0.1.1 → 0.1.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.
@@ -3,7 +3,7 @@ import path2 from "path";
3
3
  import crypto from "crypto";
4
4
  import fs2 from "fs";
5
5
  import glob from "glob";
6
- import { mergeConfig, normalizePath } from "vite";
6
+ import { mergeConfig, resolvePackageData } from "vite";
7
7
  import markoVitePlugin, { FileStore } from "@marko/vite";
8
8
 
9
9
  // src/vite/constants.ts
@@ -626,7 +626,7 @@ function renderRouter(routes, options = {
626
626
  writer.writeLines(`// @marko/run/router`);
627
627
  const imports = writer.branch("imports");
628
628
  imports.writeLines(
629
- `import { NotHandled, NotMatched, createInput } from 'virtual:marko-run/internal';`
629
+ `import { NotHandled, NotMatched, createContext } from 'virtual:marko-run/internal';`
630
630
  );
631
631
  for (const route of routes.list) {
632
632
  const verbs = getVerbs(route);
@@ -643,7 +643,17 @@ function renderRouter(routes, options = {
643
643
  `import page${key} from '${virtualFilePrefix}/${markoRunFilePrefix}special__${key}.marko${serverEntryQuery}';`
644
644
  );
645
645
  }
646
- writer.writeLines(``).writeBlockStart(`export function match(method, pathname) {`).writeLines(
646
+ writer.writeLines(
647
+ `
648
+ const page404ResponseInit = {
649
+ status: 404,
650
+ headers: { "content-type": "text/html;charset=UTF-8" },
651
+ };
652
+ const page500ResponseInit = {
653
+ status: 404,
654
+ headers: { "content-type": "text/html;charset=UTF-8" },
655
+ };`
656
+ ).writeBlockStart(`export function match(method, pathname) {`).writeLines(
647
657
  `if (!pathname) {
648
658
  pathname = '/';
649
659
  } else if (pathname.charAt(0) !== '/') {
@@ -661,17 +671,10 @@ function renderRouter(routes, options = {
661
671
  }
662
672
  writer.writeBlockEnd("}").writeLines("return null;").writeBlockEnd("}");
663
673
  writer.write(`
664
- export async function invoke(route, request, platform, url = new URL(request.url)) {
665
- const context = {
666
- url,
667
- request,
668
- platform
669
- };
670
- const buildInput = createInput(context);
674
+ export async function invoke(route, request, platform, url) {
675
+ const [context, buildInput] = createContext(route, request, platform, url);
671
676
  try {
672
677
  if (route) {
673
- context.params = route.params;
674
- context.meta = route.meta;
675
678
  try {
676
679
  const response = await route.handler(context, buildInput);
677
680
  if (response) return response;
@@ -686,14 +689,9 @@ export async function invoke(route, request, platform, url = new URL(request.url
686
689
  if (routes.special[RoutableFileTypes.NotFound]) {
687
690
  writer.write(
688
691
  ` } else {
689
- context.params = {};
690
- context.meta = {};
691
692
  }
692
693
  if (context.request.headers.get('Accept')?.includes('text/html')) {
693
- return new Response(page404.stream(buildInput()), {
694
- status: 404,
695
- headers: { "content-type": "text/html;charset=UTF-8" },
696
- });
694
+ return new Response(page404.stream(buildInput()), page404ResponseInit);
697
695
  }
698
696
  `
699
697
  );
@@ -705,13 +703,8 @@ export async function invoke(route, request, platform, url = new URL(request.url
705
703
  if (routes.special[RoutableFileTypes.Error]) {
706
704
  writer.writeBlockStart(
707
705
  `if (context.request.headers.get('Accept')?.includes('text/html')) {`
708
- ).writeBlock(
709
- `return new Response(page500.stream(buildInput({ error })), {`,
710
- [
711
- `status: 500,`,
712
- `headers: { "content-type": "text/html;charset=UTF-8" },`
713
- ],
714
- `});`
706
+ ).writeLines(
707
+ `return new Response(page500.stream(buildInput({ error })), page500ResponseInit);`
715
708
  ).writeBlockEnd("}");
716
709
  }
717
710
  writer.writeLines(`throw error;`).writeBlockEnd("}").writeBlockEnd("}").write(`
@@ -947,8 +940,8 @@ function stripTsExtension(path3) {
947
940
  }
948
941
  return path3;
949
942
  }
950
- function renderRouteTypeInfo(routes, pathPrefix = ".", adapterTypes = "") {
951
- var _a, _b;
943
+ async function renderRouteTypeInfo(routes, pathPrefix = ".", adapter) {
944
+ var _a, _b, _c, _d;
952
945
  const writer = createStringWriter();
953
946
  writer.writeLines(
954
947
  `/*
@@ -956,28 +949,25 @@ function renderRouteTypeInfo(routes, pathPrefix = ".", adapterTypes = "") {
956
949
  Do NOT manually edit this file or your changes will be lost.
957
950
  */
958
951
  `,
959
- `import type { HandlerLike, Route as AnyRoute, Context as AnyContext, ValidatePath, ValidateHref } from "@marko/run";`,
960
- adapterTypes,
961
- `
962
-
963
- declare global {
964
- namespace MarkoRun {`
952
+ `import type { HandlerLike, Route as AnyRoute, Context as AnyContext, ParamsObject, ValidatePath, ValidateHref } from "@marko/run";`
965
953
  );
966
- const pathsWriter = writer.branch("paths");
967
- writer.write(`
968
- type GetablePath<T extends string> = ValidatePath<GetPaths, T>;
969
- type GetableHref<T extends string> = ValidateHref<GetPaths, T>;
970
- type PostablePath<T extends string> = ValidatePath<PostPaths, T>;
971
- type PostableHref<T extends string> = ValidateHref<PostPaths, T>;
954
+ let platformType = "unknown";
955
+ if (adapter && adapter.typeInfo) {
956
+ platformType = await adapter.typeInfo((data) => writer.write(data));
957
+ writer.writeLines("");
972
958
  }
973
- }
959
+ writer.writeLines(`
960
+ interface NoParams extends ParamsObject {}
961
+ interface NoMeta {}
974
962
  `);
963
+ const pathsWriter = writer.branch("paths");
975
964
  const routesWriter = writer.branch("types");
976
965
  const serverWriter = writer.branch("server");
977
966
  const middlewareRouteTypes = /* @__PURE__ */ new Map();
978
967
  const layoutRouteTypes = /* @__PURE__ */ new Map();
979
968
  const getPaths = /* @__PURE__ */ new Set();
980
969
  const postPaths = /* @__PURE__ */ new Set();
970
+ writeModuleDeclaration(serverWriter, void 0, void 0, platformType);
981
971
  for (const route of routes.list) {
982
972
  const { meta, handler, params, middleware, page, layouts } = route;
983
973
  const routeType = `Route${route.index}`;
@@ -985,8 +975,8 @@ declare global {
985
975
  /\/\$(\$?)([^\/]*)/,
986
976
  (_, catchAll, name) => catchAll ? `/:${name || "rest"}*` : `/:${name}`
987
977
  )}\``;
988
- const paramsType = params ? renderParamsInfoType(params) : "{}";
989
- let metaType = "undefined";
978
+ const paramsType = (params == null ? void 0 : params.length) ? renderParamsInfoType(params) : "NoParams";
979
+ let metaType = "NoMeta";
990
980
  if (page || handler) {
991
981
  const isGet = page || ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes("get"));
992
982
  const isPost = (_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes("post");
@@ -1006,31 +996,31 @@ declare global {
1006
996
  }
1007
997
  }
1008
998
  if (meta) {
1009
- metaType = `typeof import('${pathPrefix}/${stripTsExtension(
1010
- meta.relativePath
1011
- )}')`;
999
+ const path3 = stripTsExtension(`${pathPrefix}/${meta.relativePath}`);
1000
+ metaType = `typeof import('${path3}')`;
1012
1001
  if (/\.(ts|js|mjs)$/.test(meta.relativePath)) {
1013
1002
  metaType += `['default']`;
1014
1003
  }
1015
1004
  }
1016
1005
  if (handler) {
1017
- writeRouteTypeModule(
1006
+ writeModuleDeclaration(
1018
1007
  serverWriter,
1019
- pathPrefix,
1020
- handler.relativePath,
1021
- routeType
1008
+ `${pathPrefix}/${handler.relativePath}`,
1009
+ routeType,
1010
+ platformType
1022
1011
  );
1023
1012
  }
1024
1013
  if (page) {
1025
- writer.writeLines(`
1026
- declare module '${pathPrefix}/${page.relativePath}' {
1027
- export interface Input {}
1028
-
1029
- namespace MarkoRun {
1030
- type Route = ${routeType};
1031
- type Context = AnyContext<AnyContext['platform'], Route>;
1032
- }
1033
- }`);
1014
+ writeModuleDeclaration(
1015
+ writer,
1016
+ `${pathPrefix}/${page.relativePath}`,
1017
+ routeType,
1018
+ platformType,
1019
+ `
1020
+ export interface Input {
1021
+ renderBody: Marko.Body;
1022
+ }`
1023
+ );
1034
1024
  }
1035
1025
  if (middleware) {
1036
1026
  let i = 0;
@@ -1060,74 +1050,106 @@ declare module '${pathPrefix}/${page.relativePath}' {
1060
1050
  }
1061
1051
  }
1062
1052
  routesWriter.writeLines(
1063
- `interface ${routeType} extends AnyRoute<${paramsType}, ${metaType}, ${pathType}> {}`
1053
+ `type ${routeType} = AnyRoute<${paramsType}, ${metaType}, ${pathType}>;`
1064
1054
  );
1065
1055
  }
1066
- pathsWriter.write(" type GetPaths =");
1067
- for (const path3 of getPaths) {
1068
- pathsWriter.write(`
1069
- | '${path3}'`);
1056
+ pathsWriter.write(`type Get =`);
1057
+ if (getPaths.size) {
1058
+ for (const path3 of getPaths) {
1059
+ pathsWriter.write(`
1060
+ | '${path3}'`);
1061
+ }
1062
+ } else {
1063
+ pathsWriter.write(" never");
1070
1064
  }
1071
1065
  pathsWriter.writeLines(";", "");
1072
- pathsWriter.write(" type PostPaths =");
1073
- for (const path3 of postPaths) {
1074
- pathsWriter.write(`
1075
- | '${path3}'`);
1066
+ pathsWriter.write("type Post =");
1067
+ if (postPaths.size) {
1068
+ for (const path3 of postPaths) {
1069
+ pathsWriter.write(`
1070
+ | '${path3}'`);
1071
+ }
1072
+ } else {
1073
+ pathsWriter.write(" never");
1076
1074
  }
1077
- pathsWriter.writeLines(";");
1075
+ pathsWriter.writeLines(";", "");
1078
1076
  pathsWriter.join();
1079
1077
  for (const [file, { routeTypes }] of middlewareRouteTypes) {
1080
- writeRouteTypeModule(
1078
+ writeModuleDeclaration(
1081
1079
  serverWriter,
1082
- pathPrefix,
1083
- file.relativePath,
1084
- routeTypes.join(" | ")
1080
+ `${pathPrefix}/${file.relativePath}`,
1081
+ routeTypes.join(" | "),
1082
+ platformType
1085
1083
  );
1086
1084
  }
1087
1085
  for (const [file, { routeTypes }] of layoutRouteTypes) {
1088
- writer.writeLines(`
1089
- declare module '${pathPrefix}/${file.relativePath}' {
1086
+ writeModuleDeclaration(
1087
+ writer,
1088
+ `${pathPrefix}/${file.relativePath}`,
1089
+ routeTypes.join(" | "),
1090
+ platformType,
1091
+ `
1090
1092
  export interface Input {
1091
1093
  renderBody: Marko.Body;
1094
+ }`
1095
+ );
1092
1096
  }
1093
-
1094
- namespace MarkoRun {
1095
- type Route = ${routeTypes.join(" | ")};
1096
- type Context = AnyContext<AnyContext['platform'], Route>;
1097
- }
1098
- }`);
1097
+ if ((_c = routes.special["404"]) == null ? void 0 : _c.page) {
1098
+ writeModuleDeclaration(
1099
+ writer,
1100
+ `${pathPrefix}/${routes.special["404"].page.relativePath}`,
1101
+ void 0,
1102
+ platformType,
1103
+ `
1104
+ export interface Input {}`
1105
+ );
1099
1106
  }
1100
- for (const route of [routes.special["404"], routes.special["500"]]) {
1101
- if (route && route.page) {
1102
- writer.write(`
1103
- declare module '${pathPrefix}/${route.page.relativePath}' {
1104
- export interface Input {`);
1105
- if (route.page.type === RoutableFileTypes.Error) {
1106
- writer.write(`
1107
+ if ((_d = routes.special["500"]) == null ? void 0 : _d.page) {
1108
+ writeModuleDeclaration(
1109
+ writer,
1110
+ `${pathPrefix}/${routes.special["500"].page.relativePath}`,
1111
+ void 0,
1112
+ platformType,
1113
+ `
1114
+ export interface Input {
1107
1115
  error: unknown;
1108
- `);
1109
- }
1110
- writer.writeLines(`}
1111
-
1112
- namespace MarkoRun {
1113
- type Route = AnyRoute;
1114
- type Context = AnyContext<AnyContext['platform'], Route>;
1115
- }
1116
- }`);
1117
- }
1116
+ }`
1117
+ );
1118
1118
  }
1119
1119
  serverWriter.join();
1120
1120
  return writer.end();
1121
1121
  }
1122
- function writeRouteTypeModule(writer, pathPrefix, path3, routeType) {
1123
- writer.writeLines(`
1124
- declare module '${pathPrefix}/${stripTsExtension(path3)}' {
1122
+ function writeModuleDeclaration(writer, path3 = "global", routeType = "AnyRoute", platformType = "unknown", moduleTypes) {
1123
+ writer.writeLines("");
1124
+ if (path3 === "global") {
1125
+ writer.write("declare global {");
1126
+ } else {
1127
+ writer.write(`declare module '${stripTsExtension(path3)}' {`);
1128
+ }
1129
+ if (moduleTypes) {
1130
+ writer.writeLines(moduleTypes);
1131
+ }
1132
+ const isMarko = path3.endsWith(".marko");
1133
+ writer.write(`
1125
1134
  namespace MarkoRun {
1135
+ type GetPaths = Get;
1136
+ type PostPaths = Post;
1137
+ type GetablePath<T extends string> = ValidatePath<Get, T>;
1138
+ type GetableHref<T extends string> = ValidateHref<Get, T>;
1139
+ type PostablePath<T extends string> = ValidatePath<Post, T>;
1140
+ type PostableHref<T extends string> = ValidateHref<Post, T>;
1141
+ type Platform = ${platformType};`);
1142
+ if (path3 !== "global") {
1143
+ writer.write(`
1126
1144
  type Route = ${routeType};
1127
- type Context = AnyContext<AnyContext['platform'], Route>;
1145
+ type Context = AnyContext<Platform, Route>${isMarko ? " & Marko.Global" : ""};
1128
1146
  type Handler<_Params = Route['params'], _Meta = Route['meta']> = HandlerLike<Route>;
1129
1147
  function route(handler: Handler): typeof handler;
1130
1148
  function route<_Params = Route['params'], _Meta = Route['meta']>(handler: Handler): typeof handler;
1149
+ const NotHandled: unique symbol;
1150
+ const NotMatched: unique symbol;`);
1151
+ }
1152
+ writer.writeLines(`
1131
1153
  }
1132
1154
  }`);
1133
1155
  }
@@ -1319,11 +1341,15 @@ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterCon
1319
1341
  import { fileURLToPath } from "url";
1320
1342
  var __dirname = fileURLToPath(new URL(".", import.meta.url));
1321
1343
  var markoExt = ".marko";
1344
+ var POSIX_SEP = "/";
1345
+ var WINDOWS_SEP = "\\";
1346
+ var normalizePath = path2.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
1322
1347
  function isMarkoFile(id) {
1323
1348
  return id.endsWith(markoExt);
1324
1349
  }
1325
- function markoServe(opts = {}) {
1326
- const { routesDir = "src/routes", adapter, ...markoOptions } = opts;
1350
+ function markoRun(opts = {}) {
1351
+ let { routesDir = "src/routes", adapter, ...markoOptions } = opts;
1352
+ let compiler;
1327
1353
  let store;
1328
1354
  let root;
1329
1355
  let resolvedRoutesDir;
@@ -1333,6 +1359,7 @@ function markoServe(opts = {}) {
1333
1359
  let tsConfigExists;
1334
1360
  let ssrEntryFiles;
1335
1361
  let devEntryFile;
1362
+ let devEntryFilePosix;
1336
1363
  let devServer;
1337
1364
  let routes;
1338
1365
  let routeData;
@@ -1353,8 +1380,11 @@ function markoServe(opts = {}) {
1353
1380
  "{.tsconfig*,tsconfig*.json}"
1354
1381
  ))) {
1355
1382
  const filepath = path2.join(typesDir, "routes.d.ts");
1356
- const adapterTypeInfo = (adapter == null ? void 0 : adapter.writeTypeInfo) && await (adapter == null ? void 0 : adapter.writeTypeInfo());
1357
- const data = renderRouteTypeInfo(routes, path2.relative(typesDir, routesDir), adapterTypeInfo);
1383
+ const data = await renderRouteTypeInfo(
1384
+ routes,
1385
+ path2.relative(typesDir, routesDir),
1386
+ adapter
1387
+ );
1358
1388
  if (data !== typesFile || !fs2.existsSync(filepath)) {
1359
1389
  await ensureDir(typesDir);
1360
1390
  await fs2.promises.writeFile(filepath, typesFile = data);
@@ -1367,24 +1397,30 @@ function markoServe(opts = {}) {
1367
1397
  route.handler.verbs = await extractVerbs(route.handler.filePath);
1368
1398
  if (!route.handler.verbs.length) {
1369
1399
  console.warn(
1370
- `Did not find any valid exports in middleware entry file:'${route.handler.filePath}' - expected to find any of 'get', 'post', 'put' or 'del'`
1400
+ `Did not find any valid exports in middleware entry file:'${route.handler.filePath}' - expected to find any of 'GET', 'POST', 'PUT' or 'DELETE'`
1371
1401
  );
1372
1402
  }
1373
1403
  }
1374
1404
  if (route.page) {
1375
1405
  virtualFiles.set(
1376
- path2.join(root, `${markoRunFilePrefix}route__${route.key}.marko`),
1406
+ path2.posix.join(
1407
+ root,
1408
+ `${markoRunFilePrefix}route__${route.key}.marko`
1409
+ ),
1377
1410
  render ? renderRouteTemplate(route) : ""
1378
1411
  );
1379
1412
  }
1380
1413
  virtualFiles.set(
1381
- path2.join(root, `${markoRunFilePrefix}route__${route.key}.js`),
1414
+ path2.posix.join(root, `${markoRunFilePrefix}route__${route.key}.js`),
1382
1415
  render ? renderRouteEntry(route) : ""
1383
1416
  );
1384
1417
  }
1385
1418
  for (const route of Object.values(routes.special)) {
1386
1419
  virtualFiles.set(
1387
- path2.join(root, `${markoRunFilePrefix}special__${route.key}.marko`),
1420
+ path2.posix.join(
1421
+ root,
1422
+ `${markoRunFilePrefix}special__${route.key}.marko`
1423
+ ),
1388
1424
  render ? renderRouteTemplate(route) : ""
1389
1425
  );
1390
1426
  }
@@ -1395,7 +1431,7 @@ function markoServe(opts = {}) {
1395
1431
  }) : ""
1396
1432
  );
1397
1433
  virtualFiles.set(
1398
- path2.join(root, `${markoRunFilePrefix}middleware.js`),
1434
+ path2.posix.join(root, `${markoRunFilePrefix}middleware.js`),
1399
1435
  render ? renderMiddleware(routes.middleware) : ""
1400
1436
  );
1401
1437
  }
@@ -1424,25 +1460,36 @@ function markoServe(opts = {}) {
1424
1460
  if (externalPluginOptions) {
1425
1461
  opts = mergeConfig(opts, externalPluginOptions);
1426
1462
  }
1463
+ root = normalizePath(config2.root || process.cwd());
1464
+ isBuild = env.command === "build";
1465
+ isSSRBuild = isBuild && Boolean((_a = config2.build) == null ? void 0 : _a.ssr);
1466
+ adapter = await resolveAdapter(root, opts, config2.logLevel !== "silent" && !isBuild || isSSRBuild);
1427
1467
  if (adapter) {
1428
1468
  const externalAdapterConfig = getExternalAdapterOptions(config2);
1429
1469
  if (externalAdapterConfig && adapter.configure) {
1430
1470
  adapter.configure(externalAdapterConfig);
1431
1471
  }
1432
- const adapterOptions = await ((_a = adapter.pluginOptions) == null ? void 0 : _a.call(adapter, opts));
1472
+ const adapterOptions = await ((_b = adapter.pluginOptions) == null ? void 0 : _b.call(adapter, opts));
1433
1473
  if (adapterOptions) {
1434
1474
  opts = mergeConfig(opts, adapterOptions);
1435
1475
  }
1436
1476
  }
1437
- root = normalizePath(config2.root || process.cwd());
1477
+ compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
1478
+ compiler.taglib.register("@marko/run", {
1479
+ "<*>": {
1480
+ template: path2.resolve(
1481
+ __dirname,
1482
+ "../components/src-attributes-transformer.cjs"
1483
+ )
1484
+ }
1485
+ });
1438
1486
  store = opts.store || new FileStore(
1439
1487
  `marko-serve-vite-${crypto.createHash("SHA1").update(root).digest("hex")}`
1440
1488
  );
1441
- isBuild = env.command === "build";
1442
- isSSRBuild = isBuild && Boolean((_b = config2.build) == null ? void 0 : _b.ssr);
1443
1489
  resolvedRoutesDir = path2.resolve(root, routesDir);
1444
1490
  typesDir = path2.join(root, ".marko-run");
1445
1491
  devEntryFile = path2.join(root, "index.html");
1492
+ devEntryFilePosix = normalizePath(devEntryFile);
1446
1493
  let pluginConfig = {
1447
1494
  logLevel: isBuild ? "warn" : void 0,
1448
1495
  define: isBuild ? {
@@ -1535,9 +1582,10 @@ function markoServe(opts = {}) {
1535
1582
  root,
1536
1583
  importee.slice(virtualFilePrefix.length + 1)
1537
1584
  );
1538
- } else if (!isBuild && importer === devEntryFile && importee.startsWith(`/${markoRunFilePrefix}`)) {
1585
+ } else if (!isBuild && importer && (importer === devEntryFile || normalizePath(importer) === devEntryFilePosix) && importee.startsWith(`/${markoRunFilePrefix}`)) {
1539
1586
  importee = path2.resolve(root, "." + importee);
1540
1587
  }
1588
+ importee = normalizePath(importee);
1541
1589
  if (isStale) {
1542
1590
  await buildVirtualFiles();
1543
1591
  }
@@ -1679,6 +1727,31 @@ async function ensureDir(dir) {
1679
1727
  await fs2.promises.mkdir(dir, { recursive: true });
1680
1728
  }
1681
1729
  }
1730
+ async function resolveAdapter(root, options, log) {
1731
+ const { adapter } = options;
1732
+ if (adapter !== void 0) {
1733
+ return adapter;
1734
+ }
1735
+ const pkg = resolvePackageData(".", root);
1736
+ if (pkg) {
1737
+ const dependecies = { ...pkg.data.dependecies, ...pkg.data.devDependencies };
1738
+ for (const name of Object.keys(dependecies)) {
1739
+ if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
1740
+ try {
1741
+ const module2 = await import(name);
1742
+ log && console.log(`Using adapter ${name} listed in your package.json dependecies`);
1743
+ return module2.default();
1744
+ } catch (err) {
1745
+ log && console.warn(`Attempt to use package '${name}' failed`, err);
1746
+ }
1747
+ }
1748
+ }
1749
+ }
1750
+ const defaultAdapter = "@marko/run/adapter";
1751
+ const module = await import(defaultAdapter);
1752
+ log && console.log("Using default adapter");
1753
+ return module.default();
1754
+ }
1682
1755
 
1683
1756
  // src/vite/utils/server.ts
1684
1757
  import net from "net";
@@ -1750,7 +1823,7 @@ function sleep(ms) {
1750
1823
  return new Promise((resolve) => setTimeout(resolve, ms));
1751
1824
  }
1752
1825
  export {
1753
- markoServe as default,
1826
+ markoRun as default,
1754
1827
  getAvailablePort,
1755
1828
  isPortInUse,
1756
1829
  loadEnv,
@@ -1,3 +1,4 @@
1
1
  import type { Plugin } from "vite";
2
- import type { Options } from "./types";
3
- export default function markoServe(opts?: Options): Plugin[];
2
+ import type { Options, Adapter } from "./types";
3
+ export default function markoRun(opts?: Options): Plugin[];
4
+ export declare function resolveAdapter(root: string, options: Options, log?: boolean): Promise<Adapter | null>;
@@ -8,7 +8,7 @@ export interface WalkOptions {
8
8
  onEnter?: (dir: WalkEntry) => (() => void) | false | void;
9
9
  maxDepth?: number;
10
10
  }
11
- export declare type Walker = (options: WalkOptions) => Promise<void>;
11
+ export type Walker = (options: WalkOptions) => Promise<void>;
12
12
  export declare function createFSWalker(dir: string): Walker;
13
- export declare type TestFileTree = [string, (string | TestFileTree)[]];
13
+ export type TestFileTree = [string, (string | TestFileTree)[]];
14
14
  export declare function createTestWalker(dir: TestFileTree): Walker;
@@ -2,7 +2,7 @@ import type { RoutableFileType, HttpVerb, RoutableFileTypes } from "./constants"
2
2
  import type { Options as MarkoViteOptions } from "@marko/vite";
3
3
  import type { ResolvedConfig, UserConfig } from "vite";
4
4
  export type { RoutableFileType, HttpVerb };
5
- export declare type StartServer = (port?: number) => Promise<void>;
5
+ export type StartServer = (port?: number) => Promise<void>;
6
6
  export interface AdapterConfig {
7
7
  [name: PropertyKey]: any;
8
8
  }
@@ -15,7 +15,7 @@ export interface Adapter {
15
15
  startDev?(configFile: string, port: number, envFile?: string): Promise<void> | void;
16
16
  startPreview?(dir: string, entry?: string, port?: number, envFile?: string): Promise<void> | void;
17
17
  buildEnd?(config: ResolvedConfig, routes: Route[], builtEntries: string[], sourceEntries: string[]): Promise<void> | void;
18
- writeTypeInfo?(): Promise<string> | string;
18
+ typeInfo?(writer: (data: string) => void): Promise<string> | string;
19
19
  }
20
20
  export interface RouterOptions {
21
21
  trailingSlashes: 'Ignore' | 'RedirectWithout' | 'RedirectWith' | 'RewriteWithout' | 'RewriteWith';
@@ -23,9 +23,9 @@ export interface RouterOptions {
23
23
  export interface MarkoServeOptions extends Partial<RouterOptions> {
24
24
  routesDir?: string;
25
25
  emitRoutes?(routes: Route[]): void | Promise<void>;
26
- adapter?: Adapter;
26
+ adapter?: Adapter | null;
27
27
  }
28
- export declare type Options = MarkoServeOptions & MarkoViteOptions;
28
+ export type Options = MarkoServeOptions & MarkoViteOptions;
29
29
  export interface Route {
30
30
  key: string;
31
31
  index: number;
@@ -1,3 +1,3 @@
1
1
  import type { HttpVerb, Route } from "../types";
2
- export declare function getVerbs(route: Route): ("get" | "delete" | "post" | "put")[];
2
+ export declare function getVerbs(route: Route): ("get" | "post" | "put" | "delete")[];
3
3
  export declare function hasVerb(route: Route, verb: HttpVerb): boolean | import("../types").RoutableFile | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/run",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "The Marko application framework.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/marko-js/run/tree/main/packages/run",
@@ -79,12 +79,10 @@
79
79
  "dist"
80
80
  ],
81
81
  "peerDependencies": {
82
- "@marko/vite": "^2.3.12",
83
82
  "marko": "^5"
84
83
  },
85
84
  "devDependencies": {
86
85
  "@babel/types": "^7.19.0",
87
- "@marko/vite": "^2.3.12",
88
86
  "@types/glob": "^8.0.1",
89
87
  "@types/human-format": "^1.0.0",
90
88
  "@types/mocha": "^9.1.1",
@@ -100,6 +98,7 @@
100
98
  "typescript": "^4.7.4"
101
99
  },
102
100
  "dependencies": {
101
+ "@marko/vite": "^2.3.13",
103
102
  "cli-table3": "^0.6.3",
104
103
  "compression": "^1.7.4",
105
104
  "dotenv": "^16.0.3",
@@ -109,7 +108,9 @@
109
108
  "kleur": "^4.1.5",
110
109
  "sade": "^1.8.1",
111
110
  "serve-static": "^1.15.0",
111
+ "strip-ansi": "^7.0.1",
112
112
  "undici": "^5.20.0",
113
- "vite": "^4.1.4"
113
+ "vite": "^4.1.4",
114
+ "warp10": "^2.1.0"
114
115
  }
115
116
  }