@react-router/dev 0.0.0-experimental-ab0e85b04 → 0.0.0-experimental-818f8e08d
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/dist/cli/index.js +154 -243
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +80 -163
- package/dist/vite.js +294 -371
- package/package.json +6 -6
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-818f8e08d
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -47,7 +47,7 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
47
47
|
// vite/plugin.ts
|
|
48
48
|
var import_node_crypto = require("crypto");
|
|
49
49
|
var fs3 = __toESM(require("fs"));
|
|
50
|
-
var
|
|
50
|
+
var path6 = __toESM(require("path"));
|
|
51
51
|
var url = __toESM(require("url"));
|
|
52
52
|
var fse = __toESM(require("fs-extra"));
|
|
53
53
|
var babel = __toESM(require("@babel/core"));
|
|
@@ -61,7 +61,7 @@ var import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
|
61
61
|
// typegen/index.ts
|
|
62
62
|
var import_node_fs2 = __toESM(require("fs"));
|
|
63
63
|
var import_dedent2 = __toESM(require("dedent"));
|
|
64
|
-
var
|
|
64
|
+
var Path4 = __toESM(require("pathe"));
|
|
65
65
|
var import_picocolors2 = __toESM(require("picocolors"));
|
|
66
66
|
|
|
67
67
|
// config/config.ts
|
|
@@ -136,15 +136,13 @@ var ssrExternals = isReactRouterRepo() ? [
|
|
|
136
136
|
// vite/vite-node.ts
|
|
137
137
|
async function createContext({
|
|
138
138
|
root,
|
|
139
|
-
mode
|
|
140
|
-
customLogger
|
|
139
|
+
mode
|
|
141
140
|
}) {
|
|
142
141
|
await preloadVite();
|
|
143
142
|
const vite2 = getVite();
|
|
144
143
|
const devServer = await vite2.createServer({
|
|
145
144
|
root,
|
|
146
145
|
mode,
|
|
147
|
-
customLogger,
|
|
148
146
|
server: {
|
|
149
147
|
preTransformRequests: false,
|
|
150
148
|
hmr: false,
|
|
@@ -242,7 +240,7 @@ function validateRouteConfig({
|
|
|
242
240
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
243
241
|
root ? `${root}` : [],
|
|
244
242
|
nested ? Object.entries(nested).map(
|
|
245
|
-
([
|
|
243
|
+
([path7, message]) => `Path: routes.${path7}
|
|
246
244
|
${message}`
|
|
247
245
|
) : []
|
|
248
246
|
].flat().join("\n\n")
|
|
@@ -358,8 +356,7 @@ function err(error) {
|
|
|
358
356
|
async function resolveConfig({
|
|
359
357
|
root,
|
|
360
358
|
viteNodeContext,
|
|
361
|
-
reactRouterConfigFile
|
|
362
|
-
skipRoutes
|
|
359
|
+
reactRouterConfigFile
|
|
363
360
|
}) {
|
|
364
361
|
let reactRouterUserConfig = {};
|
|
365
362
|
if (reactRouterConfigFile) {
|
|
@@ -475,50 +472,45 @@ async function resolveConfig({
|
|
|
475
472
|
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
476
473
|
);
|
|
477
474
|
}
|
|
478
|
-
let routes = {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
root,
|
|
488
|
-
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
489
|
-
);
|
|
490
|
-
return err(
|
|
491
|
-
`Route config file not found at "${routeConfigDisplayPath}".`
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
setAppDirectory(appDirectory);
|
|
495
|
-
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
496
|
-
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
497
|
-
)).default;
|
|
498
|
-
let routeConfig = await routeConfigExport;
|
|
499
|
-
let result = validateRouteConfig({
|
|
500
|
-
routeConfigFile,
|
|
501
|
-
routeConfig
|
|
502
|
-
});
|
|
503
|
-
if (!result.valid) {
|
|
504
|
-
return err(result.message);
|
|
505
|
-
}
|
|
506
|
-
routes = {
|
|
507
|
-
...routes,
|
|
508
|
-
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
509
|
-
};
|
|
510
|
-
} catch (error) {
|
|
511
|
-
return err(
|
|
512
|
-
[
|
|
513
|
-
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
514
|
-
"",
|
|
515
|
-
error.loc?.file && error.loc?.column && error.frame ? [
|
|
516
|
-
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
517
|
-
error.frame.trim?.()
|
|
518
|
-
] : error.stack
|
|
519
|
-
].flat().join("\n")
|
|
475
|
+
let routes = {
|
|
476
|
+
root: { path: "", id: "root", file: rootRouteFile }
|
|
477
|
+
};
|
|
478
|
+
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
479
|
+
try {
|
|
480
|
+
if (!routeConfigFile) {
|
|
481
|
+
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
482
|
+
root,
|
|
483
|
+
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
520
484
|
);
|
|
485
|
+
return err(`Route config file not found at "${routeConfigDisplayPath}".`);
|
|
486
|
+
}
|
|
487
|
+
setAppDirectory(appDirectory);
|
|
488
|
+
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
489
|
+
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
490
|
+
)).default;
|
|
491
|
+
let routeConfig = await routeConfigExport;
|
|
492
|
+
let result = validateRouteConfig({
|
|
493
|
+
routeConfigFile,
|
|
494
|
+
routeConfig
|
|
495
|
+
});
|
|
496
|
+
if (!result.valid) {
|
|
497
|
+
return err(result.message);
|
|
521
498
|
}
|
|
499
|
+
routes = {
|
|
500
|
+
...routes,
|
|
501
|
+
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
502
|
+
};
|
|
503
|
+
} catch (error) {
|
|
504
|
+
return err(
|
|
505
|
+
[
|
|
506
|
+
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
507
|
+
"",
|
|
508
|
+
error.loc?.file && error.loc?.column && error.frame ? [
|
|
509
|
+
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
510
|
+
error.frame.trim?.()
|
|
511
|
+
] : error.stack
|
|
512
|
+
].flat().join("\n")
|
|
513
|
+
);
|
|
522
514
|
}
|
|
523
515
|
let future = {
|
|
524
516
|
unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
|
|
@@ -549,34 +541,24 @@ async function resolveConfig({
|
|
|
549
541
|
async function createConfigLoader({
|
|
550
542
|
rootDirectory: root,
|
|
551
543
|
watch: watch2,
|
|
552
|
-
mode
|
|
553
|
-
skipRoutes
|
|
544
|
+
mode
|
|
554
545
|
}) {
|
|
555
|
-
root =
|
|
556
|
-
let vite2 = await import("vite");
|
|
546
|
+
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
557
547
|
let viteNodeContext = await createContext({
|
|
558
548
|
root,
|
|
559
|
-
mode
|
|
560
|
-
// Filter out any info level logs from vite-node
|
|
561
|
-
customLogger: vite2.createLogger("warn", {
|
|
562
|
-
prefix: "[react-router]"
|
|
563
|
-
})
|
|
549
|
+
mode
|
|
564
550
|
});
|
|
565
|
-
let reactRouterConfigFile
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
});
|
|
570
|
-
};
|
|
571
|
-
updateReactRouterConfigFile();
|
|
572
|
-
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
|
|
551
|
+
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
552
|
+
absolute: true
|
|
553
|
+
});
|
|
554
|
+
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
|
|
573
555
|
let appDirectory;
|
|
574
556
|
let initialConfigResult = await getConfig();
|
|
575
557
|
if (!initialConfigResult.ok) {
|
|
576
558
|
throw new Error(initialConfigResult.error);
|
|
577
559
|
}
|
|
578
|
-
appDirectory =
|
|
579
|
-
let
|
|
560
|
+
appDirectory = initialConfigResult.value.appDirectory;
|
|
561
|
+
let lastConfig = initialConfigResult.value;
|
|
580
562
|
let fsWatcher;
|
|
581
563
|
let changeHandlers = [];
|
|
582
564
|
return {
|
|
@@ -589,71 +571,41 @@ async function createConfigLoader({
|
|
|
589
571
|
}
|
|
590
572
|
changeHandlers.push(handler);
|
|
591
573
|
if (!fsWatcher) {
|
|
592
|
-
fsWatcher = import_chokidar.default.watch(
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
dirname5 !== root;
|
|
600
|
-
}
|
|
601
|
-
});
|
|
574
|
+
fsWatcher = import_chokidar.default.watch(
|
|
575
|
+
[
|
|
576
|
+
...reactRouterConfigFile ? [reactRouterConfigFile] : [],
|
|
577
|
+
appDirectory
|
|
578
|
+
],
|
|
579
|
+
{ ignoreInitial: true }
|
|
580
|
+
);
|
|
602
581
|
fsWatcher.on("all", async (...args) => {
|
|
603
582
|
let [event, rawFilepath] = args;
|
|
604
583
|
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
605
|
-
let
|
|
606
|
-
let
|
|
607
|
-
let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
|
|
608
|
-
let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
|
|
609
|
-
if (configFileAddedOrRemoved) {
|
|
610
|
-
updateReactRouterConfigFile();
|
|
611
|
-
}
|
|
612
|
-
let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
|
|
584
|
+
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
585
|
+
let configCodeUpdated = Boolean(
|
|
613
586
|
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
614
587
|
);
|
|
615
|
-
if (
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
619
|
-
viteNodeContext.runner?.moduleCache.clear();
|
|
620
|
-
let result = await getConfig();
|
|
621
|
-
let prevAppDirectory = appDirectory;
|
|
622
|
-
appDirectory = import_pathe3.default.normalize(
|
|
623
|
-
(result.value ?? currentConfig).appDirectory
|
|
624
|
-
);
|
|
625
|
-
if (appDirectory !== prevAppDirectory) {
|
|
626
|
-
fsWatcher.unwatch(prevAppDirectory);
|
|
627
|
-
fsWatcher.add(appDirectory);
|
|
588
|
+
if (configCodeUpdated || appFileAddedOrRemoved) {
|
|
589
|
+
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
590
|
+
viteNodeContext.runner?.moduleCache.clear();
|
|
628
591
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
result,
|
|
647
|
-
configCodeChanged,
|
|
648
|
-
routeConfigCodeChanged,
|
|
649
|
-
configChanged,
|
|
650
|
-
routeConfigChanged,
|
|
651
|
-
path: filepath,
|
|
652
|
-
event
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
if (result.ok) {
|
|
656
|
-
currentConfig = result.value;
|
|
592
|
+
if (appFileAddedOrRemoved || configCodeUpdated) {
|
|
593
|
+
let result = await getConfig();
|
|
594
|
+
let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
|
|
595
|
+
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
|
|
596
|
+
for (let handler2 of changeHandlers) {
|
|
597
|
+
handler2({
|
|
598
|
+
result,
|
|
599
|
+
configCodeUpdated,
|
|
600
|
+
configChanged,
|
|
601
|
+
routeConfigChanged,
|
|
602
|
+
path: filepath,
|
|
603
|
+
event
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
if (result.ok) {
|
|
607
|
+
lastConfig = result.value;
|
|
608
|
+
}
|
|
657
609
|
}
|
|
658
610
|
});
|
|
659
611
|
}
|
|
@@ -729,16 +681,7 @@ async function resolveEntryFiles({
|
|
|
729
681
|
let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
|
|
730
682
|
return { entryClientFilePath, entryServerFilePath };
|
|
731
683
|
}
|
|
732
|
-
function omitRoutes(config) {
|
|
733
|
-
return {
|
|
734
|
-
...config,
|
|
735
|
-
routes: {}
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
684
|
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
739
|
-
function isEntryFile(entryBasename, filename3) {
|
|
740
|
-
return entryExts.some((ext) => filename3 === `${entryBasename}${ext}`);
|
|
741
|
-
}
|
|
742
685
|
function findEntry(dir, basename2, options) {
|
|
743
686
|
let currentDir = import_pathe3.default.resolve(dir);
|
|
744
687
|
let { root } = import_pathe3.default.parse(currentDir);
|
|
@@ -759,30 +702,6 @@ function findEntry(dir, basename2, options) {
|
|
|
759
702
|
currentDir = parentDir;
|
|
760
703
|
}
|
|
761
704
|
}
|
|
762
|
-
function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
|
|
763
|
-
entryFilepath = import_pathe3.default.normalize(entryFilepath);
|
|
764
|
-
filepath = import_pathe3.default.normalize(filepath);
|
|
765
|
-
if (visited.has(filepath)) {
|
|
766
|
-
return false;
|
|
767
|
-
}
|
|
768
|
-
visited.add(filepath);
|
|
769
|
-
if (filepath === entryFilepath) {
|
|
770
|
-
return true;
|
|
771
|
-
}
|
|
772
|
-
let mod = moduleGraph.getModuleById(filepath);
|
|
773
|
-
if (!mod) {
|
|
774
|
-
return false;
|
|
775
|
-
}
|
|
776
|
-
for (let importer of mod.importers) {
|
|
777
|
-
if (!importer.id) {
|
|
778
|
-
continue;
|
|
779
|
-
}
|
|
780
|
-
if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
|
|
781
|
-
return true;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
return false;
|
|
785
|
-
}
|
|
786
705
|
|
|
787
706
|
// vite/babel.ts
|
|
788
707
|
var babel_exports = {};
|
|
@@ -799,20 +718,20 @@ var generate = require("@babel/generator").default;
|
|
|
799
718
|
|
|
800
719
|
// typegen/generate.ts
|
|
801
720
|
var import_dedent = __toESM(require("dedent"));
|
|
802
|
-
var
|
|
721
|
+
var Path3 = __toESM(require("pathe"));
|
|
803
722
|
var Pathe2 = __toESM(require("pathe/utils"));
|
|
804
723
|
|
|
805
724
|
// typegen/paths.ts
|
|
806
|
-
var
|
|
725
|
+
var Path2 = __toESM(require("pathe"));
|
|
807
726
|
var Pathe = __toESM(require("pathe/utils"));
|
|
808
727
|
function getTypesDir(ctx) {
|
|
809
|
-
return
|
|
728
|
+
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
810
729
|
}
|
|
811
730
|
function getTypesPath(ctx, route) {
|
|
812
|
-
return
|
|
731
|
+
return Path2.join(
|
|
813
732
|
getTypesDir(ctx),
|
|
814
|
-
|
|
815
|
-
|
|
733
|
+
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
734
|
+
Path2.dirname(route.file),
|
|
816
735
|
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
817
736
|
);
|
|
818
737
|
}
|
|
@@ -847,7 +766,7 @@ function lineage(routes, route) {
|
|
|
847
766
|
}
|
|
848
767
|
function fullpath(lineage2) {
|
|
849
768
|
if (lineage2.length === 1 && lineage2[0].id === "root") return "/";
|
|
850
|
-
return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
769
|
+
return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path7) => path7 !== void 0 && path7 !== "").join("/");
|
|
851
770
|
}
|
|
852
771
|
|
|
853
772
|
// typegen/generate.ts
|
|
@@ -857,8 +776,8 @@ function generate2(ctx, route) {
|
|
|
857
776
|
const typesPath = getTypesPath(ctx, route);
|
|
858
777
|
const parents = lineage2.slice(0, -1);
|
|
859
778
|
const parentTypeImports = parents.map((parent, i) => {
|
|
860
|
-
const rel =
|
|
861
|
-
|
|
779
|
+
const rel = Path3.relative(
|
|
780
|
+
Path3.dirname(typesPath),
|
|
862
781
|
getTypesPath(ctx, parent)
|
|
863
782
|
);
|
|
864
783
|
const indent = i === 0 ? "" : " ".repeat(2);
|
|
@@ -913,7 +832,7 @@ function generate2(ctx, route) {
|
|
|
913
832
|
}
|
|
914
833
|
`;
|
|
915
834
|
}
|
|
916
|
-
var noExtension = (
|
|
835
|
+
var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
|
|
917
836
|
function formatParamProperties(fullpath2) {
|
|
918
837
|
const params = parse2(fullpath2);
|
|
919
838
|
const properties = Object.entries(params).map(
|
|
@@ -927,22 +846,20 @@ async function watch(rootDirectory, { mode, logger }) {
|
|
|
927
846
|
const ctx = await createContext2({ rootDirectory, mode, watch: true });
|
|
928
847
|
await writeAll(ctx);
|
|
929
848
|
logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
|
|
930
|
-
ctx.configLoader.onChange(
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return;
|
|
935
|
-
}
|
|
936
|
-
ctx.config = result.value;
|
|
937
|
-
if (configChanged || routeConfigChanged) {
|
|
938
|
-
await writeAll(ctx);
|
|
939
|
-
logger?.info(import_picocolors2.default.green("regenerated types"), {
|
|
940
|
-
timestamp: true,
|
|
941
|
-
clear: true
|
|
942
|
-
});
|
|
943
|
-
}
|
|
849
|
+
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
850
|
+
if (!result.ok) {
|
|
851
|
+
logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
|
|
852
|
+
return;
|
|
944
853
|
}
|
|
945
|
-
|
|
854
|
+
ctx.config = result.value;
|
|
855
|
+
if (routeConfigChanged) {
|
|
856
|
+
await writeAll(ctx);
|
|
857
|
+
logger?.info(import_picocolors2.default.green("regenerated types"), {
|
|
858
|
+
timestamp: true,
|
|
859
|
+
clear: true
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
});
|
|
946
863
|
return {
|
|
947
864
|
close: async () => await ctx.configLoader.close()
|
|
948
865
|
};
|
|
@@ -970,12 +887,12 @@ async function writeAll(ctx) {
|
|
|
970
887
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
971
888
|
const typesPath = getTypesPath(ctx, route);
|
|
972
889
|
const content = generate2(ctx, route);
|
|
973
|
-
import_node_fs2.default.mkdirSync(
|
|
890
|
+
import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
974
891
|
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
975
892
|
});
|
|
976
|
-
const registerPath =
|
|
893
|
+
const registerPath = Path4.join(typegenDir, "+register.ts");
|
|
977
894
|
import_node_fs2.default.writeFileSync(registerPath, register(ctx));
|
|
978
|
-
const virtualPath =
|
|
895
|
+
const virtualPath = Path4.join(typegenDir, "+virtual.d.ts");
|
|
979
896
|
import_node_fs2.default.writeFileSync(virtualPath, virtual);
|
|
980
897
|
}
|
|
981
898
|
function register(ctx) {
|
|
@@ -986,25 +903,21 @@ function register(ctx) {
|
|
|
986
903
|
interface Register {
|
|
987
904
|
params: Params;
|
|
988
905
|
}
|
|
989
|
-
|
|
990
|
-
interface Future {
|
|
991
|
-
unstable_middleware: ${ctx.config.future.unstable_middleware}
|
|
992
|
-
}
|
|
993
906
|
}
|
|
994
907
|
`;
|
|
995
908
|
const { t: t2 } = babel_exports;
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
const lineage2 = lineage(ctx.config.routes, route);
|
|
1000
|
-
const fullpath2 = fullpath(lineage2);
|
|
1001
|
-
fullpaths.add(fullpath2);
|
|
1002
|
-
});
|
|
909
|
+
const indexPaths = new Set(
|
|
910
|
+
Object.values(ctx.config.routes).filter((route) => route.index).map((route) => route.path)
|
|
911
|
+
);
|
|
1003
912
|
const typeParams = t2.tsTypeAliasDeclaration(
|
|
1004
913
|
t2.identifier("Params"),
|
|
1005
914
|
null,
|
|
1006
915
|
t2.tsTypeLiteral(
|
|
1007
|
-
|
|
916
|
+
Object.values(ctx.config.routes).map((route) => {
|
|
917
|
+
if (route.id !== "root" && !route.path) return void 0;
|
|
918
|
+
if (!route.index && indexPaths.has(route.path)) return void 0;
|
|
919
|
+
const lineage2 = lineage(ctx.config.routes, route);
|
|
920
|
+
const fullpath2 = fullpath(lineage2);
|
|
1008
921
|
const params = parse2(fullpath2);
|
|
1009
922
|
return t2.tsPropertySignature(
|
|
1010
923
|
t2.stringLiteral(fullpath2),
|
|
@@ -1021,7 +934,7 @@ function register(ctx) {
|
|
|
1021
934
|
)
|
|
1022
935
|
)
|
|
1023
936
|
);
|
|
1024
|
-
})
|
|
937
|
+
}).filter((x) => x !== void 0)
|
|
1025
938
|
)
|
|
1026
939
|
);
|
|
1027
940
|
return [register2, generate(typeParams).code].join("\n\n");
|
|
@@ -1121,17 +1034,17 @@ async function toNodeRequest(res, nodeRes) {
|
|
|
1121
1034
|
}
|
|
1122
1035
|
|
|
1123
1036
|
// vite/styles.ts
|
|
1124
|
-
var
|
|
1037
|
+
var path5 = __toESM(require("path"));
|
|
1125
1038
|
var import_react_router = require("react-router");
|
|
1126
1039
|
|
|
1127
1040
|
// vite/resolve-file-url.ts
|
|
1128
|
-
var
|
|
1041
|
+
var path4 = __toESM(require("path"));
|
|
1129
1042
|
var resolveFileUrl = ({ rootDirectory }, filePath) => {
|
|
1130
1043
|
let vite2 = getVite();
|
|
1131
|
-
let relativePath =
|
|
1132
|
-
let isWithinRoot = !relativePath.startsWith("..") && !
|
|
1044
|
+
let relativePath = path4.relative(rootDirectory, filePath);
|
|
1045
|
+
let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
|
|
1133
1046
|
if (!isWithinRoot) {
|
|
1134
|
-
return
|
|
1047
|
+
return path4.posix.join("/@fs", vite2.normalizePath(filePath));
|
|
1135
1048
|
}
|
|
1136
1049
|
return "/" + vite2.normalizePath(relativePath);
|
|
1137
1050
|
};
|
|
@@ -1168,7 +1081,7 @@ var getStylesForFiles = async ({
|
|
|
1168
1081
|
let deps = /* @__PURE__ */ new Set();
|
|
1169
1082
|
try {
|
|
1170
1083
|
for (let file of files) {
|
|
1171
|
-
let normalizedPath =
|
|
1084
|
+
let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
|
|
1172
1085
|
let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
1173
1086
|
if (!node) {
|
|
1174
1087
|
try {
|
|
@@ -1269,9 +1182,9 @@ var getStylesForPathname = async ({
|
|
|
1269
1182
|
return void 0;
|
|
1270
1183
|
}
|
|
1271
1184
|
let routesWithChildren = createRoutesWithChildren(reactRouterConfig.routes);
|
|
1272
|
-
let appPath =
|
|
1185
|
+
let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
|
|
1273
1186
|
let documentRouteFiles = (0, import_react_router.matchRoutes)(routesWithChildren, pathname, reactRouterConfig.basename)?.map(
|
|
1274
|
-
(match) =>
|
|
1187
|
+
(match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
|
|
1275
1188
|
) ?? [];
|
|
1276
1189
|
let styles = await getStylesForFiles({
|
|
1277
1190
|
viteDevServer,
|
|
@@ -1279,27 +1192,13 @@ var getStylesForPathname = async ({
|
|
|
1279
1192
|
loadCssContents,
|
|
1280
1193
|
files: [
|
|
1281
1194
|
// Always include the client entry file when crawling the module graph for CSS
|
|
1282
|
-
|
|
1195
|
+
path5.relative(rootDirectory, entryClientFilePath),
|
|
1283
1196
|
// Then include any styles from the matched routes
|
|
1284
1197
|
...documentRouteFiles
|
|
1285
1198
|
]
|
|
1286
1199
|
});
|
|
1287
1200
|
return styles;
|
|
1288
1201
|
};
|
|
1289
|
-
var getCssStringFromViteDevModuleCode = (code) => {
|
|
1290
|
-
let cssContent = void 0;
|
|
1291
|
-
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1292
|
-
traverse(ast, {
|
|
1293
|
-
VariableDeclaration(path6) {
|
|
1294
|
-
const declaration = path6.node.declarations[0];
|
|
1295
|
-
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1296
|
-
cssContent = declaration.init.value;
|
|
1297
|
-
path6.stop();
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
});
|
|
1301
|
-
return cssContent;
|
|
1302
|
-
};
|
|
1303
1202
|
|
|
1304
1203
|
// vite/virtual-module.ts
|
|
1305
1204
|
function create(name) {
|
|
@@ -1323,10 +1222,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1323
1222
|
let exportsFiltered = false;
|
|
1324
1223
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1325
1224
|
traverse(ast, {
|
|
1326
|
-
ExportDeclaration(
|
|
1327
|
-
if (
|
|
1328
|
-
if (
|
|
1329
|
-
|
|
1225
|
+
ExportDeclaration(path7) {
|
|
1226
|
+
if (path7.node.type === "ExportNamedDeclaration") {
|
|
1227
|
+
if (path7.node.specifiers.length) {
|
|
1228
|
+
path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
|
|
1330
1229
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1331
1230
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1332
1231
|
exportsFiltered = true;
|
|
@@ -1335,12 +1234,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1335
1234
|
}
|
|
1336
1235
|
return true;
|
|
1337
1236
|
});
|
|
1338
|
-
if (
|
|
1339
|
-
markedForRemoval.add(
|
|
1237
|
+
if (path7.node.specifiers.length === 0) {
|
|
1238
|
+
markedForRemoval.add(path7);
|
|
1340
1239
|
}
|
|
1341
1240
|
}
|
|
1342
|
-
if (
|
|
1343
|
-
let declaration =
|
|
1241
|
+
if (path7.node.declaration?.type === "VariableDeclaration") {
|
|
1242
|
+
let declaration = path7.node.declaration;
|
|
1344
1243
|
declaration.declarations = declaration.declarations.filter(
|
|
1345
1244
|
(declaration2) => {
|
|
1346
1245
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1354,30 +1253,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1354
1253
|
}
|
|
1355
1254
|
);
|
|
1356
1255
|
if (declaration.declarations.length === 0) {
|
|
1357
|
-
markedForRemoval.add(
|
|
1256
|
+
markedForRemoval.add(path7);
|
|
1358
1257
|
}
|
|
1359
1258
|
}
|
|
1360
|
-
if (
|
|
1361
|
-
let id =
|
|
1259
|
+
if (path7.node.declaration?.type === "FunctionDeclaration") {
|
|
1260
|
+
let id = path7.node.declaration.id;
|
|
1362
1261
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1363
|
-
markedForRemoval.add(
|
|
1262
|
+
markedForRemoval.add(path7);
|
|
1364
1263
|
}
|
|
1365
1264
|
}
|
|
1366
|
-
if (
|
|
1367
|
-
let id =
|
|
1265
|
+
if (path7.node.declaration?.type === "ClassDeclaration") {
|
|
1266
|
+
let id = path7.node.declaration.id;
|
|
1368
1267
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1369
|
-
markedForRemoval.add(
|
|
1268
|
+
markedForRemoval.add(path7);
|
|
1370
1269
|
}
|
|
1371
1270
|
}
|
|
1372
1271
|
}
|
|
1373
|
-
if (
|
|
1374
|
-
markedForRemoval.add(
|
|
1272
|
+
if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
1273
|
+
markedForRemoval.add(path7);
|
|
1375
1274
|
}
|
|
1376
1275
|
}
|
|
1377
1276
|
});
|
|
1378
1277
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1379
|
-
for (let
|
|
1380
|
-
|
|
1278
|
+
for (let path7 of markedForRemoval) {
|
|
1279
|
+
path7.remove();
|
|
1381
1280
|
}
|
|
1382
1281
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1383
1282
|
}
|
|
@@ -1448,28 +1347,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1448
1347
|
)
|
|
1449
1348
|
);
|
|
1450
1349
|
}
|
|
1451
|
-
function assertNodePath(
|
|
1350
|
+
function assertNodePath(path7) {
|
|
1452
1351
|
invariant(
|
|
1453
|
-
|
|
1454
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1352
|
+
path7 && !Array.isArray(path7),
|
|
1353
|
+
`Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
|
|
1455
1354
|
);
|
|
1456
1355
|
}
|
|
1457
|
-
function assertNodePathIsStatement(
|
|
1356
|
+
function assertNodePathIsStatement(path7) {
|
|
1458
1357
|
invariant(
|
|
1459
|
-
|
|
1460
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1358
|
+
path7 && !Array.isArray(path7) && t.isStatement(path7.node),
|
|
1359
|
+
`Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1461
1360
|
);
|
|
1462
1361
|
}
|
|
1463
|
-
function assertNodePathIsVariableDeclarator(
|
|
1362
|
+
function assertNodePathIsVariableDeclarator(path7) {
|
|
1464
1363
|
invariant(
|
|
1465
|
-
|
|
1466
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1364
|
+
path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
|
|
1365
|
+
`Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1467
1366
|
);
|
|
1468
1367
|
}
|
|
1469
|
-
function assertNodePathIsPattern(
|
|
1368
|
+
function assertNodePathIsPattern(path7) {
|
|
1470
1369
|
invariant(
|
|
1471
|
-
|
|
1472
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1370
|
+
path7 && !Array.isArray(path7) && t.isPattern(path7.node),
|
|
1371
|
+
`Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
|
|
1473
1372
|
);
|
|
1474
1373
|
}
|
|
1475
1374
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1505,8 +1404,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1505
1404
|
}
|
|
1506
1405
|
let isWithinExportDestructuring = Boolean(
|
|
1507
1406
|
identifier.findParent(
|
|
1508
|
-
(
|
|
1509
|
-
|
|
1407
|
+
(path7) => Boolean(
|
|
1408
|
+
path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1510
1409
|
)
|
|
1511
1410
|
)
|
|
1512
1411
|
);
|
|
@@ -1584,7 +1483,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1584
1483
|
for (let specifier of node.specifiers) {
|
|
1585
1484
|
if (t.isIdentifier(specifier.exported)) {
|
|
1586
1485
|
let name = specifier.exported.name;
|
|
1587
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1486
|
+
let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
|
|
1588
1487
|
invariant(
|
|
1589
1488
|
specifierPath,
|
|
1590
1489
|
`Expected to find specifier path for ${name}`
|
|
@@ -1601,22 +1500,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1601
1500
|
}
|
|
1602
1501
|
);
|
|
1603
1502
|
}
|
|
1604
|
-
function getDependentIdentifiersForPath(
|
|
1503
|
+
function getDependentIdentifiersForPath(path7, state) {
|
|
1605
1504
|
let { visited, identifiers } = state ?? {
|
|
1606
1505
|
visited: /* @__PURE__ */ new Set(),
|
|
1607
1506
|
identifiers: /* @__PURE__ */ new Set()
|
|
1608
1507
|
};
|
|
1609
|
-
if (visited.has(
|
|
1508
|
+
if (visited.has(path7)) {
|
|
1610
1509
|
return identifiers;
|
|
1611
1510
|
}
|
|
1612
|
-
visited.add(
|
|
1613
|
-
|
|
1614
|
-
Identifier(
|
|
1615
|
-
if (identifiers.has(
|
|
1511
|
+
visited.add(path7);
|
|
1512
|
+
path7.traverse({
|
|
1513
|
+
Identifier(path8) {
|
|
1514
|
+
if (identifiers.has(path8)) {
|
|
1616
1515
|
return;
|
|
1617
1516
|
}
|
|
1618
|
-
identifiers.add(
|
|
1619
|
-
let binding =
|
|
1517
|
+
identifiers.add(path8);
|
|
1518
|
+
let binding = path8.scope.getBinding(path8.node.name);
|
|
1620
1519
|
if (!binding) {
|
|
1621
1520
|
return;
|
|
1622
1521
|
}
|
|
@@ -1638,7 +1537,7 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1638
1537
|
}
|
|
1639
1538
|
}
|
|
1640
1539
|
});
|
|
1641
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1540
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1642
1541
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1643
1542
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1644
1543
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1647,9 +1546,9 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1647
1546
|
identifiers
|
|
1648
1547
|
});
|
|
1649
1548
|
}
|
|
1650
|
-
if (withinExportStatement &&
|
|
1651
|
-
t.isPattern(
|
|
1652
|
-
let variableDeclarator =
|
|
1549
|
+
if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
|
|
1550
|
+
t.isPattern(path7.parentPath.parentPath?.node))) {
|
|
1551
|
+
let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
|
|
1653
1552
|
assertNodePath(variableDeclarator);
|
|
1654
1553
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1655
1554
|
visited,
|
|
@@ -1658,16 +1557,16 @@ function getDependentIdentifiersForPath(path6, state) {
|
|
|
1658
1557
|
}
|
|
1659
1558
|
return identifiers;
|
|
1660
1559
|
}
|
|
1661
|
-
function getTopLevelStatementPathForPath(
|
|
1662
|
-
let ancestry =
|
|
1560
|
+
function getTopLevelStatementPathForPath(path7) {
|
|
1561
|
+
let ancestry = path7.getAncestry();
|
|
1663
1562
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1664
1563
|
assertNodePathIsStatement(topLevelStatement);
|
|
1665
1564
|
return topLevelStatement;
|
|
1666
1565
|
}
|
|
1667
1566
|
function getTopLevelStatementsForPaths(paths) {
|
|
1668
1567
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1669
|
-
for (let
|
|
1670
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1568
|
+
for (let path7 of paths) {
|
|
1569
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path7);
|
|
1671
1570
|
topLevelStatements.add(topLevelStatement.node);
|
|
1672
1571
|
}
|
|
1673
1572
|
return topLevelStatements;
|
|
@@ -2084,24 +1983,24 @@ var plugin = {
|
|
|
2084
1983
|
};
|
|
2085
1984
|
var transform = (ast) => {
|
|
2086
1985
|
const hocs = [];
|
|
2087
|
-
function getHocUid(
|
|
2088
|
-
const uid =
|
|
1986
|
+
function getHocUid(path7, hocName) {
|
|
1987
|
+
const uid = path7.scope.generateUidIdentifier(hocName);
|
|
2089
1988
|
hocs.push([hocName, uid]);
|
|
2090
1989
|
return uid;
|
|
2091
1990
|
}
|
|
2092
1991
|
traverse(ast, {
|
|
2093
|
-
ExportDeclaration(
|
|
2094
|
-
if (
|
|
2095
|
-
const declaration =
|
|
1992
|
+
ExportDeclaration(path7) {
|
|
1993
|
+
if (path7.isExportDefaultDeclaration()) {
|
|
1994
|
+
const declaration = path7.get("declaration");
|
|
2096
1995
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2097
1996
|
if (expr) {
|
|
2098
|
-
const uid = getHocUid(
|
|
1997
|
+
const uid = getHocUid(path7, "withComponentProps");
|
|
2099
1998
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2100
1999
|
}
|
|
2101
2000
|
return;
|
|
2102
2001
|
}
|
|
2103
|
-
if (
|
|
2104
|
-
const decl =
|
|
2002
|
+
if (path7.isExportNamedDeclaration()) {
|
|
2003
|
+
const decl = path7.get("declaration");
|
|
2105
2004
|
if (decl.isVariableDeclaration()) {
|
|
2106
2005
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2107
2006
|
const id = varDeclarator.get("id");
|
|
@@ -2111,7 +2010,7 @@ var transform = (ast) => {
|
|
|
2111
2010
|
if (!id.isIdentifier()) return;
|
|
2112
2011
|
const { name } = id.node;
|
|
2113
2012
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
2114
|
-
const uid = getHocUid(
|
|
2013
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
2115
2014
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2116
2015
|
});
|
|
2117
2016
|
return;
|
|
@@ -2121,7 +2020,7 @@ var transform = (ast) => {
|
|
|
2121
2020
|
if (!id) return;
|
|
2122
2021
|
const { name } = id;
|
|
2123
2022
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
2124
|
-
const uid = getHocUid(
|
|
2023
|
+
const uid = getHocUid(path7, `with${name}Props`);
|
|
2125
2024
|
decl.replaceWith(
|
|
2126
2025
|
t.variableDeclaration("const", [
|
|
2127
2026
|
t.variableDeclarator(
|
|
@@ -2186,6 +2085,7 @@ var SSR_BUNDLE_PREFIX = "ssrBundle_";
|
|
|
2186
2085
|
function isSsrBundleEnvironmentName(name) {
|
|
2187
2086
|
return name.startsWith(SSR_BUNDLE_PREFIX);
|
|
2188
2087
|
}
|
|
2088
|
+
var CSS_DEV_HELPER_ENVIRONMENT_NAME = "__react_router_css_dev_helper__";
|
|
2189
2089
|
function getServerEnvironmentEntries(ctx, record) {
|
|
2190
2090
|
return Object.entries(record).filter(
|
|
2191
2091
|
([name]) => ctx.buildManifest?.serverBundles ? isSsrBundleEnvironmentName(name) : name === "ssr"
|
|
@@ -2221,14 +2121,14 @@ var virtualHmrRuntime = create("hmr-runtime");
|
|
|
2221
2121
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
2222
2122
|
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
2223
2123
|
let vite2 = getVite();
|
|
2224
|
-
let fullPath =
|
|
2225
|
-
let relativePath =
|
|
2124
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
2125
|
+
let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
|
|
2226
2126
|
return vite2.normalizePath(relativePath).split("?")[0];
|
|
2227
2127
|
};
|
|
2228
2128
|
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
2229
2129
|
let vite2 = getVite();
|
|
2230
2130
|
let file = route.file;
|
|
2231
|
-
let fullPath =
|
|
2131
|
+
let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
|
|
2232
2132
|
return vite2.normalizePath(fullPath);
|
|
2233
2133
|
};
|
|
2234
2134
|
var virtual2 = {
|
|
@@ -2251,7 +2151,7 @@ var getHash = (source, maxLength) => {
|
|
|
2251
2151
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
2252
2152
|
let vite2 = getVite();
|
|
2253
2153
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
2254
|
-
|
|
2154
|
+
path6.relative(ctx.rootDirectory, absoluteFilePath)
|
|
2255
2155
|
);
|
|
2256
2156
|
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
2257
2157
|
if (!entryChunk) {
|
|
@@ -2315,7 +2215,7 @@ function dedupe(array2) {
|
|
|
2315
2215
|
return [...new Set(array2)];
|
|
2316
2216
|
}
|
|
2317
2217
|
var writeFileSafe = async (file, contents) => {
|
|
2318
|
-
await fse.ensureDir(
|
|
2218
|
+
await fse.ensureDir(path6.dirname(file));
|
|
2319
2219
|
await fse.writeFile(file, contents);
|
|
2320
2220
|
};
|
|
2321
2221
|
var getExportNames = (code) => {
|
|
@@ -2341,7 +2241,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2341
2241
|
}
|
|
2342
2242
|
let ssr = true;
|
|
2343
2243
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
2344
|
-
let routePath =
|
|
2244
|
+
let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2345
2245
|
let url2 = resolveFileUrl(ctx, routePath);
|
|
2346
2246
|
let resolveId = async () => {
|
|
2347
2247
|
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
@@ -2383,12 +2283,12 @@ var resolveEnvironmentBuildContext = ({
|
|
|
2383
2283
|
};
|
|
2384
2284
|
return resolvedBuildContext;
|
|
2385
2285
|
};
|
|
2386
|
-
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) =>
|
|
2286
|
+
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
|
|
2387
2287
|
reactRouterConfig.buildDirectory,
|
|
2388
2288
|
"server",
|
|
2389
2289
|
...serverBundleId ? [serverBundleId] : []
|
|
2390
2290
|
);
|
|
2391
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
2291
|
+
var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
|
|
2392
2292
|
var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
2393
2293
|
if (!ctx.buildManifest) {
|
|
2394
2294
|
return void 0;
|
|
@@ -2406,13 +2306,14 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
|
2406
2306
|
);
|
|
2407
2307
|
return Object.keys(serverBundleRoutes);
|
|
2408
2308
|
};
|
|
2409
|
-
var
|
|
2410
|
-
|
|
2309
|
+
var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
|
|
2310
|
+
var defaultEntriesDir = path6.resolve(
|
|
2311
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
2411
2312
|
"dist",
|
|
2412
2313
|
"config",
|
|
2413
2314
|
"defaults"
|
|
2414
2315
|
);
|
|
2415
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) =>
|
|
2316
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
|
|
2416
2317
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2417
2318
|
var reactRouterDevLoadContext = () => void 0;
|
|
2418
2319
|
var reactRouterVitePlugin = () => {
|
|
@@ -2511,7 +2412,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2511
2412
|
virtual2.serverManifest.id
|
|
2512
2413
|
)};
|
|
2513
2414
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2514
|
-
|
|
2415
|
+
path6.relative(
|
|
2515
2416
|
ctx.rootDirectory,
|
|
2516
2417
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
2517
2418
|
)
|
|
@@ -2550,7 +2451,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2550
2451
|
};
|
|
2551
2452
|
let loadViteManifest = async (directory) => {
|
|
2552
2453
|
let manifestContents = await fse.readFile(
|
|
2553
|
-
|
|
2454
|
+
path6.resolve(directory, ".vite", "manifest.json"),
|
|
2554
2455
|
"utf-8"
|
|
2555
2456
|
);
|
|
2556
2457
|
return JSON.parse(manifestContents);
|
|
@@ -2581,7 +2482,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2581
2482
|
let contents;
|
|
2582
2483
|
try {
|
|
2583
2484
|
contents = await fse.readFile(
|
|
2584
|
-
|
|
2485
|
+
path6.join(entry.path, entry.name),
|
|
2585
2486
|
"utf-8"
|
|
2586
2487
|
);
|
|
2587
2488
|
} catch (e) {
|
|
@@ -2590,7 +2491,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2590
2491
|
}
|
|
2591
2492
|
let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
|
|
2592
2493
|
let filepath = getVite().normalizePath(
|
|
2593
|
-
|
|
2494
|
+
path6.relative(clientBuildDirectory, path6.join(entry.path, entry.name))
|
|
2594
2495
|
);
|
|
2595
2496
|
sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
|
|
2596
2497
|
}
|
|
@@ -2617,7 +2518,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2617
2518
|
);
|
|
2618
2519
|
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2619
2520
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2620
|
-
let routeFile =
|
|
2521
|
+
let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2621
2522
|
let sourceExports = routeManifestExports[route.id];
|
|
2622
2523
|
let isRootRoute = route.parentId === void 0;
|
|
2623
2524
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
@@ -2693,7 +2594,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2693
2594
|
}
|
|
2694
2595
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
2695
2596
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
2696
|
-
let manifestPath =
|
|
2597
|
+
let manifestPath = path6.posix.join(
|
|
2697
2598
|
viteConfig.build.assetsDir,
|
|
2698
2599
|
`manifest-${version}.js`
|
|
2699
2600
|
);
|
|
@@ -2705,7 +2606,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2705
2606
|
sri: void 0
|
|
2706
2607
|
};
|
|
2707
2608
|
await writeFileSafe(
|
|
2708
|
-
|
|
2609
|
+
path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
2709
2610
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
2710
2611
|
reactRouterBrowserManifest
|
|
2711
2612
|
)};`
|
|
@@ -2815,17 +2716,31 @@ var reactRouterVitePlugin = () => {
|
|
|
2815
2716
|
if (dep.file && isCssModulesFile(dep.file)) {
|
|
2816
2717
|
return cssModulesManifest[dep.file];
|
|
2817
2718
|
}
|
|
2818
|
-
|
|
2719
|
+
const vite2 = getVite();
|
|
2720
|
+
const viteMajor = parseInt(vite2.version.split(".")[0], 10);
|
|
2721
|
+
const url2 = viteMajor >= 6 ? (
|
|
2722
|
+
// We need the ?inline query in Vite v6 when loading CSS in SSR
|
|
2723
|
+
// since it does not expose the default export for CSS in a
|
|
2724
|
+
// server environment. This is to align with non-SSR
|
|
2725
|
+
// environments. For backwards compatibility with v5 we keep
|
|
2726
|
+
// using the URL without ?inline query because the HMR code was
|
|
2727
|
+
// relying on the implicit SSR-client module graph relationship.
|
|
2728
|
+
injectQuery(dep.url, "inline")
|
|
2729
|
+
) : dep.url;
|
|
2730
|
+
let cssMod;
|
|
2731
|
+
if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi) {
|
|
2732
|
+
const cssDevHelperEnvironment = viteDevServer.environments[CSS_DEV_HELPER_ENVIRONMENT_NAME];
|
|
2733
|
+
invariant(cssDevHelperEnvironment, "Missing CSS dev helper environment");
|
|
2734
|
+
invariant(vite2.isRunnableDevEnvironment(cssDevHelperEnvironment));
|
|
2735
|
+
cssMod = await cssDevHelperEnvironment.runner.import(url2);
|
|
2736
|
+
} else {
|
|
2737
|
+
cssMod = await viteDevServer.ssrLoadModule(url2);
|
|
2738
|
+
}
|
|
2819
2739
|
invariant(
|
|
2820
|
-
|
|
2740
|
+
typeof cssMod === "object" && cssMod !== null && "default" in cssMod && typeof cssMod.default === "string",
|
|
2821
2741
|
`Failed to load CSS for ${dep.file ?? dep.url}`
|
|
2822
2742
|
);
|
|
2823
|
-
|
|
2824
|
-
invariant(
|
|
2825
|
-
typeof cssString === "string",
|
|
2826
|
-
`Failed to extract CSS for ${dep.file ?? dep.url}`
|
|
2827
|
-
);
|
|
2828
|
-
return cssString;
|
|
2743
|
+
return cssMod.default;
|
|
2829
2744
|
};
|
|
2830
2745
|
return [
|
|
2831
2746
|
{
|
|
@@ -3111,8 +3026,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3111
3026
|
reactRouterConfigLoader.onChange(
|
|
3112
3027
|
async ({
|
|
3113
3028
|
result,
|
|
3114
|
-
|
|
3115
|
-
routeConfigCodeChanged,
|
|
3029
|
+
configCodeUpdated,
|
|
3116
3030
|
configChanged,
|
|
3117
3031
|
routeConfigChanged
|
|
3118
3032
|
}) => {
|
|
@@ -3124,13 +3038,19 @@ var reactRouterVitePlugin = () => {
|
|
|
3124
3038
|
});
|
|
3125
3039
|
return;
|
|
3126
3040
|
}
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3041
|
+
if (routeConfigChanged) {
|
|
3042
|
+
logger.info(import_picocolors3.default.green("Route config changed."), {
|
|
3043
|
+
clear: true,
|
|
3044
|
+
timestamp: true
|
|
3045
|
+
});
|
|
3046
|
+
} else if (configCodeUpdated) {
|
|
3047
|
+
logger.info(import_picocolors3.default.green("Config updated."), {
|
|
3048
|
+
clear: true,
|
|
3049
|
+
timestamp: true
|
|
3050
|
+
});
|
|
3051
|
+
}
|
|
3132
3052
|
await updatePluginContext();
|
|
3133
|
-
if (configChanged
|
|
3053
|
+
if (configChanged) {
|
|
3134
3054
|
invalidateVirtualModules(viteDevServer);
|
|
3135
3055
|
}
|
|
3136
3056
|
}
|
|
@@ -3212,8 +3132,8 @@ var reactRouterVitePlugin = () => {
|
|
|
3212
3132
|
let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
|
|
3213
3133
|
let movedAssetPaths = [];
|
|
3214
3134
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
3215
|
-
let src =
|
|
3216
|
-
let dest =
|
|
3135
|
+
let src = path6.join(serverBuildDirectory, ssrAssetPath);
|
|
3136
|
+
let dest = path6.join(clientBuildDirectory, ssrAssetPath);
|
|
3217
3137
|
if (!fse.existsSync(dest)) {
|
|
3218
3138
|
await fse.move(src, dest);
|
|
3219
3139
|
movedAssetPaths.push(dest);
|
|
@@ -3226,7 +3146,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3226
3146
|
);
|
|
3227
3147
|
await Promise.all(
|
|
3228
3148
|
ssrCssPaths.map(
|
|
3229
|
-
(cssPath) => fse.remove(
|
|
3149
|
+
(cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
|
|
3230
3150
|
)
|
|
3231
3151
|
);
|
|
3232
3152
|
if (movedAssetPaths.length) {
|
|
@@ -3235,7 +3155,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3235
3155
|
"",
|
|
3236
3156
|
`${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
|
|
3237
3157
|
...movedAssetPaths.map(
|
|
3238
|
-
(movedAssetPath) => import_picocolors3.default.dim(
|
|
3158
|
+
(movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
|
|
3239
3159
|
),
|
|
3240
3160
|
""
|
|
3241
3161
|
].join("\n")
|
|
@@ -3314,7 +3234,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3314
3234
|
);
|
|
3315
3235
|
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
3316
3236
|
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
3317
|
-
let chunkBasePath = `./${
|
|
3237
|
+
let chunkBasePath = `./${path6.basename(id)}`;
|
|
3318
3238
|
return [
|
|
3319
3239
|
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
3320
3240
|
chunkBasePath,
|
|
@@ -3334,7 +3254,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3334
3254
|
async transform(code, id, options) {
|
|
3335
3255
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
3336
3256
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
3337
|
-
let routeFileName =
|
|
3257
|
+
let routeFileName = path6.basename(routeModuleId);
|
|
3338
3258
|
let sourceExports = await getRouteModuleExports(
|
|
3339
3259
|
viteChildCompiler,
|
|
3340
3260
|
ctx,
|
|
@@ -3461,7 +3381,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3461
3381
|
}
|
|
3462
3382
|
let vite2 = getVite();
|
|
3463
3383
|
let importerShort = vite2.normalizePath(
|
|
3464
|
-
|
|
3384
|
+
path6.relative(ctx.rootDirectory, importer)
|
|
3465
3385
|
);
|
|
3466
3386
|
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
3467
3387
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
@@ -3584,10 +3504,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3584
3504
|
},
|
|
3585
3505
|
async load(id) {
|
|
3586
3506
|
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
3587
|
-
let reactRefreshDir =
|
|
3507
|
+
let reactRefreshDir = path6.dirname(
|
|
3588
3508
|
require.resolve("react-refresh/package.json")
|
|
3589
3509
|
);
|
|
3590
|
-
let reactRefreshRuntimePath =
|
|
3510
|
+
let reactRefreshRuntimePath = path6.join(
|
|
3591
3511
|
reactRefreshDir,
|
|
3592
3512
|
"cjs/react-refresh-runtime.development.js"
|
|
3593
3513
|
);
|
|
@@ -3768,7 +3688,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
3768
3688
|
function getRoute(pluginConfig, file) {
|
|
3769
3689
|
let vite2 = getVite();
|
|
3770
3690
|
let routePath = vite2.normalizePath(
|
|
3771
|
-
|
|
3691
|
+
path6.relative(pluginConfig.appDirectory, file)
|
|
3772
3692
|
);
|
|
3773
3693
|
let route = Object.values(pluginConfig.routes).find(
|
|
3774
3694
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -3807,7 +3727,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
3807
3727
|
caseSensitive: route.caseSensitive,
|
|
3808
3728
|
url: combineURLs(
|
|
3809
3729
|
ctx.publicPath,
|
|
3810
|
-
"/" +
|
|
3730
|
+
"/" + path6.relative(
|
|
3811
3731
|
ctx.rootDirectory,
|
|
3812
3732
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
3813
3733
|
)
|
|
@@ -3835,7 +3755,7 @@ function isSpaModeEnabled(reactRouterConfig) {
|
|
|
3835
3755
|
return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
|
|
3836
3756
|
}
|
|
3837
3757
|
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
3838
|
-
let serverBuildPath =
|
|
3758
|
+
let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
|
|
3839
3759
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
3840
3760
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
3841
3761
|
return {
|
|
@@ -3877,9 +3797,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
3877
3797
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
3878
3798
|
);
|
|
3879
3799
|
}
|
|
3880
|
-
await fse.writeFile(
|
|
3881
|
-
let prettyDir =
|
|
3882
|
-
let prettyPath =
|
|
3800
|
+
await fse.writeFile(path6.join(clientBuildDirectory, filename3), html);
|
|
3801
|
+
let prettyDir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3802
|
+
let prettyPath = path6.join(prettyDir, filename3);
|
|
3883
3803
|
if (build.prerender.length > 0) {
|
|
3884
3804
|
viteConfig.logger.info(
|
|
3885
3805
|
`Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
|
|
@@ -3895,17 +3815,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3895
3815
|
serverBuildPath
|
|
3896
3816
|
);
|
|
3897
3817
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
3898
|
-
for (let
|
|
3899
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
3818
|
+
for (let path7 of build.prerender) {
|
|
3819
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
3900
3820
|
if (!matches) {
|
|
3901
3821
|
throw new Error(
|
|
3902
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
3822
|
+
`Unable to prerender path because it does not match any routes: ${path7}`
|
|
3903
3823
|
);
|
|
3904
3824
|
}
|
|
3905
3825
|
}
|
|
3906
3826
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
3907
|
-
for (let
|
|
3908
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
3827
|
+
for (let path7 of build.prerender) {
|
|
3828
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path7}/`.replace(/^\/\/+/, "/"));
|
|
3909
3829
|
if (!matches) {
|
|
3910
3830
|
continue;
|
|
3911
3831
|
}
|
|
@@ -3918,7 +3838,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3918
3838
|
if (manifestRoute.loader) {
|
|
3919
3839
|
await prerenderData(
|
|
3920
3840
|
handler,
|
|
3921
|
-
|
|
3841
|
+
path7,
|
|
3922
3842
|
[leafRoute.id],
|
|
3923
3843
|
clientBuildDirectory,
|
|
3924
3844
|
reactRouterConfig,
|
|
@@ -3926,7 +3846,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3926
3846
|
);
|
|
3927
3847
|
await prerenderResourceRoute(
|
|
3928
3848
|
handler,
|
|
3929
|
-
|
|
3849
|
+
path7,
|
|
3930
3850
|
clientBuildDirectory,
|
|
3931
3851
|
reactRouterConfig,
|
|
3932
3852
|
viteConfig
|
|
@@ -3944,7 +3864,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3944
3864
|
if (!isResourceRoute && hasLoaders) {
|
|
3945
3865
|
data = await prerenderData(
|
|
3946
3866
|
handler,
|
|
3947
|
-
|
|
3867
|
+
path7,
|
|
3948
3868
|
null,
|
|
3949
3869
|
clientBuildDirectory,
|
|
3950
3870
|
reactRouterConfig,
|
|
@@ -3953,7 +3873,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3953
3873
|
}
|
|
3954
3874
|
await prerenderRoute(
|
|
3955
3875
|
handler,
|
|
3956
|
-
|
|
3876
|
+
path7,
|
|
3957
3877
|
clientBuildDirectory,
|
|
3958
3878
|
reactRouterConfig,
|
|
3959
3879
|
viteConfig,
|
|
@@ -4006,9 +3926,9 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
|
|
|
4006
3926
|
${normalizedPath}`
|
|
4007
3927
|
);
|
|
4008
3928
|
}
|
|
4009
|
-
let outdir =
|
|
4010
|
-
let outfile =
|
|
4011
|
-
await fse.ensureDir(
|
|
3929
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3930
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
3931
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
4012
3932
|
await fse.outputFile(outfile, data);
|
|
4013
3933
|
viteConfig.logger.info(
|
|
4014
3934
|
`Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -4045,9 +3965,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
4045
3965
|
${html}`
|
|
4046
3966
|
);
|
|
4047
3967
|
}
|
|
4048
|
-
let outdir =
|
|
4049
|
-
let outfile =
|
|
4050
|
-
await fse.ensureDir(
|
|
3968
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3969
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
|
|
3970
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
4051
3971
|
await fse.outputFile(outfile, html);
|
|
4052
3972
|
viteConfig.logger.info(
|
|
4053
3973
|
`Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -4064,9 +3984,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
4064
3984
|
${content.toString("utf8")}`
|
|
4065
3985
|
);
|
|
4066
3986
|
}
|
|
4067
|
-
let outdir =
|
|
4068
|
-
let outfile =
|
|
4069
|
-
await fse.ensureDir(
|
|
3987
|
+
let outdir = path6.relative(process.cwd(), clientBuildDirectory);
|
|
3988
|
+
let outfile = path6.join(outdir, ...normalizedPath.split("/"));
|
|
3989
|
+
await fse.ensureDir(path6.dirname(outfile));
|
|
4070
3990
|
await fse.outputFile(outfile, content);
|
|
4071
3991
|
viteConfig.logger.info(
|
|
4072
3992
|
`Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -4142,14 +4062,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4142
4062
|
}
|
|
4143
4063
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4144
4064
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4145
|
-
for (let
|
|
4065
|
+
for (let path7 of prerenderPaths) {
|
|
4146
4066
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4147
4067
|
prerenderRoutes,
|
|
4148
|
-
`/${
|
|
4068
|
+
`/${path7}/`.replace(/^\/\/+/, "/")
|
|
4149
4069
|
);
|
|
4150
4070
|
invariant(
|
|
4151
4071
|
matches,
|
|
4152
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4072
|
+
`Unable to prerender path because it does not match any routes: ${path7}`
|
|
4153
4073
|
);
|
|
4154
4074
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4155
4075
|
}
|
|
@@ -4316,8 +4236,8 @@ function validateRouteChunks({
|
|
|
4316
4236
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
4317
4237
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
4318
4238
|
let isWithinRoot = () => {
|
|
4319
|
-
let relativePath =
|
|
4320
|
-
return !relativePath.startsWith("..") && !
|
|
4239
|
+
let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
|
|
4240
|
+
return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
|
|
4321
4241
|
};
|
|
4322
4242
|
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
4323
4243
|
await fse.remove(buildDirectory);
|
|
@@ -4328,7 +4248,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4328
4248
|
([environmentName, options]) => {
|
|
4329
4249
|
let outDir = options.build?.outDir;
|
|
4330
4250
|
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
4331
|
-
return
|
|
4251
|
+
return path6.join(outDir, ".vite/manifest.json");
|
|
4332
4252
|
}
|
|
4333
4253
|
);
|
|
4334
4254
|
await Promise.all(
|
|
@@ -4338,7 +4258,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4338
4258
|
if (!ctx.viteManifestEnabled) {
|
|
4339
4259
|
await fse.remove(viteManifestPath);
|
|
4340
4260
|
}
|
|
4341
|
-
let viteDir =
|
|
4261
|
+
let viteDir = path6.dirname(viteManifestPath);
|
|
4342
4262
|
let viteDirFiles = await fse.readdir(viteDir);
|
|
4343
4263
|
if (viteDirFiles.length === 0) {
|
|
4344
4264
|
await fse.remove(viteDir);
|
|
@@ -4356,12 +4276,12 @@ async function getBuildManifest({
|
|
|
4356
4276
|
}
|
|
4357
4277
|
let { normalizePath } = await import("vite");
|
|
4358
4278
|
let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
|
|
4359
|
-
let resolvedAppDirectory =
|
|
4279
|
+
let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
|
|
4360
4280
|
let rootRelativeRoutes = Object.fromEntries(
|
|
4361
4281
|
Object.entries(routes).map(([id, route]) => {
|
|
4362
|
-
let filePath =
|
|
4282
|
+
let filePath = path6.join(resolvedAppDirectory, route.file);
|
|
4363
4283
|
let rootRelativeFilePath = normalizePath(
|
|
4364
|
-
|
|
4284
|
+
path6.relative(rootDirectory, filePath)
|
|
4365
4285
|
);
|
|
4366
4286
|
return [id, { ...route, file: rootRelativeFilePath }];
|
|
4367
4287
|
})
|
|
@@ -4379,7 +4299,7 @@ async function getBuildManifest({
|
|
|
4379
4299
|
(route2) => configRouteToBranchRoute({
|
|
4380
4300
|
...route2,
|
|
4381
4301
|
// Ensure absolute paths are passed to the serverBundles function
|
|
4382
|
-
file:
|
|
4302
|
+
file: path6.join(resolvedAppDirectory, route2.file)
|
|
4383
4303
|
})
|
|
4384
4304
|
)
|
|
4385
4305
|
});
|
|
@@ -4403,10 +4323,10 @@ async function getBuildManifest({
|
|
|
4403
4323
|
buildManifest.serverBundles[serverBundleId] ??= {
|
|
4404
4324
|
id: serverBundleId,
|
|
4405
4325
|
file: normalizePath(
|
|
4406
|
-
|
|
4407
|
-
|
|
4326
|
+
path6.join(
|
|
4327
|
+
path6.relative(
|
|
4408
4328
|
rootDirectory,
|
|
4409
|
-
|
|
4329
|
+
path6.join(serverBuildDirectory, serverBundleId)
|
|
4410
4330
|
),
|
|
4411
4331
|
reactRouterConfig.serverBuildFile
|
|
4412
4332
|
)
|
|
@@ -4425,10 +4345,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
|
|
|
4425
4345
|
}
|
|
4426
4346
|
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
4427
4347
|
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
4428
|
-
let packageRoot =
|
|
4348
|
+
let packageRoot = path6.dirname(
|
|
4429
4349
|
require.resolve("@react-router/dev/package.json")
|
|
4430
4350
|
);
|
|
4431
|
-
let { moduleSyncEnabled } = await import(`file:///${
|
|
4351
|
+
let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
4432
4352
|
let vite2 = getVite();
|
|
4433
4353
|
let viteServerConditions = [
|
|
4434
4354
|
...vite2.defaultServerConditions ?? [],
|
|
@@ -4502,7 +4422,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4502
4422
|
ctx.entryClientFilePath,
|
|
4503
4423
|
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
4504
4424
|
(route) => {
|
|
4505
|
-
let routeFilePath =
|
|
4425
|
+
let routeFilePath = path6.resolve(
|
|
4506
4426
|
ctx.reactRouterConfig.appDirectory,
|
|
4507
4427
|
route.file
|
|
4508
4428
|
);
|
|
@@ -4526,7 +4446,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4526
4446
|
) : null;
|
|
4527
4447
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4528
4448
|
let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
4529
|
-
return
|
|
4449
|
+
return path6.posix.join(
|
|
4530
4450
|
assetsDir,
|
|
4531
4451
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4532
4452
|
);
|
|
@@ -4562,6 +4482,9 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4562
4482
|
}
|
|
4563
4483
|
});
|
|
4564
4484
|
}
|
|
4485
|
+
if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi && viteCommand === "serve") {
|
|
4486
|
+
environmentOptionsResolvers[CSS_DEV_HELPER_ENVIRONMENT_NAME] = () => ({});
|
|
4487
|
+
}
|
|
4565
4488
|
return environmentOptionsResolvers;
|
|
4566
4489
|
}
|
|
4567
4490
|
function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {
|