@react-router/dev 0.0.0-experimental-2bfe0a2f2 → 0.0.0-experimental-345f1da12
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 +255 -233
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +48 -7
- package/dist/vite.js +473 -410
- 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-345f1da12
|
|
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");
|
|
@@ -57,7 +57,8 @@ var import_picocolors3 = __toESM(require("picocolors"));
|
|
|
57
57
|
|
|
58
58
|
// typegen/index.ts
|
|
59
59
|
var import_node_fs2 = __toESM(require("fs"));
|
|
60
|
-
var
|
|
60
|
+
var import_dedent2 = __toESM(require("dedent"));
|
|
61
|
+
var Path3 = __toESM(require("pathe"));
|
|
61
62
|
var import_picocolors2 = __toESM(require("picocolors"));
|
|
62
63
|
|
|
63
64
|
// config/config.ts
|
|
@@ -70,6 +71,9 @@ var import_server = require("vite-node/server");
|
|
|
70
71
|
var import_client = require("vite-node/client");
|
|
71
72
|
var import_source_map = require("vite-node/source-map");
|
|
72
73
|
|
|
74
|
+
// vite/vite.ts
|
|
75
|
+
var import_pathe2 = __toESM(require("pathe"));
|
|
76
|
+
|
|
73
77
|
// invariant.ts
|
|
74
78
|
function invariant(value, message) {
|
|
75
79
|
if (value === false || value === null || typeof value === "undefined") {
|
|
@@ -80,20 +84,41 @@ function invariant(value, message) {
|
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
//
|
|
87
|
+
// config/is-react-router-repo.ts
|
|
88
|
+
var import_pathe = __toESM(require("pathe"));
|
|
89
|
+
function isReactRouterRepo() {
|
|
90
|
+
let serverRuntimePath = import_pathe.default.dirname(
|
|
91
|
+
require.resolve("@react-router/node/package.json")
|
|
92
|
+
);
|
|
93
|
+
let serverRuntimeParentDir = import_pathe.default.basename(
|
|
94
|
+
import_pathe.default.resolve(serverRuntimePath, "..")
|
|
95
|
+
);
|
|
96
|
+
return serverRuntimeParentDir === "packages";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// vite/vite.ts
|
|
84
100
|
var vite;
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
var viteImportSpecifier = isReactRouterRepo() ? (
|
|
102
|
+
// Support testing against different versions of Vite by ensuring that Vite
|
|
103
|
+
// is resolved from the current working directory when running within this
|
|
104
|
+
// repo. If we don't do this, Vite will always be imported relative to this
|
|
105
|
+
// file, which means that it will always resolve to Vite 6.
|
|
106
|
+
`file:///${import_pathe2.default.normalize(
|
|
107
|
+
require.resolve("vite/package.json", { paths: [process.cwd()] })
|
|
108
|
+
).replace("package.json", "dist/node/index.js")}`
|
|
109
|
+
) : "vite";
|
|
110
|
+
async function preloadVite() {
|
|
111
|
+
vite = await import(viteImportSpecifier);
|
|
87
112
|
}
|
|
88
|
-
function
|
|
89
|
-
invariant(vite, "
|
|
113
|
+
function getVite() {
|
|
114
|
+
invariant(vite, "getVite() called before preloadVite()");
|
|
90
115
|
return vite;
|
|
91
116
|
}
|
|
92
117
|
|
|
93
118
|
// vite/vite-node.ts
|
|
94
119
|
async function createContext(viteConfig = {}) {
|
|
95
|
-
await
|
|
96
|
-
const vite2 =
|
|
120
|
+
await preloadVite();
|
|
121
|
+
const vite2 = getVite();
|
|
97
122
|
const devServer = await vite2.createServer(
|
|
98
123
|
vite2.mergeConfig(
|
|
99
124
|
{
|
|
@@ -119,18 +144,18 @@ async function createContext(viteConfig = {}) {
|
|
|
119
144
|
const runner = new import_client.ViteNodeRunner({
|
|
120
145
|
root: devServer.config.root,
|
|
121
146
|
base: devServer.config.base,
|
|
122
|
-
fetchModule(
|
|
123
|
-
return server.fetchModule(
|
|
147
|
+
fetchModule(id) {
|
|
148
|
+
return server.fetchModule(id);
|
|
124
149
|
},
|
|
125
|
-
resolveId(
|
|
126
|
-
return server.resolveId(
|
|
150
|
+
resolveId(id, importer) {
|
|
151
|
+
return server.resolveId(id, importer);
|
|
127
152
|
}
|
|
128
153
|
});
|
|
129
154
|
return { devServer, server, runner };
|
|
130
155
|
}
|
|
131
156
|
|
|
132
157
|
// config/config.ts
|
|
133
|
-
var
|
|
158
|
+
var import_pathe3 = __toESM(require("pathe"));
|
|
134
159
|
var import_chokidar = __toESM(require("chokidar"));
|
|
135
160
|
var import_picocolors = __toESM(require("picocolors"));
|
|
136
161
|
var import_pick2 = __toESM(require("lodash/pick"));
|
|
@@ -184,7 +209,7 @@ function validateRouteConfig({
|
|
|
184
209
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
185
210
|
root ? `${root}` : [],
|
|
186
211
|
nested ? Object.entries(nested).map(
|
|
187
|
-
([
|
|
212
|
+
([path7, message]) => `Path: routes.${path7}
|
|
188
213
|
${message}`
|
|
189
214
|
) : []
|
|
190
215
|
].flat().join("\n\n")
|
|
@@ -195,24 +220,24 @@ ${message}`
|
|
|
195
220
|
function configRoutesToRouteManifest(appDirectory, routes, rootId = "root") {
|
|
196
221
|
let routeManifest = {};
|
|
197
222
|
function walk(route, parentId) {
|
|
198
|
-
let
|
|
223
|
+
let id = route.id || createRouteId(route.file);
|
|
199
224
|
let manifestItem = {
|
|
200
|
-
id
|
|
225
|
+
id,
|
|
201
226
|
parentId,
|
|
202
227
|
file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
|
|
203
228
|
path: route.path,
|
|
204
229
|
index: route.index,
|
|
205
230
|
caseSensitive: route.caseSensitive
|
|
206
231
|
};
|
|
207
|
-
if (routeManifest.hasOwnProperty(
|
|
232
|
+
if (routeManifest.hasOwnProperty(id)) {
|
|
208
233
|
throw new Error(
|
|
209
|
-
`Unable to define routes with duplicate route id: "${
|
|
234
|
+
`Unable to define routes with duplicate route id: "${id}"`
|
|
210
235
|
);
|
|
211
236
|
}
|
|
212
|
-
routeManifest[
|
|
237
|
+
routeManifest[id] = manifestItem;
|
|
213
238
|
if (route.children) {
|
|
214
239
|
for (let child of route.children) {
|
|
215
|
-
walk(child,
|
|
240
|
+
walk(child, id);
|
|
216
241
|
}
|
|
217
242
|
}
|
|
218
243
|
}
|
|
@@ -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,7 +437,7 @@ 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")
|
|
@@ -484,8 +509,8 @@ async function createConfigLoader({
|
|
|
484
509
|
);
|
|
485
510
|
fsWatcher.on("all", async (...args) => {
|
|
486
511
|
let [event, rawFilepath] = args;
|
|
487
|
-
let filepath =
|
|
488
|
-
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(
|
|
512
|
+
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
513
|
+
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
489
514
|
let configCodeUpdated = Boolean(
|
|
490
515
|
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
491
516
|
);
|
|
@@ -531,8 +556,8 @@ async function resolveEntryFiles({
|
|
|
531
556
|
reactRouterConfig
|
|
532
557
|
}) {
|
|
533
558
|
let { appDirectory } = reactRouterConfig;
|
|
534
|
-
let defaultsDirectory =
|
|
535
|
-
|
|
559
|
+
let defaultsDirectory = import_pathe3.default.resolve(
|
|
560
|
+
import_pathe3.default.dirname(require.resolve("@react-router/dev/package.json")),
|
|
536
561
|
"dist",
|
|
537
562
|
"config",
|
|
538
563
|
"defaults"
|
|
@@ -570,11 +595,11 @@ async function resolveEntryFiles({
|
|
|
570
595
|
}
|
|
571
596
|
entryServerFile = `entry.server.node.tsx`;
|
|
572
597
|
}
|
|
573
|
-
let entryClientFilePath = userEntryClientFile ?
|
|
574
|
-
let entryServerFilePath = userEntryServerFile ?
|
|
598
|
+
let entryClientFilePath = userEntryClientFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_pathe3.default.resolve(defaultsDirectory, entryClientFile);
|
|
599
|
+
let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
|
|
575
600
|
return { entryClientFilePath, entryServerFilePath };
|
|
576
601
|
}
|
|
577
|
-
var ssrExternals =
|
|
602
|
+
var ssrExternals = isReactRouterRepo() ? [
|
|
578
603
|
// This is only needed within this repo because these packages
|
|
579
604
|
// are linked to a directory outside of node_modules so Vite
|
|
580
605
|
// treats them as internal code by default.
|
|
@@ -587,21 +612,12 @@ var ssrExternals = isInReactRouterMonorepo() ? [
|
|
|
587
612
|
"@react-router/node",
|
|
588
613
|
"@react-router/serve"
|
|
589
614
|
] : 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
615
|
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
600
616
|
function findEntry(dir, basename2, options) {
|
|
601
617
|
for (let ext of entryExts) {
|
|
602
|
-
let file =
|
|
618
|
+
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
603
619
|
if (import_node_fs.default.existsSync(file)) {
|
|
604
|
-
return options?.absolute ?? false ? file :
|
|
620
|
+
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
605
621
|
}
|
|
606
622
|
}
|
|
607
623
|
return void 0;
|
|
@@ -609,127 +625,54 @@ function findEntry(dir, basename2, options) {
|
|
|
609
625
|
|
|
610
626
|
// typegen/generate.ts
|
|
611
627
|
var import_dedent = __toESM(require("dedent"));
|
|
612
|
-
|
|
613
|
-
var Pathe2 = __toESM(require("pathe/utils"));
|
|
614
|
-
|
|
615
|
-
// typegen/paths.ts
|
|
616
|
-
var Path2 = __toESM(require("pathe"));
|
|
617
|
-
var Pathe = __toESM(require("pathe/utils"));
|
|
618
|
-
function getTypesDir(ctx) {
|
|
619
|
-
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
620
|
-
}
|
|
621
|
-
function getTypesPath(ctx, route) {
|
|
622
|
-
return Path2.join(
|
|
623
|
-
getTypesDir(ctx),
|
|
624
|
-
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
625
|
-
Path2.dirname(route.file),
|
|
626
|
-
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
// typegen/generate.ts
|
|
631
|
-
function generate(ctx, route) {
|
|
632
|
-
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
633
|
-
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
634
|
-
const typesPath = getTypesPath(ctx, route);
|
|
635
|
-
const parents = lineage.slice(0, -1);
|
|
636
|
-
const parentTypeImports = parents.map((parent, i) => {
|
|
637
|
-
const rel = Path3.relative(
|
|
638
|
-
Path3.dirname(typesPath),
|
|
639
|
-
getTypesPath(ctx, parent)
|
|
640
|
-
);
|
|
641
|
-
const indent = i === 0 ? "" : " ".repeat(2);
|
|
642
|
-
let source = noExtension(rel);
|
|
643
|
-
if (!source.startsWith("../")) source = "./" + source;
|
|
644
|
-
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
645
|
-
}).join("\n");
|
|
628
|
+
function generate(route) {
|
|
646
629
|
return import_dedent.default`
|
|
647
630
|
// React Router generated types for route:
|
|
648
631
|
// ${route.file}
|
|
649
632
|
|
|
650
|
-
import type
|
|
651
|
-
|
|
652
|
-
${parentTypeImports}
|
|
633
|
+
import type { RouteExports, Routes } from "react-router/types";
|
|
653
634
|
|
|
654
|
-
type
|
|
635
|
+
type RouteId = "${route.id}"
|
|
636
|
+
export type Info = Routes[RouteId];
|
|
655
637
|
|
|
656
|
-
|
|
657
|
-
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
658
|
-
id: "${route.id}"
|
|
659
|
-
file: "${route.file}"
|
|
660
|
-
path: "${route.path}"
|
|
661
|
-
params: {${formatParamProperties(
|
|
662
|
-
urlpath
|
|
663
|
-
)}} & { [key: string]: string | undefined }
|
|
664
|
-
module: Module
|
|
665
|
-
loaderData: T.CreateLoaderData<Module>
|
|
666
|
-
actionData: T.CreateActionData<Module>
|
|
667
|
-
}
|
|
638
|
+
type Exports = RouteExports[RouteId];
|
|
668
639
|
|
|
669
640
|
export namespace Route {
|
|
670
|
-
export type LinkDescriptors =
|
|
671
|
-
export type LinksFunction = () => LinkDescriptors
|
|
641
|
+
export type LinkDescriptors = Exports["links"]["return"];
|
|
642
|
+
export type LinksFunction = () => LinkDescriptors;
|
|
672
643
|
|
|
673
|
-
export type MetaArgs =
|
|
674
|
-
export type MetaDescriptors =
|
|
675
|
-
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
644
|
+
export type MetaArgs = Exports["meta"]["args"];
|
|
645
|
+
export type MetaDescriptors = Exports["meta"]["return"];
|
|
646
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors;
|
|
676
647
|
|
|
677
|
-
export type HeadersArgs =
|
|
678
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
648
|
+
export type HeadersArgs = Exports["headers"]["args"];
|
|
649
|
+
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit;
|
|
679
650
|
|
|
680
|
-
export type
|
|
681
|
-
export type
|
|
682
|
-
export type
|
|
683
|
-
export type
|
|
684
|
-
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
685
|
-
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
651
|
+
export type LoaderArgs = Exports["loader"]["args"];
|
|
652
|
+
export type ClientLoaderArgs = Exports["clientLoader"]["args"];
|
|
653
|
+
export type ActionArgs = Exports["action"]["args"];
|
|
654
|
+
export type ClientActionArgs = Exports["clientAction"]["args"];
|
|
686
655
|
|
|
687
|
-
export type HydrateFallbackProps =
|
|
688
|
-
export type ComponentProps =
|
|
689
|
-
export type ErrorBoundaryProps =
|
|
656
|
+
export type HydrateFallbackProps = Exports["HydrateFallback"]["args"];
|
|
657
|
+
export type ComponentProps = Exports["default"]["args"];
|
|
658
|
+
export type ErrorBoundaryProps = Exports["ErrorBoundary"]["args"];
|
|
690
659
|
}
|
|
691
660
|
`;
|
|
692
661
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
route = routes[route.parentId];
|
|
700
|
-
}
|
|
701
|
-
result.reverse();
|
|
702
|
-
return result;
|
|
703
|
-
}
|
|
704
|
-
function formatParamProperties(urlpath) {
|
|
705
|
-
const params = parseParams(urlpath);
|
|
706
|
-
const properties = Object.entries(params).map(([name, values]) => {
|
|
707
|
-
if (values.length === 1) {
|
|
708
|
-
const isOptional = values[0];
|
|
709
|
-
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
710
|
-
}
|
|
711
|
-
const items = values.map(
|
|
712
|
-
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
713
|
-
);
|
|
714
|
-
return `"${name}": [${items.join(", ")}]`;
|
|
715
|
-
});
|
|
716
|
-
return properties.join("; ");
|
|
662
|
+
|
|
663
|
+
// typegen/paths.ts
|
|
664
|
+
var Path2 = __toESM(require("pathe"));
|
|
665
|
+
var Pathe = __toESM(require("pathe/utils"));
|
|
666
|
+
function getTypesDir(ctx) {
|
|
667
|
+
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
717
668
|
}
|
|
718
|
-
function
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const isOptional = match[2] !== void 0;
|
|
726
|
-
result[param] ??= [];
|
|
727
|
-
result[param].push(isOptional);
|
|
728
|
-
return;
|
|
729
|
-
});
|
|
730
|
-
const hasSplat = segments.at(-1) === "*";
|
|
731
|
-
if (hasSplat) result["*"] = [false];
|
|
732
|
-
return result;
|
|
669
|
+
function getTypesPath(ctx, route) {
|
|
670
|
+
return Path2.join(
|
|
671
|
+
getTypesDir(ctx),
|
|
672
|
+
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
673
|
+
Path2.dirname(route.file),
|
|
674
|
+
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
675
|
+
);
|
|
733
676
|
}
|
|
734
677
|
|
|
735
678
|
// typegen/index.ts
|
|
@@ -771,16 +714,93 @@ async function createContext2({
|
|
|
771
714
|
config
|
|
772
715
|
};
|
|
773
716
|
}
|
|
717
|
+
function asJS(path7) {
|
|
718
|
+
return path7.replace(/\.(js|ts)x?$/, ".js");
|
|
719
|
+
}
|
|
720
|
+
function formatRoute({ id, path: path7, file, parentId }) {
|
|
721
|
+
return [
|
|
722
|
+
`"${id}": {`,
|
|
723
|
+
` parentId: ${JSON.stringify(parentId)}`,
|
|
724
|
+
` path: ${JSON.stringify(path7)}`,
|
|
725
|
+
` module: typeof import("./app/${asJS(file)}")`,
|
|
726
|
+
`}`
|
|
727
|
+
].map((line) => ` ${line}`).join("\n");
|
|
728
|
+
}
|
|
774
729
|
async function writeAll(ctx) {
|
|
730
|
+
let routes = Object.values(ctx.config.routes);
|
|
731
|
+
let pathsToParams = /* @__PURE__ */ new Map();
|
|
732
|
+
for (let route of routes) {
|
|
733
|
+
if (route.path === void 0) continue;
|
|
734
|
+
let lineage = getRouteLineage(ctx.config.routes, route);
|
|
735
|
+
let path7 = lineage.filter((route2) => route2.path !== void 0).map((route2) => route2.path).join("/");
|
|
736
|
+
if (path7 === "") path7 = "/";
|
|
737
|
+
pathsToParams.set(path7, parseParams(path7));
|
|
738
|
+
}
|
|
739
|
+
let formattedPaths = `type Paths = {`;
|
|
740
|
+
for (let [path7, params] of pathsToParams.entries()) {
|
|
741
|
+
let formattedParams = Object.entries(params).map(
|
|
742
|
+
([param, required]) => `"${param}"${required ? "" : "?"}: string`
|
|
743
|
+
);
|
|
744
|
+
let formattedEntry = `"${path7}": {${formattedParams.join(",")}},
|
|
745
|
+
`;
|
|
746
|
+
formattedPaths += formattedEntry;
|
|
747
|
+
}
|
|
748
|
+
formattedPaths += `}`;
|
|
775
749
|
const typegenDir = getTypesDir(ctx);
|
|
776
750
|
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
751
|
+
const newTypes = Path3.join(typegenDir, "routes.ts");
|
|
752
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(newTypes), { recursive: true });
|
|
753
|
+
import_node_fs2.default.writeFileSync(
|
|
754
|
+
newTypes,
|
|
755
|
+
formattedPaths + `
|
|
756
|
+
|
|
757
|
+
type Routes = {
|
|
758
|
+
${routes.map(formatRoute).join("\n")}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
` + import_dedent2.default`
|
|
762
|
+
declare module "react-router/types" {
|
|
763
|
+
interface Register {
|
|
764
|
+
paths: Paths
|
|
765
|
+
routes: Routes
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export {}
|
|
770
|
+
`
|
|
771
|
+
);
|
|
777
772
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
778
773
|
const typesPath = getTypesPath(ctx, route);
|
|
779
|
-
const content = generate(
|
|
780
|
-
import_node_fs2.default.mkdirSync(
|
|
774
|
+
const content = generate(route);
|
|
775
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(typesPath), { recursive: true });
|
|
781
776
|
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
782
777
|
});
|
|
783
778
|
}
|
|
779
|
+
function getRouteLineage(routes, route) {
|
|
780
|
+
const result = [];
|
|
781
|
+
while (route) {
|
|
782
|
+
result.push(route);
|
|
783
|
+
if (!route.parentId) break;
|
|
784
|
+
route = routes[route.parentId];
|
|
785
|
+
}
|
|
786
|
+
result.reverse();
|
|
787
|
+
return result;
|
|
788
|
+
}
|
|
789
|
+
function parseParams(urlpath) {
|
|
790
|
+
const result = {};
|
|
791
|
+
let segments = urlpath.split("/");
|
|
792
|
+
segments.forEach((segment) => {
|
|
793
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
794
|
+
if (!match) return;
|
|
795
|
+
const param = match[1];
|
|
796
|
+
const isRequired = match[2] === void 0;
|
|
797
|
+
result[param] ||= isRequired;
|
|
798
|
+
return;
|
|
799
|
+
});
|
|
800
|
+
const hasSplat = segments.at(-1) === "*";
|
|
801
|
+
if (hasSplat) result["*"] = true;
|
|
802
|
+
return result;
|
|
803
|
+
}
|
|
784
804
|
|
|
785
805
|
// vite/babel.ts
|
|
786
806
|
var import_parser = require("@babel/parser");
|
|
@@ -814,7 +834,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
814
834
|
nodeReq.originalUrl,
|
|
815
835
|
"Expected `nodeReq.originalUrl` to be defined"
|
|
816
836
|
);
|
|
817
|
-
let
|
|
837
|
+
let url2 = new URL(nodeReq.originalUrl, origin);
|
|
818
838
|
let controller = new AbortController();
|
|
819
839
|
let init = {
|
|
820
840
|
method: nodeReq.method,
|
|
@@ -827,7 +847,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
827
847
|
init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
|
|
828
848
|
init.duplex = "half";
|
|
829
849
|
}
|
|
830
|
-
return new Request(
|
|
850
|
+
return new Request(url2.href, init);
|
|
831
851
|
}
|
|
832
852
|
async function toNodeRequest(res, nodeRes) {
|
|
833
853
|
nodeRes.statusCode = res.status;
|
|
@@ -852,17 +872,17 @@ async function toNodeRequest(res, nodeRes) {
|
|
|
852
872
|
}
|
|
853
873
|
|
|
854
874
|
// vite/styles.ts
|
|
855
|
-
var
|
|
875
|
+
var path5 = __toESM(require("path"));
|
|
856
876
|
var import_react_router = require("react-router");
|
|
857
877
|
|
|
858
878
|
// vite/resolve-file-url.ts
|
|
859
|
-
var
|
|
879
|
+
var path4 = __toESM(require("path"));
|
|
860
880
|
var resolveFileUrl = ({ rootDirectory }, filePath) => {
|
|
861
|
-
let vite2 =
|
|
862
|
-
let relativePath =
|
|
863
|
-
let isWithinRoot = !relativePath.startsWith("..") && !
|
|
881
|
+
let vite2 = getVite();
|
|
882
|
+
let relativePath = path4.relative(rootDirectory, filePath);
|
|
883
|
+
let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
|
|
864
884
|
if (!isWithinRoot) {
|
|
865
|
-
return
|
|
885
|
+
return path4.posix.join("/@fs", vite2.normalizePath(filePath));
|
|
866
886
|
}
|
|
867
887
|
return "/" + vite2.normalizePath(relativePath);
|
|
868
888
|
};
|
|
@@ -873,8 +893,8 @@ var cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
|
873
893
|
var isCssFile = (file) => cssFileRegExp.test(file);
|
|
874
894
|
var isCssModulesFile = (file) => cssModulesRegExp.test(file);
|
|
875
895
|
var cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
|
|
876
|
-
var isCssUrlWithoutSideEffects = (
|
|
877
|
-
let queryString =
|
|
896
|
+
var isCssUrlWithoutSideEffects = (url2) => {
|
|
897
|
+
let queryString = url2.split("?")[1];
|
|
878
898
|
if (!queryString) {
|
|
879
899
|
return false;
|
|
880
900
|
}
|
|
@@ -882,24 +902,27 @@ var isCssUrlWithoutSideEffects = (url3) => {
|
|
|
882
902
|
for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
|
|
883
903
|
if (
|
|
884
904
|
// Parameter is blank and not explicitly set, i.e. "?url", not "?url="
|
|
885
|
-
params.get(paramWithoutSideEffects) === "" && !
|
|
905
|
+
params.get(paramWithoutSideEffects) === "" && !url2.includes(`?${paramWithoutSideEffects}=`) && !url2.includes(`&${paramWithoutSideEffects}=`)
|
|
886
906
|
) {
|
|
887
907
|
return true;
|
|
888
908
|
}
|
|
889
909
|
}
|
|
890
910
|
return false;
|
|
891
911
|
};
|
|
912
|
+
var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
|
|
892
913
|
var getStylesForFiles = async ({
|
|
893
914
|
viteDevServer,
|
|
894
915
|
rootDirectory,
|
|
895
916
|
cssModulesManifest,
|
|
896
917
|
files
|
|
897
918
|
}) => {
|
|
919
|
+
let vite2 = getVite();
|
|
920
|
+
let viteMajor = parseInt(vite2.version.split(".")[0], 10);
|
|
898
921
|
let styles = {};
|
|
899
922
|
let deps = /* @__PURE__ */ new Set();
|
|
900
923
|
try {
|
|
901
924
|
for (let file of files) {
|
|
902
|
-
let normalizedPath =
|
|
925
|
+
let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
|
|
903
926
|
let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
904
927
|
if (!node) {
|
|
905
928
|
try {
|
|
@@ -923,7 +946,15 @@ var getStylesForFiles = async ({
|
|
|
923
946
|
for (let dep of deps) {
|
|
924
947
|
if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url)) {
|
|
925
948
|
try {
|
|
926
|
-
let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(
|
|
949
|
+
let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(
|
|
950
|
+
// We need the ?inline query in Vite v6 when loading CSS in SSR
|
|
951
|
+
// since it does not expose the default export for CSS in a
|
|
952
|
+
// server environment. This is to align with non-SSR
|
|
953
|
+
// environments. For backwards compatibility with v5 we keep
|
|
954
|
+
// using the URL without ?inline query because the HMR code was
|
|
955
|
+
// relying on the implicit SSR-client module graph relationship.
|
|
956
|
+
viteMajor >= 6 ? injectQuery(dep.url, "inline") : dep.url
|
|
957
|
+
)).default;
|
|
927
958
|
if (css === void 0) {
|
|
928
959
|
throw new Error();
|
|
929
960
|
}
|
|
@@ -947,8 +978,8 @@ var findDeps = async (vite2, node, deps) => {
|
|
|
947
978
|
await findDeps(vite2, node2, deps);
|
|
948
979
|
}
|
|
949
980
|
}
|
|
950
|
-
async function addFromUrl(
|
|
951
|
-
let node2 = await vite2.moduleGraph.getModuleByUrl(
|
|
981
|
+
async function addFromUrl(url2) {
|
|
982
|
+
let node2 = await vite2.moduleGraph.getModuleByUrl(url2);
|
|
952
983
|
if (node2) {
|
|
953
984
|
await addFromNode(node2);
|
|
954
985
|
}
|
|
@@ -956,7 +987,7 @@ var findDeps = async (vite2, node, deps) => {
|
|
|
956
987
|
if (node.ssrTransformResult) {
|
|
957
988
|
if (node.ssrTransformResult.deps) {
|
|
958
989
|
node.ssrTransformResult.deps.forEach(
|
|
959
|
-
(
|
|
990
|
+
(url2) => branches.push(addFromUrl(url2))
|
|
960
991
|
);
|
|
961
992
|
}
|
|
962
993
|
} else {
|
|
@@ -990,15 +1021,15 @@ var getStylesForUrl = async ({
|
|
|
990
1021
|
entryClientFilePath,
|
|
991
1022
|
cssModulesManifest,
|
|
992
1023
|
build,
|
|
993
|
-
url:
|
|
1024
|
+
url: url2
|
|
994
1025
|
}) => {
|
|
995
|
-
if (
|
|
1026
|
+
if (url2 === void 0 || url2.includes("?_data=")) {
|
|
996
1027
|
return void 0;
|
|
997
1028
|
}
|
|
998
1029
|
let routes = createRoutes(build.routes);
|
|
999
|
-
let appPath =
|
|
1000
|
-
let documentRouteFiles = (0, import_react_router.matchRoutes)(routes,
|
|
1001
|
-
(match) =>
|
|
1030
|
+
let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
|
|
1031
|
+
let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url2, build.basename)?.map(
|
|
1032
|
+
(match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
|
|
1002
1033
|
) ?? [];
|
|
1003
1034
|
let styles = await getStylesForFiles({
|
|
1004
1035
|
viteDevServer,
|
|
@@ -1006,7 +1037,7 @@ var getStylesForUrl = async ({
|
|
|
1006
1037
|
cssModulesManifest,
|
|
1007
1038
|
files: [
|
|
1008
1039
|
// Always include the client entry file when crawling the module graph for CSS
|
|
1009
|
-
|
|
1040
|
+
path5.relative(rootDirectory, entryClientFilePath),
|
|
1010
1041
|
// Then include any styles from the matched routes
|
|
1011
1042
|
...documentRouteFiles
|
|
1012
1043
|
]
|
|
@@ -1014,10 +1045,15 @@ var getStylesForUrl = async ({
|
|
|
1014
1045
|
return styles;
|
|
1015
1046
|
};
|
|
1016
1047
|
|
|
1017
|
-
// vite/
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1048
|
+
// vite/virtual-module.ts
|
|
1049
|
+
function create(name) {
|
|
1050
|
+
let id = `virtual:react-router/${name}`;
|
|
1051
|
+
return {
|
|
1052
|
+
id,
|
|
1053
|
+
resolvedId: `\0${id}`,
|
|
1054
|
+
url: `/@id/__x00__${id}`
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1021
1057
|
|
|
1022
1058
|
// vite/combine-urls.ts
|
|
1023
1059
|
function combineURLs(baseURL, relativeURL) {
|
|
@@ -1031,10 +1067,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1031
1067
|
let exportsFiltered = false;
|
|
1032
1068
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1033
1069
|
traverse(ast, {
|
|
1034
|
-
ExportDeclaration(
|
|
1035
|
-
if (
|
|
1036
|
-
if (
|
|
1037
|
-
|
|
1070
|
+
ExportDeclaration(path7) {
|
|
1071
|
+
if (path7.node.type === "ExportNamedDeclaration") {
|
|
1072
|
+
if (path7.node.specifiers.length) {
|
|
1073
|
+
path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
|
|
1038
1074
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1039
1075
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1040
1076
|
exportsFiltered = true;
|
|
@@ -1043,12 +1079,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1043
1079
|
}
|
|
1044
1080
|
return true;
|
|
1045
1081
|
});
|
|
1046
|
-
if (
|
|
1047
|
-
markedForRemoval.add(
|
|
1082
|
+
if (path7.node.specifiers.length === 0) {
|
|
1083
|
+
markedForRemoval.add(path7);
|
|
1048
1084
|
}
|
|
1049
1085
|
}
|
|
1050
|
-
if (
|
|
1051
|
-
let declaration =
|
|
1086
|
+
if (path7.node.declaration?.type === "VariableDeclaration") {
|
|
1087
|
+
let declaration = path7.node.declaration;
|
|
1052
1088
|
declaration.declarations = declaration.declarations.filter(
|
|
1053
1089
|
(declaration2) => {
|
|
1054
1090
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1062,37 +1098,37 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1062
1098
|
}
|
|
1063
1099
|
);
|
|
1064
1100
|
if (declaration.declarations.length === 0) {
|
|
1065
|
-
markedForRemoval.add(
|
|
1101
|
+
markedForRemoval.add(path7);
|
|
1066
1102
|
}
|
|
1067
1103
|
}
|
|
1068
|
-
if (
|
|
1069
|
-
let
|
|
1070
|
-
if (
|
|
1071
|
-
markedForRemoval.add(
|
|
1104
|
+
if (path7.node.declaration?.type === "FunctionDeclaration") {
|
|
1105
|
+
let id = path7.node.declaration.id;
|
|
1106
|
+
if (id && exportsToRemove.includes(id.name)) {
|
|
1107
|
+
markedForRemoval.add(path7);
|
|
1072
1108
|
}
|
|
1073
1109
|
}
|
|
1074
|
-
if (
|
|
1075
|
-
let
|
|
1076
|
-
if (
|
|
1077
|
-
markedForRemoval.add(
|
|
1110
|
+
if (path7.node.declaration?.type === "ClassDeclaration") {
|
|
1111
|
+
let id = path7.node.declaration.id;
|
|
1112
|
+
if (id && exportsToRemove.includes(id.name)) {
|
|
1113
|
+
markedForRemoval.add(path7);
|
|
1078
1114
|
}
|
|
1079
1115
|
}
|
|
1080
1116
|
}
|
|
1081
|
-
if (
|
|
1082
|
-
markedForRemoval.add(
|
|
1117
|
+
if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
1118
|
+
markedForRemoval.add(path7);
|
|
1083
1119
|
}
|
|
1084
1120
|
}
|
|
1085
1121
|
});
|
|
1086
1122
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1087
|
-
for (let
|
|
1088
|
-
|
|
1123
|
+
for (let path7 of markedForRemoval) {
|
|
1124
|
+
path7.remove();
|
|
1089
1125
|
}
|
|
1090
1126
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1091
1127
|
}
|
|
1092
1128
|
};
|
|
1093
|
-
function validateDestructuredExports(
|
|
1094
|
-
if (
|
|
1095
|
-
for (let element of
|
|
1129
|
+
function validateDestructuredExports(id, exportsToRemove) {
|
|
1130
|
+
if (id.type === "ArrayPattern") {
|
|
1131
|
+
for (let element of id.elements) {
|
|
1096
1132
|
if (!element) {
|
|
1097
1133
|
continue;
|
|
1098
1134
|
}
|
|
@@ -1107,8 +1143,8 @@ function validateDestructuredExports(id2, exportsToRemove) {
|
|
|
1107
1143
|
}
|
|
1108
1144
|
}
|
|
1109
1145
|
}
|
|
1110
|
-
if (
|
|
1111
|
-
for (let property of
|
|
1146
|
+
if (id.type === "ObjectPattern") {
|
|
1147
|
+
for (let property of id.properties) {
|
|
1112
1148
|
if (!property) {
|
|
1113
1149
|
continue;
|
|
1114
1150
|
}
|
|
@@ -1131,18 +1167,18 @@ function invalidDestructureError(name) {
|
|
|
1131
1167
|
}
|
|
1132
1168
|
|
|
1133
1169
|
// vite/with-props.ts
|
|
1134
|
-
var
|
|
1135
|
-
var
|
|
1170
|
+
var import_dedent3 = __toESM(require("dedent"));
|
|
1171
|
+
var vmod = create("with-props");
|
|
1136
1172
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
1137
1173
|
var plugin = {
|
|
1138
1174
|
name: "react-router-with-props",
|
|
1139
1175
|
enforce: "pre",
|
|
1140
|
-
resolveId(
|
|
1141
|
-
if (
|
|
1176
|
+
resolveId(id) {
|
|
1177
|
+
if (id === vmod.id) return vmod.resolvedId;
|
|
1142
1178
|
},
|
|
1143
|
-
async load(
|
|
1144
|
-
if (
|
|
1145
|
-
return
|
|
1179
|
+
async load(id) {
|
|
1180
|
+
if (id !== vmod.resolvedId) return;
|
|
1181
|
+
return import_dedent3.default`
|
|
1146
1182
|
import { createElement as h } from "react";
|
|
1147
1183
|
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
1148
1184
|
|
|
@@ -1183,44 +1219,44 @@ var plugin = {
|
|
|
1183
1219
|
};
|
|
1184
1220
|
var transform = (ast) => {
|
|
1185
1221
|
const hocs = [];
|
|
1186
|
-
function getHocUid(
|
|
1187
|
-
const uid =
|
|
1222
|
+
function getHocUid(path7, hocName) {
|
|
1223
|
+
const uid = path7.scope.generateUidIdentifier(hocName);
|
|
1188
1224
|
hocs.push([hocName, uid]);
|
|
1189
1225
|
return uid;
|
|
1190
1226
|
}
|
|
1191
1227
|
traverse(ast, {
|
|
1192
|
-
ExportDeclaration(
|
|
1193
|
-
if (
|
|
1194
|
-
const declaration =
|
|
1228
|
+
ExportDeclaration(path7) {
|
|
1229
|
+
if (path7.isExportDefaultDeclaration()) {
|
|
1230
|
+
const declaration = path7.get("declaration");
|
|
1195
1231
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
1196
1232
|
if (expr) {
|
|
1197
|
-
const uid = getHocUid(
|
|
1233
|
+
const uid = getHocUid(path7, "withComponentProps");
|
|
1198
1234
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
1199
1235
|
}
|
|
1200
1236
|
return;
|
|
1201
1237
|
}
|
|
1202
|
-
if (
|
|
1203
|
-
const decl =
|
|
1238
|
+
if (path7.isExportNamedDeclaration()) {
|
|
1239
|
+
const decl = path7.get("declaration");
|
|
1204
1240
|
if (decl.isVariableDeclaration()) {
|
|
1205
1241
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
1206
|
-
const
|
|
1242
|
+
const id = varDeclarator.get("id");
|
|
1207
1243
|
const init = varDeclarator.get("init");
|
|
1208
1244
|
const expr = init.node;
|
|
1209
1245
|
if (!expr) return;
|
|
1210
|
-
if (!
|
|
1211
|
-
const { name } =
|
|
1246
|
+
if (!id.isIdentifier()) return;
|
|
1247
|
+
const { name } = id.node;
|
|
1212
1248
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
1213
|
-
const uid = getHocUid(
|
|
1249
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
1214
1250
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
1215
1251
|
});
|
|
1216
1252
|
return;
|
|
1217
1253
|
}
|
|
1218
1254
|
if (decl.isFunctionDeclaration()) {
|
|
1219
|
-
const { id
|
|
1220
|
-
if (!
|
|
1221
|
-
const { name } =
|
|
1255
|
+
const { id } = decl.node;
|
|
1256
|
+
if (!id) return;
|
|
1257
|
+
const { name } = id;
|
|
1222
1258
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
1223
|
-
const uid = getHocUid(
|
|
1259
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
1224
1260
|
decl.replaceWith(
|
|
1225
1261
|
t.variableDeclaration("const", [
|
|
1226
1262
|
t.variableDeclarator(
|
|
@@ -1239,7 +1275,7 @@ var transform = (ast) => {
|
|
|
1239
1275
|
hocs.map(
|
|
1240
1276
|
([name, identifier]) => t.importSpecifier(identifier, t.identifier(name))
|
|
1241
1277
|
),
|
|
1242
|
-
t.stringLiteral(
|
|
1278
|
+
t.stringLiteral(vmod.id)
|
|
1243
1279
|
)
|
|
1244
1280
|
);
|
|
1245
1281
|
}
|
|
@@ -1255,11 +1291,10 @@ function toFunctionExpression(decl) {
|
|
|
1255
1291
|
}
|
|
1256
1292
|
|
|
1257
1293
|
// vite/plugin.ts
|
|
1258
|
-
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "
|
|
1294
|
+
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "headers"];
|
|
1259
1295
|
var CLIENT_ROUTE_EXPORTS = [
|
|
1260
1296
|
"clientAction",
|
|
1261
1297
|
"clientLoader",
|
|
1262
|
-
"clientMiddleware",
|
|
1263
1298
|
"default",
|
|
1264
1299
|
"ErrorBoundary",
|
|
1265
1300
|
"handle",
|
|
@@ -1269,27 +1304,23 @@ var CLIENT_ROUTE_EXPORTS = [
|
|
|
1269
1304
|
"meta",
|
|
1270
1305
|
"shouldRevalidate"
|
|
1271
1306
|
];
|
|
1272
|
-
var
|
|
1273
|
-
var
|
|
1274
|
-
|
|
1275
|
-
};
|
|
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");
|
|
1307
|
+
var BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
|
|
1308
|
+
var virtualHmrRuntime = create("hmr-runtime");
|
|
1309
|
+
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
1281
1310
|
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
1282
|
-
let vite2 =
|
|
1311
|
+
let vite2 = getVite();
|
|
1283
1312
|
let file = route.file;
|
|
1284
|
-
let fullPath =
|
|
1313
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
1285
1314
|
return vite2.normalizePath(fullPath);
|
|
1286
1315
|
};
|
|
1287
|
-
var
|
|
1316
|
+
var virtual = {
|
|
1317
|
+
serverBuild: create("server-build"),
|
|
1318
|
+
serverManifest: create("server-manifest"),
|
|
1319
|
+
browserManifest: create("browser-manifest")
|
|
1320
|
+
};
|
|
1288
1321
|
var invalidateVirtualModules = (viteDevServer) => {
|
|
1289
|
-
|
|
1290
|
-
let mod = viteDevServer.moduleGraph.getModuleById(
|
|
1291
|
-
resolve3(vmod)
|
|
1292
|
-
);
|
|
1322
|
+
Object.values(virtual).forEach((vmod2) => {
|
|
1323
|
+
let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
|
|
1293
1324
|
if (mod) {
|
|
1294
1325
|
viteDevServer.moduleGraph.invalidateModule(mod);
|
|
1295
1326
|
}
|
|
@@ -1300,11 +1331,11 @@ var getHash = (source, maxLength) => {
|
|
|
1300
1331
|
return typeof maxLength === "number" ? hash.slice(0, maxLength) : hash;
|
|
1301
1332
|
};
|
|
1302
1333
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
1303
|
-
let vite2 =
|
|
1334
|
+
let vite2 = getVite();
|
|
1304
1335
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
1305
|
-
|
|
1336
|
+
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
1306
1337
|
);
|
|
1307
|
-
let entryChunk = viteManifest[rootRelativeFilePath +
|
|
1338
|
+
let entryChunk = viteManifest[rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
|
|
1308
1339
|
if (!entryChunk) {
|
|
1309
1340
|
let knownManifestKeys = Object.keys(viteManifest).map((key) => '"' + key + '"').join(", ");
|
|
1310
1341
|
throw new Error(
|
|
@@ -1354,7 +1385,7 @@ function dedupe(array2) {
|
|
|
1354
1385
|
return [...new Set(array2)];
|
|
1355
1386
|
}
|
|
1356
1387
|
var writeFileSafe = async (file, contents) => {
|
|
1357
|
-
await fse.ensureDir(
|
|
1388
|
+
await fse.ensureDir(path6.dirname(file));
|
|
1358
1389
|
await fse.writeFile(file, contents);
|
|
1359
1390
|
};
|
|
1360
1391
|
var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
|
|
@@ -1376,20 +1407,20 @@ var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteF
|
|
|
1376
1407
|
}
|
|
1377
1408
|
let ssr = true;
|
|
1378
1409
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
1379
|
-
let routePath =
|
|
1380
|
-
let
|
|
1410
|
+
let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
1411
|
+
let url2 = resolveFileUrl(ctx, routePath);
|
|
1381
1412
|
let resolveId = async () => {
|
|
1382
|
-
let result = await pluginContainer.resolveId(
|
|
1383
|
-
if (!result) throw new Error(`Could not resolve module ID for ${
|
|
1413
|
+
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
1414
|
+
if (!result) throw new Error(`Could not resolve module ID for ${url2}`);
|
|
1384
1415
|
return result.id;
|
|
1385
1416
|
};
|
|
1386
|
-
let [
|
|
1417
|
+
let [id, code] = await Promise.all([
|
|
1387
1418
|
resolveId(),
|
|
1388
1419
|
readRouteFile?.() ?? fse.readFile(routePath, "utf-8"),
|
|
1389
1420
|
// pluginContainer.transform(...) fails if we don't do this first:
|
|
1390
|
-
moduleGraph.ensureEntryFromUrl(
|
|
1421
|
+
moduleGraph.ensureEntryFromUrl(url2, ssr)
|
|
1391
1422
|
]);
|
|
1392
|
-
let transformed = await pluginContainer.transform(code,
|
|
1423
|
+
let transformed = await pluginContainer.transform(code, id, { ssr });
|
|
1393
1424
|
let [, exports2] = (0, import_es_module_lexer.parse)(transformed.code);
|
|
1394
1425
|
let exportNames = exports2.map((e) => e.n);
|
|
1395
1426
|
return exportNames;
|
|
@@ -1400,19 +1431,19 @@ var getServerBundleBuildConfig = (viteUserConfig) => {
|
|
|
1400
1431
|
}
|
|
1401
1432
|
return viteUserConfig.__reactRouterServerBundleBuildConfig;
|
|
1402
1433
|
};
|
|
1403
|
-
var getServerBuildDirectory = (ctx) =>
|
|
1434
|
+
var getServerBuildDirectory = (ctx) => path6.join(
|
|
1404
1435
|
ctx.reactRouterConfig.buildDirectory,
|
|
1405
1436
|
"server",
|
|
1406
1437
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
1407
1438
|
);
|
|
1408
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
1409
|
-
var defaultEntriesDir =
|
|
1410
|
-
|
|
1439
|
+
var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
|
|
1440
|
+
var defaultEntriesDir = path6.resolve(
|
|
1441
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1411
1442
|
"dist",
|
|
1412
1443
|
"config",
|
|
1413
1444
|
"defaults"
|
|
1414
1445
|
);
|
|
1415
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
1446
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path6.join(defaultEntriesDir, filename2));
|
|
1416
1447
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1417
1448
|
var reactRouterDevLoadContext = () => ({});
|
|
1418
1449
|
var reactRouterVitePlugin = () => {
|
|
@@ -1494,12 +1525,14 @@ var reactRouterVitePlugin = () => {
|
|
|
1494
1525
|
resolveFileUrl(
|
|
1495
1526
|
ctx,
|
|
1496
1527
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
1497
|
-
)
|
|
1528
|
+
)
|
|
1498
1529
|
)};`;
|
|
1499
1530
|
}).join("\n")}
|
|
1500
|
-
export { default as assets } from ${JSON.stringify(
|
|
1531
|
+
export { default as assets } from ${JSON.stringify(
|
|
1532
|
+
virtual.serverManifest.id
|
|
1533
|
+
)};
|
|
1501
1534
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
1502
|
-
|
|
1535
|
+
path6.relative(
|
|
1503
1536
|
ctx.rootDirectory,
|
|
1504
1537
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
1505
1538
|
)
|
|
@@ -1525,7 +1558,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1525
1558
|
};
|
|
1526
1559
|
let loadViteManifest = async (directory) => {
|
|
1527
1560
|
let manifestContents = await fse.readFile(
|
|
1528
|
-
|
|
1561
|
+
path6.resolve(directory, ".vite", "manifest.json"),
|
|
1529
1562
|
"utf-8"
|
|
1530
1563
|
);
|
|
1531
1564
|
return JSON.parse(manifestContents);
|
|
@@ -1561,7 +1594,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1561
1594
|
ctx
|
|
1562
1595
|
);
|
|
1563
1596
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
1564
|
-
let routeFilePath =
|
|
1597
|
+
let routeFilePath = path6.join(
|
|
1565
1598
|
ctx.reactRouterConfig.appDirectory,
|
|
1566
1599
|
route.file
|
|
1567
1600
|
);
|
|
@@ -1596,18 +1629,18 @@ var reactRouterVitePlugin = () => {
|
|
|
1596
1629
|
}
|
|
1597
1630
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
1598
1631
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
1599
|
-
let manifestPath =
|
|
1632
|
+
let manifestPath = path6.posix.join(
|
|
1600
1633
|
viteConfig.build.assetsDir,
|
|
1601
1634
|
`manifest-${version}.js`
|
|
1602
1635
|
);
|
|
1603
|
-
let
|
|
1604
|
-
let nonFingerprintedValues = { url:
|
|
1636
|
+
let url2 = `${ctx.publicPath}${manifestPath}`;
|
|
1637
|
+
let nonFingerprintedValues = { url: url2, version };
|
|
1605
1638
|
let reactRouterBrowserManifest = {
|
|
1606
1639
|
...fingerprintedValues,
|
|
1607
1640
|
...nonFingerprintedValues
|
|
1608
1641
|
};
|
|
1609
1642
|
await writeFileSafe(
|
|
1610
|
-
|
|
1643
|
+
path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
1611
1644
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
1612
1645
|
reactRouterBrowserManifest
|
|
1613
1646
|
)};`
|
|
@@ -1637,10 +1670,10 @@ var reactRouterVitePlugin = () => {
|
|
|
1637
1670
|
caseSensitive: route.caseSensitive,
|
|
1638
1671
|
module: combineURLs(
|
|
1639
1672
|
ctx.publicPath,
|
|
1640
|
-
|
|
1673
|
+
resolveFileUrl(
|
|
1641
1674
|
ctx,
|
|
1642
1675
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
1643
|
-
)
|
|
1676
|
+
)
|
|
1644
1677
|
),
|
|
1645
1678
|
hasAction: sourceExports.includes("action"),
|
|
1646
1679
|
hasLoader: sourceExports.includes("loader"),
|
|
@@ -1652,12 +1685,9 @@ var reactRouterVitePlugin = () => {
|
|
|
1652
1685
|
}
|
|
1653
1686
|
return {
|
|
1654
1687
|
version: String(Math.random()),
|
|
1655
|
-
url: combineURLs(ctx.publicPath, url
|
|
1688
|
+
url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
|
|
1656
1689
|
hmr: {
|
|
1657
|
-
runtime: combineURLs(
|
|
1658
|
-
ctx.publicPath,
|
|
1659
|
-
url(injectHmrRuntimeId)
|
|
1660
|
-
)
|
|
1690
|
+
runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
|
|
1661
1691
|
},
|
|
1662
1692
|
entry: {
|
|
1663
1693
|
module: combineURLs(
|
|
@@ -1673,11 +1703,17 @@ var reactRouterVitePlugin = () => {
|
|
|
1673
1703
|
{
|
|
1674
1704
|
name: "react-router",
|
|
1675
1705
|
config: async (_viteUserConfig, _viteConfigEnv) => {
|
|
1676
|
-
await
|
|
1677
|
-
let vite2 =
|
|
1706
|
+
await preloadVite();
|
|
1707
|
+
let vite2 = getVite();
|
|
1678
1708
|
viteUserConfig = _viteUserConfig;
|
|
1679
1709
|
viteConfigEnv = _viteConfigEnv;
|
|
1680
1710
|
viteCommand = viteConfigEnv.command;
|
|
1711
|
+
let viteClientConditions = [
|
|
1712
|
+
...vite2.defaultClientConditions ?? []
|
|
1713
|
+
];
|
|
1714
|
+
let viteServerConditions = [
|
|
1715
|
+
...vite2.defaultServerConditions ?? []
|
|
1716
|
+
];
|
|
1681
1717
|
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
1682
1718
|
prefix: "[react-router]"
|
|
1683
1719
|
});
|
|
@@ -1727,15 +1763,15 @@ var reactRouterVitePlugin = () => {
|
|
|
1727
1763
|
ssr: {
|
|
1728
1764
|
external: ssrExternals,
|
|
1729
1765
|
resolve: {
|
|
1730
|
-
conditions: viteCommand === "build" ?
|
|
1731
|
-
externalConditions: viteCommand === "build" ?
|
|
1766
|
+
conditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions],
|
|
1767
|
+
externalConditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions]
|
|
1732
1768
|
}
|
|
1733
1769
|
},
|
|
1734
1770
|
optimizeDeps: {
|
|
1735
1771
|
entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
|
|
1736
1772
|
ctx.entryClientFilePath,
|
|
1737
1773
|
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1738
|
-
(route) =>
|
|
1774
|
+
(route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
|
|
1739
1775
|
)
|
|
1740
1776
|
] : [],
|
|
1741
1777
|
include: [
|
|
@@ -1769,7 +1805,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1769
1805
|
"react-router/dom",
|
|
1770
1806
|
"react-router-dom"
|
|
1771
1807
|
],
|
|
1772
|
-
conditions: viteCommand === "build" ?
|
|
1808
|
+
conditions: viteCommand === "build" ? viteClientConditions : ["development", ...viteClientConditions]
|
|
1773
1809
|
},
|
|
1774
1810
|
base: viteUserConfig.base,
|
|
1775
1811
|
// When consumer provides an allow list for files that can be read by
|
|
@@ -1791,10 +1827,10 @@ var reactRouterVitePlugin = () => {
|
|
|
1791
1827
|
input: [
|
|
1792
1828
|
ctx.entryClientFilePath,
|
|
1793
1829
|
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1794
|
-
(route) => `${
|
|
1830
|
+
(route) => `${path6.resolve(
|
|
1795
1831
|
ctx.reactRouterConfig.appDirectory,
|
|
1796
1832
|
route.file
|
|
1797
|
-
)}${
|
|
1833
|
+
)}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
|
|
1798
1834
|
)
|
|
1799
1835
|
]
|
|
1800
1836
|
}
|
|
@@ -1813,7 +1849,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1813
1849
|
rollupOptions: {
|
|
1814
1850
|
...baseRollupOptions,
|
|
1815
1851
|
preserveEntrySignatures: "exports-only",
|
|
1816
|
-
input: viteUserConfig.build?.rollupOptions?.input ??
|
|
1852
|
+
input: viteUserConfig.build?.rollupOptions?.input ?? virtual.serverBuild.id,
|
|
1817
1853
|
output: {
|
|
1818
1854
|
entryFileNames: ctx.reactRouterConfig.serverBuildFile,
|
|
1819
1855
|
format: ctx.reactRouterConfig.serverModuleFormat
|
|
@@ -1840,7 +1876,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1840
1876
|
"The React Router Vite plugin requires the use of a Vite config file"
|
|
1841
1877
|
);
|
|
1842
1878
|
}
|
|
1843
|
-
let vite2 =
|
|
1879
|
+
let vite2 = getVite();
|
|
1844
1880
|
let childCompilerConfigFile = await vite2.loadConfigFromFile(
|
|
1845
1881
|
{
|
|
1846
1882
|
command: viteConfig.command,
|
|
@@ -1876,15 +1912,15 @@ var reactRouterVitePlugin = () => {
|
|
|
1876
1912
|
envFile: false,
|
|
1877
1913
|
plugins: [
|
|
1878
1914
|
...(childCompilerConfigFile.config.plugins ?? []).flat().filter(
|
|
1879
|
-
(plugin2) => typeof plugin2 === "object" && plugin2 !== null && "name" in plugin2 && plugin2.name !== "react-router" && plugin2.name !== "react-router
|
|
1915
|
+
(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
1916
|
)
|
|
1881
1917
|
]
|
|
1882
1918
|
});
|
|
1883
1919
|
await viteChildCompiler.pluginContainer.buildStart({});
|
|
1884
1920
|
},
|
|
1885
|
-
async transform(code,
|
|
1886
|
-
if (isCssModulesFile(
|
|
1887
|
-
cssModulesManifest[
|
|
1921
|
+
async transform(code, id) {
|
|
1922
|
+
if (isCssModulesFile(id)) {
|
|
1923
|
+
cssModulesManifest[id] = code;
|
|
1888
1924
|
}
|
|
1889
1925
|
},
|
|
1890
1926
|
buildStart() {
|
|
@@ -1908,7 +1944,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1908
1944
|
(0, import_react_router2.unstable_setDevServerHooks)({
|
|
1909
1945
|
// Give the request handler access to the critical CSS in dev to avoid a
|
|
1910
1946
|
// flash of unstyled content since Vite injects CSS file contents via JS
|
|
1911
|
-
getCriticalCss: async (build,
|
|
1947
|
+
getCriticalCss: async (build, url2) => {
|
|
1912
1948
|
return getStylesForUrl({
|
|
1913
1949
|
rootDirectory: ctx.rootDirectory,
|
|
1914
1950
|
entryClientFilePath: ctx.entryClientFilePath,
|
|
@@ -1916,7 +1952,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1916
1952
|
viteDevServer,
|
|
1917
1953
|
cssModulesManifest,
|
|
1918
1954
|
build,
|
|
1919
|
-
url:
|
|
1955
|
+
url: url2
|
|
1920
1956
|
});
|
|
1921
1957
|
},
|
|
1922
1958
|
// If an error is caught within the request handler, let Vite fix the
|
|
@@ -1964,7 +2000,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1964
2000
|
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
1965
2001
|
try {
|
|
1966
2002
|
let build = await viteDevServer.ssrLoadModule(
|
|
1967
|
-
|
|
2003
|
+
virtual.serverBuild.id
|
|
1968
2004
|
);
|
|
1969
2005
|
let handler = (0, import_react_router2.createRequestHandler)(build, "development");
|
|
1970
2006
|
let nodeHandler = async (nodeReq, nodeRes) => {
|
|
@@ -1999,8 +2035,8 @@ var reactRouterVitePlugin = () => {
|
|
|
1999
2035
|
let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
|
|
2000
2036
|
let movedAssetPaths = [];
|
|
2001
2037
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
2002
|
-
let src =
|
|
2003
|
-
let dest =
|
|
2038
|
+
let src = path6.join(serverBuildDirectory, ssrAssetPath);
|
|
2039
|
+
let dest = path6.join(clientBuildDirectory, ssrAssetPath);
|
|
2004
2040
|
if (!fse.existsSync(dest)) {
|
|
2005
2041
|
await fse.move(src, dest);
|
|
2006
2042
|
movedAssetPaths.push(dest);
|
|
@@ -2013,7 +2049,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2013
2049
|
);
|
|
2014
2050
|
await Promise.all(
|
|
2015
2051
|
ssrCssPaths.map(
|
|
2016
|
-
(cssPath) => fse.remove(
|
|
2052
|
+
(cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
|
|
2017
2053
|
)
|
|
2018
2054
|
);
|
|
2019
2055
|
if (movedAssetPaths.length) {
|
|
@@ -2022,7 +2058,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2022
2058
|
"",
|
|
2023
2059
|
`${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
|
|
2024
2060
|
...movedAssetPaths.map(
|
|
2025
|
-
(movedAssetPath) => import_picocolors3.default.dim(
|
|
2061
|
+
(movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
|
|
2026
2062
|
),
|
|
2027
2063
|
""
|
|
2028
2064
|
].join("\n")
|
|
@@ -2064,12 +2100,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2064
2100
|
}
|
|
2065
2101
|
},
|
|
2066
2102
|
{
|
|
2067
|
-
name: "react-router-route
|
|
2103
|
+
name: "react-router:build-client-route",
|
|
2068
2104
|
enforce: "pre",
|
|
2069
|
-
async transform(_code,
|
|
2070
|
-
if (!
|
|
2071
|
-
let routeModuleId =
|
|
2072
|
-
let routeFileName =
|
|
2105
|
+
async transform(_code, id, options) {
|
|
2106
|
+
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
2107
|
+
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
2108
|
+
let routeFileName = path6.basename(routeModuleId);
|
|
2073
2109
|
let sourceExports = await getRouteModuleExports(
|
|
2074
2110
|
viteChildCompiler,
|
|
2075
2111
|
ctx,
|
|
@@ -2082,23 +2118,24 @@ var reactRouterVitePlugin = () => {
|
|
|
2082
2118
|
}
|
|
2083
2119
|
},
|
|
2084
2120
|
{
|
|
2085
|
-
name: "react-router
|
|
2121
|
+
name: "react-router:virtual-modules",
|
|
2086
2122
|
enforce: "pre",
|
|
2087
|
-
resolveId(
|
|
2088
|
-
|
|
2123
|
+
resolveId(id) {
|
|
2124
|
+
const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
|
|
2125
|
+
if (vmod2) return vmod2.resolvedId;
|
|
2089
2126
|
},
|
|
2090
|
-
async load(
|
|
2091
|
-
switch (
|
|
2092
|
-
case
|
|
2127
|
+
async load(id) {
|
|
2128
|
+
switch (id) {
|
|
2129
|
+
case virtual.serverBuild.resolvedId: {
|
|
2093
2130
|
return await getServerEntry();
|
|
2094
2131
|
}
|
|
2095
|
-
case
|
|
2132
|
+
case virtual.serverManifest.resolvedId: {
|
|
2096
2133
|
let reactRouterManifest = ctx.isSsrBuild ? await ctx.getReactRouterServerManifest() : await getReactRouterManifestForDev();
|
|
2097
2134
|
return `export default ${(0, import_jsesc.default)(reactRouterManifest, {
|
|
2098
2135
|
es6: true
|
|
2099
2136
|
})};`;
|
|
2100
2137
|
}
|
|
2101
|
-
case
|
|
2138
|
+
case virtual.browserManifest.resolvedId: {
|
|
2102
2139
|
if (viteCommand === "build") {
|
|
2103
2140
|
throw new Error("This module only exists in development");
|
|
2104
2141
|
}
|
|
@@ -2112,15 +2149,15 @@ var reactRouterVitePlugin = () => {
|
|
|
2112
2149
|
}
|
|
2113
2150
|
},
|
|
2114
2151
|
{
|
|
2115
|
-
name: "react-router
|
|
2152
|
+
name: "react-router:dot-server",
|
|
2116
2153
|
enforce: "pre",
|
|
2117
|
-
async resolveId(
|
|
2154
|
+
async resolveId(id, importer, options) {
|
|
2118
2155
|
let isOptimizeDeps = viteCommand === "serve" && options?.scan === true;
|
|
2119
2156
|
if (isOptimizeDeps || options?.ssr) return;
|
|
2120
|
-
let isResolving = options?.custom?.["react-router
|
|
2157
|
+
let isResolving = options?.custom?.["react-router:dot-server"] ?? false;
|
|
2121
2158
|
if (isResolving) return;
|
|
2122
|
-
options.custom = { ...options.custom, "react-router
|
|
2123
|
-
let resolved = await this.resolve(
|
|
2159
|
+
options.custom = { ...options.custom, "react-router:dot-server": true };
|
|
2160
|
+
let resolved = await this.resolve(id, importer, options);
|
|
2124
2161
|
if (!resolved) return;
|
|
2125
2162
|
let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
|
|
2126
2163
|
let serverDirRE = /\/\.server\//;
|
|
@@ -2130,9 +2167,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2130
2167
|
if (viteCommand !== "build" && importer.endsWith(".html")) {
|
|
2131
2168
|
return;
|
|
2132
2169
|
}
|
|
2133
|
-
let vite2 =
|
|
2170
|
+
let vite2 = getVite();
|
|
2134
2171
|
let importerShort = vite2.normalizePath(
|
|
2135
|
-
|
|
2172
|
+
path6.relative(ctx.rootDirectory, importer)
|
|
2136
2173
|
);
|
|
2137
2174
|
let isRoute = getRoute(ctx.reactRouterConfig, importer);
|
|
2138
2175
|
if (isRoute) {
|
|
@@ -2143,12 +2180,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2143
2180
|
[
|
|
2144
2181
|
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
2145
2182
|
"",
|
|
2146
|
-
` '${
|
|
2183
|
+
` '${id}' imported by route '${importerShort}'`,
|
|
2147
2184
|
"",
|
|
2148
2185
|
` React Router automatically removes server-code from these exports:`,
|
|
2149
2186
|
` ${serverOnlyExports}`,
|
|
2150
2187
|
"",
|
|
2151
|
-
` But other route exports in '${importerShort}' depend on '${
|
|
2188
|
+
` But other route exports in '${importerShort}' depend on '${id}'.`,
|
|
2152
2189
|
"",
|
|
2153
2190
|
" See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
|
|
2154
2191
|
""
|
|
@@ -2159,7 +2196,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2159
2196
|
[
|
|
2160
2197
|
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
2161
2198
|
"",
|
|
2162
|
-
` '${
|
|
2199
|
+
` '${id}' imported by '${importerShort}'`,
|
|
2163
2200
|
"",
|
|
2164
2201
|
" See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
|
|
2165
2202
|
""
|
|
@@ -2168,12 +2205,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2168
2205
|
}
|
|
2169
2206
|
},
|
|
2170
2207
|
{
|
|
2171
|
-
name: "react-router
|
|
2172
|
-
async transform(code,
|
|
2208
|
+
name: "react-router:dot-client",
|
|
2209
|
+
async transform(code, id, options) {
|
|
2173
2210
|
if (!options?.ssr) return;
|
|
2174
2211
|
let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
|
|
2175
2212
|
let clientDirRE = /\/\.client\//;
|
|
2176
|
-
if (clientFileRE.test(
|
|
2213
|
+
if (clientFileRE.test(id) || clientDirRE.test(id)) {
|
|
2177
2214
|
let exports2 = (0, import_es_module_lexer.parse)(code)[1];
|
|
2178
2215
|
return {
|
|
2179
2216
|
code: exports2.map(
|
|
@@ -2186,9 +2223,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2186
2223
|
},
|
|
2187
2224
|
plugin,
|
|
2188
2225
|
{
|
|
2189
|
-
name: "react-router
|
|
2190
|
-
async transform(code,
|
|
2191
|
-
let route = getRoute(ctx.reactRouterConfig,
|
|
2226
|
+
name: "react-router:route-exports",
|
|
2227
|
+
async transform(code, id, options) {
|
|
2228
|
+
let route = getRoute(ctx.reactRouterConfig, id);
|
|
2192
2229
|
if (!route) return;
|
|
2193
2230
|
if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
|
|
2194
2231
|
let serverOnlyExports = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));
|
|
@@ -2205,7 +2242,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2205
2242
|
}
|
|
2206
2243
|
}
|
|
2207
2244
|
}
|
|
2208
|
-
let [filepath] =
|
|
2245
|
+
let [filepath] = id.split("?");
|
|
2209
2246
|
let ast = (0, import_parser.parse)(code, { sourceType: "module" });
|
|
2210
2247
|
if (!options?.ssr) {
|
|
2211
2248
|
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
|
|
@@ -2213,22 +2250,23 @@ var reactRouterVitePlugin = () => {
|
|
|
2213
2250
|
transform(ast);
|
|
2214
2251
|
return generate2(ast, {
|
|
2215
2252
|
sourceMaps: true,
|
|
2216
|
-
filename:
|
|
2253
|
+
filename: id,
|
|
2217
2254
|
sourceFileName: filepath
|
|
2218
2255
|
});
|
|
2219
2256
|
}
|
|
2220
2257
|
},
|
|
2221
2258
|
{
|
|
2222
|
-
name: "react-router
|
|
2259
|
+
name: "react-router:inject-hmr-runtime",
|
|
2223
2260
|
enforce: "pre",
|
|
2224
|
-
resolveId(
|
|
2225
|
-
if (
|
|
2226
|
-
return
|
|
2261
|
+
resolveId(id) {
|
|
2262
|
+
if (id === virtualInjectHmrRuntime.id) {
|
|
2263
|
+
return virtualInjectHmrRuntime.resolvedId;
|
|
2264
|
+
}
|
|
2227
2265
|
},
|
|
2228
|
-
async load(
|
|
2229
|
-
if (
|
|
2266
|
+
async load(id) {
|
|
2267
|
+
if (id !== virtualInjectHmrRuntime.resolvedId) return;
|
|
2230
2268
|
return [
|
|
2231
|
-
`import RefreshRuntime from "${
|
|
2269
|
+
`import RefreshRuntime from "${virtualHmrRuntime.id}"`,
|
|
2232
2270
|
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
2233
2271
|
"window.$RefreshReg$ = () => {}",
|
|
2234
2272
|
"window.$RefreshSig$ = () => (type) => type",
|
|
@@ -2237,17 +2275,17 @@ var reactRouterVitePlugin = () => {
|
|
|
2237
2275
|
}
|
|
2238
2276
|
},
|
|
2239
2277
|
{
|
|
2240
|
-
name: "react-router
|
|
2278
|
+
name: "react-router:hmr-runtime",
|
|
2241
2279
|
enforce: "pre",
|
|
2242
|
-
resolveId(
|
|
2243
|
-
if (
|
|
2280
|
+
resolveId(id) {
|
|
2281
|
+
if (id === virtualHmrRuntime.id) return virtualHmrRuntime.resolvedId;
|
|
2244
2282
|
},
|
|
2245
|
-
async load(
|
|
2246
|
-
if (
|
|
2247
|
-
let reactRefreshDir =
|
|
2283
|
+
async load(id) {
|
|
2284
|
+
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
2285
|
+
let reactRefreshDir = path6.dirname(
|
|
2248
2286
|
require.resolve("react-refresh/package.json")
|
|
2249
2287
|
);
|
|
2250
|
-
let reactRefreshRuntimePath =
|
|
2288
|
+
let reactRefreshRuntimePath = path6.join(
|
|
2251
2289
|
reactRefreshDir,
|
|
2252
2290
|
"cjs/react-refresh-runtime.development.js"
|
|
2253
2291
|
);
|
|
@@ -2263,11 +2301,11 @@ var reactRouterVitePlugin = () => {
|
|
|
2263
2301
|
}
|
|
2264
2302
|
},
|
|
2265
2303
|
{
|
|
2266
|
-
name: "react-router
|
|
2267
|
-
async transform(code,
|
|
2304
|
+
name: "react-router:react-refresh-babel",
|
|
2305
|
+
async transform(code, id, options) {
|
|
2268
2306
|
if (viteCommand !== "serve") return;
|
|
2269
|
-
if (
|
|
2270
|
-
let [filepath] =
|
|
2307
|
+
if (id.includes("/node_modules/")) return;
|
|
2308
|
+
let [filepath] = id.split("?");
|
|
2271
2309
|
let extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
2272
2310
|
if (!extensionsRE.test(filepath)) return;
|
|
2273
2311
|
let devRuntime = "react/jsx-dev-runtime";
|
|
@@ -2275,13 +2313,10 @@ var reactRouterVitePlugin = () => {
|
|
|
2275
2313
|
let isJSX = filepath.endsWith("x");
|
|
2276
2314
|
let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
2277
2315
|
if (!useFastRefresh) return;
|
|
2278
|
-
if (isRouteEntry(id2)) {
|
|
2279
|
-
return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id2) };
|
|
2280
|
-
}
|
|
2281
2316
|
let result = await babel.transformAsync(code, {
|
|
2282
2317
|
babelrc: false,
|
|
2283
2318
|
configFile: false,
|
|
2284
|
-
filename:
|
|
2319
|
+
filename: id,
|
|
2285
2320
|
sourceFileName: filepath,
|
|
2286
2321
|
parserOpts: {
|
|
2287
2322
|
sourceType: "module",
|
|
@@ -2294,18 +2329,18 @@ var reactRouterVitePlugin = () => {
|
|
|
2294
2329
|
code = result.code;
|
|
2295
2330
|
let refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
2296
2331
|
if (refreshContentRE.test(code)) {
|
|
2297
|
-
code = addRefreshWrapper(ctx.reactRouterConfig, code,
|
|
2332
|
+
code = addRefreshWrapper(ctx.reactRouterConfig, code, id);
|
|
2298
2333
|
}
|
|
2299
2334
|
return { code, map: result.map };
|
|
2300
2335
|
}
|
|
2301
2336
|
},
|
|
2302
2337
|
{
|
|
2303
|
-
name: "react-router
|
|
2338
|
+
name: "react-router:hmr-updates",
|
|
2304
2339
|
async handleHotUpdate({ server, file, modules, read }) {
|
|
2305
2340
|
let route = getRoute(ctx.reactRouterConfig, file);
|
|
2306
2341
|
let hmrEventData = { route: null };
|
|
2307
2342
|
if (route) {
|
|
2308
|
-
let serverManifest = (await server.ssrLoadModule(
|
|
2343
|
+
let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
|
|
2309
2344
|
let oldRouteMetadata = serverManifest.routes[route.id];
|
|
2310
2345
|
let newRouteMetadata = await getRouteMetadata(
|
|
2311
2346
|
ctx,
|
|
@@ -2331,39 +2366,69 @@ var reactRouterVitePlugin = () => {
|
|
|
2331
2366
|
});
|
|
2332
2367
|
return modules;
|
|
2333
2368
|
}
|
|
2369
|
+
},
|
|
2370
|
+
{
|
|
2371
|
+
name: "react-router-server-change-trigger-client-hmr",
|
|
2372
|
+
// This hook is only available in Vite v6+ so this is a no-op in v5.
|
|
2373
|
+
// Previously the server and client modules were shared in a single module
|
|
2374
|
+
// graph. This meant that changes to server code automatically resulted in
|
|
2375
|
+
// client HMR updates. In Vite v6+ these module graphs are separate from
|
|
2376
|
+
// each other so we need to manually trigger client HMR updates if server
|
|
2377
|
+
// code has changed.
|
|
2378
|
+
hotUpdate({ server, modules }) {
|
|
2379
|
+
if (this.environment.name !== "ssr" && modules.length <= 0) {
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
let clientModules = uniqueNodes(
|
|
2383
|
+
modules.flatMap(
|
|
2384
|
+
(mod) => getParentClientNodes(server.environments.client.moduleGraph, mod)
|
|
2385
|
+
)
|
|
2386
|
+
);
|
|
2387
|
+
for (let clientModule of clientModules) {
|
|
2388
|
+
server.environments.client.reloadModule(clientModule);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2334
2391
|
}
|
|
2335
2392
|
];
|
|
2336
2393
|
};
|
|
2337
|
-
function
|
|
2338
|
-
|
|
2339
|
-
|
|
2394
|
+
function getParentClientNodes(clientModuleGraph, module2) {
|
|
2395
|
+
if (!module2.id) {
|
|
2396
|
+
return [];
|
|
2397
|
+
}
|
|
2398
|
+
let clientModule = clientModuleGraph.getModuleById(module2.id);
|
|
2399
|
+
if (clientModule) {
|
|
2400
|
+
return [clientModule];
|
|
2401
|
+
}
|
|
2402
|
+
return [...module2.importers].flatMap(
|
|
2403
|
+
(importer) => getParentClientNodes(clientModuleGraph, importer)
|
|
2404
|
+
);
|
|
2405
|
+
}
|
|
2406
|
+
function uniqueNodes(nodes) {
|
|
2407
|
+
let nodeUrls = /* @__PURE__ */ new Set();
|
|
2408
|
+
let unique = [];
|
|
2409
|
+
for (let node of nodes) {
|
|
2410
|
+
if (nodeUrls.has(node.url)) {
|
|
2411
|
+
continue;
|
|
2412
|
+
}
|
|
2413
|
+
nodeUrls.add(node.url);
|
|
2414
|
+
unique.push(node);
|
|
2415
|
+
}
|
|
2416
|
+
return unique;
|
|
2417
|
+
}
|
|
2418
|
+
function addRefreshWrapper(reactRouterConfig, code, id) {
|
|
2419
|
+
let route = getRoute(reactRouterConfig, id);
|
|
2420
|
+
let acceptExports = route ? [
|
|
2340
2421
|
"clientAction",
|
|
2341
2422
|
"clientLoader",
|
|
2342
|
-
"clientMiddleware",
|
|
2343
2423
|
"handle",
|
|
2344
2424
|
"meta",
|
|
2345
2425
|
"links",
|
|
2346
2426
|
"shouldRevalidate"
|
|
2347
2427
|
] : [];
|
|
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}`;
|
|
2428
|
+
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
2429
|
}
|
|
2365
2430
|
var REACT_REFRESH_HEADER = `
|
|
2366
|
-
import RefreshRuntime from "${
|
|
2431
|
+
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
2367
2432
|
|
|
2368
2433
|
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
2369
2434
|
let prevRefreshReg;
|
|
@@ -2382,7 +2447,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
2382
2447
|
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
2383
2448
|
};
|
|
2384
2449
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
2385
|
-
}`.
|
|
2450
|
+
}`.replaceAll("\n", "");
|
|
2386
2451
|
var REACT_REFRESH_FOOTER = `
|
|
2387
2452
|
if (import.meta.hot && !inWebWorker) {
|
|
2388
2453
|
window.$RefreshReg$ = prevRefreshReg;
|
|
@@ -2396,11 +2461,11 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
2396
2461
|
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
2397
2462
|
});
|
|
2398
2463
|
});
|
|
2399
|
-
}
|
|
2464
|
+
}`;
|
|
2400
2465
|
function getRoute(pluginConfig, file) {
|
|
2401
|
-
let vite2 =
|
|
2466
|
+
let vite2 = getVite();
|
|
2402
2467
|
let routePath = vite2.normalizePath(
|
|
2403
|
-
|
|
2468
|
+
path6.relative(pluginConfig.appDirectory, file)
|
|
2404
2469
|
);
|
|
2405
2470
|
let route = Object.values(pluginConfig.routes).find(
|
|
2406
2471
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -2422,7 +2487,7 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
|
2422
2487
|
caseSensitive: route.caseSensitive,
|
|
2423
2488
|
url: combineURLs(
|
|
2424
2489
|
ctx.publicPath,
|
|
2425
|
-
"/" +
|
|
2490
|
+
"/" + path6.relative(
|
|
2426
2491
|
ctx.rootDirectory,
|
|
2427
2492
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2428
2493
|
)
|
|
@@ -2445,11 +2510,11 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
|
2445
2510
|
return info;
|
|
2446
2511
|
}
|
|
2447
2512
|
async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
|
|
2448
|
-
let serverBuildPath =
|
|
2513
|
+
let serverBuildPath = path6.join(
|
|
2449
2514
|
serverBuildDirectory,
|
|
2450
2515
|
reactRouterConfig.serverBuildFile
|
|
2451
2516
|
);
|
|
2452
|
-
let build = await import(
|
|
2517
|
+
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
2453
2518
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
2454
2519
|
return {
|
|
2455
2520
|
build,
|
|
@@ -2467,9 +2532,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
2467
2532
|
let html = await response.text();
|
|
2468
2533
|
validatePrerenderedResponse(response, html, "SPA Mode", "/");
|
|
2469
2534
|
validatePrerenderedHtml(html, "SPA Mode");
|
|
2470
|
-
await fse.writeFile(
|
|
2535
|
+
await fse.writeFile(path6.join(clientBuildDirectory, "index.html"), html);
|
|
2471
2536
|
viteConfig.logger.info(
|
|
2472
|
-
"SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(
|
|
2537
|
+
"SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path6.relative(process.cwd(), clientBuildDirectory)) + " directory"
|
|
2473
2538
|
);
|
|
2474
2539
|
}
|
|
2475
2540
|
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
|
|
@@ -2499,14 +2564,14 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2499
2564
|
// build time or runtime
|
|
2500
2565
|
"X-React-Router-Prerender": "yes"
|
|
2501
2566
|
};
|
|
2502
|
-
for (let
|
|
2503
|
-
let matches = (0, import_react_router2.matchRoutes)(routes,
|
|
2567
|
+
for (let path7 of routesToPrerender) {
|
|
2568
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
2504
2569
|
let hasLoaders = matches?.some((m) => m.route.loader);
|
|
2505
2570
|
let data;
|
|
2506
2571
|
if (hasLoaders) {
|
|
2507
2572
|
data = await prerenderData(
|
|
2508
2573
|
handler,
|
|
2509
|
-
|
|
2574
|
+
path7,
|
|
2510
2575
|
clientBuildDirectory,
|
|
2511
2576
|
reactRouterConfig,
|
|
2512
2577
|
viteConfig,
|
|
@@ -2519,7 +2584,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2519
2584
|
if (isResourceRoute) {
|
|
2520
2585
|
await prerenderResourceRoute(
|
|
2521
2586
|
handler,
|
|
2522
|
-
|
|
2587
|
+
path7,
|
|
2523
2588
|
clientBuildDirectory,
|
|
2524
2589
|
reactRouterConfig,
|
|
2525
2590
|
viteConfig,
|
|
@@ -2528,7 +2593,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2528
2593
|
} else {
|
|
2529
2594
|
await prerenderRoute(
|
|
2530
2595
|
handler,
|
|
2531
|
-
|
|
2596
|
+
path7,
|
|
2532
2597
|
clientBuildDirectory,
|
|
2533
2598
|
reactRouterConfig,
|
|
2534
2599
|
viteConfig,
|
|
@@ -2585,9 +2650,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
|
|
|
2585
2650
|
let response = await handler(request);
|
|
2586
2651
|
let data = await response.text();
|
|
2587
2652
|
validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
|
|
2588
|
-
let outdir =
|
|
2589
|
-
let outfile =
|
|
2590
|
-
await fse.ensureDir(
|
|
2653
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
2654
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
2655
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2591
2656
|
await fse.outputFile(outfile, data);
|
|
2592
2657
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2593
2658
|
return data;
|
|
@@ -2604,9 +2669,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
2604
2669
|
if (!reactRouterConfig.ssr) {
|
|
2605
2670
|
validatePrerenderedHtml(html, "Prerender");
|
|
2606
2671
|
}
|
|
2607
|
-
let outdir =
|
|
2608
|
-
let outfile =
|
|
2609
|
-
await fse.ensureDir(
|
|
2672
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
2673
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
|
|
2674
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2610
2675
|
await fse.outputFile(outfile, html);
|
|
2611
2676
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2612
2677
|
}
|
|
@@ -2616,9 +2681,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
2616
2681
|
let response = await handler(request);
|
|
2617
2682
|
let text = await response.text();
|
|
2618
2683
|
validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
|
|
2619
|
-
let outdir =
|
|
2620
|
-
let outfile =
|
|
2621
|
-
await fse.ensureDir(
|
|
2684
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
2685
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
2686
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2622
2687
|
await fse.outputFile(outfile, text);
|
|
2623
2688
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2624
2689
|
}
|
|
@@ -2627,17 +2692,17 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
|
|
|
2627
2692
|
/\/\/+/g,
|
|
2628
2693
|
"/"
|
|
2629
2694
|
);
|
|
2630
|
-
let outdir =
|
|
2631
|
-
let outfile =
|
|
2632
|
-
await fse.ensureDir(
|
|
2695
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
2696
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
2697
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
2633
2698
|
let manifestData = JSON.stringify(build.assets.routes);
|
|
2634
2699
|
await fse.outputFile(outfile, manifestData);
|
|
2635
2700
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2636
2701
|
}
|
|
2637
|
-
function validatePrerenderedResponse(response, html, prefix,
|
|
2702
|
+
function validatePrerenderedResponse(response, html, prefix, path7) {
|
|
2638
2703
|
if (response.status !== 200) {
|
|
2639
2704
|
throw new Error(
|
|
2640
|
-
`${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${
|
|
2705
|
+
`${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${path7}\` path.
|
|
2641
2706
|
${html}`
|
|
2642
2707
|
);
|
|
2643
2708
|
}
|
|
@@ -2672,8 +2737,6 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
|
|
|
2672
2737
|
loader: route.module.loader ? () => null : void 0,
|
|
2673
2738
|
action: void 0,
|
|
2674
2739
|
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
2740
|
};
|
|
2678
2741
|
return route.index ? {
|
|
2679
2742
|
index: true,
|