@react-router/dev 0.0.0-experimental-818f8e08d → 0.0.0-experimental-aecfb0db1
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 +243 -154
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +163 -80
- package/dist/vite.js +371 -294
- package/package.json +6 -6
package/dist/config.js
CHANGED
package/dist/routes.js
CHANGED
package/dist/vite/cloudflare.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-aecfb0db1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -197,13 +197,15 @@ var ssrExternals = isReactRouterRepo() ? [
|
|
|
197
197
|
// vite/vite-node.ts
|
|
198
198
|
async function createContext({
|
|
199
199
|
root,
|
|
200
|
-
mode
|
|
200
|
+
mode,
|
|
201
|
+
customLogger
|
|
201
202
|
}) {
|
|
202
203
|
await preloadVite();
|
|
203
204
|
const vite2 = getVite();
|
|
204
205
|
const devServer = await vite2.createServer({
|
|
205
206
|
root,
|
|
206
207
|
mode,
|
|
208
|
+
customLogger,
|
|
207
209
|
server: {
|
|
208
210
|
preTransformRequests: false,
|
|
209
211
|
hmr: false,
|
|
@@ -301,7 +303,7 @@ function validateRouteConfig({
|
|
|
301
303
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
302
304
|
root ? `${root}` : [],
|
|
303
305
|
nested ? Object.entries(nested).map(
|
|
304
|
-
([
|
|
306
|
+
([path3, message]) => `Path: routes.${path3}
|
|
305
307
|
${message}`
|
|
306
308
|
) : []
|
|
307
309
|
].flat().join("\n\n")
|
|
@@ -394,7 +396,8 @@ function err(error) {
|
|
|
394
396
|
async function resolveConfig({
|
|
395
397
|
root,
|
|
396
398
|
viteNodeContext,
|
|
397
|
-
reactRouterConfigFile
|
|
399
|
+
reactRouterConfigFile,
|
|
400
|
+
skipRoutes
|
|
398
401
|
}) {
|
|
399
402
|
let reactRouterUserConfig = {};
|
|
400
403
|
if (reactRouterConfigFile) {
|
|
@@ -510,45 +513,50 @@ async function resolveConfig({
|
|
|
510
513
|
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
511
514
|
);
|
|
512
515
|
}
|
|
513
|
-
let routes = {
|
|
514
|
-
|
|
515
|
-
};
|
|
516
|
-
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
517
|
-
try {
|
|
518
|
-
if (!routeConfigFile) {
|
|
519
|
-
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
520
|
-
root,
|
|
521
|
-
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
522
|
-
);
|
|
523
|
-
return err(`Route config file not found at "${routeConfigDisplayPath}".`);
|
|
524
|
-
}
|
|
525
|
-
setAppDirectory(appDirectory);
|
|
526
|
-
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
527
|
-
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
528
|
-
)).default;
|
|
529
|
-
let routeConfig = await routeConfigExport;
|
|
530
|
-
let result = validateRouteConfig({
|
|
531
|
-
routeConfigFile,
|
|
532
|
-
routeConfig
|
|
533
|
-
});
|
|
534
|
-
if (!result.valid) {
|
|
535
|
-
return err(result.message);
|
|
536
|
-
}
|
|
516
|
+
let routes = {};
|
|
517
|
+
if (!skipRoutes) {
|
|
537
518
|
routes = {
|
|
538
|
-
|
|
539
|
-
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
519
|
+
root: { path: "", id: "root", file: rootRouteFile }
|
|
540
520
|
};
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
521
|
+
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
522
|
+
try {
|
|
523
|
+
if (!routeConfigFile) {
|
|
524
|
+
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
525
|
+
root,
|
|
526
|
+
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
527
|
+
);
|
|
528
|
+
return err(
|
|
529
|
+
`Route config file not found at "${routeConfigDisplayPath}".`
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
setAppDirectory(appDirectory);
|
|
533
|
+
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
534
|
+
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
535
|
+
)).default;
|
|
536
|
+
let routeConfig = await routeConfigExport;
|
|
537
|
+
let result = validateRouteConfig({
|
|
538
|
+
routeConfigFile,
|
|
539
|
+
routeConfig
|
|
540
|
+
});
|
|
541
|
+
if (!result.valid) {
|
|
542
|
+
return err(result.message);
|
|
543
|
+
}
|
|
544
|
+
routes = {
|
|
545
|
+
...routes,
|
|
546
|
+
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
547
|
+
};
|
|
548
|
+
} catch (error) {
|
|
549
|
+
return err(
|
|
550
|
+
[
|
|
551
|
+
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
552
|
+
"",
|
|
553
|
+
error.loc?.file && error.loc?.column && error.frame ? [
|
|
554
|
+
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
555
|
+
error.frame.trim?.()
|
|
556
|
+
] : error.stack
|
|
557
|
+
].flat().join("\n")
|
|
558
|
+
);
|
|
559
|
+
}
|
|
552
560
|
}
|
|
553
561
|
let future = {
|
|
554
562
|
unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
|
|
@@ -579,24 +587,34 @@ async function resolveConfig({
|
|
|
579
587
|
async function createConfigLoader({
|
|
580
588
|
rootDirectory: root,
|
|
581
589
|
watch,
|
|
582
|
-
mode
|
|
590
|
+
mode,
|
|
591
|
+
skipRoutes
|
|
583
592
|
}) {
|
|
584
|
-
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
593
|
+
root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
|
|
594
|
+
let vite2 = await import("vite");
|
|
585
595
|
let viteNodeContext = await createContext({
|
|
586
596
|
root,
|
|
587
|
-
mode
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
597
|
+
mode,
|
|
598
|
+
// Filter out any info level logs from vite-node
|
|
599
|
+
customLogger: vite2.createLogger("warn", {
|
|
600
|
+
prefix: "[react-router]"
|
|
601
|
+
})
|
|
591
602
|
});
|
|
592
|
-
let
|
|
603
|
+
let reactRouterConfigFile;
|
|
604
|
+
let updateReactRouterConfigFile = () => {
|
|
605
|
+
reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
606
|
+
absolute: true
|
|
607
|
+
});
|
|
608
|
+
};
|
|
609
|
+
updateReactRouterConfigFile();
|
|
610
|
+
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
|
|
593
611
|
let appDirectory;
|
|
594
612
|
let initialConfigResult = await getConfig();
|
|
595
613
|
if (!initialConfigResult.ok) {
|
|
596
614
|
throw new Error(initialConfigResult.error);
|
|
597
615
|
}
|
|
598
|
-
appDirectory = initialConfigResult.value.appDirectory;
|
|
599
|
-
let
|
|
616
|
+
appDirectory = import_pathe3.default.normalize(initialConfigResult.value.appDirectory);
|
|
617
|
+
let currentConfig = initialConfigResult.value;
|
|
600
618
|
let fsWatcher;
|
|
601
619
|
let changeHandlers = [];
|
|
602
620
|
return {
|
|
@@ -609,41 +627,71 @@ async function createConfigLoader({
|
|
|
609
627
|
}
|
|
610
628
|
changeHandlers.push(handler);
|
|
611
629
|
if (!fsWatcher) {
|
|
612
|
-
fsWatcher = import_chokidar.default.watch(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
630
|
+
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
631
|
+
ignoreInitial: true,
|
|
632
|
+
ignored: (path3) => {
|
|
633
|
+
let dirname = import_pathe3.default.dirname(path3);
|
|
634
|
+
return !dirname.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
635
|
+
// that are at the root level, not nested in subdirectories
|
|
636
|
+
path3 !== root && // Watch the root directory itself
|
|
637
|
+
dirname !== root;
|
|
638
|
+
}
|
|
639
|
+
});
|
|
619
640
|
fsWatcher.on("all", async (...args) => {
|
|
620
641
|
let [event, rawFilepath] = args;
|
|
621
642
|
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
622
|
-
let
|
|
623
|
-
let
|
|
643
|
+
let fileAddedOrRemoved = event === "add" || event === "unlink";
|
|
644
|
+
let appFileAddedOrRemoved = fileAddedOrRemoved && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
645
|
+
let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
|
|
646
|
+
let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
|
|
647
|
+
if (configFileAddedOrRemoved) {
|
|
648
|
+
updateReactRouterConfigFile();
|
|
649
|
+
}
|
|
650
|
+
let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
|
|
624
651
|
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
625
652
|
);
|
|
626
|
-
if (
|
|
627
|
-
|
|
628
|
-
viteNodeContext.runner?.moduleCache.clear();
|
|
653
|
+
if (!moduleGraphChanged && !appFileAddedOrRemoved) {
|
|
654
|
+
return;
|
|
629
655
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
656
|
+
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
657
|
+
viteNodeContext.runner?.moduleCache.clear();
|
|
658
|
+
let result = await getConfig();
|
|
659
|
+
let prevAppDirectory = appDirectory;
|
|
660
|
+
appDirectory = import_pathe3.default.normalize(
|
|
661
|
+
(result.value ?? currentConfig).appDirectory
|
|
662
|
+
);
|
|
663
|
+
if (appDirectory !== prevAppDirectory) {
|
|
664
|
+
fsWatcher.unwatch(prevAppDirectory);
|
|
665
|
+
fsWatcher.add(appDirectory);
|
|
666
|
+
}
|
|
667
|
+
let configCodeChanged = configFileAddedOrRemoved || reactRouterConfigFile !== void 0 && isEntryFileDependency(
|
|
668
|
+
viteNodeContext.devServer.moduleGraph,
|
|
669
|
+
reactRouterConfigFile,
|
|
670
|
+
filepath
|
|
671
|
+
);
|
|
672
|
+
let routeConfigFile = !skipRoutes ? findEntry(appDirectory, "routes", {
|
|
673
|
+
absolute: true
|
|
674
|
+
}) : void 0;
|
|
675
|
+
let routeConfigCodeChanged = routeConfigFile !== void 0 && isEntryFileDependency(
|
|
676
|
+
viteNodeContext.devServer.moduleGraph,
|
|
677
|
+
routeConfigFile,
|
|
678
|
+
filepath
|
|
679
|
+
);
|
|
680
|
+
let configChanged = result.ok && !(0, import_isEqual.default)(omitRoutes(currentConfig), omitRoutes(result.value));
|
|
681
|
+
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(currentConfig?.routes, result.value.routes);
|
|
682
|
+
for (let handler2 of changeHandlers) {
|
|
683
|
+
handler2({
|
|
684
|
+
result,
|
|
685
|
+
configCodeChanged,
|
|
686
|
+
routeConfigCodeChanged,
|
|
687
|
+
configChanged,
|
|
688
|
+
routeConfigChanged,
|
|
689
|
+
path: filepath,
|
|
690
|
+
event
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
if (result.ok) {
|
|
694
|
+
currentConfig = result.value;
|
|
647
695
|
}
|
|
648
696
|
});
|
|
649
697
|
}
|
|
@@ -662,18 +710,29 @@ async function createConfigLoader({
|
|
|
662
710
|
}
|
|
663
711
|
async function loadConfig({
|
|
664
712
|
rootDirectory,
|
|
665
|
-
mode
|
|
713
|
+
mode,
|
|
714
|
+
skipRoutes
|
|
666
715
|
}) {
|
|
667
716
|
let configLoader = await createConfigLoader({
|
|
668
717
|
rootDirectory,
|
|
669
718
|
mode,
|
|
719
|
+
skipRoutes,
|
|
670
720
|
watch: false
|
|
671
721
|
});
|
|
672
722
|
let config = await configLoader.getConfig();
|
|
673
723
|
await configLoader.close();
|
|
674
724
|
return config;
|
|
675
725
|
}
|
|
726
|
+
function omitRoutes(config) {
|
|
727
|
+
return {
|
|
728
|
+
...config,
|
|
729
|
+
routes: {}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
676
732
|
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
733
|
+
function isEntryFile(entryBasename, filename) {
|
|
734
|
+
return entryExts.some((ext) => filename === `${entryBasename}${ext}`);
|
|
735
|
+
}
|
|
677
736
|
function findEntry(dir, basename, options) {
|
|
678
737
|
let currentDir = import_pathe3.default.resolve(dir);
|
|
679
738
|
let { root } = import_pathe3.default.parse(currentDir);
|
|
@@ -694,6 +753,30 @@ function findEntry(dir, basename, options) {
|
|
|
694
753
|
currentDir = parentDir;
|
|
695
754
|
}
|
|
696
755
|
}
|
|
756
|
+
function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
|
|
757
|
+
entryFilepath = import_pathe3.default.normalize(entryFilepath);
|
|
758
|
+
filepath = import_pathe3.default.normalize(filepath);
|
|
759
|
+
if (visited.has(filepath)) {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
visited.add(filepath);
|
|
763
|
+
if (filepath === entryFilepath) {
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
let mod = moduleGraph.getModuleById(filepath);
|
|
767
|
+
if (!mod) {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
for (let importer of mod.importers) {
|
|
771
|
+
if (!importer.id) {
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
|
|
775
|
+
return true;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
697
780
|
|
|
698
781
|
// vite/cloudflare-dev-proxy.ts
|
|
699
782
|
var serverBuildId = "virtual:react-router/server-build";
|