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