@react-router/dev 0.0.0-experimental-2bfe0a2f2 → 0.0.0-experimental-d312c78a4
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 +30 -0
- package/bin.js +13 -0
- package/dist/cli/index.js +166 -118
- package/dist/config.d.ts +5 -1
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/static/refresh-utils.cjs +1 -0
- package/dist/vite/cloudflare.js +48 -7
- package/dist/vite.js +1306 -349
- package/package.json +10 -10
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-d312c78a4
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -46,8 +46,8 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
46
46
|
|
|
47
47
|
// vite/plugin.ts
|
|
48
48
|
var import_node_crypto = require("crypto");
|
|
49
|
-
var
|
|
50
|
-
var
|
|
49
|
+
var path6 = __toESM(require("path"));
|
|
50
|
+
var url = __toESM(require("url"));
|
|
51
51
|
var fse = __toESM(require("fs-extra"));
|
|
52
52
|
var babel = __toESM(require("@babel/core"));
|
|
53
53
|
var import_react_router2 = require("react-router");
|
|
@@ -70,6 +70,9 @@ var import_server = require("vite-node/server");
|
|
|
70
70
|
var import_client = require("vite-node/client");
|
|
71
71
|
var import_source_map = require("vite-node/source-map");
|
|
72
72
|
|
|
73
|
+
// vite/vite.ts
|
|
74
|
+
var import_pathe2 = __toESM(require("pathe"));
|
|
75
|
+
|
|
73
76
|
// invariant.ts
|
|
74
77
|
function invariant(value, message) {
|
|
75
78
|
if (value === false || value === null || typeof value === "undefined") {
|
|
@@ -80,20 +83,41 @@ function invariant(value, message) {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
//
|
|
86
|
+
// config/is-react-router-repo.ts
|
|
87
|
+
var import_pathe = __toESM(require("pathe"));
|
|
88
|
+
function isReactRouterRepo() {
|
|
89
|
+
let serverRuntimePath = import_pathe.default.dirname(
|
|
90
|
+
require.resolve("@react-router/node/package.json")
|
|
91
|
+
);
|
|
92
|
+
let serverRuntimeParentDir = import_pathe.default.basename(
|
|
93
|
+
import_pathe.default.resolve(serverRuntimePath, "..")
|
|
94
|
+
);
|
|
95
|
+
return serverRuntimeParentDir === "packages";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// vite/vite.ts
|
|
84
99
|
var vite;
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
var viteImportSpecifier = isReactRouterRepo() ? (
|
|
101
|
+
// Support testing against different versions of Vite by ensuring that Vite
|
|
102
|
+
// is resolved from the current working directory when running within this
|
|
103
|
+
// repo. If we don't do this, Vite will always be imported relative to this
|
|
104
|
+
// file, which means that it will always resolve to Vite 6.
|
|
105
|
+
`file:///${import_pathe2.default.normalize(
|
|
106
|
+
require.resolve("vite/package.json", { paths: [process.cwd()] })
|
|
107
|
+
).replace("package.json", "dist/node/index.js")}`
|
|
108
|
+
) : "vite";
|
|
109
|
+
async function preloadVite() {
|
|
110
|
+
vite = await import(viteImportSpecifier);
|
|
87
111
|
}
|
|
88
|
-
function
|
|
89
|
-
invariant(vite, "
|
|
112
|
+
function getVite() {
|
|
113
|
+
invariant(vite, "getVite() called before preloadVite()");
|
|
90
114
|
return vite;
|
|
91
115
|
}
|
|
92
116
|
|
|
93
117
|
// vite/vite-node.ts
|
|
94
118
|
async function createContext(viteConfig = {}) {
|
|
95
|
-
await
|
|
96
|
-
const vite2 =
|
|
119
|
+
await preloadVite();
|
|
120
|
+
const vite2 = getVite();
|
|
97
121
|
const devServer = await vite2.createServer(
|
|
98
122
|
vite2.mergeConfig(
|
|
99
123
|
{
|
|
@@ -119,18 +143,18 @@ async function createContext(viteConfig = {}) {
|
|
|
119
143
|
const runner = new import_client.ViteNodeRunner({
|
|
120
144
|
root: devServer.config.root,
|
|
121
145
|
base: devServer.config.base,
|
|
122
|
-
fetchModule(
|
|
123
|
-
return server.fetchModule(
|
|
146
|
+
fetchModule(id) {
|
|
147
|
+
return server.fetchModule(id);
|
|
124
148
|
},
|
|
125
|
-
resolveId(
|
|
126
|
-
return server.resolveId(
|
|
149
|
+
resolveId(id, importer) {
|
|
150
|
+
return server.resolveId(id, importer);
|
|
127
151
|
}
|
|
128
152
|
});
|
|
129
153
|
return { devServer, server, runner };
|
|
130
154
|
}
|
|
131
155
|
|
|
132
156
|
// config/config.ts
|
|
133
|
-
var
|
|
157
|
+
var import_pathe3 = __toESM(require("pathe"));
|
|
134
158
|
var import_chokidar = __toESM(require("chokidar"));
|
|
135
159
|
var import_picocolors = __toESM(require("picocolors"));
|
|
136
160
|
var import_pick2 = __toESM(require("lodash/pick"));
|
|
@@ -184,7 +208,7 @@ function validateRouteConfig({
|
|
|
184
208
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
185
209
|
root ? `${root}` : [],
|
|
186
210
|
nested ? Object.entries(nested).map(
|
|
187
|
-
([
|
|
211
|
+
([path7, message]) => `Path: routes.${path7}
|
|
188
212
|
${message}`
|
|
189
213
|
) : []
|
|
190
214
|
].flat().join("\n\n")
|
|
@@ -195,24 +219,24 @@ ${message}`
|
|
|
195
219
|
function configRoutesToRouteManifest(appDirectory, routes, rootId = "root") {
|
|
196
220
|
let routeManifest = {};
|
|
197
221
|
function walk(route, parentId) {
|
|
198
|
-
let
|
|
222
|
+
let id = route.id || createRouteId(route.file);
|
|
199
223
|
let manifestItem = {
|
|
200
|
-
id
|
|
224
|
+
id,
|
|
201
225
|
parentId,
|
|
202
226
|
file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
|
|
203
227
|
path: route.path,
|
|
204
228
|
index: route.index,
|
|
205
229
|
caseSensitive: route.caseSensitive
|
|
206
230
|
};
|
|
207
|
-
if (routeManifest.hasOwnProperty(
|
|
231
|
+
if (routeManifest.hasOwnProperty(id)) {
|
|
208
232
|
throw new Error(
|
|
209
|
-
`Unable to define routes with duplicate route id: "${
|
|
233
|
+
`Unable to define routes with duplicate route id: "${id}"`
|
|
210
234
|
);
|
|
211
235
|
}
|
|
212
|
-
routeManifest[
|
|
236
|
+
routeManifest[id] = manifestItem;
|
|
213
237
|
if (route.children) {
|
|
214
238
|
for (let child of route.children) {
|
|
215
|
-
walk(child,
|
|
239
|
+
walk(child, id);
|
|
216
240
|
}
|
|
217
241
|
}
|
|
218
242
|
}
|
|
@@ -347,6 +371,7 @@ async function resolveConfig({
|
|
|
347
371
|
basename: basename2,
|
|
348
372
|
buildDirectory: userBuildDirectory,
|
|
349
373
|
buildEnd,
|
|
374
|
+
future: userFuture,
|
|
350
375
|
prerender,
|
|
351
376
|
serverBuildFile,
|
|
352
377
|
serverBundles,
|
|
@@ -366,13 +391,13 @@ async function resolveConfig({
|
|
|
366
391
|
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
367
392
|
);
|
|
368
393
|
}
|
|
369
|
-
let appDirectory =
|
|
370
|
-
let buildDirectory =
|
|
394
|
+
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
395
|
+
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
371
396
|
let rootRouteFile = findEntry(appDirectory, "root");
|
|
372
397
|
if (!rootRouteFile) {
|
|
373
|
-
let rootRouteDisplayPath =
|
|
398
|
+
let rootRouteDisplayPath = import_pathe3.default.relative(
|
|
374
399
|
root,
|
|
375
|
-
|
|
400
|
+
import_pathe3.default.join(appDirectory, "root.tsx")
|
|
376
401
|
);
|
|
377
402
|
return err(
|
|
378
403
|
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
@@ -384,15 +409,15 @@ async function resolveConfig({
|
|
|
384
409
|
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
385
410
|
try {
|
|
386
411
|
if (!routeConfigFile) {
|
|
387
|
-
let routeConfigDisplayPath =
|
|
412
|
+
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
388
413
|
root,
|
|
389
|
-
|
|
414
|
+
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
390
415
|
);
|
|
391
416
|
return err(`Route config file not found at "${routeConfigDisplayPath}".`);
|
|
392
417
|
}
|
|
393
418
|
setAppDirectory(appDirectory);
|
|
394
419
|
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
395
|
-
|
|
420
|
+
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
396
421
|
)).default;
|
|
397
422
|
let routeConfig = await routeConfigExport;
|
|
398
423
|
let result = validateRouteConfig({
|
|
@@ -412,14 +437,15 @@ async function resolveConfig({
|
|
|
412
437
|
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
413
438
|
"",
|
|
414
439
|
error.loc?.file && error.loc?.column && error.frame ? [
|
|
415
|
-
|
|
440
|
+
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
416
441
|
error.frame.trim?.()
|
|
417
442
|
] : error.stack
|
|
418
443
|
].flat().join("\n")
|
|
419
444
|
);
|
|
420
445
|
}
|
|
421
446
|
let future = {
|
|
422
|
-
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
447
|
+
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
|
|
448
|
+
unstable_routeChunks: userFuture?.unstable_routeChunks ?? false
|
|
423
449
|
};
|
|
424
450
|
let reactRouterConfig = deepFreeze({
|
|
425
451
|
appDirectory,
|
|
@@ -484,8 +510,8 @@ async function createConfigLoader({
|
|
|
484
510
|
);
|
|
485
511
|
fsWatcher.on("all", async (...args) => {
|
|
486
512
|
let [event, rawFilepath] = args;
|
|
487
|
-
let filepath =
|
|
488
|
-
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(
|
|
513
|
+
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
514
|
+
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
489
515
|
let configCodeUpdated = Boolean(
|
|
490
516
|
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
491
517
|
);
|
|
@@ -531,8 +557,8 @@ async function resolveEntryFiles({
|
|
|
531
557
|
reactRouterConfig
|
|
532
558
|
}) {
|
|
533
559
|
let { appDirectory } = reactRouterConfig;
|
|
534
|
-
let defaultsDirectory =
|
|
535
|
-
|
|
560
|
+
let defaultsDirectory = import_pathe3.default.resolve(
|
|
561
|
+
import_pathe3.default.dirname(require.resolve("@react-router/dev/package.json")),
|
|
536
562
|
"dist",
|
|
537
563
|
"config",
|
|
538
564
|
"defaults"
|
|
@@ -570,11 +596,11 @@ async function resolveEntryFiles({
|
|
|
570
596
|
}
|
|
571
597
|
entryServerFile = `entry.server.node.tsx`;
|
|
572
598
|
}
|
|
573
|
-
let entryClientFilePath = userEntryClientFile ?
|
|
574
|
-
let entryServerFilePath = userEntryServerFile ?
|
|
599
|
+
let entryClientFilePath = userEntryClientFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_pathe3.default.resolve(defaultsDirectory, entryClientFile);
|
|
600
|
+
let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
|
|
575
601
|
return { entryClientFilePath, entryServerFilePath };
|
|
576
602
|
}
|
|
577
|
-
var ssrExternals =
|
|
603
|
+
var ssrExternals = isReactRouterRepo() ? [
|
|
578
604
|
// This is only needed within this repo because these packages
|
|
579
605
|
// are linked to a directory outside of node_modules so Vite
|
|
580
606
|
// treats them as internal code by default.
|
|
@@ -587,21 +613,12 @@ var ssrExternals = isInReactRouterMonorepo() ? [
|
|
|
587
613
|
"@react-router/node",
|
|
588
614
|
"@react-router/serve"
|
|
589
615
|
] : void 0;
|
|
590
|
-
function isInReactRouterMonorepo() {
|
|
591
|
-
let serverRuntimePath = import_pathe.default.dirname(
|
|
592
|
-
require.resolve("@react-router/node/package.json")
|
|
593
|
-
);
|
|
594
|
-
let serverRuntimeParentDir = import_pathe.default.basename(
|
|
595
|
-
import_pathe.default.resolve(serverRuntimePath, "..")
|
|
596
|
-
);
|
|
597
|
-
return serverRuntimeParentDir === "packages";
|
|
598
|
-
}
|
|
599
616
|
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
600
617
|
function findEntry(dir, basename2, options) {
|
|
601
618
|
for (let ext of entryExts) {
|
|
602
|
-
let file =
|
|
619
|
+
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
603
620
|
if (import_node_fs.default.existsSync(file)) {
|
|
604
|
-
return options?.absolute ?? false ? file :
|
|
621
|
+
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
605
622
|
}
|
|
606
623
|
}
|
|
607
624
|
return void 0;
|
|
@@ -677,8 +694,6 @@ function generate(ctx, route) {
|
|
|
677
694
|
export type HeadersArgs = T.HeadersArgs
|
|
678
695
|
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
679
696
|
|
|
680
|
-
export type MiddlewareArgs = T.CreateServerMiddlewareArgs<Info>
|
|
681
|
-
export type ClientMiddlewareArgs = T.CreateClientMiddlewareArgs<Info>
|
|
682
697
|
export type LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
683
698
|
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
684
699
|
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
@@ -690,7 +705,7 @@ function generate(ctx, route) {
|
|
|
690
705
|
}
|
|
691
706
|
`;
|
|
692
707
|
}
|
|
693
|
-
var noExtension = (
|
|
708
|
+
var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
|
|
694
709
|
function getRouteLineage(routes, route) {
|
|
695
710
|
const result = [];
|
|
696
711
|
while (route) {
|
|
@@ -814,7 +829,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
814
829
|
nodeReq.originalUrl,
|
|
815
830
|
"Expected `nodeReq.originalUrl` to be defined"
|
|
816
831
|
);
|
|
817
|
-
let
|
|
832
|
+
let url2 = new URL(nodeReq.originalUrl, origin);
|
|
818
833
|
let controller = new AbortController();
|
|
819
834
|
let init = {
|
|
820
835
|
method: nodeReq.method,
|
|
@@ -827,7 +842,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
827
842
|
init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
|
|
828
843
|
init.duplex = "half";
|
|
829
844
|
}
|
|
830
|
-
return new Request(
|
|
845
|
+
return new Request(url2.href, init);
|
|
831
846
|
}
|
|
832
847
|
async function toNodeRequest(res, nodeRes) {
|
|
833
848
|
nodeRes.statusCode = res.status;
|
|
@@ -852,17 +867,17 @@ async function toNodeRequest(res, nodeRes) {
|
|
|
852
867
|
}
|
|
853
868
|
|
|
854
869
|
// vite/styles.ts
|
|
855
|
-
var
|
|
870
|
+
var path5 = __toESM(require("path"));
|
|
856
871
|
var import_react_router = require("react-router");
|
|
857
872
|
|
|
858
873
|
// vite/resolve-file-url.ts
|
|
859
|
-
var
|
|
874
|
+
var path4 = __toESM(require("path"));
|
|
860
875
|
var resolveFileUrl = ({ rootDirectory }, filePath) => {
|
|
861
|
-
let vite2 =
|
|
862
|
-
let relativePath =
|
|
863
|
-
let isWithinRoot = !relativePath.startsWith("..") && !
|
|
876
|
+
let vite2 = getVite();
|
|
877
|
+
let relativePath = path4.relative(rootDirectory, filePath);
|
|
878
|
+
let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
|
|
864
879
|
if (!isWithinRoot) {
|
|
865
|
-
return
|
|
880
|
+
return path4.posix.join("/@fs", vite2.normalizePath(filePath));
|
|
866
881
|
}
|
|
867
882
|
return "/" + vite2.normalizePath(relativePath);
|
|
868
883
|
};
|
|
@@ -873,8 +888,8 @@ var cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
|
873
888
|
var isCssFile = (file) => cssFileRegExp.test(file);
|
|
874
889
|
var isCssModulesFile = (file) => cssModulesRegExp.test(file);
|
|
875
890
|
var cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
|
|
876
|
-
var isCssUrlWithoutSideEffects = (
|
|
877
|
-
let queryString =
|
|
891
|
+
var isCssUrlWithoutSideEffects = (url2) => {
|
|
892
|
+
let queryString = url2.split("?")[1];
|
|
878
893
|
if (!queryString) {
|
|
879
894
|
return false;
|
|
880
895
|
}
|
|
@@ -882,24 +897,27 @@ var isCssUrlWithoutSideEffects = (url3) => {
|
|
|
882
897
|
for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
|
|
883
898
|
if (
|
|
884
899
|
// Parameter is blank and not explicitly set, i.e. "?url", not "?url="
|
|
885
|
-
params.get(paramWithoutSideEffects) === "" && !
|
|
900
|
+
params.get(paramWithoutSideEffects) === "" && !url2.includes(`?${paramWithoutSideEffects}=`) && !url2.includes(`&${paramWithoutSideEffects}=`)
|
|
886
901
|
) {
|
|
887
902
|
return true;
|
|
888
903
|
}
|
|
889
904
|
}
|
|
890
905
|
return false;
|
|
891
906
|
};
|
|
907
|
+
var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
|
|
892
908
|
var getStylesForFiles = async ({
|
|
893
909
|
viteDevServer,
|
|
894
910
|
rootDirectory,
|
|
895
911
|
cssModulesManifest,
|
|
896
912
|
files
|
|
897
913
|
}) => {
|
|
914
|
+
let vite2 = getVite();
|
|
915
|
+
let viteMajor = parseInt(vite2.version.split(".")[0], 10);
|
|
898
916
|
let styles = {};
|
|
899
917
|
let deps = /* @__PURE__ */ new Set();
|
|
900
918
|
try {
|
|
901
919
|
for (let file of files) {
|
|
902
|
-
let normalizedPath =
|
|
920
|
+
let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
|
|
903
921
|
let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
904
922
|
if (!node) {
|
|
905
923
|
try {
|
|
@@ -923,7 +941,15 @@ var getStylesForFiles = async ({
|
|
|
923
941
|
for (let dep of deps) {
|
|
924
942
|
if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url)) {
|
|
925
943
|
try {
|
|
926
|
-
let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(
|
|
944
|
+
let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(
|
|
945
|
+
// We need the ?inline query in Vite v6 when loading CSS in SSR
|
|
946
|
+
// since it does not expose the default export for CSS in a
|
|
947
|
+
// server environment. This is to align with non-SSR
|
|
948
|
+
// environments. For backwards compatibility with v5 we keep
|
|
949
|
+
// using the URL without ?inline query because the HMR code was
|
|
950
|
+
// relying on the implicit SSR-client module graph relationship.
|
|
951
|
+
viteMajor >= 6 ? injectQuery(dep.url, "inline") : dep.url
|
|
952
|
+
)).default;
|
|
927
953
|
if (css === void 0) {
|
|
928
954
|
throw new Error();
|
|
929
955
|
}
|
|
@@ -947,8 +973,8 @@ var findDeps = async (vite2, node, deps) => {
|
|
|
947
973
|
await findDeps(vite2, node2, deps);
|
|
948
974
|
}
|
|
949
975
|
}
|
|
950
|
-
async function addFromUrl(
|
|
951
|
-
let node2 = await vite2.moduleGraph.getModuleByUrl(
|
|
976
|
+
async function addFromUrl(url2) {
|
|
977
|
+
let node2 = await vite2.moduleGraph.getModuleByUrl(url2);
|
|
952
978
|
if (node2) {
|
|
953
979
|
await addFromNode(node2);
|
|
954
980
|
}
|
|
@@ -956,7 +982,7 @@ var findDeps = async (vite2, node, deps) => {
|
|
|
956
982
|
if (node.ssrTransformResult) {
|
|
957
983
|
if (node.ssrTransformResult.deps) {
|
|
958
984
|
node.ssrTransformResult.deps.forEach(
|
|
959
|
-
(
|
|
985
|
+
(url2) => branches.push(addFromUrl(url2))
|
|
960
986
|
);
|
|
961
987
|
}
|
|
962
988
|
} else {
|
|
@@ -990,15 +1016,15 @@ var getStylesForUrl = async ({
|
|
|
990
1016
|
entryClientFilePath,
|
|
991
1017
|
cssModulesManifest,
|
|
992
1018
|
build,
|
|
993
|
-
url:
|
|
1019
|
+
url: url2
|
|
994
1020
|
}) => {
|
|
995
|
-
if (
|
|
1021
|
+
if (url2 === void 0 || url2.includes("?_data=")) {
|
|
996
1022
|
return void 0;
|
|
997
1023
|
}
|
|
998
1024
|
let routes = createRoutes(build.routes);
|
|
999
|
-
let appPath =
|
|
1000
|
-
let documentRouteFiles = (0, import_react_router.matchRoutes)(routes,
|
|
1001
|
-
(match) =>
|
|
1025
|
+
let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
|
|
1026
|
+
let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url2, build.basename)?.map(
|
|
1027
|
+
(match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
|
|
1002
1028
|
) ?? [];
|
|
1003
1029
|
let styles = await getStylesForFiles({
|
|
1004
1030
|
viteDevServer,
|
|
@@ -1006,7 +1032,7 @@ var getStylesForUrl = async ({
|
|
|
1006
1032
|
cssModulesManifest,
|
|
1007
1033
|
files: [
|
|
1008
1034
|
// Always include the client entry file when crawling the module graph for CSS
|
|
1009
|
-
|
|
1035
|
+
path5.relative(rootDirectory, entryClientFilePath),
|
|
1010
1036
|
// Then include any styles from the matched routes
|
|
1011
1037
|
...documentRouteFiles
|
|
1012
1038
|
]
|
|
@@ -1014,10 +1040,15 @@ var getStylesForUrl = async ({
|
|
|
1014
1040
|
return styles;
|
|
1015
1041
|
};
|
|
1016
1042
|
|
|
1017
|
-
// vite/
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1043
|
+
// vite/virtual-module.ts
|
|
1044
|
+
function create(name) {
|
|
1045
|
+
let id = `virtual:react-router/${name}`;
|
|
1046
|
+
return {
|
|
1047
|
+
id,
|
|
1048
|
+
resolvedId: `\0${id}`,
|
|
1049
|
+
url: `/@id/__x00__${id}`
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1021
1052
|
|
|
1022
1053
|
// vite/combine-urls.ts
|
|
1023
1054
|
function combineURLs(baseURL, relativeURL) {
|
|
@@ -1031,10 +1062,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1031
1062
|
let exportsFiltered = false;
|
|
1032
1063
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1033
1064
|
traverse(ast, {
|
|
1034
|
-
ExportDeclaration(
|
|
1035
|
-
if (
|
|
1036
|
-
if (
|
|
1037
|
-
|
|
1065
|
+
ExportDeclaration(path7) {
|
|
1066
|
+
if (path7.node.type === "ExportNamedDeclaration") {
|
|
1067
|
+
if (path7.node.specifiers.length) {
|
|
1068
|
+
path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
|
|
1038
1069
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1039
1070
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1040
1071
|
exportsFiltered = true;
|
|
@@ -1043,12 +1074,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1043
1074
|
}
|
|
1044
1075
|
return true;
|
|
1045
1076
|
});
|
|
1046
|
-
if (
|
|
1047
|
-
markedForRemoval.add(
|
|
1077
|
+
if (path7.node.specifiers.length === 0) {
|
|
1078
|
+
markedForRemoval.add(path7);
|
|
1048
1079
|
}
|
|
1049
1080
|
}
|
|
1050
|
-
if (
|
|
1051
|
-
let declaration =
|
|
1081
|
+
if (path7.node.declaration?.type === "VariableDeclaration") {
|
|
1082
|
+
let declaration = path7.node.declaration;
|
|
1052
1083
|
declaration.declarations = declaration.declarations.filter(
|
|
1053
1084
|
(declaration2) => {
|
|
1054
1085
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1062,37 +1093,37 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1062
1093
|
}
|
|
1063
1094
|
);
|
|
1064
1095
|
if (declaration.declarations.length === 0) {
|
|
1065
|
-
markedForRemoval.add(
|
|
1096
|
+
markedForRemoval.add(path7);
|
|
1066
1097
|
}
|
|
1067
1098
|
}
|
|
1068
|
-
if (
|
|
1069
|
-
let
|
|
1070
|
-
if (
|
|
1071
|
-
markedForRemoval.add(
|
|
1099
|
+
if (path7.node.declaration?.type === "FunctionDeclaration") {
|
|
1100
|
+
let id = path7.node.declaration.id;
|
|
1101
|
+
if (id && exportsToRemove.includes(id.name)) {
|
|
1102
|
+
markedForRemoval.add(path7);
|
|
1072
1103
|
}
|
|
1073
1104
|
}
|
|
1074
|
-
if (
|
|
1075
|
-
let
|
|
1076
|
-
if (
|
|
1077
|
-
markedForRemoval.add(
|
|
1105
|
+
if (path7.node.declaration?.type === "ClassDeclaration") {
|
|
1106
|
+
let id = path7.node.declaration.id;
|
|
1107
|
+
if (id && exportsToRemove.includes(id.name)) {
|
|
1108
|
+
markedForRemoval.add(path7);
|
|
1078
1109
|
}
|
|
1079
1110
|
}
|
|
1080
1111
|
}
|
|
1081
|
-
if (
|
|
1082
|
-
markedForRemoval.add(
|
|
1112
|
+
if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
1113
|
+
markedForRemoval.add(path7);
|
|
1083
1114
|
}
|
|
1084
1115
|
}
|
|
1085
1116
|
});
|
|
1086
1117
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1087
|
-
for (let
|
|
1088
|
-
|
|
1118
|
+
for (let path7 of markedForRemoval) {
|
|
1119
|
+
path7.remove();
|
|
1089
1120
|
}
|
|
1090
1121
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1091
1122
|
}
|
|
1092
1123
|
};
|
|
1093
|
-
function validateDestructuredExports(
|
|
1094
|
-
if (
|
|
1095
|
-
for (let element of
|
|
1124
|
+
function validateDestructuredExports(id, exportsToRemove) {
|
|
1125
|
+
if (id.type === "ArrayPattern") {
|
|
1126
|
+
for (let element of id.elements) {
|
|
1096
1127
|
if (!element) {
|
|
1097
1128
|
continue;
|
|
1098
1129
|
}
|
|
@@ -1107,8 +1138,8 @@ function validateDestructuredExports(id2, exportsToRemove) {
|
|
|
1107
1138
|
}
|
|
1108
1139
|
}
|
|
1109
1140
|
}
|
|
1110
|
-
if (
|
|
1111
|
-
for (let property of
|
|
1141
|
+
if (id.type === "ObjectPattern") {
|
|
1142
|
+
for (let property of id.properties) {
|
|
1112
1143
|
if (!property) {
|
|
1113
1144
|
continue;
|
|
1114
1145
|
}
|
|
@@ -1130,18 +1161,619 @@ function invalidDestructureError(name) {
|
|
|
1130
1161
|
return new Error(`Cannot remove destructured export "${name}"`);
|
|
1131
1162
|
}
|
|
1132
1163
|
|
|
1164
|
+
// vite/cache.ts
|
|
1165
|
+
function getOrSetFromCache(cache, key, version, getValue) {
|
|
1166
|
+
if (!cache) {
|
|
1167
|
+
return getValue();
|
|
1168
|
+
}
|
|
1169
|
+
let entry = cache.get(key);
|
|
1170
|
+
if (entry?.version === version) {
|
|
1171
|
+
return entry.value;
|
|
1172
|
+
}
|
|
1173
|
+
let value = getValue();
|
|
1174
|
+
let newEntry = { value, version };
|
|
1175
|
+
cache.set(key, newEntry);
|
|
1176
|
+
return value;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// vite/route-chunks.ts
|
|
1180
|
+
function codeToAst(code, cache, cacheKey) {
|
|
1181
|
+
return structuredClone(
|
|
1182
|
+
getOrSetFromCache(
|
|
1183
|
+
cache,
|
|
1184
|
+
`${cacheKey}::codeToAst`,
|
|
1185
|
+
code,
|
|
1186
|
+
() => (0, import_parser.parse)(code, { sourceType: "module" })
|
|
1187
|
+
)
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
function assertNodePath(path7) {
|
|
1191
|
+
invariant(
|
|
1192
|
+
path7 && !Array.isArray(path7),
|
|
1193
|
+
`Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
function assertNodePathIsStatement(path7) {
|
|
1197
|
+
invariant(
|
|
1198
|
+
path7 && !Array.isArray(path7) && t.isStatement(path7.node),
|
|
1199
|
+
`Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1200
|
+
);
|
|
1201
|
+
}
|
|
1202
|
+
function assertNodePathIsVariableDeclarator(path7) {
|
|
1203
|
+
invariant(
|
|
1204
|
+
path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
|
|
1205
|
+
`Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
function assertNodePathIsPattern(path7) {
|
|
1209
|
+
invariant(
|
|
1210
|
+
path7 && !Array.isArray(path7) && t.isPattern(path7.node),
|
|
1211
|
+
`Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
function getExportDependencies(code, cache, cacheKey) {
|
|
1215
|
+
return getOrSetFromCache(
|
|
1216
|
+
cache,
|
|
1217
|
+
`${cacheKey}::getExportDependencies`,
|
|
1218
|
+
code,
|
|
1219
|
+
() => {
|
|
1220
|
+
let exportDependencies = /* @__PURE__ */ new Map();
|
|
1221
|
+
let ast = codeToAst(code, cache, cacheKey);
|
|
1222
|
+
function handleExport(exportName, exportPath, identifiersPath = exportPath) {
|
|
1223
|
+
let identifiers = getDependentIdentifiersForPath(identifiersPath);
|
|
1224
|
+
let topLevelStatements = /* @__PURE__ */ new Set([
|
|
1225
|
+
exportPath.node,
|
|
1226
|
+
...getTopLevelStatementsForPaths(identifiers)
|
|
1227
|
+
]);
|
|
1228
|
+
let topLevelNonModuleStatements = new Set(
|
|
1229
|
+
Array.from(topLevelStatements).filter(
|
|
1230
|
+
(statement) => !t.isImportDeclaration(statement) && !t.isExportDeclaration(statement)
|
|
1231
|
+
)
|
|
1232
|
+
);
|
|
1233
|
+
let importedIdentifierNames = /* @__PURE__ */ new Set();
|
|
1234
|
+
for (let identifier of identifiers) {
|
|
1235
|
+
if (identifier.parentPath.parentPath?.isImportDeclaration()) {
|
|
1236
|
+
importedIdentifierNames.add(identifier.node.name);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
let exportedVariableDeclarators = /* @__PURE__ */ new Set();
|
|
1240
|
+
for (let identifier of identifiers) {
|
|
1241
|
+
if (identifier.parentPath.isVariableDeclarator() && identifier.parentPath.parentPath.parentPath?.isExportNamedDeclaration()) {
|
|
1242
|
+
exportedVariableDeclarators.add(identifier.parentPath.node);
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
let isWithinExportNamedDeclaration = Boolean(
|
|
1246
|
+
identifier.findParent((path7) => path7.isExportNamedDeclaration())
|
|
1247
|
+
);
|
|
1248
|
+
if (isWithinExportNamedDeclaration) {
|
|
1249
|
+
let currentPath = identifier;
|
|
1250
|
+
while (currentPath) {
|
|
1251
|
+
if (
|
|
1252
|
+
// Check the identifier is within a variable declaration, and if
|
|
1253
|
+
// so, ensure we're on the left-hand side of the expression
|
|
1254
|
+
// since these identifiers are what make up the export names,
|
|
1255
|
+
// e.g. export const { foo } = { foo: bar }; should pick up
|
|
1256
|
+
// `foo` but not `bar`.
|
|
1257
|
+
currentPath.parentPath?.isVariableDeclarator() && currentPath.parentKey === "id"
|
|
1258
|
+
) {
|
|
1259
|
+
exportedVariableDeclarators.add(currentPath.parentPath.node);
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1262
|
+
currentPath = currentPath.parentPath;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
let dependencies = {
|
|
1267
|
+
topLevelStatements,
|
|
1268
|
+
topLevelNonModuleStatements,
|
|
1269
|
+
importedIdentifierNames,
|
|
1270
|
+
exportedVariableDeclarators
|
|
1271
|
+
};
|
|
1272
|
+
exportDependencies.set(exportName, dependencies);
|
|
1273
|
+
}
|
|
1274
|
+
traverse(ast, {
|
|
1275
|
+
ExportDeclaration(exportPath) {
|
|
1276
|
+
let { node } = exportPath;
|
|
1277
|
+
if (t.isExportAllDeclaration(node)) {
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
if (t.isExportDefaultDeclaration(node)) {
|
|
1281
|
+
handleExport("default", exportPath);
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
let { declaration } = node;
|
|
1285
|
+
if (t.isVariableDeclaration(declaration)) {
|
|
1286
|
+
let { declarations } = declaration;
|
|
1287
|
+
for (let i = 0; i < declarations.length; i++) {
|
|
1288
|
+
let declarator = declarations[i];
|
|
1289
|
+
if (t.isIdentifier(declarator.id)) {
|
|
1290
|
+
let declaratorPath = exportPath.get(
|
|
1291
|
+
`declaration.declarations.${i}`
|
|
1292
|
+
);
|
|
1293
|
+
assertNodePathIsVariableDeclarator(declaratorPath);
|
|
1294
|
+
handleExport(declarator.id.name, exportPath, declaratorPath);
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
if (t.isPattern(declarator.id)) {
|
|
1298
|
+
let exportedPatternPath = exportPath.get(
|
|
1299
|
+
`declaration.declarations.${i}.id`
|
|
1300
|
+
);
|
|
1301
|
+
assertNodePathIsPattern(exportedPatternPath);
|
|
1302
|
+
let identifiers = getIdentifiersForPatternPath(exportedPatternPath);
|
|
1303
|
+
for (let identifier of identifiers) {
|
|
1304
|
+
handleExport(identifier.node.name, exportPath, identifier);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
if (t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration)) {
|
|
1311
|
+
invariant(
|
|
1312
|
+
declaration.id,
|
|
1313
|
+
"Expected exported function or class declaration to have a name when not the default export"
|
|
1314
|
+
);
|
|
1315
|
+
handleExport(declaration.id.name, exportPath);
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
if (t.isExportNamedDeclaration(node)) {
|
|
1319
|
+
for (let specifier of node.specifiers) {
|
|
1320
|
+
if (t.isIdentifier(specifier.exported)) {
|
|
1321
|
+
let name = specifier.exported.name;
|
|
1322
|
+
let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
|
|
1323
|
+
invariant(
|
|
1324
|
+
specifierPath,
|
|
1325
|
+
`Expected to find specifier path for ${name}`
|
|
1326
|
+
);
|
|
1327
|
+
handleExport(name, exportPath, specifierPath);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
throw new Error(`Unknown export node type: ${node.type}`);
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
return exportDependencies;
|
|
1336
|
+
}
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
function getDependentIdentifiersForPath(path7, state) {
|
|
1340
|
+
let { visited, identifiers } = state ?? {
|
|
1341
|
+
visited: /* @__PURE__ */ new Set(),
|
|
1342
|
+
identifiers: /* @__PURE__ */ new Set()
|
|
1343
|
+
};
|
|
1344
|
+
if (visited.has(path7)) {
|
|
1345
|
+
return identifiers;
|
|
1346
|
+
}
|
|
1347
|
+
visited.add(path7);
|
|
1348
|
+
path7.traverse({
|
|
1349
|
+
Identifier(path8) {
|
|
1350
|
+
if (identifiers.has(path8)) {
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
identifiers.add(path8);
|
|
1354
|
+
let binding = path8.scope.getBinding(path8.node.name);
|
|
1355
|
+
if (!binding) {
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
getDependentIdentifiersForPath(binding.path, { visited, identifiers });
|
|
1359
|
+
for (let reference of binding.referencePaths) {
|
|
1360
|
+
if (reference.isExportNamedDeclaration()) {
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
getDependentIdentifiersForPath(reference, {
|
|
1364
|
+
visited,
|
|
1365
|
+
identifiers
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
for (let constantViolation of binding.constantViolations) {
|
|
1369
|
+
getDependentIdentifiersForPath(constantViolation, {
|
|
1370
|
+
visited,
|
|
1371
|
+
identifiers
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1377
|
+
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1378
|
+
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1379
|
+
if (!withinImportStatement && !withinExportStatement) {
|
|
1380
|
+
getDependentIdentifiersForPath(topLevelStatement, {
|
|
1381
|
+
visited,
|
|
1382
|
+
identifiers
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
|
|
1386
|
+
t.isPattern(path7.parentPath.parentPath?.node))) {
|
|
1387
|
+
let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
|
|
1388
|
+
assertNodePath(variableDeclarator);
|
|
1389
|
+
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1390
|
+
visited,
|
|
1391
|
+
identifiers
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
return identifiers;
|
|
1395
|
+
}
|
|
1396
|
+
function getTopLevelStatementPathForPath(path7) {
|
|
1397
|
+
let ancestry = path7.getAncestry();
|
|
1398
|
+
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1399
|
+
assertNodePathIsStatement(topLevelStatement);
|
|
1400
|
+
return topLevelStatement;
|
|
1401
|
+
}
|
|
1402
|
+
function getTopLevelStatementsForPaths(paths) {
|
|
1403
|
+
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1404
|
+
for (let path7 of paths) {
|
|
1405
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1406
|
+
topLevelStatements.add(topLevelStatement.node);
|
|
1407
|
+
}
|
|
1408
|
+
return topLevelStatements;
|
|
1409
|
+
}
|
|
1410
|
+
function getIdentifiersForPatternPath(patternPath, identifiers = /* @__PURE__ */ new Set()) {
|
|
1411
|
+
function walk(currentPath) {
|
|
1412
|
+
if (currentPath.isIdentifier()) {
|
|
1413
|
+
identifiers.add(currentPath);
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
if (currentPath.isObjectPattern()) {
|
|
1417
|
+
let { properties } = currentPath.node;
|
|
1418
|
+
for (let i = 0; i < properties.length; i++) {
|
|
1419
|
+
const property = properties[i];
|
|
1420
|
+
if (t.isObjectProperty(property)) {
|
|
1421
|
+
let valuePath = currentPath.get(`properties.${i}.value`);
|
|
1422
|
+
assertNodePath(valuePath);
|
|
1423
|
+
walk(valuePath);
|
|
1424
|
+
} else if (t.isRestElement(property)) {
|
|
1425
|
+
let argumentPath = currentPath.get(`properties.${i}.argument`);
|
|
1426
|
+
assertNodePath(argumentPath);
|
|
1427
|
+
walk(argumentPath);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
} else if (currentPath.isArrayPattern()) {
|
|
1431
|
+
let { elements } = currentPath.node;
|
|
1432
|
+
for (let i = 0; i < elements.length; i++) {
|
|
1433
|
+
const element = elements[i];
|
|
1434
|
+
if (element) {
|
|
1435
|
+
let elementPath = currentPath.get(`elements.${i}`);
|
|
1436
|
+
assertNodePath(elementPath);
|
|
1437
|
+
walk(elementPath);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
} else if (currentPath.isRestElement()) {
|
|
1441
|
+
let argumentPath = currentPath.get("argument");
|
|
1442
|
+
assertNodePath(argumentPath);
|
|
1443
|
+
walk(argumentPath);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
walk(patternPath);
|
|
1447
|
+
return identifiers;
|
|
1448
|
+
}
|
|
1449
|
+
var getExportedName = (exported) => {
|
|
1450
|
+
return t.isIdentifier(exported) ? exported.name : exported.value;
|
|
1451
|
+
};
|
|
1452
|
+
function setsIntersect(set1, set2) {
|
|
1453
|
+
let smallerSet = set1;
|
|
1454
|
+
let largerSet = set2;
|
|
1455
|
+
if (set1.size > set2.size) {
|
|
1456
|
+
smallerSet = set2;
|
|
1457
|
+
largerSet = set1;
|
|
1458
|
+
}
|
|
1459
|
+
for (let element of smallerSet) {
|
|
1460
|
+
if (largerSet.has(element)) {
|
|
1461
|
+
return true;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
return false;
|
|
1465
|
+
}
|
|
1466
|
+
function hasChunkableExport(code, exportName, cache, cacheKey) {
|
|
1467
|
+
return getOrSetFromCache(
|
|
1468
|
+
cache,
|
|
1469
|
+
`${cacheKey}::hasChunkableExport::${exportName}`,
|
|
1470
|
+
code,
|
|
1471
|
+
() => {
|
|
1472
|
+
let exportDependencies = getExportDependencies(code, cache, cacheKey);
|
|
1473
|
+
let dependencies = exportDependencies.get(exportName);
|
|
1474
|
+
if (!dependencies) {
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
for (let [currentExportName, currentDependencies] of exportDependencies) {
|
|
1478
|
+
if (currentExportName === exportName) {
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
if (setsIntersect(
|
|
1482
|
+
currentDependencies.topLevelNonModuleStatements,
|
|
1483
|
+
dependencies.topLevelNonModuleStatements
|
|
1484
|
+
)) {
|
|
1485
|
+
return false;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
if (dependencies.exportedVariableDeclarators.size > 1) {
|
|
1489
|
+
return false;
|
|
1490
|
+
}
|
|
1491
|
+
if (dependencies.exportedVariableDeclarators.size > 0) {
|
|
1492
|
+
for (let [
|
|
1493
|
+
currentExportName,
|
|
1494
|
+
currentDependencies
|
|
1495
|
+
] of exportDependencies) {
|
|
1496
|
+
if (currentExportName === exportName) {
|
|
1497
|
+
continue;
|
|
1498
|
+
}
|
|
1499
|
+
if (setsIntersect(
|
|
1500
|
+
currentDependencies.exportedVariableDeclarators,
|
|
1501
|
+
dependencies.exportedVariableDeclarators
|
|
1502
|
+
)) {
|
|
1503
|
+
return false;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return true;
|
|
1508
|
+
}
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1511
|
+
function getChunkedExport(code, exportName, generateOptions = {}, cache, cacheKey) {
|
|
1512
|
+
return getOrSetFromCache(
|
|
1513
|
+
cache,
|
|
1514
|
+
`${cacheKey}::getChunkedExport::${exportName}::${JSON.stringify(
|
|
1515
|
+
generateOptions
|
|
1516
|
+
)}`,
|
|
1517
|
+
code,
|
|
1518
|
+
() => {
|
|
1519
|
+
if (!hasChunkableExport(code, exportName, cache, cacheKey)) {
|
|
1520
|
+
return void 0;
|
|
1521
|
+
}
|
|
1522
|
+
let exportDependencies = getExportDependencies(code, cache, cacheKey);
|
|
1523
|
+
let dependencies = exportDependencies.get(exportName);
|
|
1524
|
+
invariant(dependencies, "Expected export to have dependencies");
|
|
1525
|
+
let topLevelStatementsArray = Array.from(dependencies.topLevelStatements);
|
|
1526
|
+
let exportedVariableDeclaratorsArray = Array.from(
|
|
1527
|
+
dependencies.exportedVariableDeclarators
|
|
1528
|
+
);
|
|
1529
|
+
let ast = codeToAst(code, cache, cacheKey);
|
|
1530
|
+
ast.program.body = ast.program.body.filter(
|
|
1531
|
+
(node) => topLevelStatementsArray.some(
|
|
1532
|
+
(statement) => t.isNodesEquivalent(node, statement)
|
|
1533
|
+
)
|
|
1534
|
+
).map((node) => {
|
|
1535
|
+
if (!t.isImportDeclaration(node)) {
|
|
1536
|
+
return node;
|
|
1537
|
+
}
|
|
1538
|
+
if (dependencies.importedIdentifierNames.size === 0) {
|
|
1539
|
+
return null;
|
|
1540
|
+
}
|
|
1541
|
+
node.specifiers = node.specifiers.filter(
|
|
1542
|
+
(specifier) => dependencies.importedIdentifierNames.has(specifier.local.name)
|
|
1543
|
+
);
|
|
1544
|
+
invariant(
|
|
1545
|
+
node.specifiers.length > 0,
|
|
1546
|
+
"Expected import statement to have used specifiers"
|
|
1547
|
+
);
|
|
1548
|
+
return node;
|
|
1549
|
+
}).map((node) => {
|
|
1550
|
+
if (!t.isExportDeclaration(node)) {
|
|
1551
|
+
return node;
|
|
1552
|
+
}
|
|
1553
|
+
if (t.isExportAllDeclaration(node)) {
|
|
1554
|
+
return null;
|
|
1555
|
+
}
|
|
1556
|
+
if (t.isExportDefaultDeclaration(node)) {
|
|
1557
|
+
return exportName === "default" ? node : null;
|
|
1558
|
+
}
|
|
1559
|
+
let { declaration } = node;
|
|
1560
|
+
if (t.isVariableDeclaration(declaration)) {
|
|
1561
|
+
declaration.declarations = declaration.declarations.filter(
|
|
1562
|
+
(node2) => exportedVariableDeclaratorsArray.some(
|
|
1563
|
+
(declarator) => t.isNodesEquivalent(node2, declarator)
|
|
1564
|
+
)
|
|
1565
|
+
);
|
|
1566
|
+
if (declaration.declarations.length === 0) {
|
|
1567
|
+
return null;
|
|
1568
|
+
}
|
|
1569
|
+
return node;
|
|
1570
|
+
}
|
|
1571
|
+
if (t.isFunctionDeclaration(node.declaration) || t.isClassDeclaration(node.declaration)) {
|
|
1572
|
+
return node.declaration.id?.name === exportName ? node : null;
|
|
1573
|
+
}
|
|
1574
|
+
if (t.isExportNamedDeclaration(node)) {
|
|
1575
|
+
if (node.specifiers.length === 0) {
|
|
1576
|
+
return null;
|
|
1577
|
+
}
|
|
1578
|
+
node.specifiers = node.specifiers.filter(
|
|
1579
|
+
(specifier) => getExportedName(specifier.exported) === exportName
|
|
1580
|
+
);
|
|
1581
|
+
if (node.specifiers.length === 0) {
|
|
1582
|
+
return null;
|
|
1583
|
+
}
|
|
1584
|
+
return node;
|
|
1585
|
+
}
|
|
1586
|
+
throw new Error(`Unknown export node type: ${node.type}`);
|
|
1587
|
+
}).filter((node) => node !== null);
|
|
1588
|
+
return generate2(ast, generateOptions);
|
|
1589
|
+
}
|
|
1590
|
+
);
|
|
1591
|
+
}
|
|
1592
|
+
function omitChunkedExports(code, exportNames, generateOptions = {}, cache, cacheKey) {
|
|
1593
|
+
return getOrSetFromCache(
|
|
1594
|
+
cache,
|
|
1595
|
+
`${cacheKey}::omitChunkedExports::${exportNames.join(
|
|
1596
|
+
","
|
|
1597
|
+
)}::${JSON.stringify(generateOptions)}`,
|
|
1598
|
+
code,
|
|
1599
|
+
() => {
|
|
1600
|
+
const isChunkable = (exportName) => hasChunkableExport(code, exportName, cache, cacheKey);
|
|
1601
|
+
const isOmitted = (exportName) => exportNames.includes(exportName) && isChunkable(exportName);
|
|
1602
|
+
const isRetained = (exportName) => !isOmitted(exportName);
|
|
1603
|
+
let exportDependencies = getExportDependencies(code, cache, cacheKey);
|
|
1604
|
+
let allExportNames = Array.from(exportDependencies.keys());
|
|
1605
|
+
let omittedExportNames = allExportNames.filter(isOmitted);
|
|
1606
|
+
let retainedExportNames = allExportNames.filter(isRetained);
|
|
1607
|
+
let omittedStatements = /* @__PURE__ */ new Set();
|
|
1608
|
+
let omittedExportedVariableDeclarators = /* @__PURE__ */ new Set();
|
|
1609
|
+
for (let omittedExportName of omittedExportNames) {
|
|
1610
|
+
let dependencies = exportDependencies.get(omittedExportName);
|
|
1611
|
+
invariant(
|
|
1612
|
+
dependencies,
|
|
1613
|
+
`Expected dependencies for ${omittedExportName}`
|
|
1614
|
+
);
|
|
1615
|
+
for (let statement of dependencies.topLevelNonModuleStatements) {
|
|
1616
|
+
omittedStatements.add(statement);
|
|
1617
|
+
}
|
|
1618
|
+
for (let declarator of dependencies.exportedVariableDeclarators) {
|
|
1619
|
+
omittedExportedVariableDeclarators.add(declarator);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
let ast = codeToAst(code, cache, cacheKey);
|
|
1623
|
+
let omittedStatementsArray = Array.from(omittedStatements);
|
|
1624
|
+
let omittedExportedVariableDeclaratorsArray = Array.from(
|
|
1625
|
+
omittedExportedVariableDeclarators
|
|
1626
|
+
);
|
|
1627
|
+
ast.program.body = ast.program.body.filter(
|
|
1628
|
+
(node) => omittedStatementsArray.every(
|
|
1629
|
+
(statement) => !t.isNodesEquivalent(node, statement)
|
|
1630
|
+
)
|
|
1631
|
+
).map((node) => {
|
|
1632
|
+
if (!t.isImportDeclaration(node)) {
|
|
1633
|
+
return node;
|
|
1634
|
+
}
|
|
1635
|
+
if (node.specifiers.length === 0) {
|
|
1636
|
+
return node;
|
|
1637
|
+
}
|
|
1638
|
+
node.specifiers = node.specifiers.filter((specifier) => {
|
|
1639
|
+
let importedName = specifier.local.name;
|
|
1640
|
+
for (let retainedExportName of retainedExportNames) {
|
|
1641
|
+
let dependencies = exportDependencies.get(retainedExportName);
|
|
1642
|
+
if (dependencies?.importedIdentifierNames?.has(importedName)) {
|
|
1643
|
+
return true;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
for (let omittedExportName of omittedExportNames) {
|
|
1647
|
+
let dependencies = exportDependencies.get(omittedExportName);
|
|
1648
|
+
if (dependencies?.importedIdentifierNames?.has(importedName)) {
|
|
1649
|
+
return false;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
return true;
|
|
1653
|
+
});
|
|
1654
|
+
if (node.specifiers.length === 0) {
|
|
1655
|
+
return null;
|
|
1656
|
+
}
|
|
1657
|
+
return node;
|
|
1658
|
+
}).map((node) => {
|
|
1659
|
+
if (!t.isExportDeclaration(node)) {
|
|
1660
|
+
return node;
|
|
1661
|
+
}
|
|
1662
|
+
if (t.isExportAllDeclaration(node)) {
|
|
1663
|
+
return node;
|
|
1664
|
+
}
|
|
1665
|
+
if (t.isExportDefaultDeclaration(node)) {
|
|
1666
|
+
return isOmitted("default") ? null : node;
|
|
1667
|
+
}
|
|
1668
|
+
if (t.isVariableDeclaration(node.declaration)) {
|
|
1669
|
+
node.declaration.declarations = node.declaration.declarations.filter(
|
|
1670
|
+
(node2) => omittedExportedVariableDeclaratorsArray.every(
|
|
1671
|
+
(declarator) => !t.isNodesEquivalent(node2, declarator)
|
|
1672
|
+
)
|
|
1673
|
+
);
|
|
1674
|
+
if (node.declaration.declarations.length === 0) {
|
|
1675
|
+
return null;
|
|
1676
|
+
}
|
|
1677
|
+
return node;
|
|
1678
|
+
}
|
|
1679
|
+
if (t.isFunctionDeclaration(node.declaration) || t.isClassDeclaration(node.declaration)) {
|
|
1680
|
+
invariant(
|
|
1681
|
+
node.declaration.id,
|
|
1682
|
+
"Expected exported function or class declaration to have a name when not the default export"
|
|
1683
|
+
);
|
|
1684
|
+
return isOmitted(node.declaration.id.name) ? null : node;
|
|
1685
|
+
}
|
|
1686
|
+
if (t.isExportNamedDeclaration(node)) {
|
|
1687
|
+
if (node.specifiers.length === 0) {
|
|
1688
|
+
return node;
|
|
1689
|
+
}
|
|
1690
|
+
node.specifiers = node.specifiers.filter((specifier) => {
|
|
1691
|
+
const exportedName = getExportedName(specifier.exported);
|
|
1692
|
+
return !isOmitted(exportedName);
|
|
1693
|
+
});
|
|
1694
|
+
if (node.specifiers.length === 0) {
|
|
1695
|
+
return null;
|
|
1696
|
+
}
|
|
1697
|
+
return node;
|
|
1698
|
+
}
|
|
1699
|
+
throw new Error(`Unknown node type: ${node.type}`);
|
|
1700
|
+
}).filter((node) => node !== null);
|
|
1701
|
+
if (ast.program.body.length === 0) {
|
|
1702
|
+
return void 0;
|
|
1703
|
+
}
|
|
1704
|
+
return generate2(ast, generateOptions);
|
|
1705
|
+
}
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
function detectRouteChunks(code, cache, cacheKey) {
|
|
1709
|
+
const hasRouteChunkByExportName = Object.fromEntries(
|
|
1710
|
+
routeChunkExportNames.map((exportName) => [
|
|
1711
|
+
exportName,
|
|
1712
|
+
hasChunkableExport(code, exportName, cache, cacheKey)
|
|
1713
|
+
])
|
|
1714
|
+
);
|
|
1715
|
+
const chunkedExports = Object.entries(hasRouteChunkByExportName).filter(([, isChunked]) => isChunked).map(([exportName]) => exportName);
|
|
1716
|
+
const hasRouteChunks = chunkedExports.length > 0;
|
|
1717
|
+
return {
|
|
1718
|
+
hasRouteChunks,
|
|
1719
|
+
hasRouteChunkByExportName,
|
|
1720
|
+
chunkedExports
|
|
1721
|
+
};
|
|
1722
|
+
}
|
|
1723
|
+
var routeChunkExportNames = [
|
|
1724
|
+
"clientAction",
|
|
1725
|
+
"clientLoader",
|
|
1726
|
+
"HydrateFallback"
|
|
1727
|
+
];
|
|
1728
|
+
var mainChunkName = "main";
|
|
1729
|
+
var routeChunkNames = ["main", ...routeChunkExportNames];
|
|
1730
|
+
function getRouteChunkCode(code, chunkName, cache, cacheKey) {
|
|
1731
|
+
if (chunkName === mainChunkName) {
|
|
1732
|
+
return omitChunkedExports(code, routeChunkExportNames, {}, cache, cacheKey);
|
|
1733
|
+
}
|
|
1734
|
+
return getChunkedExport(code, chunkName, {}, cache, cacheKey);
|
|
1735
|
+
}
|
|
1736
|
+
var routeChunkQueryStringPrefix = "?route-chunk=";
|
|
1737
|
+
var routeChunkQueryStrings = {
|
|
1738
|
+
main: `${routeChunkQueryStringPrefix}main`,
|
|
1739
|
+
clientAction: `${routeChunkQueryStringPrefix}clientAction`,
|
|
1740
|
+
clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
|
|
1741
|
+
HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
|
|
1742
|
+
};
|
|
1743
|
+
function getRouteChunkModuleId(filePath, chunkName) {
|
|
1744
|
+
return `${filePath}${routeChunkQueryStrings[chunkName]}`;
|
|
1745
|
+
}
|
|
1746
|
+
function isRouteChunkModuleId(id) {
|
|
1747
|
+
return Object.values(routeChunkQueryStrings).some(
|
|
1748
|
+
(queryString) => id.endsWith(queryString)
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1751
|
+
function isRouteChunkName(name) {
|
|
1752
|
+
return name === mainChunkName || routeChunkExportNames.includes(name);
|
|
1753
|
+
}
|
|
1754
|
+
function getRouteChunkNameFromModuleId(id) {
|
|
1755
|
+
if (!isRouteChunkModuleId(id)) {
|
|
1756
|
+
return null;
|
|
1757
|
+
}
|
|
1758
|
+
let chunkName = id.split(routeChunkQueryStringPrefix)[1].split("&")[0];
|
|
1759
|
+
if (!isRouteChunkName(chunkName)) {
|
|
1760
|
+
return null;
|
|
1761
|
+
}
|
|
1762
|
+
return chunkName;
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1133
1765
|
// vite/with-props.ts
|
|
1134
1766
|
var import_dedent2 = __toESM(require("dedent"));
|
|
1135
|
-
var
|
|
1767
|
+
var vmod = create("with-props");
|
|
1136
1768
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
1137
1769
|
var plugin = {
|
|
1138
1770
|
name: "react-router-with-props",
|
|
1139
1771
|
enforce: "pre",
|
|
1140
|
-
resolveId(
|
|
1141
|
-
if (
|
|
1772
|
+
resolveId(id) {
|
|
1773
|
+
if (id === vmod.id) return vmod.resolvedId;
|
|
1142
1774
|
},
|
|
1143
|
-
async load(
|
|
1144
|
-
if (
|
|
1775
|
+
async load(id) {
|
|
1776
|
+
if (id !== vmod.resolvedId) return;
|
|
1145
1777
|
return import_dedent2.default`
|
|
1146
1778
|
import { createElement as h } from "react";
|
|
1147
1779
|
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
@@ -1183,44 +1815,44 @@ var plugin = {
|
|
|
1183
1815
|
};
|
|
1184
1816
|
var transform = (ast) => {
|
|
1185
1817
|
const hocs = [];
|
|
1186
|
-
function getHocUid(
|
|
1187
|
-
const uid =
|
|
1818
|
+
function getHocUid(path7, hocName) {
|
|
1819
|
+
const uid = path7.scope.generateUidIdentifier(hocName);
|
|
1188
1820
|
hocs.push([hocName, uid]);
|
|
1189
1821
|
return uid;
|
|
1190
1822
|
}
|
|
1191
1823
|
traverse(ast, {
|
|
1192
|
-
ExportDeclaration(
|
|
1193
|
-
if (
|
|
1194
|
-
const declaration =
|
|
1824
|
+
ExportDeclaration(path7) {
|
|
1825
|
+
if (path7.isExportDefaultDeclaration()) {
|
|
1826
|
+
const declaration = path7.get("declaration");
|
|
1195
1827
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
1196
1828
|
if (expr) {
|
|
1197
|
-
const uid = getHocUid(
|
|
1829
|
+
const uid = getHocUid(path7, "withComponentProps");
|
|
1198
1830
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
1199
1831
|
}
|
|
1200
1832
|
return;
|
|
1201
1833
|
}
|
|
1202
|
-
if (
|
|
1203
|
-
const decl =
|
|
1834
|
+
if (path7.isExportNamedDeclaration()) {
|
|
1835
|
+
const decl = path7.get("declaration");
|
|
1204
1836
|
if (decl.isVariableDeclaration()) {
|
|
1205
1837
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
1206
|
-
const
|
|
1838
|
+
const id = varDeclarator.get("id");
|
|
1207
1839
|
const init = varDeclarator.get("init");
|
|
1208
1840
|
const expr = init.node;
|
|
1209
1841
|
if (!expr) return;
|
|
1210
|
-
if (!
|
|
1211
|
-
const { name } =
|
|
1842
|
+
if (!id.isIdentifier()) return;
|
|
1843
|
+
const { name } = id.node;
|
|
1212
1844
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
1213
|
-
const uid = getHocUid(
|
|
1845
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
1214
1846
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
1215
1847
|
});
|
|
1216
1848
|
return;
|
|
1217
1849
|
}
|
|
1218
1850
|
if (decl.isFunctionDeclaration()) {
|
|
1219
|
-
const { id
|
|
1220
|
-
if (!
|
|
1221
|
-
const { name } =
|
|
1851
|
+
const { id } = decl.node;
|
|
1852
|
+
if (!id) return;
|
|
1853
|
+
const { name } = id;
|
|
1222
1854
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
1223
|
-
const uid = getHocUid(
|
|
1855
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
1224
1856
|
decl.replaceWith(
|
|
1225
1857
|
t.variableDeclaration("const", [
|
|
1226
1858
|
t.variableDeclarator(
|
|
@@ -1239,7 +1871,7 @@ var transform = (ast) => {
|
|
|
1239
1871
|
hocs.map(
|
|
1240
1872
|
([name, identifier]) => t.importSpecifier(identifier, t.identifier(name))
|
|
1241
1873
|
),
|
|
1242
|
-
t.stringLiteral(
|
|
1874
|
+
t.stringLiteral(vmod.id)
|
|
1243
1875
|
)
|
|
1244
1876
|
);
|
|
1245
1877
|
}
|
|
@@ -1255,11 +1887,10 @@ function toFunctionExpression(decl) {
|
|
|
1255
1887
|
}
|
|
1256
1888
|
|
|
1257
1889
|
// vite/plugin.ts
|
|
1258
|
-
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "
|
|
1890
|
+
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "headers"];
|
|
1259
1891
|
var CLIENT_ROUTE_EXPORTS = [
|
|
1260
1892
|
"clientAction",
|
|
1261
1893
|
"clientLoader",
|
|
1262
|
-
"clientMiddleware",
|
|
1263
1894
|
"default",
|
|
1264
1895
|
"ErrorBoundary",
|
|
1265
1896
|
"handle",
|
|
@@ -1269,27 +1900,35 @@ var CLIENT_ROUTE_EXPORTS = [
|
|
|
1269
1900
|
"meta",
|
|
1270
1901
|
"shouldRevalidate"
|
|
1271
1902
|
];
|
|
1272
|
-
var
|
|
1273
|
-
var
|
|
1274
|
-
return
|
|
1903
|
+
var BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
|
|
1904
|
+
var isRouteEntryModuleId = (id) => {
|
|
1905
|
+
return id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING);
|
|
1906
|
+
};
|
|
1907
|
+
var isRouteVirtualModule = (id) => {
|
|
1908
|
+
return isRouteEntryModuleId(id) || isRouteChunkModuleId(id);
|
|
1909
|
+
};
|
|
1910
|
+
var virtualHmrRuntime = create("hmr-runtime");
|
|
1911
|
+
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
1912
|
+
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
1913
|
+
let vite2 = getVite();
|
|
1914
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
1915
|
+
let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
|
|
1916
|
+
return vite2.normalizePath(relativePath).split("?")[0];
|
|
1275
1917
|
};
|
|
1276
|
-
var serverBuildId = id("server-build");
|
|
1277
|
-
var serverManifestId = id("server-manifest");
|
|
1278
|
-
var browserManifestId = id("browser-manifest");
|
|
1279
|
-
var hmrRuntimeId = id("hmr-runtime");
|
|
1280
|
-
var injectHmrRuntimeId = id("inject-hmr-runtime");
|
|
1281
1918
|
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
1282
|
-
let vite2 =
|
|
1919
|
+
let vite2 = getVite();
|
|
1283
1920
|
let file = route.file;
|
|
1284
|
-
let fullPath =
|
|
1921
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
1285
1922
|
return vite2.normalizePath(fullPath);
|
|
1286
1923
|
};
|
|
1287
|
-
var
|
|
1924
|
+
var virtual = {
|
|
1925
|
+
serverBuild: create("server-build"),
|
|
1926
|
+
serverManifest: create("server-manifest"),
|
|
1927
|
+
browserManifest: create("browser-manifest")
|
|
1928
|
+
};
|
|
1288
1929
|
var invalidateVirtualModules = (viteDevServer) => {
|
|
1289
|
-
|
|
1290
|
-
let mod = viteDevServer.moduleGraph.getModuleById(
|
|
1291
|
-
resolve3(vmod)
|
|
1292
|
-
);
|
|
1930
|
+
Object.values(virtual).forEach((vmod2) => {
|
|
1931
|
+
let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
|
|
1293
1932
|
if (mod) {
|
|
1294
1933
|
viteDevServer.moduleGraph.invalidateModule(mod);
|
|
1295
1934
|
}
|
|
@@ -1300,27 +1939,39 @@ var getHash = (source, maxLength) => {
|
|
|
1300
1939
|
return typeof maxLength === "number" ? hash.slice(0, maxLength) : hash;
|
|
1301
1940
|
};
|
|
1302
1941
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
1303
|
-
let vite2 =
|
|
1942
|
+
let vite2 = getVite();
|
|
1304
1943
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
1305
|
-
|
|
1944
|
+
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
1306
1945
|
);
|
|
1307
|
-
let entryChunk = viteManifest[rootRelativeFilePath
|
|
1946
|
+
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
1308
1947
|
if (!entryChunk) {
|
|
1309
|
-
|
|
1310
|
-
throw new Error(
|
|
1311
|
-
`No manifest entry found for "${rootRelativeFilePath}". Known manifest keys: ${knownManifestKeys}`
|
|
1312
|
-
);
|
|
1948
|
+
return void 0;
|
|
1313
1949
|
}
|
|
1314
1950
|
return entryChunk;
|
|
1315
1951
|
};
|
|
1952
|
+
var getPublicModulePathForEntry = (ctx, viteManifest, entryFilePath) => {
|
|
1953
|
+
let entryChunk = resolveChunk(ctx, viteManifest, entryFilePath);
|
|
1954
|
+
return entryChunk ? `${ctx.publicPath}${entryChunk.file}` : void 0;
|
|
1955
|
+
};
|
|
1316
1956
|
var getReactRouterManifestBuildAssets = (ctx, viteManifest, entryFilePath, prependedAssetFilePaths = []) => {
|
|
1317
1957
|
let entryChunk = resolveChunk(ctx, viteManifest, entryFilePath);
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1958
|
+
invariant(entryChunk, "Chunk not found");
|
|
1959
|
+
let prependedAssetChunks = prependedAssetFilePaths.map((filePath) => {
|
|
1960
|
+
let chunk = resolveChunk(ctx, viteManifest, filePath);
|
|
1961
|
+
invariant(chunk, "Chunk not found");
|
|
1962
|
+
return chunk;
|
|
1963
|
+
});
|
|
1964
|
+
let routeModuleChunks = routeChunkNames.map(
|
|
1965
|
+
(routeChunkName) => resolveChunk(
|
|
1966
|
+
ctx,
|
|
1967
|
+
viteManifest,
|
|
1968
|
+
getRouteChunkModuleId(entryFilePath.split("?")[0], routeChunkName)
|
|
1969
|
+
)
|
|
1970
|
+
).filter(isNonNullable);
|
|
1321
1971
|
let chunks = resolveDependantChunks(viteManifest, [
|
|
1322
1972
|
...prependedAssetChunks,
|
|
1323
|
-
entryChunk
|
|
1973
|
+
entryChunk,
|
|
1974
|
+
...routeModuleChunks
|
|
1324
1975
|
]);
|
|
1325
1976
|
return {
|
|
1326
1977
|
module: `${ctx.publicPath}${entryChunk.file}`,
|
|
@@ -1354,9 +2005,13 @@ function dedupe(array2) {
|
|
|
1354
2005
|
return [...new Set(array2)];
|
|
1355
2006
|
}
|
|
1356
2007
|
var writeFileSafe = async (file, contents) => {
|
|
1357
|
-
await fse.ensureDir(
|
|
2008
|
+
await fse.ensureDir(path6.dirname(file));
|
|
1358
2009
|
await fse.writeFile(file, contents);
|
|
1359
2010
|
};
|
|
2011
|
+
var getExportNames = (code) => {
|
|
2012
|
+
let [, exportSpecifiers] = (0, import_es_module_lexer.parse)(code);
|
|
2013
|
+
return exportSpecifiers.map(({ n: name }) => name);
|
|
2014
|
+
};
|
|
1360
2015
|
var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
|
|
1361
2016
|
let entries = await Promise.all(
|
|
1362
2017
|
Object.entries(ctx.reactRouterConfig.routes).map(async ([key, route]) => {
|
|
@@ -1370,29 +2025,39 @@ var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
|
|
|
1370
2025
|
);
|
|
1371
2026
|
return Object.fromEntries(entries);
|
|
1372
2027
|
};
|
|
1373
|
-
var
|
|
2028
|
+
var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile) => {
|
|
1374
2029
|
if (!viteChildCompiler) {
|
|
1375
2030
|
throw new Error("Vite child compiler not found");
|
|
1376
2031
|
}
|
|
1377
2032
|
let ssr = true;
|
|
1378
2033
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
1379
|
-
let routePath =
|
|
1380
|
-
let
|
|
2034
|
+
let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2035
|
+
let url2 = resolveFileUrl(ctx, routePath);
|
|
1381
2036
|
let resolveId = async () => {
|
|
1382
|
-
let result = await pluginContainer.resolveId(
|
|
1383
|
-
if (!result) throw new Error(`Could not resolve module ID for ${
|
|
2037
|
+
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
2038
|
+
if (!result) throw new Error(`Could not resolve module ID for ${url2}`);
|
|
1384
2039
|
return result.id;
|
|
1385
2040
|
};
|
|
1386
|
-
let [
|
|
2041
|
+
let [id, code] = await Promise.all([
|
|
1387
2042
|
resolveId(),
|
|
1388
2043
|
readRouteFile?.() ?? fse.readFile(routePath, "utf-8"),
|
|
1389
2044
|
// pluginContainer.transform(...) fails if we don't do this first:
|
|
1390
|
-
moduleGraph.ensureEntryFromUrl(
|
|
2045
|
+
moduleGraph.ensureEntryFromUrl(url2, ssr)
|
|
1391
2046
|
]);
|
|
1392
|
-
let transformed = await pluginContainer.transform(code,
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
2047
|
+
let transformed = await pluginContainer.transform(code, id, { ssr });
|
|
2048
|
+
return transformed.code;
|
|
2049
|
+
};
|
|
2050
|
+
var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteFile) => {
|
|
2051
|
+
if (!viteChildCompiler) {
|
|
2052
|
+
throw new Error("Vite child compiler not found");
|
|
2053
|
+
}
|
|
2054
|
+
let code = await compileRouteFile(
|
|
2055
|
+
viteChildCompiler,
|
|
2056
|
+
ctx,
|
|
2057
|
+
routeFile,
|
|
2058
|
+
readRouteFile
|
|
2059
|
+
);
|
|
2060
|
+
return getExportNames(code);
|
|
1396
2061
|
};
|
|
1397
2062
|
var getServerBundleBuildConfig = (viteUserConfig) => {
|
|
1398
2063
|
if (!("__reactRouterServerBundleBuildConfig" in viteUserConfig) || !viteUserConfig.__reactRouterServerBundleBuildConfig) {
|
|
@@ -1400,19 +2065,19 @@ var getServerBundleBuildConfig = (viteUserConfig) => {
|
|
|
1400
2065
|
}
|
|
1401
2066
|
return viteUserConfig.__reactRouterServerBundleBuildConfig;
|
|
1402
2067
|
};
|
|
1403
|
-
var getServerBuildDirectory = (ctx) =>
|
|
2068
|
+
var getServerBuildDirectory = (ctx) => path6.join(
|
|
1404
2069
|
ctx.reactRouterConfig.buildDirectory,
|
|
1405
2070
|
"server",
|
|
1406
2071
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
1407
2072
|
);
|
|
1408
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
1409
|
-
var defaultEntriesDir =
|
|
1410
|
-
|
|
2073
|
+
var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
|
|
2074
|
+
var defaultEntriesDir = path6.resolve(
|
|
2075
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1411
2076
|
"dist",
|
|
1412
2077
|
"config",
|
|
1413
2078
|
"defaults"
|
|
1414
2079
|
);
|
|
1415
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) =>
|
|
2080
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
|
|
1416
2081
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1417
2082
|
var reactRouterDevLoadContext = () => ({});
|
|
1418
2083
|
var reactRouterVitePlugin = () => {
|
|
@@ -1423,6 +2088,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1423
2088
|
let viteConfig;
|
|
1424
2089
|
let cssModulesManifest = {};
|
|
1425
2090
|
let viteChildCompiler = null;
|
|
2091
|
+
let cache = /* @__PURE__ */ new Map();
|
|
1426
2092
|
let reactRouterConfigLoader;
|
|
1427
2093
|
let typegenWatcherPromise;
|
|
1428
2094
|
let logger;
|
|
@@ -1494,12 +2160,14 @@ var reactRouterVitePlugin = () => {
|
|
|
1494
2160
|
resolveFileUrl(
|
|
1495
2161
|
ctx,
|
|
1496
2162
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
1497
|
-
)
|
|
2163
|
+
)
|
|
1498
2164
|
)};`;
|
|
1499
2165
|
}).join("\n")}
|
|
1500
|
-
export { default as assets } from ${JSON.stringify(
|
|
2166
|
+
export { default as assets } from ${JSON.stringify(
|
|
2167
|
+
virtual.serverManifest.id
|
|
2168
|
+
)};
|
|
1501
2169
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
1502
|
-
|
|
2170
|
+
path6.relative(
|
|
1503
2171
|
ctx.rootDirectory,
|
|
1504
2172
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
1505
2173
|
)
|
|
@@ -1525,7 +2193,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1525
2193
|
};
|
|
1526
2194
|
let loadViteManifest = async (directory) => {
|
|
1527
2195
|
let manifestContents = await fse.readFile(
|
|
1528
|
-
|
|
2196
|
+
path6.resolve(directory, ".vite", "manifest.json"),
|
|
1529
2197
|
"utf-8"
|
|
1530
2198
|
);
|
|
1531
2199
|
return JSON.parse(manifestContents);
|
|
@@ -1560,13 +2228,31 @@ var reactRouterVitePlugin = () => {
|
|
|
1560
2228
|
viteChildCompiler,
|
|
1561
2229
|
ctx
|
|
1562
2230
|
);
|
|
2231
|
+
let enforceRouteChunks = ctx.reactRouterConfig.future.unstable_routeChunks === "enforce";
|
|
1563
2232
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
1564
|
-
let
|
|
1565
|
-
ctx.reactRouterConfig.appDirectory,
|
|
1566
|
-
route.file
|
|
1567
|
-
);
|
|
2233
|
+
let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
1568
2234
|
let sourceExports = routeManifestExports[key];
|
|
1569
2235
|
let isRootRoute = route.parentId === void 0;
|
|
2236
|
+
let hasClientAction = sourceExports.includes("clientAction");
|
|
2237
|
+
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
2238
|
+
let hasHydrateFallback = sourceExports.includes("HydrateFallback");
|
|
2239
|
+
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
2240
|
+
cache,
|
|
2241
|
+
ctx,
|
|
2242
|
+
routeFile,
|
|
2243
|
+
{ routeFile, viteChildCompiler }
|
|
2244
|
+
);
|
|
2245
|
+
if (enforceRouteChunks) {
|
|
2246
|
+
validateRouteChunks({
|
|
2247
|
+
ctx,
|
|
2248
|
+
id: route.file,
|
|
2249
|
+
valid: {
|
|
2250
|
+
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
2251
|
+
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
2252
|
+
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
2253
|
+
}
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
1570
2256
|
let routeManifestEntry = {
|
|
1571
2257
|
id: route.id,
|
|
1572
2258
|
parentId: route.parentId,
|
|
@@ -1575,18 +2261,33 @@ var reactRouterVitePlugin = () => {
|
|
|
1575
2261
|
caseSensitive: route.caseSensitive,
|
|
1576
2262
|
hasAction: sourceExports.includes("action"),
|
|
1577
2263
|
hasLoader: sourceExports.includes("loader"),
|
|
1578
|
-
hasClientAction
|
|
1579
|
-
hasClientLoader
|
|
2264
|
+
hasClientAction,
|
|
2265
|
+
hasClientLoader,
|
|
1580
2266
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
1581
2267
|
...getReactRouterManifestBuildAssets(
|
|
1582
2268
|
ctx,
|
|
1583
2269
|
viteManifest,
|
|
1584
|
-
|
|
2270
|
+
`${routeFile}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
|
|
1585
2271
|
// If this is the root route, we also need to include assets from the
|
|
1586
2272
|
// client entry file as this is a common way for consumers to import
|
|
1587
2273
|
// global reset styles, etc.
|
|
1588
2274
|
isRootRoute ? [ctx.entryClientFilePath] : []
|
|
1589
|
-
)
|
|
2275
|
+
),
|
|
2276
|
+
clientActionModule: hasRouteChunkByExportName.clientAction ? getPublicModulePathForEntry(
|
|
2277
|
+
ctx,
|
|
2278
|
+
viteManifest,
|
|
2279
|
+
getRouteChunkModuleId(routeFile, "clientAction")
|
|
2280
|
+
) : void 0,
|
|
2281
|
+
clientLoaderModule: hasRouteChunkByExportName.clientLoader ? getPublicModulePathForEntry(
|
|
2282
|
+
ctx,
|
|
2283
|
+
viteManifest,
|
|
2284
|
+
getRouteChunkModuleId(routeFile, "clientLoader")
|
|
2285
|
+
) : void 0,
|
|
2286
|
+
hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? getPublicModulePathForEntry(
|
|
2287
|
+
ctx,
|
|
2288
|
+
viteManifest,
|
|
2289
|
+
getRouteChunkModuleId(routeFile, "HydrateFallback")
|
|
2290
|
+
) : void 0
|
|
1590
2291
|
};
|
|
1591
2292
|
browserRoutes[key] = routeManifestEntry;
|
|
1592
2293
|
let serverBundleRoutes = ctx.serverBundleBuildConfig?.routes;
|
|
@@ -1596,18 +2297,18 @@ var reactRouterVitePlugin = () => {
|
|
|
1596
2297
|
}
|
|
1597
2298
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
1598
2299
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
1599
|
-
let manifestPath =
|
|
2300
|
+
let manifestPath = path6.posix.join(
|
|
1600
2301
|
viteConfig.build.assetsDir,
|
|
1601
2302
|
`manifest-${version}.js`
|
|
1602
2303
|
);
|
|
1603
|
-
let
|
|
1604
|
-
let nonFingerprintedValues = { url:
|
|
2304
|
+
let url2 = `${ctx.publicPath}${manifestPath}`;
|
|
2305
|
+
let nonFingerprintedValues = { url: url2, version };
|
|
1605
2306
|
let reactRouterBrowserManifest = {
|
|
1606
2307
|
...fingerprintedValues,
|
|
1607
2308
|
...nonFingerprintedValues
|
|
1608
2309
|
};
|
|
1609
2310
|
await writeFileSafe(
|
|
1610
|
-
|
|
2311
|
+
path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
1611
2312
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
1612
2313
|
reactRouterBrowserManifest
|
|
1613
2314
|
)};`
|
|
@@ -1627,37 +2328,61 @@ var reactRouterVitePlugin = () => {
|
|
|
1627
2328
|
viteChildCompiler,
|
|
1628
2329
|
ctx
|
|
1629
2330
|
);
|
|
2331
|
+
let enforceRouteChunks = ctx.reactRouterConfig.future.unstable_routeChunks === "enforce";
|
|
1630
2332
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
2333
|
+
let routeFile = route.file;
|
|
1631
2334
|
let sourceExports = routeManifestExports[key];
|
|
2335
|
+
let hasClientAction = sourceExports.includes("clientAction");
|
|
2336
|
+
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
2337
|
+
let hasHydrateFallback = sourceExports.includes("HydrateFallback");
|
|
2338
|
+
let routeModulePath = combineURLs(
|
|
2339
|
+
ctx.publicPath,
|
|
2340
|
+
`${resolveFileUrl(
|
|
2341
|
+
ctx,
|
|
2342
|
+
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2343
|
+
)}`
|
|
2344
|
+
);
|
|
2345
|
+
if (enforceRouteChunks) {
|
|
2346
|
+
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
2347
|
+
cache,
|
|
2348
|
+
ctx,
|
|
2349
|
+
routeFile,
|
|
2350
|
+
{ routeFile, viteChildCompiler }
|
|
2351
|
+
);
|
|
2352
|
+
validateRouteChunks({
|
|
2353
|
+
ctx,
|
|
2354
|
+
id: route.file,
|
|
2355
|
+
valid: {
|
|
2356
|
+
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
2357
|
+
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
2358
|
+
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
1632
2362
|
routes[key] = {
|
|
1633
2363
|
id: route.id,
|
|
1634
2364
|
parentId: route.parentId,
|
|
1635
2365
|
path: route.path,
|
|
1636
2366
|
index: route.index,
|
|
1637
2367
|
caseSensitive: route.caseSensitive,
|
|
1638
|
-
module:
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
)}${ROUTE_ENTRY_QUERY_STRING}`
|
|
1644
|
-
),
|
|
2368
|
+
module: routeModulePath,
|
|
2369
|
+
// Route chunks are a build-time optimization
|
|
2370
|
+
clientActionModule: void 0,
|
|
2371
|
+
clientLoaderModule: void 0,
|
|
2372
|
+
hydrateFallbackModule: void 0,
|
|
1645
2373
|
hasAction: sourceExports.includes("action"),
|
|
1646
2374
|
hasLoader: sourceExports.includes("loader"),
|
|
1647
|
-
hasClientAction
|
|
1648
|
-
hasClientLoader
|
|
2375
|
+
hasClientAction,
|
|
2376
|
+
hasClientLoader,
|
|
1649
2377
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
1650
2378
|
imports: []
|
|
1651
2379
|
};
|
|
1652
2380
|
}
|
|
1653
2381
|
return {
|
|
1654
2382
|
version: String(Math.random()),
|
|
1655
|
-
url: combineURLs(ctx.publicPath, url
|
|
2383
|
+
url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
|
|
1656
2384
|
hmr: {
|
|
1657
|
-
runtime: combineURLs(
|
|
1658
|
-
ctx.publicPath,
|
|
1659
|
-
url(injectHmrRuntimeId)
|
|
1660
|
-
)
|
|
2385
|
+
runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
|
|
1661
2386
|
},
|
|
1662
2387
|
entry: {
|
|
1663
2388
|
module: combineURLs(
|
|
@@ -1673,11 +2398,17 @@ var reactRouterVitePlugin = () => {
|
|
|
1673
2398
|
{
|
|
1674
2399
|
name: "react-router",
|
|
1675
2400
|
config: async (_viteUserConfig, _viteConfigEnv) => {
|
|
1676
|
-
await
|
|
1677
|
-
let vite2 =
|
|
2401
|
+
await preloadVite();
|
|
2402
|
+
let vite2 = getVite();
|
|
1678
2403
|
viteUserConfig = _viteUserConfig;
|
|
1679
2404
|
viteConfigEnv = _viteConfigEnv;
|
|
1680
2405
|
viteCommand = viteConfigEnv.command;
|
|
2406
|
+
let viteClientConditions = [
|
|
2407
|
+
...vite2.defaultClientConditions ?? []
|
|
2408
|
+
];
|
|
2409
|
+
let viteServerConditions = [
|
|
2410
|
+
...vite2.defaultServerConditions ?? []
|
|
2411
|
+
];
|
|
1681
2412
|
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
1682
2413
|
prefix: "[react-router]"
|
|
1683
2414
|
});
|
|
@@ -1727,15 +2458,15 @@ var reactRouterVitePlugin = () => {
|
|
|
1727
2458
|
ssr: {
|
|
1728
2459
|
external: ssrExternals,
|
|
1729
2460
|
resolve: {
|
|
1730
|
-
conditions: viteCommand === "build" ?
|
|
1731
|
-
externalConditions: viteCommand === "build" ?
|
|
2461
|
+
conditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions],
|
|
2462
|
+
externalConditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions]
|
|
1732
2463
|
}
|
|
1733
2464
|
},
|
|
1734
2465
|
optimizeDeps: {
|
|
1735
2466
|
entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
|
|
1736
2467
|
ctx.entryClientFilePath,
|
|
1737
2468
|
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1738
|
-
(route) =>
|
|
2469
|
+
(route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
|
|
1739
2470
|
)
|
|
1740
2471
|
] : [],
|
|
1741
2472
|
include: [
|
|
@@ -1769,7 +2500,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1769
2500
|
"react-router/dom",
|
|
1770
2501
|
"react-router-dom"
|
|
1771
2502
|
],
|
|
1772
|
-
conditions: viteCommand === "build" ?
|
|
2503
|
+
conditions: viteCommand === "build" ? viteClientConditions : ["development", ...viteClientConditions]
|
|
1773
2504
|
},
|
|
1774
2505
|
base: viteUserConfig.base,
|
|
1775
2506
|
// When consumer provides an allow list for files that can be read by
|
|
@@ -1790,12 +2521,28 @@ var reactRouterVitePlugin = () => {
|
|
|
1790
2521
|
preserveEntrySignatures: "exports-only",
|
|
1791
2522
|
input: [
|
|
1792
2523
|
ctx.entryClientFilePath,
|
|
1793
|
-
...Object.values(
|
|
1794
|
-
|
|
2524
|
+
...Object.values(
|
|
2525
|
+
ctx.reactRouterConfig.routes
|
|
2526
|
+
).flatMap((route) => {
|
|
2527
|
+
let routeFilePath = path6.resolve(
|
|
1795
2528
|
ctx.reactRouterConfig.appDirectory,
|
|
1796
2529
|
route.file
|
|
1797
|
-
)
|
|
1798
|
-
|
|
2530
|
+
);
|
|
2531
|
+
let isRootRoute = route.file === ctx.reactRouterConfig.routes.root.file;
|
|
2532
|
+
let code = fse.readFileSync(
|
|
2533
|
+
routeFilePath,
|
|
2534
|
+
"utf-8"
|
|
2535
|
+
);
|
|
2536
|
+
return [
|
|
2537
|
+
`${routeFilePath}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
|
|
2538
|
+
...!isRootRoute ? routeChunkExportNames.map(
|
|
2539
|
+
(exportName) => code.includes(exportName) ? getRouteChunkModuleId(
|
|
2540
|
+
routeFilePath,
|
|
2541
|
+
exportName
|
|
2542
|
+
) : null
|
|
2543
|
+
) : []
|
|
2544
|
+
].filter(isNonNullable);
|
|
2545
|
+
})
|
|
1799
2546
|
]
|
|
1800
2547
|
}
|
|
1801
2548
|
} : {
|
|
@@ -1813,7 +2560,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1813
2560
|
rollupOptions: {
|
|
1814
2561
|
...baseRollupOptions,
|
|
1815
2562
|
preserveEntrySignatures: "exports-only",
|
|
1816
|
-
input: viteUserConfig.build?.rollupOptions?.input ??
|
|
2563
|
+
input: viteUserConfig.build?.rollupOptions?.input ?? virtual.serverBuild.id,
|
|
1817
2564
|
output: {
|
|
1818
2565
|
entryFileNames: ctx.reactRouterConfig.serverBuildFile,
|
|
1819
2566
|
format: ctx.reactRouterConfig.serverModuleFormat
|
|
@@ -1840,7 +2587,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1840
2587
|
"The React Router Vite plugin requires the use of a Vite config file"
|
|
1841
2588
|
);
|
|
1842
2589
|
}
|
|
1843
|
-
let vite2 =
|
|
2590
|
+
let vite2 = getVite();
|
|
1844
2591
|
let childCompilerConfigFile = await vite2.loadConfigFromFile(
|
|
1845
2592
|
{
|
|
1846
2593
|
command: viteConfig.command,
|
|
@@ -1876,15 +2623,15 @@ var reactRouterVitePlugin = () => {
|
|
|
1876
2623
|
envFile: false,
|
|
1877
2624
|
plugins: [
|
|
1878
2625
|
...(childCompilerConfigFile.config.plugins ?? []).flat().filter(
|
|
1879
|
-
(plugin2) => typeof plugin2 === "object" && plugin2 !== null && "name" in plugin2 && plugin2.name !== "react-router" && plugin2.name !== "react-router
|
|
2626
|
+
(plugin2) => typeof plugin2 === "object" && plugin2 !== null && "name" in plugin2 && plugin2.name !== "react-router" && plugin2.name !== "react-router:route-exports" && plugin2.name !== "react-router:hmr-updates"
|
|
1880
2627
|
)
|
|
1881
2628
|
]
|
|
1882
2629
|
});
|
|
1883
2630
|
await viteChildCompiler.pluginContainer.buildStart({});
|
|
1884
2631
|
},
|
|
1885
|
-
async transform(code,
|
|
1886
|
-
if (isCssModulesFile(
|
|
1887
|
-
cssModulesManifest[
|
|
2632
|
+
async transform(code, id) {
|
|
2633
|
+
if (isCssModulesFile(id)) {
|
|
2634
|
+
cssModulesManifest[id] = code;
|
|
1888
2635
|
}
|
|
1889
2636
|
},
|
|
1890
2637
|
buildStart() {
|
|
@@ -1908,7 +2655,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1908
2655
|
(0, import_react_router2.unstable_setDevServerHooks)({
|
|
1909
2656
|
// Give the request handler access to the critical CSS in dev to avoid a
|
|
1910
2657
|
// flash of unstyled content since Vite injects CSS file contents via JS
|
|
1911
|
-
getCriticalCss: async (build,
|
|
2658
|
+
getCriticalCss: async (build, url2) => {
|
|
1912
2659
|
return getStylesForUrl({
|
|
1913
2660
|
rootDirectory: ctx.rootDirectory,
|
|
1914
2661
|
entryClientFilePath: ctx.entryClientFilePath,
|
|
@@ -1916,7 +2663,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1916
2663
|
viteDevServer,
|
|
1917
2664
|
cssModulesManifest,
|
|
1918
2665
|
build,
|
|
1919
|
-
url:
|
|
2666
|
+
url: url2
|
|
1920
2667
|
});
|
|
1921
2668
|
},
|
|
1922
2669
|
// If an error is caught within the request handler, let Vite fix the
|
|
@@ -1964,7 +2711,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1964
2711
|
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
1965
2712
|
try {
|
|
1966
2713
|
let build = await viteDevServer.ssrLoadModule(
|
|
1967
|
-
|
|
2714
|
+
virtual.serverBuild.id
|
|
1968
2715
|
);
|
|
1969
2716
|
let handler = (0, import_react_router2.createRequestHandler)(build, "development");
|
|
1970
2717
|
let nodeHandler = async (nodeReq, nodeRes) => {
|
|
@@ -1999,8 +2746,8 @@ var reactRouterVitePlugin = () => {
|
|
|
1999
2746
|
let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
|
|
2000
2747
|
let movedAssetPaths = [];
|
|
2001
2748
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
2002
|
-
let src =
|
|
2003
|
-
let dest =
|
|
2749
|
+
let src = path6.join(serverBuildDirectory, ssrAssetPath);
|
|
2750
|
+
let dest = path6.join(clientBuildDirectory, ssrAssetPath);
|
|
2004
2751
|
if (!fse.existsSync(dest)) {
|
|
2005
2752
|
await fse.move(src, dest);
|
|
2006
2753
|
movedAssetPaths.push(dest);
|
|
@@ -2013,7 +2760,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2013
2760
|
);
|
|
2014
2761
|
await Promise.all(
|
|
2015
2762
|
ssrCssPaths.map(
|
|
2016
|
-
(cssPath) => fse.remove(
|
|
2763
|
+
(cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
|
|
2017
2764
|
)
|
|
2018
2765
|
);
|
|
2019
2766
|
if (movedAssetPaths.length) {
|
|
@@ -2022,7 +2769,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2022
2769
|
"",
|
|
2023
2770
|
`${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
|
|
2024
2771
|
...movedAssetPaths.map(
|
|
2025
|
-
(movedAssetPath) => import_picocolors3.default.dim(
|
|
2772
|
+
(movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
|
|
2026
2773
|
),
|
|
2027
2774
|
""
|
|
2028
2775
|
].join("\n")
|
|
@@ -2064,41 +2811,132 @@ var reactRouterVitePlugin = () => {
|
|
|
2064
2811
|
}
|
|
2065
2812
|
},
|
|
2066
2813
|
{
|
|
2067
|
-
name: "react-router
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2814
|
+
name: "react-router:route-chunks-index",
|
|
2815
|
+
// This plugin provides the route module "index" since route modules can
|
|
2816
|
+
// be chunked and may be made up of multiple smaller modules. This plugin
|
|
2817
|
+
// primarily ensures code is never duplicated across a route module and
|
|
2818
|
+
// its chunks. If we didn't have this plugin, any app that explicitly
|
|
2819
|
+
// imports a route module would result in duplicate code since the app
|
|
2820
|
+
// would contain code for both the unprocessed route module as well as its
|
|
2821
|
+
// individual chunks. This is because, since they have different module
|
|
2822
|
+
// IDs, they are treated as completely separate modules even though they
|
|
2823
|
+
// all reference the same underlying file. This plugin addresses this by
|
|
2824
|
+
// ensuring that any explicit imports of a route module resolve to a
|
|
2825
|
+
// module that simply re-exports from its underlying chunks, if present.
|
|
2826
|
+
async transform(code, id, options) {
|
|
2827
|
+
if (viteCommand !== "build") return;
|
|
2828
|
+
if (options?.ssr) {
|
|
2829
|
+
return;
|
|
2830
|
+
}
|
|
2831
|
+
if (!isRoute(ctx.reactRouterConfig, id)) {
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
if (isRouteVirtualModule(id)) {
|
|
2835
|
+
return;
|
|
2836
|
+
}
|
|
2837
|
+
let { hasRouteChunks, chunkedExports } = await detectRouteChunksIfEnabled(cache, ctx, id, code);
|
|
2838
|
+
if (!hasRouteChunks) {
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2841
|
+
let sourceExports = await getRouteModuleExports(
|
|
2842
|
+
viteChildCompiler,
|
|
2843
|
+
ctx,
|
|
2844
|
+
id
|
|
2845
|
+
);
|
|
2846
|
+
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
2847
|
+
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
2848
|
+
let chunkBasePath = `./${path6.basename(id)}`;
|
|
2849
|
+
return [
|
|
2850
|
+
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
2851
|
+
chunkBasePath,
|
|
2852
|
+
"main"
|
|
2853
|
+
)}";`,
|
|
2854
|
+
...chunkedExports.map(
|
|
2855
|
+
(exportName) => `export { ${exportName} } from "${getRouteChunkModuleId(
|
|
2856
|
+
chunkBasePath,
|
|
2857
|
+
exportName
|
|
2858
|
+
)}";`
|
|
2859
|
+
)
|
|
2860
|
+
].filter(Boolean).join("\n");
|
|
2861
|
+
}
|
|
2862
|
+
},
|
|
2863
|
+
{
|
|
2864
|
+
name: "react-router:build-client-route",
|
|
2865
|
+
async transform(code, id, options) {
|
|
2866
|
+
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
2867
|
+
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
2868
|
+
let routeFileName = path6.basename(routeModuleId);
|
|
2073
2869
|
let sourceExports = await getRouteModuleExports(
|
|
2074
2870
|
viteChildCompiler,
|
|
2075
2871
|
ctx,
|
|
2076
2872
|
routeModuleId
|
|
2077
2873
|
);
|
|
2078
|
-
let
|
|
2079
|
-
|
|
2080
|
-
|
|
2874
|
+
let { chunkedExports = [] } = options?.ssr ? {} : await detectRouteChunksIfEnabled(cache, ctx, id, code);
|
|
2875
|
+
let reexports = sourceExports.filter((exportName) => {
|
|
2876
|
+
let isRouteEntryExport = options?.ssr && SERVER_ONLY_ROUTE_EXPORTS.includes(exportName) || CLIENT_ROUTE_EXPORTS.includes(exportName);
|
|
2877
|
+
let isChunkedExport = chunkedExports.includes(
|
|
2878
|
+
exportName
|
|
2879
|
+
);
|
|
2880
|
+
return isRouteEntryExport && !isChunkedExport;
|
|
2881
|
+
}).join(", ");
|
|
2081
2882
|
return `export { ${reexports} } from "./${routeFileName}";`;
|
|
2082
2883
|
}
|
|
2083
2884
|
},
|
|
2084
2885
|
{
|
|
2085
|
-
name: "react-router-
|
|
2886
|
+
name: "react-router:route-chunks",
|
|
2887
|
+
async transform(code, id, options) {
|
|
2888
|
+
if (options?.ssr) return;
|
|
2889
|
+
if (!isRouteChunkModuleId(id)) return;
|
|
2890
|
+
let chunkName = getRouteChunkNameFromModuleId(id);
|
|
2891
|
+
if (!chunkName) {
|
|
2892
|
+
throw new Error(`Invalid route chunk name "${chunkName}" in "${id}"`);
|
|
2893
|
+
}
|
|
2894
|
+
let chunk = await getRouteChunkIfEnabled(
|
|
2895
|
+
cache,
|
|
2896
|
+
ctx,
|
|
2897
|
+
id,
|
|
2898
|
+
chunkName,
|
|
2899
|
+
code
|
|
2900
|
+
);
|
|
2901
|
+
let preventEmptyChunkSnippet = ({ reason }) => `Math.random()<0&&console.log(${JSON.stringify(reason)});`;
|
|
2902
|
+
if (chunk === null) {
|
|
2903
|
+
return preventEmptyChunkSnippet({ reason: "Route chunks disabled" });
|
|
2904
|
+
}
|
|
2905
|
+
let enforceRouteChunks = ctx.reactRouterConfig.future.unstable_routeChunks === "enforce";
|
|
2906
|
+
if (enforceRouteChunks && chunkName === "main" && chunk) {
|
|
2907
|
+
let exportNames = getExportNames(chunk.code);
|
|
2908
|
+
validateRouteChunks({
|
|
2909
|
+
ctx,
|
|
2910
|
+
id,
|
|
2911
|
+
valid: {
|
|
2912
|
+
clientAction: !exportNames.includes("clientAction"),
|
|
2913
|
+
clientLoader: !exportNames.includes("clientLoader"),
|
|
2914
|
+
HydrateFallback: !exportNames.includes("HydrateFallback")
|
|
2915
|
+
}
|
|
2916
|
+
});
|
|
2917
|
+
}
|
|
2918
|
+
return chunk ?? preventEmptyChunkSnippet({ reason: `No ${chunkName} chunk` });
|
|
2919
|
+
}
|
|
2920
|
+
},
|
|
2921
|
+
{
|
|
2922
|
+
name: "react-router:virtual-modules",
|
|
2086
2923
|
enforce: "pre",
|
|
2087
|
-
resolveId(
|
|
2088
|
-
|
|
2924
|
+
resolveId(id) {
|
|
2925
|
+
const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
|
|
2926
|
+
if (vmod2) return vmod2.resolvedId;
|
|
2089
2927
|
},
|
|
2090
|
-
async load(
|
|
2091
|
-
switch (
|
|
2092
|
-
case
|
|
2928
|
+
async load(id) {
|
|
2929
|
+
switch (id) {
|
|
2930
|
+
case virtual.serverBuild.resolvedId: {
|
|
2093
2931
|
return await getServerEntry();
|
|
2094
2932
|
}
|
|
2095
|
-
case
|
|
2933
|
+
case virtual.serverManifest.resolvedId: {
|
|
2096
2934
|
let reactRouterManifest = ctx.isSsrBuild ? await ctx.getReactRouterServerManifest() : await getReactRouterManifestForDev();
|
|
2097
2935
|
return `export default ${(0, import_jsesc.default)(reactRouterManifest, {
|
|
2098
2936
|
es6: true
|
|
2099
2937
|
})};`;
|
|
2100
2938
|
}
|
|
2101
|
-
case
|
|
2939
|
+
case virtual.browserManifest.resolvedId: {
|
|
2102
2940
|
if (viteCommand === "build") {
|
|
2103
2941
|
throw new Error("This module only exists in development");
|
|
2104
2942
|
}
|
|
@@ -2112,15 +2950,15 @@ var reactRouterVitePlugin = () => {
|
|
|
2112
2950
|
}
|
|
2113
2951
|
},
|
|
2114
2952
|
{
|
|
2115
|
-
name: "react-router
|
|
2953
|
+
name: "react-router:dot-server",
|
|
2116
2954
|
enforce: "pre",
|
|
2117
|
-
async resolveId(
|
|
2955
|
+
async resolveId(id, importer, options) {
|
|
2118
2956
|
let isOptimizeDeps = viteCommand === "serve" && options?.scan === true;
|
|
2119
2957
|
if (isOptimizeDeps || options?.ssr) return;
|
|
2120
|
-
let isResolving = options?.custom?.["react-router
|
|
2958
|
+
let isResolving = options?.custom?.["react-router:dot-server"] ?? false;
|
|
2121
2959
|
if (isResolving) return;
|
|
2122
|
-
options.custom = { ...options.custom, "react-router
|
|
2123
|
-
let resolved = await this.resolve(
|
|
2960
|
+
options.custom = { ...options.custom, "react-router:dot-server": true };
|
|
2961
|
+
let resolved = await this.resolve(id, importer, options);
|
|
2124
2962
|
if (!resolved) return;
|
|
2125
2963
|
let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
|
|
2126
2964
|
let serverDirRE = /\/\.server\//;
|
|
@@ -2130,12 +2968,11 @@ var reactRouterVitePlugin = () => {
|
|
|
2130
2968
|
if (viteCommand !== "build" && importer.endsWith(".html")) {
|
|
2131
2969
|
return;
|
|
2132
2970
|
}
|
|
2133
|
-
let vite2 =
|
|
2971
|
+
let vite2 = getVite();
|
|
2134
2972
|
let importerShort = vite2.normalizePath(
|
|
2135
|
-
|
|
2973
|
+
path6.relative(ctx.rootDirectory, importer)
|
|
2136
2974
|
);
|
|
2137
|
-
|
|
2138
|
-
if (isRoute) {
|
|
2975
|
+
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
2139
2976
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
2140
2977
|
(xport) => `\`${xport}\``
|
|
2141
2978
|
).join(", ");
|
|
@@ -2143,12 +2980,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2143
2980
|
[
|
|
2144
2981
|
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
2145
2982
|
"",
|
|
2146
|
-
` '${
|
|
2983
|
+
` '${id}' imported by route '${importerShort}'`,
|
|
2147
2984
|
"",
|
|
2148
2985
|
` React Router automatically removes server-code from these exports:`,
|
|
2149
2986
|
` ${serverOnlyExports}`,
|
|
2150
2987
|
"",
|
|
2151
|
-
` But other route exports in '${importerShort}' depend on '${
|
|
2988
|
+
` But other route exports in '${importerShort}' depend on '${id}'.`,
|
|
2152
2989
|
"",
|
|
2153
2990
|
" See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
|
|
2154
2991
|
""
|
|
@@ -2159,7 +2996,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2159
2996
|
[
|
|
2160
2997
|
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
2161
2998
|
"",
|
|
2162
|
-
` '${
|
|
2999
|
+
` '${id}' imported by '${importerShort}'`,
|
|
2163
3000
|
"",
|
|
2164
3001
|
" See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
|
|
2165
3002
|
""
|
|
@@ -2168,16 +3005,16 @@ var reactRouterVitePlugin = () => {
|
|
|
2168
3005
|
}
|
|
2169
3006
|
},
|
|
2170
3007
|
{
|
|
2171
|
-
name: "react-router
|
|
2172
|
-
async transform(code,
|
|
3008
|
+
name: "react-router:dot-client",
|
|
3009
|
+
async transform(code, id, options) {
|
|
2173
3010
|
if (!options?.ssr) return;
|
|
2174
3011
|
let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
|
|
2175
3012
|
let clientDirRE = /\/\.client\//;
|
|
2176
|
-
if (clientFileRE.test(
|
|
2177
|
-
let exports2 = (
|
|
3013
|
+
if (clientFileRE.test(id) || clientDirRE.test(id)) {
|
|
3014
|
+
let exports2 = getExportNames(code);
|
|
2178
3015
|
return {
|
|
2179
3016
|
code: exports2.map(
|
|
2180
|
-
(
|
|
3017
|
+
(name) => name === "default" ? "export default undefined;" : `export const ${name} = undefined;`
|
|
2181
3018
|
).join("\n"),
|
|
2182
3019
|
map: null
|
|
2183
3020
|
};
|
|
@@ -2186,26 +3023,31 @@ var reactRouterVitePlugin = () => {
|
|
|
2186
3023
|
},
|
|
2187
3024
|
plugin,
|
|
2188
3025
|
{
|
|
2189
|
-
name: "react-router
|
|
2190
|
-
async transform(code,
|
|
2191
|
-
let route = getRoute(ctx.reactRouterConfig,
|
|
3026
|
+
name: "react-router:route-exports",
|
|
3027
|
+
async transform(code, id, options) {
|
|
3028
|
+
let route = getRoute(ctx.reactRouterConfig, id);
|
|
2192
3029
|
if (!route) return;
|
|
2193
3030
|
if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
|
|
2194
|
-
let
|
|
3031
|
+
let exportNames = getExportNames(code);
|
|
3032
|
+
let serverOnlyExports = exportNames.filter(
|
|
3033
|
+
(exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp)
|
|
3034
|
+
);
|
|
2195
3035
|
if (serverOnlyExports.length > 0) {
|
|
2196
3036
|
let str = serverOnlyExports.map((e) => `\`${e}\``).join(", ");
|
|
2197
3037
|
let message = `SPA Mode: ${serverOnlyExports.length} invalid route export(s) in \`${route.file}\`: ${str}. See https://remix.run/guides/spa-mode for more information.`;
|
|
2198
3038
|
throw Error(message);
|
|
2199
3039
|
}
|
|
2200
3040
|
if (route.id !== "root") {
|
|
2201
|
-
let hasHydrateFallback =
|
|
3041
|
+
let hasHydrateFallback = exportNames.some(
|
|
3042
|
+
(exp) => exp === "HydrateFallback"
|
|
3043
|
+
);
|
|
2202
3044
|
if (hasHydrateFallback) {
|
|
2203
3045
|
let message = `SPA Mode: Invalid \`HydrateFallback\` export found in \`${route.file}\`. \`HydrateFallback\` is only permitted on the root route in SPA Mode. See https://remix.run/guides/spa-mode for more information.`;
|
|
2204
3046
|
throw Error(message);
|
|
2205
3047
|
}
|
|
2206
3048
|
}
|
|
2207
3049
|
}
|
|
2208
|
-
let [filepath] =
|
|
3050
|
+
let [filepath] = id.split("?");
|
|
2209
3051
|
let ast = (0, import_parser.parse)(code, { sourceType: "module" });
|
|
2210
3052
|
if (!options?.ssr) {
|
|
2211
3053
|
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
|
|
@@ -2213,22 +3055,23 @@ var reactRouterVitePlugin = () => {
|
|
|
2213
3055
|
transform(ast);
|
|
2214
3056
|
return generate2(ast, {
|
|
2215
3057
|
sourceMaps: true,
|
|
2216
|
-
filename:
|
|
3058
|
+
filename: id,
|
|
2217
3059
|
sourceFileName: filepath
|
|
2218
3060
|
});
|
|
2219
3061
|
}
|
|
2220
3062
|
},
|
|
2221
3063
|
{
|
|
2222
|
-
name: "react-router
|
|
3064
|
+
name: "react-router:inject-hmr-runtime",
|
|
2223
3065
|
enforce: "pre",
|
|
2224
|
-
resolveId(
|
|
2225
|
-
if (
|
|
2226
|
-
return
|
|
3066
|
+
resolveId(id) {
|
|
3067
|
+
if (id === virtualInjectHmrRuntime.id) {
|
|
3068
|
+
return virtualInjectHmrRuntime.resolvedId;
|
|
3069
|
+
}
|
|
2227
3070
|
},
|
|
2228
|
-
async load(
|
|
2229
|
-
if (
|
|
3071
|
+
async load(id) {
|
|
3072
|
+
if (id !== virtualInjectHmrRuntime.resolvedId) return;
|
|
2230
3073
|
return [
|
|
2231
|
-
`import RefreshRuntime from "${
|
|
3074
|
+
`import RefreshRuntime from "${virtualHmrRuntime.id}"`,
|
|
2232
3075
|
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
2233
3076
|
"window.$RefreshReg$ = () => {}",
|
|
2234
3077
|
"window.$RefreshSig$ = () => (type) => type",
|
|
@@ -2237,17 +3080,17 @@ var reactRouterVitePlugin = () => {
|
|
|
2237
3080
|
}
|
|
2238
3081
|
},
|
|
2239
3082
|
{
|
|
2240
|
-
name: "react-router
|
|
3083
|
+
name: "react-router:hmr-runtime",
|
|
2241
3084
|
enforce: "pre",
|
|
2242
|
-
resolveId(
|
|
2243
|
-
if (
|
|
3085
|
+
resolveId(id) {
|
|
3086
|
+
if (id === virtualHmrRuntime.id) return virtualHmrRuntime.resolvedId;
|
|
2244
3087
|
},
|
|
2245
|
-
async load(
|
|
2246
|
-
if (
|
|
2247
|
-
let reactRefreshDir =
|
|
3088
|
+
async load(id) {
|
|
3089
|
+
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
3090
|
+
let reactRefreshDir = path6.dirname(
|
|
2248
3091
|
require.resolve("react-refresh/package.json")
|
|
2249
3092
|
);
|
|
2250
|
-
let reactRefreshRuntimePath =
|
|
3093
|
+
let reactRefreshRuntimePath = path6.join(
|
|
2251
3094
|
reactRefreshDir,
|
|
2252
3095
|
"cjs/react-refresh-runtime.development.js"
|
|
2253
3096
|
);
|
|
@@ -2263,11 +3106,11 @@ var reactRouterVitePlugin = () => {
|
|
|
2263
3106
|
}
|
|
2264
3107
|
},
|
|
2265
3108
|
{
|
|
2266
|
-
name: "react-router
|
|
2267
|
-
async transform(code,
|
|
3109
|
+
name: "react-router:react-refresh-babel",
|
|
3110
|
+
async transform(code, id, options) {
|
|
2268
3111
|
if (viteCommand !== "serve") return;
|
|
2269
|
-
if (
|
|
2270
|
-
let [filepath] =
|
|
3112
|
+
if (id.includes("/node_modules/")) return;
|
|
3113
|
+
let [filepath] = id.split("?");
|
|
2271
3114
|
let extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
2272
3115
|
if (!extensionsRE.test(filepath)) return;
|
|
2273
3116
|
let devRuntime = "react/jsx-dev-runtime";
|
|
@@ -2275,13 +3118,13 @@ var reactRouterVitePlugin = () => {
|
|
|
2275
3118
|
let isJSX = filepath.endsWith("x");
|
|
2276
3119
|
let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
2277
3120
|
if (!useFastRefresh) return;
|
|
2278
|
-
if (
|
|
2279
|
-
return { code: addRefreshWrapper(ctx.reactRouterConfig, code,
|
|
3121
|
+
if (isRouteVirtualModule(id)) {
|
|
3122
|
+
return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id) };
|
|
2280
3123
|
}
|
|
2281
3124
|
let result = await babel.transformAsync(code, {
|
|
2282
3125
|
babelrc: false,
|
|
2283
3126
|
configFile: false,
|
|
2284
|
-
filename:
|
|
3127
|
+
filename: id,
|
|
2285
3128
|
sourceFileName: filepath,
|
|
2286
3129
|
parserOpts: {
|
|
2287
3130
|
sourceType: "module",
|
|
@@ -2294,20 +3137,21 @@ var reactRouterVitePlugin = () => {
|
|
|
2294
3137
|
code = result.code;
|
|
2295
3138
|
let refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
2296
3139
|
if (refreshContentRE.test(code)) {
|
|
2297
|
-
code = addRefreshWrapper(ctx.reactRouterConfig, code,
|
|
3140
|
+
code = addRefreshWrapper(ctx.reactRouterConfig, code, id);
|
|
2298
3141
|
}
|
|
2299
3142
|
return { code, map: result.map };
|
|
2300
3143
|
}
|
|
2301
3144
|
},
|
|
2302
3145
|
{
|
|
2303
|
-
name: "react-router
|
|
3146
|
+
name: "react-router:hmr-updates",
|
|
2304
3147
|
async handleHotUpdate({ server, file, modules, read }) {
|
|
2305
3148
|
let route = getRoute(ctx.reactRouterConfig, file);
|
|
2306
3149
|
let hmrEventData = { route: null };
|
|
2307
3150
|
if (route) {
|
|
2308
|
-
let serverManifest = (await server.ssrLoadModule(
|
|
3151
|
+
let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
|
|
2309
3152
|
let oldRouteMetadata = serverManifest.routes[route.id];
|
|
2310
3153
|
let newRouteMetadata = await getRouteMetadata(
|
|
3154
|
+
cache,
|
|
2311
3155
|
ctx,
|
|
2312
3156
|
viteChildCompiler,
|
|
2313
3157
|
route,
|
|
@@ -2317,9 +3161,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2317
3161
|
if (!oldRouteMetadata || [
|
|
2318
3162
|
"hasLoader",
|
|
2319
3163
|
"hasClientLoader",
|
|
3164
|
+
"clientLoaderModule",
|
|
2320
3165
|
"hasAction",
|
|
2321
3166
|
"hasClientAction",
|
|
2322
|
-
"
|
|
3167
|
+
"clientActionModule",
|
|
3168
|
+
"hasErrorBoundary",
|
|
3169
|
+
"hydrateFallbackModule"
|
|
2323
3170
|
].some((key) => oldRouteMetadata[key] !== newRouteMetadata[key])) {
|
|
2324
3171
|
invalidateVirtualModules(server);
|
|
2325
3172
|
}
|
|
@@ -2331,39 +3178,69 @@ var reactRouterVitePlugin = () => {
|
|
|
2331
3178
|
});
|
|
2332
3179
|
return modules;
|
|
2333
3180
|
}
|
|
3181
|
+
},
|
|
3182
|
+
{
|
|
3183
|
+
name: "react-router-server-change-trigger-client-hmr",
|
|
3184
|
+
// This hook is only available in Vite v6+ so this is a no-op in v5.
|
|
3185
|
+
// Previously the server and client modules were shared in a single module
|
|
3186
|
+
// graph. This meant that changes to server code automatically resulted in
|
|
3187
|
+
// client HMR updates. In Vite v6+ these module graphs are separate from
|
|
3188
|
+
// each other so we need to manually trigger client HMR updates if server
|
|
3189
|
+
// code has changed.
|
|
3190
|
+
hotUpdate({ server, modules }) {
|
|
3191
|
+
if (this.environment.name !== "ssr" && modules.length <= 0) {
|
|
3192
|
+
return;
|
|
3193
|
+
}
|
|
3194
|
+
let clientModules = uniqueNodes(
|
|
3195
|
+
modules.flatMap(
|
|
3196
|
+
(mod) => getParentClientNodes(server.environments.client.moduleGraph, mod)
|
|
3197
|
+
)
|
|
3198
|
+
);
|
|
3199
|
+
for (let clientModule of clientModules) {
|
|
3200
|
+
server.environments.client.reloadModule(clientModule);
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
2334
3203
|
}
|
|
2335
3204
|
];
|
|
2336
3205
|
};
|
|
2337
|
-
function
|
|
2338
|
-
|
|
2339
|
-
|
|
3206
|
+
function getParentClientNodes(clientModuleGraph, module2) {
|
|
3207
|
+
if (!module2.id) {
|
|
3208
|
+
return [];
|
|
3209
|
+
}
|
|
3210
|
+
let clientModule = clientModuleGraph.getModuleById(module2.id);
|
|
3211
|
+
if (clientModule) {
|
|
3212
|
+
return [clientModule];
|
|
3213
|
+
}
|
|
3214
|
+
return [...module2.importers].flatMap(
|
|
3215
|
+
(importer) => getParentClientNodes(clientModuleGraph, importer)
|
|
3216
|
+
);
|
|
3217
|
+
}
|
|
3218
|
+
function uniqueNodes(nodes) {
|
|
3219
|
+
let nodeUrls = /* @__PURE__ */ new Set();
|
|
3220
|
+
let unique = [];
|
|
3221
|
+
for (let node of nodes) {
|
|
3222
|
+
if (nodeUrls.has(node.url)) {
|
|
3223
|
+
continue;
|
|
3224
|
+
}
|
|
3225
|
+
nodeUrls.add(node.url);
|
|
3226
|
+
unique.push(node);
|
|
3227
|
+
}
|
|
3228
|
+
return unique;
|
|
3229
|
+
}
|
|
3230
|
+
function addRefreshWrapper(reactRouterConfig, code, id) {
|
|
3231
|
+
let route = getRoute(reactRouterConfig, id);
|
|
3232
|
+
let acceptExports = route ? [
|
|
2340
3233
|
"clientAction",
|
|
2341
3234
|
"clientLoader",
|
|
2342
|
-
"clientMiddleware",
|
|
2343
3235
|
"handle",
|
|
2344
3236
|
"meta",
|
|
2345
3237
|
"links",
|
|
2346
3238
|
"shouldRevalidate"
|
|
2347
3239
|
] : [];
|
|
2348
|
-
return "
|
|
2349
|
-
"REACT REFRESH HEADER",
|
|
2350
|
-
REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id2))
|
|
2351
|
-
) + "\n\n" + withCommentBoundaries("REACT REFRESH BODY", code) + "\n\n" + withCommentBoundaries(
|
|
2352
|
-
"REACT REFRESH FOOTER",
|
|
2353
|
-
REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id2)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(route?.id))
|
|
2354
|
-
) + "\n";
|
|
2355
|
-
}
|
|
2356
|
-
function withCommentBoundaries(label, text) {
|
|
2357
|
-
let begin = `// [BEGIN] ${label} `;
|
|
2358
|
-
begin += "-".repeat(80 - begin.length);
|
|
2359
|
-
let end = `// [END] ${label} `;
|
|
2360
|
-
end += "-".repeat(80 - end.length);
|
|
2361
|
-
return `${begin}
|
|
2362
|
-
${text}
|
|
2363
|
-
${end}`;
|
|
3240
|
+
return REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id)) + code + REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(route?.id));
|
|
2364
3241
|
}
|
|
2365
3242
|
var REACT_REFRESH_HEADER = `
|
|
2366
|
-
import RefreshRuntime from "${
|
|
3243
|
+
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
2367
3244
|
|
|
2368
3245
|
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
2369
3246
|
let prevRefreshReg;
|
|
@@ -2382,7 +3259,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
2382
3259
|
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
2383
3260
|
};
|
|
2384
3261
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
2385
|
-
}`.
|
|
3262
|
+
}`.replaceAll("\n", "");
|
|
2386
3263
|
var REACT_REFRESH_FOOTER = `
|
|
2387
3264
|
if (import.meta.hot && !inWebWorker) {
|
|
2388
3265
|
window.$RefreshReg$ = prevRefreshReg;
|
|
@@ -2396,24 +3273,41 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
2396
3273
|
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
2397
3274
|
});
|
|
2398
3275
|
});
|
|
2399
|
-
}
|
|
3276
|
+
}`;
|
|
2400
3277
|
function getRoute(pluginConfig, file) {
|
|
2401
|
-
let vite2 =
|
|
3278
|
+
let vite2 = getVite();
|
|
2402
3279
|
let routePath = vite2.normalizePath(
|
|
2403
|
-
|
|
3280
|
+
path6.relative(pluginConfig.appDirectory, file)
|
|
2404
3281
|
);
|
|
2405
3282
|
let route = Object.values(pluginConfig.routes).find(
|
|
2406
3283
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
2407
3284
|
);
|
|
2408
3285
|
return route;
|
|
2409
3286
|
}
|
|
2410
|
-
|
|
3287
|
+
function isRoute(pluginConfig, file) {
|
|
3288
|
+
return Boolean(getRoute(pluginConfig, file));
|
|
3289
|
+
}
|
|
3290
|
+
async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteFile) {
|
|
3291
|
+
let routeFile = route.file;
|
|
2411
3292
|
let sourceExports = await getRouteModuleExports(
|
|
2412
3293
|
viteChildCompiler,
|
|
2413
3294
|
ctx,
|
|
2414
3295
|
route.file,
|
|
2415
3296
|
readRouteFile
|
|
2416
3297
|
);
|
|
3298
|
+
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
3299
|
+
cache,
|
|
3300
|
+
ctx,
|
|
3301
|
+
routeFile,
|
|
3302
|
+
{ routeFile, readRouteFile, viteChildCompiler }
|
|
3303
|
+
);
|
|
3304
|
+
let moduleUrl = combineURLs(
|
|
3305
|
+
ctx.publicPath,
|
|
3306
|
+
`${resolveFileUrl(
|
|
3307
|
+
ctx,
|
|
3308
|
+
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
3309
|
+
)}`
|
|
3310
|
+
);
|
|
2417
3311
|
let info = {
|
|
2418
3312
|
id: route.id,
|
|
2419
3313
|
parentId: route.parentId,
|
|
@@ -2422,19 +3316,16 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
|
2422
3316
|
caseSensitive: route.caseSensitive,
|
|
2423
3317
|
url: combineURLs(
|
|
2424
3318
|
ctx.publicPath,
|
|
2425
|
-
"/" +
|
|
3319
|
+
"/" + path6.relative(
|
|
2426
3320
|
ctx.rootDirectory,
|
|
2427
3321
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2428
3322
|
)
|
|
2429
3323
|
),
|
|
2430
|
-
module:
|
|
2431
|
-
ctx.publicPath,
|
|
2432
|
-
`${resolveFileUrl(
|
|
2433
|
-
ctx,
|
|
2434
|
-
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2435
|
-
)}?import`
|
|
2436
|
-
),
|
|
3324
|
+
module: `${moduleUrl}?import`,
|
|
2437
3325
|
// Ensure the Vite dev server responds with a JS module
|
|
3326
|
+
clientActionModule: hasRouteChunkByExportName.clientAction ? `${getRouteChunkModuleId(moduleUrl, "clientAction")}` : void 0,
|
|
3327
|
+
clientLoaderModule: hasRouteChunkByExportName.clientLoader ? `${getRouteChunkModuleId(moduleUrl, "clientLoader")}` : void 0,
|
|
3328
|
+
hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? `${getRouteChunkModuleId(moduleUrl, "HydrateFallback")}` : void 0,
|
|
2438
3329
|
hasAction: sourceExports.includes("action"),
|
|
2439
3330
|
hasClientAction: sourceExports.includes("clientAction"),
|
|
2440
3331
|
hasLoader: sourceExports.includes("loader"),
|
|
@@ -2445,11 +3336,11 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
|
2445
3336
|
return info;
|
|
2446
3337
|
}
|
|
2447
3338
|
async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
|
|
2448
|
-
let serverBuildPath =
|
|
3339
|
+
let serverBuildPath = path6.join(
|
|
2449
3340
|
serverBuildDirectory,
|
|
2450
3341
|
reactRouterConfig.serverBuildFile
|
|
2451
3342
|
);
|
|
2452
|
-
let build = await import(
|
|
3343
|
+
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
2453
3344
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
2454
3345
|
return {
|
|
2455
3346
|
build,
|
|
@@ -2467,9 +3358,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
2467
3358
|
let html = await response.text();
|
|
2468
3359
|
validatePrerenderedResponse(response, html, "SPA Mode", "/");
|
|
2469
3360
|
validatePrerenderedHtml(html, "SPA Mode");
|
|
2470
|
-
await fse.writeFile(
|
|
3361
|
+
await fse.writeFile(path6.join(clientBuildDirectory, "index.html"), html);
|
|
2471
3362
|
viteConfig.logger.info(
|
|
2472
|
-
"SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(
|
|
3363
|
+
"SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path6.relative(process.cwd(), clientBuildDirectory)) + " directory"
|
|
2473
3364
|
);
|
|
2474
3365
|
}
|
|
2475
3366
|
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
|
|
@@ -2499,14 +3390,14 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2499
3390
|
// build time or runtime
|
|
2500
3391
|
"X-React-Router-Prerender": "yes"
|
|
2501
3392
|
};
|
|
2502
|
-
for (let
|
|
2503
|
-
let matches = (0, import_react_router2.matchRoutes)(routes,
|
|
3393
|
+
for (let path7 of routesToPrerender) {
|
|
3394
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
2504
3395
|
let hasLoaders = matches?.some((m) => m.route.loader);
|
|
2505
3396
|
let data;
|
|
2506
3397
|
if (hasLoaders) {
|
|
2507
3398
|
data = await prerenderData(
|
|
2508
3399
|
handler,
|
|
2509
|
-
|
|
3400
|
+
path7,
|
|
2510
3401
|
clientBuildDirectory,
|
|
2511
3402
|
reactRouterConfig,
|
|
2512
3403
|
viteConfig,
|
|
@@ -2519,7 +3410,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2519
3410
|
if (isResourceRoute) {
|
|
2520
3411
|
await prerenderResourceRoute(
|
|
2521
3412
|
handler,
|
|
2522
|
-
|
|
3413
|
+
path7,
|
|
2523
3414
|
clientBuildDirectory,
|
|
2524
3415
|
reactRouterConfig,
|
|
2525
3416
|
viteConfig,
|
|
@@ -2528,7 +3419,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2528
3419
|
} else {
|
|
2529
3420
|
await prerenderRoute(
|
|
2530
3421
|
handler,
|
|
2531
|
-
|
|
3422
|
+
path7,
|
|
2532
3423
|
clientBuildDirectory,
|
|
2533
3424
|
reactRouterConfig,
|
|
2534
3425
|
viteConfig,
|
|
@@ -2585,9 +3476,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
|
|
|
2585
3476
|
let response = await handler(request);
|
|
2586
3477
|
let data = await response.text();
|
|
2587
3478
|
validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
|
|
2588
|
-
let outdir =
|
|
2589
|
-
let outfile =
|
|
2590
|
-
await fse.ensureDir(
|
|
3479
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3480
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
3481
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2591
3482
|
await fse.outputFile(outfile, data);
|
|
2592
3483
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2593
3484
|
return data;
|
|
@@ -2604,9 +3495,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
2604
3495
|
if (!reactRouterConfig.ssr) {
|
|
2605
3496
|
validatePrerenderedHtml(html, "Prerender");
|
|
2606
3497
|
}
|
|
2607
|
-
let outdir =
|
|
2608
|
-
let outfile =
|
|
2609
|
-
await fse.ensureDir(
|
|
3498
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3499
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
|
|
3500
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2610
3501
|
await fse.outputFile(outfile, html);
|
|
2611
3502
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2612
3503
|
}
|
|
@@ -2616,9 +3507,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
2616
3507
|
let response = await handler(request);
|
|
2617
3508
|
let text = await response.text();
|
|
2618
3509
|
validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
|
|
2619
|
-
let outdir =
|
|
2620
|
-
let outfile =
|
|
2621
|
-
await fse.ensureDir(
|
|
3510
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3511
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
3512
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2622
3513
|
await fse.outputFile(outfile, text);
|
|
2623
3514
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2624
3515
|
}
|
|
@@ -2627,17 +3518,17 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
|
|
|
2627
3518
|
/\/\/+/g,
|
|
2628
3519
|
"/"
|
|
2629
3520
|
);
|
|
2630
|
-
let outdir =
|
|
2631
|
-
let outfile =
|
|
2632
|
-
await fse.ensureDir(
|
|
3521
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3522
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
3523
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2633
3524
|
let manifestData = JSON.stringify(build.assets.routes);
|
|
2634
3525
|
await fse.outputFile(outfile, manifestData);
|
|
2635
3526
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2636
3527
|
}
|
|
2637
|
-
function validatePrerenderedResponse(response, html, prefix,
|
|
3528
|
+
function validatePrerenderedResponse(response, html, prefix, path7) {
|
|
2638
3529
|
if (response.status !== 200) {
|
|
2639
3530
|
throw new Error(
|
|
2640
|
-
`${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${
|
|
3531
|
+
`${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${path7}\` path.
|
|
2641
3532
|
${html}`
|
|
2642
3533
|
);
|
|
2643
3534
|
}
|
|
@@ -2672,8 +3563,6 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
|
|
|
2672
3563
|
loader: route.module.loader ? () => null : void 0,
|
|
2673
3564
|
action: void 0,
|
|
2674
3565
|
handle: route.module.handle
|
|
2675
|
-
// middleware is not necessary here since we just need to know which
|
|
2676
|
-
// routes have loaders so we know what paths to prerender
|
|
2677
3566
|
};
|
|
2678
3567
|
return route.index ? {
|
|
2679
3568
|
index: true,
|
|
@@ -2685,6 +3574,74 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
|
|
|
2685
3574
|
};
|
|
2686
3575
|
});
|
|
2687
3576
|
}
|
|
3577
|
+
var resolveRouteFileCode = async (ctx, input) => {
|
|
3578
|
+
if (typeof input === "string") return input;
|
|
3579
|
+
invariant(input.viteChildCompiler);
|
|
3580
|
+
return await compileRouteFile(
|
|
3581
|
+
input.viteChildCompiler,
|
|
3582
|
+
ctx,
|
|
3583
|
+
input.routeFile,
|
|
3584
|
+
input.readRouteFile
|
|
3585
|
+
);
|
|
3586
|
+
};
|
|
3587
|
+
async function detectRouteChunksIfEnabled(cache, ctx, id, input) {
|
|
3588
|
+
function noRouteChunks() {
|
|
3589
|
+
return {
|
|
3590
|
+
chunkedExports: [],
|
|
3591
|
+
hasRouteChunks: false,
|
|
3592
|
+
hasRouteChunkByExportName: {
|
|
3593
|
+
clientAction: false,
|
|
3594
|
+
clientLoader: false,
|
|
3595
|
+
HydrateFallback: false
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
}
|
|
3599
|
+
if (!ctx.reactRouterConfig.future.unstable_routeChunks) {
|
|
3600
|
+
return noRouteChunks();
|
|
3601
|
+
}
|
|
3602
|
+
if (normalizeRelativeFilePath(id, ctx.reactRouterConfig) === ctx.reactRouterConfig.routes.root.file) {
|
|
3603
|
+
return noRouteChunks();
|
|
3604
|
+
}
|
|
3605
|
+
let code = await resolveRouteFileCode(ctx, input);
|
|
3606
|
+
if (!routeChunkExportNames.some((exportName) => code.includes(exportName))) {
|
|
3607
|
+
return noRouteChunks();
|
|
3608
|
+
}
|
|
3609
|
+
let cacheKey = normalizeRelativeFilePath(id, ctx.reactRouterConfig) + (typeof input === "string" ? "" : "?read");
|
|
3610
|
+
return detectRouteChunks(code, cache, cacheKey);
|
|
3611
|
+
}
|
|
3612
|
+
async function getRouteChunkIfEnabled(cache, ctx, id, chunkName, input) {
|
|
3613
|
+
if (!ctx.reactRouterConfig.future.unstable_routeChunks) {
|
|
3614
|
+
return null;
|
|
3615
|
+
}
|
|
3616
|
+
let code = await resolveRouteFileCode(ctx, input);
|
|
3617
|
+
let cacheKey = normalizeRelativeFilePath(id, ctx.reactRouterConfig) + (typeof input === "string" ? "" : "?read");
|
|
3618
|
+
return getRouteChunkCode(code, chunkName, cache, cacheKey);
|
|
3619
|
+
}
|
|
3620
|
+
function validateRouteChunks({
|
|
3621
|
+
ctx,
|
|
3622
|
+
id,
|
|
3623
|
+
valid
|
|
3624
|
+
}) {
|
|
3625
|
+
let invalidChunks = Object.entries(valid).filter(([_, isValid]) => !isValid).map(([chunkName]) => chunkName);
|
|
3626
|
+
if (invalidChunks.length === 0) {
|
|
3627
|
+
return;
|
|
3628
|
+
}
|
|
3629
|
+
let plural = invalidChunks.length > 1;
|
|
3630
|
+
throw new Error(
|
|
3631
|
+
[
|
|
3632
|
+
`Route chunks error: ${normalizeRelativeFilePath(
|
|
3633
|
+
id,
|
|
3634
|
+
ctx.reactRouterConfig
|
|
3635
|
+
)}`,
|
|
3636
|
+
invalidChunks.map((name) => `- ${name}`).join("\n"),
|
|
3637
|
+
`${plural ? `These exports were` : `This export was`} unable to be split into ${plural ? "their own chunks" : "its own chunk"} because ${plural ? "they reference" : "it references"} code in the same file that is used by other route module exports.`,
|
|
3638
|
+
`If you need to share code between ${plural ? `these` : `this`} and other exports, you should extract the shared code into a separate module.`
|
|
3639
|
+
].join("\n\n")
|
|
3640
|
+
);
|
|
3641
|
+
}
|
|
3642
|
+
function isNonNullable(x) {
|
|
3643
|
+
return x != null;
|
|
3644
|
+
}
|
|
2688
3645
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2689
3646
|
0 && (module.exports = {
|
|
2690
3647
|
reactRouter
|