@react-router/dev 0.0.0-experimental-d312c78a4 → 0.0.0-experimental-9ea41ead4
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 +87 -120
- package/dist/config/defaults/entry.server.node.tsx +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/static/refresh-utils.cjs +0 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +31 -19
- package/module-sync-enabled/false.cjs +1 -0
- package/module-sync-enabled/index.d.mts +2 -0
- package/module-sync-enabled/index.mjs +4 -0
- package/module-sync-enabled/true.mjs +2 -0
- package/package.json +14 -6
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/dev v0.0.0-experimental-
|
|
3
|
+
* @react-router/dev v0.0.0-experimental-9ea41ead4
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -317,7 +317,6 @@ async function resolveConfig({
|
|
|
317
317
|
basename: basename2,
|
|
318
318
|
buildDirectory: userBuildDirectory,
|
|
319
319
|
buildEnd,
|
|
320
|
-
future: userFuture,
|
|
321
320
|
prerender,
|
|
322
321
|
serverBuildFile,
|
|
323
322
|
serverBundles,
|
|
@@ -391,7 +390,7 @@ async function resolveConfig({
|
|
|
391
390
|
}
|
|
392
391
|
let future = {
|
|
393
392
|
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
|
|
394
|
-
|
|
393
|
+
unstable_splitRouteModules: reactRouterUserConfig.future?.unstable_splitRouteModules ?? false
|
|
395
394
|
};
|
|
396
395
|
let reactRouterConfig = deepFreeze({
|
|
397
396
|
appDirectory,
|
|
@@ -498,6 +497,15 @@ async function createConfigLoader({
|
|
|
498
497
|
}
|
|
499
498
|
};
|
|
500
499
|
}
|
|
500
|
+
async function loadConfig({ rootDirectory }) {
|
|
501
|
+
let configLoader = await createConfigLoader({
|
|
502
|
+
rootDirectory,
|
|
503
|
+
watch: false
|
|
504
|
+
});
|
|
505
|
+
let config = await configLoader.getConfig();
|
|
506
|
+
await configLoader.close();
|
|
507
|
+
return config;
|
|
508
|
+
}
|
|
501
509
|
function findEntry(dir, basename2, options) {
|
|
502
510
|
for (let ext of entryExts) {
|
|
503
511
|
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
@@ -588,6 +596,45 @@ var init_config = __esm({
|
|
|
588
596
|
}
|
|
589
597
|
});
|
|
590
598
|
|
|
599
|
+
// vite/profiler.ts
|
|
600
|
+
var import_node_fs2, import_node_path, import_picocolors2, getSession, start, profileCount, stop;
|
|
601
|
+
var init_profiler = __esm({
|
|
602
|
+
"vite/profiler.ts"() {
|
|
603
|
+
"use strict";
|
|
604
|
+
import_node_fs2 = __toESM(require("fs"));
|
|
605
|
+
import_node_path = __toESM(require("path"));
|
|
606
|
+
import_picocolors2 = __toESM(require("picocolors"));
|
|
607
|
+
getSession = () => global.__reactRouter_profile_session;
|
|
608
|
+
start = async (callback) => {
|
|
609
|
+
let inspector = await import("inspector").then((r) => r.default);
|
|
610
|
+
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
611
|
+
session.connect();
|
|
612
|
+
session.post("Profiler.enable", () => {
|
|
613
|
+
session.post("Profiler.start", callback);
|
|
614
|
+
});
|
|
615
|
+
};
|
|
616
|
+
profileCount = 0;
|
|
617
|
+
stop = (log) => {
|
|
618
|
+
let session = getSession();
|
|
619
|
+
if (!session) return;
|
|
620
|
+
return new Promise((res, rej) => {
|
|
621
|
+
session.post("Profiler.stop", (err2, { profile }) => {
|
|
622
|
+
if (err2) return rej(err2);
|
|
623
|
+
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
624
|
+
import_node_fs2.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
625
|
+
log(
|
|
626
|
+
import_picocolors2.default.yellow(
|
|
627
|
+
`CPU profile written to ${import_picocolors2.default.white(import_picocolors2.default.dim(outPath))}`
|
|
628
|
+
)
|
|
629
|
+
);
|
|
630
|
+
global.__reactRouter_profile_session = void 0;
|
|
631
|
+
res();
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
|
|
591
638
|
// typegen/paths.ts
|
|
592
639
|
function getTypesDir(ctx) {
|
|
593
640
|
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
@@ -730,16 +777,16 @@ async function run(rootDirectory) {
|
|
|
730
777
|
async function watch(rootDirectory, { logger } = {}) {
|
|
731
778
|
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
732
779
|
await writeAll(ctx);
|
|
733
|
-
logger?.info(
|
|
780
|
+
logger?.info(import_picocolors3.default.green("generated types"), { timestamp: true, clear: true });
|
|
734
781
|
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
735
782
|
if (!result.ok) {
|
|
736
|
-
logger?.error(
|
|
783
|
+
logger?.error(import_picocolors3.default.red(result.error), { timestamp: true, clear: true });
|
|
737
784
|
return;
|
|
738
785
|
}
|
|
739
786
|
ctx.config = result.value;
|
|
740
787
|
if (routeConfigChanged) {
|
|
741
788
|
await writeAll(ctx);
|
|
742
|
-
logger?.info(
|
|
789
|
+
logger?.info(import_picocolors3.default.green("regenerated types"), {
|
|
743
790
|
timestamp: true,
|
|
744
791
|
clear: true
|
|
745
792
|
});
|
|
@@ -767,21 +814,21 @@ async function createContext2({
|
|
|
767
814
|
}
|
|
768
815
|
async function writeAll(ctx) {
|
|
769
816
|
const typegenDir = getTypesDir(ctx);
|
|
770
|
-
|
|
817
|
+
import_node_fs3.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
771
818
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
772
819
|
const typesPath = getTypesPath(ctx, route);
|
|
773
820
|
const content = generate(ctx, route);
|
|
774
|
-
|
|
775
|
-
|
|
821
|
+
import_node_fs3.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
822
|
+
import_node_fs3.default.writeFileSync(typesPath, content);
|
|
776
823
|
});
|
|
777
824
|
}
|
|
778
|
-
var
|
|
825
|
+
var import_node_fs3, Path4, import_picocolors3;
|
|
779
826
|
var init_typegen = __esm({
|
|
780
827
|
"typegen/index.ts"() {
|
|
781
828
|
"use strict";
|
|
782
|
-
|
|
829
|
+
import_node_fs3 = __toESM(require("fs"));
|
|
783
830
|
Path4 = __toESM(require("pathe"));
|
|
784
|
-
|
|
831
|
+
import_picocolors3 = __toESM(require("picocolors"));
|
|
785
832
|
init_config();
|
|
786
833
|
init_generate();
|
|
787
834
|
init_paths();
|
|
@@ -814,21 +861,21 @@ var init_node_adapter = __esm({
|
|
|
814
861
|
});
|
|
815
862
|
|
|
816
863
|
// vite/resolve-file-url.ts
|
|
817
|
-
var
|
|
864
|
+
var path5;
|
|
818
865
|
var init_resolve_file_url = __esm({
|
|
819
866
|
"vite/resolve-file-url.ts"() {
|
|
820
867
|
"use strict";
|
|
821
|
-
|
|
868
|
+
path5 = __toESM(require("path"));
|
|
822
869
|
init_vite();
|
|
823
870
|
}
|
|
824
871
|
});
|
|
825
872
|
|
|
826
873
|
// vite/styles.ts
|
|
827
|
-
var
|
|
874
|
+
var path6, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
828
875
|
var init_styles = __esm({
|
|
829
876
|
"vite/styles.ts"() {
|
|
830
877
|
"use strict";
|
|
831
|
-
|
|
878
|
+
path6 = __toESM(require("path"));
|
|
832
879
|
import_react_router = require("react-router");
|
|
833
880
|
init_resolve_file_url();
|
|
834
881
|
init_vite();
|
|
@@ -936,56 +983,19 @@ async function resolveViteConfig({
|
|
|
936
983
|
async function extractPluginContext(viteConfig) {
|
|
937
984
|
return viteConfig["__reactRouterPluginContext"];
|
|
938
985
|
}
|
|
939
|
-
|
|
940
|
-
configFile,
|
|
941
|
-
root
|
|
942
|
-
}) {
|
|
943
|
-
if (!root) {
|
|
944
|
-
root = process.env.REACT_ROUTER_ROOT || process.cwd();
|
|
945
|
-
}
|
|
946
|
-
configFile = configFile ?? findConfig(root, "vite.config", [
|
|
947
|
-
".ts",
|
|
948
|
-
".cts",
|
|
949
|
-
".mts",
|
|
950
|
-
".js",
|
|
951
|
-
".cjs",
|
|
952
|
-
".mjs"
|
|
953
|
-
]);
|
|
954
|
-
if (!configFile) {
|
|
955
|
-
console.error(import_picocolors3.default.red("Vite config file not found"));
|
|
956
|
-
process.exit(1);
|
|
957
|
-
}
|
|
958
|
-
let viteConfig = await resolveViteConfig({ configFile, root });
|
|
959
|
-
let ctx = await extractPluginContext(viteConfig);
|
|
960
|
-
if (!ctx) {
|
|
961
|
-
console.error(
|
|
962
|
-
import_picocolors3.default.red("React Router Vite plugin not found in Vite config")
|
|
963
|
-
);
|
|
964
|
-
process.exit(1);
|
|
965
|
-
}
|
|
966
|
-
return ctx;
|
|
967
|
-
}
|
|
968
|
-
function findConfig(dir, basename2, extensions) {
|
|
969
|
-
for (let ext of extensions) {
|
|
970
|
-
let name = basename2 + ext;
|
|
971
|
-
let file = path6.join(dir, name);
|
|
972
|
-
if (fse.existsSync(file)) return file;
|
|
973
|
-
}
|
|
974
|
-
return void 0;
|
|
975
|
-
}
|
|
976
|
-
var import_node_crypto, path6, url, fse, babel, import_react_router2, import_es_module_lexer, import_jsesc, import_picocolors3, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
|
|
986
|
+
var import_node_crypto, path7, url, fse, babel2, import_react_router2, import_es_module_lexer, import_jsesc, import_picocolors4, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
|
|
977
987
|
var init_plugin = __esm({
|
|
978
988
|
"vite/plugin.ts"() {
|
|
979
989
|
"use strict";
|
|
980
990
|
import_node_crypto = require("crypto");
|
|
981
|
-
|
|
991
|
+
path7 = __toESM(require("path"));
|
|
982
992
|
url = __toESM(require("url"));
|
|
983
993
|
fse = __toESM(require("fs-extra"));
|
|
984
|
-
|
|
994
|
+
babel2 = __toESM(require("@babel/core"));
|
|
985
995
|
import_react_router2 = require("react-router");
|
|
986
996
|
import_es_module_lexer = require("es-module-lexer");
|
|
987
997
|
import_jsesc = __toESM(require("jsesc"));
|
|
988
|
-
|
|
998
|
+
import_picocolors4 = __toESM(require("picocolors"));
|
|
989
999
|
init_typegen();
|
|
990
1000
|
init_invariant();
|
|
991
1001
|
init_babel();
|
|
@@ -1006,18 +1016,18 @@ var init_plugin = __esm({
|
|
|
1006
1016
|
serverManifest: create("server-manifest"),
|
|
1007
1017
|
browserManifest: create("browser-manifest")
|
|
1008
1018
|
};
|
|
1009
|
-
getServerBuildDirectory = (ctx) =>
|
|
1019
|
+
getServerBuildDirectory = (ctx) => path7.join(
|
|
1010
1020
|
ctx.reactRouterConfig.buildDirectory,
|
|
1011
1021
|
"server",
|
|
1012
1022
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
1013
1023
|
);
|
|
1014
|
-
defaultEntriesDir =
|
|
1015
|
-
|
|
1024
|
+
defaultEntriesDir = path7.resolve(
|
|
1025
|
+
path7.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1016
1026
|
"dist",
|
|
1017
1027
|
"config",
|
|
1018
1028
|
"defaults"
|
|
1019
1029
|
);
|
|
1020
|
-
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) =>
|
|
1030
|
+
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path7.join(defaultEntriesDir, filename3));
|
|
1021
1031
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1022
1032
|
REACT_REFRESH_HEADER = `
|
|
1023
1033
|
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
@@ -1043,45 +1053,6 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
1043
1053
|
}
|
|
1044
1054
|
});
|
|
1045
1055
|
|
|
1046
|
-
// vite/profiler.ts
|
|
1047
|
-
var import_node_fs3, import_node_path, import_picocolors4, getSession, start, profileCount, stop;
|
|
1048
|
-
var init_profiler = __esm({
|
|
1049
|
-
"vite/profiler.ts"() {
|
|
1050
|
-
"use strict";
|
|
1051
|
-
import_node_fs3 = __toESM(require("fs"));
|
|
1052
|
-
import_node_path = __toESM(require("path"));
|
|
1053
|
-
import_picocolors4 = __toESM(require("picocolors"));
|
|
1054
|
-
getSession = () => global.__reactRouter_profile_session;
|
|
1055
|
-
start = async (callback) => {
|
|
1056
|
-
let inspector = await import("inspector").then((r) => r.default);
|
|
1057
|
-
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
1058
|
-
session.connect();
|
|
1059
|
-
session.post("Profiler.enable", () => {
|
|
1060
|
-
session.post("Profiler.start", callback);
|
|
1061
|
-
});
|
|
1062
|
-
};
|
|
1063
|
-
profileCount = 0;
|
|
1064
|
-
stop = (log) => {
|
|
1065
|
-
let session = getSession();
|
|
1066
|
-
if (!session) return;
|
|
1067
|
-
return new Promise((res, rej) => {
|
|
1068
|
-
session.post("Profiler.stop", (err2, { profile }) => {
|
|
1069
|
-
if (err2) return rej(err2);
|
|
1070
|
-
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
1071
|
-
import_node_fs3.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
1072
|
-
log(
|
|
1073
|
-
import_picocolors4.default.yellow(
|
|
1074
|
-
`CPU profile written to ${import_picocolors4.default.white(import_picocolors4.default.dim(outPath))}`
|
|
1075
|
-
)
|
|
1076
|
-
);
|
|
1077
|
-
global.__reactRouter_profile_session = void 0;
|
|
1078
|
-
res();
|
|
1079
|
-
});
|
|
1080
|
-
});
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
|
|
1085
1056
|
// vite/build.ts
|
|
1086
1057
|
var build_exports = {};
|
|
1087
1058
|
__export(build_exports, {
|
|
@@ -1381,6 +1352,8 @@ var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
|
1381
1352
|
var import_package_json2 = __toESM(require("@npmcli/package-json"));
|
|
1382
1353
|
var import_exit_hook = __toESM(require("exit-hook"));
|
|
1383
1354
|
var import_picocolors7 = __toESM(require("picocolors"));
|
|
1355
|
+
var import_react_router3 = require("react-router");
|
|
1356
|
+
init_config();
|
|
1384
1357
|
|
|
1385
1358
|
// config/format.ts
|
|
1386
1359
|
function formatRoutes(routeManifest, format) {
|
|
@@ -1438,16 +1411,13 @@ function formatRoutesAsJsx(routeManifest) {
|
|
|
1438
1411
|
return output;
|
|
1439
1412
|
}
|
|
1440
1413
|
|
|
1441
|
-
// cli/commands.ts
|
|
1442
|
-
init_plugin();
|
|
1443
|
-
|
|
1444
1414
|
// cli/useJavascript.ts
|
|
1445
|
-
var
|
|
1415
|
+
var babel = __toESM(require("@babel/core"));
|
|
1446
1416
|
var import_plugin_syntax_jsx = __toESM(require("@babel/plugin-syntax-jsx"));
|
|
1447
1417
|
var import_preset_typescript = __toESM(require("@babel/preset-typescript"));
|
|
1448
1418
|
var import_prettier = __toESM(require("prettier"));
|
|
1449
1419
|
function transpile(tsx, options = {}) {
|
|
1450
|
-
let mjs =
|
|
1420
|
+
let mjs = babel.transformSync(tsx, {
|
|
1451
1421
|
compact: false,
|
|
1452
1422
|
cwd: options.cwd,
|
|
1453
1423
|
filename: options.filename,
|
|
@@ -1464,18 +1434,14 @@ init_profiler();
|
|
|
1464
1434
|
init_typegen();
|
|
1465
1435
|
init_vite();
|
|
1466
1436
|
async function routes(reactRouterRoot, flags = {}) {
|
|
1467
|
-
let
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
if (!ctx) {
|
|
1472
|
-
console.error(
|
|
1473
|
-
import_picocolors7.default.red("React Router Vite plugin not found in Vite config")
|
|
1474
|
-
);
|
|
1437
|
+
let rootDirectory = reactRouterRoot ?? process.cwd();
|
|
1438
|
+
let configResult = await loadConfig({ rootDirectory });
|
|
1439
|
+
if (!configResult.ok) {
|
|
1440
|
+
console.error(import_picocolors7.default.red(configResult.error));
|
|
1475
1441
|
process.exit(1);
|
|
1476
1442
|
}
|
|
1477
1443
|
let format = flags.json ? "json" : "jsx";
|
|
1478
|
-
console.log(formatRoutes(
|
|
1444
|
+
console.log(formatRoutes(configResult.value.routes, format));
|
|
1479
1445
|
}
|
|
1480
1446
|
async function build2(root, options = {}) {
|
|
1481
1447
|
if (!root) {
|
|
@@ -1509,17 +1475,18 @@ var conjunctionListFormat = new Intl.ListFormat("en", {
|
|
|
1509
1475
|
type: "conjunction"
|
|
1510
1476
|
});
|
|
1511
1477
|
async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
1512
|
-
let ctx = await loadPluginContext({
|
|
1513
|
-
root: reactRouterRoot,
|
|
1514
|
-
configFile: flags.config
|
|
1515
|
-
});
|
|
1516
|
-
let rootDirectory = ctx.rootDirectory;
|
|
1517
|
-
let appDirectory = ctx.reactRouterConfig.appDirectory;
|
|
1518
1478
|
if (!entry) {
|
|
1519
1479
|
await generateEntry("entry.client", reactRouterRoot, flags);
|
|
1520
1480
|
await generateEntry("entry.server", reactRouterRoot, flags);
|
|
1521
1481
|
return;
|
|
1522
1482
|
}
|
|
1483
|
+
let rootDirectory = reactRouterRoot ?? process.cwd();
|
|
1484
|
+
let configResult = await loadConfig({ rootDirectory });
|
|
1485
|
+
if (!configResult.ok) {
|
|
1486
|
+
console.error(import_picocolors7.default.red(configResult.error));
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
let appDirectory = configResult.value.appDirectory;
|
|
1523
1490
|
if (!entries.includes(entry)) {
|
|
1524
1491
|
let entriesArray = Array.from(entries);
|
|
1525
1492
|
let list = conjunctionListFormat.format(entriesArray);
|
|
@@ -61,7 +61,7 @@ export default function handleRequest(
|
|
|
61
61
|
}
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
-
// Abort the rendering stream after the `streamTimeout` so it has
|
|
64
|
+
// Abort the rendering stream after the `streamTimeout` so it has time to
|
|
65
65
|
// flush down the rejected boundaries
|
|
66
66
|
setTimeout(abort, streamTimeout + 1000);
|
|
67
67
|
});
|
package/dist/config.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ interface FutureConfig {
|
|
|
41
41
|
/**
|
|
42
42
|
* Automatically split route modules into multiple chunks when possible.
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
unstable_splitRouteModules?: boolean | "enforce";
|
|
45
45
|
}
|
|
46
46
|
type BuildManifest = DefaultBuildManifest | ServerBundlesBuildManifest;
|
|
47
47
|
type BuildEndHook = (args: {
|
|
@@ -133,7 +133,7 @@ type ResolvedReactRouterConfig = Readonly<{
|
|
|
133
133
|
/**
|
|
134
134
|
* Enabled future flags
|
|
135
135
|
*/
|
|
136
|
-
future:
|
|
136
|
+
future: FutureConfig;
|
|
137
137
|
/**
|
|
138
138
|
* An array of URLs to prerender to HTML files at build time. Can also be a
|
|
139
139
|
* function returning an array to dynamically generate URLs.
|
package/dist/config.js
CHANGED
package/dist/routes.js
CHANGED
package/dist/vite/cloudflare.js
CHANGED
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-9ea41ead4
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -371,7 +371,6 @@ async function resolveConfig({
|
|
|
371
371
|
basename: basename2,
|
|
372
372
|
buildDirectory: userBuildDirectory,
|
|
373
373
|
buildEnd,
|
|
374
|
-
future: userFuture,
|
|
375
374
|
prerender,
|
|
376
375
|
serverBuildFile,
|
|
377
376
|
serverBundles,
|
|
@@ -445,7 +444,7 @@ async function resolveConfig({
|
|
|
445
444
|
}
|
|
446
445
|
let future = {
|
|
447
446
|
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
|
|
448
|
-
|
|
447
|
+
unstable_splitRouteModules: reactRouterUserConfig.future?.unstable_splitRouteModules ?? false
|
|
449
448
|
};
|
|
450
449
|
let reactRouterConfig = deepFreeze({
|
|
451
450
|
appDirectory,
|
|
@@ -2228,7 +2227,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2228
2227
|
viteChildCompiler,
|
|
2229
2228
|
ctx
|
|
2230
2229
|
);
|
|
2231
|
-
let
|
|
2230
|
+
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2232
2231
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
2233
2232
|
let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2234
2233
|
let sourceExports = routeManifestExports[key];
|
|
@@ -2242,7 +2241,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2242
2241
|
routeFile,
|
|
2243
2242
|
{ routeFile, viteChildCompiler }
|
|
2244
2243
|
);
|
|
2245
|
-
if (
|
|
2244
|
+
if (enforceSplitRouteModules) {
|
|
2246
2245
|
validateRouteChunks({
|
|
2247
2246
|
ctx,
|
|
2248
2247
|
id: route.file,
|
|
@@ -2328,7 +2327,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2328
2327
|
viteChildCompiler,
|
|
2329
2328
|
ctx
|
|
2330
2329
|
);
|
|
2331
|
-
let
|
|
2330
|
+
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2332
2331
|
for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
|
|
2333
2332
|
let routeFile = route.file;
|
|
2334
2333
|
let sourceExports = routeManifestExports[key];
|
|
@@ -2342,7 +2341,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2342
2341
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
2343
2342
|
)}`
|
|
2344
2343
|
);
|
|
2345
|
-
if (
|
|
2344
|
+
if (enforceSplitRouteModules) {
|
|
2346
2345
|
let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
|
|
2347
2346
|
cache,
|
|
2348
2347
|
ctx,
|
|
@@ -2366,7 +2365,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2366
2365
|
index: route.index,
|
|
2367
2366
|
caseSensitive: route.caseSensitive,
|
|
2368
2367
|
module: routeModulePath,
|
|
2369
|
-
//
|
|
2368
|
+
// Split route modules are a build-time optimization
|
|
2370
2369
|
clientActionModule: void 0,
|
|
2371
2370
|
clientLoaderModule: void 0,
|
|
2372
2371
|
hydrateFallbackModule: void 0,
|
|
@@ -2406,8 +2405,13 @@ var reactRouterVitePlugin = () => {
|
|
|
2406
2405
|
let viteClientConditions = [
|
|
2407
2406
|
...vite2.defaultClientConditions ?? []
|
|
2408
2407
|
];
|
|
2408
|
+
let packageRoot = path6.dirname(
|
|
2409
|
+
require.resolve("@react-router/dev/package.json")
|
|
2410
|
+
);
|
|
2411
|
+
let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
2409
2412
|
let viteServerConditions = [
|
|
2410
|
-
...vite2.defaultServerConditions ?? []
|
|
2413
|
+
...vite2.defaultServerConditions ?? [],
|
|
2414
|
+
...moduleSyncEnabled ? ["module-sync"] : []
|
|
2411
2415
|
];
|
|
2412
2416
|
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
2413
2417
|
prefix: "[react-router]"
|
|
@@ -2535,7 +2539,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2535
2539
|
);
|
|
2536
2540
|
return [
|
|
2537
2541
|
`${routeFilePath}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
|
|
2538
|
-
|
|
2542
|
+
...ctx.reactRouterConfig.future.unstable_splitRouteModules && !isRootRoute ? routeChunkExportNames.map(
|
|
2539
2543
|
(exportName) => code.includes(exportName) ? getRouteChunkModuleId(
|
|
2540
2544
|
routeFilePath,
|
|
2541
2545
|
exportName
|
|
@@ -2883,10 +2887,14 @@ var reactRouterVitePlugin = () => {
|
|
|
2883
2887
|
}
|
|
2884
2888
|
},
|
|
2885
2889
|
{
|
|
2886
|
-
name: "react-router:route-
|
|
2890
|
+
name: "react-router:split-route-modules",
|
|
2887
2891
|
async transform(code, id, options) {
|
|
2888
2892
|
if (options?.ssr) return;
|
|
2889
2893
|
if (!isRouteChunkModuleId(id)) return;
|
|
2894
|
+
invariant(
|
|
2895
|
+
viteCommand === "build",
|
|
2896
|
+
"Route modules are only split in build mode"
|
|
2897
|
+
);
|
|
2890
2898
|
let chunkName = getRouteChunkNameFromModuleId(id);
|
|
2891
2899
|
if (!chunkName) {
|
|
2892
2900
|
throw new Error(`Invalid route chunk name "${chunkName}" in "${id}"`);
|
|
@@ -2900,10 +2908,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2900
2908
|
);
|
|
2901
2909
|
let preventEmptyChunkSnippet = ({ reason }) => `Math.random()<0&&console.log(${JSON.stringify(reason)});`;
|
|
2902
2910
|
if (chunk === null) {
|
|
2903
|
-
return preventEmptyChunkSnippet({
|
|
2911
|
+
return preventEmptyChunkSnippet({
|
|
2912
|
+
reason: "Split round modules disabled"
|
|
2913
|
+
});
|
|
2904
2914
|
}
|
|
2905
|
-
let
|
|
2906
|
-
if (
|
|
2915
|
+
let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
|
|
2916
|
+
if (enforceSplitRouteModules && chunkName === "main" && chunk) {
|
|
2907
2917
|
let exportNames = getExportNames(chunk.code);
|
|
2908
2918
|
validateRouteChunks({
|
|
2909
2919
|
ctx,
|
|
@@ -3025,6 +3035,9 @@ var reactRouterVitePlugin = () => {
|
|
|
3025
3035
|
{
|
|
3026
3036
|
name: "react-router:route-exports",
|
|
3027
3037
|
async transform(code, id, options) {
|
|
3038
|
+
if (isRouteChunkModuleId(id)) {
|
|
3039
|
+
id = id.split("?")[0];
|
|
3040
|
+
}
|
|
3028
3041
|
let route = getRoute(ctx.reactRouterConfig, id);
|
|
3029
3042
|
if (!route) return;
|
|
3030
3043
|
if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
|
|
@@ -3596,7 +3609,7 @@ async function detectRouteChunksIfEnabled(cache, ctx, id, input) {
|
|
|
3596
3609
|
}
|
|
3597
3610
|
};
|
|
3598
3611
|
}
|
|
3599
|
-
if (!ctx.reactRouterConfig.future.
|
|
3612
|
+
if (!ctx.reactRouterConfig.future.unstable_splitRouteModules) {
|
|
3600
3613
|
return noRouteChunks();
|
|
3601
3614
|
}
|
|
3602
3615
|
if (normalizeRelativeFilePath(id, ctx.reactRouterConfig) === ctx.reactRouterConfig.routes.root.file) {
|
|
@@ -3610,7 +3623,7 @@ async function detectRouteChunksIfEnabled(cache, ctx, id, input) {
|
|
|
3610
3623
|
return detectRouteChunks(code, cache, cacheKey);
|
|
3611
3624
|
}
|
|
3612
3625
|
async function getRouteChunkIfEnabled(cache, ctx, id, chunkName, input) {
|
|
3613
|
-
if (!ctx.reactRouterConfig.future.
|
|
3626
|
+
if (!ctx.reactRouterConfig.future.unstable_splitRouteModules) {
|
|
3614
3627
|
return null;
|
|
3615
3628
|
}
|
|
3616
3629
|
let code = await resolveRouteFileCode(ctx, input);
|
|
@@ -3629,13 +3642,12 @@ function validateRouteChunks({
|
|
|
3629
3642
|
let plural = invalidChunks.length > 1;
|
|
3630
3643
|
throw new Error(
|
|
3631
3644
|
[
|
|
3632
|
-
`
|
|
3645
|
+
`Error splitting route module: ${normalizeRelativeFilePath(
|
|
3633
3646
|
id,
|
|
3634
3647
|
ctx.reactRouterConfig
|
|
3635
3648
|
)}`,
|
|
3636
3649
|
invalidChunks.map((name) => `- ${name}`).join("\n"),
|
|
3637
|
-
`${plural ?
|
|
3638
|
-
`If you need to share code between ${plural ? `these` : `this`} and other exports, you should extract the shared code into a separate module.`
|
|
3650
|
+
`${plural ? "These exports" : "This export"} could not be split into ${plural ? "their own chunks" : "its own chunk"} because ${plural ? "they share" : "it shares"} code with other exports. You should extract any shared code into its own module and then import it within the route module.`
|
|
3639
3651
|
].join("\n\n")
|
|
3640
3652
|
);
|
|
3641
3653
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports.default = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/dev",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-9ea41ead4",
|
|
4
4
|
"description": "Dev tools and CLI for React Router",
|
|
5
5
|
"homepage": "https://reactrouter.com",
|
|
6
6
|
"bugs": {
|
|
@@ -31,6 +31,12 @@
|
|
|
31
31
|
},
|
|
32
32
|
"./package.json": "./package.json"
|
|
33
33
|
},
|
|
34
|
+
"imports": {
|
|
35
|
+
"#module-sync-enabled": {
|
|
36
|
+
"module-sync": "./module-sync-enabled/true.mjs",
|
|
37
|
+
"default": "./module-sync-enabled/false.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
34
40
|
"bin": {
|
|
35
41
|
"react-router": "bin.js"
|
|
36
42
|
},
|
|
@@ -40,6 +46,7 @@
|
|
|
40
46
|
"files": [
|
|
41
47
|
"cli/**",
|
|
42
48
|
"config/**",
|
|
49
|
+
"module-sync-enabled/**",
|
|
43
50
|
"typegen/**",
|
|
44
51
|
"vite/**",
|
|
45
52
|
"*.ts",
|
|
@@ -81,7 +88,7 @@
|
|
|
81
88
|
"set-cookie-parser": "^2.6.0",
|
|
82
89
|
"valibot": "^0.41.0",
|
|
83
90
|
"vite-node": "3.0.0-beta.2",
|
|
84
|
-
"@react-router/node": "0.0.0-experimental-
|
|
91
|
+
"@react-router/node": "0.0.0-experimental-9ea41ead4"
|
|
85
92
|
},
|
|
86
93
|
"devDependencies": {
|
|
87
94
|
"@types/babel__core": "^7.20.5",
|
|
@@ -110,15 +117,15 @@
|
|
|
110
117
|
"vite": "^6.0.0",
|
|
111
118
|
"wireit": "0.14.9",
|
|
112
119
|
"wrangler": "^3.28.2",
|
|
113
|
-
"@react-router/serve": "0.0.0-experimental-
|
|
114
|
-
"react-router": "^0.0.0-experimental-
|
|
120
|
+
"@react-router/serve": "0.0.0-experimental-9ea41ead4",
|
|
121
|
+
"react-router": "^0.0.0-experimental-9ea41ead4"
|
|
115
122
|
},
|
|
116
123
|
"peerDependencies": {
|
|
117
124
|
"typescript": "^5.1.0",
|
|
118
125
|
"vite": "^5.1.0 || ^6.0.0",
|
|
119
126
|
"wrangler": "^3.28.2",
|
|
120
|
-
"@react-router/serve": "^0.0.0-experimental-
|
|
121
|
-
"react-router": "^0.0.0-experimental-
|
|
127
|
+
"@react-router/serve": "^0.0.0-experimental-9ea41ead4",
|
|
128
|
+
"react-router": "^0.0.0-experimental-9ea41ead4"
|
|
122
129
|
},
|
|
123
130
|
"peerDependenciesMeta": {
|
|
124
131
|
"@react-router/serve": {
|
|
@@ -136,6 +143,7 @@
|
|
|
136
143
|
},
|
|
137
144
|
"files": [
|
|
138
145
|
"dist/",
|
|
146
|
+
"module-sync-enabled/",
|
|
139
147
|
"bin.js",
|
|
140
148
|
"CHANGELOG.md",
|
|
141
149
|
"LICENSE.md",
|