@react-router/dev 0.0.0-experimental-6b51a129b → 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 -235
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +48 -7
- package/dist/vite.js +473 -412
- 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,129 +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 LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
685
|
-
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
686
|
-
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
687
|
-
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"];
|
|
688
655
|
|
|
689
|
-
export type HydrateFallbackProps =
|
|
690
|
-
export type ComponentProps =
|
|
691
|
-
export type ErrorBoundaryProps =
|
|
656
|
+
export type HydrateFallbackProps = Exports["HydrateFallback"]["args"];
|
|
657
|
+
export type ComponentProps = Exports["default"]["args"];
|
|
658
|
+
export type ErrorBoundaryProps = Exports["ErrorBoundary"]["args"];
|
|
692
659
|
}
|
|
693
660
|
`;
|
|
694
661
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
route = routes[route.parentId];
|
|
702
|
-
}
|
|
703
|
-
result.reverse();
|
|
704
|
-
return result;
|
|
705
|
-
}
|
|
706
|
-
function formatParamProperties(urlpath) {
|
|
707
|
-
const params = parseParams(urlpath);
|
|
708
|
-
const properties = Object.entries(params).map(([name, values]) => {
|
|
709
|
-
if (values.length === 1) {
|
|
710
|
-
const isOptional = values[0];
|
|
711
|
-
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
712
|
-
}
|
|
713
|
-
const items = values.map(
|
|
714
|
-
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
715
|
-
);
|
|
716
|
-
return `"${name}": [${items.join(", ")}]`;
|
|
717
|
-
});
|
|
718
|
-
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");
|
|
719
668
|
}
|
|
720
|
-
function
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const isOptional = match[2] !== void 0;
|
|
728
|
-
result[param] ??= [];
|
|
729
|
-
result[param].push(isOptional);
|
|
730
|
-
return;
|
|
731
|
-
});
|
|
732
|
-
const hasSplat = segments.at(-1) === "*";
|
|
733
|
-
if (hasSplat) result["*"] = [false];
|
|
734
|
-
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
|
+
);
|
|
735
676
|
}
|
|
736
677
|
|
|
737
678
|
// typegen/index.ts
|
|
@@ -773,16 +714,93 @@ async function createContext2({
|
|
|
773
714
|
config
|
|
774
715
|
};
|
|
775
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
|
+
}
|
|
776
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 += `}`;
|
|
777
749
|
const typegenDir = getTypesDir(ctx);
|
|
778
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
|
+
);
|
|
779
772
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
780
773
|
const typesPath = getTypesPath(ctx, route);
|
|
781
|
-
const content = generate(
|
|
782
|
-
import_node_fs2.default.mkdirSync(
|
|
774
|
+
const content = generate(route);
|
|
775
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(typesPath), { recursive: true });
|
|
783
776
|
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
784
777
|
});
|
|
785
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
|
+
}
|
|
786
804
|
|
|
787
805
|
// vite/babel.ts
|
|
788
806
|
var import_parser = require("@babel/parser");
|
|
@@ -816,7 +834,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
816
834
|
nodeReq.originalUrl,
|
|
817
835
|
"Expected `nodeReq.originalUrl` to be defined"
|
|
818
836
|
);
|
|
819
|
-
let
|
|
837
|
+
let url2 = new URL(nodeReq.originalUrl, origin);
|
|
820
838
|
let controller = new AbortController();
|
|
821
839
|
let init = {
|
|
822
840
|
method: nodeReq.method,
|
|
@@ -829,7 +847,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
829
847
|
init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
|
|
830
848
|
init.duplex = "half";
|
|
831
849
|
}
|
|
832
|
-
return new Request(
|
|
850
|
+
return new Request(url2.href, init);
|
|
833
851
|
}
|
|
834
852
|
async function toNodeRequest(res, nodeRes) {
|
|
835
853
|
nodeRes.statusCode = res.status;
|
|
@@ -854,17 +872,17 @@ async function toNodeRequest(res, nodeRes) {
|
|
|
854
872
|
}
|
|
855
873
|
|
|
856
874
|
// vite/styles.ts
|
|
857
|
-
var
|
|
875
|
+
var path5 = __toESM(require("path"));
|
|
858
876
|
var import_react_router = require("react-router");
|
|
859
877
|
|
|
860
878
|
// vite/resolve-file-url.ts
|
|
861
|
-
var
|
|
879
|
+
var path4 = __toESM(require("path"));
|
|
862
880
|
var resolveFileUrl = ({ rootDirectory }, filePath) => {
|
|
863
|
-
let vite2 =
|
|
864
|
-
let relativePath =
|
|
865
|
-
let isWithinRoot = !relativePath.startsWith("..") && !
|
|
881
|
+
let vite2 = getVite();
|
|
882
|
+
let relativePath = path4.relative(rootDirectory, filePath);
|
|
883
|
+
let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
|
|
866
884
|
if (!isWithinRoot) {
|
|
867
|
-
return
|
|
885
|
+
return path4.posix.join("/@fs", vite2.normalizePath(filePath));
|
|
868
886
|
}
|
|
869
887
|
return "/" + vite2.normalizePath(relativePath);
|
|
870
888
|
};
|
|
@@ -875,8 +893,8 @@ var cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
|
875
893
|
var isCssFile = (file) => cssFileRegExp.test(file);
|
|
876
894
|
var isCssModulesFile = (file) => cssModulesRegExp.test(file);
|
|
877
895
|
var cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
|
|
878
|
-
var isCssUrlWithoutSideEffects = (
|
|
879
|
-
let queryString =
|
|
896
|
+
var isCssUrlWithoutSideEffects = (url2) => {
|
|
897
|
+
let queryString = url2.split("?")[1];
|
|
880
898
|
if (!queryString) {
|
|
881
899
|
return false;
|
|
882
900
|
}
|
|
@@ -884,24 +902,27 @@ var isCssUrlWithoutSideEffects = (url3) => {
|
|
|
884
902
|
for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
|
|
885
903
|
if (
|
|
886
904
|
// Parameter is blank and not explicitly set, i.e. "?url", not "?url="
|
|
887
|
-
params.get(paramWithoutSideEffects) === "" && !
|
|
905
|
+
params.get(paramWithoutSideEffects) === "" && !url2.includes(`?${paramWithoutSideEffects}=`) && !url2.includes(`&${paramWithoutSideEffects}=`)
|
|
888
906
|
) {
|
|
889
907
|
return true;
|
|
890
908
|
}
|
|
891
909
|
}
|
|
892
910
|
return false;
|
|
893
911
|
};
|
|
912
|
+
var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
|
|
894
913
|
var getStylesForFiles = async ({
|
|
895
914
|
viteDevServer,
|
|
896
915
|
rootDirectory,
|
|
897
916
|
cssModulesManifest,
|
|
898
917
|
files
|
|
899
918
|
}) => {
|
|
919
|
+
let vite2 = getVite();
|
|
920
|
+
let viteMajor = parseInt(vite2.version.split(".")[0], 10);
|
|
900
921
|
let styles = {};
|
|
901
922
|
let deps = /* @__PURE__ */ new Set();
|
|
902
923
|
try {
|
|
903
924
|
for (let file of files) {
|
|
904
|
-
let normalizedPath =
|
|
925
|
+
let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
|
|
905
926
|
let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
906
927
|
if (!node) {
|
|
907
928
|
try {
|
|
@@ -925,7 +946,15 @@ var getStylesForFiles = async ({
|
|
|
925
946
|
for (let dep of deps) {
|
|
926
947
|
if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url)) {
|
|
927
948
|
try {
|
|
928
|
-
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;
|
|
929
958
|
if (css === void 0) {
|
|
930
959
|
throw new Error();
|
|
931
960
|
}
|
|
@@ -949,8 +978,8 @@ var findDeps = async (vite2, node, deps) => {
|
|
|
949
978
|
await findDeps(vite2, node2, deps);
|
|
950
979
|
}
|
|
951
980
|
}
|
|
952
|
-
async function addFromUrl(
|
|
953
|
-
let node2 = await vite2.moduleGraph.getModuleByUrl(
|
|
981
|
+
async function addFromUrl(url2) {
|
|
982
|
+
let node2 = await vite2.moduleGraph.getModuleByUrl(url2);
|
|
954
983
|
if (node2) {
|
|
955
984
|
await addFromNode(node2);
|
|
956
985
|
}
|
|
@@ -958,7 +987,7 @@ var findDeps = async (vite2, node, deps) => {
|
|
|
958
987
|
if (node.ssrTransformResult) {
|
|
959
988
|
if (node.ssrTransformResult.deps) {
|
|
960
989
|
node.ssrTransformResult.deps.forEach(
|
|
961
|
-
(
|
|
990
|
+
(url2) => branches.push(addFromUrl(url2))
|
|
962
991
|
);
|
|
963
992
|
}
|
|
964
993
|
} else {
|
|
@@ -992,15 +1021,15 @@ var getStylesForUrl = async ({
|
|
|
992
1021
|
entryClientFilePath,
|
|
993
1022
|
cssModulesManifest,
|
|
994
1023
|
build,
|
|
995
|
-
url:
|
|
1024
|
+
url: url2
|
|
996
1025
|
}) => {
|
|
997
|
-
if (
|
|
1026
|
+
if (url2 === void 0 || url2.includes("?_data=")) {
|
|
998
1027
|
return void 0;
|
|
999
1028
|
}
|
|
1000
1029
|
let routes = createRoutes(build.routes);
|
|
1001
|
-
let appPath =
|
|
1002
|
-
let documentRouteFiles = (0, import_react_router.matchRoutes)(routes,
|
|
1003
|
-
(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)
|
|
1004
1033
|
) ?? [];
|
|
1005
1034
|
let styles = await getStylesForFiles({
|
|
1006
1035
|
viteDevServer,
|
|
@@ -1008,7 +1037,7 @@ var getStylesForUrl = async ({
|
|
|
1008
1037
|
cssModulesManifest,
|
|
1009
1038
|
files: [
|
|
1010
1039
|
// Always include the client entry file when crawling the module graph for CSS
|
|
1011
|
-
|
|
1040
|
+
path5.relative(rootDirectory, entryClientFilePath),
|
|
1012
1041
|
// Then include any styles from the matched routes
|
|
1013
1042
|
...documentRouteFiles
|
|
1014
1043
|
]
|
|
@@ -1016,10 +1045,15 @@ var getStylesForUrl = async ({
|
|
|
1016
1045
|
return styles;
|
|
1017
1046
|
};
|
|
1018
1047
|
|
|
1019
|
-
// vite/
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
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
|
+
}
|
|
1023
1057
|
|
|
1024
1058
|
// vite/combine-urls.ts
|
|
1025
1059
|
function combineURLs(baseURL, relativeURL) {
|
|
@@ -1033,10 +1067,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1033
1067
|
let exportsFiltered = false;
|
|
1034
1068
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1035
1069
|
traverse(ast, {
|
|
1036
|
-
ExportDeclaration(
|
|
1037
|
-
if (
|
|
1038
|
-
if (
|
|
1039
|
-
|
|
1070
|
+
ExportDeclaration(path7) {
|
|
1071
|
+
if (path7.node.type === "ExportNamedDeclaration") {
|
|
1072
|
+
if (path7.node.specifiers.length) {
|
|
1073
|
+
path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
|
|
1040
1074
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1041
1075
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1042
1076
|
exportsFiltered = true;
|
|
@@ -1045,12 +1079,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1045
1079
|
}
|
|
1046
1080
|
return true;
|
|
1047
1081
|
});
|
|
1048
|
-
if (
|
|
1049
|
-
markedForRemoval.add(
|
|
1082
|
+
if (path7.node.specifiers.length === 0) {
|
|
1083
|
+
markedForRemoval.add(path7);
|
|
1050
1084
|
}
|
|
1051
1085
|
}
|
|
1052
|
-
if (
|
|
1053
|
-
let declaration =
|
|
1086
|
+
if (path7.node.declaration?.type === "VariableDeclaration") {
|
|
1087
|
+
let declaration = path7.node.declaration;
|
|
1054
1088
|
declaration.declarations = declaration.declarations.filter(
|
|
1055
1089
|
(declaration2) => {
|
|
1056
1090
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1064,37 +1098,37 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1064
1098
|
}
|
|
1065
1099
|
);
|
|
1066
1100
|
if (declaration.declarations.length === 0) {
|
|
1067
|
-
markedForRemoval.add(
|
|
1101
|
+
markedForRemoval.add(path7);
|
|
1068
1102
|
}
|
|
1069
1103
|
}
|
|
1070
|
-
if (
|
|
1071
|
-
let
|
|
1072
|
-
if (
|
|
1073
|
-
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);
|
|
1074
1108
|
}
|
|
1075
1109
|
}
|
|
1076
|
-
if (
|
|
1077
|
-
let
|
|
1078
|
-
if (
|
|
1079
|
-
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);
|
|
1080
1114
|
}
|
|
1081
1115
|
}
|
|
1082
1116
|
}
|
|
1083
|
-
if (
|
|
1084
|
-
markedForRemoval.add(
|
|
1117
|
+
if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
1118
|
+
markedForRemoval.add(path7);
|
|
1085
1119
|
}
|
|
1086
1120
|
}
|
|
1087
1121
|
});
|
|
1088
1122
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1089
|
-
for (let
|
|
1090
|
-
|
|
1123
|
+
for (let path7 of markedForRemoval) {
|
|
1124
|
+
path7.remove();
|
|
1091
1125
|
}
|
|
1092
1126
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1093
1127
|
}
|
|
1094
1128
|
};
|
|
1095
|
-
function validateDestructuredExports(
|
|
1096
|
-
if (
|
|
1097
|
-
for (let element of
|
|
1129
|
+
function validateDestructuredExports(id, exportsToRemove) {
|
|
1130
|
+
if (id.type === "ArrayPattern") {
|
|
1131
|
+
for (let element of id.elements) {
|
|
1098
1132
|
if (!element) {
|
|
1099
1133
|
continue;
|
|
1100
1134
|
}
|
|
@@ -1109,8 +1143,8 @@ function validateDestructuredExports(id2, exportsToRemove) {
|
|
|
1109
1143
|
}
|
|
1110
1144
|
}
|
|
1111
1145
|
}
|
|
1112
|
-
if (
|
|
1113
|
-
for (let property of
|
|
1146
|
+
if (id.type === "ObjectPattern") {
|
|
1147
|
+
for (let property of id.properties) {
|
|
1114
1148
|
if (!property) {
|
|
1115
1149
|
continue;
|
|
1116
1150
|
}
|
|
@@ -1133,18 +1167,18 @@ function invalidDestructureError(name) {
|
|
|
1133
1167
|
}
|
|
1134
1168
|
|
|
1135
1169
|
// vite/with-props.ts
|
|
1136
|
-
var
|
|
1137
|
-
var
|
|
1170
|
+
var import_dedent3 = __toESM(require("dedent"));
|
|
1171
|
+
var vmod = create("with-props");
|
|
1138
1172
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
1139
1173
|
var plugin = {
|
|
1140
1174
|
name: "react-router-with-props",
|
|
1141
1175
|
enforce: "pre",
|
|
1142
|
-
resolveId(
|
|
1143
|
-
if (
|
|
1176
|
+
resolveId(id) {
|
|
1177
|
+
if (id === vmod.id) return vmod.resolvedId;
|
|
1144
1178
|
},
|
|
1145
|
-
async load(
|
|
1146
|
-
if (
|
|
1147
|
-
return
|
|
1179
|
+
async load(id) {
|
|
1180
|
+
if (id !== vmod.resolvedId) return;
|
|
1181
|
+
return import_dedent3.default`
|
|
1148
1182
|
import { createElement as h } from "react";
|
|
1149
1183
|
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
1150
1184
|
|
|
@@ -1185,44 +1219,44 @@ var plugin = {
|
|
|
1185
1219
|
};
|
|
1186
1220
|
var transform = (ast) => {
|
|
1187
1221
|
const hocs = [];
|
|
1188
|
-
function getHocUid(
|
|
1189
|
-
const uid =
|
|
1222
|
+
function getHocUid(path7, hocName) {
|
|
1223
|
+
const uid = path7.scope.generateUidIdentifier(hocName);
|
|
1190
1224
|
hocs.push([hocName, uid]);
|
|
1191
1225
|
return uid;
|
|
1192
1226
|
}
|
|
1193
1227
|
traverse(ast, {
|
|
1194
|
-
ExportDeclaration(
|
|
1195
|
-
if (
|
|
1196
|
-
const declaration =
|
|
1228
|
+
ExportDeclaration(path7) {
|
|
1229
|
+
if (path7.isExportDefaultDeclaration()) {
|
|
1230
|
+
const declaration = path7.get("declaration");
|
|
1197
1231
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
1198
1232
|
if (expr) {
|
|
1199
|
-
const uid = getHocUid(
|
|
1233
|
+
const uid = getHocUid(path7, "withComponentProps");
|
|
1200
1234
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
1201
1235
|
}
|
|
1202
1236
|
return;
|
|
1203
1237
|
}
|
|
1204
|
-
if (
|
|
1205
|
-
const decl =
|
|
1238
|
+
if (path7.isExportNamedDeclaration()) {
|
|
1239
|
+
const decl = path7.get("declaration");
|
|
1206
1240
|
if (decl.isVariableDeclaration()) {
|
|
1207
1241
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
1208
|
-
const
|
|
1242
|
+
const id = varDeclarator.get("id");
|
|
1209
1243
|
const init = varDeclarator.get("init");
|
|
1210
1244
|
const expr = init.node;
|
|
1211
1245
|
if (!expr) return;
|
|
1212
|
-
if (!
|
|
1213
|
-
const { name } =
|
|
1246
|
+
if (!id.isIdentifier()) return;
|
|
1247
|
+
const { name } = id.node;
|
|
1214
1248
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
1215
|
-
const uid = getHocUid(
|
|
1249
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
1216
1250
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
1217
1251
|
});
|
|
1218
1252
|
return;
|
|
1219
1253
|
}
|
|
1220
1254
|
if (decl.isFunctionDeclaration()) {
|
|
1221
|
-
const { id
|
|
1222
|
-
if (!
|
|
1223
|
-
const { name } =
|
|
1255
|
+
const { id } = decl.node;
|
|
1256
|
+
if (!id) return;
|
|
1257
|
+
const { name } = id;
|
|
1224
1258
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
1225
|
-
const uid = getHocUid(
|
|
1259
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
1226
1260
|
decl.replaceWith(
|
|
1227
1261
|
t.variableDeclaration("const", [
|
|
1228
1262
|
t.variableDeclarator(
|
|
@@ -1241,7 +1275,7 @@ var transform = (ast) => {
|
|
|
1241
1275
|
hocs.map(
|
|
1242
1276
|
([name, identifier]) => t.importSpecifier(identifier, t.identifier(name))
|
|
1243
1277
|
),
|
|
1244
|
-
t.stringLiteral(
|
|
1278
|
+
t.stringLiteral(vmod.id)
|
|
1245
1279
|
)
|
|
1246
1280
|
);
|
|
1247
1281
|
}
|
|
@@ -1257,11 +1291,10 @@ function toFunctionExpression(decl) {
|
|
|
1257
1291
|
}
|
|
1258
1292
|
|
|
1259
1293
|
// vite/plugin.ts
|
|
1260
|
-
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "
|
|
1294
|
+
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "headers"];
|
|
1261
1295
|
var CLIENT_ROUTE_EXPORTS = [
|
|
1262
1296
|
"clientAction",
|
|
1263
1297
|
"clientLoader",
|
|
1264
|
-
"clientMiddleware",
|
|
1265
1298
|
"default",
|
|
1266
1299
|
"ErrorBoundary",
|
|
1267
1300
|
"handle",
|
|
@@ -1271,27 +1304,23 @@ var CLIENT_ROUTE_EXPORTS = [
|
|
|
1271
1304
|
"meta",
|
|
1272
1305
|
"shouldRevalidate"
|
|
1273
1306
|
];
|
|
1274
|
-
var
|
|
1275
|
-
var
|
|
1276
|
-
|
|
1277
|
-
};
|
|
1278
|
-
var serverBuildId = id("server-build");
|
|
1279
|
-
var serverManifestId = id("server-manifest");
|
|
1280
|
-
var browserManifestId = id("browser-manifest");
|
|
1281
|
-
var hmrRuntimeId = id("hmr-runtime");
|
|
1282
|
-
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");
|
|
1283
1310
|
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
1284
|
-
let vite2 =
|
|
1311
|
+
let vite2 = getVite();
|
|
1285
1312
|
let file = route.file;
|
|
1286
|
-
let fullPath =
|
|
1313
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
1287
1314
|
return vite2.normalizePath(fullPath);
|
|
1288
1315
|
};
|
|
1289
|
-
var
|
|
1316
|
+
var virtual = {
|
|
1317
|
+
serverBuild: create("server-build"),
|
|
1318
|
+
serverManifest: create("server-manifest"),
|
|
1319
|
+
browserManifest: create("browser-manifest")
|
|
1320
|
+
};
|
|
1290
1321
|
var invalidateVirtualModules = (viteDevServer) => {
|
|
1291
|
-
|
|
1292
|
-
let mod = viteDevServer.moduleGraph.getModuleById(
|
|
1293
|
-
resolve3(vmod)
|
|
1294
|
-
);
|
|
1322
|
+
Object.values(virtual).forEach((vmod2) => {
|
|
1323
|
+
let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
|
|
1295
1324
|
if (mod) {
|
|
1296
1325
|
viteDevServer.moduleGraph.invalidateModule(mod);
|
|
1297
1326
|
}
|
|
@@ -1302,11 +1331,11 @@ var getHash = (source, maxLength) => {
|
|
|
1302
1331
|
return typeof maxLength === "number" ? hash.slice(0, maxLength) : hash;
|
|
1303
1332
|
};
|
|
1304
1333
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
1305
|
-
let vite2 =
|
|
1334
|
+
let vite2 = getVite();
|
|
1306
1335
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
1307
|
-
|
|
1336
|
+
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
1308
1337
|
);
|
|
1309
|
-
let entryChunk = viteManifest[rootRelativeFilePath +
|
|
1338
|
+
let entryChunk = viteManifest[rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
|
|
1310
1339
|
if (!entryChunk) {
|
|
1311
1340
|
let knownManifestKeys = Object.keys(viteManifest).map((key) => '"' + key + '"').join(", ");
|
|
1312
1341
|
throw new Error(
|
|
@@ -1356,7 +1385,7 @@ function dedupe(array2) {
|
|
|
1356
1385
|
return [...new Set(array2)];
|
|
1357
1386
|
}
|
|
1358
1387
|
var writeFileSafe = async (file, contents) => {
|
|
1359
|
-
await fse.ensureDir(
|
|
1388
|
+
await fse.ensureDir(path6.dirname(file));
|
|
1360
1389
|
await fse.writeFile(file, contents);
|
|
1361
1390
|
};
|
|
1362
1391
|
var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
|
|
@@ -1378,20 +1407,20 @@ var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteF
|
|
|
1378
1407
|
}
|
|
1379
1408
|
let ssr = true;
|
|
1380
1409
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
1381
|
-
let routePath =
|
|
1382
|
-
let
|
|
1410
|
+
let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
1411
|
+
let url2 = resolveFileUrl(ctx, routePath);
|
|
1383
1412
|
let resolveId = async () => {
|
|
1384
|
-
let result = await pluginContainer.resolveId(
|
|
1385
|
-
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}`);
|
|
1386
1415
|
return result.id;
|
|
1387
1416
|
};
|
|
1388
|
-
let [
|
|
1417
|
+
let [id, code] = await Promise.all([
|
|
1389
1418
|
resolveId(),
|
|
1390
1419
|
readRouteFile?.() ?? fse.readFile(routePath, "utf-8"),
|
|
1391
1420
|
// pluginContainer.transform(...) fails if we don't do this first:
|
|
1392
|
-
moduleGraph.ensureEntryFromUrl(
|
|
1421
|
+
moduleGraph.ensureEntryFromUrl(url2, ssr)
|
|
1393
1422
|
]);
|
|
1394
|
-
let transformed = await pluginContainer.transform(code,
|
|
1423
|
+
let transformed = await pluginContainer.transform(code, id, { ssr });
|
|
1395
1424
|
let [, exports2] = (0, import_es_module_lexer.parse)(transformed.code);
|
|
1396
1425
|
let exportNames = exports2.map((e) => e.n);
|
|
1397
1426
|
return exportNames;
|
|
@@ -1402,19 +1431,19 @@ var getServerBundleBuildConfig = (viteUserConfig) => {
|
|
|
1402
1431
|
}
|
|
1403
1432
|
return viteUserConfig.__reactRouterServerBundleBuildConfig;
|
|
1404
1433
|
};
|
|
1405
|
-
var getServerBuildDirectory = (ctx) =>
|
|
1434
|
+
var getServerBuildDirectory = (ctx) => path6.join(
|
|
1406
1435
|
ctx.reactRouterConfig.buildDirectory,
|
|
1407
1436
|
"server",
|
|
1408
1437
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
1409
1438
|
);
|
|
1410
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
1411
|
-
var defaultEntriesDir =
|
|
1412
|
-
|
|
1439
|
+
var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
|
|
1440
|
+
var defaultEntriesDir = path6.resolve(
|
|
1441
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1413
1442
|
"dist",
|
|
1414
1443
|
"config",
|
|
1415
1444
|
"defaults"
|
|
1416
1445
|
);
|
|
1417
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
1446
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path6.join(defaultEntriesDir, filename2));
|
|
1418
1447
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1419
1448
|
var reactRouterDevLoadContext = () => ({});
|
|
1420
1449
|
var reactRouterVitePlugin = () => {
|
|
@@ -1496,12 +1525,14 @@ var reactRouterVitePlugin = () => {
|
|
|
1496
1525
|
resolveFileUrl(
|
|
1497
1526
|
ctx,
|
|
1498
1527
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
1499
|
-
)
|
|
1528
|
+
)
|
|
1500
1529
|
)};`;
|
|
1501
1530
|
}).join("\n")}
|
|
1502
|
-
export { default as assets } from ${JSON.stringify(
|
|
1531
|
+
export { default as assets } from ${JSON.stringify(
|
|
1532
|
+
virtual.serverManifest.id
|
|
1533
|
+
)};
|
|
1503
1534
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
1504
|
-
|
|
1535
|
+
path6.relative(
|
|
1505
1536
|
ctx.rootDirectory,
|
|
1506
1537
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
1507
1538
|
)
|
|
@@ -1527,7 +1558,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1527
1558
|
};
|
|
1528
1559
|
let loadViteManifest = async (directory) => {
|
|
1529
1560
|
let manifestContents = await fse.readFile(
|
|
1530
|
-
|
|
1561
|
+
path6.resolve(directory, ".vite", "manifest.json"),
|
|
1531
1562
|
"utf-8"
|
|
1532
1563
|
);
|
|
1533
1564
|
return JSON.parse(manifestContents);
|
|
@@ -1563,7 +1594,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1563
1594
|
ctx
|
|
1564
1595
|
);
|
|
1565
1596
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
1566
|
-
let routeFilePath =
|
|
1597
|
+
let routeFilePath = path6.join(
|
|
1567
1598
|
ctx.reactRouterConfig.appDirectory,
|
|
1568
1599
|
route.file
|
|
1569
1600
|
);
|
|
@@ -1598,18 +1629,18 @@ var reactRouterVitePlugin = () => {
|
|
|
1598
1629
|
}
|
|
1599
1630
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
1600
1631
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
1601
|
-
let manifestPath =
|
|
1632
|
+
let manifestPath = path6.posix.join(
|
|
1602
1633
|
viteConfig.build.assetsDir,
|
|
1603
1634
|
`manifest-${version}.js`
|
|
1604
1635
|
);
|
|
1605
|
-
let
|
|
1606
|
-
let nonFingerprintedValues = { url:
|
|
1636
|
+
let url2 = `${ctx.publicPath}${manifestPath}`;
|
|
1637
|
+
let nonFingerprintedValues = { url: url2, version };
|
|
1607
1638
|
let reactRouterBrowserManifest = {
|
|
1608
1639
|
...fingerprintedValues,
|
|
1609
1640
|
...nonFingerprintedValues
|
|
1610
1641
|
};
|
|
1611
1642
|
await writeFileSafe(
|
|
1612
|
-
|
|
1643
|
+
path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
1613
1644
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
1614
1645
|
reactRouterBrowserManifest
|
|
1615
1646
|
)};`
|
|
@@ -1639,10 +1670,10 @@ var reactRouterVitePlugin = () => {
|
|
|
1639
1670
|
caseSensitive: route.caseSensitive,
|
|
1640
1671
|
module: combineURLs(
|
|
1641
1672
|
ctx.publicPath,
|
|
1642
|
-
|
|
1673
|
+
resolveFileUrl(
|
|
1643
1674
|
ctx,
|
|
1644
1675
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
1645
|
-
)
|
|
1676
|
+
)
|
|
1646
1677
|
),
|
|
1647
1678
|
hasAction: sourceExports.includes("action"),
|
|
1648
1679
|
hasLoader: sourceExports.includes("loader"),
|
|
@@ -1654,12 +1685,9 @@ var reactRouterVitePlugin = () => {
|
|
|
1654
1685
|
}
|
|
1655
1686
|
return {
|
|
1656
1687
|
version: String(Math.random()),
|
|
1657
|
-
url: combineURLs(ctx.publicPath, url
|
|
1688
|
+
url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
|
|
1658
1689
|
hmr: {
|
|
1659
|
-
runtime: combineURLs(
|
|
1660
|
-
ctx.publicPath,
|
|
1661
|
-
url(injectHmrRuntimeId)
|
|
1662
|
-
)
|
|
1690
|
+
runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
|
|
1663
1691
|
},
|
|
1664
1692
|
entry: {
|
|
1665
1693
|
module: combineURLs(
|
|
@@ -1675,11 +1703,17 @@ var reactRouterVitePlugin = () => {
|
|
|
1675
1703
|
{
|
|
1676
1704
|
name: "react-router",
|
|
1677
1705
|
config: async (_viteUserConfig, _viteConfigEnv) => {
|
|
1678
|
-
await
|
|
1679
|
-
let vite2 =
|
|
1706
|
+
await preloadVite();
|
|
1707
|
+
let vite2 = getVite();
|
|
1680
1708
|
viteUserConfig = _viteUserConfig;
|
|
1681
1709
|
viteConfigEnv = _viteConfigEnv;
|
|
1682
1710
|
viteCommand = viteConfigEnv.command;
|
|
1711
|
+
let viteClientConditions = [
|
|
1712
|
+
...vite2.defaultClientConditions ?? []
|
|
1713
|
+
];
|
|
1714
|
+
let viteServerConditions = [
|
|
1715
|
+
...vite2.defaultServerConditions ?? []
|
|
1716
|
+
];
|
|
1683
1717
|
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
1684
1718
|
prefix: "[react-router]"
|
|
1685
1719
|
});
|
|
@@ -1729,15 +1763,15 @@ var reactRouterVitePlugin = () => {
|
|
|
1729
1763
|
ssr: {
|
|
1730
1764
|
external: ssrExternals,
|
|
1731
1765
|
resolve: {
|
|
1732
|
-
conditions: viteCommand === "build" ?
|
|
1733
|
-
externalConditions: viteCommand === "build" ?
|
|
1766
|
+
conditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions],
|
|
1767
|
+
externalConditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions]
|
|
1734
1768
|
}
|
|
1735
1769
|
},
|
|
1736
1770
|
optimizeDeps: {
|
|
1737
1771
|
entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
|
|
1738
1772
|
ctx.entryClientFilePath,
|
|
1739
1773
|
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1740
|
-
(route) =>
|
|
1774
|
+
(route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
|
|
1741
1775
|
)
|
|
1742
1776
|
] : [],
|
|
1743
1777
|
include: [
|
|
@@ -1771,7 +1805,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1771
1805
|
"react-router/dom",
|
|
1772
1806
|
"react-router-dom"
|
|
1773
1807
|
],
|
|
1774
|
-
conditions: viteCommand === "build" ?
|
|
1808
|
+
conditions: viteCommand === "build" ? viteClientConditions : ["development", ...viteClientConditions]
|
|
1775
1809
|
},
|
|
1776
1810
|
base: viteUserConfig.base,
|
|
1777
1811
|
// When consumer provides an allow list for files that can be read by
|
|
@@ -1793,10 +1827,10 @@ var reactRouterVitePlugin = () => {
|
|
|
1793
1827
|
input: [
|
|
1794
1828
|
ctx.entryClientFilePath,
|
|
1795
1829
|
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1796
|
-
(route) => `${
|
|
1830
|
+
(route) => `${path6.resolve(
|
|
1797
1831
|
ctx.reactRouterConfig.appDirectory,
|
|
1798
1832
|
route.file
|
|
1799
|
-
)}${
|
|
1833
|
+
)}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
|
|
1800
1834
|
)
|
|
1801
1835
|
]
|
|
1802
1836
|
}
|
|
@@ -1815,7 +1849,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1815
1849
|
rollupOptions: {
|
|
1816
1850
|
...baseRollupOptions,
|
|
1817
1851
|
preserveEntrySignatures: "exports-only",
|
|
1818
|
-
input: viteUserConfig.build?.rollupOptions?.input ??
|
|
1852
|
+
input: viteUserConfig.build?.rollupOptions?.input ?? virtual.serverBuild.id,
|
|
1819
1853
|
output: {
|
|
1820
1854
|
entryFileNames: ctx.reactRouterConfig.serverBuildFile,
|
|
1821
1855
|
format: ctx.reactRouterConfig.serverModuleFormat
|
|
@@ -1842,7 +1876,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1842
1876
|
"The React Router Vite plugin requires the use of a Vite config file"
|
|
1843
1877
|
);
|
|
1844
1878
|
}
|
|
1845
|
-
let vite2 =
|
|
1879
|
+
let vite2 = getVite();
|
|
1846
1880
|
let childCompilerConfigFile = await vite2.loadConfigFromFile(
|
|
1847
1881
|
{
|
|
1848
1882
|
command: viteConfig.command,
|
|
@@ -1878,15 +1912,15 @@ var reactRouterVitePlugin = () => {
|
|
|
1878
1912
|
envFile: false,
|
|
1879
1913
|
plugins: [
|
|
1880
1914
|
...(childCompilerConfigFile.config.plugins ?? []).flat().filter(
|
|
1881
|
-
(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"
|
|
1882
1916
|
)
|
|
1883
1917
|
]
|
|
1884
1918
|
});
|
|
1885
1919
|
await viteChildCompiler.pluginContainer.buildStart({});
|
|
1886
1920
|
},
|
|
1887
|
-
async transform(code,
|
|
1888
|
-
if (isCssModulesFile(
|
|
1889
|
-
cssModulesManifest[
|
|
1921
|
+
async transform(code, id) {
|
|
1922
|
+
if (isCssModulesFile(id)) {
|
|
1923
|
+
cssModulesManifest[id] = code;
|
|
1890
1924
|
}
|
|
1891
1925
|
},
|
|
1892
1926
|
buildStart() {
|
|
@@ -1910,7 +1944,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1910
1944
|
(0, import_react_router2.unstable_setDevServerHooks)({
|
|
1911
1945
|
// Give the request handler access to the critical CSS in dev to avoid a
|
|
1912
1946
|
// flash of unstyled content since Vite injects CSS file contents via JS
|
|
1913
|
-
getCriticalCss: async (build,
|
|
1947
|
+
getCriticalCss: async (build, url2) => {
|
|
1914
1948
|
return getStylesForUrl({
|
|
1915
1949
|
rootDirectory: ctx.rootDirectory,
|
|
1916
1950
|
entryClientFilePath: ctx.entryClientFilePath,
|
|
@@ -1918,7 +1952,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1918
1952
|
viteDevServer,
|
|
1919
1953
|
cssModulesManifest,
|
|
1920
1954
|
build,
|
|
1921
|
-
url:
|
|
1955
|
+
url: url2
|
|
1922
1956
|
});
|
|
1923
1957
|
},
|
|
1924
1958
|
// If an error is caught within the request handler, let Vite fix the
|
|
@@ -1966,7 +2000,7 @@ var reactRouterVitePlugin = () => {
|
|
|
1966
2000
|
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
1967
2001
|
try {
|
|
1968
2002
|
let build = await viteDevServer.ssrLoadModule(
|
|
1969
|
-
|
|
2003
|
+
virtual.serverBuild.id
|
|
1970
2004
|
);
|
|
1971
2005
|
let handler = (0, import_react_router2.createRequestHandler)(build, "development");
|
|
1972
2006
|
let nodeHandler = async (nodeReq, nodeRes) => {
|
|
@@ -2001,8 +2035,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2001
2035
|
let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
|
|
2002
2036
|
let movedAssetPaths = [];
|
|
2003
2037
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
2004
|
-
let src =
|
|
2005
|
-
let dest =
|
|
2038
|
+
let src = path6.join(serverBuildDirectory, ssrAssetPath);
|
|
2039
|
+
let dest = path6.join(clientBuildDirectory, ssrAssetPath);
|
|
2006
2040
|
if (!fse.existsSync(dest)) {
|
|
2007
2041
|
await fse.move(src, dest);
|
|
2008
2042
|
movedAssetPaths.push(dest);
|
|
@@ -2015,7 +2049,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2015
2049
|
);
|
|
2016
2050
|
await Promise.all(
|
|
2017
2051
|
ssrCssPaths.map(
|
|
2018
|
-
(cssPath) => fse.remove(
|
|
2052
|
+
(cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
|
|
2019
2053
|
)
|
|
2020
2054
|
);
|
|
2021
2055
|
if (movedAssetPaths.length) {
|
|
@@ -2024,7 +2058,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2024
2058
|
"",
|
|
2025
2059
|
`${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
|
|
2026
2060
|
...movedAssetPaths.map(
|
|
2027
|
-
(movedAssetPath) => import_picocolors3.default.dim(
|
|
2061
|
+
(movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
|
|
2028
2062
|
),
|
|
2029
2063
|
""
|
|
2030
2064
|
].join("\n")
|
|
@@ -2066,12 +2100,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2066
2100
|
}
|
|
2067
2101
|
},
|
|
2068
2102
|
{
|
|
2069
|
-
name: "react-router-route
|
|
2103
|
+
name: "react-router:build-client-route",
|
|
2070
2104
|
enforce: "pre",
|
|
2071
|
-
async transform(_code,
|
|
2072
|
-
if (!
|
|
2073
|
-
let routeModuleId =
|
|
2074
|
-
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);
|
|
2075
2109
|
let sourceExports = await getRouteModuleExports(
|
|
2076
2110
|
viteChildCompiler,
|
|
2077
2111
|
ctx,
|
|
@@ -2084,23 +2118,24 @@ var reactRouterVitePlugin = () => {
|
|
|
2084
2118
|
}
|
|
2085
2119
|
},
|
|
2086
2120
|
{
|
|
2087
|
-
name: "react-router
|
|
2121
|
+
name: "react-router:virtual-modules",
|
|
2088
2122
|
enforce: "pre",
|
|
2089
|
-
resolveId(
|
|
2090
|
-
|
|
2123
|
+
resolveId(id) {
|
|
2124
|
+
const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
|
|
2125
|
+
if (vmod2) return vmod2.resolvedId;
|
|
2091
2126
|
},
|
|
2092
|
-
async load(
|
|
2093
|
-
switch (
|
|
2094
|
-
case
|
|
2127
|
+
async load(id) {
|
|
2128
|
+
switch (id) {
|
|
2129
|
+
case virtual.serverBuild.resolvedId: {
|
|
2095
2130
|
return await getServerEntry();
|
|
2096
2131
|
}
|
|
2097
|
-
case
|
|
2132
|
+
case virtual.serverManifest.resolvedId: {
|
|
2098
2133
|
let reactRouterManifest = ctx.isSsrBuild ? await ctx.getReactRouterServerManifest() : await getReactRouterManifestForDev();
|
|
2099
2134
|
return `export default ${(0, import_jsesc.default)(reactRouterManifest, {
|
|
2100
2135
|
es6: true
|
|
2101
2136
|
})};`;
|
|
2102
2137
|
}
|
|
2103
|
-
case
|
|
2138
|
+
case virtual.browserManifest.resolvedId: {
|
|
2104
2139
|
if (viteCommand === "build") {
|
|
2105
2140
|
throw new Error("This module only exists in development");
|
|
2106
2141
|
}
|
|
@@ -2114,15 +2149,15 @@ var reactRouterVitePlugin = () => {
|
|
|
2114
2149
|
}
|
|
2115
2150
|
},
|
|
2116
2151
|
{
|
|
2117
|
-
name: "react-router
|
|
2152
|
+
name: "react-router:dot-server",
|
|
2118
2153
|
enforce: "pre",
|
|
2119
|
-
async resolveId(
|
|
2154
|
+
async resolveId(id, importer, options) {
|
|
2120
2155
|
let isOptimizeDeps = viteCommand === "serve" && options?.scan === true;
|
|
2121
2156
|
if (isOptimizeDeps || options?.ssr) return;
|
|
2122
|
-
let isResolving = options?.custom?.["react-router
|
|
2157
|
+
let isResolving = options?.custom?.["react-router:dot-server"] ?? false;
|
|
2123
2158
|
if (isResolving) return;
|
|
2124
|
-
options.custom = { ...options.custom, "react-router
|
|
2125
|
-
let resolved = await this.resolve(
|
|
2159
|
+
options.custom = { ...options.custom, "react-router:dot-server": true };
|
|
2160
|
+
let resolved = await this.resolve(id, importer, options);
|
|
2126
2161
|
if (!resolved) return;
|
|
2127
2162
|
let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
|
|
2128
2163
|
let serverDirRE = /\/\.server\//;
|
|
@@ -2132,9 +2167,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2132
2167
|
if (viteCommand !== "build" && importer.endsWith(".html")) {
|
|
2133
2168
|
return;
|
|
2134
2169
|
}
|
|
2135
|
-
let vite2 =
|
|
2170
|
+
let vite2 = getVite();
|
|
2136
2171
|
let importerShort = vite2.normalizePath(
|
|
2137
|
-
|
|
2172
|
+
path6.relative(ctx.rootDirectory, importer)
|
|
2138
2173
|
);
|
|
2139
2174
|
let isRoute = getRoute(ctx.reactRouterConfig, importer);
|
|
2140
2175
|
if (isRoute) {
|
|
@@ -2145,12 +2180,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2145
2180
|
[
|
|
2146
2181
|
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
2147
2182
|
"",
|
|
2148
|
-
` '${
|
|
2183
|
+
` '${id}' imported by route '${importerShort}'`,
|
|
2149
2184
|
"",
|
|
2150
2185
|
` React Router automatically removes server-code from these exports:`,
|
|
2151
2186
|
` ${serverOnlyExports}`,
|
|
2152
2187
|
"",
|
|
2153
|
-
` But other route exports in '${importerShort}' depend on '${
|
|
2188
|
+
` But other route exports in '${importerShort}' depend on '${id}'.`,
|
|
2154
2189
|
"",
|
|
2155
2190
|
" See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
|
|
2156
2191
|
""
|
|
@@ -2161,7 +2196,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2161
2196
|
[
|
|
2162
2197
|
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
2163
2198
|
"",
|
|
2164
|
-
` '${
|
|
2199
|
+
` '${id}' imported by '${importerShort}'`,
|
|
2165
2200
|
"",
|
|
2166
2201
|
" See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
|
|
2167
2202
|
""
|
|
@@ -2170,12 +2205,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2170
2205
|
}
|
|
2171
2206
|
},
|
|
2172
2207
|
{
|
|
2173
|
-
name: "react-router
|
|
2174
|
-
async transform(code,
|
|
2208
|
+
name: "react-router:dot-client",
|
|
2209
|
+
async transform(code, id, options) {
|
|
2175
2210
|
if (!options?.ssr) return;
|
|
2176
2211
|
let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
|
|
2177
2212
|
let clientDirRE = /\/\.client\//;
|
|
2178
|
-
if (clientFileRE.test(
|
|
2213
|
+
if (clientFileRE.test(id) || clientDirRE.test(id)) {
|
|
2179
2214
|
let exports2 = (0, import_es_module_lexer.parse)(code)[1];
|
|
2180
2215
|
return {
|
|
2181
2216
|
code: exports2.map(
|
|
@@ -2188,9 +2223,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2188
2223
|
},
|
|
2189
2224
|
plugin,
|
|
2190
2225
|
{
|
|
2191
|
-
name: "react-router
|
|
2192
|
-
async transform(code,
|
|
2193
|
-
let route = getRoute(ctx.reactRouterConfig,
|
|
2226
|
+
name: "react-router:route-exports",
|
|
2227
|
+
async transform(code, id, options) {
|
|
2228
|
+
let route = getRoute(ctx.reactRouterConfig, id);
|
|
2194
2229
|
if (!route) return;
|
|
2195
2230
|
if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
|
|
2196
2231
|
let serverOnlyExports = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));
|
|
@@ -2207,7 +2242,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2207
2242
|
}
|
|
2208
2243
|
}
|
|
2209
2244
|
}
|
|
2210
|
-
let [filepath] =
|
|
2245
|
+
let [filepath] = id.split("?");
|
|
2211
2246
|
let ast = (0, import_parser.parse)(code, { sourceType: "module" });
|
|
2212
2247
|
if (!options?.ssr) {
|
|
2213
2248
|
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
|
|
@@ -2215,22 +2250,23 @@ var reactRouterVitePlugin = () => {
|
|
|
2215
2250
|
transform(ast);
|
|
2216
2251
|
return generate2(ast, {
|
|
2217
2252
|
sourceMaps: true,
|
|
2218
|
-
filename:
|
|
2253
|
+
filename: id,
|
|
2219
2254
|
sourceFileName: filepath
|
|
2220
2255
|
});
|
|
2221
2256
|
}
|
|
2222
2257
|
},
|
|
2223
2258
|
{
|
|
2224
|
-
name: "react-router
|
|
2259
|
+
name: "react-router:inject-hmr-runtime",
|
|
2225
2260
|
enforce: "pre",
|
|
2226
|
-
resolveId(
|
|
2227
|
-
if (
|
|
2228
|
-
return
|
|
2261
|
+
resolveId(id) {
|
|
2262
|
+
if (id === virtualInjectHmrRuntime.id) {
|
|
2263
|
+
return virtualInjectHmrRuntime.resolvedId;
|
|
2264
|
+
}
|
|
2229
2265
|
},
|
|
2230
|
-
async load(
|
|
2231
|
-
if (
|
|
2266
|
+
async load(id) {
|
|
2267
|
+
if (id !== virtualInjectHmrRuntime.resolvedId) return;
|
|
2232
2268
|
return [
|
|
2233
|
-
`import RefreshRuntime from "${
|
|
2269
|
+
`import RefreshRuntime from "${virtualHmrRuntime.id}"`,
|
|
2234
2270
|
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
2235
2271
|
"window.$RefreshReg$ = () => {}",
|
|
2236
2272
|
"window.$RefreshSig$ = () => (type) => type",
|
|
@@ -2239,17 +2275,17 @@ var reactRouterVitePlugin = () => {
|
|
|
2239
2275
|
}
|
|
2240
2276
|
},
|
|
2241
2277
|
{
|
|
2242
|
-
name: "react-router
|
|
2278
|
+
name: "react-router:hmr-runtime",
|
|
2243
2279
|
enforce: "pre",
|
|
2244
|
-
resolveId(
|
|
2245
|
-
if (
|
|
2280
|
+
resolveId(id) {
|
|
2281
|
+
if (id === virtualHmrRuntime.id) return virtualHmrRuntime.resolvedId;
|
|
2246
2282
|
},
|
|
2247
|
-
async load(
|
|
2248
|
-
if (
|
|
2249
|
-
let reactRefreshDir =
|
|
2283
|
+
async load(id) {
|
|
2284
|
+
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
2285
|
+
let reactRefreshDir = path6.dirname(
|
|
2250
2286
|
require.resolve("react-refresh/package.json")
|
|
2251
2287
|
);
|
|
2252
|
-
let reactRefreshRuntimePath =
|
|
2288
|
+
let reactRefreshRuntimePath = path6.join(
|
|
2253
2289
|
reactRefreshDir,
|
|
2254
2290
|
"cjs/react-refresh-runtime.development.js"
|
|
2255
2291
|
);
|
|
@@ -2265,11 +2301,11 @@ var reactRouterVitePlugin = () => {
|
|
|
2265
2301
|
}
|
|
2266
2302
|
},
|
|
2267
2303
|
{
|
|
2268
|
-
name: "react-router
|
|
2269
|
-
async transform(code,
|
|
2304
|
+
name: "react-router:react-refresh-babel",
|
|
2305
|
+
async transform(code, id, options) {
|
|
2270
2306
|
if (viteCommand !== "serve") return;
|
|
2271
|
-
if (
|
|
2272
|
-
let [filepath] =
|
|
2307
|
+
if (id.includes("/node_modules/")) return;
|
|
2308
|
+
let [filepath] = id.split("?");
|
|
2273
2309
|
let extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
2274
2310
|
if (!extensionsRE.test(filepath)) return;
|
|
2275
2311
|
let devRuntime = "react/jsx-dev-runtime";
|
|
@@ -2277,13 +2313,10 @@ var reactRouterVitePlugin = () => {
|
|
|
2277
2313
|
let isJSX = filepath.endsWith("x");
|
|
2278
2314
|
let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
2279
2315
|
if (!useFastRefresh) return;
|
|
2280
|
-
if (isRouteEntry(id2)) {
|
|
2281
|
-
return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id2) };
|
|
2282
|
-
}
|
|
2283
2316
|
let result = await babel.transformAsync(code, {
|
|
2284
2317
|
babelrc: false,
|
|
2285
2318
|
configFile: false,
|
|
2286
|
-
filename:
|
|
2319
|
+
filename: id,
|
|
2287
2320
|
sourceFileName: filepath,
|
|
2288
2321
|
parserOpts: {
|
|
2289
2322
|
sourceType: "module",
|
|
@@ -2296,18 +2329,18 @@ var reactRouterVitePlugin = () => {
|
|
|
2296
2329
|
code = result.code;
|
|
2297
2330
|
let refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
2298
2331
|
if (refreshContentRE.test(code)) {
|
|
2299
|
-
code = addRefreshWrapper(ctx.reactRouterConfig, code,
|
|
2332
|
+
code = addRefreshWrapper(ctx.reactRouterConfig, code, id);
|
|
2300
2333
|
}
|
|
2301
2334
|
return { code, map: result.map };
|
|
2302
2335
|
}
|
|
2303
2336
|
},
|
|
2304
2337
|
{
|
|
2305
|
-
name: "react-router
|
|
2338
|
+
name: "react-router:hmr-updates",
|
|
2306
2339
|
async handleHotUpdate({ server, file, modules, read }) {
|
|
2307
2340
|
let route = getRoute(ctx.reactRouterConfig, file);
|
|
2308
2341
|
let hmrEventData = { route: null };
|
|
2309
2342
|
if (route) {
|
|
2310
|
-
let serverManifest = (await server.ssrLoadModule(
|
|
2343
|
+
let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
|
|
2311
2344
|
let oldRouteMetadata = serverManifest.routes[route.id];
|
|
2312
2345
|
let newRouteMetadata = await getRouteMetadata(
|
|
2313
2346
|
ctx,
|
|
@@ -2333,39 +2366,69 @@ var reactRouterVitePlugin = () => {
|
|
|
2333
2366
|
});
|
|
2334
2367
|
return modules;
|
|
2335
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
|
+
}
|
|
2336
2391
|
}
|
|
2337
2392
|
];
|
|
2338
2393
|
};
|
|
2339
|
-
function
|
|
2340
|
-
|
|
2341
|
-
|
|
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 ? [
|
|
2342
2421
|
"clientAction",
|
|
2343
2422
|
"clientLoader",
|
|
2344
|
-
"clientMiddleware",
|
|
2345
2423
|
"handle",
|
|
2346
2424
|
"meta",
|
|
2347
2425
|
"links",
|
|
2348
2426
|
"shouldRevalidate"
|
|
2349
2427
|
] : [];
|
|
2350
|
-
return "
|
|
2351
|
-
"REACT REFRESH HEADER",
|
|
2352
|
-
REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id2))
|
|
2353
|
-
) + "\n\n" + withCommentBoundaries("REACT REFRESH BODY", code) + "\n\n" + withCommentBoundaries(
|
|
2354
|
-
"REACT REFRESH FOOTER",
|
|
2355
|
-
REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id2)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(route?.id))
|
|
2356
|
-
) + "\n";
|
|
2357
|
-
}
|
|
2358
|
-
function withCommentBoundaries(label, text) {
|
|
2359
|
-
let begin = `// [BEGIN] ${label} `;
|
|
2360
|
-
begin += "-".repeat(80 - begin.length);
|
|
2361
|
-
let end = `// [END] ${label} `;
|
|
2362
|
-
end += "-".repeat(80 - end.length);
|
|
2363
|
-
return `${begin}
|
|
2364
|
-
${text}
|
|
2365
|
-
${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));
|
|
2366
2429
|
}
|
|
2367
2430
|
var REACT_REFRESH_HEADER = `
|
|
2368
|
-
import RefreshRuntime from "${
|
|
2431
|
+
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
2369
2432
|
|
|
2370
2433
|
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
2371
2434
|
let prevRefreshReg;
|
|
@@ -2384,7 +2447,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
2384
2447
|
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
2385
2448
|
};
|
|
2386
2449
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
2387
|
-
}`.
|
|
2450
|
+
}`.replaceAll("\n", "");
|
|
2388
2451
|
var REACT_REFRESH_FOOTER = `
|
|
2389
2452
|
if (import.meta.hot && !inWebWorker) {
|
|
2390
2453
|
window.$RefreshReg$ = prevRefreshReg;
|
|
@@ -2398,11 +2461,11 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
2398
2461
|
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
2399
2462
|
});
|
|
2400
2463
|
});
|
|
2401
|
-
}
|
|
2464
|
+
}`;
|
|
2402
2465
|
function getRoute(pluginConfig, file) {
|
|
2403
|
-
let vite2 =
|
|
2466
|
+
let vite2 = getVite();
|
|
2404
2467
|
let routePath = vite2.normalizePath(
|
|
2405
|
-
|
|
2468
|
+
path6.relative(pluginConfig.appDirectory, file)
|
|
2406
2469
|
);
|
|
2407
2470
|
let route = Object.values(pluginConfig.routes).find(
|
|
2408
2471
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -2424,7 +2487,7 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
|
2424
2487
|
caseSensitive: route.caseSensitive,
|
|
2425
2488
|
url: combineURLs(
|
|
2426
2489
|
ctx.publicPath,
|
|
2427
|
-
"/" +
|
|
2490
|
+
"/" + path6.relative(
|
|
2428
2491
|
ctx.rootDirectory,
|
|
2429
2492
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2430
2493
|
)
|
|
@@ -2447,11 +2510,11 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
|
2447
2510
|
return info;
|
|
2448
2511
|
}
|
|
2449
2512
|
async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
|
|
2450
|
-
let serverBuildPath =
|
|
2513
|
+
let serverBuildPath = path6.join(
|
|
2451
2514
|
serverBuildDirectory,
|
|
2452
2515
|
reactRouterConfig.serverBuildFile
|
|
2453
2516
|
);
|
|
2454
|
-
let build = await import(
|
|
2517
|
+
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
2455
2518
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
2456
2519
|
return {
|
|
2457
2520
|
build,
|
|
@@ -2469,9 +2532,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
2469
2532
|
let html = await response.text();
|
|
2470
2533
|
validatePrerenderedResponse(response, html, "SPA Mode", "/");
|
|
2471
2534
|
validatePrerenderedHtml(html, "SPA Mode");
|
|
2472
|
-
await fse.writeFile(
|
|
2535
|
+
await fse.writeFile(path6.join(clientBuildDirectory, "index.html"), html);
|
|
2473
2536
|
viteConfig.logger.info(
|
|
2474
|
-
"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"
|
|
2475
2538
|
);
|
|
2476
2539
|
}
|
|
2477
2540
|
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
|
|
@@ -2501,14 +2564,14 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2501
2564
|
// build time or runtime
|
|
2502
2565
|
"X-React-Router-Prerender": "yes"
|
|
2503
2566
|
};
|
|
2504
|
-
for (let
|
|
2505
|
-
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(/^\/\/+/, "/"));
|
|
2506
2569
|
let hasLoaders = matches?.some((m) => m.route.loader);
|
|
2507
2570
|
let data;
|
|
2508
2571
|
if (hasLoaders) {
|
|
2509
2572
|
data = await prerenderData(
|
|
2510
2573
|
handler,
|
|
2511
|
-
|
|
2574
|
+
path7,
|
|
2512
2575
|
clientBuildDirectory,
|
|
2513
2576
|
reactRouterConfig,
|
|
2514
2577
|
viteConfig,
|
|
@@ -2521,7 +2584,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2521
2584
|
if (isResourceRoute) {
|
|
2522
2585
|
await prerenderResourceRoute(
|
|
2523
2586
|
handler,
|
|
2524
|
-
|
|
2587
|
+
path7,
|
|
2525
2588
|
clientBuildDirectory,
|
|
2526
2589
|
reactRouterConfig,
|
|
2527
2590
|
viteConfig,
|
|
@@ -2530,7 +2593,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2530
2593
|
} else {
|
|
2531
2594
|
await prerenderRoute(
|
|
2532
2595
|
handler,
|
|
2533
|
-
|
|
2596
|
+
path7,
|
|
2534
2597
|
clientBuildDirectory,
|
|
2535
2598
|
reactRouterConfig,
|
|
2536
2599
|
viteConfig,
|
|
@@ -2587,9 +2650,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
|
|
|
2587
2650
|
let response = await handler(request);
|
|
2588
2651
|
let data = await response.text();
|
|
2589
2652
|
validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
|
|
2590
|
-
let outdir =
|
|
2591
|
-
let outfile =
|
|
2592
|
-
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));
|
|
2593
2656
|
await fse.outputFile(outfile, data);
|
|
2594
2657
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2595
2658
|
return data;
|
|
@@ -2606,9 +2669,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
2606
2669
|
if (!reactRouterConfig.ssr) {
|
|
2607
2670
|
validatePrerenderedHtml(html, "Prerender");
|
|
2608
2671
|
}
|
|
2609
|
-
let outdir =
|
|
2610
|
-
let outfile =
|
|
2611
|
-
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));
|
|
2612
2675
|
await fse.outputFile(outfile, html);
|
|
2613
2676
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2614
2677
|
}
|
|
@@ -2618,9 +2681,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
2618
2681
|
let response = await handler(request);
|
|
2619
2682
|
let text = await response.text();
|
|
2620
2683
|
validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
|
|
2621
|
-
let outdir =
|
|
2622
|
-
let outfile =
|
|
2623
|
-
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));
|
|
2624
2687
|
await fse.outputFile(outfile, text);
|
|
2625
2688
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2626
2689
|
}
|
|
@@ -2629,17 +2692,17 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
|
|
|
2629
2692
|
/\/\/+/g,
|
|
2630
2693
|
"/"
|
|
2631
2694
|
);
|
|
2632
|
-
let outdir =
|
|
2633
|
-
let outfile =
|
|
2634
|
-
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));
|
|
2635
2698
|
let manifestData = JSON.stringify(build.assets.routes);
|
|
2636
2699
|
await fse.outputFile(outfile, manifestData);
|
|
2637
2700
|
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2638
2701
|
}
|
|
2639
|
-
function validatePrerenderedResponse(response, html, prefix,
|
|
2702
|
+
function validatePrerenderedResponse(response, html, prefix, path7) {
|
|
2640
2703
|
if (response.status !== 200) {
|
|
2641
2704
|
throw new Error(
|
|
2642
|
-
`${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.
|
|
2643
2706
|
${html}`
|
|
2644
2707
|
);
|
|
2645
2708
|
}
|
|
@@ -2674,8 +2737,6 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
|
|
|
2674
2737
|
loader: route.module.loader ? () => null : void 0,
|
|
2675
2738
|
action: void 0,
|
|
2676
2739
|
handle: route.module.handle
|
|
2677
|
-
// middleware is not necessary here since we just need to know which
|
|
2678
|
-
// routes have loaders so we know what paths to prerender
|
|
2679
2740
|
};
|
|
2680
2741
|
return route.index ? {
|
|
2681
2742
|
index: true,
|