@react-router/dev 0.0.0-experimental-aecfb0db1 → 0.0.0-experimental-5bbc45fb6
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/cli/index.js +347 -217
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +341 -214
- package/package.json +6 -6
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-5bbc45fb6
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -59,10 +59,9 @@ var import_picocolors3 = __toESM(require("picocolors"));
|
|
|
59
59
|
var import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
60
60
|
|
|
61
61
|
// typegen/index.ts
|
|
62
|
-
var
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var import_picocolors2 = __toESM(require("picocolors"));
|
|
62
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
63
|
+
var Path4 = __toESM(require("pathe"));
|
|
64
|
+
var import_picocolors2 = require("picocolors");
|
|
66
65
|
|
|
67
66
|
// config/config.ts
|
|
68
67
|
var import_node_fs = __toESM(require("fs"));
|
|
@@ -414,7 +413,7 @@ async function resolveConfig({
|
|
|
414
413
|
);
|
|
415
414
|
let {
|
|
416
415
|
appDirectory: userAppDirectory,
|
|
417
|
-
basename:
|
|
416
|
+
basename: basename3,
|
|
418
417
|
buildDirectory: userBuildDirectory,
|
|
419
418
|
buildEnd,
|
|
420
419
|
prerender,
|
|
@@ -529,7 +528,7 @@ async function resolveConfig({
|
|
|
529
528
|
};
|
|
530
529
|
let reactRouterConfig = deepFreeze({
|
|
531
530
|
appDirectory,
|
|
532
|
-
basename:
|
|
531
|
+
basename: basename3,
|
|
533
532
|
buildDirectory,
|
|
534
533
|
buildEnd,
|
|
535
534
|
future,
|
|
@@ -592,11 +591,11 @@ async function createConfigLoader({
|
|
|
592
591
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
593
592
|
ignoreInitial: true,
|
|
594
593
|
ignored: (path6) => {
|
|
595
|
-
let
|
|
596
|
-
return !
|
|
594
|
+
let dirname4 = import_pathe3.default.dirname(path6);
|
|
595
|
+
return !dirname4.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
597
596
|
// that are at the root level, not nested in subdirectories
|
|
598
597
|
path6 !== root && // Watch the root directory itself
|
|
599
|
-
|
|
598
|
+
dirname4 !== root;
|
|
600
599
|
}
|
|
601
600
|
});
|
|
602
601
|
fsWatcher.on("all", async (...args) => {
|
|
@@ -736,15 +735,15 @@ function omitRoutes(config) {
|
|
|
736
735
|
};
|
|
737
736
|
}
|
|
738
737
|
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
739
|
-
function isEntryFile(entryBasename,
|
|
740
|
-
return entryExts.some((ext) =>
|
|
738
|
+
function isEntryFile(entryBasename, filename2) {
|
|
739
|
+
return entryExts.some((ext) => filename2 === `${entryBasename}${ext}`);
|
|
741
740
|
}
|
|
742
|
-
function findEntry(dir,
|
|
741
|
+
function findEntry(dir, basename3, options) {
|
|
743
742
|
let currentDir = import_pathe3.default.resolve(dir);
|
|
744
743
|
let { root } = import_pathe3.default.parse(currentDir);
|
|
745
744
|
while (true) {
|
|
746
745
|
for (let ext of options?.extensions ?? entryExts) {
|
|
747
|
-
let file = import_pathe3.default.resolve(currentDir,
|
|
746
|
+
let file = import_pathe3.default.resolve(currentDir, basename3 + ext);
|
|
748
747
|
if (import_node_fs.default.existsSync(file)) {
|
|
749
748
|
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
750
749
|
}
|
|
@@ -784,6 +783,30 @@ function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /
|
|
|
784
783
|
return false;
|
|
785
784
|
}
|
|
786
785
|
|
|
786
|
+
// typegen/context.ts
|
|
787
|
+
async function createContext2({
|
|
788
|
+
rootDirectory,
|
|
789
|
+
watch: watch2,
|
|
790
|
+
mode
|
|
791
|
+
}) {
|
|
792
|
+
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
793
|
+
const configResult = await configLoader.getConfig();
|
|
794
|
+
if (!configResult.ok) {
|
|
795
|
+
throw new Error(configResult.error);
|
|
796
|
+
}
|
|
797
|
+
const config = configResult.value;
|
|
798
|
+
return {
|
|
799
|
+
configLoader,
|
|
800
|
+
rootDirectory,
|
|
801
|
+
config
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// typegen/generate.ts
|
|
806
|
+
var import_dedent = __toESM(require("dedent"));
|
|
807
|
+
var Path3 = __toESM(require("pathe"));
|
|
808
|
+
var Pathe = __toESM(require("pathe/utils"));
|
|
809
|
+
|
|
787
810
|
// vite/babel.ts
|
|
788
811
|
var babel_exports = {};
|
|
789
812
|
__export(babel_exports, {
|
|
@@ -797,26 +820,6 @@ var t = __toESM(require("@babel/types"));
|
|
|
797
820
|
var traverse = require("@babel/traverse").default;
|
|
798
821
|
var generate = require("@babel/generator").default;
|
|
799
822
|
|
|
800
|
-
// typegen/generate.ts
|
|
801
|
-
var import_dedent = __toESM(require("dedent"));
|
|
802
|
-
var Path4 = __toESM(require("pathe"));
|
|
803
|
-
var Pathe2 = __toESM(require("pathe/utils"));
|
|
804
|
-
|
|
805
|
-
// typegen/paths.ts
|
|
806
|
-
var Path3 = __toESM(require("pathe"));
|
|
807
|
-
var Pathe = __toESM(require("pathe/utils"));
|
|
808
|
-
function getTypesDir(ctx) {
|
|
809
|
-
return Path3.join(ctx.rootDirectory, ".react-router/types");
|
|
810
|
-
}
|
|
811
|
-
function getTypesPath(ctx, route) {
|
|
812
|
-
return Path3.join(
|
|
813
|
-
getTypesDir(ctx),
|
|
814
|
-
Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
815
|
-
Path3.dirname(route.file),
|
|
816
|
-
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
817
|
-
);
|
|
818
|
-
}
|
|
819
|
-
|
|
820
823
|
// typegen/params.ts
|
|
821
824
|
function parse2(fullpath2) {
|
|
822
825
|
const result = {};
|
|
@@ -851,92 +854,312 @@ function fullpath(lineage2) {
|
|
|
851
854
|
}
|
|
852
855
|
|
|
853
856
|
// typegen/generate.ts
|
|
854
|
-
function
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
const
|
|
859
|
-
const
|
|
860
|
-
|
|
861
|
-
Path4.dirname(typesPath),
|
|
862
|
-
getTypesPath(ctx, parent)
|
|
863
|
-
);
|
|
864
|
-
const indent = i === 0 ? "" : " ".repeat(2);
|
|
865
|
-
let source = noExtension(rel);
|
|
866
|
-
if (!source.startsWith("../")) source = "./" + source;
|
|
867
|
-
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
868
|
-
}).join("\n");
|
|
869
|
-
return import_dedent.default`
|
|
870
|
-
// React Router generated types for route:
|
|
871
|
-
// ${route.file}
|
|
872
|
-
|
|
873
|
-
import type * as T from "react-router/route-module"
|
|
857
|
+
function typesDirectory(ctx) {
|
|
858
|
+
return Path3.join(ctx.rootDirectory, ".react-router/types");
|
|
859
|
+
}
|
|
860
|
+
function generateFuture(ctx) {
|
|
861
|
+
const filename2 = Path3.join(typesDirectory(ctx), "+future.ts");
|
|
862
|
+
const content = import_dedent.default`
|
|
863
|
+
// Generated by React Router
|
|
874
864
|
|
|
875
|
-
|
|
865
|
+
import "react-router";
|
|
876
866
|
|
|
877
|
-
|
|
867
|
+
declare module "react-router" {
|
|
868
|
+
interface Future {
|
|
869
|
+
unstable_middleware: ${ctx.config.future.unstable_middleware}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
`;
|
|
873
|
+
return { filename: filename2, content };
|
|
874
|
+
}
|
|
875
|
+
function generateServerBuild(ctx) {
|
|
876
|
+
const filename2 = Path3.join(typesDirectory(ctx), "+server-build.d.ts");
|
|
877
|
+
const content = import_dedent.default`
|
|
878
|
+
// Generated by React Router
|
|
878
879
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
880
|
+
declare module "virtual:react-router/server-build" {
|
|
881
|
+
import { ServerBuild } from "react-router";
|
|
882
|
+
export const assets: ServerBuild["assets"];
|
|
883
|
+
export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
|
|
884
|
+
export const basename: ServerBuild["basename"];
|
|
885
|
+
export const entry: ServerBuild["entry"];
|
|
886
|
+
export const future: ServerBuild["future"];
|
|
887
|
+
export const isSpaMode: ServerBuild["isSpaMode"];
|
|
888
|
+
export const prerender: ServerBuild["prerender"];
|
|
889
|
+
export const publicPath: ServerBuild["publicPath"];
|
|
890
|
+
export const routeDiscovery: ServerBuild["routeDiscovery"];
|
|
891
|
+
export const routes: ServerBuild["routes"];
|
|
892
|
+
export const ssr: ServerBuild["ssr"];
|
|
893
|
+
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
890
894
|
}
|
|
895
|
+
`;
|
|
896
|
+
return { filename: filename2, content };
|
|
897
|
+
}
|
|
898
|
+
var { t: t2 } = babel_exports;
|
|
899
|
+
function generatePages(ctx) {
|
|
900
|
+
const filename2 = Path3.join(typesDirectory(ctx), "+pages.ts");
|
|
901
|
+
const fullpaths = /* @__PURE__ */ new Set();
|
|
902
|
+
Object.values(ctx.config.routes).forEach((route) => {
|
|
903
|
+
if (route.id !== "root" && !route.path) return;
|
|
904
|
+
const lineage2 = lineage(ctx.config.routes, route);
|
|
905
|
+
const fullpath2 = fullpath(lineage2);
|
|
906
|
+
fullpaths.add(fullpath2);
|
|
907
|
+
});
|
|
908
|
+
const pagesType = t2.tsTypeAliasDeclaration(
|
|
909
|
+
t2.identifier("Pages"),
|
|
910
|
+
null,
|
|
911
|
+
t2.tsTypeLiteral(
|
|
912
|
+
Array.from(fullpaths).map((fullpath2) => {
|
|
913
|
+
return t2.tsPropertySignature(
|
|
914
|
+
t2.stringLiteral(fullpath2),
|
|
915
|
+
t2.tsTypeAnnotation(
|
|
916
|
+
t2.tsTypeLiteral([
|
|
917
|
+
t2.tsPropertySignature(
|
|
918
|
+
t2.identifier("params"),
|
|
919
|
+
t2.tsTypeAnnotation(paramsType(fullpath2))
|
|
920
|
+
)
|
|
921
|
+
])
|
|
922
|
+
)
|
|
923
|
+
);
|
|
924
|
+
})
|
|
925
|
+
)
|
|
926
|
+
);
|
|
927
|
+
const content = import_dedent.default`
|
|
928
|
+
// Generated by React Router
|
|
891
929
|
|
|
892
|
-
|
|
893
|
-
export type LinkDescriptors = T.LinkDescriptors
|
|
894
|
-
export type LinksFunction = () => LinkDescriptors
|
|
930
|
+
import "react-router"
|
|
895
931
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
932
|
+
declare module "react-router" {
|
|
933
|
+
interface Register {
|
|
934
|
+
pages: Pages
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
` + "\n\n" + generate(pagesType).code;
|
|
938
|
+
return { filename: filename2, content };
|
|
939
|
+
}
|
|
940
|
+
function generateRoutes(ctx) {
|
|
941
|
+
const filename2 = Path3.join(typesDirectory(ctx), "+routes-pre.ts");
|
|
942
|
+
const routesType = t2.tsTypeAliasDeclaration(
|
|
943
|
+
t2.identifier("routesPre"),
|
|
944
|
+
null,
|
|
945
|
+
t2.tsTypeLiteral(
|
|
946
|
+
Object.values(ctx.config.routes).map((route) => {
|
|
947
|
+
return t2.tsPropertySignature(
|
|
948
|
+
t2.stringLiteral(route.id),
|
|
949
|
+
t2.tsTypeAnnotation(
|
|
950
|
+
t2.tsTypeLiteral([
|
|
951
|
+
t2.tsPropertySignature(
|
|
952
|
+
t2.identifier("parentId"),
|
|
953
|
+
t2.tsTypeAnnotation(
|
|
954
|
+
route.parentId ? t2.tsLiteralType(t2.stringLiteral(route.parentId)) : t2.tsUndefinedKeyword()
|
|
955
|
+
)
|
|
956
|
+
),
|
|
957
|
+
t2.tsPropertySignature(
|
|
958
|
+
t2.identifier("path"),
|
|
959
|
+
t2.tsTypeAnnotation(
|
|
960
|
+
route.path ? t2.tsLiteralType(t2.stringLiteral(route.path)) : t2.tsUndefinedKeyword()
|
|
961
|
+
)
|
|
962
|
+
),
|
|
963
|
+
t2.tsPropertySignature(
|
|
964
|
+
t2.identifier("params"),
|
|
965
|
+
t2.tsTypeAnnotation(paramsType(route.path ?? ""))
|
|
966
|
+
),
|
|
967
|
+
t2.tsPropertySignature(
|
|
968
|
+
t2.identifier("index"),
|
|
969
|
+
t2.tsTypeAnnotation(
|
|
970
|
+
t2.tsLiteralType(t2.booleanLiteral(route.index ?? false))
|
|
971
|
+
)
|
|
972
|
+
),
|
|
973
|
+
t2.tsPropertySignature(
|
|
974
|
+
t2.identifier("file"),
|
|
975
|
+
t2.tsTypeAnnotation(t2.tsLiteralType(t2.stringLiteral(route.file)))
|
|
976
|
+
)
|
|
977
|
+
])
|
|
978
|
+
)
|
|
979
|
+
);
|
|
980
|
+
})
|
|
981
|
+
)
|
|
982
|
+
);
|
|
983
|
+
const content = import_dedent.default`
|
|
984
|
+
// Generated by React Router
|
|
899
985
|
|
|
900
|
-
|
|
901
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
986
|
+
import "react-router"
|
|
902
987
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
988
|
+
declare module "react-router" {
|
|
989
|
+
interface Register {
|
|
990
|
+
routesPre: routesPre
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
` + "\n\n" + generate(routesType).code;
|
|
994
|
+
return { filename: filename2, content };
|
|
995
|
+
}
|
|
996
|
+
function generateRouteModuleAnnotations(ctx) {
|
|
997
|
+
return Object.values(ctx.config.routes).map((route) => {
|
|
998
|
+
const filename2 = getRouteModuleAnnotationsFilepath(ctx, route);
|
|
999
|
+
const parents = getParents(ctx, route);
|
|
1000
|
+
const content = import_dedent.default`
|
|
1001
|
+
// Generated by React Router
|
|
909
1002
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1003
|
+
import type {
|
|
1004
|
+
Params,
|
|
1005
|
+
RouteModuleAnnotations,
|
|
1006
|
+
CreateLoaderData,
|
|
1007
|
+
CreateActionData,
|
|
1008
|
+
} from "react-router/internal";
|
|
1009
|
+
|
|
1010
|
+
${parents.map((parent) => parent.import).join("\n" + " ".repeat(3))}
|
|
1011
|
+
type Parents = [${parents.map((parent) => parent.name).join(", ")}]
|
|
1012
|
+
|
|
1013
|
+
type Id = "${route.id}"
|
|
1014
|
+
type Module = typeof import("../${Pathe.filename(route.file)}.js")
|
|
1015
|
+
|
|
1016
|
+
export type unstable_Props = {
|
|
1017
|
+
params: Params[Id]
|
|
1018
|
+
loaderData: CreateLoaderData<Module>
|
|
1019
|
+
actionData: CreateActionData<Module>
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
type Annotations = RouteModuleAnnotations<unstable_Props & {
|
|
1023
|
+
parents: Parents,
|
|
1024
|
+
module: Module,
|
|
1025
|
+
}>;
|
|
1026
|
+
|
|
1027
|
+
export namespace Route {
|
|
1028
|
+
// links
|
|
1029
|
+
export type LinkDescriptors = Annotations["LinkDescriptors"];
|
|
1030
|
+
export type LinksFunction = Annotations["LinksFunction"];
|
|
1031
|
+
|
|
1032
|
+
// meta
|
|
1033
|
+
export type MetaArgs = Annotations["MetaArgs"];
|
|
1034
|
+
export type MetaDescriptors = Annotations["MetaDescriptors"];
|
|
1035
|
+
export type MetaFunction = Annotations["MetaFunction"];
|
|
1036
|
+
|
|
1037
|
+
// headers
|
|
1038
|
+
export type HeadersArgs = Annotations["HeadersArgs"];
|
|
1039
|
+
export type HeadersFunction = Annotations["HeadersFunction"];
|
|
1040
|
+
|
|
1041
|
+
// unstable_middleware
|
|
1042
|
+
export type unstable_MiddlewareFunction = Annotations["unstable_MiddlewareFunction"];
|
|
1043
|
+
|
|
1044
|
+
// unstable_clientMiddleware
|
|
1045
|
+
export type unstable_ClientMiddlewareFunction = Annotations["unstable_ClientMiddlewareFunction"];
|
|
1046
|
+
|
|
1047
|
+
// loader
|
|
1048
|
+
export type LoaderArgs = Annotations["LoaderArgs"];
|
|
1049
|
+
|
|
1050
|
+
// clientLoader
|
|
1051
|
+
export type ClientLoaderArgs = Annotations["ClientLoaderArgs"];
|
|
1052
|
+
|
|
1053
|
+
// action
|
|
1054
|
+
export type ActionArgs = Annotations["ActionArgs"];
|
|
1055
|
+
|
|
1056
|
+
// clientAction
|
|
1057
|
+
export type ClientActionArgs = Annotations["ClientActionArgs"];
|
|
1058
|
+
|
|
1059
|
+
// HydrateFallback
|
|
1060
|
+
export type HydrateFallbackProps = Annotations["HydrateFallbackProps"];
|
|
1061
|
+
|
|
1062
|
+
// Component
|
|
1063
|
+
export type ComponentProps = Annotations["ComponentProps"];
|
|
1064
|
+
|
|
1065
|
+
// ErrorBoundary
|
|
1066
|
+
export type ErrorBoundaryProps = Annotations["ErrorBoundaryProps"];
|
|
1067
|
+
}
|
|
1068
|
+
`;
|
|
1069
|
+
return { filename: filename2, content };
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
function getRouteModuleAnnotationsFilepath(ctx, route) {
|
|
1073
|
+
return Path3.join(
|
|
1074
|
+
typesDirectory(ctx),
|
|
1075
|
+
Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
1076
|
+
Path3.dirname(route.file),
|
|
1077
|
+
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
1078
|
+
);
|
|
915
1079
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
const
|
|
919
|
-
const
|
|
920
|
-
|
|
1080
|
+
function getParents(ctx, route) {
|
|
1081
|
+
const typesPath = getRouteModuleAnnotationsFilepath(ctx, route);
|
|
1082
|
+
const lineage2 = lineage(ctx.config.routes, route);
|
|
1083
|
+
const parents = lineage2.slice(0, -1);
|
|
1084
|
+
return parents.map((parent, i) => {
|
|
1085
|
+
const rel = Path3.relative(
|
|
1086
|
+
Path3.dirname(typesPath),
|
|
1087
|
+
getRouteModuleAnnotationsFilepath(ctx, parent)
|
|
1088
|
+
);
|
|
1089
|
+
let source = noExtension(rel);
|
|
1090
|
+
if (!source.startsWith("../")) source = "./" + source;
|
|
1091
|
+
const name = `Parent${i}`;
|
|
1092
|
+
return {
|
|
1093
|
+
name,
|
|
1094
|
+
import: `import type { unstable_Props as ${name} } from "${source}.js"`
|
|
1095
|
+
};
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
function noExtension(path6) {
|
|
1099
|
+
return Path3.join(Path3.dirname(path6), Pathe.filename(path6));
|
|
1100
|
+
}
|
|
1101
|
+
function paramsType(path6) {
|
|
1102
|
+
const params = parse2(path6);
|
|
1103
|
+
return t2.tsTypeLiteral(
|
|
1104
|
+
Object.entries(params).map(([param, isRequired]) => {
|
|
1105
|
+
const property = t2.tsPropertySignature(
|
|
1106
|
+
t2.stringLiteral(param),
|
|
1107
|
+
t2.tsTypeAnnotation(t2.tsStringKeyword())
|
|
1108
|
+
);
|
|
1109
|
+
property.optional = !isRequired;
|
|
1110
|
+
return property;
|
|
1111
|
+
})
|
|
921
1112
|
);
|
|
922
|
-
return properties.join("; ");
|
|
923
1113
|
}
|
|
924
1114
|
|
|
925
1115
|
// typegen/index.ts
|
|
1116
|
+
async function clearRouteModuleAnnotations(ctx) {
|
|
1117
|
+
await import_promises.default.rm(
|
|
1118
|
+
Path4.join(typesDirectory(ctx), Path4.basename(ctx.config.appDirectory)),
|
|
1119
|
+
{ recursive: true, force: true }
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
async function write(...files) {
|
|
1123
|
+
return Promise.all(
|
|
1124
|
+
files.map(async ({ filename: filename2, content }) => {
|
|
1125
|
+
await import_promises.default.mkdir(Path4.dirname(filename2), { recursive: true });
|
|
1126
|
+
await import_promises.default.writeFile(filename2, content);
|
|
1127
|
+
})
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
926
1130
|
async function watch(rootDirectory, { mode, logger }) {
|
|
927
1131
|
const ctx = await createContext2({ rootDirectory, mode, watch: true });
|
|
928
|
-
await
|
|
929
|
-
|
|
1132
|
+
await clearRouteModuleAnnotations(ctx);
|
|
1133
|
+
await write(
|
|
1134
|
+
generateFuture(ctx),
|
|
1135
|
+
generatePages(ctx),
|
|
1136
|
+
generateRoutes(ctx),
|
|
1137
|
+
generateServerBuild(ctx),
|
|
1138
|
+
...generateRouteModuleAnnotations(ctx)
|
|
1139
|
+
);
|
|
1140
|
+
logger?.info((0, import_picocolors2.green)("generated types"), { timestamp: true, clear: true });
|
|
930
1141
|
ctx.configLoader.onChange(
|
|
931
1142
|
async ({ result, configChanged, routeConfigChanged }) => {
|
|
932
1143
|
if (!result.ok) {
|
|
933
|
-
logger?.error(import_picocolors2.
|
|
1144
|
+
logger?.error((0, import_picocolors2.red)(result.error), { timestamp: true, clear: true });
|
|
934
1145
|
return;
|
|
935
1146
|
}
|
|
936
1147
|
ctx.config = result.value;
|
|
937
|
-
if (configChanged
|
|
938
|
-
await
|
|
939
|
-
logger?.info(import_picocolors2.
|
|
1148
|
+
if (configChanged) {
|
|
1149
|
+
await write(generateFuture(ctx));
|
|
1150
|
+
logger?.info((0, import_picocolors2.green)("regenerated types"), {
|
|
1151
|
+
timestamp: true,
|
|
1152
|
+
clear: true
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
if (routeConfigChanged) {
|
|
1156
|
+
await clearRouteModuleAnnotations(ctx);
|
|
1157
|
+
await write(
|
|
1158
|
+
generatePages(ctx),
|
|
1159
|
+
generateRoutes(ctx),
|
|
1160
|
+
...generateRouteModuleAnnotations(ctx)
|
|
1161
|
+
);
|
|
1162
|
+
logger?.info((0, import_picocolors2.green)("regenerated types"), {
|
|
940
1163
|
timestamp: true,
|
|
941
1164
|
clear: true
|
|
942
1165
|
});
|
|
@@ -947,102 +1170,6 @@ async function watch(rootDirectory, { mode, logger }) {
|
|
|
947
1170
|
close: async () => await ctx.configLoader.close()
|
|
948
1171
|
};
|
|
949
1172
|
}
|
|
950
|
-
async function createContext2({
|
|
951
|
-
rootDirectory,
|
|
952
|
-
watch: watch2,
|
|
953
|
-
mode
|
|
954
|
-
}) {
|
|
955
|
-
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
956
|
-
const configResult = await configLoader.getConfig();
|
|
957
|
-
if (!configResult.ok) {
|
|
958
|
-
throw new Error(configResult.error);
|
|
959
|
-
}
|
|
960
|
-
const config = configResult.value;
|
|
961
|
-
return {
|
|
962
|
-
configLoader,
|
|
963
|
-
rootDirectory,
|
|
964
|
-
config
|
|
965
|
-
};
|
|
966
|
-
}
|
|
967
|
-
async function writeAll(ctx) {
|
|
968
|
-
const typegenDir = getTypesDir(ctx);
|
|
969
|
-
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
970
|
-
Object.values(ctx.config.routes).forEach((route) => {
|
|
971
|
-
const typesPath = getTypesPath(ctx, route);
|
|
972
|
-
const content = generate2(ctx, route);
|
|
973
|
-
import_node_fs2.default.mkdirSync(Path5.dirname(typesPath), { recursive: true });
|
|
974
|
-
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
975
|
-
});
|
|
976
|
-
const registerPath = Path5.join(typegenDir, "+register.ts");
|
|
977
|
-
import_node_fs2.default.writeFileSync(registerPath, register(ctx));
|
|
978
|
-
const virtualPath = Path5.join(typegenDir, "+virtual.d.ts");
|
|
979
|
-
import_node_fs2.default.writeFileSync(virtualPath, virtual);
|
|
980
|
-
}
|
|
981
|
-
function register(ctx) {
|
|
982
|
-
const register2 = import_dedent2.default`
|
|
983
|
-
import "react-router";
|
|
984
|
-
|
|
985
|
-
declare module "react-router" {
|
|
986
|
-
interface Register {
|
|
987
|
-
params: Params;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
interface Future {
|
|
991
|
-
unstable_middleware: ${ctx.config.future.unstable_middleware}
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
`;
|
|
995
|
-
const { t: t2 } = babel_exports;
|
|
996
|
-
const fullpaths = /* @__PURE__ */ new Set();
|
|
997
|
-
Object.values(ctx.config.routes).forEach((route) => {
|
|
998
|
-
if (route.id !== "root" && !route.path) return;
|
|
999
|
-
const lineage2 = lineage(ctx.config.routes, route);
|
|
1000
|
-
const fullpath2 = fullpath(lineage2);
|
|
1001
|
-
fullpaths.add(fullpath2);
|
|
1002
|
-
});
|
|
1003
|
-
const typeParams = t2.tsTypeAliasDeclaration(
|
|
1004
|
-
t2.identifier("Params"),
|
|
1005
|
-
null,
|
|
1006
|
-
t2.tsTypeLiteral(
|
|
1007
|
-
Array.from(fullpaths).map((fullpath2) => {
|
|
1008
|
-
const params = parse2(fullpath2);
|
|
1009
|
-
return t2.tsPropertySignature(
|
|
1010
|
-
t2.stringLiteral(fullpath2),
|
|
1011
|
-
t2.tsTypeAnnotation(
|
|
1012
|
-
t2.tsTypeLiteral(
|
|
1013
|
-
Object.entries(params).map(([param, isRequired]) => {
|
|
1014
|
-
const property = t2.tsPropertySignature(
|
|
1015
|
-
t2.stringLiteral(param),
|
|
1016
|
-
t2.tsTypeAnnotation(t2.tsStringKeyword())
|
|
1017
|
-
);
|
|
1018
|
-
property.optional = !isRequired;
|
|
1019
|
-
return property;
|
|
1020
|
-
})
|
|
1021
|
-
)
|
|
1022
|
-
)
|
|
1023
|
-
);
|
|
1024
|
-
})
|
|
1025
|
-
)
|
|
1026
|
-
);
|
|
1027
|
-
return [register2, generate(typeParams).code].join("\n\n");
|
|
1028
|
-
}
|
|
1029
|
-
var virtual = import_dedent2.default`
|
|
1030
|
-
declare module "virtual:react-router/server-build" {
|
|
1031
|
-
import { ServerBuild } from "react-router";
|
|
1032
|
-
export const assets: ServerBuild["assets"];
|
|
1033
|
-
export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
|
|
1034
|
-
export const basename: ServerBuild["basename"];
|
|
1035
|
-
export const entry: ServerBuild["entry"];
|
|
1036
|
-
export const future: ServerBuild["future"];
|
|
1037
|
-
export const isSpaMode: ServerBuild["isSpaMode"];
|
|
1038
|
-
export const prerender: ServerBuild["prerender"];
|
|
1039
|
-
export const publicPath: ServerBuild["publicPath"];
|
|
1040
|
-
export const routeDiscovery: ServerBuild["routeDiscovery"];
|
|
1041
|
-
export const routes: ServerBuild["routes"];
|
|
1042
|
-
export const ssr: ServerBuild["ssr"];
|
|
1043
|
-
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
1044
|
-
}
|
|
1045
|
-
`;
|
|
1046
1173
|
|
|
1047
1174
|
// vite/node-adapter.ts
|
|
1048
1175
|
var import_node_events = require("events");
|
|
@@ -2030,7 +2157,7 @@ function getRouteChunkNameFromModuleId(id) {
|
|
|
2030
2157
|
}
|
|
2031
2158
|
|
|
2032
2159
|
// vite/with-props.ts
|
|
2033
|
-
var
|
|
2160
|
+
var import_dedent2 = __toESM(require("dedent"));
|
|
2034
2161
|
var vmod = create("with-props");
|
|
2035
2162
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
2036
2163
|
var plugin = {
|
|
@@ -2041,7 +2168,7 @@ var plugin = {
|
|
|
2041
2168
|
},
|
|
2042
2169
|
async load(id) {
|
|
2043
2170
|
if (id !== vmod.resolvedId) return;
|
|
2044
|
-
return
|
|
2171
|
+
return import_dedent2.default`
|
|
2045
2172
|
import { createElement as h } from "react";
|
|
2046
2173
|
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
2047
2174
|
|
|
@@ -2201,7 +2328,7 @@ var isRouteVirtualModule = (id) => {
|
|
|
2201
2328
|
return isRouteEntryModuleId(id) || isRouteChunkModuleId(id);
|
|
2202
2329
|
};
|
|
2203
2330
|
var isServerBuildVirtualModuleId = (id) => {
|
|
2204
|
-
return id.split("?")[0] ===
|
|
2331
|
+
return id.split("?")[0] === virtual.serverBuild.id;
|
|
2205
2332
|
};
|
|
2206
2333
|
var getServerBuildFile = (viteManifest) => {
|
|
2207
2334
|
let serverBuildIds = Object.keys(viteManifest).filter(
|
|
@@ -2231,13 +2358,13 @@ var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
|
2231
2358
|
let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
|
|
2232
2359
|
return vite2.normalizePath(fullPath);
|
|
2233
2360
|
};
|
|
2234
|
-
var
|
|
2361
|
+
var virtual = {
|
|
2235
2362
|
serverBuild: create("server-build"),
|
|
2236
2363
|
serverManifest: create("server-manifest"),
|
|
2237
2364
|
browserManifest: create("browser-manifest")
|
|
2238
2365
|
};
|
|
2239
2366
|
var invalidateVirtualModules = (viteDevServer) => {
|
|
2240
|
-
Object.values(
|
|
2367
|
+
Object.values(virtual).forEach((vmod2) => {
|
|
2241
2368
|
let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
|
|
2242
2369
|
if (mod) {
|
|
2243
2370
|
viteDevServer.moduleGraph.invalidateModule(mod);
|
|
@@ -2412,7 +2539,7 @@ var defaultEntriesDir = path5.resolve(
|
|
|
2412
2539
|
"config",
|
|
2413
2540
|
"defaults"
|
|
2414
2541
|
);
|
|
2415
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
2542
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path5.join(defaultEntriesDir, filename2));
|
|
2416
2543
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2417
2544
|
var reactRouterDevLoadContext = () => void 0;
|
|
2418
2545
|
var reactRouterVitePlugin = () => {
|
|
@@ -2508,7 +2635,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2508
2635
|
}
|
|
2509
2636
|
}).join("\n")}
|
|
2510
2637
|
export { default as assets } from ${JSON.stringify(
|
|
2511
|
-
|
|
2638
|
+
virtual.serverManifest.id
|
|
2512
2639
|
)};
|
|
2513
2640
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2514
2641
|
path5.relative(
|
|
@@ -2790,7 +2917,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2790
2917
|
let sri = void 0;
|
|
2791
2918
|
let reactRouterManifestForDev = {
|
|
2792
2919
|
version: String(Math.random()),
|
|
2793
|
-
url: combineURLs(ctx.publicPath,
|
|
2920
|
+
url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
|
|
2794
2921
|
hmr: {
|
|
2795
2922
|
runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
|
|
2796
2923
|
},
|
|
@@ -3171,11 +3298,11 @@ var reactRouterVitePlugin = () => {
|
|
|
3171
3298
|
return;
|
|
3172
3299
|
}
|
|
3173
3300
|
build = await ssrEnvironment.runner.import(
|
|
3174
|
-
|
|
3301
|
+
virtual.serverBuild.id
|
|
3175
3302
|
);
|
|
3176
3303
|
} else {
|
|
3177
3304
|
build = await viteDevServer.ssrLoadModule(
|
|
3178
|
-
|
|
3305
|
+
virtual.serverBuild.id
|
|
3179
3306
|
);
|
|
3180
3307
|
}
|
|
3181
3308
|
let handler = (0, import_react_router2.createRequestHandler)(build, "development");
|
|
@@ -3400,16 +3527,16 @@ var reactRouterVitePlugin = () => {
|
|
|
3400
3527
|
name: "react-router:virtual-modules",
|
|
3401
3528
|
enforce: "pre",
|
|
3402
3529
|
resolveId(id) {
|
|
3403
|
-
const vmod2 = Object.values(
|
|
3530
|
+
const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
|
|
3404
3531
|
if (vmod2) return vmod2.resolvedId;
|
|
3405
3532
|
},
|
|
3406
3533
|
async load(id) {
|
|
3407
3534
|
switch (id) {
|
|
3408
|
-
case
|
|
3535
|
+
case virtual.serverBuild.resolvedId: {
|
|
3409
3536
|
let routeIds = getServerBundleRouteIds(this, ctx);
|
|
3410
3537
|
return await getServerEntry({ routeIds });
|
|
3411
3538
|
}
|
|
3412
|
-
case
|
|
3539
|
+
case virtual.serverManifest.resolvedId: {
|
|
3413
3540
|
let routeIds = getServerBundleRouteIds(this, ctx);
|
|
3414
3541
|
let reactRouterManifest = viteCommand === "build" ? (await generateReactRouterManifestsForBuild({
|
|
3415
3542
|
routeIds
|
|
@@ -3427,7 +3554,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3427
3554
|
es6: true
|
|
3428
3555
|
})};`;
|
|
3429
3556
|
}
|
|
3430
|
-
case
|
|
3557
|
+
case virtual.browserManifest.resolvedId: {
|
|
3431
3558
|
if (viteCommand === "build") {
|
|
3432
3559
|
throw new Error("This module only exists in development");
|
|
3433
3560
|
}
|
|
@@ -3858,16 +3985,16 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
3858
3985
|
let response = await handler(request);
|
|
3859
3986
|
let html = await response.text();
|
|
3860
3987
|
let isPrerenderSpaFallback = build.prerender.includes("/");
|
|
3861
|
-
let
|
|
3988
|
+
let filename2 = isPrerenderSpaFallback ? "__spa-fallback.html" : "index.html";
|
|
3862
3989
|
if (response.status !== 200) {
|
|
3863
3990
|
if (isPrerenderSpaFallback) {
|
|
3864
3991
|
throw new Error(
|
|
3865
|
-
`Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${
|
|
3992
|
+
`Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename2}\` file.
|
|
3866
3993
|
` + html
|
|
3867
3994
|
);
|
|
3868
3995
|
} else {
|
|
3869
3996
|
throw new Error(
|
|
3870
|
-
`SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${
|
|
3997
|
+
`SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename2}\` file.
|
|
3871
3998
|
` + html
|
|
3872
3999
|
);
|
|
3873
4000
|
}
|
|
@@ -3877,9 +4004,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
3877
4004
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
3878
4005
|
);
|
|
3879
4006
|
}
|
|
3880
|
-
await fse.writeFile(path5.join(clientBuildDirectory,
|
|
4007
|
+
await fse.writeFile(path5.join(clientBuildDirectory, filename2), html);
|
|
3881
4008
|
let prettyDir = path5.relative(process.cwd(), clientBuildDirectory);
|
|
3882
|
-
let prettyPath = path5.join(prettyDir,
|
|
4009
|
+
let prettyPath = path5.join(prettyDir, filename2);
|
|
3883
4010
|
if (build.prerender.length > 0) {
|
|
3884
4011
|
viteConfig.logger.info(
|
|
3885
4012
|
`Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
|
|
@@ -4485,7 +4612,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4485
4612
|
copyPublicDir: false,
|
|
4486
4613
|
// Assets in the public directory are only used by the client
|
|
4487
4614
|
rollupOptions: {
|
|
4488
|
-
input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ??
|
|
4615
|
+
input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual.serverBuild.id,
|
|
4489
4616
|
output: {
|
|
4490
4617
|
entryFileNames: serverBuildFile,
|
|
4491
4618
|
format: serverModuleFormat
|