@react-router/dev 0.0.0-experimental-a25eed86d → 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 +239 -150
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +163 -80
- package/dist/vite.js +349 -270
- 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,7 +1279,7 @@ 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
|
]
|
|
@@ -1206,11 +1290,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1206
1290
|
let cssContent = void 0;
|
|
1207
1291
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1208
1292
|
traverse(ast, {
|
|
1209
|
-
VariableDeclaration(
|
|
1210
|
-
const declaration =
|
|
1293
|
+
VariableDeclaration(path6) {
|
|
1294
|
+
const declaration = path6.node.declarations[0];
|
|
1211
1295
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1212
1296
|
cssContent = declaration.init.value;
|
|
1213
|
-
|
|
1297
|
+
path6.stop();
|
|
1214
1298
|
}
|
|
1215
1299
|
}
|
|
1216
1300
|
});
|
|
@@ -1239,10 +1323,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1239
1323
|
let exportsFiltered = false;
|
|
1240
1324
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1241
1325
|
traverse(ast, {
|
|
1242
|
-
ExportDeclaration(
|
|
1243
|
-
if (
|
|
1244
|
-
if (
|
|
1245
|
-
|
|
1326
|
+
ExportDeclaration(path6) {
|
|
1327
|
+
if (path6.node.type === "ExportNamedDeclaration") {
|
|
1328
|
+
if (path6.node.specifiers.length) {
|
|
1329
|
+
path6.node.specifiers = path6.node.specifiers.filter((specifier) => {
|
|
1246
1330
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1247
1331
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1248
1332
|
exportsFiltered = true;
|
|
@@ -1251,12 +1335,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1251
1335
|
}
|
|
1252
1336
|
return true;
|
|
1253
1337
|
});
|
|
1254
|
-
if (
|
|
1255
|
-
markedForRemoval.add(
|
|
1338
|
+
if (path6.node.specifiers.length === 0) {
|
|
1339
|
+
markedForRemoval.add(path6);
|
|
1256
1340
|
}
|
|
1257
1341
|
}
|
|
1258
|
-
if (
|
|
1259
|
-
let declaration =
|
|
1342
|
+
if (path6.node.declaration?.type === "VariableDeclaration") {
|
|
1343
|
+
let declaration = path6.node.declaration;
|
|
1260
1344
|
declaration.declarations = declaration.declarations.filter(
|
|
1261
1345
|
(declaration2) => {
|
|
1262
1346
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1270,30 +1354,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1270
1354
|
}
|
|
1271
1355
|
);
|
|
1272
1356
|
if (declaration.declarations.length === 0) {
|
|
1273
|
-
markedForRemoval.add(
|
|
1357
|
+
markedForRemoval.add(path6);
|
|
1274
1358
|
}
|
|
1275
1359
|
}
|
|
1276
|
-
if (
|
|
1277
|
-
let id =
|
|
1360
|
+
if (path6.node.declaration?.type === "FunctionDeclaration") {
|
|
1361
|
+
let id = path6.node.declaration.id;
|
|
1278
1362
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1279
|
-
markedForRemoval.add(
|
|
1363
|
+
markedForRemoval.add(path6);
|
|
1280
1364
|
}
|
|
1281
1365
|
}
|
|
1282
|
-
if (
|
|
1283
|
-
let id =
|
|
1366
|
+
if (path6.node.declaration?.type === "ClassDeclaration") {
|
|
1367
|
+
let id = path6.node.declaration.id;
|
|
1284
1368
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1285
|
-
markedForRemoval.add(
|
|
1369
|
+
markedForRemoval.add(path6);
|
|
1286
1370
|
}
|
|
1287
1371
|
}
|
|
1288
1372
|
}
|
|
1289
|
-
if (
|
|
1290
|
-
markedForRemoval.add(
|
|
1373
|
+
if (path6.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
1374
|
+
markedForRemoval.add(path6);
|
|
1291
1375
|
}
|
|
1292
1376
|
}
|
|
1293
1377
|
});
|
|
1294
1378
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1295
|
-
for (let
|
|
1296
|
-
|
|
1379
|
+
for (let path6 of markedForRemoval) {
|
|
1380
|
+
path6.remove();
|
|
1297
1381
|
}
|
|
1298
1382
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1299
1383
|
}
|
|
@@ -1364,28 +1448,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1364
1448
|
)
|
|
1365
1449
|
);
|
|
1366
1450
|
}
|
|
1367
|
-
function assertNodePath(
|
|
1451
|
+
function assertNodePath(path6) {
|
|
1368
1452
|
invariant(
|
|
1369
|
-
|
|
1370
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1453
|
+
path6 && !Array.isArray(path6),
|
|
1454
|
+
`Expected a Path, but got ${Array.isArray(path6) ? "an array" : path6}`
|
|
1371
1455
|
);
|
|
1372
1456
|
}
|
|
1373
|
-
function assertNodePathIsStatement(
|
|
1457
|
+
function assertNodePathIsStatement(path6) {
|
|
1374
1458
|
invariant(
|
|
1375
|
-
|
|
1376
|
-
`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}`
|
|
1377
1461
|
);
|
|
1378
1462
|
}
|
|
1379
|
-
function assertNodePathIsVariableDeclarator(
|
|
1463
|
+
function assertNodePathIsVariableDeclarator(path6) {
|
|
1380
1464
|
invariant(
|
|
1381
|
-
|
|
1382
|
-
`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}`
|
|
1383
1467
|
);
|
|
1384
1468
|
}
|
|
1385
|
-
function assertNodePathIsPattern(
|
|
1469
|
+
function assertNodePathIsPattern(path6) {
|
|
1386
1470
|
invariant(
|
|
1387
|
-
|
|
1388
|
-
`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}`
|
|
1389
1473
|
);
|
|
1390
1474
|
}
|
|
1391
1475
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1421,8 +1505,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1421
1505
|
}
|
|
1422
1506
|
let isWithinExportDestructuring = Boolean(
|
|
1423
1507
|
identifier.findParent(
|
|
1424
|
-
(
|
|
1425
|
-
|
|
1508
|
+
(path6) => Boolean(
|
|
1509
|
+
path6.isPattern() && path6.parentPath?.isVariableDeclarator() && path6.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1426
1510
|
)
|
|
1427
1511
|
)
|
|
1428
1512
|
);
|
|
@@ -1500,7 +1584,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1500
1584
|
for (let specifier of node.specifiers) {
|
|
1501
1585
|
if (t.isIdentifier(specifier.exported)) {
|
|
1502
1586
|
let name = specifier.exported.name;
|
|
1503
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1587
|
+
let specifierPath = exportPath.get("specifiers").find((path6) => path6.node === specifier);
|
|
1504
1588
|
invariant(
|
|
1505
1589
|
specifierPath,
|
|
1506
1590
|
`Expected to find specifier path for ${name}`
|
|
@@ -1517,22 +1601,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1517
1601
|
}
|
|
1518
1602
|
);
|
|
1519
1603
|
}
|
|
1520
|
-
function getDependentIdentifiersForPath(
|
|
1604
|
+
function getDependentIdentifiersForPath(path6, state) {
|
|
1521
1605
|
let { visited, identifiers } = state ?? {
|
|
1522
1606
|
visited: /* @__PURE__ */ new Set(),
|
|
1523
1607
|
identifiers: /* @__PURE__ */ new Set()
|
|
1524
1608
|
};
|
|
1525
|
-
if (visited.has(
|
|
1609
|
+
if (visited.has(path6)) {
|
|
1526
1610
|
return identifiers;
|
|
1527
1611
|
}
|
|
1528
|
-
visited.add(
|
|
1529
|
-
|
|
1530
|
-
Identifier(
|
|
1531
|
-
if (identifiers.has(
|
|
1612
|
+
visited.add(path6);
|
|
1613
|
+
path6.traverse({
|
|
1614
|
+
Identifier(path7) {
|
|
1615
|
+
if (identifiers.has(path7)) {
|
|
1532
1616
|
return;
|
|
1533
1617
|
}
|
|
1534
|
-
identifiers.add(
|
|
1535
|
-
let binding =
|
|
1618
|
+
identifiers.add(path7);
|
|
1619
|
+
let binding = path7.scope.getBinding(path7.node.name);
|
|
1536
1620
|
if (!binding) {
|
|
1537
1621
|
return;
|
|
1538
1622
|
}
|
|
@@ -1554,7 +1638,7 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1554
1638
|
}
|
|
1555
1639
|
}
|
|
1556
1640
|
});
|
|
1557
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1641
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path6);
|
|
1558
1642
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1559
1643
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1560
1644
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1563,9 +1647,9 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1563
1647
|
identifiers
|
|
1564
1648
|
});
|
|
1565
1649
|
}
|
|
1566
|
-
if (withinExportStatement &&
|
|
1567
|
-
t.isPattern(
|
|
1568
|
-
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());
|
|
1569
1653
|
assertNodePath(variableDeclarator);
|
|
1570
1654
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1571
1655
|
visited,
|
|
@@ -1574,16 +1658,16 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1574
1658
|
}
|
|
1575
1659
|
return identifiers;
|
|
1576
1660
|
}
|
|
1577
|
-
function getTopLevelStatementPathForPath(
|
|
1578
|
-
let ancestry =
|
|
1661
|
+
function getTopLevelStatementPathForPath(path6) {
|
|
1662
|
+
let ancestry = path6.getAncestry();
|
|
1579
1663
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1580
1664
|
assertNodePathIsStatement(topLevelStatement);
|
|
1581
1665
|
return topLevelStatement;
|
|
1582
1666
|
}
|
|
1583
1667
|
function getTopLevelStatementsForPaths(paths) {
|
|
1584
1668
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1585
|
-
for (let
|
|
1586
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1669
|
+
for (let path6 of paths) {
|
|
1670
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path6);
|
|
1587
1671
|
topLevelStatements.add(topLevelStatement.node);
|
|
1588
1672
|
}
|
|
1589
1673
|
return topLevelStatements;
|
|
@@ -2000,24 +2084,24 @@ var plugin = {
|
|
|
2000
2084
|
};
|
|
2001
2085
|
var transform = (ast) => {
|
|
2002
2086
|
const hocs = [];
|
|
2003
|
-
function getHocUid(
|
|
2004
|
-
const uid =
|
|
2087
|
+
function getHocUid(path6, hocName) {
|
|
2088
|
+
const uid = path6.scope.generateUidIdentifier(hocName);
|
|
2005
2089
|
hocs.push([hocName, uid]);
|
|
2006
2090
|
return uid;
|
|
2007
2091
|
}
|
|
2008
2092
|
traverse(ast, {
|
|
2009
|
-
ExportDeclaration(
|
|
2010
|
-
if (
|
|
2011
|
-
const declaration =
|
|
2093
|
+
ExportDeclaration(path6) {
|
|
2094
|
+
if (path6.isExportDefaultDeclaration()) {
|
|
2095
|
+
const declaration = path6.get("declaration");
|
|
2012
2096
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2013
2097
|
if (expr) {
|
|
2014
|
-
const uid = getHocUid(
|
|
2098
|
+
const uid = getHocUid(path6, "withComponentProps");
|
|
2015
2099
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2016
2100
|
}
|
|
2017
2101
|
return;
|
|
2018
2102
|
}
|
|
2019
|
-
if (
|
|
2020
|
-
const decl =
|
|
2103
|
+
if (path6.isExportNamedDeclaration()) {
|
|
2104
|
+
const decl = path6.get("declaration");
|
|
2021
2105
|
if (decl.isVariableDeclaration()) {
|
|
2022
2106
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2023
2107
|
const id = varDeclarator.get("id");
|
|
@@ -2027,7 +2111,7 @@ var transform = (ast) => {
|
|
|
2027
2111
|
if (!id.isIdentifier()) return;
|
|
2028
2112
|
const { name } = id.node;
|
|
2029
2113
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
2030
|
-
const uid = getHocUid(
|
|
2114
|
+
const uid = getHocUid(path6, `with${name}Props`);
|
|
2031
2115
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2032
2116
|
});
|
|
2033
2117
|
return;
|
|
@@ -2037,7 +2121,7 @@ var transform = (ast) => {
|
|
|
2037
2121
|
if (!id) return;
|
|
2038
2122
|
const { name } = id;
|
|
2039
2123
|
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
2040
|
-
const uid = getHocUid(
|
|
2124
|
+
const uid = getHocUid(path6, `with${name}Props`);
|
|
2041
2125
|
decl.replaceWith(
|
|
2042
2126
|
t.variableDeclaration("const", [
|
|
2043
2127
|
t.variableDeclarator(
|
|
@@ -2137,14 +2221,14 @@ var virtualHmrRuntime = create("hmr-runtime");
|
|
|
2137
2221
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
2138
2222
|
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
2139
2223
|
let vite2 = getVite();
|
|
2140
|
-
let fullPath =
|
|
2141
|
-
let relativePath =
|
|
2224
|
+
let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
|
|
2225
|
+
let relativePath = path5.relative(reactRouterConfig.appDirectory, fullPath);
|
|
2142
2226
|
return vite2.normalizePath(relativePath).split("?")[0];
|
|
2143
2227
|
};
|
|
2144
2228
|
var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
|
|
2145
2229
|
let vite2 = getVite();
|
|
2146
2230
|
let file = route.file;
|
|
2147
|
-
let fullPath =
|
|
2231
|
+
let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
|
|
2148
2232
|
return vite2.normalizePath(fullPath);
|
|
2149
2233
|
};
|
|
2150
2234
|
var virtual2 = {
|
|
@@ -2167,7 +2251,7 @@ var getHash = (source, maxLength) => {
|
|
|
2167
2251
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
2168
2252
|
let vite2 = getVite();
|
|
2169
2253
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
2170
|
-
|
|
2254
|
+
path5.relative(ctx.rootDirectory, absoluteFilePath)
|
|
2171
2255
|
);
|
|
2172
2256
|
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
2173
2257
|
if (!entryChunk) {
|
|
@@ -2231,7 +2315,7 @@ function dedupe(array2) {
|
|
|
2231
2315
|
return [...new Set(array2)];
|
|
2232
2316
|
}
|
|
2233
2317
|
var writeFileSafe = async (file, contents) => {
|
|
2234
|
-
await fse.ensureDir(
|
|
2318
|
+
await fse.ensureDir(path5.dirname(file));
|
|
2235
2319
|
await fse.writeFile(file, contents);
|
|
2236
2320
|
};
|
|
2237
2321
|
var getExportNames = (code) => {
|
|
@@ -2257,7 +2341,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2257
2341
|
}
|
|
2258
2342
|
let ssr = true;
|
|
2259
2343
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
2260
|
-
let routePath =
|
|
2344
|
+
let routePath = path5.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2261
2345
|
let url2 = resolveFileUrl(ctx, routePath);
|
|
2262
2346
|
let resolveId = async () => {
|
|
2263
2347
|
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
@@ -2299,12 +2383,12 @@ var resolveEnvironmentBuildContext = ({
|
|
|
2299
2383
|
};
|
|
2300
2384
|
return resolvedBuildContext;
|
|
2301
2385
|
};
|
|
2302
|
-
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) =>
|
|
2386
|
+
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path5.join(
|
|
2303
2387
|
reactRouterConfig.buildDirectory,
|
|
2304
2388
|
"server",
|
|
2305
2389
|
...serverBundleId ? [serverBundleId] : []
|
|
2306
2390
|
);
|
|
2307
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
2391
|
+
var getClientBuildDirectory = (reactRouterConfig) => path5.join(reactRouterConfig.buildDirectory, "client");
|
|
2308
2392
|
var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
2309
2393
|
if (!ctx.buildManifest) {
|
|
2310
2394
|
return void 0;
|
|
@@ -2322,13 +2406,13 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
|
2322
2406
|
);
|
|
2323
2407
|
return Object.keys(serverBundleRoutes);
|
|
2324
2408
|
};
|
|
2325
|
-
var defaultEntriesDir =
|
|
2326
|
-
|
|
2409
|
+
var defaultEntriesDir = path5.resolve(
|
|
2410
|
+
path5.dirname(require.resolve("@react-router/dev/package.json")),
|
|
2327
2411
|
"dist",
|
|
2328
2412
|
"config",
|
|
2329
2413
|
"defaults"
|
|
2330
2414
|
);
|
|
2331
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) =>
|
|
2415
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path5.join(defaultEntriesDir, filename3));
|
|
2332
2416
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2333
2417
|
var reactRouterDevLoadContext = () => void 0;
|
|
2334
2418
|
var reactRouterVitePlugin = () => {
|
|
@@ -2427,7 +2511,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2427
2511
|
virtual2.serverManifest.id
|
|
2428
2512
|
)};
|
|
2429
2513
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2430
|
-
|
|
2514
|
+
path5.relative(
|
|
2431
2515
|
ctx.rootDirectory,
|
|
2432
2516
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
2433
2517
|
)
|
|
@@ -2466,7 +2550,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2466
2550
|
};
|
|
2467
2551
|
let loadViteManifest = async (directory) => {
|
|
2468
2552
|
let manifestContents = await fse.readFile(
|
|
2469
|
-
|
|
2553
|
+
path5.resolve(directory, ".vite", "manifest.json"),
|
|
2470
2554
|
"utf-8"
|
|
2471
2555
|
);
|
|
2472
2556
|
return JSON.parse(manifestContents);
|
|
@@ -2497,7 +2581,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2497
2581
|
let contents;
|
|
2498
2582
|
try {
|
|
2499
2583
|
contents = await fse.readFile(
|
|
2500
|
-
|
|
2584
|
+
path5.join(entry.path, entry.name),
|
|
2501
2585
|
"utf-8"
|
|
2502
2586
|
);
|
|
2503
2587
|
} catch (e) {
|
|
@@ -2506,7 +2590,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2506
2590
|
}
|
|
2507
2591
|
let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
|
|
2508
2592
|
let filepath = getVite().normalizePath(
|
|
2509
|
-
|
|
2593
|
+
path5.relative(clientBuildDirectory, path5.join(entry.path, entry.name))
|
|
2510
2594
|
);
|
|
2511
2595
|
sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
|
|
2512
2596
|
}
|
|
@@ -2533,7 +2617,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2533
2617
|
);
|
|
2534
2618
|
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2535
2619
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2536
|
-
let routeFile =
|
|
2620
|
+
let routeFile = path5.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2537
2621
|
let sourceExports = routeManifestExports[route.id];
|
|
2538
2622
|
let isRootRoute = route.parentId === void 0;
|
|
2539
2623
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
@@ -2609,7 +2693,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2609
2693
|
}
|
|
2610
2694
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
2611
2695
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
2612
|
-
let manifestPath =
|
|
2696
|
+
let manifestPath = path5.posix.join(
|
|
2613
2697
|
viteConfig.build.assetsDir,
|
|
2614
2698
|
`manifest-${version}.js`
|
|
2615
2699
|
);
|
|
@@ -2621,7 +2705,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2621
2705
|
sri: void 0
|
|
2622
2706
|
};
|
|
2623
2707
|
await writeFileSafe(
|
|
2624
|
-
|
|
2708
|
+
path5.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
2625
2709
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
2626
2710
|
reactRouterBrowserManifest
|
|
2627
2711
|
)};`
|
|
@@ -3027,7 +3111,8 @@ var reactRouterVitePlugin = () => {
|
|
|
3027
3111
|
reactRouterConfigLoader.onChange(
|
|
3028
3112
|
async ({
|
|
3029
3113
|
result,
|
|
3030
|
-
|
|
3114
|
+
configCodeChanged,
|
|
3115
|
+
routeConfigCodeChanged,
|
|
3031
3116
|
configChanged,
|
|
3032
3117
|
routeConfigChanged
|
|
3033
3118
|
}) => {
|
|
@@ -3039,19 +3124,13 @@ var reactRouterVitePlugin = () => {
|
|
|
3039
3124
|
});
|
|
3040
3125
|
return;
|
|
3041
3126
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
} else if (configCodeUpdated) {
|
|
3048
|
-
logger.info(import_picocolors3.default.green("Config updated."), {
|
|
3049
|
-
clear: true,
|
|
3050
|
-
timestamp: true
|
|
3051
|
-
});
|
|
3052
|
-
}
|
|
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
|
+
});
|
|
3053
3132
|
await updatePluginContext();
|
|
3054
|
-
if (configChanged) {
|
|
3133
|
+
if (configChanged || routeConfigChanged) {
|
|
3055
3134
|
invalidateVirtualModules(viteDevServer);
|
|
3056
3135
|
}
|
|
3057
3136
|
}
|
|
@@ -3133,8 +3212,8 @@ var reactRouterVitePlugin = () => {
|
|
|
3133
3212
|
let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
|
|
3134
3213
|
let movedAssetPaths = [];
|
|
3135
3214
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
3136
|
-
let src =
|
|
3137
|
-
let dest =
|
|
3215
|
+
let src = path5.join(serverBuildDirectory, ssrAssetPath);
|
|
3216
|
+
let dest = path5.join(clientBuildDirectory, ssrAssetPath);
|
|
3138
3217
|
if (!fse.existsSync(dest)) {
|
|
3139
3218
|
await fse.move(src, dest);
|
|
3140
3219
|
movedAssetPaths.push(dest);
|
|
@@ -3147,7 +3226,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3147
3226
|
);
|
|
3148
3227
|
await Promise.all(
|
|
3149
3228
|
ssrCssPaths.map(
|
|
3150
|
-
(cssPath) => fse.remove(
|
|
3229
|
+
(cssPath) => fse.remove(path5.join(serverBuildDirectory, cssPath))
|
|
3151
3230
|
)
|
|
3152
3231
|
);
|
|
3153
3232
|
if (movedAssetPaths.length) {
|
|
@@ -3156,7 +3235,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3156
3235
|
"",
|
|
3157
3236
|
`${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
|
|
3158
3237
|
...movedAssetPaths.map(
|
|
3159
|
-
(movedAssetPath) => import_picocolors3.default.dim(
|
|
3238
|
+
(movedAssetPath) => import_picocolors3.default.dim(path5.relative(ctx.rootDirectory, movedAssetPath))
|
|
3160
3239
|
),
|
|
3161
3240
|
""
|
|
3162
3241
|
].join("\n")
|
|
@@ -3235,7 +3314,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3235
3314
|
);
|
|
3236
3315
|
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
3237
3316
|
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
3238
|
-
let chunkBasePath = `./${
|
|
3317
|
+
let chunkBasePath = `./${path5.basename(id)}`;
|
|
3239
3318
|
return [
|
|
3240
3319
|
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
3241
3320
|
chunkBasePath,
|
|
@@ -3255,7 +3334,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3255
3334
|
async transform(code, id, options) {
|
|
3256
3335
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
3257
3336
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
3258
|
-
let routeFileName =
|
|
3337
|
+
let routeFileName = path5.basename(routeModuleId);
|
|
3259
3338
|
let sourceExports = await getRouteModuleExports(
|
|
3260
3339
|
viteChildCompiler,
|
|
3261
3340
|
ctx,
|
|
@@ -3382,7 +3461,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3382
3461
|
}
|
|
3383
3462
|
let vite2 = getVite();
|
|
3384
3463
|
let importerShort = vite2.normalizePath(
|
|
3385
|
-
|
|
3464
|
+
path5.relative(ctx.rootDirectory, importer)
|
|
3386
3465
|
);
|
|
3387
3466
|
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
3388
3467
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
@@ -3505,10 +3584,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3505
3584
|
},
|
|
3506
3585
|
async load(id) {
|
|
3507
3586
|
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
3508
|
-
let reactRefreshDir =
|
|
3587
|
+
let reactRefreshDir = path5.dirname(
|
|
3509
3588
|
require.resolve("react-refresh/package.json")
|
|
3510
3589
|
);
|
|
3511
|
-
let reactRefreshRuntimePath =
|
|
3590
|
+
let reactRefreshRuntimePath = path5.join(
|
|
3512
3591
|
reactRefreshDir,
|
|
3513
3592
|
"cjs/react-refresh-runtime.development.js"
|
|
3514
3593
|
);
|
|
@@ -3689,7 +3768,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
3689
3768
|
function getRoute(pluginConfig, file) {
|
|
3690
3769
|
let vite2 = getVite();
|
|
3691
3770
|
let routePath = vite2.normalizePath(
|
|
3692
|
-
|
|
3771
|
+
path5.relative(pluginConfig.appDirectory, file)
|
|
3693
3772
|
);
|
|
3694
3773
|
let route = Object.values(pluginConfig.routes).find(
|
|
3695
3774
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -3728,7 +3807,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
3728
3807
|
caseSensitive: route.caseSensitive,
|
|
3729
3808
|
url: combineURLs(
|
|
3730
3809
|
ctx.publicPath,
|
|
3731
|
-
"/" +
|
|
3810
|
+
"/" + path5.relative(
|
|
3732
3811
|
ctx.rootDirectory,
|
|
3733
3812
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
3734
3813
|
)
|
|
@@ -3756,7 +3835,7 @@ function isSpaModeEnabled(reactRouterConfig) {
|
|
|
3756
3835
|
return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
|
|
3757
3836
|
}
|
|
3758
3837
|
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
3759
|
-
let serverBuildPath =
|
|
3838
|
+
let serverBuildPath = path5.join(serverBuildDirectory, serverBuildFile);
|
|
3760
3839
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
3761
3840
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
3762
3841
|
return {
|
|
@@ -3798,9 +3877,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
3798
3877
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
3799
3878
|
);
|
|
3800
3879
|
}
|
|
3801
|
-
await fse.writeFile(
|
|
3802
|
-
let prettyDir =
|
|
3803
|
-
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);
|
|
3804
3883
|
if (build.prerender.length > 0) {
|
|
3805
3884
|
viteConfig.logger.info(
|
|
3806
3885
|
`Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
|
|
@@ -3816,17 +3895,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3816
3895
|
serverBuildPath
|
|
3817
3896
|
);
|
|
3818
3897
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
3819
|
-
for (let
|
|
3820
|
-
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(/^\/\/+/, "/"));
|
|
3821
3900
|
if (!matches) {
|
|
3822
3901
|
throw new Error(
|
|
3823
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
3902
|
+
`Unable to prerender path because it does not match any routes: ${path6}`
|
|
3824
3903
|
);
|
|
3825
3904
|
}
|
|
3826
3905
|
}
|
|
3827
3906
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
3828
|
-
for (let
|
|
3829
|
-
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(/^\/\/+/, "/"));
|
|
3830
3909
|
if (!matches) {
|
|
3831
3910
|
continue;
|
|
3832
3911
|
}
|
|
@@ -3839,7 +3918,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3839
3918
|
if (manifestRoute.loader) {
|
|
3840
3919
|
await prerenderData(
|
|
3841
3920
|
handler,
|
|
3842
|
-
|
|
3921
|
+
path6,
|
|
3843
3922
|
[leafRoute.id],
|
|
3844
3923
|
clientBuildDirectory,
|
|
3845
3924
|
reactRouterConfig,
|
|
@@ -3847,7 +3926,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3847
3926
|
);
|
|
3848
3927
|
await prerenderResourceRoute(
|
|
3849
3928
|
handler,
|
|
3850
|
-
|
|
3929
|
+
path6,
|
|
3851
3930
|
clientBuildDirectory,
|
|
3852
3931
|
reactRouterConfig,
|
|
3853
3932
|
viteConfig
|
|
@@ -3865,7 +3944,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3865
3944
|
if (!isResourceRoute && hasLoaders) {
|
|
3866
3945
|
data = await prerenderData(
|
|
3867
3946
|
handler,
|
|
3868
|
-
|
|
3947
|
+
path6,
|
|
3869
3948
|
null,
|
|
3870
3949
|
clientBuildDirectory,
|
|
3871
3950
|
reactRouterConfig,
|
|
@@ -3874,7 +3953,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
3874
3953
|
}
|
|
3875
3954
|
await prerenderRoute(
|
|
3876
3955
|
handler,
|
|
3877
|
-
|
|
3956
|
+
path6,
|
|
3878
3957
|
clientBuildDirectory,
|
|
3879
3958
|
reactRouterConfig,
|
|
3880
3959
|
viteConfig,
|
|
@@ -3927,9 +4006,9 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
|
|
|
3927
4006
|
${normalizedPath}`
|
|
3928
4007
|
);
|
|
3929
4008
|
}
|
|
3930
|
-
let outdir =
|
|
3931
|
-
let outfile =
|
|
3932
|
-
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));
|
|
3933
4012
|
await fse.outputFile(outfile, data);
|
|
3934
4013
|
viteConfig.logger.info(
|
|
3935
4014
|
`Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -3966,9 +4045,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
3966
4045
|
${html}`
|
|
3967
4046
|
);
|
|
3968
4047
|
}
|
|
3969
|
-
let outdir =
|
|
3970
|
-
let outfile =
|
|
3971
|
-
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));
|
|
3972
4051
|
await fse.outputFile(outfile, html);
|
|
3973
4052
|
viteConfig.logger.info(
|
|
3974
4053
|
`Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -3985,9 +4064,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
3985
4064
|
${content.toString("utf8")}`
|
|
3986
4065
|
);
|
|
3987
4066
|
}
|
|
3988
|
-
let outdir =
|
|
3989
|
-
let outfile =
|
|
3990
|
-
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));
|
|
3991
4070
|
await fse.outputFile(outfile, content);
|
|
3992
4071
|
viteConfig.logger.info(
|
|
3993
4072
|
`Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
|
|
@@ -4063,14 +4142,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4063
4142
|
}
|
|
4064
4143
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4065
4144
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4066
|
-
for (let
|
|
4145
|
+
for (let path6 of prerenderPaths) {
|
|
4067
4146
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4068
4147
|
prerenderRoutes,
|
|
4069
|
-
`/${
|
|
4148
|
+
`/${path6}/`.replace(/^\/\/+/, "/")
|
|
4070
4149
|
);
|
|
4071
4150
|
invariant(
|
|
4072
4151
|
matches,
|
|
4073
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4152
|
+
`Unable to prerender path because it does not match any routes: ${path6}`
|
|
4074
4153
|
);
|
|
4075
4154
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4076
4155
|
}
|
|
@@ -4237,8 +4316,8 @@ function validateRouteChunks({
|
|
|
4237
4316
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
4238
4317
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
4239
4318
|
let isWithinRoot = () => {
|
|
4240
|
-
let relativePath =
|
|
4241
|
-
return !relativePath.startsWith("..") && !
|
|
4319
|
+
let relativePath = path5.relative(ctx.rootDirectory, buildDirectory);
|
|
4320
|
+
return !relativePath.startsWith("..") && !path5.isAbsolute(relativePath);
|
|
4242
4321
|
};
|
|
4243
4322
|
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
4244
4323
|
await fse.remove(buildDirectory);
|
|
@@ -4249,7 +4328,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4249
4328
|
([environmentName, options]) => {
|
|
4250
4329
|
let outDir = options.build?.outDir;
|
|
4251
4330
|
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
4252
|
-
return
|
|
4331
|
+
return path5.join(outDir, ".vite/manifest.json");
|
|
4253
4332
|
}
|
|
4254
4333
|
);
|
|
4255
4334
|
await Promise.all(
|
|
@@ -4259,7 +4338,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4259
4338
|
if (!ctx.viteManifestEnabled) {
|
|
4260
4339
|
await fse.remove(viteManifestPath);
|
|
4261
4340
|
}
|
|
4262
|
-
let viteDir =
|
|
4341
|
+
let viteDir = path5.dirname(viteManifestPath);
|
|
4263
4342
|
let viteDirFiles = await fse.readdir(viteDir);
|
|
4264
4343
|
if (viteDirFiles.length === 0) {
|
|
4265
4344
|
await fse.remove(viteDir);
|
|
@@ -4277,12 +4356,12 @@ async function getBuildManifest({
|
|
|
4277
4356
|
}
|
|
4278
4357
|
let { normalizePath } = await import("vite");
|
|
4279
4358
|
let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
|
|
4280
|
-
let resolvedAppDirectory =
|
|
4359
|
+
let resolvedAppDirectory = path5.resolve(rootDirectory, appDirectory);
|
|
4281
4360
|
let rootRelativeRoutes = Object.fromEntries(
|
|
4282
4361
|
Object.entries(routes).map(([id, route]) => {
|
|
4283
|
-
let filePath =
|
|
4362
|
+
let filePath = path5.join(resolvedAppDirectory, route.file);
|
|
4284
4363
|
let rootRelativeFilePath = normalizePath(
|
|
4285
|
-
|
|
4364
|
+
path5.relative(rootDirectory, filePath)
|
|
4286
4365
|
);
|
|
4287
4366
|
return [id, { ...route, file: rootRelativeFilePath }];
|
|
4288
4367
|
})
|
|
@@ -4300,7 +4379,7 @@ async function getBuildManifest({
|
|
|
4300
4379
|
(route2) => configRouteToBranchRoute({
|
|
4301
4380
|
...route2,
|
|
4302
4381
|
// Ensure absolute paths are passed to the serverBundles function
|
|
4303
|
-
file:
|
|
4382
|
+
file: path5.join(resolvedAppDirectory, route2.file)
|
|
4304
4383
|
})
|
|
4305
4384
|
)
|
|
4306
4385
|
});
|
|
@@ -4324,10 +4403,10 @@ async function getBuildManifest({
|
|
|
4324
4403
|
buildManifest.serverBundles[serverBundleId] ??= {
|
|
4325
4404
|
id: serverBundleId,
|
|
4326
4405
|
file: normalizePath(
|
|
4327
|
-
|
|
4328
|
-
|
|
4406
|
+
path5.join(
|
|
4407
|
+
path5.relative(
|
|
4329
4408
|
rootDirectory,
|
|
4330
|
-
|
|
4409
|
+
path5.join(serverBuildDirectory, serverBundleId)
|
|
4331
4410
|
),
|
|
4332
4411
|
reactRouterConfig.serverBuildFile
|
|
4333
4412
|
)
|
|
@@ -4346,10 +4425,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
|
|
|
4346
4425
|
}
|
|
4347
4426
|
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
4348
4427
|
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
4349
|
-
let packageRoot =
|
|
4428
|
+
let packageRoot = path5.dirname(
|
|
4350
4429
|
require.resolve("@react-router/dev/package.json")
|
|
4351
4430
|
);
|
|
4352
|
-
let { moduleSyncEnabled } = await import(`file:///${
|
|
4431
|
+
let { moduleSyncEnabled } = await import(`file:///${path5.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
4353
4432
|
let vite2 = getVite();
|
|
4354
4433
|
let viteServerConditions = [
|
|
4355
4434
|
...vite2.defaultServerConditions ?? [],
|
|
@@ -4423,7 +4502,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4423
4502
|
ctx.entryClientFilePath,
|
|
4424
4503
|
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
4425
4504
|
(route) => {
|
|
4426
|
-
let routeFilePath =
|
|
4505
|
+
let routeFilePath = path5.resolve(
|
|
4427
4506
|
ctx.reactRouterConfig.appDirectory,
|
|
4428
4507
|
route.file
|
|
4429
4508
|
);
|
|
@@ -4447,7 +4526,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4447
4526
|
) : null;
|
|
4448
4527
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4449
4528
|
let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
4450
|
-
return
|
|
4529
|
+
return path5.posix.join(
|
|
4451
4530
|
assetsDir,
|
|
4452
4531
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4453
4532
|
);
|