@react-router/dev 0.0.0-experimental-795b50c5b → 0.0.0-experimental-4cf5bd08c
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 +31 -0
- package/dist/cli/index.js +206 -86
- package/dist/config/default-rsc-entries/entry.rsc.tsx +6 -0
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +20 -6
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +1199 -256
- package/package.json +11 -11
- package/dist/internal.d.ts +0 -9
- package/dist/internal.js +0 -2016
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-4cf5bd08c
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -40,7 +40,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
40
40
|
// vite.ts
|
|
41
41
|
var vite_exports = {};
|
|
42
42
|
__export(vite_exports, {
|
|
43
|
-
reactRouter: () => reactRouterVitePlugin
|
|
43
|
+
reactRouter: () => reactRouterVitePlugin,
|
|
44
|
+
unstable_reactRouterRSC: () => reactRouterRSCVitePlugin
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(vite_exports);
|
|
46
47
|
|
|
@@ -48,15 +49,14 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
48
49
|
var import_node_crypto = require("crypto");
|
|
49
50
|
var import_node_fs2 = require("fs");
|
|
50
51
|
var import_promises2 = require("fs/promises");
|
|
51
|
-
var
|
|
52
|
+
var path6 = __toESM(require("path"));
|
|
52
53
|
var url = __toESM(require("url"));
|
|
53
54
|
var babel = __toESM(require("@babel/core"));
|
|
54
55
|
var import_react_router2 = require("react-router");
|
|
55
56
|
var import_es_module_lexer = require("es-module-lexer");
|
|
56
|
-
var import_tinyglobby = require("tinyglobby");
|
|
57
57
|
var import_pick3 = __toESM(require("lodash/pick"));
|
|
58
58
|
var import_jsesc = __toESM(require("jsesc"));
|
|
59
|
-
var
|
|
59
|
+
var import_picocolors4 = __toESM(require("picocolors"));
|
|
60
60
|
var import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
61
61
|
|
|
62
62
|
// typegen/index.ts
|
|
@@ -247,7 +247,7 @@ function validateRouteConfig({
|
|
|
247
247
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
248
248
|
root ? `${root}` : [],
|
|
249
249
|
nested ? Object.entries(nested).map(
|
|
250
|
-
([
|
|
250
|
+
([path9, message]) => `Path: routes.${path9}
|
|
251
251
|
${message}`
|
|
252
252
|
) : []
|
|
253
253
|
].flat().join("\n\n")
|
|
@@ -367,7 +367,8 @@ async function resolveConfig({
|
|
|
367
367
|
root,
|
|
368
368
|
viteNodeContext,
|
|
369
369
|
reactRouterConfigFile,
|
|
370
|
-
skipRoutes
|
|
370
|
+
skipRoutes,
|
|
371
|
+
validateConfig
|
|
371
372
|
}) {
|
|
372
373
|
let reactRouterUserConfig = {};
|
|
373
374
|
if (reactRouterConfigFile) {
|
|
@@ -385,6 +386,12 @@ async function resolveConfig({
|
|
|
385
386
|
return err(`${reactRouterConfigFile} must export a config`);
|
|
386
387
|
}
|
|
387
388
|
reactRouterUserConfig = configModule.default;
|
|
389
|
+
if (validateConfig) {
|
|
390
|
+
const error = validateConfig(reactRouterUserConfig);
|
|
391
|
+
if (error) {
|
|
392
|
+
return err(error);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
388
395
|
} catch (error) {
|
|
389
396
|
return err(`Error loading ${reactRouterConfigFile}: ${error}`);
|
|
390
397
|
}
|
|
@@ -473,7 +480,7 @@ async function resolveConfig({
|
|
|
473
480
|
}
|
|
474
481
|
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
475
482
|
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
476
|
-
let rootRouteFile = findEntry(appDirectory, "root");
|
|
483
|
+
let rootRouteFile = findEntry(appDirectory, "root", { absolute: true });
|
|
477
484
|
if (!rootRouteFile) {
|
|
478
485
|
let rootRouteDisplayPath = import_pathe3.default.relative(
|
|
479
486
|
root,
|
|
@@ -514,7 +521,7 @@ async function resolveConfig({
|
|
|
514
521
|
{
|
|
515
522
|
id: "root",
|
|
516
523
|
path: "",
|
|
517
|
-
file: rootRouteFile,
|
|
524
|
+
file: import_pathe3.default.relative(appDirectory, rootRouteFile),
|
|
518
525
|
children: result.routeConfig
|
|
519
526
|
}
|
|
520
527
|
];
|
|
@@ -563,7 +570,8 @@ async function createConfigLoader({
|
|
|
563
570
|
rootDirectory: root,
|
|
564
571
|
watch: watch2,
|
|
565
572
|
mode,
|
|
566
|
-
skipRoutes
|
|
573
|
+
skipRoutes,
|
|
574
|
+
validateConfig
|
|
567
575
|
}) {
|
|
568
576
|
root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
|
|
569
577
|
let vite2 = await import("vite");
|
|
@@ -582,7 +590,13 @@ async function createConfigLoader({
|
|
|
582
590
|
});
|
|
583
591
|
};
|
|
584
592
|
updateReactRouterConfigFile();
|
|
585
|
-
let getConfig = () => resolveConfig({
|
|
593
|
+
let getConfig = () => resolveConfig({
|
|
594
|
+
root,
|
|
595
|
+
viteNodeContext,
|
|
596
|
+
reactRouterConfigFile,
|
|
597
|
+
skipRoutes,
|
|
598
|
+
validateConfig
|
|
599
|
+
});
|
|
586
600
|
let appDirectory;
|
|
587
601
|
let initialConfigResult = await getConfig();
|
|
588
602
|
if (!initialConfigResult.ok) {
|
|
@@ -604,12 +618,12 @@ async function createConfigLoader({
|
|
|
604
618
|
if (!fsWatcher) {
|
|
605
619
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
606
620
|
ignoreInitial: true,
|
|
607
|
-
ignored: (
|
|
608
|
-
let
|
|
609
|
-
return !
|
|
621
|
+
ignored: (path9) => {
|
|
622
|
+
let dirname5 = import_pathe3.default.dirname(path9);
|
|
623
|
+
return !dirname5.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
610
624
|
// that are at the root level, not nested in subdirectories
|
|
611
|
-
|
|
612
|
-
|
|
625
|
+
path9 !== root && // Watch the root directory itself
|
|
626
|
+
dirname5 !== root;
|
|
613
627
|
}
|
|
614
628
|
});
|
|
615
629
|
fsWatcher.on("all", async (...args) => {
|
|
@@ -801,7 +815,8 @@ function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /
|
|
|
801
815
|
async function createContext2({
|
|
802
816
|
rootDirectory,
|
|
803
817
|
watch: watch2,
|
|
804
|
-
mode
|
|
818
|
+
mode,
|
|
819
|
+
rsc
|
|
805
820
|
}) {
|
|
806
821
|
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
807
822
|
const configResult = await configLoader.getConfig();
|
|
@@ -812,7 +827,8 @@ async function createContext2({
|
|
|
812
827
|
return {
|
|
813
828
|
configLoader,
|
|
814
829
|
rootDirectory,
|
|
815
|
-
config
|
|
830
|
+
config,
|
|
831
|
+
rsc
|
|
816
832
|
};
|
|
817
833
|
}
|
|
818
834
|
|
|
@@ -867,7 +883,7 @@ function fullpath(lineage2) {
|
|
|
867
883
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
868
884
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
869
885
|
if (isLayout) return void 0;
|
|
870
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
886
|
+
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
|
|
871
887
|
}
|
|
872
888
|
|
|
873
889
|
// typegen/generate.ts
|
|
@@ -883,7 +899,7 @@ function generateFuture(ctx) {
|
|
|
883
899
|
|
|
884
900
|
declare module "react-router" {
|
|
885
901
|
interface Future {
|
|
886
|
-
|
|
902
|
+
v8_middleware: ${ctx.config.future.v8_middleware}
|
|
887
903
|
}
|
|
888
904
|
}
|
|
889
905
|
`;
|
|
@@ -1023,8 +1039,8 @@ function routeFilesType({
|
|
|
1023
1039
|
);
|
|
1024
1040
|
}
|
|
1025
1041
|
function isInAppDirectory(ctx, routeFile) {
|
|
1026
|
-
const
|
|
1027
|
-
return
|
|
1042
|
+
const path9 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1043
|
+
return path9.startsWith(ctx.config.appDirectory);
|
|
1028
1044
|
}
|
|
1029
1045
|
function getRouteAnnotations({
|
|
1030
1046
|
ctx,
|
|
@@ -1089,7 +1105,7 @@ function getRouteAnnotations({
|
|
|
1089
1105
|
module: Module
|
|
1090
1106
|
}>
|
|
1091
1107
|
` + "\n\n" + generate(matchesType).code + "\n\n" + import_dedent.default`
|
|
1092
|
-
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }>;
|
|
1108
|
+
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }, ${ctx.rsc}>;
|
|
1093
1109
|
|
|
1094
1110
|
export namespace Route {
|
|
1095
1111
|
// links
|
|
@@ -1136,21 +1152,21 @@ function getRouteAnnotations({
|
|
|
1136
1152
|
return { filename: filename2, content };
|
|
1137
1153
|
}
|
|
1138
1154
|
function relativeImportSource(from, to) {
|
|
1139
|
-
let
|
|
1140
|
-
let extension = Path3.extname(
|
|
1141
|
-
|
|
1142
|
-
if (!
|
|
1155
|
+
let path9 = Path3.relative(Path3.dirname(from), to);
|
|
1156
|
+
let extension = Path3.extname(path9);
|
|
1157
|
+
path9 = Path3.join(Path3.dirname(path9), Pathe.filename(path9));
|
|
1158
|
+
if (!path9.startsWith("../")) path9 = "./" + path9;
|
|
1143
1159
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1144
1160
|
extension = ".js";
|
|
1145
1161
|
}
|
|
1146
|
-
return
|
|
1162
|
+
return path9 + extension;
|
|
1147
1163
|
}
|
|
1148
1164
|
function rootDirsPath(ctx, typesPath) {
|
|
1149
1165
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1150
1166
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1151
1167
|
}
|
|
1152
|
-
function paramsType(
|
|
1153
|
-
const params = parse2(
|
|
1168
|
+
function paramsType(path9) {
|
|
1169
|
+
const params = parse2(path9);
|
|
1154
1170
|
return t2.tsTypeLiteral(
|
|
1155
1171
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1156
1172
|
const property = t2.tsPropertySignature(
|
|
@@ -1200,8 +1216,8 @@ async function write(...files) {
|
|
|
1200
1216
|
})
|
|
1201
1217
|
);
|
|
1202
1218
|
}
|
|
1203
|
-
async function watch(rootDirectory, { mode, logger }) {
|
|
1204
|
-
const ctx = await createContext2({ rootDirectory, mode, watch: true });
|
|
1219
|
+
async function watch(rootDirectory, { mode, logger, rsc }) {
|
|
1220
|
+
const ctx = await createContext2({ rootDirectory, mode, rsc, watch: true });
|
|
1205
1221
|
await import_promises.default.rm(typesDirectory(ctx), { recursive: true, force: true });
|
|
1206
1222
|
await write(
|
|
1207
1223
|
generateFuture(ctx),
|
|
@@ -1486,11 +1502,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1486
1502
|
let cssContent = void 0;
|
|
1487
1503
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1488
1504
|
traverse(ast, {
|
|
1489
|
-
VariableDeclaration(
|
|
1490
|
-
const declaration =
|
|
1505
|
+
VariableDeclaration(path9) {
|
|
1506
|
+
const declaration = path9.node.declarations[0];
|
|
1491
1507
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1492
1508
|
cssContent = declaration.init.value;
|
|
1493
|
-
|
|
1509
|
+
path9.stop();
|
|
1494
1510
|
}
|
|
1495
1511
|
}
|
|
1496
1512
|
});
|
|
@@ -1507,6 +1523,15 @@ function create(name) {
|
|
|
1507
1523
|
};
|
|
1508
1524
|
}
|
|
1509
1525
|
|
|
1526
|
+
// vite/resolve-relative-route-file-path.ts
|
|
1527
|
+
var import_pathe4 = __toESM(require("pathe"));
|
|
1528
|
+
function resolveRelativeRouteFilePath(route, reactRouterConfig) {
|
|
1529
|
+
let vite2 = getVite();
|
|
1530
|
+
let file = route.file;
|
|
1531
|
+
let fullPath = import_pathe4.default.resolve(reactRouterConfig.appDirectory, file);
|
|
1532
|
+
return vite2.normalizePath(fullPath);
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1510
1535
|
// vite/combine-urls.ts
|
|
1511
1536
|
function combineURLs(baseURL, relativeURL) {
|
|
1512
1537
|
return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
@@ -1520,10 +1545,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1520
1545
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1521
1546
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1522
1547
|
traverse(ast, {
|
|
1523
|
-
ExportDeclaration(
|
|
1524
|
-
if (
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1548
|
+
ExportDeclaration(path9) {
|
|
1549
|
+
if (path9.node.type === "ExportNamedDeclaration") {
|
|
1550
|
+
if (path9.node.specifiers.length) {
|
|
1551
|
+
path9.node.specifiers = path9.node.specifiers.filter((specifier) => {
|
|
1527
1552
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1528
1553
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1529
1554
|
exportsFiltered = true;
|
|
@@ -1535,12 +1560,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1535
1560
|
}
|
|
1536
1561
|
return true;
|
|
1537
1562
|
});
|
|
1538
|
-
if (
|
|
1539
|
-
markedForRemoval.add(
|
|
1563
|
+
if (path9.node.specifiers.length === 0) {
|
|
1564
|
+
markedForRemoval.add(path9);
|
|
1540
1565
|
}
|
|
1541
1566
|
}
|
|
1542
|
-
if (
|
|
1543
|
-
let declaration =
|
|
1567
|
+
if (path9.node.declaration?.type === "VariableDeclaration") {
|
|
1568
|
+
let declaration = path9.node.declaration;
|
|
1544
1569
|
declaration.declarations = declaration.declarations.filter(
|
|
1545
1570
|
(declaration2) => {
|
|
1546
1571
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1554,30 +1579,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1554
1579
|
}
|
|
1555
1580
|
);
|
|
1556
1581
|
if (declaration.declarations.length === 0) {
|
|
1557
|
-
markedForRemoval.add(
|
|
1582
|
+
markedForRemoval.add(path9);
|
|
1558
1583
|
}
|
|
1559
1584
|
}
|
|
1560
|
-
if (
|
|
1561
|
-
let id =
|
|
1585
|
+
if (path9.node.declaration?.type === "FunctionDeclaration") {
|
|
1586
|
+
let id = path9.node.declaration.id;
|
|
1562
1587
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1563
|
-
markedForRemoval.add(
|
|
1588
|
+
markedForRemoval.add(path9);
|
|
1564
1589
|
}
|
|
1565
1590
|
}
|
|
1566
|
-
if (
|
|
1567
|
-
let id =
|
|
1591
|
+
if (path9.node.declaration?.type === "ClassDeclaration") {
|
|
1592
|
+
let id = path9.node.declaration.id;
|
|
1568
1593
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1569
|
-
markedForRemoval.add(
|
|
1594
|
+
markedForRemoval.add(path9);
|
|
1570
1595
|
}
|
|
1571
1596
|
}
|
|
1572
1597
|
}
|
|
1573
|
-
if (
|
|
1598
|
+
if (path9.node.type === "ExportDefaultDeclaration") {
|
|
1574
1599
|
if (exportsToRemove.includes("default")) {
|
|
1575
|
-
markedForRemoval.add(
|
|
1576
|
-
if (
|
|
1577
|
-
if (
|
|
1578
|
-
removedExportLocalNames.add(
|
|
1579
|
-
} else if ((
|
|
1580
|
-
removedExportLocalNames.add(
|
|
1600
|
+
markedForRemoval.add(path9);
|
|
1601
|
+
if (path9.node.declaration) {
|
|
1602
|
+
if (path9.node.declaration.type === "Identifier") {
|
|
1603
|
+
removedExportLocalNames.add(path9.node.declaration.name);
|
|
1604
|
+
} else if ((path9.node.declaration.type === "FunctionDeclaration" || path9.node.declaration.type === "ClassDeclaration") && path9.node.declaration.id) {
|
|
1605
|
+
removedExportLocalNames.add(path9.node.declaration.id.name);
|
|
1581
1606
|
}
|
|
1582
1607
|
}
|
|
1583
1608
|
}
|
|
@@ -1585,21 +1610,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1585
1610
|
}
|
|
1586
1611
|
});
|
|
1587
1612
|
traverse(ast, {
|
|
1588
|
-
ExpressionStatement(
|
|
1589
|
-
if (!
|
|
1613
|
+
ExpressionStatement(path9) {
|
|
1614
|
+
if (!path9.parentPath.isProgram()) {
|
|
1590
1615
|
return;
|
|
1591
1616
|
}
|
|
1592
|
-
if (
|
|
1593
|
-
const left =
|
|
1617
|
+
if (path9.node.expression.type === "AssignmentExpression") {
|
|
1618
|
+
const left = path9.node.expression.left;
|
|
1594
1619
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1595
|
-
markedForRemoval.add(
|
|
1620
|
+
markedForRemoval.add(path9);
|
|
1596
1621
|
}
|
|
1597
1622
|
}
|
|
1598
1623
|
}
|
|
1599
1624
|
});
|
|
1600
1625
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1601
|
-
for (let
|
|
1602
|
-
|
|
1626
|
+
for (let path9 of markedForRemoval) {
|
|
1627
|
+
path9.remove();
|
|
1603
1628
|
}
|
|
1604
1629
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1605
1630
|
}
|
|
@@ -1644,6 +1669,18 @@ function invalidDestructureError(name) {
|
|
|
1644
1669
|
return new Error(`Cannot remove destructured export "${name}"`);
|
|
1645
1670
|
}
|
|
1646
1671
|
|
|
1672
|
+
// vite/has-dependency.ts
|
|
1673
|
+
function hasDependency({
|
|
1674
|
+
name,
|
|
1675
|
+
rootDirectory
|
|
1676
|
+
}) {
|
|
1677
|
+
try {
|
|
1678
|
+
return Boolean(require.resolve(name, { paths: [rootDirectory] }));
|
|
1679
|
+
} catch (err2) {
|
|
1680
|
+
return false;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1647
1684
|
// vite/cache.ts
|
|
1648
1685
|
function getOrSetFromCache(cache, key, version, getValue) {
|
|
1649
1686
|
if (!cache) {
|
|
@@ -1670,28 +1707,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1670
1707
|
)
|
|
1671
1708
|
);
|
|
1672
1709
|
}
|
|
1673
|
-
function assertNodePath(
|
|
1710
|
+
function assertNodePath(path9) {
|
|
1674
1711
|
invariant(
|
|
1675
|
-
|
|
1676
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1712
|
+
path9 && !Array.isArray(path9),
|
|
1713
|
+
`Expected a Path, but got ${Array.isArray(path9) ? "an array" : path9}`
|
|
1677
1714
|
);
|
|
1678
1715
|
}
|
|
1679
|
-
function assertNodePathIsStatement(
|
|
1716
|
+
function assertNodePathIsStatement(path9) {
|
|
1680
1717
|
invariant(
|
|
1681
|
-
|
|
1682
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1718
|
+
path9 && !Array.isArray(path9) && t.isStatement(path9.node),
|
|
1719
|
+
`Expected a Statement path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1683
1720
|
);
|
|
1684
1721
|
}
|
|
1685
|
-
function assertNodePathIsVariableDeclarator(
|
|
1722
|
+
function assertNodePathIsVariableDeclarator(path9) {
|
|
1686
1723
|
invariant(
|
|
1687
|
-
|
|
1688
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1724
|
+
path9 && !Array.isArray(path9) && t.isVariableDeclarator(path9.node),
|
|
1725
|
+
`Expected an Identifier path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1689
1726
|
);
|
|
1690
1727
|
}
|
|
1691
|
-
function assertNodePathIsPattern(
|
|
1728
|
+
function assertNodePathIsPattern(path9) {
|
|
1692
1729
|
invariant(
|
|
1693
|
-
|
|
1694
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1730
|
+
path9 && !Array.isArray(path9) && t.isPattern(path9.node),
|
|
1731
|
+
`Expected a Pattern path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1695
1732
|
);
|
|
1696
1733
|
}
|
|
1697
1734
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1727,8 +1764,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1727
1764
|
}
|
|
1728
1765
|
let isWithinExportDestructuring = Boolean(
|
|
1729
1766
|
identifier.findParent(
|
|
1730
|
-
(
|
|
1731
|
-
|
|
1767
|
+
(path9) => Boolean(
|
|
1768
|
+
path9.isPattern() && path9.parentPath?.isVariableDeclarator() && path9.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1732
1769
|
)
|
|
1733
1770
|
)
|
|
1734
1771
|
);
|
|
@@ -1806,7 +1843,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1806
1843
|
for (let specifier of node.specifiers) {
|
|
1807
1844
|
if (t.isIdentifier(specifier.exported)) {
|
|
1808
1845
|
let name = specifier.exported.name;
|
|
1809
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1846
|
+
let specifierPath = exportPath.get("specifiers").find((path9) => path9.node === specifier);
|
|
1810
1847
|
invariant(
|
|
1811
1848
|
specifierPath,
|
|
1812
1849
|
`Expected to find specifier path for ${name}`
|
|
@@ -1823,22 +1860,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1823
1860
|
}
|
|
1824
1861
|
);
|
|
1825
1862
|
}
|
|
1826
|
-
function getDependentIdentifiersForPath(
|
|
1863
|
+
function getDependentIdentifiersForPath(path9, state) {
|
|
1827
1864
|
let { visited, identifiers } = state ?? {
|
|
1828
1865
|
visited: /* @__PURE__ */ new Set(),
|
|
1829
1866
|
identifiers: /* @__PURE__ */ new Set()
|
|
1830
1867
|
};
|
|
1831
|
-
if (visited.has(
|
|
1868
|
+
if (visited.has(path9)) {
|
|
1832
1869
|
return identifiers;
|
|
1833
1870
|
}
|
|
1834
|
-
visited.add(
|
|
1835
|
-
|
|
1836
|
-
Identifier(
|
|
1837
|
-
if (identifiers.has(
|
|
1871
|
+
visited.add(path9);
|
|
1872
|
+
path9.traverse({
|
|
1873
|
+
Identifier(path10) {
|
|
1874
|
+
if (identifiers.has(path10)) {
|
|
1838
1875
|
return;
|
|
1839
1876
|
}
|
|
1840
|
-
identifiers.add(
|
|
1841
|
-
let binding =
|
|
1877
|
+
identifiers.add(path10);
|
|
1878
|
+
let binding = path10.scope.getBinding(path10.node.name);
|
|
1842
1879
|
if (!binding) {
|
|
1843
1880
|
return;
|
|
1844
1881
|
}
|
|
@@ -1860,7 +1897,7 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1860
1897
|
}
|
|
1861
1898
|
}
|
|
1862
1899
|
});
|
|
1863
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1900
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1864
1901
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1865
1902
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1866
1903
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1869,9 +1906,9 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1869
1906
|
identifiers
|
|
1870
1907
|
});
|
|
1871
1908
|
}
|
|
1872
|
-
if (withinExportStatement &&
|
|
1873
|
-
t.isPattern(
|
|
1874
|
-
let variableDeclarator =
|
|
1909
|
+
if (withinExportStatement && path9.isIdentifier() && (t.isPattern(path9.parentPath.node) || // [foo]
|
|
1910
|
+
t.isPattern(path9.parentPath.parentPath?.node))) {
|
|
1911
|
+
let variableDeclarator = path9.findParent((p) => p.isVariableDeclarator());
|
|
1875
1912
|
assertNodePath(variableDeclarator);
|
|
1876
1913
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1877
1914
|
visited,
|
|
@@ -1880,16 +1917,16 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1880
1917
|
}
|
|
1881
1918
|
return identifiers;
|
|
1882
1919
|
}
|
|
1883
|
-
function getTopLevelStatementPathForPath(
|
|
1884
|
-
let ancestry =
|
|
1920
|
+
function getTopLevelStatementPathForPath(path9) {
|
|
1921
|
+
let ancestry = path9.getAncestry();
|
|
1885
1922
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1886
1923
|
assertNodePathIsStatement(topLevelStatement);
|
|
1887
1924
|
return topLevelStatement;
|
|
1888
1925
|
}
|
|
1889
1926
|
function getTopLevelStatementsForPaths(paths) {
|
|
1890
1927
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1891
|
-
for (let
|
|
1892
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1928
|
+
for (let path9 of paths) {
|
|
1929
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1893
1930
|
topLevelStatements.add(topLevelStatement.node);
|
|
1894
1931
|
}
|
|
1895
1932
|
return topLevelStatements;
|
|
@@ -2251,6 +2288,31 @@ function getRouteChunkNameFromModuleId(id) {
|
|
|
2251
2288
|
return chunkName;
|
|
2252
2289
|
}
|
|
2253
2290
|
|
|
2291
|
+
// vite/optimize-deps-entries.ts
|
|
2292
|
+
var import_tinyglobby = require("tinyglobby");
|
|
2293
|
+
function getOptimizeDepsEntries({
|
|
2294
|
+
entryClientFilePath,
|
|
2295
|
+
reactRouterConfig
|
|
2296
|
+
}) {
|
|
2297
|
+
if (!reactRouterConfig.future.unstable_optimizeDeps) {
|
|
2298
|
+
return [];
|
|
2299
|
+
}
|
|
2300
|
+
const vite2 = getVite();
|
|
2301
|
+
const viteMajorVersion = parseInt(vite2.version.split(".")[0], 10);
|
|
2302
|
+
return [
|
|
2303
|
+
vite2.normalizePath(entryClientFilePath),
|
|
2304
|
+
...Object.values(reactRouterConfig.routes).map(
|
|
2305
|
+
(route) => resolveRelativeRouteFilePath(route, reactRouterConfig)
|
|
2306
|
+
)
|
|
2307
|
+
].map(
|
|
2308
|
+
(entry) => (
|
|
2309
|
+
// In Vite 7, the `optimizeDeps.entries` option only accepts glob patterns.
|
|
2310
|
+
// In prior versions, absolute file paths were treated differently.
|
|
2311
|
+
viteMajorVersion >= 7 ? (0, import_tinyglobby.escapePath)(entry) : entry
|
|
2312
|
+
)
|
|
2313
|
+
);
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2254
2316
|
// vite/with-props.ts
|
|
2255
2317
|
var namedComponentExports = ["HydrateFallback", "ErrorBoundary"];
|
|
2256
2318
|
function isNamedComponentExport(name) {
|
|
@@ -2258,24 +2320,24 @@ function isNamedComponentExport(name) {
|
|
|
2258
2320
|
}
|
|
2259
2321
|
var decorateComponentExportsWithProps = (ast) => {
|
|
2260
2322
|
const hocs = [];
|
|
2261
|
-
function getHocUid(
|
|
2262
|
-
const uid =
|
|
2323
|
+
function getHocUid(path9, hocName) {
|
|
2324
|
+
const uid = path9.scope.generateUidIdentifier(hocName);
|
|
2263
2325
|
hocs.push([hocName, uid]);
|
|
2264
2326
|
return uid;
|
|
2265
2327
|
}
|
|
2266
2328
|
traverse(ast, {
|
|
2267
|
-
ExportDeclaration(
|
|
2268
|
-
if (
|
|
2269
|
-
const declaration =
|
|
2329
|
+
ExportDeclaration(path9) {
|
|
2330
|
+
if (path9.isExportDefaultDeclaration()) {
|
|
2331
|
+
const declaration = path9.get("declaration");
|
|
2270
2332
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2271
2333
|
if (expr) {
|
|
2272
|
-
const uid = getHocUid(
|
|
2334
|
+
const uid = getHocUid(path9, "UNSAFE_withComponentProps");
|
|
2273
2335
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2274
2336
|
}
|
|
2275
2337
|
return;
|
|
2276
2338
|
}
|
|
2277
|
-
if (
|
|
2278
|
-
const decl =
|
|
2339
|
+
if (path9.isExportNamedDeclaration()) {
|
|
2340
|
+
const decl = path9.get("declaration");
|
|
2279
2341
|
if (decl.isVariableDeclaration()) {
|
|
2280
2342
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2281
2343
|
const id = varDeclarator.get("id");
|
|
@@ -2285,7 +2347,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2285
2347
|
if (!id.isIdentifier()) return;
|
|
2286
2348
|
const { name } = id.node;
|
|
2287
2349
|
if (!isNamedComponentExport(name)) return;
|
|
2288
|
-
const uid = getHocUid(
|
|
2350
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2289
2351
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2290
2352
|
});
|
|
2291
2353
|
return;
|
|
@@ -2295,7 +2357,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2295
2357
|
if (!id) return;
|
|
2296
2358
|
const { name } = id;
|
|
2297
2359
|
if (!isNamedComponentExport(name)) return;
|
|
2298
|
-
const uid = getHocUid(
|
|
2360
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2299
2361
|
decl.replaceWith(
|
|
2300
2362
|
t.variableDeclaration("const", [
|
|
2301
2363
|
t.variableDeclarator(
|
|
@@ -2329,6 +2391,26 @@ function toFunctionExpression(decl) {
|
|
|
2329
2391
|
);
|
|
2330
2392
|
}
|
|
2331
2393
|
|
|
2394
|
+
// vite/load-dotenv.ts
|
|
2395
|
+
async function loadDotenv({
|
|
2396
|
+
rootDirectory,
|
|
2397
|
+
viteUserConfig,
|
|
2398
|
+
mode
|
|
2399
|
+
}) {
|
|
2400
|
+
const vite2 = await import("vite");
|
|
2401
|
+
Object.assign(
|
|
2402
|
+
process.env,
|
|
2403
|
+
vite2.loadEnv(
|
|
2404
|
+
mode,
|
|
2405
|
+
viteUserConfig.envDir ?? rootDirectory,
|
|
2406
|
+
// We override the default prefix of "VITE_" with a blank string since
|
|
2407
|
+
// we're targeting the server, so we want to load all environment
|
|
2408
|
+
// variables, not just those explicitly marked for the client
|
|
2409
|
+
""
|
|
2410
|
+
)
|
|
2411
|
+
);
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2332
2414
|
// vite/plugins/validate-plugin-order.ts
|
|
2333
2415
|
function validatePluginOrder() {
|
|
2334
2416
|
return {
|
|
@@ -2340,16 +2422,57 @@ function validatePluginOrder() {
|
|
|
2340
2422
|
(plugin) => pluginName.includes(plugin.name)
|
|
2341
2423
|
);
|
|
2342
2424
|
};
|
|
2343
|
-
let
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2425
|
+
let reactRouterRscPluginIndex = pluginIndex("react-router/rsc");
|
|
2426
|
+
let viteRscPluginIndex = pluginIndex("rsc");
|
|
2427
|
+
if (reactRouterRscPluginIndex >= 0 && viteRscPluginIndex >= 0 && reactRouterRscPluginIndex > viteRscPluginIndex) {
|
|
2428
|
+
throw new Error(
|
|
2429
|
+
`The "@vitejs/plugin-rsc" plugin should be placed after the React Router RSC plugin in your Vite config`
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2432
|
+
let reactRouterPluginIndex = pluginIndex([
|
|
2433
|
+
"react-router",
|
|
2434
|
+
"react-router/rsc"
|
|
2435
|
+
]);
|
|
2436
|
+
let mdxPluginIndex = pluginIndex("@mdx-js/rollup");
|
|
2437
|
+
if (mdxPluginIndex >= 0 && mdxPluginIndex > reactRouterPluginIndex) {
|
|
2438
|
+
throw new Error(
|
|
2439
|
+
`The "@mdx-js/rollup" plugin should be placed before the React Router plugin in your Vite config`
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
// vite/plugins/warn-on-client-source-maps.ts
|
|
2447
|
+
var import_picocolors3 = __toESM(require("picocolors"));
|
|
2448
|
+
function warnOnClientSourceMaps() {
|
|
2449
|
+
let viteConfig;
|
|
2450
|
+
let viteCommand;
|
|
2451
|
+
let logged = false;
|
|
2452
|
+
return {
|
|
2453
|
+
name: "react-router:warn-on-client-source-maps",
|
|
2454
|
+
config(_, configEnv) {
|
|
2455
|
+
viteCommand = configEnv.command;
|
|
2456
|
+
},
|
|
2457
|
+
configResolved(config) {
|
|
2458
|
+
viteConfig = config;
|
|
2459
|
+
},
|
|
2460
|
+
buildStart() {
|
|
2461
|
+
invariant(viteConfig);
|
|
2462
|
+
if (!logged && viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && (viteConfig.build.sourcemap || viteConfig.environments?.client?.build.sourcemap)) {
|
|
2463
|
+
viteConfig.logger.warn(
|
|
2464
|
+
import_picocolors3.default.yellow(
|
|
2465
|
+
"\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
|
|
2466
|
+
"This makes your server code publicly",
|
|
2467
|
+
"visible in the browser. This is highly",
|
|
2468
|
+
"discouraged! If you insist, ensure that",
|
|
2469
|
+
"you are using environment variables for",
|
|
2470
|
+
"secrets and not hard-coding them in",
|
|
2471
|
+
"your source code."
|
|
2472
|
+
].map((line) => " " + line).join("\n") + "\n"
|
|
2473
|
+
)
|
|
2474
|
+
);
|
|
2475
|
+
logged = true;
|
|
2353
2476
|
}
|
|
2354
2477
|
}
|
|
2355
2478
|
};
|
|
@@ -2416,16 +2539,10 @@ var virtualHmrRuntime = create("hmr-runtime");
|
|
|
2416
2539
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
2417
2540
|
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
2418
2541
|
let vite2 = getVite();
|
|
2419
|
-
let fullPath =
|
|
2420
|
-
let relativePath =
|
|
2542
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
2543
|
+
let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
|
|
2421
2544
|
return vite2.normalizePath(relativePath).split("?")[0];
|
|
2422
2545
|
};
|
|
2423
|
-
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
2424
|
-
let vite2 = getVite();
|
|
2425
|
-
let file = route.file;
|
|
2426
|
-
let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
|
|
2427
|
-
return vite2.normalizePath(fullPath);
|
|
2428
|
-
};
|
|
2429
2546
|
var virtual = {
|
|
2430
2547
|
serverBuild: create("server-build"),
|
|
2431
2548
|
serverManifest: create("server-manifest"),
|
|
@@ -2446,7 +2563,7 @@ var getHash = (source, maxLength) => {
|
|
|
2446
2563
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
2447
2564
|
let vite2 = getVite();
|
|
2448
2565
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
2449
|
-
|
|
2566
|
+
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
2450
2567
|
);
|
|
2451
2568
|
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
2452
2569
|
if (!entryChunk) {
|
|
@@ -2535,7 +2652,7 @@ function dedupe(array2) {
|
|
|
2535
2652
|
return [...new Set(array2)];
|
|
2536
2653
|
}
|
|
2537
2654
|
var writeFileSafe = async (file, contents) => {
|
|
2538
|
-
await (0, import_promises2.mkdir)(
|
|
2655
|
+
await (0, import_promises2.mkdir)(path6.dirname(file), { recursive: true });
|
|
2539
2656
|
await (0, import_promises2.writeFile)(file, contents);
|
|
2540
2657
|
};
|
|
2541
2658
|
var getExportNames = (code) => {
|
|
@@ -2561,7 +2678,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2561
2678
|
}
|
|
2562
2679
|
let ssr = true;
|
|
2563
2680
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
2564
|
-
let routePath =
|
|
2681
|
+
let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2565
2682
|
let url2 = resolveFileUrl(ctx, routePath);
|
|
2566
2683
|
let resolveId = async () => {
|
|
2567
2684
|
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
@@ -2603,12 +2720,12 @@ var resolveEnvironmentBuildContext = ({
|
|
|
2603
2720
|
};
|
|
2604
2721
|
return resolvedBuildContext;
|
|
2605
2722
|
};
|
|
2606
|
-
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) =>
|
|
2723
|
+
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
|
|
2607
2724
|
reactRouterConfig.buildDirectory,
|
|
2608
2725
|
"server",
|
|
2609
2726
|
...serverBundleId ? [serverBundleId] : []
|
|
2610
2727
|
);
|
|
2611
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
2728
|
+
var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
|
|
2612
2729
|
var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
2613
2730
|
if (!ctx.buildManifest) {
|
|
2614
2731
|
return void 0;
|
|
@@ -2626,14 +2743,14 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
|
2626
2743
|
);
|
|
2627
2744
|
return Object.keys(serverBundleRoutes);
|
|
2628
2745
|
};
|
|
2629
|
-
var defaultEntriesDir =
|
|
2630
|
-
|
|
2746
|
+
var defaultEntriesDir = path6.resolve(
|
|
2747
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
2631
2748
|
"dist",
|
|
2632
2749
|
"config",
|
|
2633
2750
|
"defaults"
|
|
2634
2751
|
);
|
|
2635
2752
|
var defaultEntries = (0, import_node_fs2.readdirSync)(defaultEntriesDir).map(
|
|
2636
|
-
(filename2) =>
|
|
2753
|
+
(filename2) => path6.join(defaultEntriesDir, filename2)
|
|
2637
2754
|
);
|
|
2638
2755
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2639
2756
|
var reactRouterDevLoadContext = () => void 0;
|
|
@@ -2671,7 +2788,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2671
2788
|
let publicPath = viteUserConfig.base ?? "/";
|
|
2672
2789
|
if (reactRouterConfig.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !reactRouterConfig.basename.startsWith(publicPath)) {
|
|
2673
2790
|
logger.error(
|
|
2674
|
-
|
|
2791
|
+
import_picocolors4.default.red(
|
|
2675
2792
|
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
2676
2793
|
)
|
|
2677
2794
|
);
|
|
@@ -2729,7 +2846,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2729
2846
|
virtual.serverManifest.id
|
|
2730
2847
|
)};
|
|
2731
2848
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2732
|
-
|
|
2849
|
+
path6.relative(
|
|
2733
2850
|
ctx.rootDirectory,
|
|
2734
2851
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
2735
2852
|
)
|
|
@@ -2768,18 +2885,11 @@ var reactRouterVitePlugin = () => {
|
|
|
2768
2885
|
};
|
|
2769
2886
|
let loadViteManifest = async (directory) => {
|
|
2770
2887
|
let manifestContents = await (0, import_promises2.readFile)(
|
|
2771
|
-
|
|
2888
|
+
path6.resolve(directory, ".vite", "manifest.json"),
|
|
2772
2889
|
"utf-8"
|
|
2773
2890
|
);
|
|
2774
2891
|
return JSON.parse(manifestContents);
|
|
2775
2892
|
};
|
|
2776
|
-
let hasDependency = (name) => {
|
|
2777
|
-
try {
|
|
2778
|
-
return Boolean(require.resolve(name, { paths: [ctx.rootDirectory] }));
|
|
2779
|
-
} catch (err2) {
|
|
2780
|
-
return false;
|
|
2781
|
-
}
|
|
2782
|
-
};
|
|
2783
2893
|
let getViteManifestAssetPaths = (viteManifest) => {
|
|
2784
2894
|
let cssUrlPaths = Object.values(viteManifest).filter((chunk) => chunk.file.endsWith(".css")).map((chunk) => chunk.file);
|
|
2785
2895
|
let chunkAssetPaths = Object.values(viteManifest).flatMap(
|
|
@@ -2800,7 +2910,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2800
2910
|
let contents;
|
|
2801
2911
|
try {
|
|
2802
2912
|
contents = await (0, import_promises2.readFile)(
|
|
2803
|
-
|
|
2913
|
+
path6.join(entryNormalizedPath, entry.name),
|
|
2804
2914
|
"utf-8"
|
|
2805
2915
|
);
|
|
2806
2916
|
} catch (e) {
|
|
@@ -2809,9 +2919,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2809
2919
|
}
|
|
2810
2920
|
let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
|
|
2811
2921
|
let filepath = getVite().normalizePath(
|
|
2812
|
-
|
|
2922
|
+
path6.relative(
|
|
2813
2923
|
clientBuildDirectory,
|
|
2814
|
-
|
|
2924
|
+
path6.join(entryNormalizedPath, entry.name)
|
|
2815
2925
|
)
|
|
2816
2926
|
);
|
|
2817
2927
|
sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
|
|
@@ -2842,7 +2952,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2842
2952
|
);
|
|
2843
2953
|
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2844
2954
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2845
|
-
let routeFile =
|
|
2955
|
+
let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2846
2956
|
let sourceExports = routeManifestExports[route.id];
|
|
2847
2957
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
2848
2958
|
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
@@ -2913,7 +3023,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2913
3023
|
}
|
|
2914
3024
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
2915
3025
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
2916
|
-
let manifestPath =
|
|
3026
|
+
let manifestPath = path6.posix.join(
|
|
2917
3027
|
viteConfig2.build.assetsDir,
|
|
2918
3028
|
`manifest-${version}.js`
|
|
2919
3029
|
);
|
|
@@ -2925,7 +3035,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2925
3035
|
sri: void 0
|
|
2926
3036
|
};
|
|
2927
3037
|
await writeFileSafe(
|
|
2928
|
-
|
|
3038
|
+
path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
2929
3039
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
2930
3040
|
reactRouterBrowserManifest
|
|
2931
3041
|
)};`
|
|
@@ -3051,7 +3161,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3051
3161
|
config: async (_viteUserConfig, _viteConfigEnv) => {
|
|
3052
3162
|
await preloadVite();
|
|
3053
3163
|
let vite2 = getVite();
|
|
3054
|
-
let viteMajorVersion = parseInt(vite2.version.split(".")[0], 10);
|
|
3055
3164
|
viteUserConfig = _viteUserConfig;
|
|
3056
3165
|
viteConfigEnv = _viteConfigEnv;
|
|
3057
3166
|
viteCommand = viteConfigEnv.command;
|
|
@@ -3066,6 +3175,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3066
3175
|
if (viteCommand === "serve") {
|
|
3067
3176
|
typegenWatcherPromise = watch(rootDirectory, {
|
|
3068
3177
|
mode,
|
|
3178
|
+
rsc: false,
|
|
3069
3179
|
// ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
|
|
3070
3180
|
logger: vite2.createLogger("warn", { prefix: "[react-router]" })
|
|
3071
3181
|
});
|
|
@@ -3076,17 +3186,11 @@ var reactRouterVitePlugin = () => {
|
|
|
3076
3186
|
watch: viteCommand === "serve"
|
|
3077
3187
|
});
|
|
3078
3188
|
await updatePluginContext();
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
// We override the default prefix of "VITE_" with a blank string since
|
|
3085
|
-
// we're targeting the server, so we want to load all environment
|
|
3086
|
-
// variables, not just those explicitly marked for the client
|
|
3087
|
-
""
|
|
3088
|
-
)
|
|
3089
|
-
);
|
|
3189
|
+
await loadDotenv({
|
|
3190
|
+
rootDirectory,
|
|
3191
|
+
viteUserConfig,
|
|
3192
|
+
mode
|
|
3193
|
+
});
|
|
3090
3194
|
let environments = await getEnvironmentsOptions(ctx, viteCommand, {
|
|
3091
3195
|
viteUserConfig
|
|
3092
3196
|
});
|
|
@@ -3105,18 +3209,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3105
3209
|
resolve: serverEnvironment.resolve
|
|
3106
3210
|
},
|
|
3107
3211
|
optimizeDeps: {
|
|
3108
|
-
entries:
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
)
|
|
3113
|
-
].map(
|
|
3114
|
-
(entry) => (
|
|
3115
|
-
// In Vite 7, the `optimizeDeps.entries` option only accepts glob patterns.
|
|
3116
|
-
// In prior versions, absolute file paths were treated differently.
|
|
3117
|
-
viteMajorVersion >= 7 ? (0, import_tinyglobby.escapePath)(entry) : entry
|
|
3118
|
-
)
|
|
3119
|
-
) : [],
|
|
3212
|
+
entries: getOptimizeDepsEntries({
|
|
3213
|
+
entryClientFilePath: ctx.entryClientFilePath,
|
|
3214
|
+
reactRouterConfig: ctx.reactRouterConfig
|
|
3215
|
+
}),
|
|
3120
3216
|
include: [
|
|
3121
3217
|
// Pre-bundle React dependencies to avoid React duplicates,
|
|
3122
3218
|
// even if React dependencies are not direct dependencies.
|
|
@@ -3131,7 +3227,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3131
3227
|
"react-router",
|
|
3132
3228
|
"react-router/dom",
|
|
3133
3229
|
// Check to avoid "Failed to resolve dependency: react-router-dom, present in 'optimizeDeps.include'"
|
|
3134
|
-
...hasDependency(
|
|
3230
|
+
...hasDependency({
|
|
3231
|
+
name: "react-router-dom",
|
|
3232
|
+
rootDirectory: ctx.rootDirectory
|
|
3233
|
+
}) ? ["react-router-dom"] : []
|
|
3135
3234
|
]
|
|
3136
3235
|
},
|
|
3137
3236
|
esbuild: {
|
|
@@ -3283,23 +3382,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3283
3382
|
cssModulesManifest[id] = code;
|
|
3284
3383
|
}
|
|
3285
3384
|
},
|
|
3286
|
-
buildStart() {
|
|
3287
|
-
invariant(viteConfig);
|
|
3288
|
-
if (viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && viteConfig.build.sourcemap) {
|
|
3289
|
-
viteConfig.logger.warn(
|
|
3290
|
-
import_picocolors3.default.yellow(
|
|
3291
|
-
"\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
|
|
3292
|
-
"This makes your server code publicly",
|
|
3293
|
-
"visible in the browser. This is highly",
|
|
3294
|
-
"discouraged! If you insist, ensure that",
|
|
3295
|
-
"you are using environment variables for",
|
|
3296
|
-
"secrets and not hard-coding them in",
|
|
3297
|
-
"your source code."
|
|
3298
|
-
].map((line) => " " + line).join("\n") + "\n"
|
|
3299
|
-
)
|
|
3300
|
-
);
|
|
3301
|
-
}
|
|
3302
|
-
},
|
|
3303
3385
|
async configureServer(viteDevServer) {
|
|
3304
3386
|
(0, import_react_router2.unstable_setDevServerHooks)({
|
|
3305
3387
|
// Give the request handler access to the critical CSS in dev to avoid a
|
|
@@ -3339,7 +3421,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3339
3421
|
return;
|
|
3340
3422
|
}
|
|
3341
3423
|
let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
|
|
3342
|
-
logger.info(
|
|
3424
|
+
logger.info(import_picocolors4.default.green(message), {
|
|
3343
3425
|
clear: true,
|
|
3344
3426
|
timestamp: true
|
|
3345
3427
|
});
|
|
@@ -3429,11 +3511,11 @@ var reactRouterVitePlugin = () => {
|
|
|
3429
3511
|
let removedAssetPaths = [];
|
|
3430
3512
|
let copiedAssetPaths = [];
|
|
3431
3513
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
3432
|
-
let src =
|
|
3433
|
-
let dest =
|
|
3514
|
+
let src = path6.join(serverBuildDirectory, ssrAssetPath);
|
|
3515
|
+
let dest = path6.join(clientBuildDirectory, ssrAssetPath);
|
|
3434
3516
|
if (!userSsrEmitAssets) {
|
|
3435
3517
|
if (!(0, import_node_fs2.existsSync)(dest)) {
|
|
3436
|
-
await (0, import_promises2.mkdir)(
|
|
3518
|
+
await (0, import_promises2.mkdir)(path6.dirname(dest), { recursive: true });
|
|
3437
3519
|
await (0, import_promises2.rename)(src, dest);
|
|
3438
3520
|
movedAssetPaths.push(dest);
|
|
3439
3521
|
} else {
|
|
@@ -3451,7 +3533,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3451
3533
|
);
|
|
3452
3534
|
await Promise.all(
|
|
3453
3535
|
ssrCssPaths.map(async (cssPath) => {
|
|
3454
|
-
let src =
|
|
3536
|
+
let src = path6.join(serverBuildDirectory, cssPath);
|
|
3455
3537
|
await (0, import_promises2.rm)(src, { force: true, recursive: true });
|
|
3456
3538
|
removedAssetPaths.push(src);
|
|
3457
3539
|
})
|
|
@@ -3459,7 +3541,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3459
3541
|
}
|
|
3460
3542
|
let cleanedAssetPaths = [...removedAssetPaths, ...movedAssetPaths];
|
|
3461
3543
|
let handledAssetPaths = [...cleanedAssetPaths, ...copiedAssetPaths];
|
|
3462
|
-
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(
|
|
3544
|
+
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(path6.dirname));
|
|
3463
3545
|
await Promise.all(
|
|
3464
3546
|
Array.from(cleanedAssetDirs).map(async (dir) => {
|
|
3465
3547
|
try {
|
|
@@ -3479,9 +3561,9 @@ var reactRouterVitePlugin = () => {
|
|
|
3479
3561
|
if (paths.length) {
|
|
3480
3562
|
viteConfig.logger.info(
|
|
3481
3563
|
[
|
|
3482
|
-
`${
|
|
3564
|
+
`${import_picocolors4.default.green("\u2713")} ${message}`,
|
|
3483
3565
|
...paths.map(
|
|
3484
|
-
(assetPath) =>
|
|
3566
|
+
(assetPath) => import_picocolors4.default.dim(path6.relative(ctx.rootDirectory, assetPath))
|
|
3485
3567
|
)
|
|
3486
3568
|
].join("\n")
|
|
3487
3569
|
);
|
|
@@ -3525,7 +3607,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3525
3607
|
viteConfig.logger.info(
|
|
3526
3608
|
[
|
|
3527
3609
|
"Removing the server build in",
|
|
3528
|
-
|
|
3610
|
+
import_picocolors4.default.green(serverBuildDirectory),
|
|
3529
3611
|
"due to ssr:false"
|
|
3530
3612
|
].join(" ")
|
|
3531
3613
|
);
|
|
@@ -3575,7 +3657,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3575
3657
|
);
|
|
3576
3658
|
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
3577
3659
|
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
3578
|
-
let chunkBasePath = `./${
|
|
3660
|
+
let chunkBasePath = `./${path6.basename(id)}`;
|
|
3579
3661
|
return [
|
|
3580
3662
|
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
3581
3663
|
chunkBasePath,
|
|
@@ -3595,7 +3677,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3595
3677
|
async transform(code, id, options) {
|
|
3596
3678
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
3597
3679
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
3598
|
-
let routeFileName =
|
|
3680
|
+
let routeFileName = path6.basename(routeModuleId);
|
|
3599
3681
|
let sourceExports = await getRouteModuleExports(
|
|
3600
3682
|
viteChildCompiler,
|
|
3601
3683
|
ctx,
|
|
@@ -3722,7 +3804,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3722
3804
|
}
|
|
3723
3805
|
let vite2 = getVite();
|
|
3724
3806
|
let importerShort = vite2.normalizePath(
|
|
3725
|
-
|
|
3807
|
+
path6.relative(ctx.rootDirectory, importer)
|
|
3726
3808
|
);
|
|
3727
3809
|
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
3728
3810
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
@@ -3730,7 +3812,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3730
3812
|
).join(", ");
|
|
3731
3813
|
throw Error(
|
|
3732
3814
|
[
|
|
3733
|
-
|
|
3815
|
+
import_picocolors4.default.red(`Server-only module referenced by client`),
|
|
3734
3816
|
"",
|
|
3735
3817
|
` '${id}' imported by route '${importerShort}'`,
|
|
3736
3818
|
"",
|
|
@@ -3746,7 +3828,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3746
3828
|
}
|
|
3747
3829
|
throw Error(
|
|
3748
3830
|
[
|
|
3749
|
-
|
|
3831
|
+
import_picocolors4.default.red(`Server-only module referenced by client`),
|
|
3750
3832
|
"",
|
|
3751
3833
|
` '${id}' imported by '${importerShort}'`,
|
|
3752
3834
|
"",
|
|
@@ -3844,10 +3926,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3844
3926
|
},
|
|
3845
3927
|
async load(id) {
|
|
3846
3928
|
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
3847
|
-
let reactRefreshDir =
|
|
3929
|
+
let reactRefreshDir = path6.dirname(
|
|
3848
3930
|
require.resolve("react-refresh/package.json")
|
|
3849
3931
|
);
|
|
3850
|
-
let reactRefreshRuntimePath =
|
|
3932
|
+
let reactRefreshRuntimePath = path6.join(
|
|
3851
3933
|
reactRefreshDir,
|
|
3852
3934
|
"cjs/react-refresh-runtime.development.js"
|
|
3853
3935
|
);
|
|
@@ -3956,7 +4038,8 @@ var reactRouterVitePlugin = () => {
|
|
|
3956
4038
|
}
|
|
3957
4039
|
}
|
|
3958
4040
|
},
|
|
3959
|
-
validatePluginOrder()
|
|
4041
|
+
validatePluginOrder(),
|
|
4042
|
+
warnOnClientSourceMaps()
|
|
3960
4043
|
];
|
|
3961
4044
|
};
|
|
3962
4045
|
function getParentClientNodes(clientModuleGraph, module2) {
|
|
@@ -4026,7 +4109,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
4026
4109
|
function getRoute(pluginConfig, file) {
|
|
4027
4110
|
let vite2 = getVite();
|
|
4028
4111
|
let routePath = vite2.normalizePath(
|
|
4029
|
-
|
|
4112
|
+
path6.relative(pluginConfig.appDirectory, file)
|
|
4030
4113
|
);
|
|
4031
4114
|
let route = Object.values(pluginConfig.routes).find(
|
|
4032
4115
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -4065,7 +4148,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
4065
4148
|
caseSensitive: route.caseSensitive,
|
|
4066
4149
|
url: combineURLs(
|
|
4067
4150
|
ctx.publicPath,
|
|
4068
|
-
"/" +
|
|
4151
|
+
"/" + path6.relative(
|
|
4069
4152
|
ctx.rootDirectory,
|
|
4070
4153
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
4071
4154
|
)
|
|
@@ -4093,7 +4176,7 @@ function isSpaModeEnabled(reactRouterConfig) {
|
|
|
4093
4176
|
return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
|
|
4094
4177
|
}
|
|
4095
4178
|
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
4096
|
-
let serverBuildPath =
|
|
4179
|
+
let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
|
|
4097
4180
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
4098
4181
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
4099
4182
|
return {
|
|
@@ -4135,15 +4218,15 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
4135
4218
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
4136
4219
|
);
|
|
4137
4220
|
}
|
|
4138
|
-
await (0, import_promises2.writeFile)(
|
|
4139
|
-
let prettyDir =
|
|
4140
|
-
let prettyPath =
|
|
4221
|
+
await (0, import_promises2.writeFile)(path6.join(clientBuildDirectory, filename2), html);
|
|
4222
|
+
let prettyDir = path6.relative(viteConfig.root, clientBuildDirectory);
|
|
4223
|
+
let prettyPath = path6.join(prettyDir, filename2);
|
|
4141
4224
|
if (build.prerender.length > 0) {
|
|
4142
4225
|
viteConfig.logger.info(
|
|
4143
|
-
`Prerender (html): SPA Fallback -> ${
|
|
4226
|
+
`Prerender (html): SPA Fallback -> ${import_picocolors4.default.bold(prettyPath)}`
|
|
4144
4227
|
);
|
|
4145
4228
|
} else {
|
|
4146
|
-
viteConfig.logger.info(`SPA Mode: Generated ${
|
|
4229
|
+
viteConfig.logger.info(`SPA Mode: Generated ${import_picocolors4.default.bold(prettyPath)}`);
|
|
4147
4230
|
}
|
|
4148
4231
|
}
|
|
4149
4232
|
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildPath, clientBuildDirectory) {
|
|
@@ -4153,17 +4236,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4153
4236
|
serverBuildPath
|
|
4154
4237
|
);
|
|
4155
4238
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4156
|
-
for (let
|
|
4157
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
4239
|
+
for (let path9 of build.prerender) {
|
|
4240
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4158
4241
|
if (!matches) {
|
|
4159
4242
|
throw new Error(
|
|
4160
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4243
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4161
4244
|
);
|
|
4162
4245
|
}
|
|
4163
4246
|
}
|
|
4164
4247
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4165
|
-
for (let
|
|
4166
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
4248
|
+
for (let path9 of build.prerender) {
|
|
4249
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4167
4250
|
if (!matches) {
|
|
4168
4251
|
continue;
|
|
4169
4252
|
}
|
|
@@ -4176,7 +4259,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4176
4259
|
if (manifestRoute.loader) {
|
|
4177
4260
|
await prerenderData(
|
|
4178
4261
|
handler,
|
|
4179
|
-
|
|
4262
|
+
path9,
|
|
4180
4263
|
[leafRoute.id],
|
|
4181
4264
|
clientBuildDirectory,
|
|
4182
4265
|
reactRouterConfig,
|
|
@@ -4184,7 +4267,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4184
4267
|
);
|
|
4185
4268
|
await prerenderResourceRoute(
|
|
4186
4269
|
handler,
|
|
4187
|
-
|
|
4270
|
+
path9,
|
|
4188
4271
|
clientBuildDirectory,
|
|
4189
4272
|
reactRouterConfig,
|
|
4190
4273
|
viteConfig
|
|
@@ -4202,7 +4285,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4202
4285
|
if (!isResourceRoute && hasLoaders) {
|
|
4203
4286
|
data = await prerenderData(
|
|
4204
4287
|
handler,
|
|
4205
|
-
|
|
4288
|
+
path9,
|
|
4206
4289
|
null,
|
|
4207
4290
|
clientBuildDirectory,
|
|
4208
4291
|
reactRouterConfig,
|
|
@@ -4211,7 +4294,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4211
4294
|
}
|
|
4212
4295
|
await prerenderRoute(
|
|
4213
4296
|
handler,
|
|
4214
|
-
|
|
4297
|
+
path9,
|
|
4215
4298
|
clientBuildDirectory,
|
|
4216
4299
|
reactRouterConfig,
|
|
4217
4300
|
viteConfig,
|
|
@@ -4264,12 +4347,12 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
|
|
|
4264
4347
|
${normalizedPath}`
|
|
4265
4348
|
);
|
|
4266
4349
|
}
|
|
4267
|
-
let outfile =
|
|
4268
|
-
await (0, import_promises2.mkdir)(
|
|
4350
|
+
let outfile = path6.join(clientBuildDirectory, ...normalizedPath.split("/"));
|
|
4351
|
+
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4269
4352
|
await (0, import_promises2.writeFile)(outfile, data);
|
|
4270
4353
|
viteConfig.logger.info(
|
|
4271
|
-
`Prerender (data): ${prerenderPath} -> ${
|
|
4272
|
-
|
|
4354
|
+
`Prerender (data): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4355
|
+
path6.relative(viteConfig.root, outfile)
|
|
4273
4356
|
)}`
|
|
4274
4357
|
);
|
|
4275
4358
|
return data;
|
|
@@ -4304,16 +4387,16 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
4304
4387
|
${html}`
|
|
4305
4388
|
);
|
|
4306
4389
|
}
|
|
4307
|
-
let outfile =
|
|
4390
|
+
let outfile = path6.join(
|
|
4308
4391
|
clientBuildDirectory,
|
|
4309
4392
|
...normalizedPath.split("/"),
|
|
4310
4393
|
"index.html"
|
|
4311
4394
|
);
|
|
4312
|
-
await (0, import_promises2.mkdir)(
|
|
4395
|
+
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4313
4396
|
await (0, import_promises2.writeFile)(outfile, html);
|
|
4314
4397
|
viteConfig.logger.info(
|
|
4315
|
-
`Prerender (html): ${prerenderPath} -> ${
|
|
4316
|
-
|
|
4398
|
+
`Prerender (html): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4399
|
+
path6.relative(viteConfig.root, outfile)
|
|
4317
4400
|
)}`
|
|
4318
4401
|
);
|
|
4319
4402
|
}
|
|
@@ -4328,12 +4411,12 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
4328
4411
|
${content.toString("utf8")}`
|
|
4329
4412
|
);
|
|
4330
4413
|
}
|
|
4331
|
-
let outfile =
|
|
4332
|
-
await (0, import_promises2.mkdir)(
|
|
4414
|
+
let outfile = path6.join(clientBuildDirectory, ...normalizedPath.split("/"));
|
|
4415
|
+
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4333
4416
|
await (0, import_promises2.writeFile)(outfile, content);
|
|
4334
4417
|
viteConfig.logger.info(
|
|
4335
|
-
`Prerender (resource): ${prerenderPath} -> ${
|
|
4336
|
-
|
|
4418
|
+
`Prerender (resource): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4419
|
+
path6.relative(viteConfig.root, outfile)
|
|
4337
4420
|
)}`
|
|
4338
4421
|
);
|
|
4339
4422
|
}
|
|
@@ -4345,7 +4428,7 @@ async function getPrerenderPaths(prerender, ssr, routes, logWarning = false) {
|
|
|
4345
4428
|
let { paths, paramRoutes } = getStaticPrerenderPaths(prerenderRoutes);
|
|
4346
4429
|
if (logWarning && !ssr && paramRoutes.length > 0) {
|
|
4347
4430
|
console.warn(
|
|
4348
|
-
|
|
4431
|
+
import_picocolors4.default.yellow(
|
|
4349
4432
|
[
|
|
4350
4433
|
"\u26A0\uFE0F Paths with dynamic/splat params cannot be prerendered when using `prerender: true`. You may want to use the `prerender()` API to prerender the following paths:",
|
|
4351
4434
|
...paramRoutes.map((p) => " - " + p)
|
|
@@ -4407,14 +4490,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4407
4490
|
}
|
|
4408
4491
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4409
4492
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4410
|
-
for (let
|
|
4493
|
+
for (let path9 of prerenderPaths) {
|
|
4411
4494
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4412
4495
|
prerenderRoutes,
|
|
4413
|
-
`/${
|
|
4496
|
+
`/${path9}/`.replace(/^\/\/+/, "/")
|
|
4414
4497
|
);
|
|
4415
4498
|
invariant(
|
|
4416
4499
|
matches,
|
|
4417
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4500
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4418
4501
|
);
|
|
4419
4502
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4420
4503
|
}
|
|
@@ -4452,7 +4535,7 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4452
4535
|
}
|
|
4453
4536
|
}
|
|
4454
4537
|
if (errors.length > 0) {
|
|
4455
|
-
viteConfig.logger.error(
|
|
4538
|
+
viteConfig.logger.error(import_picocolors4.default.red(errors.join("\n")));
|
|
4456
4539
|
throw new Error(
|
|
4457
4540
|
"Invalid route exports found when prerendering with `ssr:false`"
|
|
4458
4541
|
);
|
|
@@ -4581,8 +4664,8 @@ function validateRouteChunks({
|
|
|
4581
4664
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
4582
4665
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
4583
4666
|
let isWithinRoot = () => {
|
|
4584
|
-
let relativePath =
|
|
4585
|
-
return !relativePath.startsWith("..") && !
|
|
4667
|
+
let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
|
|
4668
|
+
return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
|
|
4586
4669
|
};
|
|
4587
4670
|
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
4588
4671
|
await (0, import_promises2.rm)(buildDirectory, { force: true, recursive: true });
|
|
@@ -4593,7 +4676,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4593
4676
|
([environmentName, options]) => {
|
|
4594
4677
|
let outDir = options.build?.outDir;
|
|
4595
4678
|
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
4596
|
-
return
|
|
4679
|
+
return path6.join(outDir, ".vite/manifest.json");
|
|
4597
4680
|
}
|
|
4598
4681
|
);
|
|
4599
4682
|
await Promise.all(
|
|
@@ -4603,7 +4686,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4603
4686
|
if (!ctx.viteManifestEnabled) {
|
|
4604
4687
|
await (0, import_promises2.rm)(viteManifestPath, { force: true, recursive: true });
|
|
4605
4688
|
}
|
|
4606
|
-
let viteDir =
|
|
4689
|
+
let viteDir = path6.dirname(viteManifestPath);
|
|
4607
4690
|
let viteDirFiles = await (0, import_promises2.readdir)(viteDir, { recursive: true });
|
|
4608
4691
|
if (viteDirFiles.length === 0) {
|
|
4609
4692
|
await (0, import_promises2.rm)(viteDir, { force: true, recursive: true });
|
|
@@ -4621,12 +4704,12 @@ async function getBuildManifest({
|
|
|
4621
4704
|
}
|
|
4622
4705
|
let { normalizePath } = await import("vite");
|
|
4623
4706
|
let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
|
|
4624
|
-
let resolvedAppDirectory =
|
|
4707
|
+
let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
|
|
4625
4708
|
let rootRelativeRoutes = Object.fromEntries(
|
|
4626
4709
|
Object.entries(routes).map(([id, route]) => {
|
|
4627
|
-
let filePath =
|
|
4710
|
+
let filePath = path6.join(resolvedAppDirectory, route.file);
|
|
4628
4711
|
let rootRelativeFilePath = normalizePath(
|
|
4629
|
-
|
|
4712
|
+
path6.relative(rootDirectory, filePath)
|
|
4630
4713
|
);
|
|
4631
4714
|
return [id, { ...route, file: rootRelativeFilePath }];
|
|
4632
4715
|
})
|
|
@@ -4644,7 +4727,7 @@ async function getBuildManifest({
|
|
|
4644
4727
|
(route2) => configRouteToBranchRoute({
|
|
4645
4728
|
...route2,
|
|
4646
4729
|
// Ensure absolute paths are passed to the serverBundles function
|
|
4647
|
-
file:
|
|
4730
|
+
file: path6.join(resolvedAppDirectory, route2.file)
|
|
4648
4731
|
})
|
|
4649
4732
|
)
|
|
4650
4733
|
});
|
|
@@ -4668,10 +4751,10 @@ async function getBuildManifest({
|
|
|
4668
4751
|
buildManifest.serverBundles[serverBundleId] ??= {
|
|
4669
4752
|
id: serverBundleId,
|
|
4670
4753
|
file: normalizePath(
|
|
4671
|
-
|
|
4672
|
-
|
|
4754
|
+
path6.join(
|
|
4755
|
+
path6.relative(
|
|
4673
4756
|
rootDirectory,
|
|
4674
|
-
|
|
4757
|
+
path6.join(serverBuildDirectory, serverBundleId)
|
|
4675
4758
|
),
|
|
4676
4759
|
reactRouterConfig.serverBuildFile
|
|
4677
4760
|
)
|
|
@@ -4690,10 +4773,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
|
|
|
4690
4773
|
}
|
|
4691
4774
|
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
4692
4775
|
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
4693
|
-
let packageRoot =
|
|
4776
|
+
let packageRoot = path6.dirname(
|
|
4694
4777
|
require.resolve("@react-router/dev/package.json")
|
|
4695
4778
|
);
|
|
4696
|
-
let { moduleSyncEnabled } = await import(`file:///${
|
|
4779
|
+
let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
4697
4780
|
let vite2 = getVite();
|
|
4698
4781
|
function getBaseOptions({
|
|
4699
4782
|
viteUserConfig
|
|
@@ -4772,7 +4855,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4772
4855
|
ctx.entryClientFilePath,
|
|
4773
4856
|
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
4774
4857
|
(route) => {
|
|
4775
|
-
let routeFilePath =
|
|
4858
|
+
let routeFilePath = path6.resolve(
|
|
4776
4859
|
ctx.reactRouterConfig.appDirectory,
|
|
4777
4860
|
route.file
|
|
4778
4861
|
);
|
|
@@ -4796,7 +4879,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4796
4879
|
) : null;
|
|
4797
4880
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4798
4881
|
let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
4799
|
-
return
|
|
4882
|
+
return path6.posix.join(
|
|
4800
4883
|
assetsDir,
|
|
4801
4884
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4802
4885
|
);
|
|
@@ -4862,7 +4945,867 @@ async function asyncFlatten(arr) {
|
|
|
4862
4945
|
} while (arr.some((v2) => v2?.then));
|
|
4863
4946
|
return arr;
|
|
4864
4947
|
}
|
|
4948
|
+
|
|
4949
|
+
// vite/rsc/plugin.ts
|
|
4950
|
+
var import_es_module_lexer3 = require("es-module-lexer");
|
|
4951
|
+
var Path5 = __toESM(require("pathe"));
|
|
4952
|
+
var babel2 = __toESM(require("@babel/core"));
|
|
4953
|
+
var import_picocolors5 = __toESM(require("picocolors"));
|
|
4954
|
+
var import_fs = require("fs");
|
|
4955
|
+
var import_promises3 = require("fs/promises");
|
|
4956
|
+
var import_pathe6 = __toESM(require("pathe"));
|
|
4957
|
+
|
|
4958
|
+
// vite/rsc/virtual-route-config.ts
|
|
4959
|
+
var import_pathe5 = __toESM(require("pathe"));
|
|
4960
|
+
function createVirtualRouteConfig({
|
|
4961
|
+
appDirectory,
|
|
4962
|
+
routeConfig
|
|
4963
|
+
}) {
|
|
4964
|
+
let routeIdByFile = /* @__PURE__ */ new Map();
|
|
4965
|
+
let code = "export default [";
|
|
4966
|
+
const closeRouteSymbol = Symbol("CLOSE_ROUTE");
|
|
4967
|
+
let stack = [
|
|
4968
|
+
...routeConfig
|
|
4969
|
+
];
|
|
4970
|
+
while (stack.length > 0) {
|
|
4971
|
+
const route = stack.pop();
|
|
4972
|
+
if (!route) break;
|
|
4973
|
+
if (route === closeRouteSymbol) {
|
|
4974
|
+
code += "]},";
|
|
4975
|
+
continue;
|
|
4976
|
+
}
|
|
4977
|
+
code += "{";
|
|
4978
|
+
const routeFile = import_pathe5.default.resolve(appDirectory, route.file);
|
|
4979
|
+
const routeId = route.id || createRouteId2(route.file, appDirectory);
|
|
4980
|
+
routeIdByFile.set(routeFile, routeId);
|
|
4981
|
+
code += `lazy: () => import(${JSON.stringify(
|
|
4982
|
+
`${routeFile}?route-module`
|
|
4983
|
+
)}),`;
|
|
4984
|
+
code += `id: ${JSON.stringify(routeId)},`;
|
|
4985
|
+
if (typeof route.path === "string") {
|
|
4986
|
+
code += `path: ${JSON.stringify(route.path)},`;
|
|
4987
|
+
}
|
|
4988
|
+
if (route.index) {
|
|
4989
|
+
code += `index: true,`;
|
|
4990
|
+
}
|
|
4991
|
+
if (route.caseSensitive) {
|
|
4992
|
+
code += `caseSensitive: true,`;
|
|
4993
|
+
}
|
|
4994
|
+
if (route.children) {
|
|
4995
|
+
code += ["children:["];
|
|
4996
|
+
stack.push(closeRouteSymbol);
|
|
4997
|
+
stack.push(...[...route.children].reverse());
|
|
4998
|
+
} else {
|
|
4999
|
+
code += "},";
|
|
5000
|
+
}
|
|
5001
|
+
}
|
|
5002
|
+
code += "];\n";
|
|
5003
|
+
return { code, routeIdByFile };
|
|
5004
|
+
}
|
|
5005
|
+
function createRouteId2(file, appDirectory) {
|
|
5006
|
+
return import_pathe5.default.relative(appDirectory, file).replace(/\\+/, "/").slice(0, -import_pathe5.default.extname(file).length);
|
|
5007
|
+
}
|
|
5008
|
+
|
|
5009
|
+
// vite/rsc/virtual-route-modules.ts
|
|
5010
|
+
var import_es_module_lexer2 = require("es-module-lexer");
|
|
5011
|
+
var SERVER_ONLY_COMPONENT_EXPORTS = ["ServerComponent"];
|
|
5012
|
+
var SERVER_ONLY_ROUTE_EXPORTS2 = [
|
|
5013
|
+
...SERVER_ONLY_COMPONENT_EXPORTS,
|
|
5014
|
+
"loader",
|
|
5015
|
+
"action",
|
|
5016
|
+
"middleware",
|
|
5017
|
+
"headers"
|
|
5018
|
+
];
|
|
5019
|
+
var SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS2);
|
|
5020
|
+
function isServerOnlyRouteExport(name) {
|
|
5021
|
+
return SERVER_ONLY_ROUTE_EXPORTS_SET.has(name);
|
|
5022
|
+
}
|
|
5023
|
+
var COMMON_COMPONENT_EXPORTS = [
|
|
5024
|
+
"ErrorBoundary",
|
|
5025
|
+
"HydrateFallback",
|
|
5026
|
+
"Layout"
|
|
5027
|
+
];
|
|
5028
|
+
var SERVER_FIRST_COMPONENT_EXPORTS = [
|
|
5029
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
5030
|
+
...SERVER_ONLY_COMPONENT_EXPORTS
|
|
5031
|
+
];
|
|
5032
|
+
var SERVER_FIRST_COMPONENT_EXPORTS_SET = new Set(
|
|
5033
|
+
SERVER_FIRST_COMPONENT_EXPORTS
|
|
5034
|
+
);
|
|
5035
|
+
function isServerFirstComponentExport(name) {
|
|
5036
|
+
return SERVER_FIRST_COMPONENT_EXPORTS_SET.has(
|
|
5037
|
+
name
|
|
5038
|
+
);
|
|
5039
|
+
}
|
|
5040
|
+
var CLIENT_COMPONENT_EXPORTS = [
|
|
5041
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
5042
|
+
"default"
|
|
5043
|
+
];
|
|
5044
|
+
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
5045
|
+
"clientAction",
|
|
5046
|
+
"clientLoader",
|
|
5047
|
+
"clientMiddleware",
|
|
5048
|
+
"handle",
|
|
5049
|
+
"meta",
|
|
5050
|
+
"links",
|
|
5051
|
+
"shouldRevalidate"
|
|
5052
|
+
];
|
|
5053
|
+
var CLIENT_NON_COMPONENT_EXPORTS_SET = new Set(CLIENT_NON_COMPONENT_EXPORTS2);
|
|
5054
|
+
function isClientNonComponentExport(name) {
|
|
5055
|
+
return CLIENT_NON_COMPONENT_EXPORTS_SET.has(name);
|
|
5056
|
+
}
|
|
5057
|
+
var CLIENT_ROUTE_EXPORTS2 = [
|
|
5058
|
+
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
5059
|
+
...CLIENT_COMPONENT_EXPORTS
|
|
5060
|
+
];
|
|
5061
|
+
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
5062
|
+
function isClientRouteExport(name) {
|
|
5063
|
+
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
5064
|
+
}
|
|
5065
|
+
var ROUTE_EXPORTS = [
|
|
5066
|
+
...SERVER_ONLY_ROUTE_EXPORTS2,
|
|
5067
|
+
...CLIENT_ROUTE_EXPORTS2
|
|
5068
|
+
];
|
|
5069
|
+
var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
|
|
5070
|
+
function isRouteExport(name) {
|
|
5071
|
+
return ROUTE_EXPORTS_SET.has(name);
|
|
5072
|
+
}
|
|
5073
|
+
function isCustomRouteExport(name) {
|
|
5074
|
+
return !isRouteExport(name);
|
|
5075
|
+
}
|
|
5076
|
+
function hasReactServerCondition(viteEnvironment) {
|
|
5077
|
+
return viteEnvironment.config.resolve.conditions.includes("react-server");
|
|
5078
|
+
}
|
|
5079
|
+
function transformVirtualRouteModules({
|
|
5080
|
+
id,
|
|
5081
|
+
code,
|
|
5082
|
+
viteCommand,
|
|
5083
|
+
routeIdByFile,
|
|
5084
|
+
rootRouteFile,
|
|
5085
|
+
viteEnvironment
|
|
5086
|
+
}) {
|
|
5087
|
+
if (isVirtualRouteModuleId(id) || routeIdByFile.has(id)) {
|
|
5088
|
+
return createVirtualRouteModuleCode({
|
|
5089
|
+
id,
|
|
5090
|
+
code,
|
|
5091
|
+
rootRouteFile,
|
|
5092
|
+
viteCommand,
|
|
5093
|
+
viteEnvironment
|
|
5094
|
+
});
|
|
5095
|
+
}
|
|
5096
|
+
if (isVirtualServerRouteModuleId(id)) {
|
|
5097
|
+
return createVirtualServerRouteModuleCode({
|
|
5098
|
+
id,
|
|
5099
|
+
code,
|
|
5100
|
+
viteEnvironment
|
|
5101
|
+
});
|
|
5102
|
+
}
|
|
5103
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5104
|
+
return createVirtualClientRouteModuleCode({
|
|
5105
|
+
id,
|
|
5106
|
+
code,
|
|
5107
|
+
rootRouteFile,
|
|
5108
|
+
viteCommand
|
|
5109
|
+
});
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
async function createVirtualRouteModuleCode({
|
|
5113
|
+
id,
|
|
5114
|
+
code: routeSource,
|
|
5115
|
+
rootRouteFile,
|
|
5116
|
+
viteCommand,
|
|
5117
|
+
viteEnvironment
|
|
5118
|
+
}) {
|
|
5119
|
+
const isReactServer = hasReactServerCondition(viteEnvironment);
|
|
5120
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5121
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5122
|
+
const serverModuleId = getVirtualServerModuleId(id);
|
|
5123
|
+
let code = "";
|
|
5124
|
+
if (isServerFirstRoute) {
|
|
5125
|
+
if (staticExports.some(isServerFirstComponentExport)) {
|
|
5126
|
+
code += `import React from "react";
|
|
5127
|
+
`;
|
|
5128
|
+
}
|
|
5129
|
+
for (const staticExport of staticExports) {
|
|
5130
|
+
if (isClientNonComponentExport(staticExport)) {
|
|
5131
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5132
|
+
`;
|
|
5133
|
+
} else if (isReactServer && isServerFirstComponentExport(staticExport) && // Layout wraps all other component exports so doesn't need CSS injected
|
|
5134
|
+
staticExport !== "Layout") {
|
|
5135
|
+
code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
|
|
5136
|
+
`;
|
|
5137
|
+
code += `export ${staticExport === "ServerComponent" ? "default " : " "}function ${staticExport}(props) {
|
|
5138
|
+
`;
|
|
5139
|
+
code += ` return React.createElement(React.Fragment, null,
|
|
5140
|
+
`;
|
|
5141
|
+
code += ` import.meta.viteRsc.loadCss(),
|
|
5142
|
+
`;
|
|
5143
|
+
code += ` React.createElement(${staticExport}WithoutCss, props),
|
|
5144
|
+
`;
|
|
5145
|
+
code += ` );
|
|
5146
|
+
`;
|
|
5147
|
+
code += `}
|
|
5148
|
+
`;
|
|
5149
|
+
} else if (isReactServer && isRouteExport(staticExport)) {
|
|
5150
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5151
|
+
`;
|
|
5152
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5153
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5154
|
+
`;
|
|
5155
|
+
}
|
|
5156
|
+
}
|
|
5157
|
+
if (viteCommand === "serve" && !hasClientExports) {
|
|
5158
|
+
code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
|
|
5159
|
+
`;
|
|
5160
|
+
}
|
|
5161
|
+
} else {
|
|
5162
|
+
for (const staticExport of staticExports) {
|
|
5163
|
+
if (isClientRouteExport(staticExport)) {
|
|
5164
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5165
|
+
`;
|
|
5166
|
+
} else if (isReactServer && isServerOnlyRouteExport(staticExport)) {
|
|
5167
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5168
|
+
`;
|
|
5169
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5170
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5171
|
+
`;
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
}
|
|
5175
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5176
|
+
code += `export { ErrorBoundary } from "${clientModuleId}";
|
|
5177
|
+
`;
|
|
5178
|
+
}
|
|
5179
|
+
return code;
|
|
5180
|
+
}
|
|
5181
|
+
function createVirtualServerRouteModuleCode({
|
|
5182
|
+
id,
|
|
5183
|
+
code: routeSource,
|
|
5184
|
+
viteEnvironment
|
|
5185
|
+
}) {
|
|
5186
|
+
if (!hasReactServerCondition(viteEnvironment)) {
|
|
5187
|
+
throw new Error(
|
|
5188
|
+
[
|
|
5189
|
+
"Virtual server route module was loaded outside of the RSC environment.",
|
|
5190
|
+
`Environment Name: ${viteEnvironment.name}`,
|
|
5191
|
+
`Module ID: ${id}`
|
|
5192
|
+
].join("\n")
|
|
5193
|
+
);
|
|
5194
|
+
}
|
|
5195
|
+
const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
|
|
5196
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5197
|
+
const serverRouteModuleAst = import_parser.parse(routeSource, {
|
|
5198
|
+
sourceType: "module"
|
|
5199
|
+
});
|
|
5200
|
+
removeExports(
|
|
5201
|
+
serverRouteModuleAst,
|
|
5202
|
+
isServerFirstRoute ? CLIENT_NON_COMPONENT_EXPORTS2 : CLIENT_ROUTE_EXPORTS2
|
|
5203
|
+
);
|
|
5204
|
+
const generatorResult = generate(serverRouteModuleAst);
|
|
5205
|
+
if (!isServerFirstRoute) {
|
|
5206
|
+
for (const staticExport of staticExports) {
|
|
5207
|
+
if (isClientRouteExport(staticExport)) {
|
|
5208
|
+
generatorResult.code += "\n";
|
|
5209
|
+
generatorResult.code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5210
|
+
`;
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
return generatorResult;
|
|
5215
|
+
}
|
|
5216
|
+
function createVirtualClientRouteModuleCode({
|
|
5217
|
+
id,
|
|
5218
|
+
code: routeSource,
|
|
5219
|
+
rootRouteFile,
|
|
5220
|
+
viteCommand
|
|
5221
|
+
}) {
|
|
5222
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5223
|
+
const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS2, ...CLIENT_COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS2;
|
|
5224
|
+
const clientRouteModuleAst = import_parser.parse(routeSource, {
|
|
5225
|
+
sourceType: "module"
|
|
5226
|
+
});
|
|
5227
|
+
removeExports(clientRouteModuleAst, exportsToRemove);
|
|
5228
|
+
const generatorResult = generate(clientRouteModuleAst);
|
|
5229
|
+
generatorResult.code = '"use client";' + generatorResult.code;
|
|
5230
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5231
|
+
const hasRootLayout = staticExports.includes("Layout");
|
|
5232
|
+
generatorResult.code += `
|
|
5233
|
+
import { createElement as __rr_createElement } from "react";
|
|
5234
|
+
`;
|
|
5235
|
+
generatorResult.code += `import { UNSAFE_RSCDefaultRootErrorBoundary } from "react-router";
|
|
5236
|
+
`;
|
|
5237
|
+
generatorResult.code += `export function ErrorBoundary() {
|
|
5238
|
+
`;
|
|
5239
|
+
generatorResult.code += ` return __rr_createElement(UNSAFE_RSCDefaultRootErrorBoundary, { hasRootLayout: ${hasRootLayout} });
|
|
5240
|
+
`;
|
|
5241
|
+
generatorResult.code += `}
|
|
5242
|
+
`;
|
|
5243
|
+
}
|
|
5244
|
+
if (viteCommand === "serve" && isServerFirstRoute && !hasClientExports) {
|
|
5245
|
+
generatorResult.code += `
|
|
5246
|
+
export const __ensureClientRouteModuleForHMR = true;`;
|
|
5247
|
+
}
|
|
5248
|
+
return generatorResult;
|
|
5249
|
+
}
|
|
5250
|
+
function parseRouteExports(code) {
|
|
5251
|
+
const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
|
|
5252
|
+
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
5253
|
+
const isServerFirstRoute = staticExports.some(
|
|
5254
|
+
(staticExport) => staticExport === "ServerComponent"
|
|
5255
|
+
);
|
|
5256
|
+
return {
|
|
5257
|
+
staticExports,
|
|
5258
|
+
isServerFirstRoute,
|
|
5259
|
+
hasClientExports: staticExports.some(
|
|
5260
|
+
isServerFirstRoute ? isClientNonComponentExport : isClientRouteExport
|
|
5261
|
+
)
|
|
5262
|
+
};
|
|
5263
|
+
}
|
|
5264
|
+
function getVirtualClientModuleId(id) {
|
|
5265
|
+
return `${id.split("?")[0]}?client-route-module`;
|
|
5266
|
+
}
|
|
5267
|
+
function getVirtualServerModuleId(id) {
|
|
5268
|
+
return `${id.split("?")[0]}?server-route-module`;
|
|
5269
|
+
}
|
|
5270
|
+
function isVirtualRouteModuleId(id) {
|
|
5271
|
+
return /(\?|&)route-module(&|$)/.test(id);
|
|
5272
|
+
}
|
|
5273
|
+
function isVirtualClientRouteModuleId(id) {
|
|
5274
|
+
return /(\?|&)client-route-module(&|$)/.test(id);
|
|
5275
|
+
}
|
|
5276
|
+
function isVirtualServerRouteModuleId(id) {
|
|
5277
|
+
return /(\?|&)server-route-module(&|$)/.test(id);
|
|
5278
|
+
}
|
|
5279
|
+
function isRootRouteFile({
|
|
5280
|
+
id,
|
|
5281
|
+
rootRouteFile
|
|
5282
|
+
}) {
|
|
5283
|
+
const filePath = id.split("?")[0];
|
|
5284
|
+
return filePath === rootRouteFile;
|
|
5285
|
+
}
|
|
5286
|
+
|
|
5287
|
+
// vite/rsc/plugin.ts
|
|
5288
|
+
function reactRouterRSCVitePlugin() {
|
|
5289
|
+
let configLoader;
|
|
5290
|
+
let typegenWatcherPromise;
|
|
5291
|
+
let viteCommand;
|
|
5292
|
+
let routeIdByFile;
|
|
5293
|
+
let logger;
|
|
5294
|
+
const defaultEntries2 = getDefaultEntries();
|
|
5295
|
+
let config;
|
|
5296
|
+
let rootRouteFile;
|
|
5297
|
+
function updateConfig(newConfig) {
|
|
5298
|
+
config = newConfig;
|
|
5299
|
+
rootRouteFile = Path5.resolve(
|
|
5300
|
+
newConfig.appDirectory,
|
|
5301
|
+
newConfig.routes.root.file
|
|
5302
|
+
);
|
|
5303
|
+
}
|
|
5304
|
+
return [
|
|
5305
|
+
{
|
|
5306
|
+
name: "react-router/rsc",
|
|
5307
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5308
|
+
await import_es_module_lexer3.init;
|
|
5309
|
+
await preloadVite();
|
|
5310
|
+
viteCommand = command;
|
|
5311
|
+
const rootDirectory = getRootDirectory(viteUserConfig);
|
|
5312
|
+
const watch2 = command === "serve";
|
|
5313
|
+
configLoader = await createConfigLoader({
|
|
5314
|
+
rootDirectory,
|
|
5315
|
+
mode,
|
|
5316
|
+
watch: watch2,
|
|
5317
|
+
validateConfig: (userConfig) => {
|
|
5318
|
+
let errors = [];
|
|
5319
|
+
if (userConfig.buildEnd) errors.push("buildEnd");
|
|
5320
|
+
if (userConfig.prerender) errors.push("prerender");
|
|
5321
|
+
if (userConfig.presets?.length) errors.push("presets");
|
|
5322
|
+
if (userConfig.routeDiscovery) errors.push("routeDiscovery");
|
|
5323
|
+
if (userConfig.serverBundles) errors.push("serverBundles");
|
|
5324
|
+
if (userConfig.ssr === false) errors.push("ssr: false");
|
|
5325
|
+
if (userConfig.future?.unstable_splitRouteModules)
|
|
5326
|
+
errors.push("future.unstable_splitRouteModules");
|
|
5327
|
+
if (userConfig.future?.unstable_viteEnvironmentApi === false)
|
|
5328
|
+
errors.push("future.unstable_viteEnvironmentApi: false");
|
|
5329
|
+
if (userConfig.future?.v8_middleware === false)
|
|
5330
|
+
errors.push("future.v8_middleware: false");
|
|
5331
|
+
if (userConfig.future?.unstable_subResourceIntegrity)
|
|
5332
|
+
errors.push("future.unstable_subResourceIntegrity");
|
|
5333
|
+
if (errors.length) {
|
|
5334
|
+
return `RSC Framework Mode does not currently support the following React Router config:
|
|
5335
|
+
${errors.map((x) => ` - ${x}`).join("\n")}
|
|
5336
|
+
`;
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
});
|
|
5340
|
+
const configResult = await configLoader.getConfig();
|
|
5341
|
+
if (!configResult.ok) throw new Error(configResult.error);
|
|
5342
|
+
updateConfig(configResult.value);
|
|
5343
|
+
if (viteUserConfig.base && config.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !config.basename.startsWith(viteUserConfig.base)) {
|
|
5344
|
+
throw new Error(
|
|
5345
|
+
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
5346
|
+
);
|
|
5347
|
+
}
|
|
5348
|
+
await loadDotenv({
|
|
5349
|
+
rootDirectory,
|
|
5350
|
+
viteUserConfig,
|
|
5351
|
+
mode
|
|
5352
|
+
});
|
|
5353
|
+
const vite2 = await import("vite");
|
|
5354
|
+
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
5355
|
+
prefix: "[react-router]"
|
|
5356
|
+
});
|
|
5357
|
+
return {
|
|
5358
|
+
resolve: {
|
|
5359
|
+
dedupe: [
|
|
5360
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5361
|
+
"react",
|
|
5362
|
+
"react-dom",
|
|
5363
|
+
// Avoid router duplicates since mismatching routers cause `Error:
|
|
5364
|
+
// You must render this element inside a <Remix> element`.
|
|
5365
|
+
"react-router",
|
|
5366
|
+
"react-router/dom",
|
|
5367
|
+
...hasDependency({ name: "react-router-dom", rootDirectory }) ? ["react-router-dom"] : []
|
|
5368
|
+
]
|
|
5369
|
+
},
|
|
5370
|
+
optimizeDeps: {
|
|
5371
|
+
entries: getOptimizeDepsEntries({
|
|
5372
|
+
entryClientFilePath: defaultEntries2.client,
|
|
5373
|
+
reactRouterConfig: config
|
|
5374
|
+
}),
|
|
5375
|
+
esbuildOptions: {
|
|
5376
|
+
jsx: "automatic"
|
|
5377
|
+
},
|
|
5378
|
+
include: [
|
|
5379
|
+
// Pre-bundle React dependencies to avoid React duplicates,
|
|
5380
|
+
// even if React dependencies are not direct dependencies.
|
|
5381
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5382
|
+
"react",
|
|
5383
|
+
"react/jsx-runtime",
|
|
5384
|
+
"react/jsx-dev-runtime",
|
|
5385
|
+
"react-dom",
|
|
5386
|
+
"react-dom/client",
|
|
5387
|
+
"react-router/internal/react-server-client"
|
|
5388
|
+
]
|
|
5389
|
+
},
|
|
5390
|
+
esbuild: {
|
|
5391
|
+
jsx: "automatic",
|
|
5392
|
+
jsxDev: viteCommand !== "build"
|
|
5393
|
+
},
|
|
5394
|
+
environments: {
|
|
5395
|
+
client: {
|
|
5396
|
+
build: {
|
|
5397
|
+
rollupOptions: {
|
|
5398
|
+
input: {
|
|
5399
|
+
index: defaultEntries2.client
|
|
5400
|
+
}
|
|
5401
|
+
},
|
|
5402
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "client")
|
|
5403
|
+
}
|
|
5404
|
+
},
|
|
5405
|
+
rsc: {
|
|
5406
|
+
build: {
|
|
5407
|
+
rollupOptions: {
|
|
5408
|
+
input: {
|
|
5409
|
+
// We use a virtual entry here so that consumers can import
|
|
5410
|
+
// it as `virtual:react-router/unstable_rsc/rsc-entry`
|
|
5411
|
+
// without needing to know the actual file path, which is
|
|
5412
|
+
// important when using the default entries.
|
|
5413
|
+
index: defaultEntries2.rsc
|
|
5414
|
+
},
|
|
5415
|
+
output: {
|
|
5416
|
+
entryFileNames: config.serverBuildFile,
|
|
5417
|
+
format: config.serverModuleFormat
|
|
5418
|
+
}
|
|
5419
|
+
},
|
|
5420
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server")
|
|
5421
|
+
}
|
|
5422
|
+
},
|
|
5423
|
+
ssr: {
|
|
5424
|
+
build: {
|
|
5425
|
+
rollupOptions: {
|
|
5426
|
+
input: {
|
|
5427
|
+
index: defaultEntries2.ssr
|
|
5428
|
+
},
|
|
5429
|
+
output: {
|
|
5430
|
+
// Note: We don't set `entryFileNames` here because it's
|
|
5431
|
+
// considered private to the RSC environment build, and
|
|
5432
|
+
// @vitejs/plugin-rsc currently breaks if it's set to
|
|
5433
|
+
// something other than `index.js`.
|
|
5434
|
+
format: config.serverModuleFormat
|
|
5435
|
+
}
|
|
5436
|
+
},
|
|
5437
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server/__ssr_build")
|
|
5438
|
+
}
|
|
5439
|
+
}
|
|
5440
|
+
},
|
|
5441
|
+
build: {
|
|
5442
|
+
rollupOptions: {
|
|
5443
|
+
// Copied from https://github.com/vitejs/vite-plugin-react/blob/c602225271d4acf462ba00f8d6d8a2e42492c5cd/packages/common/warning.ts
|
|
5444
|
+
onwarn(warning, defaultHandler) {
|
|
5445
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
|
|
5446
|
+
return;
|
|
5447
|
+
}
|
|
5448
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
5449
|
+
return;
|
|
5450
|
+
}
|
|
5451
|
+
if (viteUserConfig.build?.rollupOptions?.onwarn) {
|
|
5452
|
+
viteUserConfig.build.rollupOptions.onwarn(
|
|
5453
|
+
warning,
|
|
5454
|
+
defaultHandler
|
|
5455
|
+
);
|
|
5456
|
+
} else {
|
|
5457
|
+
defaultHandler(warning);
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
}
|
|
5461
|
+
}
|
|
5462
|
+
};
|
|
5463
|
+
},
|
|
5464
|
+
async configureServer(viteDevServer) {
|
|
5465
|
+
configLoader.onChange(
|
|
5466
|
+
async ({
|
|
5467
|
+
result,
|
|
5468
|
+
configCodeChanged,
|
|
5469
|
+
routeConfigCodeChanged,
|
|
5470
|
+
configChanged,
|
|
5471
|
+
routeConfigChanged
|
|
5472
|
+
}) => {
|
|
5473
|
+
if (!result.ok) {
|
|
5474
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5475
|
+
logger.error(result.error, {
|
|
5476
|
+
clear: true,
|
|
5477
|
+
timestamp: true
|
|
5478
|
+
});
|
|
5479
|
+
return;
|
|
5480
|
+
}
|
|
5481
|
+
let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
|
|
5482
|
+
logger.info(import_picocolors5.default.green(message), {
|
|
5483
|
+
clear: true,
|
|
5484
|
+
timestamp: true
|
|
5485
|
+
});
|
|
5486
|
+
updateConfig(result.value);
|
|
5487
|
+
if (configChanged || routeConfigChanged) {
|
|
5488
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
);
|
|
5492
|
+
},
|
|
5493
|
+
async buildEnd() {
|
|
5494
|
+
await configLoader.close();
|
|
5495
|
+
}
|
|
5496
|
+
},
|
|
5497
|
+
{
|
|
5498
|
+
name: "react-router/rsc/typegen",
|
|
5499
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5500
|
+
if (command === "serve") {
|
|
5501
|
+
const vite2 = await import("vite");
|
|
5502
|
+
typegenWatcherPromise = watch(
|
|
5503
|
+
getRootDirectory(viteUserConfig),
|
|
5504
|
+
{
|
|
5505
|
+
mode,
|
|
5506
|
+
rsc: true,
|
|
5507
|
+
// ignore `info` logs from typegen since they are
|
|
5508
|
+
// redundant when Vite plugin logs are active
|
|
5509
|
+
logger: vite2.createLogger("warn", {
|
|
5510
|
+
prefix: "[react-router]"
|
|
5511
|
+
})
|
|
5512
|
+
}
|
|
5513
|
+
);
|
|
5514
|
+
}
|
|
5515
|
+
},
|
|
5516
|
+
async buildEnd() {
|
|
5517
|
+
(await typegenWatcherPromise)?.close();
|
|
5518
|
+
}
|
|
5519
|
+
},
|
|
5520
|
+
{
|
|
5521
|
+
name: "react-router/rsc/virtual-rsc-entry",
|
|
5522
|
+
resolveId(id) {
|
|
5523
|
+
if (id === virtual2.rscEntry.id) return defaultEntries2.rsc;
|
|
5524
|
+
}
|
|
5525
|
+
},
|
|
5526
|
+
{
|
|
5527
|
+
name: "react-router/rsc/virtual-route-config",
|
|
5528
|
+
resolveId(id) {
|
|
5529
|
+
if (id === virtual2.routeConfig.id) {
|
|
5530
|
+
return virtual2.routeConfig.resolvedId;
|
|
5531
|
+
}
|
|
5532
|
+
},
|
|
5533
|
+
load(id) {
|
|
5534
|
+
if (id === virtual2.routeConfig.resolvedId) {
|
|
5535
|
+
const result = createVirtualRouteConfig({
|
|
5536
|
+
appDirectory: config.appDirectory,
|
|
5537
|
+
routeConfig: config.unstable_routeConfig
|
|
5538
|
+
});
|
|
5539
|
+
routeIdByFile = result.routeIdByFile;
|
|
5540
|
+
return result.code;
|
|
5541
|
+
}
|
|
5542
|
+
}
|
|
5543
|
+
},
|
|
5544
|
+
{
|
|
5545
|
+
name: "react-router/rsc/virtual-route-modules",
|
|
5546
|
+
transform(code, id) {
|
|
5547
|
+
if (!routeIdByFile) return;
|
|
5548
|
+
return transformVirtualRouteModules({
|
|
5549
|
+
code,
|
|
5550
|
+
id,
|
|
5551
|
+
viteCommand,
|
|
5552
|
+
routeIdByFile,
|
|
5553
|
+
rootRouteFile,
|
|
5554
|
+
viteEnvironment: this.environment
|
|
5555
|
+
});
|
|
5556
|
+
}
|
|
5557
|
+
},
|
|
5558
|
+
{
|
|
5559
|
+
name: "react-router/rsc/virtual-basename",
|
|
5560
|
+
resolveId(id) {
|
|
5561
|
+
if (id === virtual2.basename.id) {
|
|
5562
|
+
return virtual2.basename.resolvedId;
|
|
5563
|
+
}
|
|
5564
|
+
},
|
|
5565
|
+
load(id) {
|
|
5566
|
+
if (id === virtual2.basename.resolvedId) {
|
|
5567
|
+
return `export default ${JSON.stringify(config.basename)};`;
|
|
5568
|
+
}
|
|
5569
|
+
}
|
|
5570
|
+
},
|
|
5571
|
+
{
|
|
5572
|
+
name: "react-router/rsc/hmr/inject-runtime",
|
|
5573
|
+
enforce: "pre",
|
|
5574
|
+
resolveId(id) {
|
|
5575
|
+
if (id === virtual2.injectHmrRuntime.id) {
|
|
5576
|
+
return virtual2.injectHmrRuntime.resolvedId;
|
|
5577
|
+
}
|
|
5578
|
+
},
|
|
5579
|
+
async load(id) {
|
|
5580
|
+
if (id !== virtual2.injectHmrRuntime.resolvedId) return;
|
|
5581
|
+
return viteCommand === "serve" ? [
|
|
5582
|
+
`import RefreshRuntime from "${virtual2.hmrRuntime.id}"`,
|
|
5583
|
+
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
5584
|
+
"window.$RefreshReg$ = () => {}",
|
|
5585
|
+
"window.$RefreshSig$ = () => (type) => type",
|
|
5586
|
+
"window.__vite_plugin_react_preamble_installed__ = true"
|
|
5587
|
+
].join("\n") : "";
|
|
5588
|
+
}
|
|
5589
|
+
},
|
|
5590
|
+
{
|
|
5591
|
+
name: "react-router/rsc/hmr/runtime",
|
|
5592
|
+
enforce: "pre",
|
|
5593
|
+
resolveId(id) {
|
|
5594
|
+
if (id === virtual2.hmrRuntime.id) return virtual2.hmrRuntime.resolvedId;
|
|
5595
|
+
},
|
|
5596
|
+
async load(id) {
|
|
5597
|
+
if (id !== virtual2.hmrRuntime.resolvedId) return;
|
|
5598
|
+
const reactRefreshDir = import_pathe6.default.dirname(
|
|
5599
|
+
require.resolve("react-refresh/package.json")
|
|
5600
|
+
);
|
|
5601
|
+
const reactRefreshRuntimePath = import_pathe6.default.join(
|
|
5602
|
+
reactRefreshDir,
|
|
5603
|
+
"cjs/react-refresh-runtime.development.js"
|
|
5604
|
+
);
|
|
5605
|
+
return [
|
|
5606
|
+
"const exports = {}",
|
|
5607
|
+
await (0, import_promises3.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
5608
|
+
await (0, import_promises3.readFile)(
|
|
5609
|
+
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
5610
|
+
"utf8"
|
|
5611
|
+
),
|
|
5612
|
+
"export default exports"
|
|
5613
|
+
].join("\n");
|
|
5614
|
+
}
|
|
5615
|
+
},
|
|
5616
|
+
{
|
|
5617
|
+
name: "react-router/rsc/hmr/react-refresh",
|
|
5618
|
+
async transform(code, id, options) {
|
|
5619
|
+
if (viteCommand !== "serve") return;
|
|
5620
|
+
if (id.includes("/node_modules/")) return;
|
|
5621
|
+
const filepath = id.split("?")[0];
|
|
5622
|
+
const extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
5623
|
+
if (!extensionsRE.test(filepath)) return;
|
|
5624
|
+
const devRuntime = "react/jsx-dev-runtime";
|
|
5625
|
+
const ssr = options?.ssr === true;
|
|
5626
|
+
const isJSX = filepath.endsWith("x");
|
|
5627
|
+
const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
5628
|
+
if (!useFastRefresh) return;
|
|
5629
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5630
|
+
const routeId = routeIdByFile?.get(filepath);
|
|
5631
|
+
return { code: addRefreshWrapper2({ routeId, code, id }) };
|
|
5632
|
+
}
|
|
5633
|
+
const result = await babel2.transformAsync(code, {
|
|
5634
|
+
babelrc: false,
|
|
5635
|
+
configFile: false,
|
|
5636
|
+
filename: id,
|
|
5637
|
+
sourceFileName: filepath,
|
|
5638
|
+
parserOpts: {
|
|
5639
|
+
sourceType: "module",
|
|
5640
|
+
allowAwaitOutsideFunction: true
|
|
5641
|
+
},
|
|
5642
|
+
plugins: [[require("react-refresh/babel"), { skipEnvCheck: true }]],
|
|
5643
|
+
sourceMaps: true
|
|
5644
|
+
});
|
|
5645
|
+
if (result === null) return;
|
|
5646
|
+
code = result.code;
|
|
5647
|
+
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
5648
|
+
if (refreshContentRE.test(code)) {
|
|
5649
|
+
code = addRefreshWrapper2({ code, id });
|
|
5650
|
+
}
|
|
5651
|
+
return { code, map: result.map };
|
|
5652
|
+
}
|
|
5653
|
+
},
|
|
5654
|
+
{
|
|
5655
|
+
name: "react-router/rsc/hmr/updates",
|
|
5656
|
+
async hotUpdate({ server, file, modules }) {
|
|
5657
|
+
if (this.environment.name !== "rsc") return;
|
|
5658
|
+
const clientModules = server.environments.client.moduleGraph.getModulesByFile(file);
|
|
5659
|
+
const vite2 = await import("vite");
|
|
5660
|
+
const isServerOnlyChange = !clientModules || clientModules.size === 0 || // Handle CSS injected from server-first routes (with ?direct query
|
|
5661
|
+
// string) since the client graph has a reference to the CSS
|
|
5662
|
+
vite2.isCSSRequest(file) && Array.from(clientModules).some(
|
|
5663
|
+
(mod) => mod.id?.includes("?direct")
|
|
5664
|
+
);
|
|
5665
|
+
for (const mod of getModulesWithImporters(modules)) {
|
|
5666
|
+
if (!mod.file) continue;
|
|
5667
|
+
const normalizedPath = import_pathe6.default.normalize(mod.file);
|
|
5668
|
+
const routeId = routeIdByFile?.get(normalizedPath);
|
|
5669
|
+
if (routeId !== void 0) {
|
|
5670
|
+
const routeSource = await (0, import_promises3.readFile)(normalizedPath, "utf8");
|
|
5671
|
+
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
5672
|
+
routeSource,
|
|
5673
|
+
`${normalizedPath}?route-module`
|
|
5674
|
+
)).code;
|
|
5675
|
+
const { staticExports } = parseRouteExports(virtualRouteModuleCode);
|
|
5676
|
+
const hasAction = staticExports.includes("action");
|
|
5677
|
+
const hasComponent = staticExports.includes("default");
|
|
5678
|
+
const hasErrorBoundary = staticExports.includes("ErrorBoundary");
|
|
5679
|
+
const hasLoader = staticExports.includes("loader");
|
|
5680
|
+
server.hot.send({
|
|
5681
|
+
type: "custom",
|
|
5682
|
+
event: "react-router:hmr",
|
|
5683
|
+
data: {
|
|
5684
|
+
routeId,
|
|
5685
|
+
isServerOnlyChange,
|
|
5686
|
+
hasAction,
|
|
5687
|
+
hasComponent,
|
|
5688
|
+
hasErrorBoundary,
|
|
5689
|
+
hasLoader
|
|
5690
|
+
}
|
|
5691
|
+
});
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
return modules;
|
|
5695
|
+
}
|
|
5696
|
+
},
|
|
5697
|
+
validatePluginOrder(),
|
|
5698
|
+
warnOnClientSourceMaps()
|
|
5699
|
+
];
|
|
5700
|
+
}
|
|
5701
|
+
var virtual2 = {
|
|
5702
|
+
routeConfig: create("unstable_rsc/routes"),
|
|
5703
|
+
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
5704
|
+
hmrRuntime: create("unstable_rsc/runtime"),
|
|
5705
|
+
basename: create("unstable_rsc/basename"),
|
|
5706
|
+
rscEntry: create("unstable_rsc/rsc-entry")
|
|
5707
|
+
};
|
|
5708
|
+
function invalidateVirtualModules2(viteDevServer) {
|
|
5709
|
+
for (const vmod of Object.values(virtual2)) {
|
|
5710
|
+
for (const env of Object.values(viteDevServer.environments)) {
|
|
5711
|
+
const mod = env.moduleGraph.getModuleById(vmod.resolvedId);
|
|
5712
|
+
if (mod) {
|
|
5713
|
+
env.moduleGraph.invalidateModule(mod);
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
function getRootDirectory(viteUserConfig) {
|
|
5719
|
+
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
5720
|
+
}
|
|
5721
|
+
function getDevPackageRoot() {
|
|
5722
|
+
const currentDir = (0, import_pathe6.dirname)(__dirname);
|
|
5723
|
+
let dir = currentDir;
|
|
5724
|
+
while (dir !== (0, import_pathe6.dirname)(dir)) {
|
|
5725
|
+
try {
|
|
5726
|
+
const packageJsonPath = (0, import_pathe6.join)(dir, "package.json");
|
|
5727
|
+
(0, import_fs.readFileSync)(packageJsonPath, "utf-8");
|
|
5728
|
+
return dir;
|
|
5729
|
+
} catch {
|
|
5730
|
+
dir = (0, import_pathe6.dirname)(dir);
|
|
5731
|
+
}
|
|
5732
|
+
}
|
|
5733
|
+
throw new Error("Could not find package.json");
|
|
5734
|
+
}
|
|
5735
|
+
function getDefaultEntries() {
|
|
5736
|
+
const defaultEntriesDir2 = (0, import_pathe6.join)(
|
|
5737
|
+
getDevPackageRoot(),
|
|
5738
|
+
"dist",
|
|
5739
|
+
"config",
|
|
5740
|
+
"default-rsc-entries"
|
|
5741
|
+
);
|
|
5742
|
+
return {
|
|
5743
|
+
rsc: (0, import_pathe6.join)(defaultEntriesDir2, "entry.rsc.tsx"),
|
|
5744
|
+
ssr: (0, import_pathe6.join)(defaultEntriesDir2, "entry.ssr.tsx"),
|
|
5745
|
+
client: (0, import_pathe6.join)(defaultEntriesDir2, "entry.client.tsx")
|
|
5746
|
+
};
|
|
5747
|
+
}
|
|
5748
|
+
function getModulesWithImporters(modules) {
|
|
5749
|
+
const visited = /* @__PURE__ */ new Set();
|
|
5750
|
+
const result = /* @__PURE__ */ new Set();
|
|
5751
|
+
function walk(module2) {
|
|
5752
|
+
if (visited.has(module2)) return;
|
|
5753
|
+
visited.add(module2);
|
|
5754
|
+
result.add(module2);
|
|
5755
|
+
for (const importer of module2.importers) {
|
|
5756
|
+
walk(importer);
|
|
5757
|
+
}
|
|
5758
|
+
}
|
|
5759
|
+
for (const module2 of modules) {
|
|
5760
|
+
walk(module2);
|
|
5761
|
+
}
|
|
5762
|
+
return result;
|
|
5763
|
+
}
|
|
5764
|
+
function addRefreshWrapper2({
|
|
5765
|
+
routeId,
|
|
5766
|
+
code,
|
|
5767
|
+
id
|
|
5768
|
+
}) {
|
|
5769
|
+
const acceptExports = routeId !== void 0 ? CLIENT_NON_COMPONENT_EXPORTS2 : [];
|
|
5770
|
+
return REACT_REFRESH_HEADER2.replaceAll("__SOURCE__", JSON.stringify(id)) + code + REACT_REFRESH_FOOTER2.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(routeId));
|
|
5771
|
+
}
|
|
5772
|
+
var REACT_REFRESH_HEADER2 = `
|
|
5773
|
+
import RefreshRuntime from "${virtual2.hmrRuntime.id}";
|
|
5774
|
+
|
|
5775
|
+
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
5776
|
+
let prevRefreshReg;
|
|
5777
|
+
let prevRefreshSig;
|
|
5778
|
+
|
|
5779
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5780
|
+
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
5781
|
+
throw new Error(
|
|
5782
|
+
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
5783
|
+
);
|
|
5784
|
+
}
|
|
5785
|
+
|
|
5786
|
+
prevRefreshReg = window.$RefreshReg$;
|
|
5787
|
+
prevRefreshSig = window.$RefreshSig$;
|
|
5788
|
+
window.$RefreshReg$ = (type, id) => {
|
|
5789
|
+
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
5790
|
+
};
|
|
5791
|
+
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
5792
|
+
}`.replaceAll("\n", "");
|
|
5793
|
+
var REACT_REFRESH_FOOTER2 = `
|
|
5794
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5795
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
5796
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
5797
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
5798
|
+
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
|
|
5799
|
+
import.meta.hot.accept((nextExports) => {
|
|
5800
|
+
if (!nextExports) return;
|
|
5801
|
+
__ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
|
|
5802
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
|
|
5803
|
+
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
5804
|
+
});
|
|
5805
|
+
});
|
|
5806
|
+
}`;
|
|
4865
5807
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4866
5808
|
0 && (module.exports = {
|
|
4867
|
-
reactRouter
|
|
5809
|
+
reactRouter,
|
|
5810
|
+
unstable_reactRouterRSC
|
|
4868
5811
|
});
|