@marko/run 0.5.14 → 0.5.15
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/index.cjs +10 -3
- package/dist/adapter/index.js +10 -3
- package/dist/cli/index.mjs +102 -55
- package/dist/runtime/internal.cjs +12 -2
- package/dist/runtime/internal.d.ts +3 -1
- package/dist/runtime/internal.js +9 -1
- package/dist/runtime/types.d.ts +1 -1
- package/dist/vite/constants.d.ts +1 -1
- package/dist/vite/index.cjs +102 -55
- package/dist/vite/index.js +102 -55
- package/dist/vite/utils/route.d.ts +2 -2
- package/package.json +2 -6
package/dist/cli/index.mjs
CHANGED
|
@@ -65,7 +65,15 @@ import path from "path";
|
|
|
65
65
|
// src/vite/constants.ts
|
|
66
66
|
var markoRunFilePrefix = "__marko-run__";
|
|
67
67
|
var virtualFilePrefix = "virtual:marko-run";
|
|
68
|
-
var httpVerbs = [
|
|
68
|
+
var httpVerbs = [
|
|
69
|
+
"get",
|
|
70
|
+
"head",
|
|
71
|
+
"post",
|
|
72
|
+
"put",
|
|
73
|
+
"delete",
|
|
74
|
+
"patch",
|
|
75
|
+
"options"
|
|
76
|
+
];
|
|
69
77
|
var serverEntryQuery = "?marko-server-entry";
|
|
70
78
|
var RoutableFileTypes = {
|
|
71
79
|
Page: "page",
|
|
@@ -78,17 +86,27 @@ var RoutableFileTypes = {
|
|
|
78
86
|
};
|
|
79
87
|
|
|
80
88
|
// src/vite/utils/route.ts
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
var httpVerbOrder = httpVerbs.reduce(
|
|
90
|
+
(order, verb, index) => {
|
|
91
|
+
order[verb] = index;
|
|
92
|
+
return order;
|
|
93
|
+
},
|
|
94
|
+
{}
|
|
95
|
+
);
|
|
96
|
+
function getVerbs(route, noAutoHead) {
|
|
97
|
+
var _a;
|
|
98
|
+
const verbs = new Set((_a = route.handler) == null ? void 0 : _a.verbs);
|
|
99
|
+
if (route.page) {
|
|
100
|
+
verbs.add("get");
|
|
86
101
|
}
|
|
87
|
-
|
|
102
|
+
if (!noAutoHead && verbs.has("get")) {
|
|
103
|
+
verbs.add("head");
|
|
104
|
+
}
|
|
105
|
+
return [...verbs].sort((a, b) => httpVerbOrder[a] - httpVerbOrder[b]);
|
|
88
106
|
}
|
|
89
107
|
function hasVerb(route, verb) {
|
|
90
108
|
var _a, _b;
|
|
91
|
-
return verb === "get" && route.page || ((_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb));
|
|
109
|
+
return verb === "get" && !!route.page || ((_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb)) || verb === "head" && hasVerb(route, "get");
|
|
92
110
|
}
|
|
93
111
|
|
|
94
112
|
// src/vite/codegen/writer.ts
|
|
@@ -292,12 +310,15 @@ function renderRouteEntry(route, entriesDir) {
|
|
|
292
310
|
if (handler || middleware.length) {
|
|
293
311
|
runtimeImports.push("call");
|
|
294
312
|
}
|
|
295
|
-
if (!page || verbs.
|
|
313
|
+
if (!page || verbs.some((verb) => verb !== "get" && verb !== "head")) {
|
|
296
314
|
runtimeImports.push("noContent");
|
|
297
315
|
}
|
|
298
316
|
if (page) {
|
|
299
317
|
runtimeImports.push("pageResponse");
|
|
300
318
|
}
|
|
319
|
+
if (verbs.includes("head")) {
|
|
320
|
+
runtimeImports.push("stripResponseBody");
|
|
321
|
+
}
|
|
301
322
|
if (runtimeImports.length) {
|
|
302
323
|
imports.writeLines(
|
|
303
324
|
`import { ${runtimeImports.join(
|
|
@@ -341,66 +362,80 @@ function renderRouteEntry(route, entriesDir) {
|
|
|
341
362
|
}
|
|
342
363
|
return writer.end();
|
|
343
364
|
}
|
|
344
|
-
function writePageResponse(writer, wrapFn) {
|
|
345
|
-
writer.writeLines(
|
|
346
|
-
`${wrapFn ? `const ${wrapFn} = () =>` : `return`} pageResponse(page, buildInput());`
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
function writeMiddleware(writer, middleware, next, wrapFn) {
|
|
350
|
-
if (wrapFn) {
|
|
351
|
-
writer.writeLines(
|
|
352
|
-
`const ${wrapFn} = () => call(${middleware}, ${next}, context);`
|
|
353
|
-
);
|
|
354
|
-
} else {
|
|
355
|
-
writer.writeLines(`return call(${middleware}, ${next}, context);`);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
365
|
function writeRouteEntryHandler(writer, route, verb) {
|
|
359
|
-
var _a;
|
|
366
|
+
var _a, _b, _c, _d;
|
|
360
367
|
const { key, index, page, handler, middleware } = route;
|
|
361
368
|
const len = middleware.length;
|
|
362
369
|
let nextName;
|
|
363
370
|
let currentName;
|
|
364
371
|
let hasBody = false;
|
|
365
372
|
writer.writeLines("");
|
|
366
|
-
if (page) {
|
|
373
|
+
if (page && (verb === "get" || verb === "head")) {
|
|
367
374
|
writer.writeBlockStart(
|
|
368
|
-
`export
|
|
375
|
+
`export function ${verb}${index}(context, buildInput) {`
|
|
369
376
|
);
|
|
370
377
|
} else {
|
|
371
|
-
writer.writeBlockStart(`export
|
|
378
|
+
writer.writeBlockStart(`export function ${verb}${index}(context) {`);
|
|
372
379
|
}
|
|
373
380
|
const continuations = writer.branch("cont");
|
|
374
|
-
if (page && verb === "get") {
|
|
381
|
+
if (page && (verb === "get" || verb === "head")) {
|
|
375
382
|
currentName = "__page";
|
|
376
383
|
if ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes(verb)) {
|
|
377
384
|
const name = `${verb}Handler`;
|
|
378
|
-
|
|
385
|
+
continuations.writeLines(
|
|
386
|
+
`const ${currentName} = () => pageResponse(page, buildInput());`
|
|
387
|
+
);
|
|
379
388
|
if (len) {
|
|
380
389
|
nextName = currentName;
|
|
381
390
|
currentName = `__${name}`;
|
|
382
|
-
|
|
391
|
+
continuations.writeLines(
|
|
392
|
+
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
393
|
+
);
|
|
383
394
|
} else {
|
|
384
|
-
|
|
395
|
+
if (verb === "head") {
|
|
396
|
+
writer.writeLines(
|
|
397
|
+
`return stripResponseBody(call(${name}, ${currentName}, context));`
|
|
398
|
+
);
|
|
399
|
+
} else {
|
|
400
|
+
writer.writeLines(`return call(${name}, ${currentName}, context);`);
|
|
401
|
+
}
|
|
385
402
|
hasBody = true;
|
|
386
403
|
}
|
|
404
|
+
} else if (verb === "head") {
|
|
405
|
+
writer.writeLines(
|
|
406
|
+
`return stripResponseBody(get${index}(context, buildInput));`
|
|
407
|
+
);
|
|
408
|
+
hasBody = true;
|
|
387
409
|
} else if (len) {
|
|
388
|
-
|
|
410
|
+
continuations.writeLines(
|
|
411
|
+
`const ${currentName} = () => pageResponse(page, buildInput());`
|
|
412
|
+
);
|
|
389
413
|
nextName = currentName;
|
|
390
414
|
} else {
|
|
391
|
-
|
|
415
|
+
writer.writeLines(`return pageResponse(page, buildInput());`);
|
|
392
416
|
hasBody = true;
|
|
393
417
|
}
|
|
394
|
-
} else if (handler) {
|
|
418
|
+
} else if ((_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes(verb)) {
|
|
395
419
|
const name = `${verb}Handler`;
|
|
396
420
|
currentName = `__${name}`;
|
|
397
421
|
nextName = "noContent";
|
|
398
422
|
if (len) {
|
|
399
|
-
|
|
423
|
+
continuations.writeLines(
|
|
424
|
+
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
425
|
+
);
|
|
400
426
|
} else {
|
|
401
|
-
|
|
427
|
+
if (verb === "head") {
|
|
428
|
+
writer.writeLines(
|
|
429
|
+
`return stripResponseBody(call(${name}, ${nextName}, context));`
|
|
430
|
+
);
|
|
431
|
+
} else {
|
|
432
|
+
writer.writeLines(`return call(${name}, ${nextName}, context);`);
|
|
433
|
+
}
|
|
402
434
|
hasBody = true;
|
|
403
435
|
}
|
|
436
|
+
} else if (verb === "head" && ((_d = (_c = route.handler) == null ? void 0 : _c.verbs) == null ? void 0 : _d.includes("get"))) {
|
|
437
|
+
writer.writeLines(`return stripResponseBody(get${index}(context));`);
|
|
438
|
+
hasBody = true;
|
|
404
439
|
} else {
|
|
405
440
|
throw new Error(`Route ${key} has no handler for ${verb} requests`);
|
|
406
441
|
}
|
|
@@ -411,7 +446,17 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
411
446
|
const name = `mware${id}`;
|
|
412
447
|
nextName = currentName;
|
|
413
448
|
currentName = i ? `__${name}` : "";
|
|
414
|
-
|
|
449
|
+
if (currentName) {
|
|
450
|
+
continuations.writeLines(
|
|
451
|
+
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
452
|
+
);
|
|
453
|
+
} else if (verb === "head") {
|
|
454
|
+
continuations.writeLines(
|
|
455
|
+
`return stripResponseBody(call(${name}, ${nextName}, context));`
|
|
456
|
+
);
|
|
457
|
+
} else {
|
|
458
|
+
continuations.writeLines(`return call(${name}, ${nextName}, context);`);
|
|
459
|
+
}
|
|
415
460
|
}
|
|
416
461
|
}
|
|
417
462
|
continuations.join();
|
|
@@ -1308,7 +1353,7 @@ async function buildRoutes(sources) {
|
|
|
1308
1353
|
filePath: path6,
|
|
1309
1354
|
relativePath,
|
|
1310
1355
|
importPath: `${importPrefix}/${relativePath}`,
|
|
1311
|
-
verbs: type === RoutableFileTypes.Page ? ["get"] : void 0
|
|
1356
|
+
verbs: type === RoutableFileTypes.Page ? ["get", "head"] : void 0
|
|
1312
1357
|
};
|
|
1313
1358
|
for (const dir of dirs) {
|
|
1314
1359
|
dir.addFile(file);
|
|
@@ -1550,17 +1595,16 @@ import format from "human-format";
|
|
|
1550
1595
|
import kleur2 from "kleur";
|
|
1551
1596
|
var HttpVerbColors = {
|
|
1552
1597
|
get: kleur2.green,
|
|
1598
|
+
head: kleur2.dim().green,
|
|
1553
1599
|
post: kleur2.magenta,
|
|
1554
1600
|
put: kleur2.cyan,
|
|
1555
1601
|
delete: kleur2.red,
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
var HttpVerbOrder = {
|
|
1559
|
-
get: 0,
|
|
1560
|
-
post: 1,
|
|
1561
|
-
put: 2,
|
|
1562
|
-
delete: 3
|
|
1602
|
+
patch: kleur2.yellow,
|
|
1603
|
+
options: kleur2.grey
|
|
1563
1604
|
};
|
|
1605
|
+
function verbColor(verb) {
|
|
1606
|
+
return verb in HttpVerbColors ? HttpVerbColors[verb] : kleur2.gray;
|
|
1607
|
+
}
|
|
1564
1608
|
function logRoutesTable(routes, bundle, options) {
|
|
1565
1609
|
function getRouteChunkName(route) {
|
|
1566
1610
|
return options.sanitizeFileName(`${route.entryName}.marko`);
|
|
@@ -1587,23 +1631,27 @@ function logRoutesTable(routes, bundle, options) {
|
|
|
1587
1631
|
});
|
|
1588
1632
|
for (const route of routes.list) {
|
|
1589
1633
|
for (const path6 of route.paths) {
|
|
1590
|
-
const verbs = getVerbs(route)
|
|
1591
|
-
(a, b) => HttpVerbOrder[a] - HttpVerbOrder[b]
|
|
1592
|
-
);
|
|
1634
|
+
const verbs = getVerbs(route, true);
|
|
1593
1635
|
let firstRow = true;
|
|
1594
1636
|
for (const verb of verbs) {
|
|
1595
|
-
let size = "";
|
|
1596
1637
|
const entryType = [];
|
|
1638
|
+
let size = "";
|
|
1639
|
+
let verbCell = verbColor(verb)(verb.toUpperCase());
|
|
1640
|
+
if (verb === "get" && !verbs.includes("head")) {
|
|
1641
|
+
verbCell += kleur2.dim(`,${verbColor(verb)("HEAD")}`);
|
|
1642
|
+
}
|
|
1597
1643
|
if (route.handler) {
|
|
1598
1644
|
entryType.push(kleur2.blue("handler"));
|
|
1599
1645
|
}
|
|
1600
|
-
if (verb === "get"
|
|
1646
|
+
if (route.page && (verb === "get" || verb === "head")) {
|
|
1601
1647
|
entryType.push(kleur2.yellow("page"));
|
|
1602
|
-
|
|
1648
|
+
if (verb === "get") {
|
|
1649
|
+
size = prettySize(
|
|
1650
|
+
computeRouteSize(getRouteChunkName(route), bundle)
|
|
1651
|
+
);
|
|
1652
|
+
}
|
|
1603
1653
|
}
|
|
1604
|
-
const row = [
|
|
1605
|
-
kleur2.bold(HttpVerbColors[verb](verb.toUpperCase()))
|
|
1606
|
-
];
|
|
1654
|
+
const row = [verbCell];
|
|
1607
1655
|
if (verbs.length === 1 || firstRow) {
|
|
1608
1656
|
row.push({ rowSpan: verbs.length, content: prettyPath(path6.path) });
|
|
1609
1657
|
firstRow = false;
|
|
@@ -2139,7 +2187,6 @@ function markoRun(opts = {}) {
|
|
|
2139
2187
|
},
|
|
2140
2188
|
async resolveId(importee, importer) {
|
|
2141
2189
|
if (importee === "@marko/run/router") {
|
|
2142
|
-
console.log("plugin resolveId router");
|
|
2143
2190
|
return path4.resolve(root, ROUTER_FILENAME);
|
|
2144
2191
|
} else if (importee.endsWith(".marko") && importee.includes(relativeEntryFilesDirPosix)) {
|
|
2145
2192
|
if (!importee.startsWith(root)) {
|
|
@@ -30,7 +30,9 @@ __export(internal_exports, {
|
|
|
30
30
|
notHandled: () => notHandled,
|
|
31
31
|
notMatched: () => notMatched,
|
|
32
32
|
pageResponse: () => pageResponse,
|
|
33
|
-
passthrough: () => passthrough
|
|
33
|
+
passthrough: () => passthrough,
|
|
34
|
+
stripResponseBody: () => stripResponseBody,
|
|
35
|
+
stripResponseBodySync: () => stripResponseBodySync
|
|
34
36
|
});
|
|
35
37
|
module.exports = __toCommonJS(internal_exports);
|
|
36
38
|
|
|
@@ -160,6 +162,12 @@ function normalize(obj) {
|
|
|
160
162
|
}
|
|
161
163
|
return passthrough;
|
|
162
164
|
}
|
|
165
|
+
function stripResponseBodySync(response) {
|
|
166
|
+
return response.body ? new Response(null, response) : response;
|
|
167
|
+
}
|
|
168
|
+
function stripResponseBody(response) {
|
|
169
|
+
return "then" in response ? response.then(stripResponseBodySync) : stripResponseBodySync(response);
|
|
170
|
+
}
|
|
163
171
|
function passthrough() {
|
|
164
172
|
}
|
|
165
173
|
function noContent() {
|
|
@@ -185,5 +193,7 @@ function notMatched() {
|
|
|
185
193
|
notHandled,
|
|
186
194
|
notMatched,
|
|
187
195
|
pageResponse,
|
|
188
|
-
passthrough
|
|
196
|
+
passthrough,
|
|
197
|
+
stripResponseBody,
|
|
198
|
+
stripResponseBodySync
|
|
189
199
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyRoute, Context, InputObject, MultiRouteContext, NextFunction, Platform, RouteHandler } from "./types";
|
|
1
|
+
import type { AnyRoute, Awaitable, Context, InputObject, MultiRouteContext, NextFunction, Platform, RouteHandler } from "./types";
|
|
2
2
|
export declare function pageResponse(template: any, input: Record<PropertyKey, unknown>): Response;
|
|
3
3
|
export declare const NotHandled: typeof MarkoRun.NotHandled;
|
|
4
4
|
export declare const NotMatched: typeof MarkoRun.NotMatched;
|
|
@@ -6,6 +6,8 @@ export declare function createContext<TRoute extends AnyRoute>(route: TRoute | u
|
|
|
6
6
|
export declare function call<TRoute extends AnyRoute>(handler: RouteHandler<TRoute>, next: NextFunction, context: MultiRouteContext<TRoute>): Promise<Response>;
|
|
7
7
|
export declare function compose(handlers: RouteHandler[]): RouteHandler;
|
|
8
8
|
export declare function normalize(obj: RouteHandler | RouteHandler[] | Promise<RouteHandler | RouteHandler[]>): RouteHandler;
|
|
9
|
+
export declare function stripResponseBodySync(response: Response): Response;
|
|
10
|
+
export declare function stripResponseBody(response: Awaitable<Response>): Awaitable<Response>;
|
|
9
11
|
export declare function passthrough(): void;
|
|
10
12
|
export declare function noContent(): Response;
|
|
11
13
|
export declare function notHandled(): void;
|
package/dist/runtime/internal.js
CHANGED
|
@@ -120,6 +120,12 @@ function normalize(obj) {
|
|
|
120
120
|
}
|
|
121
121
|
return passthrough;
|
|
122
122
|
}
|
|
123
|
+
function stripResponseBodySync(response) {
|
|
124
|
+
return response.body ? new Response(null, response) : response;
|
|
125
|
+
}
|
|
126
|
+
function stripResponseBody(response) {
|
|
127
|
+
return "then" in response ? response.then(stripResponseBodySync) : stripResponseBodySync(response);
|
|
128
|
+
}
|
|
123
129
|
function passthrough() {
|
|
124
130
|
}
|
|
125
131
|
function noContent() {
|
|
@@ -144,5 +150,7 @@ export {
|
|
|
144
150
|
notHandled,
|
|
145
151
|
notMatched,
|
|
146
152
|
pageResponse,
|
|
147
|
-
passthrough
|
|
153
|
+
passthrough,
|
|
154
|
+
stripResponseBody,
|
|
155
|
+
stripResponseBodySync
|
|
148
156
|
};
|
package/dist/runtime/types.d.ts
CHANGED
package/dist/vite/constants.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
type ValuesOf<T> = T[keyof T];
|
|
2
2
|
export declare const markoRunFilePrefix = "__marko-run__";
|
|
3
3
|
export declare const virtualFilePrefix = "virtual:marko-run";
|
|
4
|
-
export declare const httpVerbs: readonly ["get", "post", "put", "delete"];
|
|
4
|
+
export declare const httpVerbs: readonly ["get", "head", "post", "put", "delete", "patch", "options"];
|
|
5
5
|
export declare const serverEntryQuery = "?marko-server-entry";
|
|
6
6
|
export declare const browserEntryQuery = "?marko-browser-entry";
|
|
7
7
|
export declare const RoutableFileTypes: {
|
package/dist/vite/index.cjs
CHANGED
|
@@ -97,7 +97,15 @@ var import_path = __toESM(require("path"), 1);
|
|
|
97
97
|
// src/vite/constants.ts
|
|
98
98
|
var markoRunFilePrefix = "__marko-run__";
|
|
99
99
|
var virtualFilePrefix = "virtual:marko-run";
|
|
100
|
-
var httpVerbs = [
|
|
100
|
+
var httpVerbs = [
|
|
101
|
+
"get",
|
|
102
|
+
"head",
|
|
103
|
+
"post",
|
|
104
|
+
"put",
|
|
105
|
+
"delete",
|
|
106
|
+
"patch",
|
|
107
|
+
"options"
|
|
108
|
+
];
|
|
101
109
|
var serverEntryQuery = "?marko-server-entry";
|
|
102
110
|
var RoutableFileTypes = {
|
|
103
111
|
Page: "page",
|
|
@@ -110,17 +118,27 @@ var RoutableFileTypes = {
|
|
|
110
118
|
};
|
|
111
119
|
|
|
112
120
|
// src/vite/utils/route.ts
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
var httpVerbOrder = httpVerbs.reduce(
|
|
122
|
+
(order, verb, index) => {
|
|
123
|
+
order[verb] = index;
|
|
124
|
+
return order;
|
|
125
|
+
},
|
|
126
|
+
{}
|
|
127
|
+
);
|
|
128
|
+
function getVerbs(route, noAutoHead) {
|
|
129
|
+
var _a;
|
|
130
|
+
const verbs = new Set((_a = route.handler) == null ? void 0 : _a.verbs);
|
|
131
|
+
if (route.page) {
|
|
132
|
+
verbs.add("get");
|
|
118
133
|
}
|
|
119
|
-
|
|
134
|
+
if (!noAutoHead && verbs.has("get")) {
|
|
135
|
+
verbs.add("head");
|
|
136
|
+
}
|
|
137
|
+
return [...verbs].sort((a, b) => httpVerbOrder[a] - httpVerbOrder[b]);
|
|
120
138
|
}
|
|
121
139
|
function hasVerb(route, verb) {
|
|
122
140
|
var _a, _b;
|
|
123
|
-
return verb === "get" && route.page || ((_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb));
|
|
141
|
+
return verb === "get" && !!route.page || ((_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb)) || verb === "head" && hasVerb(route, "get");
|
|
124
142
|
}
|
|
125
143
|
|
|
126
144
|
// src/vite/codegen/writer.ts
|
|
@@ -324,12 +342,15 @@ function renderRouteEntry(route, entriesDir) {
|
|
|
324
342
|
if (handler || middleware.length) {
|
|
325
343
|
runtimeImports.push("call");
|
|
326
344
|
}
|
|
327
|
-
if (!page || verbs.
|
|
345
|
+
if (!page || verbs.some((verb) => verb !== "get" && verb !== "head")) {
|
|
328
346
|
runtimeImports.push("noContent");
|
|
329
347
|
}
|
|
330
348
|
if (page) {
|
|
331
349
|
runtimeImports.push("pageResponse");
|
|
332
350
|
}
|
|
351
|
+
if (verbs.includes("head")) {
|
|
352
|
+
runtimeImports.push("stripResponseBody");
|
|
353
|
+
}
|
|
333
354
|
if (runtimeImports.length) {
|
|
334
355
|
imports.writeLines(
|
|
335
356
|
`import { ${runtimeImports.join(
|
|
@@ -373,66 +394,80 @@ function renderRouteEntry(route, entriesDir) {
|
|
|
373
394
|
}
|
|
374
395
|
return writer.end();
|
|
375
396
|
}
|
|
376
|
-
function writePageResponse(writer, wrapFn) {
|
|
377
|
-
writer.writeLines(
|
|
378
|
-
`${wrapFn ? `const ${wrapFn} = () =>` : `return`} pageResponse(page, buildInput());`
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
function writeMiddleware(writer, middleware, next, wrapFn) {
|
|
382
|
-
if (wrapFn) {
|
|
383
|
-
writer.writeLines(
|
|
384
|
-
`const ${wrapFn} = () => call(${middleware}, ${next}, context);`
|
|
385
|
-
);
|
|
386
|
-
} else {
|
|
387
|
-
writer.writeLines(`return call(${middleware}, ${next}, context);`);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
397
|
function writeRouteEntryHandler(writer, route, verb) {
|
|
391
|
-
var _a;
|
|
398
|
+
var _a, _b, _c, _d;
|
|
392
399
|
const { key, index, page, handler, middleware } = route;
|
|
393
400
|
const len = middleware.length;
|
|
394
401
|
let nextName;
|
|
395
402
|
let currentName;
|
|
396
403
|
let hasBody = false;
|
|
397
404
|
writer.writeLines("");
|
|
398
|
-
if (page) {
|
|
405
|
+
if (page && (verb === "get" || verb === "head")) {
|
|
399
406
|
writer.writeBlockStart(
|
|
400
|
-
`export
|
|
407
|
+
`export function ${verb}${index}(context, buildInput) {`
|
|
401
408
|
);
|
|
402
409
|
} else {
|
|
403
|
-
writer.writeBlockStart(`export
|
|
410
|
+
writer.writeBlockStart(`export function ${verb}${index}(context) {`);
|
|
404
411
|
}
|
|
405
412
|
const continuations = writer.branch("cont");
|
|
406
|
-
if (page && verb === "get") {
|
|
413
|
+
if (page && (verb === "get" || verb === "head")) {
|
|
407
414
|
currentName = "__page";
|
|
408
415
|
if ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes(verb)) {
|
|
409
416
|
const name = `${verb}Handler`;
|
|
410
|
-
|
|
417
|
+
continuations.writeLines(
|
|
418
|
+
`const ${currentName} = () => pageResponse(page, buildInput());`
|
|
419
|
+
);
|
|
411
420
|
if (len) {
|
|
412
421
|
nextName = currentName;
|
|
413
422
|
currentName = `__${name}`;
|
|
414
|
-
|
|
423
|
+
continuations.writeLines(
|
|
424
|
+
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
425
|
+
);
|
|
415
426
|
} else {
|
|
416
|
-
|
|
427
|
+
if (verb === "head") {
|
|
428
|
+
writer.writeLines(
|
|
429
|
+
`return stripResponseBody(call(${name}, ${currentName}, context));`
|
|
430
|
+
);
|
|
431
|
+
} else {
|
|
432
|
+
writer.writeLines(`return call(${name}, ${currentName}, context);`);
|
|
433
|
+
}
|
|
417
434
|
hasBody = true;
|
|
418
435
|
}
|
|
436
|
+
} else if (verb === "head") {
|
|
437
|
+
writer.writeLines(
|
|
438
|
+
`return stripResponseBody(get${index}(context, buildInput));`
|
|
439
|
+
);
|
|
440
|
+
hasBody = true;
|
|
419
441
|
} else if (len) {
|
|
420
|
-
|
|
442
|
+
continuations.writeLines(
|
|
443
|
+
`const ${currentName} = () => pageResponse(page, buildInput());`
|
|
444
|
+
);
|
|
421
445
|
nextName = currentName;
|
|
422
446
|
} else {
|
|
423
|
-
|
|
447
|
+
writer.writeLines(`return pageResponse(page, buildInput());`);
|
|
424
448
|
hasBody = true;
|
|
425
449
|
}
|
|
426
|
-
} else if (handler) {
|
|
450
|
+
} else if ((_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes(verb)) {
|
|
427
451
|
const name = `${verb}Handler`;
|
|
428
452
|
currentName = `__${name}`;
|
|
429
453
|
nextName = "noContent";
|
|
430
454
|
if (len) {
|
|
431
|
-
|
|
455
|
+
continuations.writeLines(
|
|
456
|
+
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
457
|
+
);
|
|
432
458
|
} else {
|
|
433
|
-
|
|
459
|
+
if (verb === "head") {
|
|
460
|
+
writer.writeLines(
|
|
461
|
+
`return stripResponseBody(call(${name}, ${nextName}, context));`
|
|
462
|
+
);
|
|
463
|
+
} else {
|
|
464
|
+
writer.writeLines(`return call(${name}, ${nextName}, context);`);
|
|
465
|
+
}
|
|
434
466
|
hasBody = true;
|
|
435
467
|
}
|
|
468
|
+
} else if (verb === "head" && ((_d = (_c = route.handler) == null ? void 0 : _c.verbs) == null ? void 0 : _d.includes("get"))) {
|
|
469
|
+
writer.writeLines(`return stripResponseBody(get${index}(context));`);
|
|
470
|
+
hasBody = true;
|
|
436
471
|
} else {
|
|
437
472
|
throw new Error(`Route ${key} has no handler for ${verb} requests`);
|
|
438
473
|
}
|
|
@@ -443,7 +478,17 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
443
478
|
const name = `mware${id}`;
|
|
444
479
|
nextName = currentName;
|
|
445
480
|
currentName = i ? `__${name}` : "";
|
|
446
|
-
|
|
481
|
+
if (currentName) {
|
|
482
|
+
continuations.writeLines(
|
|
483
|
+
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
484
|
+
);
|
|
485
|
+
} else if (verb === "head") {
|
|
486
|
+
continuations.writeLines(
|
|
487
|
+
`return stripResponseBody(call(${name}, ${nextName}, context));`
|
|
488
|
+
);
|
|
489
|
+
} else {
|
|
490
|
+
continuations.writeLines(`return call(${name}, ${nextName}, context);`);
|
|
491
|
+
}
|
|
447
492
|
}
|
|
448
493
|
}
|
|
449
494
|
continuations.join();
|
|
@@ -1340,7 +1385,7 @@ async function buildRoutes(sources) {
|
|
|
1340
1385
|
filePath: path5,
|
|
1341
1386
|
relativePath,
|
|
1342
1387
|
importPath: `${importPrefix}/${relativePath}`,
|
|
1343
|
-
verbs: type === RoutableFileTypes.Page ? ["get"] : void 0
|
|
1388
|
+
verbs: type === RoutableFileTypes.Page ? ["get", "head"] : void 0
|
|
1344
1389
|
};
|
|
1345
1390
|
for (const dir of dirs) {
|
|
1346
1391
|
dir.addFile(file);
|
|
@@ -1581,17 +1626,16 @@ var import_human_format = __toESM(require("human-format"), 1);
|
|
|
1581
1626
|
var import_kleur2 = __toESM(require("kleur"), 1);
|
|
1582
1627
|
var HttpVerbColors = {
|
|
1583
1628
|
get: import_kleur2.default.green,
|
|
1629
|
+
head: import_kleur2.default.dim().green,
|
|
1584
1630
|
post: import_kleur2.default.magenta,
|
|
1585
1631
|
put: import_kleur2.default.cyan,
|
|
1586
1632
|
delete: import_kleur2.default.red,
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
var HttpVerbOrder = {
|
|
1590
|
-
get: 0,
|
|
1591
|
-
post: 1,
|
|
1592
|
-
put: 2,
|
|
1593
|
-
delete: 3
|
|
1633
|
+
patch: import_kleur2.default.yellow,
|
|
1634
|
+
options: import_kleur2.default.grey
|
|
1594
1635
|
};
|
|
1636
|
+
function verbColor(verb) {
|
|
1637
|
+
return verb in HttpVerbColors ? HttpVerbColors[verb] : import_kleur2.default.gray;
|
|
1638
|
+
}
|
|
1595
1639
|
function logRoutesTable(routes, bundle, options) {
|
|
1596
1640
|
function getRouteChunkName(route) {
|
|
1597
1641
|
return options.sanitizeFileName(`${route.entryName}.marko`);
|
|
@@ -1618,23 +1662,27 @@ function logRoutesTable(routes, bundle, options) {
|
|
|
1618
1662
|
});
|
|
1619
1663
|
for (const route of routes.list) {
|
|
1620
1664
|
for (const path5 of route.paths) {
|
|
1621
|
-
const verbs = getVerbs(route)
|
|
1622
|
-
(a, b) => HttpVerbOrder[a] - HttpVerbOrder[b]
|
|
1623
|
-
);
|
|
1665
|
+
const verbs = getVerbs(route, true);
|
|
1624
1666
|
let firstRow = true;
|
|
1625
1667
|
for (const verb of verbs) {
|
|
1626
|
-
let size = "";
|
|
1627
1668
|
const entryType = [];
|
|
1669
|
+
let size = "";
|
|
1670
|
+
let verbCell = verbColor(verb)(verb.toUpperCase());
|
|
1671
|
+
if (verb === "get" && !verbs.includes("head")) {
|
|
1672
|
+
verbCell += import_kleur2.default.dim(`,${verbColor(verb)("HEAD")}`);
|
|
1673
|
+
}
|
|
1628
1674
|
if (route.handler) {
|
|
1629
1675
|
entryType.push(import_kleur2.default.blue("handler"));
|
|
1630
1676
|
}
|
|
1631
|
-
if (verb === "get"
|
|
1677
|
+
if (route.page && (verb === "get" || verb === "head")) {
|
|
1632
1678
|
entryType.push(import_kleur2.default.yellow("page"));
|
|
1633
|
-
|
|
1679
|
+
if (verb === "get") {
|
|
1680
|
+
size = prettySize(
|
|
1681
|
+
computeRouteSize(getRouteChunkName(route), bundle)
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1634
1684
|
}
|
|
1635
|
-
const row = [
|
|
1636
|
-
import_kleur2.default.bold(HttpVerbColors[verb](verb.toUpperCase()))
|
|
1637
|
-
];
|
|
1685
|
+
const row = [verbCell];
|
|
1638
1686
|
if (verbs.length === 1 || firstRow) {
|
|
1639
1687
|
row.push({ rowSpan: verbs.length, content: prettyPath(path5.path) });
|
|
1640
1688
|
firstRow = false;
|
|
@@ -2170,7 +2218,6 @@ function markoRun(opts = {}) {
|
|
|
2170
2218
|
},
|
|
2171
2219
|
async resolveId(importee, importer) {
|
|
2172
2220
|
if (importee === "@marko/run/router") {
|
|
2173
|
-
console.log("plugin resolveId router");
|
|
2174
2221
|
return import_path4.default.resolve(root, ROUTER_FILENAME);
|
|
2175
2222
|
} else if (importee.endsWith(".marko") && importee.includes(relativeEntryFilesDirPosix)) {
|
|
2176
2223
|
if (!importee.startsWith(root)) {
|