@marko/run 0.9.7 → 0.11.0-rc.1
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 +7 -6
- package/dist/adapter/index.js +9 -6
- package/dist/adapter/middleware.cjs +2 -2
- package/dist/adapter/middleware.js +2 -2
- package/dist/adapter/utils.d.ts +4 -4
- package/dist/cli/index.mjs +580 -204
- package/dist/runtime/client.cjs +65 -0
- package/dist/runtime/client.d.ts +1 -0
- package/dist/runtime/client.js +59 -0
- package/dist/runtime/index.d.ts +9 -4
- package/dist/runtime/internal.cjs +285 -38
- package/dist/runtime/internal.d.ts +8 -4
- package/dist/runtime/internal.js +282 -38
- package/dist/runtime/legacy-types.d.ts +60 -0
- package/dist/runtime/namespace.d.ts +2 -1
- package/dist/runtime/router.d.ts +1 -1
- package/dist/runtime/types.d.ts +393 -100
- package/dist/runtime/url-builder.cjs +96 -0
- package/dist/runtime/url-builder.d.ts +6 -0
- package/dist/runtime/url-builder.js +61 -0
- package/dist/vite/codegen/index.d.ts +1 -1
- package/dist/vite/constants.d.ts +3 -3
- package/dist/vite/index.cjs +577 -203
- package/dist/vite/index.js +579 -203
- package/dist/vite/utils/href-replace.d.ts +44 -0
- package/dist/vite/utils/log.d.ts +1 -1
- package/dist/vite/utils/meta-data.d.ts +2 -2
- package/package.json +25 -35
package/dist/cli/index.mjs
CHANGED
|
@@ -33,6 +33,9 @@ import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
|
|
|
33
33
|
import fs3 from "fs";
|
|
34
34
|
import { glob } from "glob";
|
|
35
35
|
import path6 from "path";
|
|
36
|
+
import {
|
|
37
|
+
RolldownMagicString
|
|
38
|
+
} from "rolldown";
|
|
36
39
|
import { fileURLToPath } from "url";
|
|
37
40
|
import {
|
|
38
41
|
buildErrorMessage,
|
|
@@ -81,10 +84,10 @@ var httpVerbs = [
|
|
|
81
84
|
"options"
|
|
82
85
|
];
|
|
83
86
|
var RoutableFileTypes = {
|
|
84
|
-
Page: "page",
|
|
85
|
-
Layout: "layout",
|
|
86
|
-
Handler: "handler",
|
|
87
87
|
Middleware: "middleware",
|
|
88
|
+
Handler: "handler",
|
|
89
|
+
Layout: "layout",
|
|
90
|
+
Page: "page",
|
|
88
91
|
Meta: "meta",
|
|
89
92
|
NotFound: "404",
|
|
90
93
|
Error: "500"
|
|
@@ -273,19 +276,21 @@ function normalizedRelativePath(from, to) {
|
|
|
273
276
|
const relativePath = normalizePath(path2.relative(from, to));
|
|
274
277
|
return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
|
|
275
278
|
}
|
|
276
|
-
function renderRouteTemplate(route, markoApi) {
|
|
279
|
+
function renderRouteTemplate(route, markoApi, dev2 = false) {
|
|
277
280
|
if (!route.page) {
|
|
278
281
|
throw new Error(`Route ${route.key} has no page to render`);
|
|
279
282
|
}
|
|
280
|
-
if (!route.templateFilePath) {
|
|
281
|
-
throw new Error(`Route ${route.key} has no template file path`);
|
|
282
|
-
}
|
|
283
283
|
const writer = createStringWriter();
|
|
284
284
|
if (markoApi) {
|
|
285
285
|
writer.writeLines(`<!-- use ${markoApi} -->
|
|
286
286
|
`);
|
|
287
287
|
}
|
|
288
|
-
writer.branch("imports");
|
|
288
|
+
const importWriter = writer.branch("imports");
|
|
289
|
+
if (dev2) {
|
|
290
|
+
importWriter.writeLines(
|
|
291
|
+
`client import "virtual:marko-run/runtime/client";`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
289
294
|
writer.writeLines("");
|
|
290
295
|
writeEntryTemplateTag(
|
|
291
296
|
writer,
|
|
@@ -333,7 +338,10 @@ function renderRouteEntry(route, rootDir) {
|
|
|
333
338
|
runtimeImports.push("normalizeMeta");
|
|
334
339
|
}
|
|
335
340
|
if (handler || middleware.length) {
|
|
336
|
-
runtimeImports.push("call");
|
|
341
|
+
runtimeImports.push("call", "mergeOptions");
|
|
342
|
+
}
|
|
343
|
+
if (page) {
|
|
344
|
+
runtimeImports.push("render");
|
|
337
345
|
}
|
|
338
346
|
if (!page || verbs.some((verb) => verb !== "get" && verb !== "head")) {
|
|
339
347
|
runtimeImports.push("noContent");
|
|
@@ -372,7 +380,7 @@ function renderRouteEntry(route, rootDir) {
|
|
|
372
380
|
}
|
|
373
381
|
if (page) {
|
|
374
382
|
imports.writeLines(
|
|
375
|
-
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath
|
|
383
|
+
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath)}";`
|
|
376
384
|
);
|
|
377
385
|
}
|
|
378
386
|
if (meta) {
|
|
@@ -390,11 +398,34 @@ function renderRouteEntry(route, rootDir) {
|
|
|
390
398
|
`export const { ${metaVerbsExports} } = normalizeMeta(${metaName});`
|
|
391
399
|
);
|
|
392
400
|
}
|
|
401
|
+
const optionsWriter = writer.branch("options").writeLines("");
|
|
393
402
|
for (const verb of verbs) {
|
|
403
|
+
writeRouteOptions(optionsWriter, route, verb);
|
|
394
404
|
writeRouteEntryHandler(writer, route, verb);
|
|
395
405
|
}
|
|
406
|
+
optionsWriter.join();
|
|
396
407
|
return writer.end();
|
|
397
408
|
}
|
|
409
|
+
function writeRouteOptions(writer, route, verb) {
|
|
410
|
+
var _a, _b;
|
|
411
|
+
const hasHandler = (_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb);
|
|
412
|
+
writer.write(`export const ${verb}${route.index}_options = `);
|
|
413
|
+
if (route.middleware.length || hasHandler) {
|
|
414
|
+
writer.write(`mergeOptions(`);
|
|
415
|
+
let sep = "";
|
|
416
|
+
for (const { id } of route.middleware) {
|
|
417
|
+
writer.write(`${sep}mware${id}`);
|
|
418
|
+
sep = ", ";
|
|
419
|
+
}
|
|
420
|
+
if (hasHandler) {
|
|
421
|
+
writer.write(`${sep}${verb}Handler`);
|
|
422
|
+
}
|
|
423
|
+
writer.write(");");
|
|
424
|
+
} else {
|
|
425
|
+
writer.write("{};");
|
|
426
|
+
}
|
|
427
|
+
writer.write("\n");
|
|
428
|
+
}
|
|
398
429
|
function writeRouteEntryHandler(writer, route, verb) {
|
|
399
430
|
var _a, _b, _c, _d;
|
|
400
431
|
const { key, index, page, handler, middleware } = route;
|
|
@@ -414,13 +445,13 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
414
445
|
if ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes(verb)) {
|
|
415
446
|
const name = `${verb}Handler`;
|
|
416
447
|
continuations.writeLines(
|
|
417
|
-
`const ${currentName} = () =>
|
|
448
|
+
`const ${currentName} = (data) => render(context, page, {}, data);`
|
|
418
449
|
);
|
|
419
450
|
if (len) {
|
|
420
451
|
nextName = currentName;
|
|
421
452
|
currentName = `__${name}`;
|
|
422
453
|
continuations.writeLines(
|
|
423
|
-
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
454
|
+
`const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
|
|
424
455
|
);
|
|
425
456
|
} else {
|
|
426
457
|
if (verb === "head") {
|
|
@@ -437,11 +468,10 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
437
468
|
hasBody = true;
|
|
438
469
|
} else if (len) {
|
|
439
470
|
continuations.writeLines(
|
|
440
|
-
`const ${currentName} = () =>
|
|
471
|
+
`const ${currentName} = (data) => render(context, page, {}, data);`
|
|
441
472
|
);
|
|
442
|
-
nextName = currentName;
|
|
443
473
|
} else {
|
|
444
|
-
writer.writeLines(`return
|
|
474
|
+
writer.writeLines(`return render(context, page, {});`);
|
|
445
475
|
hasBody = true;
|
|
446
476
|
}
|
|
447
477
|
} else if ((_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes(verb)) {
|
|
@@ -450,7 +480,7 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
450
480
|
nextName = "noContent";
|
|
451
481
|
if (len) {
|
|
452
482
|
continuations.writeLines(
|
|
453
|
-
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
483
|
+
`const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
|
|
454
484
|
);
|
|
455
485
|
} else {
|
|
456
486
|
if (verb === "head") {
|
|
@@ -477,7 +507,7 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
477
507
|
currentName = i ? `__${name}` : "";
|
|
478
508
|
if (currentName) {
|
|
479
509
|
continuations.writeLines(
|
|
480
|
-
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
510
|
+
`const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
|
|
481
511
|
);
|
|
482
512
|
} else if (verb === "head") {
|
|
483
513
|
continuations.writeLines(
|
|
@@ -510,6 +540,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
510
540
|
for (const verb of verbs) {
|
|
511
541
|
const verbName = `${verb}${route.index}`;
|
|
512
542
|
routeImports.push(verbName);
|
|
543
|
+
routeImports.push(`${verbName}_options`);
|
|
513
544
|
if (route.meta) {
|
|
514
545
|
routeImports.push(`${verbName}_meta`);
|
|
515
546
|
}
|
|
@@ -520,7 +551,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
520
551
|
}
|
|
521
552
|
for (const route of Object.values(routes.special)) {
|
|
522
553
|
imports.writeLines(
|
|
523
|
-
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath
|
|
554
|
+
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath)}";`
|
|
524
555
|
);
|
|
525
556
|
}
|
|
526
557
|
writer.writeLines(
|
|
@@ -805,10 +836,10 @@ function renderParams(params, pathIndex) {
|
|
|
805
836
|
return result ? result + " }" : "{}";
|
|
806
837
|
}
|
|
807
838
|
function renderMatch(verb, route, path10, pathIndex) {
|
|
808
|
-
const
|
|
839
|
+
const name = `${verb}${route.index}`;
|
|
809
840
|
const params = path10.params ? renderParams(path10.params, pathIndex) : "{}";
|
|
810
|
-
const meta = route.meta ? `${
|
|
811
|
-
return `{ handler: ${
|
|
841
|
+
const meta = route.meta ? `${name}_meta` : "{}";
|
|
842
|
+
return `{ handler: ${name}, path: '${path10.path}', params: ${params}, options: ${name}_options, meta: ${meta} }`;
|
|
812
843
|
}
|
|
813
844
|
function renderMiddleware(middleware, rootDir) {
|
|
814
845
|
const writer = createStringWriter();
|
|
@@ -839,8 +870,14 @@ function stripTsExtension(path10) {
|
|
|
839
870
|
}
|
|
840
871
|
return path10;
|
|
841
872
|
}
|
|
873
|
+
function* routeFileIter(route) {
|
|
874
|
+
yield* route.middleware;
|
|
875
|
+
if (route.handler) yield route.handler;
|
|
876
|
+
yield* route.layouts;
|
|
877
|
+
if (route.page) yield route.page;
|
|
878
|
+
if (route.meta) yield route.meta;
|
|
879
|
+
}
|
|
842
880
|
async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
843
|
-
var _a, _b, _c, _d;
|
|
844
881
|
const writer = createStringWriter();
|
|
845
882
|
writer.writeLines(
|
|
846
883
|
`/*
|
|
@@ -849,10 +886,11 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
|
849
886
|
*/
|
|
850
887
|
`,
|
|
851
888
|
`import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace";`,
|
|
852
|
-
`import type * as
|
|
889
|
+
`import type * as $ from "@marko/run";`,
|
|
890
|
+
""
|
|
853
891
|
);
|
|
854
892
|
const headWriter = writer.branch("head");
|
|
855
|
-
writer.writeLines("
|
|
893
|
+
writer.writeLines("").writeBlockStart(`declare module "@marko/run" {`);
|
|
856
894
|
if (adapter && adapter.typeInfo) {
|
|
857
895
|
const platformType = await adapter.typeInfo(
|
|
858
896
|
(data) => headWriter.write(data)
|
|
@@ -862,139 +900,120 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
|
862
900
|
`);
|
|
863
901
|
}
|
|
864
902
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
let
|
|
873
|
-
if (
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
903
|
+
const fileInfoByType = /* @__PURE__ */ new Map();
|
|
904
|
+
let fileIndex = 1;
|
|
905
|
+
function addFile(file) {
|
|
906
|
+
let group = fileInfoByType.get(file.type);
|
|
907
|
+
if (!group) {
|
|
908
|
+
fileInfoByType.set(file.type, group = /* @__PURE__ */ new Map());
|
|
909
|
+
}
|
|
910
|
+
let info = group.get(file);
|
|
911
|
+
if (!info) {
|
|
912
|
+
info = {
|
|
913
|
+
id: "",
|
|
914
|
+
typeName: null,
|
|
915
|
+
modulePath: stripTsExtension(
|
|
916
|
+
normalizedRelativePath(outDir, file.filePath)
|
|
917
|
+
),
|
|
918
|
+
routes: /* @__PURE__ */ new Set()
|
|
919
|
+
};
|
|
920
|
+
switch (file.type) {
|
|
921
|
+
case RoutableFileTypes.Middleware:
|
|
922
|
+
info.id = `M${group.size + 1}`;
|
|
923
|
+
info.typeName = "Middleware";
|
|
924
|
+
break;
|
|
925
|
+
case RoutableFileTypes.Handler:
|
|
926
|
+
info.id = `H${group.size + 1}`;
|
|
927
|
+
info.typeName = "Handler";
|
|
928
|
+
break;
|
|
929
|
+
case RoutableFileTypes.Meta:
|
|
930
|
+
info.id = `D${group.size + 1}`;
|
|
931
|
+
info.typeName = "Meta";
|
|
932
|
+
break;
|
|
933
|
+
case RoutableFileTypes.Layout:
|
|
934
|
+
info.id = `L${group.size + 1}`;
|
|
935
|
+
info.typeName = "Template";
|
|
936
|
+
break;
|
|
937
|
+
case RoutableFileTypes.Page:
|
|
938
|
+
info.id = `P${group.size + 1}`;
|
|
939
|
+
info.typeName = "Template";
|
|
940
|
+
break;
|
|
941
|
+
default:
|
|
942
|
+
info.id = `F${fileIndex++}`;
|
|
943
|
+
break;
|
|
905
944
|
}
|
|
945
|
+
group.set(file, info);
|
|
906
946
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
947
|
+
return info;
|
|
948
|
+
}
|
|
949
|
+
writer.writeBlockStart(`interface App extends $.DefineRoutes<{`);
|
|
950
|
+
for (const route of routes.list) {
|
|
951
|
+
let routeDefFiles = "";
|
|
952
|
+
for (const file of routeFileIter(route)) {
|
|
953
|
+
const fileInfo = addFile(file);
|
|
954
|
+
fileInfo.routes.add(route);
|
|
955
|
+
if (routeDefFiles) {
|
|
956
|
+
routeDefFiles += ", ";
|
|
917
957
|
}
|
|
958
|
+
routeDefFiles += fileInfo.id;
|
|
918
959
|
}
|
|
960
|
+
writer.writeLines(`"${route.path.path}": [${routeDefFiles}];`);
|
|
919
961
|
}
|
|
920
962
|
for (const special of Object.values(routes.special)) {
|
|
921
|
-
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
const
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
const routeType = `Run.Routes[${types.join(" | ")}]`;
|
|
933
|
-
switch (file.type) {
|
|
934
|
-
case RoutableFileTypes.Handler:
|
|
935
|
-
writeModuleDeclaration(handlerWriter, modulePath, routeType);
|
|
936
|
-
break;
|
|
937
|
-
case RoutableFileTypes.Middleware:
|
|
938
|
-
writeModuleDeclaration(middlewareWriter, modulePath, routeType);
|
|
939
|
-
break;
|
|
940
|
-
case RoutableFileTypes.Page:
|
|
941
|
-
writeModuleDeclaration(pageWriter, modulePath, routeType);
|
|
942
|
-
break;
|
|
943
|
-
case RoutableFileTypes.Layout:
|
|
944
|
-
writeModuleDeclaration(
|
|
945
|
-
layoutWriter,
|
|
946
|
-
modulePath,
|
|
947
|
-
routeType,
|
|
948
|
-
`
|
|
949
|
-
export interface Input extends Run.LayoutInput<typeof import("${modulePath}")> {}`
|
|
963
|
+
addFile(special.page);
|
|
964
|
+
}
|
|
965
|
+
writer.writeBlockEnd(`}> {}`).writeBlockEnd(`}`);
|
|
966
|
+
for (const fileType of Object.values(RoutableFileTypes)) {
|
|
967
|
+
const fileGroup = fileInfoByType.get(fileType);
|
|
968
|
+
if (!fileGroup) continue;
|
|
969
|
+
for (const info of fileGroup.values()) {
|
|
970
|
+
writer.writeLines("");
|
|
971
|
+
if (info.typeName) {
|
|
972
|
+
writer.writeLines(
|
|
973
|
+
`type ${info.id} = $.${info.typeName}<"${info.id}", typeof import("${info.modulePath}")>;`
|
|
950
974
|
);
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
975
|
+
}
|
|
976
|
+
if (fileType === RoutableFileTypes.Meta) continue;
|
|
977
|
+
writer.write(`declare module "${info.modulePath}" {`);
|
|
978
|
+
switch (fileType) {
|
|
979
|
+
case RoutableFileTypes.Layout:
|
|
980
|
+
writer.write(`
|
|
981
|
+
interface Input extends $.LayoutInput<${info.id}> {}`);
|
|
982
|
+
break;
|
|
983
|
+
case RoutableFileTypes.Error:
|
|
984
|
+
writer.write(`
|
|
958
985
|
export interface Input {
|
|
959
986
|
error: unknown;
|
|
960
|
-
}`
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
handlerWriter.join();
|
|
969
|
-
middlewareWriter.join();
|
|
970
|
-
pageWriter.join();
|
|
971
|
-
layoutWriter.join();
|
|
972
|
-
return writer.end();
|
|
973
|
-
}
|
|
974
|
-
function writeModuleDeclaration(writer, name, routeType, moduleTypes) {
|
|
975
|
-
writer.writeLines("").write(`declare module "${name}" {`);
|
|
976
|
-
if (moduleTypes) {
|
|
977
|
-
writer.write(moduleTypes);
|
|
987
|
+
}`);
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
990
|
+
if (info.typeName) {
|
|
991
|
+
writer.write(`
|
|
992
|
+
const Run: $.Namespace<${info.id}>;
|
|
993
|
+
namespace Run {
|
|
994
|
+
type Context = $.ContextForFile<${info.id}>${info.typeName === "Template" ? " & Marko.Global" : ""};
|
|
978
995
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
996
|
+
`);
|
|
997
|
+
}
|
|
998
|
+
writer.write(`
|
|
999
|
+
/** @deprecated use \`Run\` namespace instead */
|
|
982
1000
|
namespace MarkoRun {
|
|
983
1001
|
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
|
|
984
|
-
export type Route = ${
|
|
985
|
-
export type Context =
|
|
986
|
-
export type Handler =
|
|
987
|
-
|
|
1002
|
+
export type Route = ${info.routes.size ? `$.Routes["${[...info.routes].map((route) => route.path.path).join('" | "')}"]` : "globalThis.MarkoRun.Route"};
|
|
1003
|
+
export type Context = ${info.modulePath.endsWith(".marko") ? "Run.Context" : "$.MultiRouteContext<Route>"};
|
|
1004
|
+
export type Handler = $.HandlerLike<Route>;`);
|
|
1005
|
+
for (const verb of httpVerbs) {
|
|
1006
|
+
writer.write(`
|
|
1007
|
+
export type ${verb.toUpperCase()} = $.HandlerLike<Route, "${verb.toUpperCase()}">;`);
|
|
1008
|
+
}
|
|
988
1009
|
writer.write(`
|
|
989
|
-
export type ${verb.toUpperCase()} = Run.HandlerLike<Route, "${verb.toUpperCase()}">;`);
|
|
990
|
-
}
|
|
991
|
-
writer.write(`
|
|
992
|
-
/** @deprecated use \`((context, next) => { ... }) satisfies MarkoRun.Handler\` instead */
|
|
993
|
-
export const route: Run.HandlerTypeFn<Route>;
|
|
994
1010
|
}`);
|
|
995
|
-
|
|
996
|
-
writer.writeLines(`
|
|
1011
|
+
writer.writeLines(`
|
|
997
1012
|
}`);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
headWriter.join();
|
|
1016
|
+
return writer.end();
|
|
998
1017
|
}
|
|
999
1018
|
function createRouteTrie(routes) {
|
|
1000
1019
|
const root = {
|
|
@@ -1479,7 +1498,7 @@ async function buildRoutes(sources, outDir) {
|
|
|
1479
1498
|
middleware: [],
|
|
1480
1499
|
layouts: [...currentLayouts],
|
|
1481
1500
|
page: file,
|
|
1482
|
-
templateFilePath:
|
|
1501
|
+
templateFilePath: path3.join(outDir, `${type}.marko`)
|
|
1483
1502
|
};
|
|
1484
1503
|
layoutsUsed = true;
|
|
1485
1504
|
}
|
|
@@ -1512,7 +1531,7 @@ async function buildRoutes(sources, outDir) {
|
|
|
1512
1531
|
meta: dir.files.get(RoutableFileTypes.Meta),
|
|
1513
1532
|
page,
|
|
1514
1533
|
handler,
|
|
1515
|
-
templateFilePath: page &&
|
|
1534
|
+
templateFilePath: page && path3.join(outDir, key + ".marko")
|
|
1516
1535
|
});
|
|
1517
1536
|
layoutsUsed = !!page;
|
|
1518
1537
|
for (const middleware2 of currentMiddleware) {
|
|
@@ -1551,7 +1570,7 @@ function createFSWalker(dir) {
|
|
|
1551
1570
|
onDir,
|
|
1552
1571
|
maxDepth = 50
|
|
1553
1572
|
}) {
|
|
1554
|
-
async function
|
|
1573
|
+
async function walk2(dir2, depth) {
|
|
1555
1574
|
const onExit = onEnter == null ? void 0 : onEnter(dir2);
|
|
1556
1575
|
if (onExit !== false) {
|
|
1557
1576
|
const dirs = [];
|
|
@@ -1572,13 +1591,13 @@ function createFSWalker(dir) {
|
|
|
1572
1591
|
}
|
|
1573
1592
|
if ((onDir == null ? void 0 : onDir()) !== false && --depth > 0) {
|
|
1574
1593
|
for (const entry of dirs) {
|
|
1575
|
-
await
|
|
1594
|
+
await walk2(entry, depth);
|
|
1576
1595
|
}
|
|
1577
1596
|
}
|
|
1578
1597
|
onExit == null ? void 0 : onExit();
|
|
1579
1598
|
}
|
|
1580
1599
|
}
|
|
1581
|
-
await
|
|
1600
|
+
await walk2(
|
|
1582
1601
|
{
|
|
1583
1602
|
path: dir,
|
|
1584
1603
|
name: path4.basename(dir)
|
|
@@ -1636,6 +1655,304 @@ var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, Plug
|
|
|
1636
1655
|
var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
|
|
1637
1656
|
var setExternalAdapterOptions = (viteConfig, value) => setConfig(viteConfig, AdapterConfigKey, value);
|
|
1638
1657
|
|
|
1658
|
+
// src/runtime/url-builder.ts
|
|
1659
|
+
var encode = encodeURIComponent;
|
|
1660
|
+
var pathParts = /* @__PURE__ */ new Map();
|
|
1661
|
+
function parsePathParts(path10) {
|
|
1662
|
+
let parts = pathParts.get(path10);
|
|
1663
|
+
if (!parts) {
|
|
1664
|
+
let lastEnd = 0;
|
|
1665
|
+
let paramStart;
|
|
1666
|
+
pathParts.set(path10, parts = [[]]);
|
|
1667
|
+
while (lastEnd >= 0 && (paramStart = path10.indexOf("/$", lastEnd) + 1)) {
|
|
1668
|
+
parts.push(path10.slice(lastEnd, paramStart++));
|
|
1669
|
+
if (path10.charAt(paramStart) === "$") {
|
|
1670
|
+
paramStart++;
|
|
1671
|
+
lastEnd = -1;
|
|
1672
|
+
} else {
|
|
1673
|
+
lastEnd = path10.indexOf("/", paramStart);
|
|
1674
|
+
}
|
|
1675
|
+
parts[0].push(path10.slice(paramStart, lastEnd < 0 ? void 0 : lastEnd));
|
|
1676
|
+
}
|
|
1677
|
+
parts.push(lastEnd >= 0 ? path10.slice(lastEnd) : "");
|
|
1678
|
+
}
|
|
1679
|
+
return parts;
|
|
1680
|
+
}
|
|
1681
|
+
function joinHref(path10, options) {
|
|
1682
|
+
let result = path10;
|
|
1683
|
+
if (options.search) {
|
|
1684
|
+
const query = "" + new URLSearchParams(options.search);
|
|
1685
|
+
if (query) result += "?" + query;
|
|
1686
|
+
}
|
|
1687
|
+
if (options.hash) result += "#" + encode(options.hash);
|
|
1688
|
+
return result;
|
|
1689
|
+
}
|
|
1690
|
+
function href(path10, ...[options]) {
|
|
1691
|
+
return options ? "params" in options ? ((parts) => href_keys(parts, options, ...parts[0]))(
|
|
1692
|
+
parsePathParts(path10)
|
|
1693
|
+
) : joinHref(path10, options) : path10;
|
|
1694
|
+
}
|
|
1695
|
+
function href_path(strings, ...params) {
|
|
1696
|
+
let i = 0;
|
|
1697
|
+
let j = 0;
|
|
1698
|
+
let result = strings[i++];
|
|
1699
|
+
if (!result || Array.isArray(result)) result = strings[i++];
|
|
1700
|
+
while (i < strings.length) {
|
|
1701
|
+
const param = params[j++];
|
|
1702
|
+
result += (Array.isArray(param) ? param.map(encode).join("/") : encode(param)) + strings[i++];
|
|
1703
|
+
}
|
|
1704
|
+
return result;
|
|
1705
|
+
}
|
|
1706
|
+
function href_values(strings, options, ...params) {
|
|
1707
|
+
return joinHref(href_path(strings, ...params), options);
|
|
1708
|
+
}
|
|
1709
|
+
function href_keys(strings, options, ...keys) {
|
|
1710
|
+
return href_values(strings, options, ...keys.map((k) => options.params[k]));
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// src/vite/utils/href-replace.ts
|
|
1714
|
+
function findHrefReplacements(code, ast) {
|
|
1715
|
+
const replacements = [];
|
|
1716
|
+
walk(ast, (node) => {
|
|
1717
|
+
var _a, _b;
|
|
1718
|
+
if (node.type !== "CallExpression") return;
|
|
1719
|
+
const callee = node.callee;
|
|
1720
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.object.name !== "Run" || callee.property.type !== "Identifier" || callee.property.name !== "href") {
|
|
1721
|
+
return;
|
|
1722
|
+
}
|
|
1723
|
+
const args = node.arguments;
|
|
1724
|
+
if (args.length === 0 || args.length > 2 || args.some((a) => a.type === "SpreadElement")) {
|
|
1725
|
+
return;
|
|
1726
|
+
}
|
|
1727
|
+
const pathString = (_a = tryStaticEval(args[0])) == null ? void 0 : _a.value;
|
|
1728
|
+
if (typeof pathString !== "string") {
|
|
1729
|
+
replacements.push({
|
|
1730
|
+
helper: "href",
|
|
1731
|
+
edits: [{ start: callee.start, end: callee.end, code: "href" }]
|
|
1732
|
+
});
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
if (args.length === 1) {
|
|
1736
|
+
replacements.push({
|
|
1737
|
+
helper: false,
|
|
1738
|
+
edits: [
|
|
1739
|
+
{
|
|
1740
|
+
start: node.start,
|
|
1741
|
+
end: node.end,
|
|
1742
|
+
code: JSON.stringify(pathString)
|
|
1743
|
+
}
|
|
1744
|
+
]
|
|
1745
|
+
});
|
|
1746
|
+
return;
|
|
1747
|
+
}
|
|
1748
|
+
const optionsNode = args[1];
|
|
1749
|
+
const optionsObject = (_b = tryStaticEval(optionsNode)) == null ? void 0 : _b.value;
|
|
1750
|
+
if (optionsObject && typeof optionsObject === "object" && !Array.isArray(optionsObject)) {
|
|
1751
|
+
replacements.push({
|
|
1752
|
+
helper: false,
|
|
1753
|
+
edits: [
|
|
1754
|
+
{
|
|
1755
|
+
start: node.start,
|
|
1756
|
+
end: node.end,
|
|
1757
|
+
code: JSON.stringify(href(pathString, optionsObject))
|
|
1758
|
+
}
|
|
1759
|
+
]
|
|
1760
|
+
});
|
|
1761
|
+
return;
|
|
1762
|
+
}
|
|
1763
|
+
const parsed = parsePathPattern(pathString);
|
|
1764
|
+
if (optionsNode.type === "ObjectExpression") {
|
|
1765
|
+
const params = tryExtractObjectProperty(optionsNode, "params");
|
|
1766
|
+
if (params && parsed.params.every((p) => params.map.has(p))) {
|
|
1767
|
+
const pathPart = buildPathTemplate(code, parsed, params.map);
|
|
1768
|
+
if (params.only) {
|
|
1769
|
+
replacements.push({
|
|
1770
|
+
helper: "href_path",
|
|
1771
|
+
edits: [
|
|
1772
|
+
{
|
|
1773
|
+
start: node.start,
|
|
1774
|
+
end: node.end,
|
|
1775
|
+
code: "href_path`" + pathPart + "`"
|
|
1776
|
+
}
|
|
1777
|
+
]
|
|
1778
|
+
});
|
|
1779
|
+
} else {
|
|
1780
|
+
const props = optionsNode.properties;
|
|
1781
|
+
const remaining = props.filter((_, i) => i !== params.index);
|
|
1782
|
+
if (remaining.length === 1 && remaining[0].type === "SpreadElement") {
|
|
1783
|
+
replacements.push({
|
|
1784
|
+
helper: "href_values",
|
|
1785
|
+
edits: [
|
|
1786
|
+
{
|
|
1787
|
+
start: node.start,
|
|
1788
|
+
end: remaining[0].argument.start,
|
|
1789
|
+
code: "href_values`${"
|
|
1790
|
+
},
|
|
1791
|
+
{
|
|
1792
|
+
start: remaining[0].argument.end,
|
|
1793
|
+
end: node.end,
|
|
1794
|
+
code: "}" + pathPart + "`"
|
|
1795
|
+
}
|
|
1796
|
+
]
|
|
1797
|
+
});
|
|
1798
|
+
} else {
|
|
1799
|
+
replacements.push({
|
|
1800
|
+
helper: "href_values",
|
|
1801
|
+
edits: [
|
|
1802
|
+
{
|
|
1803
|
+
start: node.start,
|
|
1804
|
+
end: optionsNode.start,
|
|
1805
|
+
code: "href_values`${"
|
|
1806
|
+
},
|
|
1807
|
+
{
|
|
1808
|
+
start: optionsNode.end,
|
|
1809
|
+
end: node.end,
|
|
1810
|
+
code: "}" + pathPart + "`"
|
|
1811
|
+
},
|
|
1812
|
+
params.index < props.length - 1 ? {
|
|
1813
|
+
start: props[params.index].start,
|
|
1814
|
+
end: props[params.index + 1].start,
|
|
1815
|
+
code: ""
|
|
1816
|
+
} : {
|
|
1817
|
+
start: props[params.index - 1].end,
|
|
1818
|
+
end: props[params.index].end,
|
|
1819
|
+
code: ""
|
|
1820
|
+
}
|
|
1821
|
+
]
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
replacements.push({
|
|
1829
|
+
helper: "href_keys",
|
|
1830
|
+
edits: [
|
|
1831
|
+
{ start: node.start, end: optionsNode.start, code: "href_keys`${" },
|
|
1832
|
+
{
|
|
1833
|
+
start: optionsNode.end,
|
|
1834
|
+
end: node.end,
|
|
1835
|
+
code: `}${buildPathTemplate(code, parsed)}\``
|
|
1836
|
+
}
|
|
1837
|
+
]
|
|
1838
|
+
});
|
|
1839
|
+
});
|
|
1840
|
+
return replacements;
|
|
1841
|
+
}
|
|
1842
|
+
function walk(node, visitor) {
|
|
1843
|
+
if (!node || typeof node !== "object") return;
|
|
1844
|
+
if (node.type) {
|
|
1845
|
+
visitor(node);
|
|
1846
|
+
}
|
|
1847
|
+
for (const key of Object.keys(node)) {
|
|
1848
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range") {
|
|
1849
|
+
continue;
|
|
1850
|
+
}
|
|
1851
|
+
const child = node[key];
|
|
1852
|
+
if (Array.isArray(child)) {
|
|
1853
|
+
for (const item of child) {
|
|
1854
|
+
if (item && typeof item === "object" && item.type) {
|
|
1855
|
+
walk(item, visitor);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
} else if (child && typeof child === "object" && child.type) {
|
|
1859
|
+
walk(child, visitor);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
function parsePathPattern(path10) {
|
|
1864
|
+
const parts = parsePathParts(path10);
|
|
1865
|
+
return { segments: parts.slice(1), params: parts[0] };
|
|
1866
|
+
}
|
|
1867
|
+
function buildPathTemplate(code, parsed, paramsMap) {
|
|
1868
|
+
let template = "";
|
|
1869
|
+
for (let i = 0; i < parsed.params.length; i++) {
|
|
1870
|
+
template += parsed.segments[i];
|
|
1871
|
+
if (paramsMap) {
|
|
1872
|
+
const paramProp = paramsMap.get(parsed.params[i]);
|
|
1873
|
+
const valueNode = paramProp.shorthand ? paramProp.key : paramProp.value;
|
|
1874
|
+
template += "${" + code.slice(valueNode.start, valueNode.end) + "}";
|
|
1875
|
+
} else {
|
|
1876
|
+
template += '${"' + parsed.params[i] + '"}';
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
if (parsed.segments.length > parsed.params.length) {
|
|
1880
|
+
template += parsed.segments[parsed.segments.length - 1];
|
|
1881
|
+
}
|
|
1882
|
+
return template;
|
|
1883
|
+
}
|
|
1884
|
+
function getStaticKey(prop) {
|
|
1885
|
+
if (prop.computed) return null;
|
|
1886
|
+
if (prop.key.type === "Identifier") return prop.key.name;
|
|
1887
|
+
if (prop.key.type === "Literal" && typeof prop.key.value === "string")
|
|
1888
|
+
return prop.key.value;
|
|
1889
|
+
return null;
|
|
1890
|
+
}
|
|
1891
|
+
function tryStaticEval(node) {
|
|
1892
|
+
switch (node.type) {
|
|
1893
|
+
case "Literal":
|
|
1894
|
+
return { value: node.value };
|
|
1895
|
+
case "TemplateLiteral":
|
|
1896
|
+
return node.expressions.length ? null : { value: node.quasis[0].value.cooked };
|
|
1897
|
+
case "ObjectExpression": {
|
|
1898
|
+
const value = {};
|
|
1899
|
+
for (const prop of node.properties) {
|
|
1900
|
+
if (prop.type === "SpreadElement" || prop.shorthand) return null;
|
|
1901
|
+
const key = getStaticKey(prop);
|
|
1902
|
+
if (!key) return null;
|
|
1903
|
+
const val = tryStaticEval(prop.value);
|
|
1904
|
+
if (!val) return null;
|
|
1905
|
+
value[key] = val.value;
|
|
1906
|
+
}
|
|
1907
|
+
return { value };
|
|
1908
|
+
}
|
|
1909
|
+
case "ArrayExpression": {
|
|
1910
|
+
const value = [];
|
|
1911
|
+
for (const elem of node.elements) {
|
|
1912
|
+
if (!elem || elem.type === "SpreadElement") return null;
|
|
1913
|
+
const val = tryStaticEval(elem);
|
|
1914
|
+
if (!val) return null;
|
|
1915
|
+
value.push(val.value);
|
|
1916
|
+
}
|
|
1917
|
+
return { value };
|
|
1918
|
+
}
|
|
1919
|
+
case "UnaryExpression":
|
|
1920
|
+
if (node.prefix && node.operator === "-") {
|
|
1921
|
+
const arg = tryStaticEval(node.argument);
|
|
1922
|
+
if (arg && typeof arg.value === "number") {
|
|
1923
|
+
return { value: -arg.value };
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
return null;
|
|
1927
|
+
default:
|
|
1928
|
+
return null;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
function tryExtractObjectProperty(obj, propertyName) {
|
|
1932
|
+
const props = obj.properties;
|
|
1933
|
+
for (let i = props.length - 1; i >= 0; i--) {
|
|
1934
|
+
const prop = props[i];
|
|
1935
|
+
if (prop.type === "SpreadElement") return null;
|
|
1936
|
+
if (getStaticKey(prop) !== propertyName) continue;
|
|
1937
|
+
if (prop.value.type !== "ObjectExpression") return null;
|
|
1938
|
+
const map = /* @__PURE__ */ new Map();
|
|
1939
|
+
for (const paramProp of prop.value.properties) {
|
|
1940
|
+
if (paramProp.type === "SpreadElement") return null;
|
|
1941
|
+
const paramKey = getStaticKey(paramProp);
|
|
1942
|
+
if (!paramKey) return null;
|
|
1943
|
+
map.set(paramKey, paramProp);
|
|
1944
|
+
}
|
|
1945
|
+
let only = i === props.length - 1;
|
|
1946
|
+
let j = i;
|
|
1947
|
+
while (only && j--) {
|
|
1948
|
+
const prop2 = props[j];
|
|
1949
|
+
only = prop2.type === "Property" && getStaticKey(prop2) === propertyName;
|
|
1950
|
+
}
|
|
1951
|
+
return { map, index: i, only };
|
|
1952
|
+
}
|
|
1953
|
+
return null;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1639
1956
|
// src/vite/utils/log.ts
|
|
1640
1957
|
import zlib from "node:zlib";
|
|
1641
1958
|
import Table from "cli-table3";
|
|
@@ -1820,6 +2137,7 @@ var ReadOncePersistedStore = class {
|
|
|
1820
2137
|
constructor(uid) {
|
|
1821
2138
|
this.uid = uid;
|
|
1822
2139
|
}
|
|
2140
|
+
uid;
|
|
1823
2141
|
write(value) {
|
|
1824
2142
|
values.set(this.uid, value);
|
|
1825
2143
|
}
|
|
@@ -1919,7 +2237,7 @@ function markoRun(opts = {}) {
|
|
|
1919
2237
|
var _a, _b;
|
|
1920
2238
|
routeMarkoApiCache ?? (routeMarkoApiCache = /* @__PURE__ */ new Map());
|
|
1921
2239
|
if (!routeMarkoApiCache.has(route)) {
|
|
1922
|
-
const markoAPI = route.
|
|
2240
|
+
const markoAPI = route.layouts.length ? (_b = (_a = await loadModule(context, normalizePath(route.layouts[0].filePath))) == null ? void 0 : _a.meta) == null ? void 0 : _b.markoAPI : void 0;
|
|
1923
2241
|
routeMarkoApiCache.set(route, markoAPI);
|
|
1924
2242
|
return markoAPI;
|
|
1925
2243
|
}
|
|
@@ -1941,7 +2259,6 @@ function markoRun(opts = {}) {
|
|
|
1941
2259
|
let buildVirtualFilesResult;
|
|
1942
2260
|
function buildVirtualFiles() {
|
|
1943
2261
|
return buildVirtualFilesResult ?? (buildVirtualFilesResult = (async () => {
|
|
1944
|
-
var _a, _b;
|
|
1945
2262
|
virtualFiles.clear();
|
|
1946
2263
|
if (fs3.existsSync(resolvedRoutesDir)) {
|
|
1947
2264
|
routes = await buildRoutes(
|
|
@@ -1966,9 +2283,8 @@ function markoRun(opts = {}) {
|
|
|
1966
2283
|
entryTemplates = /* @__PURE__ */ new Set();
|
|
1967
2284
|
entryTemplateImporters = /* @__PURE__ */ new Set();
|
|
1968
2285
|
for (const route of routes.list) {
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
entryTemplates.add(normalizePath(routeEntryPath));
|
|
2286
|
+
if (route.templateFilePath) {
|
|
2287
|
+
entryTemplates.add(normalizePath(route.templateFilePath));
|
|
1972
2288
|
}
|
|
1973
2289
|
for (const middleware of route.middleware) {
|
|
1974
2290
|
entryTemplateImporters.add(normalizePath(middleware.filePath));
|
|
@@ -1982,9 +2298,8 @@ function markoRun(opts = {}) {
|
|
|
1982
2298
|
);
|
|
1983
2299
|
}
|
|
1984
2300
|
for (const route of Object.values(routes.special)) {
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
entryTemplates.add(normalizePath(routeEntryPath));
|
|
2301
|
+
if (route.templateFilePath) {
|
|
2302
|
+
entryTemplates.add(normalizePath(route.templateFilePath));
|
|
1988
2303
|
}
|
|
1989
2304
|
}
|
|
1990
2305
|
if (routes.middleware.length) {
|
|
@@ -2039,7 +2354,8 @@ function markoRun(opts = {}) {
|
|
|
2039
2354
|
route.templateFilePath,
|
|
2040
2355
|
renderRouteTemplate(
|
|
2041
2356
|
route,
|
|
2042
|
-
await getMarkoApiForRoute(context, route)
|
|
2357
|
+
await getMarkoApiForRoute(context, route),
|
|
2358
|
+
!isBuild
|
|
2043
2359
|
)
|
|
2044
2360
|
);
|
|
2045
2361
|
}
|
|
@@ -2049,18 +2365,17 @@ function markoRun(opts = {}) {
|
|
|
2049
2365
|
);
|
|
2050
2366
|
}
|
|
2051
2367
|
for (const route of Object.values(routes2.special)) {
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
}
|
|
2368
|
+
fs3.mkdirSync(path6.dirname(route.templateFilePath), {
|
|
2369
|
+
recursive: true
|
|
2370
|
+
});
|
|
2371
|
+
fs3.writeFileSync(
|
|
2372
|
+
route.templateFilePath,
|
|
2373
|
+
renderRouteTemplate(
|
|
2374
|
+
route,
|
|
2375
|
+
await getMarkoApiForRoute(context, route),
|
|
2376
|
+
!isBuild
|
|
2377
|
+
)
|
|
2378
|
+
);
|
|
2064
2379
|
}
|
|
2065
2380
|
if (routes2.middleware.length) {
|
|
2066
2381
|
for (const middleware of routes2.middleware) {
|
|
@@ -2121,7 +2436,7 @@ function markoRun(opts = {}) {
|
|
|
2121
2436
|
}
|
|
2122
2437
|
},
|
|
2123
2438
|
async config(config2, env) {
|
|
2124
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z
|
|
2439
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
2125
2440
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
2126
2441
|
if (externalPluginOptions) {
|
|
2127
2442
|
opts = mergeConfig(opts, externalPluginOptions);
|
|
@@ -2168,12 +2483,12 @@ function markoRun(opts = {}) {
|
|
|
2168
2483
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
2169
2484
|
let outDir = ((_e = config2.build) == null ? void 0 : _e.outDir) || "dist";
|
|
2170
2485
|
const assetsDir = ((_f = config2.build) == null ? void 0 : _f.assetsDir) || "assets";
|
|
2171
|
-
let
|
|
2486
|
+
let rolldownOutputOptions = (_h = (_g = config2.build) == null ? void 0 : _g.rolldownOptions) == null ? void 0 : _h.output;
|
|
2172
2487
|
if (isBuild) {
|
|
2173
2488
|
if (!isSSRBuild) {
|
|
2174
2489
|
outDir = path6.join(outDir, CLIENT_OUT_DIR);
|
|
2175
2490
|
}
|
|
2176
|
-
|
|
2491
|
+
rolldownOutputOptions = mergeOutputOptions(
|
|
2177
2492
|
{
|
|
2178
2493
|
assetFileNames(info) {
|
|
2179
2494
|
var _a2;
|
|
@@ -2187,38 +2502,35 @@ function markoRun(opts = {}) {
|
|
|
2187
2502
|
},
|
|
2188
2503
|
chunkFileNames: isSSRBuild ? `_[hash].js` : `${assetsDir}/_[hash].js`
|
|
2189
2504
|
},
|
|
2190
|
-
|
|
2505
|
+
rolldownOutputOptions
|
|
2191
2506
|
);
|
|
2192
2507
|
}
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
}) : void 0;
|
|
2196
|
-
shouldEmptyOutDir = ((_j = config2.build) == null ? void 0 : _j.emptyOutDir) ?? true;
|
|
2197
|
-
const pluginConfig = await ((_k = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _k.call(adapter, config2)) || {};
|
|
2508
|
+
shouldEmptyOutDir = ((_i = config2.build) == null ? void 0 : _i.emptyOutDir) ?? true;
|
|
2509
|
+
const pluginConfig = await ((_j = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _j.call(adapter, config2)) || {};
|
|
2198
2510
|
pluginConfig.ssr ?? (pluginConfig.ssr = {});
|
|
2199
|
-
(
|
|
2511
|
+
(_k = pluginConfig.ssr).noExternal ?? (_k.noExternal = /@marko\/run($|\/)/);
|
|
2200
2512
|
pluginConfig.css ?? (pluginConfig.css = {});
|
|
2201
|
-
(
|
|
2513
|
+
(_l = pluginConfig.css).devSourcemap ?? (_l.devSourcemap = true);
|
|
2202
2514
|
pluginConfig.build ?? (pluginConfig.build = {});
|
|
2203
|
-
(
|
|
2204
|
-
(
|
|
2205
|
-
(
|
|
2206
|
-
(
|
|
2207
|
-
(
|
|
2208
|
-
(
|
|
2209
|
-
if (
|
|
2210
|
-
pluginConfig.build.
|
|
2211
|
-
|
|
2212
|
-
pluginConfig.build.
|
|
2515
|
+
(_m = pluginConfig.build).outDir ?? (_m.outDir = outDir);
|
|
2516
|
+
(_n = pluginConfig.build).assetsDir ?? (_n.assetsDir = assetsDir);
|
|
2517
|
+
(_o = pluginConfig.build).copyPublicDir ?? (_o.copyPublicDir = !isSSRBuild);
|
|
2518
|
+
(_p = pluginConfig.build).ssrEmitAssets ?? (_p.ssrEmitAssets = false);
|
|
2519
|
+
(_q = pluginConfig.build).emptyOutDir ?? (_q.emptyOutDir = false);
|
|
2520
|
+
(_r = pluginConfig.build).rolldownOptions ?? (_r.rolldownOptions = {});
|
|
2521
|
+
if (rolldownOutputOptions) {
|
|
2522
|
+
pluginConfig.build.rolldownOptions.output = mergeOutputOptions(
|
|
2523
|
+
rolldownOutputOptions,
|
|
2524
|
+
pluginConfig.build.rolldownOptions.output
|
|
2213
2525
|
);
|
|
2214
2526
|
}
|
|
2215
|
-
(
|
|
2216
|
-
(
|
|
2527
|
+
(_t = pluginConfig.build).sourcemap ?? (_t.sourcemap = ((_s = config2.build) == null ? void 0 : _s.sourcemap) ?? (isBuild && !isSSRBuild));
|
|
2528
|
+
(_u = pluginConfig.build).modulePreload ?? (_u.modulePreload = {});
|
|
2217
2529
|
if (typeof pluginConfig.build.modulePreload !== "boolean") {
|
|
2218
2530
|
pluginConfig.build.modulePreload.polyfill = false;
|
|
2219
2531
|
}
|
|
2220
2532
|
pluginConfig.optimizeDeps ?? (pluginConfig.optimizeDeps = {});
|
|
2221
|
-
if (!((
|
|
2533
|
+
if (!((_v = config2.optimizeDeps) == null ? void 0 : _v.entries)) {
|
|
2222
2534
|
pluginConfig.optimizeDeps.entries = [
|
|
2223
2535
|
`${normalizePath(path6.relative(root, routesDir))}/**/*+{page,layout}.marko`,
|
|
2224
2536
|
"!**/__snapshots__/**",
|
|
@@ -2226,21 +2538,16 @@ function markoRun(opts = {}) {
|
|
|
2226
2538
|
"!**/coverage/**"
|
|
2227
2539
|
];
|
|
2228
2540
|
}
|
|
2229
|
-
if (
|
|
2230
|
-
|
|
2231
|
-
browserslistTarget,
|
|
2232
|
-
{
|
|
2233
|
-
printUnknownTargets: false
|
|
2234
|
-
}
|
|
2235
|
-
));
|
|
2541
|
+
if (isBuild && !((_w = config2.build) == null ? void 0 : _w.target)) {
|
|
2542
|
+
pluginConfig.build.target = getBrowserslistTargets(root);
|
|
2236
2543
|
}
|
|
2237
2544
|
if (isBuild) {
|
|
2238
2545
|
pluginConfig.logLevel ?? (pluginConfig.logLevel = "warn");
|
|
2239
2546
|
pluginConfig.define ?? (pluginConfig.define = {});
|
|
2240
|
-
(
|
|
2547
|
+
(_x = pluginConfig.define)["process.env.NODE_ENV"] ?? (_x["process.env.NODE_ENV"] = "'production'");
|
|
2241
2548
|
pluginConfig.resolve ?? (pluginConfig.resolve = {});
|
|
2242
|
-
(
|
|
2243
|
-
(
|
|
2549
|
+
(_y = pluginConfig.resolve).mainFields ?? (_y.mainFields = (isSSRBuild ? [] : ["browser"]).concat(["module", "jsnext:main", "jsnext", "main"]));
|
|
2550
|
+
(_z = pluginConfig.resolve).conditions ?? (_z.conditions = [
|
|
2244
2551
|
isSSRBuild ? "node" : "browser",
|
|
2245
2552
|
"import",
|
|
2246
2553
|
"require",
|
|
@@ -2254,7 +2561,7 @@ function markoRun(opts = {}) {
|
|
|
2254
2561
|
resolvedConfig = config2;
|
|
2255
2562
|
const {
|
|
2256
2563
|
ssr,
|
|
2257
|
-
|
|
2564
|
+
rolldownOptions: { input }
|
|
2258
2565
|
} = config2.build;
|
|
2259
2566
|
if (typeof ssr === "string") {
|
|
2260
2567
|
ssrEntryFiles = [ssr];
|
|
@@ -2373,6 +2680,48 @@ function markoRun(opts = {}) {
|
|
|
2373
2680
|
{
|
|
2374
2681
|
name: `${PLUGIN_NAME_PREFIX}:post`,
|
|
2375
2682
|
enforce: "post",
|
|
2683
|
+
async transform(code) {
|
|
2684
|
+
if (!isBuild || isSSRBuild || !code.includes("Run.href")) {
|
|
2685
|
+
return;
|
|
2686
|
+
}
|
|
2687
|
+
try {
|
|
2688
|
+
const replacements = findHrefReplacements(
|
|
2689
|
+
code,
|
|
2690
|
+
this.parse(code, { lang: "js" })
|
|
2691
|
+
);
|
|
2692
|
+
if (replacements.length) {
|
|
2693
|
+
const helpers = /* @__PURE__ */ new Set();
|
|
2694
|
+
const s = new RolldownMagicString(code);
|
|
2695
|
+
for (const { helper, edits } of replacements) {
|
|
2696
|
+
for (const { start, end, code: code2 } of edits) {
|
|
2697
|
+
if (code2) {
|
|
2698
|
+
s.overwrite(start, end, code2);
|
|
2699
|
+
} else {
|
|
2700
|
+
s.remove(start, end);
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
if (helper) {
|
|
2704
|
+
helpers.add(helper);
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
if (helpers.size) {
|
|
2708
|
+
s.prepend(
|
|
2709
|
+
`import { ${[...helpers].join(", ")} } from "virtual:marko-run/runtime/url-builder";`
|
|
2710
|
+
);
|
|
2711
|
+
}
|
|
2712
|
+
return {
|
|
2713
|
+
code: s
|
|
2714
|
+
};
|
|
2715
|
+
}
|
|
2716
|
+
return null;
|
|
2717
|
+
} catch {
|
|
2718
|
+
return {
|
|
2719
|
+
code: new RolldownMagicString(code).prepend(
|
|
2720
|
+
'import "virtual:marko-run/runtime/client";'
|
|
2721
|
+
)
|
|
2722
|
+
};
|
|
2723
|
+
}
|
|
2724
|
+
},
|
|
2376
2725
|
generateBundle(options, bundle) {
|
|
2377
2726
|
if (options.sourcemap && options.sourcemap !== "inline") {
|
|
2378
2727
|
for (const key of Object.keys(bundle)) {
|
|
@@ -2534,6 +2883,33 @@ var defaultConfigPlugin = {
|
|
|
2534
2883
|
};
|
|
2535
2884
|
}
|
|
2536
2885
|
};
|
|
2886
|
+
function getBrowserslistTargets(path10) {
|
|
2887
|
+
var _a;
|
|
2888
|
+
const browserslistTarget = browserslist(void 0, { path: path10 });
|
|
2889
|
+
if (browserslistTarget.length) {
|
|
2890
|
+
const versions = /* @__PURE__ */ new Map();
|
|
2891
|
+
for (const target of resolveToEsbuildTarget(browserslistTarget, {
|
|
2892
|
+
printUnknownTargets: false
|
|
2893
|
+
})) {
|
|
2894
|
+
const index = (_a = /\d/.exec(target)) == null ? void 0 : _a.index;
|
|
2895
|
+
if (index) {
|
|
2896
|
+
const browser = target.slice(0, index);
|
|
2897
|
+
const version = Number(target.slice(index));
|
|
2898
|
+
const existingVersion = versions.get(browser);
|
|
2899
|
+
if (!existingVersion || version < existingVersion) {
|
|
2900
|
+
versions.set(browser, version);
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
if (versions.size) {
|
|
2905
|
+
const targets = [];
|
|
2906
|
+
for (const [browser, version] of versions) {
|
|
2907
|
+
targets.push(browser + version);
|
|
2908
|
+
}
|
|
2909
|
+
return targets;
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2537
2913
|
|
|
2538
2914
|
// src/vite/utils/server.ts
|
|
2539
2915
|
import cp from "child_process";
|
|
@@ -2765,7 +3141,7 @@ async function build(entry, cwd, configFile, outDir, envFile) {
|
|
|
2765
3141
|
target: "esnext",
|
|
2766
3142
|
...buildConfig.build,
|
|
2767
3143
|
ssr: entry,
|
|
2768
|
-
|
|
3144
|
+
rolldownOptions: {
|
|
2769
3145
|
output: {
|
|
2770
3146
|
entryFileNames: "index.mjs"
|
|
2771
3147
|
// Would rather build with `.js` extension but that will fail in zero-config projects where node runs in cjs mode
|