@react-router/dev 7.1.5 → 7.2.0-pre.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/CHANGELOG.md +88 -1
- package/bin.js +2 -2
- package/dist/cli/index.js +635 -248
- package/dist/config.d.ts +8 -0
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/static/refresh-utils.cjs +1 -1
- package/dist/vite/cloudflare.js +487 -3
- package/dist/vite.js +1711 -327
- package/package.json +6 -6
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/dev v7.1
|
|
3
|
+
* @react-router/dev v7.2.0-pre.1
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -178,7 +178,7 @@ function validateRouteConfig({
|
|
|
178
178
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
179
179
|
root ? `${root}` : [],
|
|
180
180
|
nested ? Object.entries(nested).map(
|
|
181
|
-
([
|
|
181
|
+
([path9, message]) => `Path: routes.${path9}
|
|
182
182
|
${message}`
|
|
183
183
|
) : []
|
|
184
184
|
].flat().join("\n\n")
|
|
@@ -389,7 +389,9 @@ async function resolveConfig({
|
|
|
389
389
|
);
|
|
390
390
|
}
|
|
391
391
|
let future = {
|
|
392
|
-
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
392
|
+
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
|
|
393
|
+
unstable_splitRouteModules: reactRouterUserConfig.future?.unstable_splitRouteModules ?? false,
|
|
394
|
+
unstable_viteEnvironmentApi: reactRouterUserConfig.future?.unstable_viteEnvironmentApi ?? false
|
|
393
395
|
};
|
|
394
396
|
let reactRouterConfig = deepFreeze({
|
|
395
397
|
appDirectory,
|
|
@@ -634,6 +636,25 @@ var init_profiler = __esm({
|
|
|
634
636
|
}
|
|
635
637
|
});
|
|
636
638
|
|
|
639
|
+
// vite/babel.ts
|
|
640
|
+
var babel_exports = {};
|
|
641
|
+
__export(babel_exports, {
|
|
642
|
+
generate: () => generate,
|
|
643
|
+
parse: () => import_parser.parse,
|
|
644
|
+
t: () => t,
|
|
645
|
+
traverse: () => traverse
|
|
646
|
+
});
|
|
647
|
+
var import_parser, t, traverse, generate;
|
|
648
|
+
var init_babel = __esm({
|
|
649
|
+
"vite/babel.ts"() {
|
|
650
|
+
"use strict";
|
|
651
|
+
import_parser = require("@babel/parser");
|
|
652
|
+
t = __toESM(require("@babel/types"));
|
|
653
|
+
traverse = require("@babel/traverse").default;
|
|
654
|
+
generate = require("@babel/generator").default;
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
637
658
|
// typegen/paths.ts
|
|
638
659
|
function getTypesDir(ctx) {
|
|
639
660
|
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
@@ -655,12 +676,55 @@ var init_paths = __esm({
|
|
|
655
676
|
}
|
|
656
677
|
});
|
|
657
678
|
|
|
679
|
+
// typegen/params.ts
|
|
680
|
+
function parse2(fullpath2) {
|
|
681
|
+
const result = {};
|
|
682
|
+
let segments = fullpath2.split("/");
|
|
683
|
+
segments.forEach((segment) => {
|
|
684
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
685
|
+
if (!match) return;
|
|
686
|
+
const param = match[1];
|
|
687
|
+
const isRequired = match[2] === void 0;
|
|
688
|
+
result[param] ||= isRequired;
|
|
689
|
+
return;
|
|
690
|
+
});
|
|
691
|
+
const hasSplat = segments.at(-1) === "*";
|
|
692
|
+
if (hasSplat) result["*"] = true;
|
|
693
|
+
return result;
|
|
694
|
+
}
|
|
695
|
+
var init_params = __esm({
|
|
696
|
+
"typegen/params.ts"() {
|
|
697
|
+
"use strict";
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
// typegen/route.ts
|
|
702
|
+
function lineage(routes2, route) {
|
|
703
|
+
const result = [];
|
|
704
|
+
while (route) {
|
|
705
|
+
result.push(route);
|
|
706
|
+
if (!route.parentId) break;
|
|
707
|
+
route = routes2[route.parentId];
|
|
708
|
+
}
|
|
709
|
+
result.reverse();
|
|
710
|
+
return result;
|
|
711
|
+
}
|
|
712
|
+
function fullpath(lineage2) {
|
|
713
|
+
if (lineage2.length === 1 && lineage2[0].id === "root") return "/";
|
|
714
|
+
return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
|
|
715
|
+
}
|
|
716
|
+
var init_route = __esm({
|
|
717
|
+
"typegen/route.ts"() {
|
|
718
|
+
"use strict";
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
|
|
658
722
|
// typegen/generate.ts
|
|
659
|
-
function
|
|
660
|
-
const
|
|
661
|
-
const
|
|
723
|
+
function generate2(ctx, route) {
|
|
724
|
+
const lineage2 = lineage(ctx.config.routes, route);
|
|
725
|
+
const fullpath2 = fullpath(lineage2);
|
|
662
726
|
const typesPath = getTypesPath(ctx, route);
|
|
663
|
-
const parents =
|
|
727
|
+
const parents = lineage2.slice(0, -1);
|
|
664
728
|
const parentTypeImports = parents.map((parent, i) => {
|
|
665
729
|
const rel = Path3.relative(
|
|
666
730
|
Path3.dirname(typesPath),
|
|
@@ -687,7 +751,7 @@ function generate(ctx, route) {
|
|
|
687
751
|
file: "${route.file}"
|
|
688
752
|
path: "${route.path}"
|
|
689
753
|
params: {${formatParamProperties(
|
|
690
|
-
|
|
754
|
+
fullpath2
|
|
691
755
|
)}} & { [key: string]: string | undefined }
|
|
692
756
|
module: Module
|
|
693
757
|
loaderData: T.CreateLoaderData<Module>
|
|
@@ -716,46 +780,13 @@ function generate(ctx, route) {
|
|
|
716
780
|
}
|
|
717
781
|
`;
|
|
718
782
|
}
|
|
719
|
-
function
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
route = routes2[route.parentId];
|
|
725
|
-
}
|
|
726
|
-
result.reverse();
|
|
727
|
-
return result;
|
|
728
|
-
}
|
|
729
|
-
function formatParamProperties(urlpath) {
|
|
730
|
-
const params = parseParams(urlpath);
|
|
731
|
-
const properties = Object.entries(params).map(([name, values]) => {
|
|
732
|
-
if (values.length === 1) {
|
|
733
|
-
const isOptional = values[0];
|
|
734
|
-
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
735
|
-
}
|
|
736
|
-
const items = values.map(
|
|
737
|
-
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
738
|
-
);
|
|
739
|
-
return `"${name}": [${items.join(", ")}]`;
|
|
740
|
-
});
|
|
783
|
+
function formatParamProperties(fullpath2) {
|
|
784
|
+
const params = parse2(fullpath2);
|
|
785
|
+
const properties = Object.entries(params).map(
|
|
786
|
+
([name, isRequired]) => isRequired ? `"${name}": string` : `"${name}"?: string`
|
|
787
|
+
);
|
|
741
788
|
return properties.join("; ");
|
|
742
789
|
}
|
|
743
|
-
function parseParams(urlpath) {
|
|
744
|
-
const result = {};
|
|
745
|
-
let segments = urlpath.split("/");
|
|
746
|
-
segments.forEach((segment) => {
|
|
747
|
-
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
748
|
-
if (!match) return;
|
|
749
|
-
const param = match[1];
|
|
750
|
-
const isOptional = match[2] !== void 0;
|
|
751
|
-
result[param] ??= [];
|
|
752
|
-
result[param].push(isOptional);
|
|
753
|
-
return;
|
|
754
|
-
});
|
|
755
|
-
const hasSplat = segments.at(-1) === "*";
|
|
756
|
-
if (hasSplat) result["*"] = [false];
|
|
757
|
-
return result;
|
|
758
|
-
}
|
|
759
790
|
var import_dedent, Path3, Pathe2, noExtension;
|
|
760
791
|
var init_generate = __esm({
|
|
761
792
|
"typegen/generate.ts"() {
|
|
@@ -764,7 +795,9 @@ var init_generate = __esm({
|
|
|
764
795
|
Path3 = __toESM(require("pathe"));
|
|
765
796
|
Pathe2 = __toESM(require("pathe/utils"));
|
|
766
797
|
init_paths();
|
|
767
|
-
|
|
798
|
+
init_params();
|
|
799
|
+
init_route();
|
|
800
|
+
noExtension = (path9) => Path3.join(Path3.dirname(path9), Pathe2.filename(path9));
|
|
768
801
|
}
|
|
769
802
|
});
|
|
770
803
|
|
|
@@ -816,33 +849,67 @@ async function writeAll(ctx) {
|
|
|
816
849
|
import_node_fs3.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
817
850
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
818
851
|
const typesPath = getTypesPath(ctx, route);
|
|
819
|
-
const content =
|
|
852
|
+
const content = generate2(ctx, route);
|
|
820
853
|
import_node_fs3.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
821
854
|
import_node_fs3.default.writeFileSync(typesPath, content);
|
|
822
855
|
});
|
|
856
|
+
const registerPath = Path4.join(typegenDir, "+register.ts");
|
|
857
|
+
import_node_fs3.default.writeFileSync(registerPath, register(ctx));
|
|
823
858
|
}
|
|
824
|
-
|
|
859
|
+
function register(ctx) {
|
|
860
|
+
const register2 = import_dedent2.default`
|
|
861
|
+
import "react-router";
|
|
862
|
+
|
|
863
|
+
declare module "react-router" {
|
|
864
|
+
interface Register {
|
|
865
|
+
params: Params;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
`;
|
|
869
|
+
const { t: t2 } = babel_exports;
|
|
870
|
+
const typeParams = t2.tsTypeAliasDeclaration(
|
|
871
|
+
t2.identifier("Params"),
|
|
872
|
+
null,
|
|
873
|
+
t2.tsTypeLiteral(
|
|
874
|
+
Object.values(ctx.config.routes).map((route) => {
|
|
875
|
+
if (route.id !== "root" && !route.path) return void 0;
|
|
876
|
+
const lineage2 = lineage(ctx.config.routes, route);
|
|
877
|
+
const fullpath2 = fullpath(lineage2);
|
|
878
|
+
const params = parse2(fullpath2);
|
|
879
|
+
return t2.tsPropertySignature(
|
|
880
|
+
t2.stringLiteral(fullpath2),
|
|
881
|
+
t2.tsTypeAnnotation(
|
|
882
|
+
t2.tsTypeLiteral(
|
|
883
|
+
Object.entries(params).map(([param, isRequired]) => {
|
|
884
|
+
const property = t2.tsPropertySignature(
|
|
885
|
+
t2.stringLiteral(param),
|
|
886
|
+
t2.tsTypeAnnotation(t2.tsStringKeyword())
|
|
887
|
+
);
|
|
888
|
+
property.optional = !isRequired;
|
|
889
|
+
return property;
|
|
890
|
+
})
|
|
891
|
+
)
|
|
892
|
+
)
|
|
893
|
+
);
|
|
894
|
+
}).filter((x) => x !== void 0)
|
|
895
|
+
)
|
|
896
|
+
);
|
|
897
|
+
return [register2, generate(typeParams).code].join("\n\n");
|
|
898
|
+
}
|
|
899
|
+
var import_node_fs3, import_dedent2, Path4, import_picocolors3;
|
|
825
900
|
var init_typegen = __esm({
|
|
826
901
|
"typegen/index.ts"() {
|
|
827
902
|
"use strict";
|
|
828
903
|
import_node_fs3 = __toESM(require("fs"));
|
|
904
|
+
import_dedent2 = __toESM(require("dedent"));
|
|
829
905
|
Path4 = __toESM(require("pathe"));
|
|
830
906
|
import_picocolors3 = __toESM(require("picocolors"));
|
|
831
907
|
init_config();
|
|
908
|
+
init_babel();
|
|
832
909
|
init_generate();
|
|
833
910
|
init_paths();
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
// vite/babel.ts
|
|
838
|
-
var import_parser, t, traverse, generate2;
|
|
839
|
-
var init_babel = __esm({
|
|
840
|
-
"vite/babel.ts"() {
|
|
841
|
-
"use strict";
|
|
842
|
-
import_parser = require("@babel/parser");
|
|
843
|
-
t = __toESM(require("@babel/types"));
|
|
844
|
-
traverse = require("@babel/traverse").default;
|
|
845
|
-
generate2 = require("@babel/generator").default;
|
|
911
|
+
init_params();
|
|
912
|
+
init_route();
|
|
846
913
|
}
|
|
847
914
|
});
|
|
848
915
|
|
|
@@ -915,12 +982,65 @@ var init_remove_exports = __esm({
|
|
|
915
982
|
}
|
|
916
983
|
});
|
|
917
984
|
|
|
985
|
+
// vite/cache.ts
|
|
986
|
+
var init_cache = __esm({
|
|
987
|
+
"vite/cache.ts"() {
|
|
988
|
+
"use strict";
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
// vite/route-chunks.ts
|
|
993
|
+
function getRouteChunkModuleId(filePath, chunkName) {
|
|
994
|
+
return `${filePath}${routeChunkQueryStrings[chunkName]}`;
|
|
995
|
+
}
|
|
996
|
+
function isRouteChunkModuleId(id) {
|
|
997
|
+
return Object.values(routeChunkQueryStrings).some(
|
|
998
|
+
(queryString) => id.endsWith(queryString)
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
function isRouteChunkName(name) {
|
|
1002
|
+
return name === mainChunkName || routeChunkExportNames.includes(name);
|
|
1003
|
+
}
|
|
1004
|
+
function getRouteChunkNameFromModuleId(id) {
|
|
1005
|
+
if (!isRouteChunkModuleId(id)) {
|
|
1006
|
+
return null;
|
|
1007
|
+
}
|
|
1008
|
+
let chunkName = id.split(routeChunkQueryStringPrefix)[1].split("&")[0];
|
|
1009
|
+
if (!isRouteChunkName(chunkName)) {
|
|
1010
|
+
return null;
|
|
1011
|
+
}
|
|
1012
|
+
return chunkName;
|
|
1013
|
+
}
|
|
1014
|
+
var routeChunkExportNames, mainChunkName, routeChunkNames, routeChunkQueryStringPrefix, routeChunkQueryStrings;
|
|
1015
|
+
var init_route_chunks = __esm({
|
|
1016
|
+
"vite/route-chunks.ts"() {
|
|
1017
|
+
"use strict";
|
|
1018
|
+
init_invariant();
|
|
1019
|
+
init_cache();
|
|
1020
|
+
init_babel();
|
|
1021
|
+
routeChunkExportNames = [
|
|
1022
|
+
"clientAction",
|
|
1023
|
+
"clientLoader",
|
|
1024
|
+
"HydrateFallback"
|
|
1025
|
+
];
|
|
1026
|
+
mainChunkName = "main";
|
|
1027
|
+
routeChunkNames = ["main", ...routeChunkExportNames];
|
|
1028
|
+
routeChunkQueryStringPrefix = "?route-chunk=";
|
|
1029
|
+
routeChunkQueryStrings = {
|
|
1030
|
+
main: `${routeChunkQueryStringPrefix}main`,
|
|
1031
|
+
clientAction: `${routeChunkQueryStringPrefix}clientAction`,
|
|
1032
|
+
clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
|
|
1033
|
+
HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
|
|
918
1038
|
// vite/with-props.ts
|
|
919
|
-
var
|
|
1039
|
+
var import_dedent3, vmod;
|
|
920
1040
|
var init_with_props = __esm({
|
|
921
1041
|
"vite/with-props.ts"() {
|
|
922
1042
|
"use strict";
|
|
923
|
-
|
|
1043
|
+
import_dedent3 = __toESM(require("dedent"));
|
|
924
1044
|
init_babel();
|
|
925
1045
|
init_virtual_module();
|
|
926
1046
|
vmod = create("with-props");
|
|
@@ -931,11 +1051,12 @@ var init_with_props = __esm({
|
|
|
931
1051
|
async function resolveViteConfig({
|
|
932
1052
|
configFile,
|
|
933
1053
|
mode,
|
|
934
|
-
root
|
|
1054
|
+
root,
|
|
1055
|
+
plugins
|
|
935
1056
|
}) {
|
|
936
1057
|
let vite2 = getVite();
|
|
937
1058
|
let viteConfig = await vite2.resolveConfig(
|
|
938
|
-
{ mode, configFile, root },
|
|
1059
|
+
{ mode, configFile, root, plugins },
|
|
939
1060
|
"build",
|
|
940
1061
|
// command
|
|
941
1062
|
"production",
|
|
@@ -951,7 +1072,315 @@ async function resolveViteConfig({
|
|
|
951
1072
|
async function extractPluginContext(viteConfig) {
|
|
952
1073
|
return viteConfig["__reactRouterPluginContext"];
|
|
953
1074
|
}
|
|
954
|
-
|
|
1075
|
+
function isSeverBundleEnvironmentName(name) {
|
|
1076
|
+
return name.startsWith(SSR_BUNDLE_PREFIX);
|
|
1077
|
+
}
|
|
1078
|
+
function getServerEnvironmentEntries(record, buildManifest) {
|
|
1079
|
+
return Object.entries(record).filter(
|
|
1080
|
+
([name]) => buildManifest.serverBundles ? isSeverBundleEnvironmentName(name) : name === "ssr"
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
function getServerEnvironmentKeys(record, buildManifest) {
|
|
1084
|
+
return getServerEnvironmentEntries(record, buildManifest).map(([key]) => key);
|
|
1085
|
+
}
|
|
1086
|
+
function getAddressableRoutes(routes2) {
|
|
1087
|
+
let nonAddressableIds = /* @__PURE__ */ new Set();
|
|
1088
|
+
for (let id in routes2) {
|
|
1089
|
+
let route = routes2[id];
|
|
1090
|
+
if (route.index) {
|
|
1091
|
+
invariant(
|
|
1092
|
+
route.parentId,
|
|
1093
|
+
`Expected index route "${route.id}" to have "parentId" set`
|
|
1094
|
+
);
|
|
1095
|
+
nonAddressableIds.add(route.parentId);
|
|
1096
|
+
}
|
|
1097
|
+
if (typeof route.path !== "string" && !route.index) {
|
|
1098
|
+
nonAddressableIds.add(id);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return Object.values(routes2).filter(
|
|
1102
|
+
(route) => !nonAddressableIds.has(route.id)
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
function getRouteBranch(routes2, routeId) {
|
|
1106
|
+
let branch = [];
|
|
1107
|
+
let currentRouteId = routeId;
|
|
1108
|
+
while (currentRouteId) {
|
|
1109
|
+
let route = routes2[currentRouteId];
|
|
1110
|
+
invariant(route, `Missing route for ${currentRouteId}`);
|
|
1111
|
+
branch.push(route);
|
|
1112
|
+
currentRouteId = route.parentId;
|
|
1113
|
+
}
|
|
1114
|
+
return branch.reverse();
|
|
1115
|
+
}
|
|
1116
|
+
function hasServerBundles(buildManifest) {
|
|
1117
|
+
return Object.keys(buildManifest.serverBundles ?? {}).length > 0;
|
|
1118
|
+
}
|
|
1119
|
+
function getRoutesByServerBundleId(buildManifest) {
|
|
1120
|
+
if (!buildManifest.routeIdToServerBundleId) {
|
|
1121
|
+
return {};
|
|
1122
|
+
}
|
|
1123
|
+
let routesByServerBundleId = {};
|
|
1124
|
+
for (let [routeId, serverBundleId] of Object.entries(
|
|
1125
|
+
buildManifest.routeIdToServerBundleId
|
|
1126
|
+
)) {
|
|
1127
|
+
routesByServerBundleId[serverBundleId] ??= {};
|
|
1128
|
+
let branch = getRouteBranch(buildManifest.routes, routeId);
|
|
1129
|
+
for (let route of branch) {
|
|
1130
|
+
routesByServerBundleId[serverBundleId][route.id] = route;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return routesByServerBundleId;
|
|
1134
|
+
}
|
|
1135
|
+
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
1136
|
+
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
1137
|
+
let isWithinRoot = () => {
|
|
1138
|
+
let relativePath = path7.relative(ctx.rootDirectory, buildDirectory);
|
|
1139
|
+
return !relativePath.startsWith("..") && !path7.isAbsolute(relativePath);
|
|
1140
|
+
};
|
|
1141
|
+
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
1142
|
+
await fse.remove(buildDirectory);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
async function cleanViteManifests(environmentsOptions, ctx) {
|
|
1146
|
+
let viteManifestPaths = Object.entries(environmentsOptions).map(
|
|
1147
|
+
([environmentName, options]) => {
|
|
1148
|
+
let outDir = options.build?.outDir;
|
|
1149
|
+
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
1150
|
+
return path7.join(outDir, ".vite/manifest.json");
|
|
1151
|
+
}
|
|
1152
|
+
);
|
|
1153
|
+
await Promise.all(
|
|
1154
|
+
viteManifestPaths.map(async (viteManifestPath) => {
|
|
1155
|
+
let manifestExists = await fse.pathExists(viteManifestPath);
|
|
1156
|
+
if (!manifestExists) return;
|
|
1157
|
+
if (!ctx.viteManifestEnabled) {
|
|
1158
|
+
await fse.remove(viteManifestPath);
|
|
1159
|
+
}
|
|
1160
|
+
let viteDir = path7.dirname(viteManifestPath);
|
|
1161
|
+
let viteDirFiles = await fse.readdir(viteDir);
|
|
1162
|
+
if (viteDirFiles.length === 0) {
|
|
1163
|
+
await fse.remove(viteDir);
|
|
1164
|
+
}
|
|
1165
|
+
})
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
async function getBuildManifest(ctx) {
|
|
1169
|
+
let { routes: routes2, serverBundles, appDirectory } = ctx.reactRouterConfig;
|
|
1170
|
+
if (!serverBundles) {
|
|
1171
|
+
return { routes: routes2 };
|
|
1172
|
+
}
|
|
1173
|
+
let { normalizePath } = await import("vite");
|
|
1174
|
+
let serverBuildDirectory = getServerBuildDirectory(ctx);
|
|
1175
|
+
let resolvedAppDirectory = path7.resolve(ctx.rootDirectory, appDirectory);
|
|
1176
|
+
let rootRelativeRoutes = Object.fromEntries(
|
|
1177
|
+
Object.entries(routes2).map(([id, route]) => {
|
|
1178
|
+
let filePath = path7.join(resolvedAppDirectory, route.file);
|
|
1179
|
+
let rootRelativeFilePath = normalizePath(
|
|
1180
|
+
path7.relative(ctx.rootDirectory, filePath)
|
|
1181
|
+
);
|
|
1182
|
+
return [id, { ...route, file: rootRelativeFilePath }];
|
|
1183
|
+
})
|
|
1184
|
+
);
|
|
1185
|
+
let buildManifest = {
|
|
1186
|
+
serverBundles: {},
|
|
1187
|
+
routeIdToServerBundleId: {},
|
|
1188
|
+
routes: rootRelativeRoutes
|
|
1189
|
+
};
|
|
1190
|
+
await Promise.all(
|
|
1191
|
+
getAddressableRoutes(routes2).map(async (route) => {
|
|
1192
|
+
let branch = getRouteBranch(routes2, route.id);
|
|
1193
|
+
let serverBundleId = await serverBundles({
|
|
1194
|
+
branch: branch.map(
|
|
1195
|
+
(route2) => configRouteToBranchRoute({
|
|
1196
|
+
...route2,
|
|
1197
|
+
// Ensure absolute paths are passed to the serverBundles function
|
|
1198
|
+
file: path7.join(resolvedAppDirectory, route2.file)
|
|
1199
|
+
})
|
|
1200
|
+
)
|
|
1201
|
+
});
|
|
1202
|
+
if (typeof serverBundleId !== "string") {
|
|
1203
|
+
throw new Error(`The "serverBundles" function must return a string`);
|
|
1204
|
+
}
|
|
1205
|
+
if (!/^[a-zA-Z0-9-_]+$/.test(serverBundleId)) {
|
|
1206
|
+
throw new Error(
|
|
1207
|
+
`The "serverBundles" function must only return strings containing alphanumeric characters, hyphens and underscores.`
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
buildManifest.routeIdToServerBundleId[route.id] = serverBundleId;
|
|
1211
|
+
buildManifest.serverBundles[serverBundleId] ??= {
|
|
1212
|
+
id: serverBundleId,
|
|
1213
|
+
file: normalizePath(
|
|
1214
|
+
path7.join(
|
|
1215
|
+
path7.relative(
|
|
1216
|
+
ctx.rootDirectory,
|
|
1217
|
+
path7.join(serverBuildDirectory, serverBundleId)
|
|
1218
|
+
),
|
|
1219
|
+
ctx.reactRouterConfig.serverBuildFile
|
|
1220
|
+
)
|
|
1221
|
+
)
|
|
1222
|
+
};
|
|
1223
|
+
})
|
|
1224
|
+
);
|
|
1225
|
+
return buildManifest;
|
|
1226
|
+
}
|
|
1227
|
+
function mergeEnvironmentOptions(base, ...overrides) {
|
|
1228
|
+
let vite2 = getVite();
|
|
1229
|
+
return overrides.reduce(
|
|
1230
|
+
(merged, override) => vite2.mergeConfig(merged, override, false),
|
|
1231
|
+
base
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
async function getEnvironmentOptionsResolvers(ctx, buildManifest, viteCommand) {
|
|
1235
|
+
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
1236
|
+
let packageRoot = path7.dirname(
|
|
1237
|
+
require.resolve("@react-router/dev/package.json")
|
|
1238
|
+
);
|
|
1239
|
+
let { moduleSyncEnabled } = await import(`file:///${path7.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
1240
|
+
let vite2 = getVite();
|
|
1241
|
+
let viteServerConditions = [
|
|
1242
|
+
...vite2.defaultServerConditions ?? [],
|
|
1243
|
+
...moduleSyncEnabled ? ["module-sync"] : []
|
|
1244
|
+
];
|
|
1245
|
+
function getBaseOptions({
|
|
1246
|
+
viteUserConfig
|
|
1247
|
+
}) {
|
|
1248
|
+
return {
|
|
1249
|
+
build: {
|
|
1250
|
+
cssMinify: viteUserConfig.build?.cssMinify ?? true,
|
|
1251
|
+
manifest: true,
|
|
1252
|
+
// The manifest is enabled for all builds to detect SSR-only assets
|
|
1253
|
+
rollupOptions: {
|
|
1254
|
+
preserveEntrySignatures: "exports-only",
|
|
1255
|
+
// Silence Rollup "use client" warnings
|
|
1256
|
+
// Adapted from https://github.com/vitejs/vite-plugin-react/pull/144
|
|
1257
|
+
onwarn(warning, defaultHandler) {
|
|
1258
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
let userHandler = viteUserConfig.build?.rollupOptions?.onwarn;
|
|
1262
|
+
if (userHandler) {
|
|
1263
|
+
userHandler(warning, defaultHandler);
|
|
1264
|
+
} else {
|
|
1265
|
+
defaultHandler(warning);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
function getBaseServerOptions({
|
|
1273
|
+
viteUserConfig
|
|
1274
|
+
}) {
|
|
1275
|
+
let conditions = viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions];
|
|
1276
|
+
return mergeEnvironmentOptions(getBaseOptions({ viteUserConfig }), {
|
|
1277
|
+
resolve: {
|
|
1278
|
+
external: ssrExternals,
|
|
1279
|
+
conditions,
|
|
1280
|
+
externalConditions: conditions
|
|
1281
|
+
},
|
|
1282
|
+
build: {
|
|
1283
|
+
// We move SSR-only assets to client assets. Note that the
|
|
1284
|
+
// SSR build can also emit code-split JS files (e.g. by
|
|
1285
|
+
// dynamic import) under the same assets directory
|
|
1286
|
+
// regardless of "ssrEmitAssets" option, so we also need to
|
|
1287
|
+
// keep these JS files have to be kept as-is.
|
|
1288
|
+
ssrEmitAssets: true,
|
|
1289
|
+
copyPublicDir: false,
|
|
1290
|
+
// Assets in the public directory are only used by the client
|
|
1291
|
+
rollupOptions: {
|
|
1292
|
+
output: {
|
|
1293
|
+
entryFileNames: serverBuildFile,
|
|
1294
|
+
format: serverModuleFormat
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
let environmentOptionsResolvers = {
|
|
1301
|
+
client: ({ viteUserConfig }) => mergeEnvironmentOptions(getBaseOptions({ viteUserConfig }), {
|
|
1302
|
+
build: {
|
|
1303
|
+
rollupOptions: {
|
|
1304
|
+
input: [
|
|
1305
|
+
ctx.entryClientFilePath,
|
|
1306
|
+
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
1307
|
+
(route) => {
|
|
1308
|
+
let routeFilePath = path7.resolve(
|
|
1309
|
+
ctx.reactRouterConfig.appDirectory,
|
|
1310
|
+
route.file
|
|
1311
|
+
);
|
|
1312
|
+
let isRootRoute = route.file === ctx.reactRouterConfig.routes.root.file;
|
|
1313
|
+
let code = fse.readFileSync(routeFilePath, "utf-8");
|
|
1314
|
+
return [
|
|
1315
|
+
`${routeFilePath}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
|
|
1316
|
+
...ctx.reactRouterConfig.future.unstable_splitRouteModules && !isRootRoute ? routeChunkExportNames.map(
|
|
1317
|
+
(exportName) => code.includes(exportName) ? getRouteChunkModuleId(routeFilePath, exportName) : null
|
|
1318
|
+
) : []
|
|
1319
|
+
].filter(isNonNullable);
|
|
1320
|
+
}
|
|
1321
|
+
)
|
|
1322
|
+
],
|
|
1323
|
+
output: {
|
|
1324
|
+
entryFileNames({ moduleIds }) {
|
|
1325
|
+
let routeChunkModuleId = moduleIds.find(isRouteChunkModuleId);
|
|
1326
|
+
let routeChunkName = routeChunkModuleId ? getRouteChunkNameFromModuleId(routeChunkModuleId) : null;
|
|
1327
|
+
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
1328
|
+
return `assets/[name]${routeChunkSuffix}-[hash].js`;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
},
|
|
1332
|
+
outDir: getClientBuildDirectory(ctx.reactRouterConfig)
|
|
1333
|
+
}
|
|
1334
|
+
})
|
|
1335
|
+
};
|
|
1336
|
+
if (hasServerBundles(buildManifest)) {
|
|
1337
|
+
for (let [serverBundleId, routes2] of Object.entries(
|
|
1338
|
+
getRoutesByServerBundleId(buildManifest)
|
|
1339
|
+
)) {
|
|
1340
|
+
const serverBundleEnvironmentId = serverBundleId.replaceAll("-", "_");
|
|
1341
|
+
const environmentName = `${SSR_BUNDLE_PREFIX}${serverBundleEnvironmentId}`;
|
|
1342
|
+
environmentOptionsResolvers[environmentName] = ({ viteUserConfig }) => mergeEnvironmentOptions(
|
|
1343
|
+
getBaseServerOptions({ viteUserConfig }),
|
|
1344
|
+
{
|
|
1345
|
+
build: {
|
|
1346
|
+
outDir: getServerBuildDirectory(ctx, { serverBundleId }),
|
|
1347
|
+
rollupOptions: {
|
|
1348
|
+
input: `${virtual.serverBuild.id}?route-ids=${Object.keys(
|
|
1349
|
+
routes2
|
|
1350
|
+
).join(",")}`
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
},
|
|
1354
|
+
// Ensure server bundle environments extend the user's SSR
|
|
1355
|
+
// environment config if it exists
|
|
1356
|
+
viteUserConfig.environments?.ssr ?? {}
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
} else {
|
|
1360
|
+
environmentOptionsResolvers.ssr = ({ viteUserConfig }) => mergeEnvironmentOptions(getBaseServerOptions({ viteUserConfig }), {
|
|
1361
|
+
build: {
|
|
1362
|
+
outDir: getServerBuildDirectory(ctx),
|
|
1363
|
+
rollupOptions: {
|
|
1364
|
+
input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual.serverBuild.id
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
return environmentOptionsResolvers;
|
|
1370
|
+
}
|
|
1371
|
+
function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {
|
|
1372
|
+
let environmentOptions = {};
|
|
1373
|
+
for (let [environmentName, resolver] of Object.entries(
|
|
1374
|
+
environmentResolvers
|
|
1375
|
+
)) {
|
|
1376
|
+
environmentOptions[environmentName] = resolver(resolverOptions);
|
|
1377
|
+
}
|
|
1378
|
+
return environmentOptions;
|
|
1379
|
+
}
|
|
1380
|
+
function isNonNullable(x) {
|
|
1381
|
+
return x != null;
|
|
1382
|
+
}
|
|
1383
|
+
var import_node_crypto, path7, url, fse, babel2, import_react_router2, import_es_module_lexer, import_pick3, import_jsesc, import_picocolors4, import_kebabCase, BUILD_CLIENT_ROUTE_QUERY_STRING, SSR_BUNDLE_PREFIX, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, getClientBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
|
|
955
1384
|
var init_plugin = __esm({
|
|
956
1385
|
"vite/plugin.ts"() {
|
|
957
1386
|
"use strict";
|
|
@@ -962,8 +1391,10 @@ var init_plugin = __esm({
|
|
|
962
1391
|
babel2 = __toESM(require("@babel/core"));
|
|
963
1392
|
import_react_router2 = require("react-router");
|
|
964
1393
|
import_es_module_lexer = require("es-module-lexer");
|
|
1394
|
+
import_pick3 = __toESM(require("lodash/pick"));
|
|
965
1395
|
import_jsesc = __toESM(require("jsesc"));
|
|
966
1396
|
import_picocolors4 = __toESM(require("picocolors"));
|
|
1397
|
+
import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
967
1398
|
init_typegen();
|
|
968
1399
|
init_invariant();
|
|
969
1400
|
init_babel();
|
|
@@ -973,9 +1404,12 @@ var init_plugin = __esm({
|
|
|
973
1404
|
init_resolve_file_url();
|
|
974
1405
|
init_combine_urls();
|
|
975
1406
|
init_remove_exports();
|
|
1407
|
+
init_route_chunks();
|
|
976
1408
|
init_vite();
|
|
977
1409
|
init_config();
|
|
978
1410
|
init_with_props();
|
|
1411
|
+
BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
|
|
1412
|
+
SSR_BUNDLE_PREFIX = "ssrBundle_";
|
|
979
1413
|
virtualHmrRuntime = create("hmr-runtime");
|
|
980
1414
|
virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
981
1415
|
virtual = {
|
|
@@ -983,11 +1417,12 @@ var init_plugin = __esm({
|
|
|
983
1417
|
serverManifest: create("server-manifest"),
|
|
984
1418
|
browserManifest: create("browser-manifest")
|
|
985
1419
|
};
|
|
986
|
-
getServerBuildDirectory = (ctx) => path7.join(
|
|
1420
|
+
getServerBuildDirectory = (ctx, { serverBundleId } = {}) => path7.join(
|
|
987
1421
|
ctx.reactRouterConfig.buildDirectory,
|
|
988
1422
|
"server",
|
|
989
|
-
...
|
|
1423
|
+
...serverBundleId ? [serverBundleId] : []
|
|
990
1424
|
);
|
|
1425
|
+
getClientBuildDirectory = (reactRouterConfig) => path7.join(reactRouterConfig.buildDirectory, "client");
|
|
991
1426
|
defaultEntriesDir = path7.resolve(
|
|
992
1427
|
path7.dirname(require.resolve("@react-router/dev/package.json")),
|
|
993
1428
|
"dist",
|
|
@@ -1025,144 +1460,83 @@ var build_exports = {};
|
|
|
1025
1460
|
__export(build_exports, {
|
|
1026
1461
|
build: () => build
|
|
1027
1462
|
});
|
|
1028
|
-
function
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
route.parentId,
|
|
1035
|
-
`Expected index route "${route.id}" to have "parentId" set`
|
|
1036
|
-
);
|
|
1037
|
-
nonAddressableIds.add(route.parentId);
|
|
1038
|
-
}
|
|
1039
|
-
if (typeof route.path !== "string" && !route.index) {
|
|
1040
|
-
nonAddressableIds.add(id);
|
|
1041
|
-
}
|
|
1463
|
+
async function build(root, viteBuildOptions) {
|
|
1464
|
+
await preloadVite();
|
|
1465
|
+
let vite2 = getVite();
|
|
1466
|
+
let configResult = await loadConfig({ rootDirectory: root });
|
|
1467
|
+
if (!configResult.ok) {
|
|
1468
|
+
throw new Error(configResult.error);
|
|
1042
1469
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
);
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
while (currentRouteId) {
|
|
1051
|
-
let route = routes2[currentRouteId];
|
|
1052
|
-
invariant(route, `Missing route for ${currentRouteId}`);
|
|
1053
|
-
branch.push(route);
|
|
1054
|
-
currentRouteId = route.parentId;
|
|
1470
|
+
let config = configResult.value;
|
|
1471
|
+
let unstable_viteEnvironmentApi = config.future.unstable_viteEnvironmentApi;
|
|
1472
|
+
let viteMajor = parseInt(vite2.version.split(".")[0], 10);
|
|
1473
|
+
if (unstable_viteEnvironmentApi && viteMajor === 5) {
|
|
1474
|
+
throw new Error(
|
|
1475
|
+
"The future.unstable_viteEnvironmentApi option is not supported in Vite 5"
|
|
1476
|
+
);
|
|
1055
1477
|
}
|
|
1056
|
-
return
|
|
1478
|
+
return await (unstable_viteEnvironmentApi ? viteAppBuild(root, viteBuildOptions) : viteBuild(root, viteBuildOptions));
|
|
1057
1479
|
}
|
|
1058
|
-
async function
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
let
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
buildManifest.serverBundles[serverBundleId] = {
|
|
1113
|
-
id: serverBundleId,
|
|
1114
|
-
file: normalizePath(
|
|
1115
|
-
import_node_path2.default.join(relativeServerBundleDirectory, serverBuildFile)
|
|
1116
|
-
)
|
|
1117
|
-
};
|
|
1118
|
-
serverBuildConfig = {
|
|
1119
|
-
routes: {},
|
|
1120
|
-
serverBundleId
|
|
1121
|
-
};
|
|
1122
|
-
serverBundleBuildConfigById.set(serverBundleId, serverBuildConfig);
|
|
1123
|
-
}
|
|
1124
|
-
for (let route2 of branch) {
|
|
1125
|
-
serverBuildConfig.routes[route2.id] = route2;
|
|
1480
|
+
async function viteAppBuild(root, {
|
|
1481
|
+
assetsInlineLimit,
|
|
1482
|
+
clearScreen,
|
|
1483
|
+
config: configFile,
|
|
1484
|
+
emptyOutDir,
|
|
1485
|
+
force,
|
|
1486
|
+
logLevel,
|
|
1487
|
+
minify,
|
|
1488
|
+
mode,
|
|
1489
|
+
sourcemapClient,
|
|
1490
|
+
sourcemapServer
|
|
1491
|
+
}) {
|
|
1492
|
+
let vite2 = getVite();
|
|
1493
|
+
let builder = await vite2.createBuilder({
|
|
1494
|
+
root,
|
|
1495
|
+
mode,
|
|
1496
|
+
configFile,
|
|
1497
|
+
build: {
|
|
1498
|
+
assetsInlineLimit,
|
|
1499
|
+
emptyOutDir,
|
|
1500
|
+
minify
|
|
1501
|
+
},
|
|
1502
|
+
optimizeDeps: { force },
|
|
1503
|
+
clearScreen,
|
|
1504
|
+
logLevel,
|
|
1505
|
+
plugins: [
|
|
1506
|
+
{
|
|
1507
|
+
name: "react-router:cli-config",
|
|
1508
|
+
configEnvironment(name) {
|
|
1509
|
+
if (sourcemapClient && name === "client") {
|
|
1510
|
+
return {
|
|
1511
|
+
build: {
|
|
1512
|
+
sourcemap: sourcemapClient
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
if (sourcemapServer && name !== "client") {
|
|
1517
|
+
return {
|
|
1518
|
+
build: {
|
|
1519
|
+
sourcemap: sourcemapServer
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
},
|
|
1524
|
+
configResolved(config) {
|
|
1525
|
+
let hasReactRouterPlugin = config.plugins.find(
|
|
1526
|
+
(plugin2) => plugin2.name === "react-router"
|
|
1527
|
+
);
|
|
1528
|
+
if (!hasReactRouterPlugin) {
|
|
1529
|
+
throw new Error(
|
|
1530
|
+
"React Router Vite plugin not found in Vite config"
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1126
1534
|
}
|
|
1127
|
-
|
|
1128
|
-
);
|
|
1129
|
-
|
|
1130
|
-
(serverBundleBuildConfig) => {
|
|
1131
|
-
let serverBuild = {
|
|
1132
|
-
ssr: true,
|
|
1133
|
-
serverBundleBuildConfig
|
|
1134
|
-
};
|
|
1135
|
-
return serverBuild;
|
|
1136
|
-
}
|
|
1137
|
-
);
|
|
1138
|
-
return {
|
|
1139
|
-
serverBuilds,
|
|
1140
|
-
buildManifest
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
1144
|
-
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
1145
|
-
let isWithinRoot = () => {
|
|
1146
|
-
let relativePath = import_node_path2.default.relative(ctx.rootDirectory, buildDirectory);
|
|
1147
|
-
return !relativePath.startsWith("..") && !import_node_path2.default.isAbsolute(relativePath);
|
|
1148
|
-
};
|
|
1149
|
-
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
1150
|
-
await import_fs_extra.default.remove(buildDirectory);
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
function getViteManifestPaths(ctx, serverBuilds) {
|
|
1154
|
-
let buildRelative = (pathname) => import_node_path2.default.resolve(ctx.reactRouterConfig.buildDirectory, pathname);
|
|
1155
|
-
let viteManifestPaths = [
|
|
1156
|
-
"client/.vite/manifest.json",
|
|
1157
|
-
...serverBuilds.map(({ serverBundleBuildConfig }) => {
|
|
1158
|
-
let serverBundleId = serverBundleBuildConfig?.serverBundleId;
|
|
1159
|
-
let serverBundlePath = serverBundleId ? serverBundleId + "/" : "";
|
|
1160
|
-
return `server/${serverBundlePath}.vite/manifest.json`;
|
|
1161
|
-
})
|
|
1162
|
-
].map((srcPath) => buildRelative(srcPath));
|
|
1163
|
-
return viteManifestPaths;
|
|
1535
|
+
]
|
|
1536
|
+
});
|
|
1537
|
+
await builder.buildApp();
|
|
1164
1538
|
}
|
|
1165
|
-
async function
|
|
1539
|
+
async function viteBuild(root, {
|
|
1166
1540
|
assetsInlineLimit,
|
|
1167
1541
|
clearScreen,
|
|
1168
1542
|
config: configFile,
|
|
@@ -1174,21 +1548,36 @@ async function build(root, {
|
|
|
1174
1548
|
sourcemapClient,
|
|
1175
1549
|
sourcemapServer
|
|
1176
1550
|
}) {
|
|
1177
|
-
|
|
1178
|
-
let viteConfig = await resolveViteConfig({
|
|
1179
|
-
|
|
1551
|
+
let viteUserConfig = {};
|
|
1552
|
+
let viteConfig = await resolveViteConfig({
|
|
1553
|
+
configFile,
|
|
1554
|
+
mode,
|
|
1555
|
+
root,
|
|
1556
|
+
plugins: [
|
|
1557
|
+
{
|
|
1558
|
+
name: "react-router:extract-vite-user-config",
|
|
1559
|
+
config(config) {
|
|
1560
|
+
viteUserConfig = config;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
]
|
|
1564
|
+
});
|
|
1565
|
+
let ctx = await extractPluginContext(viteConfig);
|
|
1180
1566
|
if (!ctx) {
|
|
1181
1567
|
console.error(
|
|
1182
1568
|
import_picocolors5.default.red("React Router Vite plugin not found in Vite config")
|
|
1183
1569
|
);
|
|
1184
1570
|
process.exit(1);
|
|
1185
1571
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1572
|
+
async function buildEnvironment(environmentName) {
|
|
1573
|
+
let vite2 = getVite();
|
|
1574
|
+
let ssr = environmentName !== "client";
|
|
1575
|
+
let resolveOptions = environmentOptionsResolvers[environmentName];
|
|
1576
|
+
invariant(resolveOptions);
|
|
1577
|
+
let environmentBuildContext = {
|
|
1578
|
+
name: environmentName,
|
|
1579
|
+
resolveOptions
|
|
1580
|
+
};
|
|
1192
1581
|
await vite2.build({
|
|
1193
1582
|
root,
|
|
1194
1583
|
mode,
|
|
@@ -1203,43 +1592,41 @@ async function build(root, {
|
|
|
1203
1592
|
optimizeDeps: { force },
|
|
1204
1593
|
clearScreen,
|
|
1205
1594
|
logLevel,
|
|
1206
|
-
...
|
|
1595
|
+
...{ __reactRouterEnvironmentBuildContext: environmentBuildContext }
|
|
1207
1596
|
});
|
|
1208
1597
|
}
|
|
1598
|
+
let { reactRouterConfig } = ctx;
|
|
1599
|
+
let buildManifest = await getBuildManifest(ctx);
|
|
1600
|
+
let environmentOptionsResolvers = await getEnvironmentOptionsResolvers(
|
|
1601
|
+
ctx,
|
|
1602
|
+
buildManifest,
|
|
1603
|
+
"build"
|
|
1604
|
+
);
|
|
1605
|
+
let environmentsOptions = resolveEnvironmentsOptions(
|
|
1606
|
+
environmentOptionsResolvers,
|
|
1607
|
+
{ viteUserConfig }
|
|
1608
|
+
);
|
|
1209
1609
|
await cleanBuildDirectory(viteConfig, ctx);
|
|
1210
|
-
await
|
|
1211
|
-
let
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
await Promise.all(
|
|
1215
|
-
viteManifestPaths.map(async (viteManifestPath) => {
|
|
1216
|
-
let manifestExists = await import_fs_extra.default.pathExists(viteManifestPath);
|
|
1217
|
-
if (!manifestExists) return;
|
|
1218
|
-
if (!ctx.viteManifestEnabled) {
|
|
1219
|
-
await import_fs_extra.default.remove(viteManifestPath);
|
|
1220
|
-
}
|
|
1221
|
-
let viteDir = import_node_path2.default.dirname(viteManifestPath);
|
|
1222
|
-
let viteDirFiles = await import_fs_extra.default.readdir(viteDir);
|
|
1223
|
-
if (viteDirFiles.length === 0) {
|
|
1224
|
-
await import_fs_extra.default.remove(viteDir);
|
|
1225
|
-
}
|
|
1226
|
-
})
|
|
1610
|
+
await buildEnvironment("client");
|
|
1611
|
+
let serverEnvironmentNames = getServerEnvironmentKeys(
|
|
1612
|
+
environmentOptionsResolvers,
|
|
1613
|
+
buildManifest
|
|
1227
1614
|
);
|
|
1615
|
+
await Promise.all(serverEnvironmentNames.map(buildEnvironment));
|
|
1616
|
+
await cleanViteManifests(environmentsOptions, ctx);
|
|
1228
1617
|
await reactRouterConfig.buildEnd?.({
|
|
1229
1618
|
buildManifest,
|
|
1230
1619
|
reactRouterConfig,
|
|
1231
1620
|
viteConfig
|
|
1232
1621
|
});
|
|
1233
1622
|
}
|
|
1234
|
-
var
|
|
1623
|
+
var import_picocolors5;
|
|
1235
1624
|
var init_build = __esm({
|
|
1236
1625
|
"vite/build.ts"() {
|
|
1237
1626
|
"use strict";
|
|
1238
|
-
import_node_path2 = __toESM(require("path"));
|
|
1239
|
-
import_fs_extra = __toESM(require("fs-extra"));
|
|
1240
1627
|
import_picocolors5 = __toESM(require("picocolors"));
|
|
1241
|
-
init_plugin();
|
|
1242
1628
|
init_config();
|
|
1629
|
+
init_plugin();
|
|
1243
1630
|
init_invariant();
|
|
1244
1631
|
init_vite();
|
|
1245
1632
|
}
|
|
@@ -1314,8 +1701,8 @@ var import_semver = __toESM(require("semver"));
|
|
|
1314
1701
|
var import_picocolors8 = __toESM(require("picocolors"));
|
|
1315
1702
|
|
|
1316
1703
|
// cli/commands.ts
|
|
1317
|
-
var
|
|
1318
|
-
var
|
|
1704
|
+
var path8 = __toESM(require("path"));
|
|
1705
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
1319
1706
|
var import_package_json2 = __toESM(require("@npmcli/package-json"));
|
|
1320
1707
|
var import_exit_hook = __toESM(require("exit-hook"));
|
|
1321
1708
|
var import_picocolors7 = __toESM(require("picocolors"));
|
|
@@ -1468,14 +1855,14 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1468
1855
|
console.error(import_picocolors7.default.red(`No default server entry detected.`));
|
|
1469
1856
|
return;
|
|
1470
1857
|
}
|
|
1471
|
-
let defaultsDirectory =
|
|
1472
|
-
|
|
1858
|
+
let defaultsDirectory = path8.resolve(
|
|
1859
|
+
path8.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1473
1860
|
"dist",
|
|
1474
1861
|
"config",
|
|
1475
1862
|
"defaults"
|
|
1476
1863
|
);
|
|
1477
|
-
let defaultEntryClient =
|
|
1478
|
-
let defaultEntryServer =
|
|
1864
|
+
let defaultEntryClient = path8.resolve(defaultsDirectory, "entry.client.tsx");
|
|
1865
|
+
let defaultEntryServer = path8.resolve(
|
|
1479
1866
|
defaultsDirectory,
|
|
1480
1867
|
`entry.server.node.tsx`
|
|
1481
1868
|
);
|
|
@@ -1484,19 +1871,19 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1484
1871
|
let useTypeScript = flags.typescript ?? true;
|
|
1485
1872
|
let outputExtension = useTypeScript ? "tsx" : "jsx";
|
|
1486
1873
|
let outputEntry = `${entry}.${outputExtension}`;
|
|
1487
|
-
let outputFile2 =
|
|
1874
|
+
let outputFile2 = path8.resolve(appDirectory, outputEntry);
|
|
1488
1875
|
if (!useTypeScript) {
|
|
1489
1876
|
let javascript = transpile(contents, {
|
|
1490
1877
|
cwd: rootDirectory,
|
|
1491
1878
|
filename: isServerEntry ? defaultEntryServer : defaultEntryClient
|
|
1492
1879
|
});
|
|
1493
|
-
await
|
|
1880
|
+
await import_fs_extra.default.writeFile(outputFile2, javascript, "utf-8");
|
|
1494
1881
|
} else {
|
|
1495
|
-
await
|
|
1882
|
+
await import_fs_extra.default.writeFile(outputFile2, contents, "utf-8");
|
|
1496
1883
|
}
|
|
1497
1884
|
console.log(
|
|
1498
1885
|
import_picocolors7.default.blue(
|
|
1499
|
-
`Entry file ${entry} created at ${
|
|
1886
|
+
`Entry file ${entry} created at ${path8.relative(
|
|
1500
1887
|
rootDirectory,
|
|
1501
1888
|
outputFile2
|
|
1502
1889
|
)}.`
|
|
@@ -1505,10 +1892,10 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1505
1892
|
}
|
|
1506
1893
|
async function checkForEntry(rootDirectory, appDirectory, entries2) {
|
|
1507
1894
|
for (let entry of entries2) {
|
|
1508
|
-
let entryPath =
|
|
1509
|
-
let exists = await
|
|
1895
|
+
let entryPath = path8.resolve(appDirectory, entry);
|
|
1896
|
+
let exists = await import_fs_extra.default.pathExists(entryPath);
|
|
1510
1897
|
if (exists) {
|
|
1511
|
-
let relative8 =
|
|
1898
|
+
let relative8 = path8.relative(rootDirectory, entryPath);
|
|
1512
1899
|
console.error(import_picocolors7.default.red(`Entry file ${relative8} already exists.`));
|
|
1513
1900
|
return process.exit(1);
|
|
1514
1901
|
}
|
|
@@ -1516,12 +1903,12 @@ async function checkForEntry(rootDirectory, appDirectory, entries2) {
|
|
|
1516
1903
|
}
|
|
1517
1904
|
async function createServerEntry(rootDirectory, appDirectory, inputFile) {
|
|
1518
1905
|
await checkForEntry(rootDirectory, appDirectory, serverEntries);
|
|
1519
|
-
let contents = await
|
|
1906
|
+
let contents = await import_fs_extra.default.readFile(inputFile, "utf-8");
|
|
1520
1907
|
return contents;
|
|
1521
1908
|
}
|
|
1522
1909
|
async function createClientEntry(rootDirectory, appDirectory, inputFile) {
|
|
1523
1910
|
await checkForEntry(rootDirectory, appDirectory, clientEntries);
|
|
1524
|
-
let contents = await
|
|
1911
|
+
let contents = await import_fs_extra.default.readFile(inputFile, "utf-8");
|
|
1525
1912
|
return contents;
|
|
1526
1913
|
}
|
|
1527
1914
|
async function typegen(root, flags) {
|
|
@@ -1671,7 +2058,7 @@ async function run2(argv = process.argv.slice(2)) {
|
|
|
1671
2058
|
return;
|
|
1672
2059
|
}
|
|
1673
2060
|
if (flags.version) {
|
|
1674
|
-
let version = require("
|
|
2061
|
+
let version = require("../../package.json").version;
|
|
1675
2062
|
console.log(version);
|
|
1676
2063
|
return;
|
|
1677
2064
|
}
|