@react-router/dev 7.8.2 → 7.9.0-pre.0
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 +21 -7
- package/dist/cli/index.js +185 -84
- package/dist/config/default-rsc-entries/entry.client.tsx +9 -1
- package/dist/config/default-rsc-entries/entry.rsc.tsx +9 -1
- package/dist/config/default-rsc-entries/entry.ssr.tsx +7 -1
- package/dist/config/defaults/entry.server.node.tsx +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/internal.js +341 -99
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.d.ts +2 -2
- package/dist/vite/cloudflare.js +19 -5
- package/dist/vite.js +318 -264
- package/package.json +11 -7
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.
|
|
2
|
+
* @react-router/dev v7.9.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -48,15 +48,14 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
48
48
|
var import_node_crypto = require("crypto");
|
|
49
49
|
var import_node_fs2 = require("fs");
|
|
50
50
|
var import_promises2 = require("fs/promises");
|
|
51
|
-
var
|
|
51
|
+
var path6 = __toESM(require("path"));
|
|
52
52
|
var url = __toESM(require("url"));
|
|
53
53
|
var babel = __toESM(require("@babel/core"));
|
|
54
54
|
var import_react_router2 = require("react-router");
|
|
55
55
|
var import_es_module_lexer = require("es-module-lexer");
|
|
56
|
-
var import_tinyglobby = require("tinyglobby");
|
|
57
56
|
var import_pick3 = __toESM(require("lodash/pick"));
|
|
58
57
|
var import_jsesc = __toESM(require("jsesc"));
|
|
59
|
-
var
|
|
58
|
+
var import_picocolors4 = __toESM(require("picocolors"));
|
|
60
59
|
var import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
61
60
|
|
|
62
61
|
// typegen/index.ts
|
|
@@ -247,7 +246,7 @@ function validateRouteConfig({
|
|
|
247
246
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
248
247
|
root ? `${root}` : [],
|
|
249
248
|
nested ? Object.entries(nested).map(
|
|
250
|
-
([
|
|
249
|
+
([path7, message]) => `Path: routes.${path7}
|
|
251
250
|
${message}`
|
|
252
251
|
) : []
|
|
253
252
|
].flat().join("\n\n")
|
|
@@ -367,7 +366,8 @@ async function resolveConfig({
|
|
|
367
366
|
root,
|
|
368
367
|
viteNodeContext,
|
|
369
368
|
reactRouterConfigFile,
|
|
370
|
-
skipRoutes
|
|
369
|
+
skipRoutes,
|
|
370
|
+
validateConfig
|
|
371
371
|
}) {
|
|
372
372
|
let reactRouterUserConfig = {};
|
|
373
373
|
if (reactRouterConfigFile) {
|
|
@@ -385,6 +385,12 @@ async function resolveConfig({
|
|
|
385
385
|
return err(`${reactRouterConfigFile} must export a config`);
|
|
386
386
|
}
|
|
387
387
|
reactRouterUserConfig = configModule.default;
|
|
388
|
+
if (validateConfig) {
|
|
389
|
+
const error = validateConfig(reactRouterUserConfig);
|
|
390
|
+
if (error) {
|
|
391
|
+
return err(error);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
388
394
|
} catch (error) {
|
|
389
395
|
return err(`Error loading ${reactRouterConfigFile}: ${error}`);
|
|
390
396
|
}
|
|
@@ -533,7 +539,7 @@ async function resolveConfig({
|
|
|
533
539
|
}
|
|
534
540
|
}
|
|
535
541
|
let future = {
|
|
536
|
-
|
|
542
|
+
v8_middleware: reactRouterUserConfig.future?.v8_middleware ?? false,
|
|
537
543
|
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
|
|
538
544
|
unstable_splitRouteModules: reactRouterUserConfig.future?.unstable_splitRouteModules ?? false,
|
|
539
545
|
unstable_subResourceIntegrity: reactRouterUserConfig.future?.unstable_subResourceIntegrity ?? false,
|
|
@@ -563,7 +569,8 @@ async function createConfigLoader({
|
|
|
563
569
|
rootDirectory: root,
|
|
564
570
|
watch: watch2,
|
|
565
571
|
mode,
|
|
566
|
-
skipRoutes
|
|
572
|
+
skipRoutes,
|
|
573
|
+
validateConfig
|
|
567
574
|
}) {
|
|
568
575
|
root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
|
|
569
576
|
let vite2 = await import("vite");
|
|
@@ -582,7 +589,13 @@ async function createConfigLoader({
|
|
|
582
589
|
});
|
|
583
590
|
};
|
|
584
591
|
updateReactRouterConfigFile();
|
|
585
|
-
let getConfig = () => resolveConfig({
|
|
592
|
+
let getConfig = () => resolveConfig({
|
|
593
|
+
root,
|
|
594
|
+
viteNodeContext,
|
|
595
|
+
reactRouterConfigFile,
|
|
596
|
+
skipRoutes,
|
|
597
|
+
validateConfig
|
|
598
|
+
});
|
|
586
599
|
let appDirectory;
|
|
587
600
|
let initialConfigResult = await getConfig();
|
|
588
601
|
if (!initialConfigResult.ok) {
|
|
@@ -604,11 +617,11 @@ async function createConfigLoader({
|
|
|
604
617
|
if (!fsWatcher) {
|
|
605
618
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
606
619
|
ignoreInitial: true,
|
|
607
|
-
ignored: (
|
|
608
|
-
let dirname4 = import_pathe3.default.dirname(
|
|
620
|
+
ignored: (path7) => {
|
|
621
|
+
let dirname4 = import_pathe3.default.dirname(path7);
|
|
609
622
|
return !dirname4.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
610
623
|
// that are at the root level, not nested in subdirectories
|
|
611
|
-
|
|
624
|
+
path7 !== root && // Watch the root directory itself
|
|
612
625
|
dirname4 !== root;
|
|
613
626
|
}
|
|
614
627
|
});
|
|
@@ -867,7 +880,7 @@ function fullpath(lineage2) {
|
|
|
867
880
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
868
881
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
869
882
|
if (isLayout) return void 0;
|
|
870
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
883
|
+
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path7) => path7 !== void 0 && path7 !== "").join("/");
|
|
871
884
|
}
|
|
872
885
|
|
|
873
886
|
// typegen/generate.ts
|
|
@@ -883,7 +896,7 @@ function generateFuture(ctx) {
|
|
|
883
896
|
|
|
884
897
|
declare module "react-router" {
|
|
885
898
|
interface Future {
|
|
886
|
-
|
|
899
|
+
middleware: ${ctx.config.future.v8_middleware}
|
|
887
900
|
}
|
|
888
901
|
}
|
|
889
902
|
`;
|
|
@@ -1023,8 +1036,8 @@ function routeFilesType({
|
|
|
1023
1036
|
);
|
|
1024
1037
|
}
|
|
1025
1038
|
function isInAppDirectory(ctx, routeFile) {
|
|
1026
|
-
const
|
|
1027
|
-
return
|
|
1039
|
+
const path7 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1040
|
+
return path7.startsWith(ctx.config.appDirectory);
|
|
1028
1041
|
}
|
|
1029
1042
|
function getRouteAnnotations({
|
|
1030
1043
|
ctx,
|
|
@@ -1105,11 +1118,11 @@ function getRouteAnnotations({
|
|
|
1105
1118
|
export type HeadersArgs = Annotations["HeadersArgs"];
|
|
1106
1119
|
export type HeadersFunction = Annotations["HeadersFunction"];
|
|
1107
1120
|
|
|
1108
|
-
//
|
|
1109
|
-
export type
|
|
1121
|
+
// middleware
|
|
1122
|
+
export type MiddlewareFunction = Annotations["MiddlewareFunction"];
|
|
1110
1123
|
|
|
1111
|
-
//
|
|
1112
|
-
export type
|
|
1124
|
+
// clientMiddleware
|
|
1125
|
+
export type ClientMiddlewareFunction = Annotations["ClientMiddlewareFunction"];
|
|
1113
1126
|
|
|
1114
1127
|
// loader
|
|
1115
1128
|
export type LoaderArgs = Annotations["LoaderArgs"];
|
|
@@ -1136,21 +1149,21 @@ function getRouteAnnotations({
|
|
|
1136
1149
|
return { filename: filename2, content };
|
|
1137
1150
|
}
|
|
1138
1151
|
function relativeImportSource(from, to) {
|
|
1139
|
-
let
|
|
1140
|
-
let extension = Path3.extname(
|
|
1141
|
-
|
|
1142
|
-
if (!
|
|
1152
|
+
let path7 = Path3.relative(Path3.dirname(from), to);
|
|
1153
|
+
let extension = Path3.extname(path7);
|
|
1154
|
+
path7 = Path3.join(Path3.dirname(path7), Pathe.filename(path7));
|
|
1155
|
+
if (!path7.startsWith("../")) path7 = "./" + path7;
|
|
1143
1156
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1144
1157
|
extension = ".js";
|
|
1145
1158
|
}
|
|
1146
|
-
return
|
|
1159
|
+
return path7 + extension;
|
|
1147
1160
|
}
|
|
1148
1161
|
function rootDirsPath(ctx, typesPath) {
|
|
1149
1162
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1150
1163
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1151
1164
|
}
|
|
1152
|
-
function paramsType(
|
|
1153
|
-
const params = parse2(
|
|
1165
|
+
function paramsType(path7) {
|
|
1166
|
+
const params = parse2(path7);
|
|
1154
1167
|
return t2.tsTypeLiteral(
|
|
1155
1168
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1156
1169
|
const property = t2.tsPropertySignature(
|
|
@@ -1486,11 +1499,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1486
1499
|
let cssContent = void 0;
|
|
1487
1500
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1488
1501
|
traverse(ast, {
|
|
1489
|
-
VariableDeclaration(
|
|
1490
|
-
const declaration =
|
|
1502
|
+
VariableDeclaration(path7) {
|
|
1503
|
+
const declaration = path7.node.declarations[0];
|
|
1491
1504
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1492
1505
|
cssContent = declaration.init.value;
|
|
1493
|
-
|
|
1506
|
+
path7.stop();
|
|
1494
1507
|
}
|
|
1495
1508
|
}
|
|
1496
1509
|
});
|
|
@@ -1507,6 +1520,15 @@ function create(name) {
|
|
|
1507
1520
|
};
|
|
1508
1521
|
}
|
|
1509
1522
|
|
|
1523
|
+
// vite/resolve-relative-route-file-path.ts
|
|
1524
|
+
var import_pathe4 = __toESM(require("pathe"));
|
|
1525
|
+
function resolveRelativeRouteFilePath(route, reactRouterConfig) {
|
|
1526
|
+
let vite2 = getVite();
|
|
1527
|
+
let file = route.file;
|
|
1528
|
+
let fullPath = import_pathe4.default.resolve(reactRouterConfig.appDirectory, file);
|
|
1529
|
+
return vite2.normalizePath(fullPath);
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1510
1532
|
// vite/combine-urls.ts
|
|
1511
1533
|
function combineURLs(baseURL, relativeURL) {
|
|
1512
1534
|
return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
@@ -1520,10 +1542,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1520
1542
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1521
1543
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1522
1544
|
traverse(ast, {
|
|
1523
|
-
ExportDeclaration(
|
|
1524
|
-
if (
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1545
|
+
ExportDeclaration(path7) {
|
|
1546
|
+
if (path7.node.type === "ExportNamedDeclaration") {
|
|
1547
|
+
if (path7.node.specifiers.length) {
|
|
1548
|
+
path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
|
|
1527
1549
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1528
1550
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1529
1551
|
exportsFiltered = true;
|
|
@@ -1535,12 +1557,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1535
1557
|
}
|
|
1536
1558
|
return true;
|
|
1537
1559
|
});
|
|
1538
|
-
if (
|
|
1539
|
-
markedForRemoval.add(
|
|
1560
|
+
if (path7.node.specifiers.length === 0) {
|
|
1561
|
+
markedForRemoval.add(path7);
|
|
1540
1562
|
}
|
|
1541
1563
|
}
|
|
1542
|
-
if (
|
|
1543
|
-
let declaration =
|
|
1564
|
+
if (path7.node.declaration?.type === "VariableDeclaration") {
|
|
1565
|
+
let declaration = path7.node.declaration;
|
|
1544
1566
|
declaration.declarations = declaration.declarations.filter(
|
|
1545
1567
|
(declaration2) => {
|
|
1546
1568
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1554,30 +1576,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1554
1576
|
}
|
|
1555
1577
|
);
|
|
1556
1578
|
if (declaration.declarations.length === 0) {
|
|
1557
|
-
markedForRemoval.add(
|
|
1579
|
+
markedForRemoval.add(path7);
|
|
1558
1580
|
}
|
|
1559
1581
|
}
|
|
1560
|
-
if (
|
|
1561
|
-
let id =
|
|
1582
|
+
if (path7.node.declaration?.type === "FunctionDeclaration") {
|
|
1583
|
+
let id = path7.node.declaration.id;
|
|
1562
1584
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1563
|
-
markedForRemoval.add(
|
|
1585
|
+
markedForRemoval.add(path7);
|
|
1564
1586
|
}
|
|
1565
1587
|
}
|
|
1566
|
-
if (
|
|
1567
|
-
let id =
|
|
1588
|
+
if (path7.node.declaration?.type === "ClassDeclaration") {
|
|
1589
|
+
let id = path7.node.declaration.id;
|
|
1568
1590
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1569
|
-
markedForRemoval.add(
|
|
1591
|
+
markedForRemoval.add(path7);
|
|
1570
1592
|
}
|
|
1571
1593
|
}
|
|
1572
1594
|
}
|
|
1573
|
-
if (
|
|
1595
|
+
if (path7.node.type === "ExportDefaultDeclaration") {
|
|
1574
1596
|
if (exportsToRemove.includes("default")) {
|
|
1575
|
-
markedForRemoval.add(
|
|
1576
|
-
if (
|
|
1577
|
-
if (
|
|
1578
|
-
removedExportLocalNames.add(
|
|
1579
|
-
} else if ((
|
|
1580
|
-
removedExportLocalNames.add(
|
|
1597
|
+
markedForRemoval.add(path7);
|
|
1598
|
+
if (path7.node.declaration) {
|
|
1599
|
+
if (path7.node.declaration.type === "Identifier") {
|
|
1600
|
+
removedExportLocalNames.add(path7.node.declaration.name);
|
|
1601
|
+
} else if ((path7.node.declaration.type === "FunctionDeclaration" || path7.node.declaration.type === "ClassDeclaration") && path7.node.declaration.id) {
|
|
1602
|
+
removedExportLocalNames.add(path7.node.declaration.id.name);
|
|
1581
1603
|
}
|
|
1582
1604
|
}
|
|
1583
1605
|
}
|
|
@@ -1585,21 +1607,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1585
1607
|
}
|
|
1586
1608
|
});
|
|
1587
1609
|
traverse(ast, {
|
|
1588
|
-
ExpressionStatement(
|
|
1589
|
-
if (!
|
|
1610
|
+
ExpressionStatement(path7) {
|
|
1611
|
+
if (!path7.parentPath.isProgram()) {
|
|
1590
1612
|
return;
|
|
1591
1613
|
}
|
|
1592
|
-
if (
|
|
1593
|
-
const left =
|
|
1614
|
+
if (path7.node.expression.type === "AssignmentExpression") {
|
|
1615
|
+
const left = path7.node.expression.left;
|
|
1594
1616
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1595
|
-
markedForRemoval.add(
|
|
1617
|
+
markedForRemoval.add(path7);
|
|
1596
1618
|
}
|
|
1597
1619
|
}
|
|
1598
1620
|
}
|
|
1599
1621
|
});
|
|
1600
1622
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1601
|
-
for (let
|
|
1602
|
-
|
|
1623
|
+
for (let path7 of markedForRemoval) {
|
|
1624
|
+
path7.remove();
|
|
1603
1625
|
}
|
|
1604
1626
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1605
1627
|
}
|
|
@@ -1644,6 +1666,18 @@ function invalidDestructureError(name) {
|
|
|
1644
1666
|
return new Error(`Cannot remove destructured export "${name}"`);
|
|
1645
1667
|
}
|
|
1646
1668
|
|
|
1669
|
+
// vite/has-dependency.ts
|
|
1670
|
+
function hasDependency({
|
|
1671
|
+
name,
|
|
1672
|
+
rootDirectory
|
|
1673
|
+
}) {
|
|
1674
|
+
try {
|
|
1675
|
+
return Boolean(require.resolve(name, { paths: [rootDirectory] }));
|
|
1676
|
+
} catch (err2) {
|
|
1677
|
+
return false;
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1647
1681
|
// vite/cache.ts
|
|
1648
1682
|
function getOrSetFromCache(cache, key, version, getValue) {
|
|
1649
1683
|
if (!cache) {
|
|
@@ -1670,28 +1704,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1670
1704
|
)
|
|
1671
1705
|
);
|
|
1672
1706
|
}
|
|
1673
|
-
function assertNodePath(
|
|
1707
|
+
function assertNodePath(path7) {
|
|
1674
1708
|
invariant(
|
|
1675
|
-
|
|
1676
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1709
|
+
path7 && !Array.isArray(path7),
|
|
1710
|
+
`Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
|
|
1677
1711
|
);
|
|
1678
1712
|
}
|
|
1679
|
-
function assertNodePathIsStatement(
|
|
1713
|
+
function assertNodePathIsStatement(path7) {
|
|
1680
1714
|
invariant(
|
|
1681
|
-
|
|
1682
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1715
|
+
path7 && !Array.isArray(path7) && t.isStatement(path7.node),
|
|
1716
|
+
`Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1683
1717
|
);
|
|
1684
1718
|
}
|
|
1685
|
-
function assertNodePathIsVariableDeclarator(
|
|
1719
|
+
function assertNodePathIsVariableDeclarator(path7) {
|
|
1686
1720
|
invariant(
|
|
1687
|
-
|
|
1688
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1721
|
+
path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
|
|
1722
|
+
`Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1689
1723
|
);
|
|
1690
1724
|
}
|
|
1691
|
-
function assertNodePathIsPattern(
|
|
1725
|
+
function assertNodePathIsPattern(path7) {
|
|
1692
1726
|
invariant(
|
|
1693
|
-
|
|
1694
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1727
|
+
path7 && !Array.isArray(path7) && t.isPattern(path7.node),
|
|
1728
|
+
`Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1695
1729
|
);
|
|
1696
1730
|
}
|
|
1697
1731
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1727,8 +1761,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1727
1761
|
}
|
|
1728
1762
|
let isWithinExportDestructuring = Boolean(
|
|
1729
1763
|
identifier.findParent(
|
|
1730
|
-
(
|
|
1731
|
-
|
|
1764
|
+
(path7) => Boolean(
|
|
1765
|
+
path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1732
1766
|
)
|
|
1733
1767
|
)
|
|
1734
1768
|
);
|
|
@@ -1806,7 +1840,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1806
1840
|
for (let specifier of node.specifiers) {
|
|
1807
1841
|
if (t.isIdentifier(specifier.exported)) {
|
|
1808
1842
|
let name = specifier.exported.name;
|
|
1809
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1843
|
+
let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
|
|
1810
1844
|
invariant(
|
|
1811
1845
|
specifierPath,
|
|
1812
1846
|
`Expected to find specifier path for ${name}`
|
|
@@ -1823,22 +1857,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1823
1857
|
}
|
|
1824
1858
|
);
|
|
1825
1859
|
}
|
|
1826
|
-
function getDependentIdentifiersForPath(
|
|
1860
|
+
function getDependentIdentifiersForPath(path7, state) {
|
|
1827
1861
|
let { visited, identifiers } = state ?? {
|
|
1828
1862
|
visited: /* @__PURE__ */ new Set(),
|
|
1829
1863
|
identifiers: /* @__PURE__ */ new Set()
|
|
1830
1864
|
};
|
|
1831
|
-
if (visited.has(
|
|
1865
|
+
if (visited.has(path7)) {
|
|
1832
1866
|
return identifiers;
|
|
1833
1867
|
}
|
|
1834
|
-
visited.add(
|
|
1835
|
-
|
|
1836
|
-
Identifier(
|
|
1837
|
-
if (identifiers.has(
|
|
1868
|
+
visited.add(path7);
|
|
1869
|
+
path7.traverse({
|
|
1870
|
+
Identifier(path8) {
|
|
1871
|
+
if (identifiers.has(path8)) {
|
|
1838
1872
|
return;
|
|
1839
1873
|
}
|
|
1840
|
-
identifiers.add(
|
|
1841
|
-
let binding =
|
|
1874
|
+
identifiers.add(path8);
|
|
1875
|
+
let binding = path8.scope.getBinding(path8.node.name);
|
|
1842
1876
|
if (!binding) {
|
|
1843
1877
|
return;
|
|
1844
1878
|
}
|
|
@@ -1860,7 +1894,7 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1860
1894
|
}
|
|
1861
1895
|
}
|
|
1862
1896
|
});
|
|
1863
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1897
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1864
1898
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1865
1899
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1866
1900
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1869,9 +1903,9 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1869
1903
|
identifiers
|
|
1870
1904
|
});
|
|
1871
1905
|
}
|
|
1872
|
-
if (withinExportStatement &&
|
|
1873
|
-
t.isPattern(
|
|
1874
|
-
let variableDeclarator =
|
|
1906
|
+
if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
|
|
1907
|
+
t.isPattern(path7.parentPath.parentPath?.node))) {
|
|
1908
|
+
let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
|
|
1875
1909
|
assertNodePath(variableDeclarator);
|
|
1876
1910
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1877
1911
|
visited,
|
|
@@ -1880,16 +1914,16 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1880
1914
|
}
|
|
1881
1915
|
return identifiers;
|
|
1882
1916
|
}
|
|
1883
|
-
function getTopLevelStatementPathForPath(
|
|
1884
|
-
let ancestry =
|
|
1917
|
+
function getTopLevelStatementPathForPath(path7) {
|
|
1918
|
+
let ancestry = path7.getAncestry();
|
|
1885
1919
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1886
1920
|
assertNodePathIsStatement(topLevelStatement);
|
|
1887
1921
|
return topLevelStatement;
|
|
1888
1922
|
}
|
|
1889
1923
|
function getTopLevelStatementsForPaths(paths) {
|
|
1890
1924
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1891
|
-
for (let
|
|
1892
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1925
|
+
for (let path7 of paths) {
|
|
1926
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1893
1927
|
topLevelStatements.add(topLevelStatement.node);
|
|
1894
1928
|
}
|
|
1895
1929
|
return topLevelStatements;
|
|
@@ -2210,7 +2244,7 @@ function detectRouteChunks(code, cache, cacheKey) {
|
|
|
2210
2244
|
var routeChunkExportNames = [
|
|
2211
2245
|
"clientAction",
|
|
2212
2246
|
"clientLoader",
|
|
2213
|
-
"
|
|
2247
|
+
"clientMiddleware",
|
|
2214
2248
|
"HydrateFallback"
|
|
2215
2249
|
];
|
|
2216
2250
|
var mainChunkName = "main";
|
|
@@ -2226,7 +2260,7 @@ var routeChunkQueryStrings = {
|
|
|
2226
2260
|
main: `${routeChunkQueryStringPrefix}main`,
|
|
2227
2261
|
clientAction: `${routeChunkQueryStringPrefix}clientAction`,
|
|
2228
2262
|
clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
|
|
2229
|
-
|
|
2263
|
+
clientMiddleware: `${routeChunkQueryStringPrefix}clientMiddleware`,
|
|
2230
2264
|
HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
|
|
2231
2265
|
};
|
|
2232
2266
|
function getRouteChunkModuleId(filePath, chunkName) {
|
|
@@ -2251,6 +2285,31 @@ function getRouteChunkNameFromModuleId(id) {
|
|
|
2251
2285
|
return chunkName;
|
|
2252
2286
|
}
|
|
2253
2287
|
|
|
2288
|
+
// vite/optimize-deps-entries.ts
|
|
2289
|
+
var import_tinyglobby = require("tinyglobby");
|
|
2290
|
+
function getOptimizeDepsEntries({
|
|
2291
|
+
entryClientFilePath,
|
|
2292
|
+
reactRouterConfig
|
|
2293
|
+
}) {
|
|
2294
|
+
if (!reactRouterConfig.future.unstable_optimizeDeps) {
|
|
2295
|
+
return [];
|
|
2296
|
+
}
|
|
2297
|
+
const vite2 = getVite();
|
|
2298
|
+
const viteMajorVersion = parseInt(vite2.version.split(".")[0], 10);
|
|
2299
|
+
return [
|
|
2300
|
+
vite2.normalizePath(entryClientFilePath),
|
|
2301
|
+
...Object.values(reactRouterConfig.routes).map(
|
|
2302
|
+
(route) => resolveRelativeRouteFilePath(route, reactRouterConfig)
|
|
2303
|
+
)
|
|
2304
|
+
].map(
|
|
2305
|
+
(entry) => (
|
|
2306
|
+
// In Vite 7, the `optimizeDeps.entries` option only accepts glob patterns.
|
|
2307
|
+
// In prior versions, absolute file paths were treated differently.
|
|
2308
|
+
viteMajorVersion >= 7 ? (0, import_tinyglobby.escapePath)(entry) : entry
|
|
2309
|
+
)
|
|
2310
|
+
);
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2254
2313
|
// vite/with-props.ts
|
|
2255
2314
|
var namedComponentExports = ["HydrateFallback", "ErrorBoundary"];
|
|
2256
2315
|
function isNamedComponentExport(name) {
|
|
@@ -2258,24 +2317,24 @@ function isNamedComponentExport(name) {
|
|
|
2258
2317
|
}
|
|
2259
2318
|
var decorateComponentExportsWithProps = (ast) => {
|
|
2260
2319
|
const hocs = [];
|
|
2261
|
-
function getHocUid(
|
|
2262
|
-
const uid =
|
|
2320
|
+
function getHocUid(path7, hocName) {
|
|
2321
|
+
const uid = path7.scope.generateUidIdentifier(hocName);
|
|
2263
2322
|
hocs.push([hocName, uid]);
|
|
2264
2323
|
return uid;
|
|
2265
2324
|
}
|
|
2266
2325
|
traverse(ast, {
|
|
2267
|
-
ExportDeclaration(
|
|
2268
|
-
if (
|
|
2269
|
-
const declaration =
|
|
2326
|
+
ExportDeclaration(path7) {
|
|
2327
|
+
if (path7.isExportDefaultDeclaration()) {
|
|
2328
|
+
const declaration = path7.get("declaration");
|
|
2270
2329
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2271
2330
|
if (expr) {
|
|
2272
|
-
const uid = getHocUid(
|
|
2331
|
+
const uid = getHocUid(path7, "UNSAFE_withComponentProps");
|
|
2273
2332
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2274
2333
|
}
|
|
2275
2334
|
return;
|
|
2276
2335
|
}
|
|
2277
|
-
if (
|
|
2278
|
-
const decl =
|
|
2336
|
+
if (path7.isExportNamedDeclaration()) {
|
|
2337
|
+
const decl = path7.get("declaration");
|
|
2279
2338
|
if (decl.isVariableDeclaration()) {
|
|
2280
2339
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2281
2340
|
const id = varDeclarator.get("id");
|
|
@@ -2285,7 +2344,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2285
2344
|
if (!id.isIdentifier()) return;
|
|
2286
2345
|
const { name } = id.node;
|
|
2287
2346
|
if (!isNamedComponentExport(name)) return;
|
|
2288
|
-
const uid = getHocUid(
|
|
2347
|
+
const uid = getHocUid(path7, `UNSAFE_with${name}Props`);
|
|
2289
2348
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2290
2349
|
});
|
|
2291
2350
|
return;
|
|
@@ -2295,7 +2354,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2295
2354
|
if (!id) return;
|
|
2296
2355
|
const { name } = id;
|
|
2297
2356
|
if (!isNamedComponentExport(name)) return;
|
|
2298
|
-
const uid = getHocUid(
|
|
2357
|
+
const uid = getHocUid(path7, `UNSAFE_with${name}Props`);
|
|
2299
2358
|
decl.replaceWith(
|
|
2300
2359
|
t.variableDeclaration("const", [
|
|
2301
2360
|
t.variableDeclarator(
|
|
@@ -2340,16 +2399,57 @@ function validatePluginOrder() {
|
|
|
2340
2399
|
(plugin) => pluginName.includes(plugin.name)
|
|
2341
2400
|
);
|
|
2342
2401
|
};
|
|
2343
|
-
let
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2402
|
+
let reactRouterRscPluginIndex = pluginIndex("react-router/rsc");
|
|
2403
|
+
let viteRscPluginIndex = pluginIndex("rsc");
|
|
2404
|
+
if (reactRouterRscPluginIndex >= 0 && viteRscPluginIndex >= 0 && reactRouterRscPluginIndex > viteRscPluginIndex) {
|
|
2405
|
+
throw new Error(
|
|
2406
|
+
`The "@vitejs/plugin-rsc" plugin should be placed after the React Router RSC plugin in your Vite config`
|
|
2407
|
+
);
|
|
2408
|
+
}
|
|
2409
|
+
let reactRouterPluginIndex = pluginIndex([
|
|
2410
|
+
"react-router",
|
|
2411
|
+
"react-router/rsc"
|
|
2412
|
+
]);
|
|
2413
|
+
let mdxPluginIndex = pluginIndex("@mdx-js/rollup");
|
|
2414
|
+
if (mdxPluginIndex >= 0 && mdxPluginIndex > reactRouterPluginIndex) {
|
|
2415
|
+
throw new Error(
|
|
2416
|
+
`The "@mdx-js/rollup" plugin should be placed before the React Router plugin in your Vite config`
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
// vite/plugins/warn-on-client-source-maps.ts
|
|
2424
|
+
var import_picocolors3 = __toESM(require("picocolors"));
|
|
2425
|
+
function warnOnClientSourceMaps() {
|
|
2426
|
+
let viteConfig;
|
|
2427
|
+
let viteCommand;
|
|
2428
|
+
let logged = false;
|
|
2429
|
+
return {
|
|
2430
|
+
name: "react-router:warn-on-client-source-maps",
|
|
2431
|
+
config(_, configEnv) {
|
|
2432
|
+
viteCommand = configEnv.command;
|
|
2433
|
+
},
|
|
2434
|
+
configResolved(config) {
|
|
2435
|
+
viteConfig = config;
|
|
2436
|
+
},
|
|
2437
|
+
buildStart() {
|
|
2438
|
+
invariant(viteConfig);
|
|
2439
|
+
if (!logged && viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && (viteConfig.build.sourcemap || viteConfig.environments?.client?.build.sourcemap)) {
|
|
2440
|
+
viteConfig.logger.warn(
|
|
2441
|
+
import_picocolors3.default.yellow(
|
|
2442
|
+
"\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
|
|
2443
|
+
"This makes your server code publicly",
|
|
2444
|
+
"visible in the browser. This is highly",
|
|
2445
|
+
"discouraged! If you insist, ensure that",
|
|
2446
|
+
"you are using environment variables for",
|
|
2447
|
+
"secrets and not hard-coding them in",
|
|
2448
|
+
"your source code."
|
|
2449
|
+
].map((line) => " " + line).join("\n") + "\n"
|
|
2450
|
+
)
|
|
2451
|
+
);
|
|
2452
|
+
logged = true;
|
|
2353
2453
|
}
|
|
2354
2454
|
}
|
|
2355
2455
|
};
|
|
@@ -2359,16 +2459,11 @@ function validatePluginOrder() {
|
|
|
2359
2459
|
function extractPluginContext(viteConfig) {
|
|
2360
2460
|
return viteConfig["__reactRouterPluginContext"];
|
|
2361
2461
|
}
|
|
2362
|
-
var SERVER_ONLY_ROUTE_EXPORTS = [
|
|
2363
|
-
"loader",
|
|
2364
|
-
"action",
|
|
2365
|
-
"unstable_middleware",
|
|
2366
|
-
"headers"
|
|
2367
|
-
];
|
|
2462
|
+
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "middleware", "headers"];
|
|
2368
2463
|
var CLIENT_NON_COMPONENT_EXPORTS = [
|
|
2369
2464
|
"clientAction",
|
|
2370
2465
|
"clientLoader",
|
|
2371
|
-
"
|
|
2466
|
+
"clientMiddleware",
|
|
2372
2467
|
"handle",
|
|
2373
2468
|
"meta",
|
|
2374
2469
|
"links",
|
|
@@ -2421,16 +2516,10 @@ var virtualHmrRuntime = create("hmr-runtime");
|
|
|
2421
2516
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
2422
2517
|
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
2423
2518
|
let vite2 = getVite();
|
|
2424
|
-
let fullPath =
|
|
2425
|
-
let relativePath =
|
|
2519
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
2520
|
+
let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
|
|
2426
2521
|
return vite2.normalizePath(relativePath).split("?")[0];
|
|
2427
2522
|
};
|
|
2428
|
-
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
2429
|
-
let vite2 = getVite();
|
|
2430
|
-
let file = route.file;
|
|
2431
|
-
let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
|
|
2432
|
-
return vite2.normalizePath(fullPath);
|
|
2433
|
-
};
|
|
2434
2523
|
var virtual = {
|
|
2435
2524
|
serverBuild: create("server-build"),
|
|
2436
2525
|
serverManifest: create("server-manifest"),
|
|
@@ -2451,7 +2540,7 @@ var getHash = (source, maxLength) => {
|
|
|
2451
2540
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
2452
2541
|
let vite2 = getVite();
|
|
2453
2542
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
2454
|
-
|
|
2543
|
+
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
2455
2544
|
);
|
|
2456
2545
|
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
2457
2546
|
if (!entryChunk) {
|
|
@@ -2540,7 +2629,7 @@ function dedupe(array2) {
|
|
|
2540
2629
|
return [...new Set(array2)];
|
|
2541
2630
|
}
|
|
2542
2631
|
var writeFileSafe = async (file, contents) => {
|
|
2543
|
-
await (0, import_promises2.mkdir)(
|
|
2632
|
+
await (0, import_promises2.mkdir)(path6.dirname(file), { recursive: true });
|
|
2544
2633
|
await (0, import_promises2.writeFile)(file, contents);
|
|
2545
2634
|
};
|
|
2546
2635
|
var getExportNames = (code) => {
|
|
@@ -2566,7 +2655,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2566
2655
|
}
|
|
2567
2656
|
let ssr = true;
|
|
2568
2657
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
2569
|
-
let routePath =
|
|
2658
|
+
let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2570
2659
|
let url2 = resolveFileUrl(ctx, routePath);
|
|
2571
2660
|
let resolveId = async () => {
|
|
2572
2661
|
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
@@ -2608,12 +2697,12 @@ var resolveEnvironmentBuildContext = ({
|
|
|
2608
2697
|
};
|
|
2609
2698
|
return resolvedBuildContext;
|
|
2610
2699
|
};
|
|
2611
|
-
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) =>
|
|
2700
|
+
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
|
|
2612
2701
|
reactRouterConfig.buildDirectory,
|
|
2613
2702
|
"server",
|
|
2614
2703
|
...serverBundleId ? [serverBundleId] : []
|
|
2615
2704
|
);
|
|
2616
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
2705
|
+
var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
|
|
2617
2706
|
var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
2618
2707
|
if (!ctx.buildManifest) {
|
|
2619
2708
|
return void 0;
|
|
@@ -2631,14 +2720,14 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
|
2631
2720
|
);
|
|
2632
2721
|
return Object.keys(serverBundleRoutes);
|
|
2633
2722
|
};
|
|
2634
|
-
var defaultEntriesDir =
|
|
2635
|
-
|
|
2723
|
+
var defaultEntriesDir = path6.resolve(
|
|
2724
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
2636
2725
|
"dist",
|
|
2637
2726
|
"config",
|
|
2638
2727
|
"defaults"
|
|
2639
2728
|
);
|
|
2640
2729
|
var defaultEntries = (0, import_node_fs2.readdirSync)(defaultEntriesDir).map(
|
|
2641
|
-
(filename2) =>
|
|
2730
|
+
(filename2) => path6.join(defaultEntriesDir, filename2)
|
|
2642
2731
|
);
|
|
2643
2732
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2644
2733
|
var reactRouterDevLoadContext = () => void 0;
|
|
@@ -2676,7 +2765,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2676
2765
|
let publicPath = viteUserConfig.base ?? "/";
|
|
2677
2766
|
if (reactRouterConfig.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !reactRouterConfig.basename.startsWith(publicPath)) {
|
|
2678
2767
|
logger.error(
|
|
2679
|
-
|
|
2768
|
+
import_picocolors4.default.red(
|
|
2680
2769
|
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
2681
2770
|
)
|
|
2682
2771
|
);
|
|
@@ -2734,7 +2823,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2734
2823
|
virtual.serverManifest.id
|
|
2735
2824
|
)};
|
|
2736
2825
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2737
|
-
|
|
2826
|
+
path6.relative(
|
|
2738
2827
|
ctx.rootDirectory,
|
|
2739
2828
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
2740
2829
|
)
|
|
@@ -2773,18 +2862,11 @@ var reactRouterVitePlugin = () => {
|
|
|
2773
2862
|
};
|
|
2774
2863
|
let loadViteManifest = async (directory) => {
|
|
2775
2864
|
let manifestContents = await (0, import_promises2.readFile)(
|
|
2776
|
-
|
|
2865
|
+
path6.resolve(directory, ".vite", "manifest.json"),
|
|
2777
2866
|
"utf-8"
|
|
2778
2867
|
);
|
|
2779
2868
|
return JSON.parse(manifestContents);
|
|
2780
2869
|
};
|
|
2781
|
-
let hasDependency = (name) => {
|
|
2782
|
-
try {
|
|
2783
|
-
return Boolean(require.resolve(name, { paths: [ctx.rootDirectory] }));
|
|
2784
|
-
} catch (err2) {
|
|
2785
|
-
return false;
|
|
2786
|
-
}
|
|
2787
|
-
};
|
|
2788
2870
|
let getViteManifestAssetPaths = (viteManifest) => {
|
|
2789
2871
|
let cssUrlPaths = Object.values(viteManifest).filter((chunk) => chunk.file.endsWith(".css")).map((chunk) => chunk.file);
|
|
2790
2872
|
let chunkAssetPaths = Object.values(viteManifest).flatMap(
|
|
@@ -2805,7 +2887,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2805
2887
|
let contents;
|
|
2806
2888
|
try {
|
|
2807
2889
|
contents = await (0, import_promises2.readFile)(
|
|
2808
|
-
|
|
2890
|
+
path6.join(entryNormalizedPath, entry.name),
|
|
2809
2891
|
"utf-8"
|
|
2810
2892
|
);
|
|
2811
2893
|
} catch (e) {
|
|
@@ -2814,9 +2896,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2814
2896
|
}
|
|
2815
2897
|
let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
|
|
2816
2898
|
let filepath = getVite().normalizePath(
|
|
2817
|
-
|
|
2899
|
+
path6.relative(
|
|
2818
2900
|
clientBuildDirectory,
|
|
2819
|
-
|
|
2901
|
+
path6.join(entryNormalizedPath, entry.name)
|
|
2820
2902
|
)
|
|
2821
2903
|
);
|
|
2822
2904
|
sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
|
|
@@ -2847,13 +2929,11 @@ var reactRouterVitePlugin = () => {
|
|
|
2847
2929
|
);
|
|
2848
2930
|
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2849
2931
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2850
|
-
let routeFile =
|
|
2932
|
+
let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2851
2933
|
let sourceExports = routeManifestExports[route.id];
|
|
2852
2934
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
2853
2935
|
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
2854
|
-
let hasClientMiddleware = sourceExports.includes(
|
|
2855
|
-
"unstable_clientMiddleware"
|
|
2856
|
-
);
|
|
2936
|
+
let hasClientMiddleware = sourceExports.includes("clientMiddleware");
|
|
2857
2937
|
let hasHydrateFallback = sourceExports.includes("HydrateFallback");
|
|
2858
2938
|
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
2859
2939
|
cache,
|
|
@@ -2868,7 +2948,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2868
2948
|
valid: {
|
|
2869
2949
|
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
2870
2950
|
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
2871
|
-
|
|
2951
|
+
clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
|
|
2872
2952
|
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
2873
2953
|
}
|
|
2874
2954
|
});
|
|
@@ -2902,10 +2982,10 @@ var reactRouterVitePlugin = () => {
|
|
|
2902
2982
|
viteManifest,
|
|
2903
2983
|
getRouteChunkModuleId(routeFile, "clientLoader")
|
|
2904
2984
|
) : void 0,
|
|
2905
|
-
clientMiddlewareModule: hasRouteChunkByExportName.
|
|
2985
|
+
clientMiddlewareModule: hasRouteChunkByExportName.clientMiddleware ? getPublicModulePathForEntry(
|
|
2906
2986
|
ctx,
|
|
2907
2987
|
viteManifest,
|
|
2908
|
-
getRouteChunkModuleId(routeFile, "
|
|
2988
|
+
getRouteChunkModuleId(routeFile, "clientMiddleware")
|
|
2909
2989
|
) : void 0,
|
|
2910
2990
|
hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? getPublicModulePathForEntry(
|
|
2911
2991
|
ctx,
|
|
@@ -2920,7 +3000,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2920
3000
|
}
|
|
2921
3001
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
2922
3002
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
2923
|
-
let manifestPath =
|
|
3003
|
+
let manifestPath = path6.posix.join(
|
|
2924
3004
|
viteConfig2.build.assetsDir,
|
|
2925
3005
|
`manifest-${version}.js`
|
|
2926
3006
|
);
|
|
@@ -2932,7 +3012,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2932
3012
|
sri: void 0
|
|
2933
3013
|
};
|
|
2934
3014
|
await writeFileSafe(
|
|
2935
|
-
|
|
3015
|
+
path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
2936
3016
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
2937
3017
|
reactRouterBrowserManifest
|
|
2938
3018
|
)};`
|
|
@@ -2964,9 +3044,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2964
3044
|
let sourceExports = routeManifestExports[key];
|
|
2965
3045
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
2966
3046
|
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
2967
|
-
let hasClientMiddleware = sourceExports.includes(
|
|
2968
|
-
"unstable_clientMiddleware"
|
|
2969
|
-
);
|
|
3047
|
+
let hasClientMiddleware = sourceExports.includes("clientMiddleware");
|
|
2970
3048
|
let hasHydrateFallback = sourceExports.includes("HydrateFallback");
|
|
2971
3049
|
let routeModulePath = combineURLs(
|
|
2972
3050
|
ctx.publicPath,
|
|
@@ -2988,7 +3066,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2988
3066
|
valid: {
|
|
2989
3067
|
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
2990
3068
|
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
2991
|
-
|
|
3069
|
+
clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
|
|
2992
3070
|
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
2993
3071
|
}
|
|
2994
3072
|
});
|
|
@@ -3060,7 +3138,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3060
3138
|
config: async (_viteUserConfig, _viteConfigEnv) => {
|
|
3061
3139
|
await preloadVite();
|
|
3062
3140
|
let vite2 = getVite();
|
|
3063
|
-
let viteMajorVersion = parseInt(vite2.version.split(".")[0], 10);
|
|
3064
3141
|
viteUserConfig = _viteUserConfig;
|
|
3065
3142
|
viteConfigEnv = _viteConfigEnv;
|
|
3066
3143
|
viteCommand = viteConfigEnv.command;
|
|
@@ -3114,18 +3191,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3114
3191
|
resolve: serverEnvironment.resolve
|
|
3115
3192
|
},
|
|
3116
3193
|
optimizeDeps: {
|
|
3117
|
-
entries:
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
)
|
|
3122
|
-
].map(
|
|
3123
|
-
(entry) => (
|
|
3124
|
-
// In Vite 7, the `optimizeDeps.entries` option only accepts glob patterns.
|
|
3125
|
-
// In prior versions, absolute file paths were treated differently.
|
|
3126
|
-
viteMajorVersion >= 7 ? (0, import_tinyglobby.escapePath)(entry) : entry
|
|
3127
|
-
)
|
|
3128
|
-
) : [],
|
|
3194
|
+
entries: getOptimizeDepsEntries({
|
|
3195
|
+
entryClientFilePath: ctx.entryClientFilePath,
|
|
3196
|
+
reactRouterConfig: ctx.reactRouterConfig
|
|
3197
|
+
}),
|
|
3129
3198
|
include: [
|
|
3130
3199
|
// Pre-bundle React dependencies to avoid React duplicates,
|
|
3131
3200
|
// even if React dependencies are not direct dependencies.
|
|
@@ -3140,7 +3209,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3140
3209
|
"react-router",
|
|
3141
3210
|
"react-router/dom",
|
|
3142
3211
|
// Check to avoid "Failed to resolve dependency: react-router-dom, present in 'optimizeDeps.include'"
|
|
3143
|
-
...hasDependency(
|
|
3212
|
+
...hasDependency({
|
|
3213
|
+
name: "react-router-dom",
|
|
3214
|
+
rootDirectory: ctx.rootDirectory
|
|
3215
|
+
}) ? ["react-router-dom"] : []
|
|
3144
3216
|
]
|
|
3145
3217
|
},
|
|
3146
3218
|
esbuild: {
|
|
@@ -3292,23 +3364,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3292
3364
|
cssModulesManifest[id] = code;
|
|
3293
3365
|
}
|
|
3294
3366
|
},
|
|
3295
|
-
buildStart() {
|
|
3296
|
-
invariant(viteConfig);
|
|
3297
|
-
if (viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && viteConfig.build.sourcemap) {
|
|
3298
|
-
viteConfig.logger.warn(
|
|
3299
|
-
import_picocolors3.default.yellow(
|
|
3300
|
-
"\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
|
|
3301
|
-
"This makes your server code publicly",
|
|
3302
|
-
"visible in the browser. This is highly",
|
|
3303
|
-
"discouraged! If you insist, ensure that",
|
|
3304
|
-
"you are using environment variables for",
|
|
3305
|
-
"secrets and not hard-coding them in",
|
|
3306
|
-
"your source code."
|
|
3307
|
-
].map((line) => " " + line).join("\n") + "\n"
|
|
3308
|
-
)
|
|
3309
|
-
);
|
|
3310
|
-
}
|
|
3311
|
-
},
|
|
3312
3367
|
async configureServer(viteDevServer) {
|
|
3313
3368
|
(0, import_react_router2.unstable_setDevServerHooks)({
|
|
3314
3369
|
// Give the request handler access to the critical CSS in dev to avoid a
|
|
@@ -3348,7 +3403,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3348
3403
|
return;
|
|
3349
3404
|
}
|
|
3350
3405
|
let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
|
|
3351
|
-
logger.info(
|
|
3406
|
+
logger.info(import_picocolors4.default.green(message), {
|
|
3352
3407
|
clear: true,
|
|
3353
3408
|
timestamp: true
|
|
3354
3409
|
});
|
|
@@ -3438,11 +3493,11 @@ var reactRouterVitePlugin = () => {
|
|
|
3438
3493
|
let removedAssetPaths = [];
|
|
3439
3494
|
let copiedAssetPaths = [];
|
|
3440
3495
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
3441
|
-
let src =
|
|
3442
|
-
let dest =
|
|
3496
|
+
let src = path6.join(serverBuildDirectory, ssrAssetPath);
|
|
3497
|
+
let dest = path6.join(clientBuildDirectory, ssrAssetPath);
|
|
3443
3498
|
if (!userSsrEmitAssets) {
|
|
3444
3499
|
if (!(0, import_node_fs2.existsSync)(dest)) {
|
|
3445
|
-
await (0, import_promises2.mkdir)(
|
|
3500
|
+
await (0, import_promises2.mkdir)(path6.dirname(dest), { recursive: true });
|
|
3446
3501
|
await (0, import_promises2.rename)(src, dest);
|
|
3447
3502
|
movedAssetPaths.push(dest);
|
|
3448
3503
|
} else {
|
|
@@ -3460,7 +3515,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3460
3515
|
);
|
|
3461
3516
|
await Promise.all(
|
|
3462
3517
|
ssrCssPaths.map(async (cssPath) => {
|
|
3463
|
-
let src =
|
|
3518
|
+
let src = path6.join(serverBuildDirectory, cssPath);
|
|
3464
3519
|
await (0, import_promises2.rm)(src, { force: true, recursive: true });
|
|
3465
3520
|
removedAssetPaths.push(src);
|
|
3466
3521
|
})
|
|
@@ -3468,7 +3523,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3468
3523
|
}
|
|
3469
3524
|
let cleanedAssetPaths = [...removedAssetPaths, ...movedAssetPaths];
|
|
3470
3525
|
let handledAssetPaths = [...cleanedAssetPaths, ...copiedAssetPaths];
|
|
3471
|
-
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(
|
|
3526
|
+
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(path6.dirname));
|
|
3472
3527
|
await Promise.all(
|
|
3473
3528
|
Array.from(cleanedAssetDirs).map(async (dir) => {
|
|
3474
3529
|
try {
|
|
@@ -3488,9 +3543,9 @@ var reactRouterVitePlugin = () => {
|
|
|
3488
3543
|
if (paths.length) {
|
|
3489
3544
|
viteConfig.logger.info(
|
|
3490
3545
|
[
|
|
3491
|
-
`${
|
|
3546
|
+
`${import_picocolors4.default.green("\u2713")} ${message}`,
|
|
3492
3547
|
...paths.map(
|
|
3493
|
-
(assetPath) =>
|
|
3548
|
+
(assetPath) => import_picocolors4.default.dim(path6.relative(ctx.rootDirectory, assetPath))
|
|
3494
3549
|
)
|
|
3495
3550
|
].join("\n")
|
|
3496
3551
|
);
|
|
@@ -3534,7 +3589,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3534
3589
|
viteConfig.logger.info(
|
|
3535
3590
|
[
|
|
3536
3591
|
"Removing the server build in",
|
|
3537
|
-
|
|
3592
|
+
import_picocolors4.default.green(serverBuildDirectory),
|
|
3538
3593
|
"due to ssr:false"
|
|
3539
3594
|
].join(" ")
|
|
3540
3595
|
);
|
|
@@ -3584,7 +3639,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3584
3639
|
);
|
|
3585
3640
|
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
3586
3641
|
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
3587
|
-
let chunkBasePath = `./${
|
|
3642
|
+
let chunkBasePath = `./${path6.basename(id)}`;
|
|
3588
3643
|
return [
|
|
3589
3644
|
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
3590
3645
|
chunkBasePath,
|
|
@@ -3604,7 +3659,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3604
3659
|
async transform(code, id, options) {
|
|
3605
3660
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
3606
3661
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
3607
|
-
let routeFileName =
|
|
3662
|
+
let routeFileName = path6.basename(routeModuleId);
|
|
3608
3663
|
let sourceExports = await getRouteModuleExports(
|
|
3609
3664
|
viteChildCompiler,
|
|
3610
3665
|
ctx,
|
|
@@ -3656,9 +3711,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3656
3711
|
valid: {
|
|
3657
3712
|
clientAction: !exportNames.includes("clientAction"),
|
|
3658
3713
|
clientLoader: !exportNames.includes("clientLoader"),
|
|
3659
|
-
|
|
3660
|
-
"unstable_clientMiddleware"
|
|
3661
|
-
),
|
|
3714
|
+
clientMiddleware: !exportNames.includes("clientMiddleware"),
|
|
3662
3715
|
HydrateFallback: !exportNames.includes("HydrateFallback")
|
|
3663
3716
|
}
|
|
3664
3717
|
});
|
|
@@ -3733,7 +3786,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3733
3786
|
}
|
|
3734
3787
|
let vite2 = getVite();
|
|
3735
3788
|
let importerShort = vite2.normalizePath(
|
|
3736
|
-
|
|
3789
|
+
path6.relative(ctx.rootDirectory, importer)
|
|
3737
3790
|
);
|
|
3738
3791
|
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
3739
3792
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
@@ -3741,7 +3794,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3741
3794
|
).join(", ");
|
|
3742
3795
|
throw Error(
|
|
3743
3796
|
[
|
|
3744
|
-
|
|
3797
|
+
import_picocolors4.default.red(`Server-only module referenced by client`),
|
|
3745
3798
|
"",
|
|
3746
3799
|
` '${id}' imported by route '${importerShort}'`,
|
|
3747
3800
|
"",
|
|
@@ -3757,7 +3810,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3757
3810
|
}
|
|
3758
3811
|
throw Error(
|
|
3759
3812
|
[
|
|
3760
|
-
|
|
3813
|
+
import_picocolors4.default.red(`Server-only module referenced by client`),
|
|
3761
3814
|
"",
|
|
3762
3815
|
` '${id}' imported by '${importerShort}'`,
|
|
3763
3816
|
"",
|
|
@@ -3855,10 +3908,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3855
3908
|
},
|
|
3856
3909
|
async load(id) {
|
|
3857
3910
|
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
3858
|
-
let reactRefreshDir =
|
|
3911
|
+
let reactRefreshDir = path6.dirname(
|
|
3859
3912
|
require.resolve("react-refresh/package.json")
|
|
3860
3913
|
);
|
|
3861
|
-
let reactRefreshRuntimePath =
|
|
3914
|
+
let reactRefreshRuntimePath = path6.join(
|
|
3862
3915
|
reactRefreshDir,
|
|
3863
3916
|
"cjs/react-refresh-runtime.development.js"
|
|
3864
3917
|
);
|
|
@@ -3967,7 +4020,8 @@ var reactRouterVitePlugin = () => {
|
|
|
3967
4020
|
}
|
|
3968
4021
|
}
|
|
3969
4022
|
},
|
|
3970
|
-
validatePluginOrder()
|
|
4023
|
+
validatePluginOrder(),
|
|
4024
|
+
warnOnClientSourceMaps()
|
|
3971
4025
|
];
|
|
3972
4026
|
};
|
|
3973
4027
|
function getParentClientNodes(clientModuleGraph, module2) {
|
|
@@ -4037,7 +4091,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
4037
4091
|
function getRoute(pluginConfig, file) {
|
|
4038
4092
|
let vite2 = getVite();
|
|
4039
4093
|
let routePath = vite2.normalizePath(
|
|
4040
|
-
|
|
4094
|
+
path6.relative(pluginConfig.appDirectory, file)
|
|
4041
4095
|
);
|
|
4042
4096
|
let route = Object.values(pluginConfig.routes).find(
|
|
4043
4097
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -4076,7 +4130,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
4076
4130
|
caseSensitive: route.caseSensitive,
|
|
4077
4131
|
url: combineURLs(
|
|
4078
4132
|
ctx.publicPath,
|
|
4079
|
-
"/" +
|
|
4133
|
+
"/" + path6.relative(
|
|
4080
4134
|
ctx.rootDirectory,
|
|
4081
4135
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
4082
4136
|
)
|
|
@@ -4085,13 +4139,13 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
4085
4139
|
// Ensure the Vite dev server responds with a JS module
|
|
4086
4140
|
clientActionModule: hasRouteChunkByExportName.clientAction ? `${getRouteChunkModuleId(moduleUrl, "clientAction")}` : void 0,
|
|
4087
4141
|
clientLoaderModule: hasRouteChunkByExportName.clientLoader ? `${getRouteChunkModuleId(moduleUrl, "clientLoader")}` : void 0,
|
|
4088
|
-
clientMiddlewareModule: hasRouteChunkByExportName.
|
|
4142
|
+
clientMiddlewareModule: hasRouteChunkByExportName.clientMiddleware ? `${getRouteChunkModuleId(moduleUrl, "clientMiddleware")}` : void 0,
|
|
4089
4143
|
hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? `${getRouteChunkModuleId(moduleUrl, "HydrateFallback")}` : void 0,
|
|
4090
4144
|
hasAction: sourceExports.includes("action"),
|
|
4091
4145
|
hasClientAction: sourceExports.includes("clientAction"),
|
|
4092
4146
|
hasLoader: sourceExports.includes("loader"),
|
|
4093
4147
|
hasClientLoader: sourceExports.includes("clientLoader"),
|
|
4094
|
-
hasClientMiddleware: sourceExports.includes("
|
|
4148
|
+
hasClientMiddleware: sourceExports.includes("clientMiddleware"),
|
|
4095
4149
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
4096
4150
|
imports: []
|
|
4097
4151
|
};
|
|
@@ -4104,7 +4158,7 @@ function isSpaModeEnabled(reactRouterConfig) {
|
|
|
4104
4158
|
return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
|
|
4105
4159
|
}
|
|
4106
4160
|
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
4107
|
-
let serverBuildPath =
|
|
4161
|
+
let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
|
|
4108
4162
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
4109
4163
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
4110
4164
|
return {
|
|
@@ -4146,15 +4200,15 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
4146
4200
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
4147
4201
|
);
|
|
4148
4202
|
}
|
|
4149
|
-
await (0, import_promises2.writeFile)(
|
|
4150
|
-
let prettyDir =
|
|
4151
|
-
let prettyPath =
|
|
4203
|
+
await (0, import_promises2.writeFile)(path6.join(clientBuildDirectory, filename2), html);
|
|
4204
|
+
let prettyDir = path6.relative(viteConfig.root, clientBuildDirectory);
|
|
4205
|
+
let prettyPath = path6.join(prettyDir, filename2);
|
|
4152
4206
|
if (build.prerender.length > 0) {
|
|
4153
4207
|
viteConfig.logger.info(
|
|
4154
|
-
`Prerender (html): SPA Fallback -> ${
|
|
4208
|
+
`Prerender (html): SPA Fallback -> ${import_picocolors4.default.bold(prettyPath)}`
|
|
4155
4209
|
);
|
|
4156
4210
|
} else {
|
|
4157
|
-
viteConfig.logger.info(`SPA Mode: Generated ${
|
|
4211
|
+
viteConfig.logger.info(`SPA Mode: Generated ${import_picocolors4.default.bold(prettyPath)}`);
|
|
4158
4212
|
}
|
|
4159
4213
|
}
|
|
4160
4214
|
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildPath, clientBuildDirectory) {
|
|
@@ -4164,17 +4218,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4164
4218
|
serverBuildPath
|
|
4165
4219
|
);
|
|
4166
4220
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4167
|
-
for (let
|
|
4168
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
4221
|
+
for (let path7 of build.prerender) {
|
|
4222
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
4169
4223
|
if (!matches) {
|
|
4170
4224
|
throw new Error(
|
|
4171
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4225
|
+
`Unable to prerender path because it does not match any routes: ${path7}`
|
|
4172
4226
|
);
|
|
4173
4227
|
}
|
|
4174
4228
|
}
|
|
4175
4229
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4176
|
-
for (let
|
|
4177
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
4230
|
+
for (let path7 of build.prerender) {
|
|
4231
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
4178
4232
|
if (!matches) {
|
|
4179
4233
|
continue;
|
|
4180
4234
|
}
|
|
@@ -4187,7 +4241,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4187
4241
|
if (manifestRoute.loader) {
|
|
4188
4242
|
await prerenderData(
|
|
4189
4243
|
handler,
|
|
4190
|
-
|
|
4244
|
+
path7,
|
|
4191
4245
|
[leafRoute.id],
|
|
4192
4246
|
clientBuildDirectory,
|
|
4193
4247
|
reactRouterConfig,
|
|
@@ -4195,7 +4249,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4195
4249
|
);
|
|
4196
4250
|
await prerenderResourceRoute(
|
|
4197
4251
|
handler,
|
|
4198
|
-
|
|
4252
|
+
path7,
|
|
4199
4253
|
clientBuildDirectory,
|
|
4200
4254
|
reactRouterConfig,
|
|
4201
4255
|
viteConfig
|
|
@@ -4213,7 +4267,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4213
4267
|
if (!isResourceRoute && hasLoaders) {
|
|
4214
4268
|
data = await prerenderData(
|
|
4215
4269
|
handler,
|
|
4216
|
-
|
|
4270
|
+
path7,
|
|
4217
4271
|
null,
|
|
4218
4272
|
clientBuildDirectory,
|
|
4219
4273
|
reactRouterConfig,
|
|
@@ -4222,7 +4276,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4222
4276
|
}
|
|
4223
4277
|
await prerenderRoute(
|
|
4224
4278
|
handler,
|
|
4225
|
-
|
|
4279
|
+
path7,
|
|
4226
4280
|
clientBuildDirectory,
|
|
4227
4281
|
reactRouterConfig,
|
|
4228
4282
|
viteConfig,
|
|
@@ -4275,12 +4329,12 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
|
|
|
4275
4329
|
${normalizedPath}`
|
|
4276
4330
|
);
|
|
4277
4331
|
}
|
|
4278
|
-
let outfile =
|
|
4279
|
-
await (0, import_promises2.mkdir)(
|
|
4332
|
+
let outfile = path6.join(clientBuildDirectory, ...normalizedPath.split("/"));
|
|
4333
|
+
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4280
4334
|
await (0, import_promises2.writeFile)(outfile, data);
|
|
4281
4335
|
viteConfig.logger.info(
|
|
4282
|
-
`Prerender (data): ${prerenderPath} -> ${
|
|
4283
|
-
|
|
4336
|
+
`Prerender (data): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4337
|
+
path6.relative(viteConfig.root, outfile)
|
|
4284
4338
|
)}`
|
|
4285
4339
|
);
|
|
4286
4340
|
return data;
|
|
@@ -4315,16 +4369,16 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
4315
4369
|
${html}`
|
|
4316
4370
|
);
|
|
4317
4371
|
}
|
|
4318
|
-
let outfile =
|
|
4372
|
+
let outfile = path6.join(
|
|
4319
4373
|
clientBuildDirectory,
|
|
4320
4374
|
...normalizedPath.split("/"),
|
|
4321
4375
|
"index.html"
|
|
4322
4376
|
);
|
|
4323
|
-
await (0, import_promises2.mkdir)(
|
|
4377
|
+
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4324
4378
|
await (0, import_promises2.writeFile)(outfile, html);
|
|
4325
4379
|
viteConfig.logger.info(
|
|
4326
|
-
`Prerender (html): ${prerenderPath} -> ${
|
|
4327
|
-
|
|
4380
|
+
`Prerender (html): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4381
|
+
path6.relative(viteConfig.root, outfile)
|
|
4328
4382
|
)}`
|
|
4329
4383
|
);
|
|
4330
4384
|
}
|
|
@@ -4339,12 +4393,12 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
4339
4393
|
${content.toString("utf8")}`
|
|
4340
4394
|
);
|
|
4341
4395
|
}
|
|
4342
|
-
let outfile =
|
|
4343
|
-
await (0, import_promises2.mkdir)(
|
|
4396
|
+
let outfile = path6.join(clientBuildDirectory, ...normalizedPath.split("/"));
|
|
4397
|
+
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4344
4398
|
await (0, import_promises2.writeFile)(outfile, content);
|
|
4345
4399
|
viteConfig.logger.info(
|
|
4346
|
-
`Prerender (resource): ${prerenderPath} -> ${
|
|
4347
|
-
|
|
4400
|
+
`Prerender (resource): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4401
|
+
path6.relative(viteConfig.root, outfile)
|
|
4348
4402
|
)}`
|
|
4349
4403
|
);
|
|
4350
4404
|
}
|
|
@@ -4356,7 +4410,7 @@ async function getPrerenderPaths(prerender, ssr, routes, logWarning = false) {
|
|
|
4356
4410
|
let { paths, paramRoutes } = getStaticPrerenderPaths(prerenderRoutes);
|
|
4357
4411
|
if (logWarning && !ssr && paramRoutes.length > 0) {
|
|
4358
4412
|
console.warn(
|
|
4359
|
-
|
|
4413
|
+
import_picocolors4.default.yellow(
|
|
4360
4414
|
[
|
|
4361
4415
|
"\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:",
|
|
4362
4416
|
...paramRoutes.map((p) => " - " + p)
|
|
@@ -4418,14 +4472,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4418
4472
|
}
|
|
4419
4473
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4420
4474
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4421
|
-
for (let
|
|
4475
|
+
for (let path7 of prerenderPaths) {
|
|
4422
4476
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4423
4477
|
prerenderRoutes,
|
|
4424
|
-
`/${
|
|
4478
|
+
`/${path7}/`.replace(/^\/\/+/, "/")
|
|
4425
4479
|
);
|
|
4426
4480
|
invariant(
|
|
4427
4481
|
matches,
|
|
4428
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4482
|
+
`Unable to prerender path because it does not match any routes: ${path7}`
|
|
4429
4483
|
);
|
|
4430
4484
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4431
4485
|
}
|
|
@@ -4463,7 +4517,7 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4463
4517
|
}
|
|
4464
4518
|
}
|
|
4465
4519
|
if (errors.length > 0) {
|
|
4466
|
-
viteConfig.logger.error(
|
|
4520
|
+
viteConfig.logger.error(import_picocolors4.default.red(errors.join("\n")));
|
|
4467
4521
|
throw new Error(
|
|
4468
4522
|
"Invalid route exports found when prerendering with `ssr:false`"
|
|
4469
4523
|
);
|
|
@@ -4539,7 +4593,7 @@ async function detectRouteChunksIfEnabled(cache, ctx, id, input) {
|
|
|
4539
4593
|
hasRouteChunkByExportName: {
|
|
4540
4594
|
clientAction: false,
|
|
4541
4595
|
clientLoader: false,
|
|
4542
|
-
|
|
4596
|
+
clientMiddleware: false,
|
|
4543
4597
|
HydrateFallback: false
|
|
4544
4598
|
}
|
|
4545
4599
|
};
|
|
@@ -4592,8 +4646,8 @@ function validateRouteChunks({
|
|
|
4592
4646
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
4593
4647
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
4594
4648
|
let isWithinRoot = () => {
|
|
4595
|
-
let relativePath =
|
|
4596
|
-
return !relativePath.startsWith("..") && !
|
|
4649
|
+
let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
|
|
4650
|
+
return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
|
|
4597
4651
|
};
|
|
4598
4652
|
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
4599
4653
|
await (0, import_promises2.rm)(buildDirectory, { force: true, recursive: true });
|
|
@@ -4604,7 +4658,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4604
4658
|
([environmentName, options]) => {
|
|
4605
4659
|
let outDir = options.build?.outDir;
|
|
4606
4660
|
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
4607
|
-
return
|
|
4661
|
+
return path6.join(outDir, ".vite/manifest.json");
|
|
4608
4662
|
}
|
|
4609
4663
|
);
|
|
4610
4664
|
await Promise.all(
|
|
@@ -4614,7 +4668,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4614
4668
|
if (!ctx.viteManifestEnabled) {
|
|
4615
4669
|
await (0, import_promises2.rm)(viteManifestPath, { force: true, recursive: true });
|
|
4616
4670
|
}
|
|
4617
|
-
let viteDir =
|
|
4671
|
+
let viteDir = path6.dirname(viteManifestPath);
|
|
4618
4672
|
let viteDirFiles = await (0, import_promises2.readdir)(viteDir, { recursive: true });
|
|
4619
4673
|
if (viteDirFiles.length === 0) {
|
|
4620
4674
|
await (0, import_promises2.rm)(viteDir, { force: true, recursive: true });
|
|
@@ -4632,12 +4686,12 @@ async function getBuildManifest({
|
|
|
4632
4686
|
}
|
|
4633
4687
|
let { normalizePath } = await import("vite");
|
|
4634
4688
|
let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
|
|
4635
|
-
let resolvedAppDirectory =
|
|
4689
|
+
let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
|
|
4636
4690
|
let rootRelativeRoutes = Object.fromEntries(
|
|
4637
4691
|
Object.entries(routes).map(([id, route]) => {
|
|
4638
|
-
let filePath =
|
|
4692
|
+
let filePath = path6.join(resolvedAppDirectory, route.file);
|
|
4639
4693
|
let rootRelativeFilePath = normalizePath(
|
|
4640
|
-
|
|
4694
|
+
path6.relative(rootDirectory, filePath)
|
|
4641
4695
|
);
|
|
4642
4696
|
return [id, { ...route, file: rootRelativeFilePath }];
|
|
4643
4697
|
})
|
|
@@ -4655,7 +4709,7 @@ async function getBuildManifest({
|
|
|
4655
4709
|
(route2) => configRouteToBranchRoute({
|
|
4656
4710
|
...route2,
|
|
4657
4711
|
// Ensure absolute paths are passed to the serverBundles function
|
|
4658
|
-
file:
|
|
4712
|
+
file: path6.join(resolvedAppDirectory, route2.file)
|
|
4659
4713
|
})
|
|
4660
4714
|
)
|
|
4661
4715
|
});
|
|
@@ -4679,10 +4733,10 @@ async function getBuildManifest({
|
|
|
4679
4733
|
buildManifest.serverBundles[serverBundleId] ??= {
|
|
4680
4734
|
id: serverBundleId,
|
|
4681
4735
|
file: normalizePath(
|
|
4682
|
-
|
|
4683
|
-
|
|
4736
|
+
path6.join(
|
|
4737
|
+
path6.relative(
|
|
4684
4738
|
rootDirectory,
|
|
4685
|
-
|
|
4739
|
+
path6.join(serverBuildDirectory, serverBundleId)
|
|
4686
4740
|
),
|
|
4687
4741
|
reactRouterConfig.serverBuildFile
|
|
4688
4742
|
)
|
|
@@ -4701,10 +4755,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
|
|
|
4701
4755
|
}
|
|
4702
4756
|
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
4703
4757
|
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
4704
|
-
let packageRoot =
|
|
4758
|
+
let packageRoot = path6.dirname(
|
|
4705
4759
|
require.resolve("@react-router/dev/package.json")
|
|
4706
4760
|
);
|
|
4707
|
-
let { moduleSyncEnabled } = await import(`file:///${
|
|
4761
|
+
let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
4708
4762
|
let vite2 = getVite();
|
|
4709
4763
|
function getBaseOptions({
|
|
4710
4764
|
viteUserConfig
|
|
@@ -4783,7 +4837,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4783
4837
|
ctx.entryClientFilePath,
|
|
4784
4838
|
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
4785
4839
|
(route) => {
|
|
4786
|
-
let routeFilePath =
|
|
4840
|
+
let routeFilePath = path6.resolve(
|
|
4787
4841
|
ctx.reactRouterConfig.appDirectory,
|
|
4788
4842
|
route.file
|
|
4789
4843
|
);
|
|
@@ -4807,7 +4861,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4807
4861
|
) : null;
|
|
4808
4862
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4809
4863
|
let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
4810
|
-
return
|
|
4864
|
+
return path6.posix.join(
|
|
4811
4865
|
assetsDir,
|
|
4812
4866
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4813
4867
|
);
|