@react-router/dev 0.0.0-experimental-ab0e85b04 → 0.0.0-experimental-818f8e08d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +154 -243
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +80 -163
- package/dist/vite.js +294 -371
- package/package.json +6 -6
package/dist/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-818f8e08d
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -197,15 +197,13 @@ var ssrExternals = isReactRouterRepo() ? [
|
|
|
197
197
|
// vite/vite-node.ts
|
|
198
198
|
async function createContext({
|
|
199
199
|
root,
|
|
200
|
-
mode
|
|
201
|
-
customLogger
|
|
200
|
+
mode
|
|
202
201
|
}) {
|
|
203
202
|
await preloadVite();
|
|
204
203
|
const vite2 = getVite();
|
|
205
204
|
const devServer = await vite2.createServer({
|
|
206
205
|
root,
|
|
207
206
|
mode,
|
|
208
|
-
customLogger,
|
|
209
207
|
server: {
|
|
210
208
|
preTransformRequests: false,
|
|
211
209
|
hmr: false,
|
|
@@ -303,7 +301,7 @@ function validateRouteConfig({
|
|
|
303
301
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
304
302
|
root ? `${root}` : [],
|
|
305
303
|
nested ? Object.entries(nested).map(
|
|
306
|
-
([
|
|
304
|
+
([path4, message]) => `Path: routes.${path4}
|
|
307
305
|
${message}`
|
|
308
306
|
) : []
|
|
309
307
|
].flat().join("\n\n")
|
|
@@ -396,8 +394,7 @@ function err(error) {
|
|
|
396
394
|
async function resolveConfig({
|
|
397
395
|
root,
|
|
398
396
|
viteNodeContext,
|
|
399
|
-
reactRouterConfigFile
|
|
400
|
-
skipRoutes
|
|
397
|
+
reactRouterConfigFile
|
|
401
398
|
}) {
|
|
402
399
|
let reactRouterUserConfig = {};
|
|
403
400
|
if (reactRouterConfigFile) {
|
|
@@ -513,50 +510,45 @@ async function resolveConfig({
|
|
|
513
510
|
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
514
511
|
);
|
|
515
512
|
}
|
|
516
|
-
let routes = {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
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")
|
|
513
|
+
let routes = {
|
|
514
|
+
root: { path: "", id: "root", file: rootRouteFile }
|
|
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")
|
|
558
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);
|
|
559
536
|
}
|
|
537
|
+
routes = {
|
|
538
|
+
...routes,
|
|
539
|
+
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
540
|
+
};
|
|
541
|
+
} catch (error) {
|
|
542
|
+
return err(
|
|
543
|
+
[
|
|
544
|
+
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
545
|
+
"",
|
|
546
|
+
error.loc?.file && error.loc?.column && error.frame ? [
|
|
547
|
+
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
548
|
+
error.frame.trim?.()
|
|
549
|
+
] : error.stack
|
|
550
|
+
].flat().join("\n")
|
|
551
|
+
);
|
|
560
552
|
}
|
|
561
553
|
let future = {
|
|
562
554
|
unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
|
|
@@ -587,34 +579,24 @@ async function resolveConfig({
|
|
|
587
579
|
async function createConfigLoader({
|
|
588
580
|
rootDirectory: root,
|
|
589
581
|
watch,
|
|
590
|
-
mode
|
|
591
|
-
skipRoutes
|
|
582
|
+
mode
|
|
592
583
|
}) {
|
|
593
|
-
root =
|
|
594
|
-
let vite2 = await import("vite");
|
|
584
|
+
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
595
585
|
let viteNodeContext = await createContext({
|
|
596
586
|
root,
|
|
597
|
-
mode
|
|
598
|
-
// Filter out any info level logs from vite-node
|
|
599
|
-
customLogger: vite2.createLogger("warn", {
|
|
600
|
-
prefix: "[react-router]"
|
|
601
|
-
})
|
|
587
|
+
mode
|
|
602
588
|
});
|
|
603
|
-
let reactRouterConfigFile
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
});
|
|
608
|
-
};
|
|
609
|
-
updateReactRouterConfigFile();
|
|
610
|
-
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
|
|
589
|
+
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
590
|
+
absolute: true
|
|
591
|
+
});
|
|
592
|
+
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
|
|
611
593
|
let appDirectory;
|
|
612
594
|
let initialConfigResult = await getConfig();
|
|
613
595
|
if (!initialConfigResult.ok) {
|
|
614
596
|
throw new Error(initialConfigResult.error);
|
|
615
597
|
}
|
|
616
|
-
appDirectory =
|
|
617
|
-
let
|
|
598
|
+
appDirectory = initialConfigResult.value.appDirectory;
|
|
599
|
+
let lastConfig = initialConfigResult.value;
|
|
618
600
|
let fsWatcher;
|
|
619
601
|
let changeHandlers = [];
|
|
620
602
|
return {
|
|
@@ -627,71 +609,41 @@ async function createConfigLoader({
|
|
|
627
609
|
}
|
|
628
610
|
changeHandlers.push(handler);
|
|
629
611
|
if (!fsWatcher) {
|
|
630
|
-
fsWatcher = import_chokidar.default.watch(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
dirname !== root;
|
|
638
|
-
}
|
|
639
|
-
});
|
|
612
|
+
fsWatcher = import_chokidar.default.watch(
|
|
613
|
+
[
|
|
614
|
+
...reactRouterConfigFile ? [reactRouterConfigFile] : [],
|
|
615
|
+
appDirectory
|
|
616
|
+
],
|
|
617
|
+
{ ignoreInitial: true }
|
|
618
|
+
);
|
|
640
619
|
fsWatcher.on("all", async (...args) => {
|
|
641
620
|
let [event, rawFilepath] = args;
|
|
642
621
|
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
643
|
-
let
|
|
644
|
-
let
|
|
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(
|
|
622
|
+
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
623
|
+
let configCodeUpdated = Boolean(
|
|
651
624
|
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
652
625
|
);
|
|
653
|
-
if (
|
|
654
|
-
|
|
655
|
-
|
|
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
|
-
});
|
|
626
|
+
if (configCodeUpdated || appFileAddedOrRemoved) {
|
|
627
|
+
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
628
|
+
viteNodeContext.runner?.moduleCache.clear();
|
|
692
629
|
}
|
|
693
|
-
if (
|
|
694
|
-
|
|
630
|
+
if (appFileAddedOrRemoved || configCodeUpdated) {
|
|
631
|
+
let result = await getConfig();
|
|
632
|
+
let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
|
|
633
|
+
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
|
|
634
|
+
for (let handler2 of changeHandlers) {
|
|
635
|
+
handler2({
|
|
636
|
+
result,
|
|
637
|
+
configCodeUpdated,
|
|
638
|
+
configChanged,
|
|
639
|
+
routeConfigChanged,
|
|
640
|
+
path: filepath,
|
|
641
|
+
event
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
if (result.ok) {
|
|
645
|
+
lastConfig = result.value;
|
|
646
|
+
}
|
|
695
647
|
}
|
|
696
648
|
});
|
|
697
649
|
}
|
|
@@ -710,29 +662,18 @@ async function createConfigLoader({
|
|
|
710
662
|
}
|
|
711
663
|
async function loadConfig({
|
|
712
664
|
rootDirectory,
|
|
713
|
-
mode
|
|
714
|
-
skipRoutes
|
|
665
|
+
mode
|
|
715
666
|
}) {
|
|
716
667
|
let configLoader = await createConfigLoader({
|
|
717
668
|
rootDirectory,
|
|
718
669
|
mode,
|
|
719
|
-
skipRoutes,
|
|
720
670
|
watch: false
|
|
721
671
|
});
|
|
722
672
|
let config = await configLoader.getConfig();
|
|
723
673
|
await configLoader.close();
|
|
724
674
|
return config;
|
|
725
675
|
}
|
|
726
|
-
function omitRoutes(config) {
|
|
727
|
-
return {
|
|
728
|
-
...config,
|
|
729
|
-
routes: {}
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
676
|
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
733
|
-
function isEntryFile(entryBasename, filename) {
|
|
734
|
-
return entryExts.some((ext) => filename === `${entryBasename}${ext}`);
|
|
735
|
-
}
|
|
736
677
|
function findEntry(dir, basename, options) {
|
|
737
678
|
let currentDir = import_pathe3.default.resolve(dir);
|
|
738
679
|
let { root } = import_pathe3.default.parse(currentDir);
|
|
@@ -753,30 +694,6 @@ function findEntry(dir, basename, options) {
|
|
|
753
694
|
currentDir = parentDir;
|
|
754
695
|
}
|
|
755
696
|
}
|
|
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
|
-
}
|
|
780
697
|
|
|
781
698
|
// vite/cloudflare-dev-proxy.ts
|
|
782
699
|
var serverBuildId = "virtual:react-router/server-build";
|