@marko/run 0.0.1-beta3 → 0.0.1-beta5

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.
@@ -980,6 +980,7 @@ function stripTsExtension(path3) {
980
980
  return path3;
981
981
  }
982
982
  function renderRouteTypeInfo(routes, pathPrefix = ".") {
983
+ var _a, _b;
983
984
  const writer = createStringWriter();
984
985
  writer.writeLines(
985
986
  `/*
@@ -987,13 +988,28 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
987
988
  Do NOT manually edit this file or your changes will be lost.
988
989
  */
989
990
  `,
990
- `import type { HandlerLike, Route } from "@marko/run";
991
- `
991
+ `import type { HandlerLike, Route, RouteContext, ValidatePath, ValidateHref } from "@marko/run";
992
+
993
+ declare global {
994
+ namespace MarkoRun {`
992
995
  );
996
+ const pathsWriter = writer.branch("paths");
997
+ writer.write(`
998
+ type GetablePath<T extends string> = ValidatePath<GetPaths, T>;
999
+ type GetableHref<T extends string> = ValidateHref<GetPaths, T>;
1000
+ type PostablePath<T extends string> = ValidatePath<PostPaths, T>;
1001
+ type PostableHref<T extends string> = ValidateHref<PostPaths, T>;
1002
+ }
1003
+ }
1004
+ `);
993
1005
  const routesWriter = writer.branch("types");
1006
+ const serverWriter = writer.branch("server");
994
1007
  const middlewareRouteTypes = /* @__PURE__ */ new Map();
1008
+ const layoutRouteTypes = /* @__PURE__ */ new Map();
1009
+ const getPaths = /* @__PURE__ */ new Set();
1010
+ const postPaths = /* @__PURE__ */ new Set();
995
1011
  for (const route of routes.list) {
996
- const { meta, handler, params, middleware } = route;
1012
+ const { meta, handler, params, middleware, page, layouts } = route;
997
1013
  const routeType = `Route${route.index}`;
998
1014
  const pathType = `\`${route.path.replace(
999
1015
  /\/\$(\$?)([^\/]*)/,
@@ -1001,6 +1017,24 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
1001
1017
  )}\``;
1002
1018
  const paramsType = params ? renderParamsInfoType(params) : "{}";
1003
1019
  let metaType = "undefined";
1020
+ if (page || handler) {
1021
+ const isGet = page || ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes("get"));
1022
+ const isPost = (_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes("post");
1023
+ if (isGet || isPost) {
1024
+ const path3 = route.path.replace(
1025
+ /\$(\$?)([^/]+)/g,
1026
+ (_, s, name) => s ? `\${...${name}}` : `\${${name}}`
1027
+ );
1028
+ const splatIndex = path3.indexOf("/${...");
1029
+ if (splatIndex >= 0) {
1030
+ const path22 = path3.slice(0, splatIndex) || "/";
1031
+ isGet && getPaths.add(path22);
1032
+ isPost && postPaths.add(path22);
1033
+ }
1034
+ isGet && getPaths.add(path3);
1035
+ isPost && postPaths.add(path3);
1036
+ }
1037
+ }
1004
1038
  if (meta) {
1005
1039
  metaType = `typeof import('${pathPrefix}/${stripTsExtension(
1006
1040
  meta.relativePath
@@ -1010,7 +1044,23 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
1010
1044
  }
1011
1045
  }
1012
1046
  if (handler) {
1013
- writeRouteTypeModule(writer, pathPrefix, handler.relativePath, routeType);
1047
+ writeRouteTypeModule(
1048
+ serverWriter,
1049
+ pathPrefix,
1050
+ handler.relativePath,
1051
+ routeType
1052
+ );
1053
+ }
1054
+ if (page) {
1055
+ writer.writeLines(`
1056
+ declare module '${pathPrefix}/${page.relativePath}' {
1057
+ export interface Input {}
1058
+
1059
+ namespace MarkoRun {
1060
+ type CurrentRoute = ${routeType};
1061
+ type CurrentContext = RouteContext<CurrentRoute>;
1062
+ }
1063
+ }`);
1014
1064
  }
1015
1065
  if (middleware) {
1016
1066
  let i = 0;
@@ -1027,21 +1077,84 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
1027
1077
  i++;
1028
1078
  }
1029
1079
  }
1080
+ if (layouts) {
1081
+ for (const layout of layouts) {
1082
+ const existing = layoutRouteTypes.get(layout);
1083
+ if (!existing) {
1084
+ layoutRouteTypes.set(layout, {
1085
+ routeTypes: [routeType]
1086
+ });
1087
+ } else {
1088
+ existing.routeTypes.push(routeType);
1089
+ }
1090
+ }
1091
+ }
1030
1092
  routesWriter.writeLines(
1031
1093
  `interface ${routeType} extends Route<${paramsType}, ${metaType}, ${pathType}> {}`
1032
1094
  );
1033
1095
  }
1096
+ pathsWriter.write(" type GetPaths =");
1097
+ for (const path3 of getPaths) {
1098
+ pathsWriter.write(`
1099
+ | '${path3}'`);
1100
+ }
1101
+ pathsWriter.writeLines(";", "");
1102
+ pathsWriter.write(" type PostPaths =");
1103
+ for (const path3 of postPaths) {
1104
+ pathsWriter.write(`
1105
+ | '${path3}'`);
1106
+ }
1107
+ pathsWriter.writeLines(";");
1108
+ pathsWriter.join();
1034
1109
  for (const [file, { routeTypes }] of middlewareRouteTypes) {
1035
- const routeType = routeTypes.length > 1 ? routeTypes.join(" | ") : routeTypes[0];
1036
- writeRouteTypeModule(writer, pathPrefix, file.relativePath, routeType);
1110
+ writeRouteTypeModule(
1111
+ serverWriter,
1112
+ pathPrefix,
1113
+ file.relativePath,
1114
+ routeTypes.join(" | ")
1115
+ );
1116
+ }
1117
+ for (const [file, { routeTypes }] of layoutRouteTypes) {
1118
+ writer.writeLines(`
1119
+ declare module '${pathPrefix}/${file.relativePath}' {
1120
+ export interface Input {
1121
+ renderBody: Marko.Body;
1122
+ }
1123
+
1124
+ namespace MarkoRun {
1125
+ type CurrentRoute = ${routeTypes.join(" | ")};
1126
+ type CurrentContext = RouteContext<CurrentRoute>;
1127
+ }
1128
+ }`);
1037
1129
  }
1130
+ for (const route of [routes.special["404"], routes.special["500"]]) {
1131
+ if (route && route.page) {
1132
+ writer.write(`
1133
+ declare module '${pathPrefix}/${route.page.relativePath}' {
1134
+ export interface Input {`);
1135
+ if (route.page.type === RoutableFileTypes.Error) {
1136
+ writer.write(`
1137
+ error: unknown;
1138
+ `);
1139
+ }
1140
+ writer.writeLines(`}
1141
+
1142
+ namespace MarkoRun {
1143
+ type CurrentRoute = Route;
1144
+ type CurrentContext = RouteContext<CurrentRoute>;
1145
+ }
1146
+ }`);
1147
+ }
1148
+ }
1149
+ serverWriter.join();
1038
1150
  return writer.end();
1039
1151
  }
1040
1152
  function writeRouteTypeModule(writer, pathPrefix, path3, routeType) {
1041
1153
  writer.writeLines(`
1042
1154
  declare module '${pathPrefix}/${stripTsExtension(path3)}' {
1043
- namespace Marko {
1155
+ namespace MarkoRun {
1044
1156
  type CurrentRoute = ${routeType};
1157
+ type CurrentContext = RouteContext<CurrentRoute>;
1045
1158
  type Handler<_Params = CurrentRoute['params'], _Meta = CurrentRoute['meta']> = HandlerLike<CurrentRoute>;
1046
1159
  function route(handler: Handler): typeof handler;
1047
1160
  function route<_Params = CurrentRoute['params'], _Meta = CurrentRoute['meta']>(handler: Handler): typeof handler;
@@ -1219,14 +1332,18 @@ function prettyPath(path3) {
1219
1332
  }
1220
1333
 
1221
1334
  // src/vite/utils/config.ts
1222
- var KEY = "__MARKO_SERVE_OPTIONS__";
1223
- function getMarkoRunOptions(viteConfig) {
1224
- return viteConfig[KEY];
1335
+ var PluginConfigKey = "__MARKO_RUN_PLUGIN_CONFIG__";
1336
+ var AdapterConfigKey = "__MARKO_RUN_ADAPTER_CONFIG__";
1337
+ function getConfig(obj, key) {
1338
+ return obj[key];
1225
1339
  }
1226
- function setMarkoRunOptions(viteConfig, options) {
1227
- viteConfig[KEY] = options;
1228
- return viteConfig;
1340
+ function setConfig(obj, key, value) {
1341
+ obj[key] = value;
1342
+ return obj;
1229
1343
  }
1344
+ var getExternalPluginOptions = (viteConfig) => getConfig(viteConfig, PluginConfigKey);
1345
+ var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, PluginConfigKey, value);
1346
+ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
1230
1347
 
1231
1348
  // src/vite/plugin.ts
1232
1349
  var import_url = require("url");
@@ -1267,10 +1384,8 @@ function markoServe(opts = {}) {
1267
1384
  "{.tsconfig*,tsconfig*.json}"
1268
1385
  ))) {
1269
1386
  const filepath = import_path2.default.join(typesDir, "routes.d.ts");
1270
- const data = renderRouteTypeInfo(
1271
- routes,
1272
- import_path2.default.relative(typesDir, routesDir)
1273
- );
1387
+ const adapterTypeInfo = (adapter == null ? void 0 : adapter.writeTypeInfo) && await (adapter == null ? void 0 : adapter.writeTypeInfo());
1388
+ const data = renderRouteTypeInfo(routes, import_path2.default.relative(typesDir, routesDir)) + adapterTypeInfo;
1274
1389
  if (data !== typesFile || !import_fs2.default.existsSync(filepath)) {
1275
1390
  await ensureDir(typesDir);
1276
1391
  await import_fs2.default.promises.writeFile(filepath, typesFile = data);
@@ -1319,13 +1434,14 @@ function markoServe(opts = {}) {
1319
1434
  const startTime = performance.now();
1320
1435
  routes = await buildRoutes(createFSWalker(resolvedRoutesDir), routesDir);
1321
1436
  times.routesBuild = performance.now() - startTime;
1322
- await Promise.all([writeTypesFile(), setVirtualFiles(false)]);
1437
+ await setVirtualFiles(false);
1323
1438
  isStale = false;
1324
1439
  isRendered = false;
1325
1440
  });
1326
1441
  const renderVirtualFiles = single(async () => {
1327
1442
  const startTime = performance.now();
1328
1443
  await setVirtualFiles(true);
1444
+ await writeTypesFile();
1329
1445
  times.routesRender = performance.now() - startTime;
1330
1446
  isRendered = true;
1331
1447
  });
@@ -1335,13 +1451,19 @@ function markoServe(opts = {}) {
1335
1451
  enforce: "pre",
1336
1452
  async config(config2, env) {
1337
1453
  var _a, _b, _c;
1338
- const externalPluginOptions = getMarkoRunOptions(config2);
1454
+ const externalPluginOptions = getExternalPluginOptions(config2);
1339
1455
  if (externalPluginOptions) {
1340
1456
  opts = (0, import_vite.mergeConfig)(opts, externalPluginOptions);
1341
1457
  }
1342
- const adapterOptions = await ((_a = adapter == null ? void 0 : adapter.pluginOptions) == null ? void 0 : _a.call(adapter, opts));
1343
- if (adapterOptions) {
1344
- opts = (0, import_vite.mergeConfig)(opts, adapterOptions);
1458
+ if (adapter) {
1459
+ const externalAdapterConfig = getExternalAdapterOptions(config2);
1460
+ if (externalAdapterConfig && adapter.configure) {
1461
+ adapter.configure(externalAdapterConfig);
1462
+ }
1463
+ const adapterOptions = await ((_a = adapter.pluginOptions) == null ? void 0 : _a.call(adapter, opts));
1464
+ if (adapterOptions) {
1465
+ opts = (0, import_vite.mergeConfig)(opts, adapterOptions);
1466
+ }
1345
1467
  }
1346
1468
  root = (0, import_vite.normalizePath)(config2.root || process.cwd());
1347
1469
  store = opts.store || new import_vite2.FileStore(
@@ -1365,7 +1487,7 @@ function markoServe(opts = {}) {
1365
1487
  if (adapterConfig) {
1366
1488
  pluginConfig = (0, import_vite.mergeConfig)(pluginConfig, adapterConfig);
1367
1489
  }
1368
- return setMarkoRunOptions(pluginConfig, opts);
1490
+ return setExternalPluginOptions(pluginConfig, opts);
1369
1491
  },
1370
1492
  configResolved(config2) {
1371
1493
  resolvedConfig = config2;
@@ -1,4 +1,4 @@
1
1
  export { default } from "./plugin";
2
2
  export { getAvailablePort, isPortInUse, loadEnv, parseEnv, spawnServer, } from "./utils/server";
3
3
  export type { SpawnedServer } from "./utils/server";
4
- export type { Adapter, Options, BuiltRoutes, HttpVerb, ParamInfo, Route, RoutableFile, RoutableFileType, } from "./types";
4
+ export type { Adapter, AdapterConfig, Options, BuiltRoutes, HttpVerb, ParamInfo, Route, RoutableFile, RoutableFileType, } from "./types";
@@ -943,6 +943,7 @@ function stripTsExtension(path3) {
943
943
  return path3;
944
944
  }
945
945
  function renderRouteTypeInfo(routes, pathPrefix = ".") {
946
+ var _a, _b;
946
947
  const writer = createStringWriter();
947
948
  writer.writeLines(
948
949
  `/*
@@ -950,13 +951,28 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
950
951
  Do NOT manually edit this file or your changes will be lost.
951
952
  */
952
953
  `,
953
- `import type { HandlerLike, Route } from "@marko/run";
954
- `
954
+ `import type { HandlerLike, Route, RouteContext, ValidatePath, ValidateHref } from "@marko/run";
955
+
956
+ declare global {
957
+ namespace MarkoRun {`
955
958
  );
959
+ const pathsWriter = writer.branch("paths");
960
+ writer.write(`
961
+ type GetablePath<T extends string> = ValidatePath<GetPaths, T>;
962
+ type GetableHref<T extends string> = ValidateHref<GetPaths, T>;
963
+ type PostablePath<T extends string> = ValidatePath<PostPaths, T>;
964
+ type PostableHref<T extends string> = ValidateHref<PostPaths, T>;
965
+ }
966
+ }
967
+ `);
956
968
  const routesWriter = writer.branch("types");
969
+ const serverWriter = writer.branch("server");
957
970
  const middlewareRouteTypes = /* @__PURE__ */ new Map();
971
+ const layoutRouteTypes = /* @__PURE__ */ new Map();
972
+ const getPaths = /* @__PURE__ */ new Set();
973
+ const postPaths = /* @__PURE__ */ new Set();
958
974
  for (const route of routes.list) {
959
- const { meta, handler, params, middleware } = route;
975
+ const { meta, handler, params, middleware, page, layouts } = route;
960
976
  const routeType = `Route${route.index}`;
961
977
  const pathType = `\`${route.path.replace(
962
978
  /\/\$(\$?)([^\/]*)/,
@@ -964,6 +980,24 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
964
980
  )}\``;
965
981
  const paramsType = params ? renderParamsInfoType(params) : "{}";
966
982
  let metaType = "undefined";
983
+ if (page || handler) {
984
+ const isGet = page || ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes("get"));
985
+ const isPost = (_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes("post");
986
+ if (isGet || isPost) {
987
+ const path3 = route.path.replace(
988
+ /\$(\$?)([^/]+)/g,
989
+ (_, s, name) => s ? `\${...${name}}` : `\${${name}}`
990
+ );
991
+ const splatIndex = path3.indexOf("/${...");
992
+ if (splatIndex >= 0) {
993
+ const path22 = path3.slice(0, splatIndex) || "/";
994
+ isGet && getPaths.add(path22);
995
+ isPost && postPaths.add(path22);
996
+ }
997
+ isGet && getPaths.add(path3);
998
+ isPost && postPaths.add(path3);
999
+ }
1000
+ }
967
1001
  if (meta) {
968
1002
  metaType = `typeof import('${pathPrefix}/${stripTsExtension(
969
1003
  meta.relativePath
@@ -973,7 +1007,23 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
973
1007
  }
974
1008
  }
975
1009
  if (handler) {
976
- writeRouteTypeModule(writer, pathPrefix, handler.relativePath, routeType);
1010
+ writeRouteTypeModule(
1011
+ serverWriter,
1012
+ pathPrefix,
1013
+ handler.relativePath,
1014
+ routeType
1015
+ );
1016
+ }
1017
+ if (page) {
1018
+ writer.writeLines(`
1019
+ declare module '${pathPrefix}/${page.relativePath}' {
1020
+ export interface Input {}
1021
+
1022
+ namespace MarkoRun {
1023
+ type CurrentRoute = ${routeType};
1024
+ type CurrentContext = RouteContext<CurrentRoute>;
1025
+ }
1026
+ }`);
977
1027
  }
978
1028
  if (middleware) {
979
1029
  let i = 0;
@@ -990,21 +1040,84 @@ function renderRouteTypeInfo(routes, pathPrefix = ".") {
990
1040
  i++;
991
1041
  }
992
1042
  }
1043
+ if (layouts) {
1044
+ for (const layout of layouts) {
1045
+ const existing = layoutRouteTypes.get(layout);
1046
+ if (!existing) {
1047
+ layoutRouteTypes.set(layout, {
1048
+ routeTypes: [routeType]
1049
+ });
1050
+ } else {
1051
+ existing.routeTypes.push(routeType);
1052
+ }
1053
+ }
1054
+ }
993
1055
  routesWriter.writeLines(
994
1056
  `interface ${routeType} extends Route<${paramsType}, ${metaType}, ${pathType}> {}`
995
1057
  );
996
1058
  }
1059
+ pathsWriter.write(" type GetPaths =");
1060
+ for (const path3 of getPaths) {
1061
+ pathsWriter.write(`
1062
+ | '${path3}'`);
1063
+ }
1064
+ pathsWriter.writeLines(";", "");
1065
+ pathsWriter.write(" type PostPaths =");
1066
+ for (const path3 of postPaths) {
1067
+ pathsWriter.write(`
1068
+ | '${path3}'`);
1069
+ }
1070
+ pathsWriter.writeLines(";");
1071
+ pathsWriter.join();
997
1072
  for (const [file, { routeTypes }] of middlewareRouteTypes) {
998
- const routeType = routeTypes.length > 1 ? routeTypes.join(" | ") : routeTypes[0];
999
- writeRouteTypeModule(writer, pathPrefix, file.relativePath, routeType);
1073
+ writeRouteTypeModule(
1074
+ serverWriter,
1075
+ pathPrefix,
1076
+ file.relativePath,
1077
+ routeTypes.join(" | ")
1078
+ );
1079
+ }
1080
+ for (const [file, { routeTypes }] of layoutRouteTypes) {
1081
+ writer.writeLines(`
1082
+ declare module '${pathPrefix}/${file.relativePath}' {
1083
+ export interface Input {
1084
+ renderBody: Marko.Body;
1085
+ }
1086
+
1087
+ namespace MarkoRun {
1088
+ type CurrentRoute = ${routeTypes.join(" | ")};
1089
+ type CurrentContext = RouteContext<CurrentRoute>;
1090
+ }
1091
+ }`);
1000
1092
  }
1093
+ for (const route of [routes.special["404"], routes.special["500"]]) {
1094
+ if (route && route.page) {
1095
+ writer.write(`
1096
+ declare module '${pathPrefix}/${route.page.relativePath}' {
1097
+ export interface Input {`);
1098
+ if (route.page.type === RoutableFileTypes.Error) {
1099
+ writer.write(`
1100
+ error: unknown;
1101
+ `);
1102
+ }
1103
+ writer.writeLines(`}
1104
+
1105
+ namespace MarkoRun {
1106
+ type CurrentRoute = Route;
1107
+ type CurrentContext = RouteContext<CurrentRoute>;
1108
+ }
1109
+ }`);
1110
+ }
1111
+ }
1112
+ serverWriter.join();
1001
1113
  return writer.end();
1002
1114
  }
1003
1115
  function writeRouteTypeModule(writer, pathPrefix, path3, routeType) {
1004
1116
  writer.writeLines(`
1005
1117
  declare module '${pathPrefix}/${stripTsExtension(path3)}' {
1006
- namespace Marko {
1118
+ namespace MarkoRun {
1007
1119
  type CurrentRoute = ${routeType};
1120
+ type CurrentContext = RouteContext<CurrentRoute>;
1008
1121
  type Handler<_Params = CurrentRoute['params'], _Meta = CurrentRoute['meta']> = HandlerLike<CurrentRoute>;
1009
1122
  function route(handler: Handler): typeof handler;
1010
1123
  function route<_Params = CurrentRoute['params'], _Meta = CurrentRoute['meta']>(handler: Handler): typeof handler;
@@ -1182,14 +1295,18 @@ function prettyPath(path3) {
1182
1295
  }
1183
1296
 
1184
1297
  // src/vite/utils/config.ts
1185
- var KEY = "__MARKO_SERVE_OPTIONS__";
1186
- function getMarkoRunOptions(viteConfig) {
1187
- return viteConfig[KEY];
1298
+ var PluginConfigKey = "__MARKO_RUN_PLUGIN_CONFIG__";
1299
+ var AdapterConfigKey = "__MARKO_RUN_ADAPTER_CONFIG__";
1300
+ function getConfig(obj, key) {
1301
+ return obj[key];
1188
1302
  }
1189
- function setMarkoRunOptions(viteConfig, options) {
1190
- viteConfig[KEY] = options;
1191
- return viteConfig;
1303
+ function setConfig(obj, key, value) {
1304
+ obj[key] = value;
1305
+ return obj;
1192
1306
  }
1307
+ var getExternalPluginOptions = (viteConfig) => getConfig(viteConfig, PluginConfigKey);
1308
+ var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, PluginConfigKey, value);
1309
+ var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
1193
1310
 
1194
1311
  // src/vite/plugin.ts
1195
1312
  import { fileURLToPath } from "url";
@@ -1229,10 +1346,8 @@ function markoServe(opts = {}) {
1229
1346
  "{.tsconfig*,tsconfig*.json}"
1230
1347
  ))) {
1231
1348
  const filepath = path2.join(typesDir, "routes.d.ts");
1232
- const data = renderRouteTypeInfo(
1233
- routes,
1234
- path2.relative(typesDir, routesDir)
1235
- );
1349
+ const adapterTypeInfo = (adapter == null ? void 0 : adapter.writeTypeInfo) && await (adapter == null ? void 0 : adapter.writeTypeInfo());
1350
+ const data = renderRouteTypeInfo(routes, path2.relative(typesDir, routesDir)) + adapterTypeInfo;
1236
1351
  if (data !== typesFile || !fs2.existsSync(filepath)) {
1237
1352
  await ensureDir(typesDir);
1238
1353
  await fs2.promises.writeFile(filepath, typesFile = data);
@@ -1281,13 +1396,14 @@ function markoServe(opts = {}) {
1281
1396
  const startTime = performance.now();
1282
1397
  routes = await buildRoutes(createFSWalker(resolvedRoutesDir), routesDir);
1283
1398
  times.routesBuild = performance.now() - startTime;
1284
- await Promise.all([writeTypesFile(), setVirtualFiles(false)]);
1399
+ await setVirtualFiles(false);
1285
1400
  isStale = false;
1286
1401
  isRendered = false;
1287
1402
  });
1288
1403
  const renderVirtualFiles = single(async () => {
1289
1404
  const startTime = performance.now();
1290
1405
  await setVirtualFiles(true);
1406
+ await writeTypesFile();
1291
1407
  times.routesRender = performance.now() - startTime;
1292
1408
  isRendered = true;
1293
1409
  });
@@ -1297,13 +1413,19 @@ function markoServe(opts = {}) {
1297
1413
  enforce: "pre",
1298
1414
  async config(config2, env) {
1299
1415
  var _a, _b, _c;
1300
- const externalPluginOptions = getMarkoRunOptions(config2);
1416
+ const externalPluginOptions = getExternalPluginOptions(config2);
1301
1417
  if (externalPluginOptions) {
1302
1418
  opts = mergeConfig(opts, externalPluginOptions);
1303
1419
  }
1304
- const adapterOptions = await ((_a = adapter == null ? void 0 : adapter.pluginOptions) == null ? void 0 : _a.call(adapter, opts));
1305
- if (adapterOptions) {
1306
- opts = mergeConfig(opts, adapterOptions);
1420
+ if (adapter) {
1421
+ const externalAdapterConfig = getExternalAdapterOptions(config2);
1422
+ if (externalAdapterConfig && adapter.configure) {
1423
+ adapter.configure(externalAdapterConfig);
1424
+ }
1425
+ const adapterOptions = await ((_a = adapter.pluginOptions) == null ? void 0 : _a.call(adapter, opts));
1426
+ if (adapterOptions) {
1427
+ opts = mergeConfig(opts, adapterOptions);
1428
+ }
1307
1429
  }
1308
1430
  root = normalizePath(config2.root || process.cwd());
1309
1431
  store = opts.store || new FileStore(
@@ -1327,7 +1449,7 @@ function markoServe(opts = {}) {
1327
1449
  if (adapterConfig) {
1328
1450
  pluginConfig = mergeConfig(pluginConfig, adapterConfig);
1329
1451
  }
1330
- return setMarkoRunOptions(pluginConfig, opts);
1452
+ return setExternalPluginOptions(pluginConfig, opts);
1331
1453
  },
1332
1454
  configResolved(config2) {
1333
1455
  resolvedConfig = config2;
@@ -3,14 +3,19 @@ import type { Options as MarkoViteOptions } from "@marko/vite";
3
3
  import type { ResolvedConfig, UserConfig } from "vite";
4
4
  export type { RoutableFileType, HttpVerb };
5
5
  export declare type StartServer = (port?: number) => Promise<void>;
6
+ export interface AdapterConfig {
7
+ [name: PropertyKey]: any;
8
+ }
6
9
  export interface Adapter {
7
10
  readonly name: string;
11
+ configure?(config: AdapterConfig): void;
8
12
  pluginOptions?(options: Options): Promise<Options> | Options | undefined;
9
13
  viteConfig?(config: UserConfig): Promise<UserConfig> | UserConfig | undefined;
10
14
  getEntryFile?(): Promise<string> | string;
11
15
  startDev?(configFile: string, port: number, envFile?: string): Promise<void> | void;
12
16
  startPreview?(dir: string, entry?: string, port?: number, envFile?: string): Promise<void> | void;
13
17
  buildEnd?(config: ResolvedConfig, routes: Route[], builtEntries: string[], sourceEntries: string[]): Promise<void> | void;
18
+ writeTypeInfo?(): Promise<string> | string;
14
19
  }
15
20
  export interface RouterOptions {
16
21
  trailingSlashes: 'Ignore' | 'RedirectWithout' | 'RedirectWith' | 'RewriteWithout' | 'RewriteWith';
@@ -1,3 +1,5 @@
1
- import type { Options } from '../types';
2
- export declare function getMarkoRunOptions<T extends Record<string, any>>(viteConfig: T): Readonly<Options> | undefined;
3
- export declare function setMarkoRunOptions<T extends Record<string, any>>(viteConfig: T, options: Options): T;
1
+ import type { Options, AdapterConfig } from '../types';
2
+ export declare const getExternalPluginOptions: <T>(viteConfig: T) => Readonly<Options> | undefined;
3
+ export declare const setExternalPluginOptions: <T>(viteConfig: T, value: Options) => T;
4
+ export declare const getExternalAdapterOptions: <T>(viteConfig: T) => Readonly<AdapterConfig> | undefined;
5
+ export declare const setExternalAdapterOptions: <T>(viteConfig: T, value: AdapterConfig) => T;
@@ -1,3 +1,3 @@
1
1
  import type { HttpVerb, Route } from "../types";
2
- export declare function getVerbs(route: Route): ("get" | "post" | "put" | "delete")[];
2
+ export declare function getVerbs(route: Route): ("get" | "delete" | "post" | "put")[];
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.0.1-beta3",
3
+ "version": "0.0.1-beta5",
4
4
  "description": "File-based routing for Marko based on Vite",
5
5
  "keywords": [],
6
6
  "author": "Ryan Turnquist <rturnq@gmail.com>",
@@ -47,19 +47,19 @@
47
47
  "typesVersions": {
48
48
  "*": {
49
49
  "*": [
50
- "./src/runtime/index.ts"
50
+ "./dist/runtime/index.d.ts"
51
51
  ],
52
52
  "router": [
53
- "./src/runtime/router.ts"
53
+ "./dist/runtime/router.d.ts"
54
54
  ],
55
55
  "vite": [
56
- "./src/vite/index.ts"
56
+ "./dist/vite/index.d.ts"
57
57
  ],
58
58
  "adapter/middleware": [
59
- "./src/adapter/middleware.ts"
59
+ "./dist/adapter/middleware.d.ts"
60
60
  ],
61
61
  "adapter": [
62
- "./src/adapter/index.ts"
62
+ "./dist/adapter/index.d.ts"
63
63
  ]
64
64
  }
65
65
  },
@@ -81,7 +81,7 @@
81
81
  "acorn": "^8.8.0",
82
82
  "cross-env": "^7.0.3",
83
83
  "esbuild": "^0.15.7",
84
- "marko": "^5.21.9",
84
+ "marko": "^5.22.4",
85
85
  "mocha": "^10.0.0",
86
86
  "mocha-snap": "^4.3.0",
87
87
  "prettier": "^2.7.1",
@@ -1,3 +0,0 @@
1
- import type { RouteHandler } from "./types";
2
- export declare function compose(...handlers: RouteHandler[]): RouteHandler;
3
- export declare function createHandler(factory: () => Promise<RouteHandler>): RouteHandler;