@marko/run 0.2.7 → 0.2.9
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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapter/default-entry.mjs +2 -2
- package/dist/adapter/dev-server.d.ts +1 -1
- package/dist/adapter/index.cjs +469 -28
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/index.js +469 -28
- package/dist/adapter/load-dev-worker.mjs +11 -10
- package/dist/adapter/middleware.cjs +15 -3
- package/dist/adapter/middleware.js +15 -3
- package/dist/adapter/utils.d.ts +10 -0
- package/dist/cli/index.mjs +77 -46
- package/dist/components/routes-explorer/+layout.marko +17 -0
- package/dist/components/routes-explorer/+page.marko +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/vite/index.cjs +69 -44
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +69 -44
- package/dist/vite/routes/builder.d.ts +6 -1
- package/dist/vite/types.d.ts +11 -0
- package/package.json +17 -12
package/dist/cli/index.mjs
CHANGED
|
@@ -403,10 +403,7 @@ function matchRoutableFile(filename) {
|
|
|
403
403
|
function isSpecialType(type) {
|
|
404
404
|
return type === RoutableFileTypes.NotFound || type === RoutableFileTypes.Error;
|
|
405
405
|
}
|
|
406
|
-
async function buildRoutes(
|
|
407
|
-
if (basePath) {
|
|
408
|
-
basePath = basePath.replace(/^\/+|\/+$/g, "");
|
|
409
|
-
}
|
|
406
|
+
async function buildRoutes(sources) {
|
|
410
407
|
const uniqueRoutes = /* @__PURE__ */ new Map();
|
|
411
408
|
const routes = [];
|
|
412
409
|
const special = {};
|
|
@@ -416,23 +413,30 @@ async function buildRoutes(walk, basePath = "") {
|
|
|
416
413
|
const currentMiddleware = /* @__PURE__ */ new Set();
|
|
417
414
|
const root = new VDir();
|
|
418
415
|
const dirStack = [];
|
|
419
|
-
let
|
|
416
|
+
let basePath;
|
|
417
|
+
let importPrefix;
|
|
418
|
+
let activeDirs;
|
|
419
|
+
let isBaseDir;
|
|
420
420
|
let nextFileId = 1;
|
|
421
421
|
let nextRouteIndex = 1;
|
|
422
|
-
|
|
423
|
-
await walk({
|
|
422
|
+
const walkOptions = {
|
|
424
423
|
onEnter({ name }) {
|
|
425
|
-
|
|
424
|
+
const prevDirStackLength = dirStack.length;
|
|
425
|
+
if (isBaseDir) {
|
|
426
426
|
isBaseDir = false;
|
|
427
|
-
|
|
427
|
+
if (!basePath) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
name = basePath;
|
|
431
|
+
} else {
|
|
432
|
+
dirStack.push(name);
|
|
428
433
|
}
|
|
429
|
-
dirStack.push(name);
|
|
430
434
|
const previousDirs = activeDirs;
|
|
431
435
|
const paths = parseFlatRoute(name);
|
|
432
436
|
activeDirs = VDir.addPaths(previousDirs, paths);
|
|
433
437
|
return () => {
|
|
434
438
|
activeDirs = previousDirs;
|
|
435
|
-
dirStack.
|
|
439
|
+
dirStack.length = prevDirStackLength;
|
|
436
440
|
};
|
|
437
441
|
},
|
|
438
442
|
onFile({ name, path: path4 }) {
|
|
@@ -460,14 +464,24 @@ async function buildRoutes(walk, basePath = "") {
|
|
|
460
464
|
type,
|
|
461
465
|
filePath: path4,
|
|
462
466
|
relativePath,
|
|
463
|
-
importPath: `${
|
|
467
|
+
importPath: `${importPrefix}/${relativePath}`,
|
|
464
468
|
verbs: type === RoutableFileTypes.Page ? ["get"] : void 0
|
|
465
469
|
};
|
|
466
470
|
for (const dir of dirs) {
|
|
467
471
|
dir.addFile(file);
|
|
468
472
|
}
|
|
469
473
|
}
|
|
470
|
-
}
|
|
474
|
+
};
|
|
475
|
+
if (!Array.isArray(sources)) {
|
|
476
|
+
sources = [sources];
|
|
477
|
+
}
|
|
478
|
+
for (const source of sources) {
|
|
479
|
+
importPrefix = source.importPrefix ? source.importPrefix.replace(/^\/+|\/+$/g, "") : "";
|
|
480
|
+
basePath = source.basePath || "";
|
|
481
|
+
activeDirs = [root];
|
|
482
|
+
isBaseDir = true;
|
|
483
|
+
await source.walker(walkOptions);
|
|
484
|
+
}
|
|
471
485
|
traverse(root);
|
|
472
486
|
return {
|
|
473
487
|
list: routes,
|
|
@@ -1115,10 +1129,18 @@ export async function fetch(request, platform) {
|
|
|
1115
1129
|
const route = match(request.method, pathname);
|
|
1116
1130
|
return await invoke(route, request, platform, url);
|
|
1117
1131
|
} catch (error) {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1132
|
+
if (import.meta.env.DEV) {
|
|
1133
|
+
let body;
|
|
1134
|
+
if (error.cause) {
|
|
1135
|
+
body = error.cause.stack || error.cause.message || error.cause;
|
|
1136
|
+
} else {
|
|
1137
|
+
body = error.stack || error.message || "Internal Server Error";
|
|
1138
|
+
}
|
|
1139
|
+
return new Response(body, {
|
|
1140
|
+
status: 500
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
return new Response(null, {
|
|
1122
1144
|
status: 500
|
|
1123
1145
|
});
|
|
1124
1146
|
}
|
|
@@ -1169,10 +1191,11 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
1169
1191
|
writer.writeBlockStart(`switch (${value}.toLowerCase()) {`);
|
|
1170
1192
|
}
|
|
1171
1193
|
for (const { key, path: path4, route: route2 } of terminal) {
|
|
1194
|
+
const decodedKey = decodeURIComponent(key);
|
|
1172
1195
|
if (useSwitch) {
|
|
1173
|
-
writer.write(`case '${
|
|
1196
|
+
writer.write(`case '${decodedKey}': `, true);
|
|
1174
1197
|
} else {
|
|
1175
|
-
writer.write(`if (${value}.toLowerCase() === '${
|
|
1198
|
+
writer.write(`if (${value}.toLowerCase() === '${decodedKey}') `, true);
|
|
1176
1199
|
}
|
|
1177
1200
|
writer.write(
|
|
1178
1201
|
`return ${renderMatch(verb, route2, path4)}; // ${path4.path}
|
|
@@ -1611,7 +1634,9 @@ function logRoutesTable(routes, bundle, options) {
|
|
|
1611
1634
|
entryType.push(kleur.yellow("page"));
|
|
1612
1635
|
size = prettySize(computeRouteSize(getRouteChunkName(route), bundle));
|
|
1613
1636
|
}
|
|
1614
|
-
const row = [
|
|
1637
|
+
const row = [
|
|
1638
|
+
kleur.bold(HttpVerbColors[verb](verb.toUpperCase()))
|
|
1639
|
+
];
|
|
1615
1640
|
if (verbs.length === 1 || firstRow) {
|
|
1616
1641
|
row.push({ rowSpan: verbs.length, content: prettyPath(path4.path) });
|
|
1617
1642
|
firstRow = false;
|
|
@@ -1649,10 +1674,7 @@ function byteSize(source) {
|
|
|
1649
1674
|
}
|
|
1650
1675
|
function computeChunkSize(chunk, bundle, seen = /* @__PURE__ */ new Set()) {
|
|
1651
1676
|
if (chunk.type === "asset") {
|
|
1652
|
-
return [
|
|
1653
|
-
byteSize(chunk.source),
|
|
1654
|
-
gzipSize(chunk.source)
|
|
1655
|
-
];
|
|
1677
|
+
return [byteSize(chunk.source), gzipSize(chunk.source)];
|
|
1656
1678
|
}
|
|
1657
1679
|
const size = [byteSize(chunk.code), gzipSize(chunk.code)];
|
|
1658
1680
|
for (const id of chunk.imports) {
|
|
@@ -1685,6 +1707,8 @@ function prettyPath(path4) {
|
|
|
1685
1707
|
}
|
|
1686
1708
|
|
|
1687
1709
|
// src/vite/plugin.ts
|
|
1710
|
+
import createDebug from "debug";
|
|
1711
|
+
var debug = createDebug("@marko/run");
|
|
1688
1712
|
var __dirname = path2.dirname(fileURLToPath(import.meta.url));
|
|
1689
1713
|
var PLUGIN_NAME_PREFIX = "marko-run-vite";
|
|
1690
1714
|
var POSIX_SEP = "/";
|
|
@@ -1739,17 +1763,15 @@ function markoRun(opts = {}) {
|
|
|
1739
1763
|
const routerOptions = {
|
|
1740
1764
|
trailingSlashes: opts.trailingSlashes || "RedirectWithout"
|
|
1741
1765
|
};
|
|
1742
|
-
if (!render) {
|
|
1743
|
-
virtualFiles.clear();
|
|
1744
|
-
isRendered = false;
|
|
1745
|
-
}
|
|
1746
1766
|
try {
|
|
1747
1767
|
if (isStale) {
|
|
1768
|
+
virtualFiles.clear();
|
|
1769
|
+
isRendered = false;
|
|
1748
1770
|
const buildStartTime = performance.now();
|
|
1749
|
-
routes = await buildRoutes(
|
|
1750
|
-
createFSWalker(resolvedRoutesDir),
|
|
1751
|
-
routesDir
|
|
1752
|
-
);
|
|
1771
|
+
routes = await buildRoutes({
|
|
1772
|
+
walker: createFSWalker(resolvedRoutesDir),
|
|
1773
|
+
importPrefix: routesDir
|
|
1774
|
+
});
|
|
1753
1775
|
times.routesBuild = performance.now() - buildStartTime;
|
|
1754
1776
|
if (!routes.list.length) {
|
|
1755
1777
|
throw new Error("No routes generated");
|
|
@@ -1795,6 +1817,12 @@ function markoRun(opts = {}) {
|
|
|
1795
1817
|
times.routesRender = performance.now() - renderStartTime;
|
|
1796
1818
|
if (render) {
|
|
1797
1819
|
await writeTypesFile(routes);
|
|
1820
|
+
if (adapter == null ? void 0 : adapter.routesGenerated) {
|
|
1821
|
+
await adapter.routesGenerated(routes, new Map(virtualFiles.entries()), {
|
|
1822
|
+
buildTime: times.routesBuild,
|
|
1823
|
+
renderTime: times.routesRender
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1798
1826
|
if (!isBuild) {
|
|
1799
1827
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
1800
1828
|
}
|
|
@@ -2035,13 +2063,10 @@ function markoRun(opts = {}) {
|
|
|
2035
2063
|
if (virtualFiles.has(importee)) {
|
|
2036
2064
|
resolved = importee;
|
|
2037
2065
|
} else if (virtualFilePath) {
|
|
2038
|
-
const
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
skipSelf: true
|
|
2043
|
-
}
|
|
2044
|
-
);
|
|
2066
|
+
const filePath = path2.resolve(__dirname, "..", virtualFilePath);
|
|
2067
|
+
const resolution = await this.resolve(filePath, importer, {
|
|
2068
|
+
skipSelf: true
|
|
2069
|
+
});
|
|
2045
2070
|
return resolution;
|
|
2046
2071
|
}
|
|
2047
2072
|
return resolved || null;
|
|
@@ -2051,7 +2076,7 @@ function markoRun(opts = {}) {
|
|
|
2051
2076
|
id = id.slice(0, -serverEntryQuery.length);
|
|
2052
2077
|
}
|
|
2053
2078
|
if (virtualFiles.has(id)) {
|
|
2054
|
-
if (!isRendered) {
|
|
2079
|
+
if (isStale || !isRendered) {
|
|
2055
2080
|
await buildVirtualFiles(true);
|
|
2056
2081
|
}
|
|
2057
2082
|
return virtualFiles.get(id);
|
|
@@ -2095,7 +2120,7 @@ function markoRun(opts = {}) {
|
|
|
2095
2120
|
}
|
|
2096
2121
|
await store.set(routeDataFilename, JSON.stringify(routeData));
|
|
2097
2122
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
2098
|
-
} else {
|
|
2123
|
+
} else if (process.env.MR_EXPLORER !== "true") {
|
|
2099
2124
|
logRoutesTable(routes, bundle, options);
|
|
2100
2125
|
}
|
|
2101
2126
|
},
|
|
@@ -2202,19 +2227,19 @@ async function resolveAdapter(root, options, log) {
|
|
|
2202
2227
|
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
2203
2228
|
try {
|
|
2204
2229
|
const module2 = await import(name);
|
|
2205
|
-
log &&
|
|
2230
|
+
log && debug(
|
|
2206
2231
|
`Using adapter ${name} listed in your package.json dependecies`
|
|
2207
2232
|
);
|
|
2208
2233
|
return module2.default();
|
|
2209
2234
|
} catch (err) {
|
|
2210
|
-
log &&
|
|
2235
|
+
log && debug(`Attempt to use package '${name}' failed %O`, err);
|
|
2211
2236
|
}
|
|
2212
2237
|
}
|
|
2213
2238
|
}
|
|
2214
2239
|
}
|
|
2215
2240
|
const defaultAdapter = "@marko/run/adapter";
|
|
2216
2241
|
const module = await import(defaultAdapter);
|
|
2217
|
-
log &&
|
|
2242
|
+
log && debug("Using default adapter");
|
|
2218
2243
|
return module.default();
|
|
2219
2244
|
}
|
|
2220
2245
|
var markoEntryFileRegex = /__marko-run__([^.]+)\.(.+)\.marko\.([^.]+)$/;
|
|
@@ -2233,7 +2258,7 @@ var __dirname2 = path3.dirname(fileURLToPath2(import.meta.url));
|
|
|
2233
2258
|
var defaultPort = Number(process.env.PORT || 3e3);
|
|
2234
2259
|
var defaultConfigFileBases = ["serve.config", "vite.config"];
|
|
2235
2260
|
var defaultConfigFileExts = [".js", ".cjs", ".mjs", ".ts", ".mts"];
|
|
2236
|
-
async function preview(entry, cwd, configFile, port, outDir, envFile, args = []) {
|
|
2261
|
+
async function preview(sourceEntry, entry, cwd, configFile, port, outDir, envFile, args = []) {
|
|
2237
2262
|
const resolvedConfig = await resolveConfig(
|
|
2238
2263
|
{ root: cwd, configFile, logLevel: "silent", build: { outDir } },
|
|
2239
2264
|
"serve"
|
|
@@ -2257,7 +2282,8 @@ async function preview(entry, cwd, configFile, port, outDir, envFile, args = [])
|
|
|
2257
2282
|
dir,
|
|
2258
2283
|
args,
|
|
2259
2284
|
port: availablePort,
|
|
2260
|
-
envFile
|
|
2285
|
+
envFile,
|
|
2286
|
+
sourceEntry
|
|
2261
2287
|
};
|
|
2262
2288
|
return await adapter.startPreview(entryFile, options);
|
|
2263
2289
|
}
|
|
@@ -2403,12 +2429,15 @@ prog.command("preview [entry]").describe("Start a production-like server for alr
|
|
|
2403
2429
|
"-p, --port",
|
|
2404
2430
|
"Port the server should listen on (defaults: `$PORT` env variable or 3000)"
|
|
2405
2431
|
).option("-f, --file", "Output file to start").action(async (entry, opts) => {
|
|
2432
|
+
var _a;
|
|
2406
2433
|
process.env.NODE_ENV = "production";
|
|
2434
|
+
(_a = process.env).MR_EXPLORER ?? (_a.MR_EXPLORER = "true");
|
|
2407
2435
|
const cwd = process.cwd();
|
|
2408
2436
|
const args = process.argv.slice(entry ? 4 : 3);
|
|
2409
2437
|
const config2 = await getViteConfig(cwd, opts.config);
|
|
2410
2438
|
await build(entry, cwd, config2, opts.output, opts.env);
|
|
2411
2439
|
await preview(
|
|
2440
|
+
entry,
|
|
2412
2441
|
opts.file,
|
|
2413
2442
|
cwd,
|
|
2414
2443
|
config2,
|
|
@@ -2422,6 +2451,8 @@ prog.command("dev [entry]", "", { default: true }).describe("Start development s
|
|
|
2422
2451
|
"-p, --port",
|
|
2423
2452
|
"Port the dev server should listen on (defaults: 'preview.port' in config, or `$PORT` env variable, or 3000)"
|
|
2424
2453
|
).example("dev --config vite.config.js").action(async (entry, opts) => {
|
|
2454
|
+
var _a;
|
|
2455
|
+
(_a = process.env).MR_EXPLORER ?? (_a.MR_EXPLORER = "true");
|
|
2425
2456
|
const cwd = process.cwd();
|
|
2426
2457
|
const args = process.argv.slice(entry ? 4 : 3);
|
|
2427
2458
|
const config2 = await getViteConfig(cwd, opts.config);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta
|
|
6
|
+
name="description"
|
|
7
|
+
content="Marko Run route explorer"
|
|
8
|
+
>
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
10
|
+
<title>Explore your routes</title>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<h2>Marko Run Route Explorer</h2>
|
|
14
|
+
<hr/>
|
|
15
|
+
<${input.renderBody} />
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<h1>Hello World!!</h1>
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { InlineConfig } from "vite";
|
|
1
2
|
import { NotHandled, NotMatched } from "./namespace";
|
|
2
3
|
import type { GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform, HandlerTypeFn, RuntimeModule, AnyRoute, AnyContext, AnyHandler } from "./types";
|
|
3
4
|
declare global {
|
|
4
5
|
var __marko_run__: RuntimeModule;
|
|
6
|
+
var __marko_run_vite_config__: InlineConfig | undefined;
|
|
5
7
|
namespace MarkoRun {
|
|
6
8
|
export const route: HandlerTypeFn;
|
|
7
9
|
export { GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform, NotHandled, NotMatched, AnyRoute as Route, AnyContext as Context, AnyHandler as Handler, };
|
package/dist/vite/index.cjs
CHANGED
|
@@ -388,10 +388,7 @@ function matchRoutableFile(filename) {
|
|
|
388
388
|
function isSpecialType(type) {
|
|
389
389
|
return type === RoutableFileTypes.NotFound || type === RoutableFileTypes.Error;
|
|
390
390
|
}
|
|
391
|
-
async function buildRoutes(
|
|
392
|
-
if (basePath) {
|
|
393
|
-
basePath = basePath.replace(/^\/+|\/+$/g, "");
|
|
394
|
-
}
|
|
391
|
+
async function buildRoutes(sources) {
|
|
395
392
|
const uniqueRoutes = /* @__PURE__ */ new Map();
|
|
396
393
|
const routes = [];
|
|
397
394
|
const special = {};
|
|
@@ -401,23 +398,30 @@ async function buildRoutes(walk, basePath = "") {
|
|
|
401
398
|
const currentMiddleware = /* @__PURE__ */ new Set();
|
|
402
399
|
const root = new VDir();
|
|
403
400
|
const dirStack = [];
|
|
404
|
-
let
|
|
401
|
+
let basePath;
|
|
402
|
+
let importPrefix;
|
|
403
|
+
let activeDirs;
|
|
404
|
+
let isBaseDir;
|
|
405
405
|
let nextFileId = 1;
|
|
406
406
|
let nextRouteIndex = 1;
|
|
407
|
-
|
|
408
|
-
await walk({
|
|
407
|
+
const walkOptions = {
|
|
409
408
|
onEnter({ name }) {
|
|
410
|
-
|
|
409
|
+
const prevDirStackLength = dirStack.length;
|
|
410
|
+
if (isBaseDir) {
|
|
411
411
|
isBaseDir = false;
|
|
412
|
-
|
|
412
|
+
if (!basePath) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
name = basePath;
|
|
416
|
+
} else {
|
|
417
|
+
dirStack.push(name);
|
|
413
418
|
}
|
|
414
|
-
dirStack.push(name);
|
|
415
419
|
const previousDirs = activeDirs;
|
|
416
420
|
const paths = parseFlatRoute(name);
|
|
417
421
|
activeDirs = VDir.addPaths(previousDirs, paths);
|
|
418
422
|
return () => {
|
|
419
423
|
activeDirs = previousDirs;
|
|
420
|
-
dirStack.
|
|
424
|
+
dirStack.length = prevDirStackLength;
|
|
421
425
|
};
|
|
422
426
|
},
|
|
423
427
|
onFile({ name, path: path3 }) {
|
|
@@ -445,14 +449,24 @@ async function buildRoutes(walk, basePath = "") {
|
|
|
445
449
|
type,
|
|
446
450
|
filePath: path3,
|
|
447
451
|
relativePath,
|
|
448
|
-
importPath: `${
|
|
452
|
+
importPath: `${importPrefix}/${relativePath}`,
|
|
449
453
|
verbs: type === RoutableFileTypes.Page ? ["get"] : void 0
|
|
450
454
|
};
|
|
451
455
|
for (const dir of dirs) {
|
|
452
456
|
dir.addFile(file);
|
|
453
457
|
}
|
|
454
458
|
}
|
|
455
|
-
}
|
|
459
|
+
};
|
|
460
|
+
if (!Array.isArray(sources)) {
|
|
461
|
+
sources = [sources];
|
|
462
|
+
}
|
|
463
|
+
for (const source of sources) {
|
|
464
|
+
importPrefix = source.importPrefix ? source.importPrefix.replace(/^\/+|\/+$/g, "") : "";
|
|
465
|
+
basePath = source.basePath || "";
|
|
466
|
+
activeDirs = [root];
|
|
467
|
+
isBaseDir = true;
|
|
468
|
+
await source.walker(walkOptions);
|
|
469
|
+
}
|
|
456
470
|
traverse(root);
|
|
457
471
|
return {
|
|
458
472
|
list: routes,
|
|
@@ -1100,10 +1114,18 @@ export async function fetch(request, platform) {
|
|
|
1100
1114
|
const route = match(request.method, pathname);
|
|
1101
1115
|
return await invoke(route, request, platform, url);
|
|
1102
1116
|
} catch (error) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1117
|
+
if (import.meta.env.DEV) {
|
|
1118
|
+
let body;
|
|
1119
|
+
if (error.cause) {
|
|
1120
|
+
body = error.cause.stack || error.cause.message || error.cause;
|
|
1121
|
+
} else {
|
|
1122
|
+
body = error.stack || error.message || "Internal Server Error";
|
|
1123
|
+
}
|
|
1124
|
+
return new Response(body, {
|
|
1125
|
+
status: 500
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
return new Response(null, {
|
|
1107
1129
|
status: 500
|
|
1108
1130
|
});
|
|
1109
1131
|
}
|
|
@@ -1154,10 +1176,11 @@ function writeRouterVerb(writer, trie, verb, level = 0, offset = 1) {
|
|
|
1154
1176
|
writer.writeBlockStart(`switch (${value}.toLowerCase()) {`);
|
|
1155
1177
|
}
|
|
1156
1178
|
for (const { key, path: path3, route: route2 } of terminal) {
|
|
1179
|
+
const decodedKey = decodeURIComponent(key);
|
|
1157
1180
|
if (useSwitch) {
|
|
1158
|
-
writer.write(`case '${
|
|
1181
|
+
writer.write(`case '${decodedKey}': `, true);
|
|
1159
1182
|
} else {
|
|
1160
|
-
writer.write(`if (${value}.toLowerCase() === '${
|
|
1183
|
+
writer.write(`if (${value}.toLowerCase() === '${decodedKey}') `, true);
|
|
1161
1184
|
}
|
|
1162
1185
|
writer.write(
|
|
1163
1186
|
`return ${renderMatch(verb, route2, path3)}; // ${path3.path}
|
|
@@ -1596,7 +1619,9 @@ function logRoutesTable(routes, bundle, options) {
|
|
|
1596
1619
|
entryType.push(import_kleur.default.yellow("page"));
|
|
1597
1620
|
size = prettySize(computeRouteSize(getRouteChunkName(route), bundle));
|
|
1598
1621
|
}
|
|
1599
|
-
const row = [
|
|
1622
|
+
const row = [
|
|
1623
|
+
import_kleur.default.bold(HttpVerbColors[verb](verb.toUpperCase()))
|
|
1624
|
+
];
|
|
1600
1625
|
if (verbs.length === 1 || firstRow) {
|
|
1601
1626
|
row.push({ rowSpan: verbs.length, content: prettyPath(path3.path) });
|
|
1602
1627
|
firstRow = false;
|
|
@@ -1634,10 +1659,7 @@ function byteSize(source) {
|
|
|
1634
1659
|
}
|
|
1635
1660
|
function computeChunkSize(chunk, bundle, seen = /* @__PURE__ */ new Set()) {
|
|
1636
1661
|
if (chunk.type === "asset") {
|
|
1637
|
-
return [
|
|
1638
|
-
byteSize(chunk.source),
|
|
1639
|
-
gzipSize(chunk.source)
|
|
1640
|
-
];
|
|
1662
|
+
return [byteSize(chunk.source), gzipSize(chunk.source)];
|
|
1641
1663
|
}
|
|
1642
1664
|
const size = [byteSize(chunk.code), gzipSize(chunk.code)];
|
|
1643
1665
|
for (const id of chunk.imports) {
|
|
@@ -1684,6 +1706,8 @@ var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, Plug
|
|
|
1684
1706
|
var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
|
|
1685
1707
|
|
|
1686
1708
|
// src/vite/plugin.ts
|
|
1709
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
1710
|
+
var debug = (0, import_debug.default)("@marko/run");
|
|
1687
1711
|
var __dirname = import_path2.default.dirname((0, import_url2.fileURLToPath)(__importMetaURL));
|
|
1688
1712
|
var PLUGIN_NAME_PREFIX = "marko-run-vite";
|
|
1689
1713
|
var POSIX_SEP = "/";
|
|
@@ -1738,17 +1762,15 @@ function markoRun(opts = {}) {
|
|
|
1738
1762
|
const routerOptions = {
|
|
1739
1763
|
trailingSlashes: opts.trailingSlashes || "RedirectWithout"
|
|
1740
1764
|
};
|
|
1741
|
-
if (!render) {
|
|
1742
|
-
virtualFiles.clear();
|
|
1743
|
-
isRendered = false;
|
|
1744
|
-
}
|
|
1745
1765
|
try {
|
|
1746
1766
|
if (isStale) {
|
|
1767
|
+
virtualFiles.clear();
|
|
1768
|
+
isRendered = false;
|
|
1747
1769
|
const buildStartTime = performance.now();
|
|
1748
|
-
routes = await buildRoutes(
|
|
1749
|
-
createFSWalker(resolvedRoutesDir),
|
|
1750
|
-
routesDir
|
|
1751
|
-
);
|
|
1770
|
+
routes = await buildRoutes({
|
|
1771
|
+
walker: createFSWalker(resolvedRoutesDir),
|
|
1772
|
+
importPrefix: routesDir
|
|
1773
|
+
});
|
|
1752
1774
|
times.routesBuild = performance.now() - buildStartTime;
|
|
1753
1775
|
if (!routes.list.length) {
|
|
1754
1776
|
throw new Error("No routes generated");
|
|
@@ -1794,6 +1816,12 @@ function markoRun(opts = {}) {
|
|
|
1794
1816
|
times.routesRender = performance.now() - renderStartTime;
|
|
1795
1817
|
if (render) {
|
|
1796
1818
|
await writeTypesFile(routes);
|
|
1819
|
+
if (adapter == null ? void 0 : adapter.routesGenerated) {
|
|
1820
|
+
await adapter.routesGenerated(routes, new Map(virtualFiles.entries()), {
|
|
1821
|
+
buildTime: times.routesBuild,
|
|
1822
|
+
renderTime: times.routesRender
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1797
1825
|
if (!isBuild) {
|
|
1798
1826
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
1799
1827
|
}
|
|
@@ -2034,13 +2062,10 @@ function markoRun(opts = {}) {
|
|
|
2034
2062
|
if (virtualFiles.has(importee)) {
|
|
2035
2063
|
resolved = importee;
|
|
2036
2064
|
} else if (virtualFilePath) {
|
|
2037
|
-
const
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
skipSelf: true
|
|
2042
|
-
}
|
|
2043
|
-
);
|
|
2065
|
+
const filePath = import_path2.default.resolve(__dirname, "..", virtualFilePath);
|
|
2066
|
+
const resolution = await this.resolve(filePath, importer, {
|
|
2067
|
+
skipSelf: true
|
|
2068
|
+
});
|
|
2044
2069
|
return resolution;
|
|
2045
2070
|
}
|
|
2046
2071
|
return resolved || null;
|
|
@@ -2050,7 +2075,7 @@ function markoRun(opts = {}) {
|
|
|
2050
2075
|
id = id.slice(0, -serverEntryQuery.length);
|
|
2051
2076
|
}
|
|
2052
2077
|
if (virtualFiles.has(id)) {
|
|
2053
|
-
if (!isRendered) {
|
|
2078
|
+
if (isStale || !isRendered) {
|
|
2054
2079
|
await buildVirtualFiles(true);
|
|
2055
2080
|
}
|
|
2056
2081
|
return virtualFiles.get(id);
|
|
@@ -2094,7 +2119,7 @@ function markoRun(opts = {}) {
|
|
|
2094
2119
|
}
|
|
2095
2120
|
await store.set(routeDataFilename, JSON.stringify(routeData));
|
|
2096
2121
|
await ((_a = opts == null ? void 0 : opts.emitRoutes) == null ? void 0 : _a.call(opts, routes.list));
|
|
2097
|
-
} else {
|
|
2122
|
+
} else if (process.env.MR_EXPLORER !== "true") {
|
|
2098
2123
|
logRoutesTable(routes, bundle, options);
|
|
2099
2124
|
}
|
|
2100
2125
|
},
|
|
@@ -2201,19 +2226,19 @@ async function resolveAdapter(root, options, log) {
|
|
|
2201
2226
|
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
2202
2227
|
try {
|
|
2203
2228
|
const module3 = await import(name);
|
|
2204
|
-
log &&
|
|
2229
|
+
log && debug(
|
|
2205
2230
|
`Using adapter ${name} listed in your package.json dependecies`
|
|
2206
2231
|
);
|
|
2207
2232
|
return module3.default();
|
|
2208
2233
|
} catch (err) {
|
|
2209
|
-
log &&
|
|
2234
|
+
log && debug(`Attempt to use package '${name}' failed %O`, err);
|
|
2210
2235
|
}
|
|
2211
2236
|
}
|
|
2212
2237
|
}
|
|
2213
2238
|
}
|
|
2214
2239
|
const defaultAdapter = "@marko/run/adapter";
|
|
2215
2240
|
const module2 = await import(defaultAdapter);
|
|
2216
|
-
log &&
|
|
2241
|
+
log && debug("Using default adapter");
|
|
2217
2242
|
return module2.default();
|
|
2218
2243
|
}
|
|
2219
2244
|
var markoEntryFileRegex = /__marko-run__([^.]+)\.(.+)\.marko\.([^.]+)$/;
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default, getPackageData } 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, AdapterConfig, Options, BuiltRoutes, HttpVerb, PackageData,
|
|
4
|
+
export type { Adapter, AdapterConfig, Options, BuiltRoutes, ExplorerData, HttpVerb, PackageData, PathInfo, RoutableFile, RoutableFileType, Route, RouteGenerationData } from "./types";
|