@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/vite/index.js
CHANGED
|
@@ -17,6 +17,9 @@ import { resolveToEsbuildTarget } from "esbuild-plugin-browserslist";
|
|
|
17
17
|
import fs3 from "fs";
|
|
18
18
|
import { glob } from "glob";
|
|
19
19
|
import path6 from "path";
|
|
20
|
+
import {
|
|
21
|
+
RolldownMagicString
|
|
22
|
+
} from "rolldown";
|
|
20
23
|
import { fileURLToPath } from "url";
|
|
21
24
|
import {
|
|
22
25
|
buildErrorMessage,
|
|
@@ -65,10 +68,10 @@ var httpVerbs = [
|
|
|
65
68
|
"options"
|
|
66
69
|
];
|
|
67
70
|
var RoutableFileTypes = {
|
|
68
|
-
Page: "page",
|
|
69
|
-
Layout: "layout",
|
|
70
|
-
Handler: "handler",
|
|
71
71
|
Middleware: "middleware",
|
|
72
|
+
Handler: "handler",
|
|
73
|
+
Layout: "layout",
|
|
74
|
+
Page: "page",
|
|
72
75
|
Meta: "meta",
|
|
73
76
|
NotFound: "404",
|
|
74
77
|
Error: "500"
|
|
@@ -257,19 +260,21 @@ function normalizedRelativePath(from, to) {
|
|
|
257
260
|
const relativePath = normalizePath(path2.relative(from, to));
|
|
258
261
|
return relativePath.startsWith(".") ? relativePath : "./" + relativePath;
|
|
259
262
|
}
|
|
260
|
-
function renderRouteTemplate(route, markoApi) {
|
|
263
|
+
function renderRouteTemplate(route, markoApi, dev = false) {
|
|
261
264
|
if (!route.page) {
|
|
262
265
|
throw new Error(`Route ${route.key} has no page to render`);
|
|
263
266
|
}
|
|
264
|
-
if (!route.templateFilePath) {
|
|
265
|
-
throw new Error(`Route ${route.key} has no template file path`);
|
|
266
|
-
}
|
|
267
267
|
const writer = createStringWriter();
|
|
268
268
|
if (markoApi) {
|
|
269
269
|
writer.writeLines(`<!-- use ${markoApi} -->
|
|
270
270
|
`);
|
|
271
271
|
}
|
|
272
|
-
writer.branch("imports");
|
|
272
|
+
const importWriter = writer.branch("imports");
|
|
273
|
+
if (dev) {
|
|
274
|
+
importWriter.writeLines(
|
|
275
|
+
`client import "virtual:marko-run/runtime/client";`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
273
278
|
writer.writeLines("");
|
|
274
279
|
writeEntryTemplateTag(
|
|
275
280
|
writer,
|
|
@@ -317,7 +322,10 @@ function renderRouteEntry(route, rootDir) {
|
|
|
317
322
|
runtimeImports.push("normalizeMeta");
|
|
318
323
|
}
|
|
319
324
|
if (handler || middleware.length) {
|
|
320
|
-
runtimeImports.push("call");
|
|
325
|
+
runtimeImports.push("call", "mergeOptions");
|
|
326
|
+
}
|
|
327
|
+
if (page) {
|
|
328
|
+
runtimeImports.push("render");
|
|
321
329
|
}
|
|
322
330
|
if (!page || verbs.some((verb) => verb !== "get" && verb !== "head")) {
|
|
323
331
|
runtimeImports.push("noContent");
|
|
@@ -356,7 +364,7 @@ function renderRouteEntry(route, rootDir) {
|
|
|
356
364
|
}
|
|
357
365
|
if (page) {
|
|
358
366
|
imports.writeLines(
|
|
359
|
-
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath
|
|
367
|
+
`import page from "${normalizedRelativePath(rootDir, route.templateFilePath)}";`
|
|
360
368
|
);
|
|
361
369
|
}
|
|
362
370
|
if (meta) {
|
|
@@ -374,11 +382,34 @@ function renderRouteEntry(route, rootDir) {
|
|
|
374
382
|
`export const { ${metaVerbsExports} } = normalizeMeta(${metaName});`
|
|
375
383
|
);
|
|
376
384
|
}
|
|
385
|
+
const optionsWriter = writer.branch("options").writeLines("");
|
|
377
386
|
for (const verb of verbs) {
|
|
387
|
+
writeRouteOptions(optionsWriter, route, verb);
|
|
378
388
|
writeRouteEntryHandler(writer, route, verb);
|
|
379
389
|
}
|
|
390
|
+
optionsWriter.join();
|
|
380
391
|
return writer.end();
|
|
381
392
|
}
|
|
393
|
+
function writeRouteOptions(writer, route, verb) {
|
|
394
|
+
var _a, _b;
|
|
395
|
+
const hasHandler = (_b = (_a = route.handler) == null ? void 0 : _a.verbs) == null ? void 0 : _b.includes(verb);
|
|
396
|
+
writer.write(`export const ${verb}${route.index}_options = `);
|
|
397
|
+
if (route.middleware.length || hasHandler) {
|
|
398
|
+
writer.write(`mergeOptions(`);
|
|
399
|
+
let sep = "";
|
|
400
|
+
for (const { id } of route.middleware) {
|
|
401
|
+
writer.write(`${sep}mware${id}`);
|
|
402
|
+
sep = ", ";
|
|
403
|
+
}
|
|
404
|
+
if (hasHandler) {
|
|
405
|
+
writer.write(`${sep}${verb}Handler`);
|
|
406
|
+
}
|
|
407
|
+
writer.write(");");
|
|
408
|
+
} else {
|
|
409
|
+
writer.write("{};");
|
|
410
|
+
}
|
|
411
|
+
writer.write("\n");
|
|
412
|
+
}
|
|
382
413
|
function writeRouteEntryHandler(writer, route, verb) {
|
|
383
414
|
var _a, _b, _c, _d;
|
|
384
415
|
const { key, index, page, handler, middleware } = route;
|
|
@@ -398,13 +429,13 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
398
429
|
if ((_a = handler == null ? void 0 : handler.verbs) == null ? void 0 : _a.includes(verb)) {
|
|
399
430
|
const name = `${verb}Handler`;
|
|
400
431
|
continuations.writeLines(
|
|
401
|
-
`const ${currentName} = () =>
|
|
432
|
+
`const ${currentName} = (data) => render(context, page, {}, data);`
|
|
402
433
|
);
|
|
403
434
|
if (len) {
|
|
404
435
|
nextName = currentName;
|
|
405
436
|
currentName = `__${name}`;
|
|
406
437
|
continuations.writeLines(
|
|
407
|
-
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
438
|
+
`const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
|
|
408
439
|
);
|
|
409
440
|
} else {
|
|
410
441
|
if (verb === "head") {
|
|
@@ -421,11 +452,10 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
421
452
|
hasBody = true;
|
|
422
453
|
} else if (len) {
|
|
423
454
|
continuations.writeLines(
|
|
424
|
-
`const ${currentName} = () =>
|
|
455
|
+
`const ${currentName} = (data) => render(context, page, {}, data);`
|
|
425
456
|
);
|
|
426
|
-
nextName = currentName;
|
|
427
457
|
} else {
|
|
428
|
-
writer.writeLines(`return
|
|
458
|
+
writer.writeLines(`return render(context, page, {});`);
|
|
429
459
|
hasBody = true;
|
|
430
460
|
}
|
|
431
461
|
} else if ((_b = handler == null ? void 0 : handler.verbs) == null ? void 0 : _b.includes(verb)) {
|
|
@@ -434,7 +464,7 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
434
464
|
nextName = "noContent";
|
|
435
465
|
if (len) {
|
|
436
466
|
continuations.writeLines(
|
|
437
|
-
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
467
|
+
`const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
|
|
438
468
|
);
|
|
439
469
|
} else {
|
|
440
470
|
if (verb === "head") {
|
|
@@ -461,7 +491,7 @@ function writeRouteEntryHandler(writer, route, verb) {
|
|
|
461
491
|
currentName = i ? `__${name}` : "";
|
|
462
492
|
if (currentName) {
|
|
463
493
|
continuations.writeLines(
|
|
464
|
-
`const ${currentName} = () => call(${name}, ${nextName}, context);`
|
|
494
|
+
`const ${currentName} = (data) => call(${name}, ${nextName}, context, data);`
|
|
465
495
|
);
|
|
466
496
|
} else if (verb === "head") {
|
|
467
497
|
continuations.writeLines(
|
|
@@ -494,6 +524,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
494
524
|
for (const verb of verbs) {
|
|
495
525
|
const verbName = `${verb}${route.index}`;
|
|
496
526
|
routeImports.push(verbName);
|
|
527
|
+
routeImports.push(`${verbName}_options`);
|
|
497
528
|
if (route.meta) {
|
|
498
529
|
routeImports.push(`${verbName}_meta`);
|
|
499
530
|
}
|
|
@@ -504,7 +535,7 @@ function renderRouter(routes, rootDir, runtimeInclude, options = {
|
|
|
504
535
|
}
|
|
505
536
|
for (const route of Object.values(routes.special)) {
|
|
506
537
|
imports.writeLines(
|
|
507
|
-
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath
|
|
538
|
+
`import page${route.key} from "${normalizedRelativePath(rootDir, route.templateFilePath)}";`
|
|
508
539
|
);
|
|
509
540
|
}
|
|
510
541
|
writer.writeLines(
|
|
@@ -789,10 +820,10 @@ function renderParams(params, pathIndex) {
|
|
|
789
820
|
return result ? result + " }" : "{}";
|
|
790
821
|
}
|
|
791
822
|
function renderMatch(verb, route, path7, pathIndex) {
|
|
792
|
-
const
|
|
823
|
+
const name = `${verb}${route.index}`;
|
|
793
824
|
const params = path7.params ? renderParams(path7.params, pathIndex) : "{}";
|
|
794
|
-
const meta = route.meta ? `${
|
|
795
|
-
return `{ handler: ${
|
|
825
|
+
const meta = route.meta ? `${name}_meta` : "{}";
|
|
826
|
+
return `{ handler: ${name}, path: '${path7.path}', params: ${params}, options: ${name}_options, meta: ${meta} }`;
|
|
796
827
|
}
|
|
797
828
|
function renderMiddleware(middleware, rootDir) {
|
|
798
829
|
const writer = createStringWriter();
|
|
@@ -823,8 +854,14 @@ function stripTsExtension(path7) {
|
|
|
823
854
|
}
|
|
824
855
|
return path7;
|
|
825
856
|
}
|
|
857
|
+
function* routeFileIter(route) {
|
|
858
|
+
yield* route.middleware;
|
|
859
|
+
if (route.handler) yield route.handler;
|
|
860
|
+
yield* route.layouts;
|
|
861
|
+
if (route.page) yield route.page;
|
|
862
|
+
if (route.meta) yield route.meta;
|
|
863
|
+
}
|
|
826
864
|
async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
827
|
-
var _a, _b, _c, _d;
|
|
828
865
|
const writer = createStringWriter();
|
|
829
866
|
writer.writeLines(
|
|
830
867
|
`/*
|
|
@@ -833,10 +870,11 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
|
833
870
|
*/
|
|
834
871
|
`,
|
|
835
872
|
`import { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform } from "@marko/run/namespace";`,
|
|
836
|
-
`import type * as
|
|
873
|
+
`import type * as $ from "@marko/run";`,
|
|
874
|
+
""
|
|
837
875
|
);
|
|
838
876
|
const headWriter = writer.branch("head");
|
|
839
|
-
writer.writeLines("
|
|
877
|
+
writer.writeLines("").writeBlockStart(`declare module "@marko/run" {`);
|
|
840
878
|
if (adapter && adapter.typeInfo) {
|
|
841
879
|
const platformType = await adapter.typeInfo(
|
|
842
880
|
(data) => headWriter.write(data)
|
|
@@ -846,139 +884,120 @@ async function renderRouteTypeInfo(routes, outDir, adapter) {
|
|
|
846
884
|
`);
|
|
847
885
|
}
|
|
848
886
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
let
|
|
857
|
-
if (
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
887
|
+
const fileInfoByType = /* @__PURE__ */ new Map();
|
|
888
|
+
let fileIndex = 1;
|
|
889
|
+
function addFile(file) {
|
|
890
|
+
let group = fileInfoByType.get(file.type);
|
|
891
|
+
if (!group) {
|
|
892
|
+
fileInfoByType.set(file.type, group = /* @__PURE__ */ new Map());
|
|
893
|
+
}
|
|
894
|
+
let info = group.get(file);
|
|
895
|
+
if (!info) {
|
|
896
|
+
info = {
|
|
897
|
+
id: "",
|
|
898
|
+
typeName: null,
|
|
899
|
+
modulePath: stripTsExtension(
|
|
900
|
+
normalizedRelativePath(outDir, file.filePath)
|
|
901
|
+
),
|
|
902
|
+
routes: /* @__PURE__ */ new Set()
|
|
903
|
+
};
|
|
904
|
+
switch (file.type) {
|
|
905
|
+
case RoutableFileTypes.Middleware:
|
|
906
|
+
info.id = `M${group.size + 1}`;
|
|
907
|
+
info.typeName = "Middleware";
|
|
908
|
+
break;
|
|
909
|
+
case RoutableFileTypes.Handler:
|
|
910
|
+
info.id = `H${group.size + 1}`;
|
|
911
|
+
info.typeName = "Handler";
|
|
912
|
+
break;
|
|
913
|
+
case RoutableFileTypes.Meta:
|
|
914
|
+
info.id = `D${group.size + 1}`;
|
|
915
|
+
info.typeName = "Meta";
|
|
916
|
+
break;
|
|
917
|
+
case RoutableFileTypes.Layout:
|
|
918
|
+
info.id = `L${group.size + 1}`;
|
|
919
|
+
info.typeName = "Template";
|
|
920
|
+
break;
|
|
921
|
+
case RoutableFileTypes.Page:
|
|
922
|
+
info.id = `P${group.size + 1}`;
|
|
923
|
+
info.typeName = "Template";
|
|
924
|
+
break;
|
|
925
|
+
default:
|
|
926
|
+
info.id = `F${fileIndex++}`;
|
|
927
|
+
break;
|
|
889
928
|
}
|
|
929
|
+
group.set(file, info);
|
|
890
930
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
931
|
+
return info;
|
|
932
|
+
}
|
|
933
|
+
writer.writeBlockStart(`interface App extends $.DefineRoutes<{`);
|
|
934
|
+
for (const route of routes.list) {
|
|
935
|
+
let routeDefFiles = "";
|
|
936
|
+
for (const file of routeFileIter(route)) {
|
|
937
|
+
const fileInfo = addFile(file);
|
|
938
|
+
fileInfo.routes.add(route);
|
|
939
|
+
if (routeDefFiles) {
|
|
940
|
+
routeDefFiles += ", ";
|
|
901
941
|
}
|
|
942
|
+
routeDefFiles += fileInfo.id;
|
|
902
943
|
}
|
|
944
|
+
writer.writeLines(`"${route.path.path}": [${routeDefFiles}];`);
|
|
903
945
|
}
|
|
904
946
|
for (const special of Object.values(routes.special)) {
|
|
905
|
-
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
const routeType = `Run.Routes[${types.join(" | ")}]`;
|
|
917
|
-
switch (file.type) {
|
|
918
|
-
case RoutableFileTypes.Handler:
|
|
919
|
-
writeModuleDeclaration(handlerWriter, modulePath, routeType);
|
|
920
|
-
break;
|
|
921
|
-
case RoutableFileTypes.Middleware:
|
|
922
|
-
writeModuleDeclaration(middlewareWriter, modulePath, routeType);
|
|
923
|
-
break;
|
|
924
|
-
case RoutableFileTypes.Page:
|
|
925
|
-
writeModuleDeclaration(pageWriter, modulePath, routeType);
|
|
926
|
-
break;
|
|
927
|
-
case RoutableFileTypes.Layout:
|
|
928
|
-
writeModuleDeclaration(
|
|
929
|
-
layoutWriter,
|
|
930
|
-
modulePath,
|
|
931
|
-
routeType,
|
|
932
|
-
`
|
|
933
|
-
export interface Input extends Run.LayoutInput<typeof import("${modulePath}")> {}`
|
|
947
|
+
addFile(special.page);
|
|
948
|
+
}
|
|
949
|
+
writer.writeBlockEnd(`}> {}`).writeBlockEnd(`}`);
|
|
950
|
+
for (const fileType of Object.values(RoutableFileTypes)) {
|
|
951
|
+
const fileGroup = fileInfoByType.get(fileType);
|
|
952
|
+
if (!fileGroup) continue;
|
|
953
|
+
for (const info of fileGroup.values()) {
|
|
954
|
+
writer.writeLines("");
|
|
955
|
+
if (info.typeName) {
|
|
956
|
+
writer.writeLines(
|
|
957
|
+
`type ${info.id} = $.${info.typeName}<"${info.id}", typeof import("${info.modulePath}")>;`
|
|
934
958
|
);
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
959
|
+
}
|
|
960
|
+
if (fileType === RoutableFileTypes.Meta) continue;
|
|
961
|
+
writer.write(`declare module "${info.modulePath}" {`);
|
|
962
|
+
switch (fileType) {
|
|
963
|
+
case RoutableFileTypes.Layout:
|
|
964
|
+
writer.write(`
|
|
965
|
+
interface Input extends $.LayoutInput<${info.id}> {}`);
|
|
966
|
+
break;
|
|
967
|
+
case RoutableFileTypes.Error:
|
|
968
|
+
writer.write(`
|
|
942
969
|
export interface Input {
|
|
943
970
|
error: unknown;
|
|
944
|
-
}`
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
handlerWriter.join();
|
|
953
|
-
middlewareWriter.join();
|
|
954
|
-
pageWriter.join();
|
|
955
|
-
layoutWriter.join();
|
|
956
|
-
return writer.end();
|
|
957
|
-
}
|
|
958
|
-
function writeModuleDeclaration(writer, name, routeType, moduleTypes) {
|
|
959
|
-
writer.writeLines("").write(`declare module "${name}" {`);
|
|
960
|
-
if (moduleTypes) {
|
|
961
|
-
writer.write(moduleTypes);
|
|
971
|
+
}`);
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
if (info.typeName) {
|
|
975
|
+
writer.write(`
|
|
976
|
+
const Run: $.Namespace<${info.id}>;
|
|
977
|
+
namespace Run {
|
|
978
|
+
type Context = $.ContextForFile<${info.id}>${info.typeName === "Template" ? " & Marko.Global" : ""};
|
|
962
979
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
980
|
+
`);
|
|
981
|
+
}
|
|
982
|
+
writer.write(`
|
|
983
|
+
/** @deprecated use \`Run\` namespace instead */
|
|
966
984
|
namespace MarkoRun {
|
|
967
985
|
export { NotHandled, NotMatched, GetPaths, PostPaths, GetablePath, GetableHref, PostablePath, PostableHref, Platform };
|
|
968
|
-
export type Route = ${
|
|
969
|
-
export type Context =
|
|
970
|
-
export type Handler =
|
|
971
|
-
|
|
986
|
+
export type Route = ${info.routes.size ? `$.Routes["${[...info.routes].map((route) => route.path.path).join('" | "')}"]` : "globalThis.MarkoRun.Route"};
|
|
987
|
+
export type Context = ${info.modulePath.endsWith(".marko") ? "Run.Context" : "$.MultiRouteContext<Route>"};
|
|
988
|
+
export type Handler = $.HandlerLike<Route>;`);
|
|
989
|
+
for (const verb of httpVerbs) {
|
|
990
|
+
writer.write(`
|
|
991
|
+
export type ${verb.toUpperCase()} = $.HandlerLike<Route, "${verb.toUpperCase()}">;`);
|
|
992
|
+
}
|
|
972
993
|
writer.write(`
|
|
973
|
-
export type ${verb.toUpperCase()} = Run.HandlerLike<Route, "${verb.toUpperCase()}">;`);
|
|
974
|
-
}
|
|
975
|
-
writer.write(`
|
|
976
|
-
/** @deprecated use \`((context, next) => { ... }) satisfies MarkoRun.Handler\` instead */
|
|
977
|
-
export const route: Run.HandlerTypeFn<Route>;
|
|
978
994
|
}`);
|
|
979
|
-
|
|
980
|
-
writer.writeLines(`
|
|
995
|
+
writer.writeLines(`
|
|
981
996
|
}`);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
headWriter.join();
|
|
1000
|
+
return writer.end();
|
|
982
1001
|
}
|
|
983
1002
|
function createRouteTrie(routes) {
|
|
984
1003
|
const root = {
|
|
@@ -1463,7 +1482,7 @@ async function buildRoutes(sources, outDir) {
|
|
|
1463
1482
|
middleware: [],
|
|
1464
1483
|
layouts: [...currentLayouts],
|
|
1465
1484
|
page: file,
|
|
1466
|
-
templateFilePath:
|
|
1485
|
+
templateFilePath: path3.join(outDir, `${type}.marko`)
|
|
1467
1486
|
};
|
|
1468
1487
|
layoutsUsed = true;
|
|
1469
1488
|
}
|
|
@@ -1496,7 +1515,7 @@ async function buildRoutes(sources, outDir) {
|
|
|
1496
1515
|
meta: dir.files.get(RoutableFileTypes.Meta),
|
|
1497
1516
|
page,
|
|
1498
1517
|
handler,
|
|
1499
|
-
templateFilePath: page &&
|
|
1518
|
+
templateFilePath: page && path3.join(outDir, key + ".marko")
|
|
1500
1519
|
});
|
|
1501
1520
|
layoutsUsed = !!page;
|
|
1502
1521
|
for (const middleware2 of currentMiddleware) {
|
|
@@ -1535,7 +1554,7 @@ function createFSWalker(dir) {
|
|
|
1535
1554
|
onDir,
|
|
1536
1555
|
maxDepth = 50
|
|
1537
1556
|
}) {
|
|
1538
|
-
async function
|
|
1557
|
+
async function walk2(dir2, depth) {
|
|
1539
1558
|
const onExit = onEnter == null ? void 0 : onEnter(dir2);
|
|
1540
1559
|
if (onExit !== false) {
|
|
1541
1560
|
const dirs = [];
|
|
@@ -1556,13 +1575,13 @@ function createFSWalker(dir) {
|
|
|
1556
1575
|
}
|
|
1557
1576
|
if ((onDir == null ? void 0 : onDir()) !== false && --depth > 0) {
|
|
1558
1577
|
for (const entry of dirs) {
|
|
1559
|
-
await
|
|
1578
|
+
await walk2(entry, depth);
|
|
1560
1579
|
}
|
|
1561
1580
|
}
|
|
1562
1581
|
onExit == null ? void 0 : onExit();
|
|
1563
1582
|
}
|
|
1564
1583
|
}
|
|
1565
|
-
await
|
|
1584
|
+
await walk2(
|
|
1566
1585
|
{
|
|
1567
1586
|
path: dir,
|
|
1568
1587
|
name: path4.basename(dir)
|
|
@@ -1619,6 +1638,304 @@ var getExternalPluginOptions = (viteConfig) => getConfig(viteConfig, PluginConfi
|
|
|
1619
1638
|
var setExternalPluginOptions = (viteConfig, value) => setConfig(viteConfig, PluginConfigKey, value);
|
|
1620
1639
|
var getExternalAdapterOptions = (viteConfig) => getConfig(viteConfig, AdapterConfigKey);
|
|
1621
1640
|
|
|
1641
|
+
// src/runtime/url-builder.ts
|
|
1642
|
+
var encode = encodeURIComponent;
|
|
1643
|
+
var pathParts = /* @__PURE__ */ new Map();
|
|
1644
|
+
function parsePathParts(path7) {
|
|
1645
|
+
let parts = pathParts.get(path7);
|
|
1646
|
+
if (!parts) {
|
|
1647
|
+
let lastEnd = 0;
|
|
1648
|
+
let paramStart;
|
|
1649
|
+
pathParts.set(path7, parts = [[]]);
|
|
1650
|
+
while (lastEnd >= 0 && (paramStart = path7.indexOf("/$", lastEnd) + 1)) {
|
|
1651
|
+
parts.push(path7.slice(lastEnd, paramStart++));
|
|
1652
|
+
if (path7.charAt(paramStart) === "$") {
|
|
1653
|
+
paramStart++;
|
|
1654
|
+
lastEnd = -1;
|
|
1655
|
+
} else {
|
|
1656
|
+
lastEnd = path7.indexOf("/", paramStart);
|
|
1657
|
+
}
|
|
1658
|
+
parts[0].push(path7.slice(paramStart, lastEnd < 0 ? void 0 : lastEnd));
|
|
1659
|
+
}
|
|
1660
|
+
parts.push(lastEnd >= 0 ? path7.slice(lastEnd) : "");
|
|
1661
|
+
}
|
|
1662
|
+
return parts;
|
|
1663
|
+
}
|
|
1664
|
+
function joinHref(path7, options) {
|
|
1665
|
+
let result = path7;
|
|
1666
|
+
if (options.search) {
|
|
1667
|
+
const query = "" + new URLSearchParams(options.search);
|
|
1668
|
+
if (query) result += "?" + query;
|
|
1669
|
+
}
|
|
1670
|
+
if (options.hash) result += "#" + encode(options.hash);
|
|
1671
|
+
return result;
|
|
1672
|
+
}
|
|
1673
|
+
function href(path7, ...[options]) {
|
|
1674
|
+
return options ? "params" in options ? ((parts) => href_keys(parts, options, ...parts[0]))(
|
|
1675
|
+
parsePathParts(path7)
|
|
1676
|
+
) : joinHref(path7, options) : path7;
|
|
1677
|
+
}
|
|
1678
|
+
function href_path(strings, ...params) {
|
|
1679
|
+
let i = 0;
|
|
1680
|
+
let j = 0;
|
|
1681
|
+
let result = strings[i++];
|
|
1682
|
+
if (!result || Array.isArray(result)) result = strings[i++];
|
|
1683
|
+
while (i < strings.length) {
|
|
1684
|
+
const param = params[j++];
|
|
1685
|
+
result += (Array.isArray(param) ? param.map(encode).join("/") : encode(param)) + strings[i++];
|
|
1686
|
+
}
|
|
1687
|
+
return result;
|
|
1688
|
+
}
|
|
1689
|
+
function href_values(strings, options, ...params) {
|
|
1690
|
+
return joinHref(href_path(strings, ...params), options);
|
|
1691
|
+
}
|
|
1692
|
+
function href_keys(strings, options, ...keys) {
|
|
1693
|
+
return href_values(strings, options, ...keys.map((k) => options.params[k]));
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// src/vite/utils/href-replace.ts
|
|
1697
|
+
function findHrefReplacements(code, ast) {
|
|
1698
|
+
const replacements = [];
|
|
1699
|
+
walk(ast, (node) => {
|
|
1700
|
+
var _a, _b;
|
|
1701
|
+
if (node.type !== "CallExpression") return;
|
|
1702
|
+
const callee = node.callee;
|
|
1703
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.object.name !== "Run" || callee.property.type !== "Identifier" || callee.property.name !== "href") {
|
|
1704
|
+
return;
|
|
1705
|
+
}
|
|
1706
|
+
const args = node.arguments;
|
|
1707
|
+
if (args.length === 0 || args.length > 2 || args.some((a) => a.type === "SpreadElement")) {
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
const pathString = (_a = tryStaticEval(args[0])) == null ? void 0 : _a.value;
|
|
1711
|
+
if (typeof pathString !== "string") {
|
|
1712
|
+
replacements.push({
|
|
1713
|
+
helper: "href",
|
|
1714
|
+
edits: [{ start: callee.start, end: callee.end, code: "href" }]
|
|
1715
|
+
});
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
if (args.length === 1) {
|
|
1719
|
+
replacements.push({
|
|
1720
|
+
helper: false,
|
|
1721
|
+
edits: [
|
|
1722
|
+
{
|
|
1723
|
+
start: node.start,
|
|
1724
|
+
end: node.end,
|
|
1725
|
+
code: JSON.stringify(pathString)
|
|
1726
|
+
}
|
|
1727
|
+
]
|
|
1728
|
+
});
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
const optionsNode = args[1];
|
|
1732
|
+
const optionsObject = (_b = tryStaticEval(optionsNode)) == null ? void 0 : _b.value;
|
|
1733
|
+
if (optionsObject && typeof optionsObject === "object" && !Array.isArray(optionsObject)) {
|
|
1734
|
+
replacements.push({
|
|
1735
|
+
helper: false,
|
|
1736
|
+
edits: [
|
|
1737
|
+
{
|
|
1738
|
+
start: node.start,
|
|
1739
|
+
end: node.end,
|
|
1740
|
+
code: JSON.stringify(href(pathString, optionsObject))
|
|
1741
|
+
}
|
|
1742
|
+
]
|
|
1743
|
+
});
|
|
1744
|
+
return;
|
|
1745
|
+
}
|
|
1746
|
+
const parsed = parsePathPattern(pathString);
|
|
1747
|
+
if (optionsNode.type === "ObjectExpression") {
|
|
1748
|
+
const params = tryExtractObjectProperty(optionsNode, "params");
|
|
1749
|
+
if (params && parsed.params.every((p) => params.map.has(p))) {
|
|
1750
|
+
const pathPart = buildPathTemplate(code, parsed, params.map);
|
|
1751
|
+
if (params.only) {
|
|
1752
|
+
replacements.push({
|
|
1753
|
+
helper: "href_path",
|
|
1754
|
+
edits: [
|
|
1755
|
+
{
|
|
1756
|
+
start: node.start,
|
|
1757
|
+
end: node.end,
|
|
1758
|
+
code: "href_path`" + pathPart + "`"
|
|
1759
|
+
}
|
|
1760
|
+
]
|
|
1761
|
+
});
|
|
1762
|
+
} else {
|
|
1763
|
+
const props = optionsNode.properties;
|
|
1764
|
+
const remaining = props.filter((_, i) => i !== params.index);
|
|
1765
|
+
if (remaining.length === 1 && remaining[0].type === "SpreadElement") {
|
|
1766
|
+
replacements.push({
|
|
1767
|
+
helper: "href_values",
|
|
1768
|
+
edits: [
|
|
1769
|
+
{
|
|
1770
|
+
start: node.start,
|
|
1771
|
+
end: remaining[0].argument.start,
|
|
1772
|
+
code: "href_values`${"
|
|
1773
|
+
},
|
|
1774
|
+
{
|
|
1775
|
+
start: remaining[0].argument.end,
|
|
1776
|
+
end: node.end,
|
|
1777
|
+
code: "}" + pathPart + "`"
|
|
1778
|
+
}
|
|
1779
|
+
]
|
|
1780
|
+
});
|
|
1781
|
+
} else {
|
|
1782
|
+
replacements.push({
|
|
1783
|
+
helper: "href_values",
|
|
1784
|
+
edits: [
|
|
1785
|
+
{
|
|
1786
|
+
start: node.start,
|
|
1787
|
+
end: optionsNode.start,
|
|
1788
|
+
code: "href_values`${"
|
|
1789
|
+
},
|
|
1790
|
+
{
|
|
1791
|
+
start: optionsNode.end,
|
|
1792
|
+
end: node.end,
|
|
1793
|
+
code: "}" + pathPart + "`"
|
|
1794
|
+
},
|
|
1795
|
+
params.index < props.length - 1 ? {
|
|
1796
|
+
start: props[params.index].start,
|
|
1797
|
+
end: props[params.index + 1].start,
|
|
1798
|
+
code: ""
|
|
1799
|
+
} : {
|
|
1800
|
+
start: props[params.index - 1].end,
|
|
1801
|
+
end: props[params.index].end,
|
|
1802
|
+
code: ""
|
|
1803
|
+
}
|
|
1804
|
+
]
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
replacements.push({
|
|
1812
|
+
helper: "href_keys",
|
|
1813
|
+
edits: [
|
|
1814
|
+
{ start: node.start, end: optionsNode.start, code: "href_keys`${" },
|
|
1815
|
+
{
|
|
1816
|
+
start: optionsNode.end,
|
|
1817
|
+
end: node.end,
|
|
1818
|
+
code: `}${buildPathTemplate(code, parsed)}\``
|
|
1819
|
+
}
|
|
1820
|
+
]
|
|
1821
|
+
});
|
|
1822
|
+
});
|
|
1823
|
+
return replacements;
|
|
1824
|
+
}
|
|
1825
|
+
function walk(node, visitor) {
|
|
1826
|
+
if (!node || typeof node !== "object") return;
|
|
1827
|
+
if (node.type) {
|
|
1828
|
+
visitor(node);
|
|
1829
|
+
}
|
|
1830
|
+
for (const key of Object.keys(node)) {
|
|
1831
|
+
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range") {
|
|
1832
|
+
continue;
|
|
1833
|
+
}
|
|
1834
|
+
const child = node[key];
|
|
1835
|
+
if (Array.isArray(child)) {
|
|
1836
|
+
for (const item of child) {
|
|
1837
|
+
if (item && typeof item === "object" && item.type) {
|
|
1838
|
+
walk(item, visitor);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
} else if (child && typeof child === "object" && child.type) {
|
|
1842
|
+
walk(child, visitor);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
function parsePathPattern(path7) {
|
|
1847
|
+
const parts = parsePathParts(path7);
|
|
1848
|
+
return { segments: parts.slice(1), params: parts[0] };
|
|
1849
|
+
}
|
|
1850
|
+
function buildPathTemplate(code, parsed, paramsMap) {
|
|
1851
|
+
let template = "";
|
|
1852
|
+
for (let i = 0; i < parsed.params.length; i++) {
|
|
1853
|
+
template += parsed.segments[i];
|
|
1854
|
+
if (paramsMap) {
|
|
1855
|
+
const paramProp = paramsMap.get(parsed.params[i]);
|
|
1856
|
+
const valueNode = paramProp.shorthand ? paramProp.key : paramProp.value;
|
|
1857
|
+
template += "${" + code.slice(valueNode.start, valueNode.end) + "}";
|
|
1858
|
+
} else {
|
|
1859
|
+
template += '${"' + parsed.params[i] + '"}';
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
if (parsed.segments.length > parsed.params.length) {
|
|
1863
|
+
template += parsed.segments[parsed.segments.length - 1];
|
|
1864
|
+
}
|
|
1865
|
+
return template;
|
|
1866
|
+
}
|
|
1867
|
+
function getStaticKey(prop) {
|
|
1868
|
+
if (prop.computed) return null;
|
|
1869
|
+
if (prop.key.type === "Identifier") return prop.key.name;
|
|
1870
|
+
if (prop.key.type === "Literal" && typeof prop.key.value === "string")
|
|
1871
|
+
return prop.key.value;
|
|
1872
|
+
return null;
|
|
1873
|
+
}
|
|
1874
|
+
function tryStaticEval(node) {
|
|
1875
|
+
switch (node.type) {
|
|
1876
|
+
case "Literal":
|
|
1877
|
+
return { value: node.value };
|
|
1878
|
+
case "TemplateLiteral":
|
|
1879
|
+
return node.expressions.length ? null : { value: node.quasis[0].value.cooked };
|
|
1880
|
+
case "ObjectExpression": {
|
|
1881
|
+
const value = {};
|
|
1882
|
+
for (const prop of node.properties) {
|
|
1883
|
+
if (prop.type === "SpreadElement" || prop.shorthand) return null;
|
|
1884
|
+
const key = getStaticKey(prop);
|
|
1885
|
+
if (!key) return null;
|
|
1886
|
+
const val = tryStaticEval(prop.value);
|
|
1887
|
+
if (!val) return null;
|
|
1888
|
+
value[key] = val.value;
|
|
1889
|
+
}
|
|
1890
|
+
return { value };
|
|
1891
|
+
}
|
|
1892
|
+
case "ArrayExpression": {
|
|
1893
|
+
const value = [];
|
|
1894
|
+
for (const elem of node.elements) {
|
|
1895
|
+
if (!elem || elem.type === "SpreadElement") return null;
|
|
1896
|
+
const val = tryStaticEval(elem);
|
|
1897
|
+
if (!val) return null;
|
|
1898
|
+
value.push(val.value);
|
|
1899
|
+
}
|
|
1900
|
+
return { value };
|
|
1901
|
+
}
|
|
1902
|
+
case "UnaryExpression":
|
|
1903
|
+
if (node.prefix && node.operator === "-") {
|
|
1904
|
+
const arg = tryStaticEval(node.argument);
|
|
1905
|
+
if (arg && typeof arg.value === "number") {
|
|
1906
|
+
return { value: -arg.value };
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
return null;
|
|
1910
|
+
default:
|
|
1911
|
+
return null;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
function tryExtractObjectProperty(obj, propertyName) {
|
|
1915
|
+
const props = obj.properties;
|
|
1916
|
+
for (let i = props.length - 1; i >= 0; i--) {
|
|
1917
|
+
const prop = props[i];
|
|
1918
|
+
if (prop.type === "SpreadElement") return null;
|
|
1919
|
+
if (getStaticKey(prop) !== propertyName) continue;
|
|
1920
|
+
if (prop.value.type !== "ObjectExpression") return null;
|
|
1921
|
+
const map = /* @__PURE__ */ new Map();
|
|
1922
|
+
for (const paramProp of prop.value.properties) {
|
|
1923
|
+
if (paramProp.type === "SpreadElement") return null;
|
|
1924
|
+
const paramKey = getStaticKey(paramProp);
|
|
1925
|
+
if (!paramKey) return null;
|
|
1926
|
+
map.set(paramKey, paramProp);
|
|
1927
|
+
}
|
|
1928
|
+
let only = i === props.length - 1;
|
|
1929
|
+
let j = i;
|
|
1930
|
+
while (only && j--) {
|
|
1931
|
+
const prop2 = props[j];
|
|
1932
|
+
only = prop2.type === "Property" && getStaticKey(prop2) === propertyName;
|
|
1933
|
+
}
|
|
1934
|
+
return { map, index: i, only };
|
|
1935
|
+
}
|
|
1936
|
+
return null;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1622
1939
|
// src/vite/utils/log.ts
|
|
1623
1940
|
import zlib from "node:zlib";
|
|
1624
1941
|
import Table from "cli-table3";
|
|
@@ -1803,6 +2120,7 @@ var ReadOncePersistedStore = class {
|
|
|
1803
2120
|
constructor(uid) {
|
|
1804
2121
|
this.uid = uid;
|
|
1805
2122
|
}
|
|
2123
|
+
uid;
|
|
1806
2124
|
write(value) {
|
|
1807
2125
|
values.set(this.uid, value);
|
|
1808
2126
|
}
|
|
@@ -1902,7 +2220,7 @@ function markoRun(opts = {}) {
|
|
|
1902
2220
|
var _a, _b;
|
|
1903
2221
|
routeMarkoApiCache ?? (routeMarkoApiCache = /* @__PURE__ */ new Map());
|
|
1904
2222
|
if (!routeMarkoApiCache.has(route)) {
|
|
1905
|
-
const markoAPI = route.
|
|
2223
|
+
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;
|
|
1906
2224
|
routeMarkoApiCache.set(route, markoAPI);
|
|
1907
2225
|
return markoAPI;
|
|
1908
2226
|
}
|
|
@@ -1924,7 +2242,6 @@ function markoRun(opts = {}) {
|
|
|
1924
2242
|
let buildVirtualFilesResult;
|
|
1925
2243
|
function buildVirtualFiles() {
|
|
1926
2244
|
return buildVirtualFilesResult ?? (buildVirtualFilesResult = (async () => {
|
|
1927
|
-
var _a, _b;
|
|
1928
2245
|
virtualFiles.clear();
|
|
1929
2246
|
if (fs3.existsSync(resolvedRoutesDir)) {
|
|
1930
2247
|
routes = await buildRoutes(
|
|
@@ -1949,9 +2266,8 @@ function markoRun(opts = {}) {
|
|
|
1949
2266
|
entryTemplates = /* @__PURE__ */ new Set();
|
|
1950
2267
|
entryTemplateImporters = /* @__PURE__ */ new Set();
|
|
1951
2268
|
for (const route of routes.list) {
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
entryTemplates.add(normalizePath(routeEntryPath));
|
|
2269
|
+
if (route.templateFilePath) {
|
|
2270
|
+
entryTemplates.add(normalizePath(route.templateFilePath));
|
|
1955
2271
|
}
|
|
1956
2272
|
for (const middleware of route.middleware) {
|
|
1957
2273
|
entryTemplateImporters.add(normalizePath(middleware.filePath));
|
|
@@ -1965,9 +2281,8 @@ function markoRun(opts = {}) {
|
|
|
1965
2281
|
);
|
|
1966
2282
|
}
|
|
1967
2283
|
for (const route of Object.values(routes.special)) {
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
entryTemplates.add(normalizePath(routeEntryPath));
|
|
2284
|
+
if (route.templateFilePath) {
|
|
2285
|
+
entryTemplates.add(normalizePath(route.templateFilePath));
|
|
1971
2286
|
}
|
|
1972
2287
|
}
|
|
1973
2288
|
if (routes.middleware.length) {
|
|
@@ -2022,7 +2337,8 @@ function markoRun(opts = {}) {
|
|
|
2022
2337
|
route.templateFilePath,
|
|
2023
2338
|
renderRouteTemplate(
|
|
2024
2339
|
route,
|
|
2025
|
-
await getMarkoApiForRoute(context, route)
|
|
2340
|
+
await getMarkoApiForRoute(context, route),
|
|
2341
|
+
!isBuild
|
|
2026
2342
|
)
|
|
2027
2343
|
);
|
|
2028
2344
|
}
|
|
@@ -2032,18 +2348,17 @@ function markoRun(opts = {}) {
|
|
|
2032
2348
|
);
|
|
2033
2349
|
}
|
|
2034
2350
|
for (const route of Object.values(routes2.special)) {
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
}
|
|
2351
|
+
fs3.mkdirSync(path6.dirname(route.templateFilePath), {
|
|
2352
|
+
recursive: true
|
|
2353
|
+
});
|
|
2354
|
+
fs3.writeFileSync(
|
|
2355
|
+
route.templateFilePath,
|
|
2356
|
+
renderRouteTemplate(
|
|
2357
|
+
route,
|
|
2358
|
+
await getMarkoApiForRoute(context, route),
|
|
2359
|
+
!isBuild
|
|
2360
|
+
)
|
|
2361
|
+
);
|
|
2047
2362
|
}
|
|
2048
2363
|
if (routes2.middleware.length) {
|
|
2049
2364
|
for (const middleware of routes2.middleware) {
|
|
@@ -2104,7 +2419,7 @@ function markoRun(opts = {}) {
|
|
|
2104
2419
|
}
|
|
2105
2420
|
},
|
|
2106
2421
|
async config(config2, env) {
|
|
2107
|
-
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
|
|
2422
|
+
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;
|
|
2108
2423
|
const externalPluginOptions = getExternalPluginOptions(config2);
|
|
2109
2424
|
if (externalPluginOptions) {
|
|
2110
2425
|
opts = mergeConfig(opts, externalPluginOptions);
|
|
@@ -2151,12 +2466,12 @@ function markoRun(opts = {}) {
|
|
|
2151
2466
|
devEntryFilePosix = normalizePath(devEntryFile);
|
|
2152
2467
|
let outDir = ((_e = config2.build) == null ? void 0 : _e.outDir) || "dist";
|
|
2153
2468
|
const assetsDir = ((_f = config2.build) == null ? void 0 : _f.assetsDir) || "assets";
|
|
2154
|
-
let
|
|
2469
|
+
let rolldownOutputOptions = (_h = (_g = config2.build) == null ? void 0 : _g.rolldownOptions) == null ? void 0 : _h.output;
|
|
2155
2470
|
if (isBuild) {
|
|
2156
2471
|
if (!isSSRBuild) {
|
|
2157
2472
|
outDir = path6.join(outDir, CLIENT_OUT_DIR);
|
|
2158
2473
|
}
|
|
2159
|
-
|
|
2474
|
+
rolldownOutputOptions = mergeOutputOptions(
|
|
2160
2475
|
{
|
|
2161
2476
|
assetFileNames(info) {
|
|
2162
2477
|
var _a2;
|
|
@@ -2170,38 +2485,35 @@ function markoRun(opts = {}) {
|
|
|
2170
2485
|
},
|
|
2171
2486
|
chunkFileNames: isSSRBuild ? `_[hash].js` : `${assetsDir}/_[hash].js`
|
|
2172
2487
|
},
|
|
2173
|
-
|
|
2488
|
+
rolldownOutputOptions
|
|
2174
2489
|
);
|
|
2175
2490
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
}) : void 0;
|
|
2179
|
-
shouldEmptyOutDir = ((_j = config2.build) == null ? void 0 : _j.emptyOutDir) ?? true;
|
|
2180
|
-
const pluginConfig = await ((_k = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _k.call(adapter, config2)) || {};
|
|
2491
|
+
shouldEmptyOutDir = ((_i = config2.build) == null ? void 0 : _i.emptyOutDir) ?? true;
|
|
2492
|
+
const pluginConfig = await ((_j = adapter == null ? void 0 : adapter.viteConfig) == null ? void 0 : _j.call(adapter, config2)) || {};
|
|
2181
2493
|
pluginConfig.ssr ?? (pluginConfig.ssr = {});
|
|
2182
|
-
(
|
|
2494
|
+
(_k = pluginConfig.ssr).noExternal ?? (_k.noExternal = /@marko\/run($|\/)/);
|
|
2183
2495
|
pluginConfig.css ?? (pluginConfig.css = {});
|
|
2184
|
-
(
|
|
2496
|
+
(_l = pluginConfig.css).devSourcemap ?? (_l.devSourcemap = true);
|
|
2185
2497
|
pluginConfig.build ?? (pluginConfig.build = {});
|
|
2186
|
-
(
|
|
2187
|
-
(
|
|
2188
|
-
(
|
|
2189
|
-
(
|
|
2190
|
-
(
|
|
2191
|
-
(
|
|
2192
|
-
if (
|
|
2193
|
-
pluginConfig.build.
|
|
2194
|
-
|
|
2195
|
-
pluginConfig.build.
|
|
2498
|
+
(_m = pluginConfig.build).outDir ?? (_m.outDir = outDir);
|
|
2499
|
+
(_n = pluginConfig.build).assetsDir ?? (_n.assetsDir = assetsDir);
|
|
2500
|
+
(_o = pluginConfig.build).copyPublicDir ?? (_o.copyPublicDir = !isSSRBuild);
|
|
2501
|
+
(_p = pluginConfig.build).ssrEmitAssets ?? (_p.ssrEmitAssets = false);
|
|
2502
|
+
(_q = pluginConfig.build).emptyOutDir ?? (_q.emptyOutDir = false);
|
|
2503
|
+
(_r = pluginConfig.build).rolldownOptions ?? (_r.rolldownOptions = {});
|
|
2504
|
+
if (rolldownOutputOptions) {
|
|
2505
|
+
pluginConfig.build.rolldownOptions.output = mergeOutputOptions(
|
|
2506
|
+
rolldownOutputOptions,
|
|
2507
|
+
pluginConfig.build.rolldownOptions.output
|
|
2196
2508
|
);
|
|
2197
2509
|
}
|
|
2198
|
-
(
|
|
2199
|
-
(
|
|
2510
|
+
(_t = pluginConfig.build).sourcemap ?? (_t.sourcemap = ((_s = config2.build) == null ? void 0 : _s.sourcemap) ?? (isBuild && !isSSRBuild));
|
|
2511
|
+
(_u = pluginConfig.build).modulePreload ?? (_u.modulePreload = {});
|
|
2200
2512
|
if (typeof pluginConfig.build.modulePreload !== "boolean") {
|
|
2201
2513
|
pluginConfig.build.modulePreload.polyfill = false;
|
|
2202
2514
|
}
|
|
2203
2515
|
pluginConfig.optimizeDeps ?? (pluginConfig.optimizeDeps = {});
|
|
2204
|
-
if (!((
|
|
2516
|
+
if (!((_v = config2.optimizeDeps) == null ? void 0 : _v.entries)) {
|
|
2205
2517
|
pluginConfig.optimizeDeps.entries = [
|
|
2206
2518
|
`${normalizePath(path6.relative(root, routesDir))}/**/*+{page,layout}.marko`,
|
|
2207
2519
|
"!**/__snapshots__/**",
|
|
@@ -2209,21 +2521,16 @@ function markoRun(opts = {}) {
|
|
|
2209
2521
|
"!**/coverage/**"
|
|
2210
2522
|
];
|
|
2211
2523
|
}
|
|
2212
|
-
if (
|
|
2213
|
-
|
|
2214
|
-
browserslistTarget,
|
|
2215
|
-
{
|
|
2216
|
-
printUnknownTargets: false
|
|
2217
|
-
}
|
|
2218
|
-
));
|
|
2524
|
+
if (isBuild && !((_w = config2.build) == null ? void 0 : _w.target)) {
|
|
2525
|
+
pluginConfig.build.target = getBrowserslistTargets(root);
|
|
2219
2526
|
}
|
|
2220
2527
|
if (isBuild) {
|
|
2221
2528
|
pluginConfig.logLevel ?? (pluginConfig.logLevel = "warn");
|
|
2222
2529
|
pluginConfig.define ?? (pluginConfig.define = {});
|
|
2223
|
-
(
|
|
2530
|
+
(_x = pluginConfig.define)["process.env.NODE_ENV"] ?? (_x["process.env.NODE_ENV"] = "'production'");
|
|
2224
2531
|
pluginConfig.resolve ?? (pluginConfig.resolve = {});
|
|
2225
|
-
(
|
|
2226
|
-
(
|
|
2532
|
+
(_y = pluginConfig.resolve).mainFields ?? (_y.mainFields = (isSSRBuild ? [] : ["browser"]).concat(["module", "jsnext:main", "jsnext", "main"]));
|
|
2533
|
+
(_z = pluginConfig.resolve).conditions ?? (_z.conditions = [
|
|
2227
2534
|
isSSRBuild ? "node" : "browser",
|
|
2228
2535
|
"import",
|
|
2229
2536
|
"require",
|
|
@@ -2237,7 +2544,7 @@ function markoRun(opts = {}) {
|
|
|
2237
2544
|
resolvedConfig = config2;
|
|
2238
2545
|
const {
|
|
2239
2546
|
ssr,
|
|
2240
|
-
|
|
2547
|
+
rolldownOptions: { input }
|
|
2241
2548
|
} = config2.build;
|
|
2242
2549
|
if (typeof ssr === "string") {
|
|
2243
2550
|
ssrEntryFiles = [ssr];
|
|
@@ -2356,6 +2663,48 @@ function markoRun(opts = {}) {
|
|
|
2356
2663
|
{
|
|
2357
2664
|
name: `${PLUGIN_NAME_PREFIX}:post`,
|
|
2358
2665
|
enforce: "post",
|
|
2666
|
+
async transform(code) {
|
|
2667
|
+
if (!isBuild || isSSRBuild || !code.includes("Run.href")) {
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
try {
|
|
2671
|
+
const replacements = findHrefReplacements(
|
|
2672
|
+
code,
|
|
2673
|
+
this.parse(code, { lang: "js" })
|
|
2674
|
+
);
|
|
2675
|
+
if (replacements.length) {
|
|
2676
|
+
const helpers = /* @__PURE__ */ new Set();
|
|
2677
|
+
const s = new RolldownMagicString(code);
|
|
2678
|
+
for (const { helper, edits } of replacements) {
|
|
2679
|
+
for (const { start, end, code: code2 } of edits) {
|
|
2680
|
+
if (code2) {
|
|
2681
|
+
s.overwrite(start, end, code2);
|
|
2682
|
+
} else {
|
|
2683
|
+
s.remove(start, end);
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
if (helper) {
|
|
2687
|
+
helpers.add(helper);
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
if (helpers.size) {
|
|
2691
|
+
s.prepend(
|
|
2692
|
+
`import { ${[...helpers].join(", ")} } from "virtual:marko-run/runtime/url-builder";`
|
|
2693
|
+
);
|
|
2694
|
+
}
|
|
2695
|
+
return {
|
|
2696
|
+
code: s
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
return null;
|
|
2700
|
+
} catch {
|
|
2701
|
+
return {
|
|
2702
|
+
code: new RolldownMagicString(code).prepend(
|
|
2703
|
+
'import "virtual:marko-run/runtime/client";'
|
|
2704
|
+
)
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
},
|
|
2359
2708
|
generateBundle(options, bundle) {
|
|
2360
2709
|
if (options.sourcemap && options.sourcemap !== "inline") {
|
|
2361
2710
|
for (const key of Object.keys(bundle)) {
|
|
@@ -2521,6 +2870,33 @@ var defaultConfigPlugin = {
|
|
|
2521
2870
|
};
|
|
2522
2871
|
}
|
|
2523
2872
|
};
|
|
2873
|
+
function getBrowserslistTargets(path7) {
|
|
2874
|
+
var _a;
|
|
2875
|
+
const browserslistTarget = browserslist(void 0, { path: path7 });
|
|
2876
|
+
if (browserslistTarget.length) {
|
|
2877
|
+
const versions = /* @__PURE__ */ new Map();
|
|
2878
|
+
for (const target of resolveToEsbuildTarget(browserslistTarget, {
|
|
2879
|
+
printUnknownTargets: false
|
|
2880
|
+
})) {
|
|
2881
|
+
const index = (_a = /\d/.exec(target)) == null ? void 0 : _a.index;
|
|
2882
|
+
if (index) {
|
|
2883
|
+
const browser = target.slice(0, index);
|
|
2884
|
+
const version = Number(target.slice(index));
|
|
2885
|
+
const existingVersion = versions.get(browser);
|
|
2886
|
+
if (!existingVersion || version < existingVersion) {
|
|
2887
|
+
versions.set(browser, version);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
if (versions.size) {
|
|
2892
|
+
const targets = [];
|
|
2893
|
+
for (const [browser, version] of versions) {
|
|
2894
|
+
targets.push(browser + version);
|
|
2895
|
+
}
|
|
2896
|
+
return targets;
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2524
2900
|
|
|
2525
2901
|
// src/vite/utils/meta-data.ts
|
|
2526
2902
|
var verbKeys = new Set(httpVerbs.map((v) => v.toUpperCase()));
|