@react-router/dev 0.0.0-experimental-345f1da12 → 0.0.0-experimental-df6bc686c
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 +236 -242
- package/dist/config/defaults/entry.server.node.tsx +1 -1
- package/dist/config.d.ts +5 -1
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/static/refresh-utils.cjs +1 -0
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +1074 -173
- 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-df6bc686c
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -317,6 +317,7 @@ async function resolveConfig({
|
|
|
317
317
|
basename: basename2,
|
|
318
318
|
buildDirectory: userBuildDirectory,
|
|
319
319
|
buildEnd,
|
|
320
|
+
future: userFuture,
|
|
320
321
|
prerender,
|
|
321
322
|
serverBuildFile,
|
|
322
323
|
serverBundles,
|
|
@@ -389,7 +390,8 @@ async function resolveConfig({
|
|
|
389
390
|
);
|
|
390
391
|
}
|
|
391
392
|
let future = {
|
|
392
|
-
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
393
|
+
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
|
|
394
|
+
unstable_splitRouteModules: userFuture?.unstable_splitRouteModules ?? false
|
|
393
395
|
};
|
|
394
396
|
let reactRouterConfig = deepFreeze({
|
|
395
397
|
appDirectory,
|
|
@@ -496,6 +498,15 @@ async function createConfigLoader({
|
|
|
496
498
|
}
|
|
497
499
|
};
|
|
498
500
|
}
|
|
501
|
+
async function loadConfig({ rootDirectory }) {
|
|
502
|
+
let configLoader = await createConfigLoader({
|
|
503
|
+
rootDirectory,
|
|
504
|
+
watch: false
|
|
505
|
+
});
|
|
506
|
+
let config = await configLoader.getConfig();
|
|
507
|
+
await configLoader.close();
|
|
508
|
+
return config;
|
|
509
|
+
}
|
|
499
510
|
function findEntry(dir, basename2, options) {
|
|
500
511
|
for (let ext of entryExts) {
|
|
501
512
|
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
@@ -586,46 +597,42 @@ var init_config = __esm({
|
|
|
586
597
|
}
|
|
587
598
|
});
|
|
588
599
|
|
|
589
|
-
//
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
// ${route.file}
|
|
594
|
-
|
|
595
|
-
import type { RouteExports, Routes } from "react-router/types";
|
|
596
|
-
|
|
597
|
-
type RouteId = "${route.id}"
|
|
598
|
-
export type Info = Routes[RouteId];
|
|
599
|
-
|
|
600
|
-
type Exports = RouteExports[RouteId];
|
|
601
|
-
|
|
602
|
-
export namespace Route {
|
|
603
|
-
export type LinkDescriptors = Exports["links"]["return"];
|
|
604
|
-
export type LinksFunction = () => LinkDescriptors;
|
|
605
|
-
|
|
606
|
-
export type MetaArgs = Exports["meta"]["args"];
|
|
607
|
-
export type MetaDescriptors = Exports["meta"]["return"];
|
|
608
|
-
export type MetaFunction = (args: MetaArgs) => MetaDescriptors;
|
|
609
|
-
|
|
610
|
-
export type HeadersArgs = Exports["headers"]["args"];
|
|
611
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit;
|
|
612
|
-
|
|
613
|
-
export type LoaderArgs = Exports["loader"]["args"];
|
|
614
|
-
export type ClientLoaderArgs = Exports["clientLoader"]["args"];
|
|
615
|
-
export type ActionArgs = Exports["action"]["args"];
|
|
616
|
-
export type ClientActionArgs = Exports["clientAction"]["args"];
|
|
617
|
-
|
|
618
|
-
export type HydrateFallbackProps = Exports["HydrateFallback"]["args"];
|
|
619
|
-
export type ComponentProps = Exports["default"]["args"];
|
|
620
|
-
export type ErrorBoundaryProps = Exports["ErrorBoundary"]["args"];
|
|
621
|
-
}
|
|
622
|
-
`;
|
|
623
|
-
}
|
|
624
|
-
var import_dedent;
|
|
625
|
-
var init_generate = __esm({
|
|
626
|
-
"typegen/generate.ts"() {
|
|
600
|
+
// vite/profiler.ts
|
|
601
|
+
var import_node_fs2, import_node_path, import_picocolors2, getSession, start, profileCount, stop;
|
|
602
|
+
var init_profiler = __esm({
|
|
603
|
+
"vite/profiler.ts"() {
|
|
627
604
|
"use strict";
|
|
628
|
-
|
|
605
|
+
import_node_fs2 = __toESM(require("fs"));
|
|
606
|
+
import_node_path = __toESM(require("path"));
|
|
607
|
+
import_picocolors2 = __toESM(require("picocolors"));
|
|
608
|
+
getSession = () => global.__reactRouter_profile_session;
|
|
609
|
+
start = async (callback) => {
|
|
610
|
+
let inspector = await import("inspector").then((r) => r.default);
|
|
611
|
+
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
612
|
+
session.connect();
|
|
613
|
+
session.post("Profiler.enable", () => {
|
|
614
|
+
session.post("Profiler.start", callback);
|
|
615
|
+
});
|
|
616
|
+
};
|
|
617
|
+
profileCount = 0;
|
|
618
|
+
stop = (log) => {
|
|
619
|
+
let session = getSession();
|
|
620
|
+
if (!session) return;
|
|
621
|
+
return new Promise((res, rej) => {
|
|
622
|
+
session.post("Profiler.stop", (err2, { profile }) => {
|
|
623
|
+
if (err2) return rej(err2);
|
|
624
|
+
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
625
|
+
import_node_fs2.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
626
|
+
log(
|
|
627
|
+
import_picocolors2.default.yellow(
|
|
628
|
+
`CPU profile written to ${import_picocolors2.default.white(import_picocolors2.default.dim(outPath))}`
|
|
629
|
+
)
|
|
630
|
+
);
|
|
631
|
+
global.__reactRouter_profile_session = void 0;
|
|
632
|
+
res();
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
};
|
|
629
636
|
}
|
|
630
637
|
});
|
|
631
638
|
|
|
@@ -650,6 +657,119 @@ var init_paths = __esm({
|
|
|
650
657
|
}
|
|
651
658
|
});
|
|
652
659
|
|
|
660
|
+
// typegen/generate.ts
|
|
661
|
+
function generate(ctx, route) {
|
|
662
|
+
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
663
|
+
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
664
|
+
const typesPath = getTypesPath(ctx, route);
|
|
665
|
+
const parents = lineage.slice(0, -1);
|
|
666
|
+
const parentTypeImports = parents.map((parent, i) => {
|
|
667
|
+
const rel = Path3.relative(
|
|
668
|
+
Path3.dirname(typesPath),
|
|
669
|
+
getTypesPath(ctx, parent)
|
|
670
|
+
);
|
|
671
|
+
const indent = i === 0 ? "" : " ".repeat(2);
|
|
672
|
+
let source = noExtension(rel);
|
|
673
|
+
if (!source.startsWith("../")) source = "./" + source;
|
|
674
|
+
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
675
|
+
}).join("\n");
|
|
676
|
+
return import_dedent.default`
|
|
677
|
+
// React Router generated types for route:
|
|
678
|
+
// ${route.file}
|
|
679
|
+
|
|
680
|
+
import type * as T from "react-router/route-module"
|
|
681
|
+
|
|
682
|
+
${parentTypeImports}
|
|
683
|
+
|
|
684
|
+
type Module = typeof import("../${Pathe2.filename(route.file)}.js")
|
|
685
|
+
|
|
686
|
+
export type Info = {
|
|
687
|
+
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
688
|
+
id: "${route.id}"
|
|
689
|
+
file: "${route.file}"
|
|
690
|
+
path: "${route.path}"
|
|
691
|
+
params: {${formatParamProperties(
|
|
692
|
+
urlpath
|
|
693
|
+
)}} & { [key: string]: string | undefined }
|
|
694
|
+
module: Module
|
|
695
|
+
loaderData: T.CreateLoaderData<Module>
|
|
696
|
+
actionData: T.CreateActionData<Module>
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
export namespace Route {
|
|
700
|
+
export type LinkDescriptors = T.LinkDescriptors
|
|
701
|
+
export type LinksFunction = () => LinkDescriptors
|
|
702
|
+
|
|
703
|
+
export type MetaArgs = T.CreateMetaArgs<Info>
|
|
704
|
+
export type MetaDescriptors = T.MetaDescriptors
|
|
705
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
706
|
+
|
|
707
|
+
export type HeadersArgs = T.HeadersArgs
|
|
708
|
+
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
709
|
+
|
|
710
|
+
export type LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
711
|
+
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
712
|
+
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
713
|
+
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
714
|
+
|
|
715
|
+
export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
|
|
716
|
+
export type ComponentProps = T.CreateComponentProps<Info>
|
|
717
|
+
export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
|
|
718
|
+
}
|
|
719
|
+
`;
|
|
720
|
+
}
|
|
721
|
+
function getRouteLineage(routes2, route) {
|
|
722
|
+
const result = [];
|
|
723
|
+
while (route) {
|
|
724
|
+
result.push(route);
|
|
725
|
+
if (!route.parentId) break;
|
|
726
|
+
route = routes2[route.parentId];
|
|
727
|
+
}
|
|
728
|
+
result.reverse();
|
|
729
|
+
return result;
|
|
730
|
+
}
|
|
731
|
+
function formatParamProperties(urlpath) {
|
|
732
|
+
const params = parseParams(urlpath);
|
|
733
|
+
const properties = Object.entries(params).map(([name, values]) => {
|
|
734
|
+
if (values.length === 1) {
|
|
735
|
+
const isOptional = values[0];
|
|
736
|
+
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
737
|
+
}
|
|
738
|
+
const items = values.map(
|
|
739
|
+
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
740
|
+
);
|
|
741
|
+
return `"${name}": [${items.join(", ")}]`;
|
|
742
|
+
});
|
|
743
|
+
return properties.join("; ");
|
|
744
|
+
}
|
|
745
|
+
function parseParams(urlpath) {
|
|
746
|
+
const result = {};
|
|
747
|
+
let segments = urlpath.split("/");
|
|
748
|
+
segments.forEach((segment) => {
|
|
749
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
750
|
+
if (!match) return;
|
|
751
|
+
const param = match[1];
|
|
752
|
+
const isOptional = match[2] !== void 0;
|
|
753
|
+
result[param] ??= [];
|
|
754
|
+
result[param].push(isOptional);
|
|
755
|
+
return;
|
|
756
|
+
});
|
|
757
|
+
const hasSplat = segments.at(-1) === "*";
|
|
758
|
+
if (hasSplat) result["*"] = [false];
|
|
759
|
+
return result;
|
|
760
|
+
}
|
|
761
|
+
var import_dedent, Path3, Pathe2, noExtension;
|
|
762
|
+
var init_generate = __esm({
|
|
763
|
+
"typegen/generate.ts"() {
|
|
764
|
+
"use strict";
|
|
765
|
+
import_dedent = __toESM(require("dedent"));
|
|
766
|
+
Path3 = __toESM(require("pathe"));
|
|
767
|
+
Pathe2 = __toESM(require("pathe/utils"));
|
|
768
|
+
init_paths();
|
|
769
|
+
noExtension = (path10) => Path3.join(Path3.dirname(path10), Pathe2.filename(path10));
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
|
|
653
773
|
// typegen/index.ts
|
|
654
774
|
async function run(rootDirectory) {
|
|
655
775
|
const ctx = await createContext2({ rootDirectory, watch: false });
|
|
@@ -658,16 +778,16 @@ async function run(rootDirectory) {
|
|
|
658
778
|
async function watch(rootDirectory, { logger } = {}) {
|
|
659
779
|
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
660
780
|
await writeAll(ctx);
|
|
661
|
-
logger?.info(
|
|
781
|
+
logger?.info(import_picocolors3.default.green("generated types"), { timestamp: true, clear: true });
|
|
662
782
|
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
663
783
|
if (!result.ok) {
|
|
664
|
-
logger?.error(
|
|
784
|
+
logger?.error(import_picocolors3.default.red(result.error), { timestamp: true, clear: true });
|
|
665
785
|
return;
|
|
666
786
|
}
|
|
667
787
|
ctx.config = result.value;
|
|
668
788
|
if (routeConfigChanged) {
|
|
669
789
|
await writeAll(ctx);
|
|
670
|
-
logger?.info(
|
|
790
|
+
logger?.info(import_picocolors3.default.green("regenerated types"), {
|
|
671
791
|
timestamp: true,
|
|
672
792
|
clear: true
|
|
673
793
|
});
|
|
@@ -693,101 +813,23 @@ async function createContext2({
|
|
|
693
813
|
config
|
|
694
814
|
};
|
|
695
815
|
}
|
|
696
|
-
function asJS(path10) {
|
|
697
|
-
return path10.replace(/\.(js|ts)x?$/, ".js");
|
|
698
|
-
}
|
|
699
|
-
function formatRoute({ id, path: path10, file, parentId }) {
|
|
700
|
-
return [
|
|
701
|
-
`"${id}": {`,
|
|
702
|
-
` parentId: ${JSON.stringify(parentId)}`,
|
|
703
|
-
` path: ${JSON.stringify(path10)}`,
|
|
704
|
-
` module: typeof import("./app/${asJS(file)}")`,
|
|
705
|
-
`}`
|
|
706
|
-
].map((line) => ` ${line}`).join("\n");
|
|
707
|
-
}
|
|
708
816
|
async function writeAll(ctx) {
|
|
709
|
-
let routes2 = Object.values(ctx.config.routes);
|
|
710
|
-
let pathsToParams = /* @__PURE__ */ new Map();
|
|
711
|
-
for (let route of routes2) {
|
|
712
|
-
if (route.path === void 0) continue;
|
|
713
|
-
let lineage = getRouteLineage(ctx.config.routes, route);
|
|
714
|
-
let path10 = lineage.filter((route2) => route2.path !== void 0).map((route2) => route2.path).join("/");
|
|
715
|
-
if (path10 === "") path10 = "/";
|
|
716
|
-
pathsToParams.set(path10, parseParams(path10));
|
|
717
|
-
}
|
|
718
|
-
let formattedPaths = `type Paths = {`;
|
|
719
|
-
for (let [path10, params] of pathsToParams.entries()) {
|
|
720
|
-
let formattedParams = Object.entries(params).map(
|
|
721
|
-
([param, required]) => `"${param}"${required ? "" : "?"}: string`
|
|
722
|
-
);
|
|
723
|
-
let formattedEntry = `"${path10}": {${formattedParams.join(",")}},
|
|
724
|
-
`;
|
|
725
|
-
formattedPaths += formattedEntry;
|
|
726
|
-
}
|
|
727
|
-
formattedPaths += `}`;
|
|
728
817
|
const typegenDir = getTypesDir(ctx);
|
|
729
|
-
|
|
730
|
-
const newTypes = Path3.join(typegenDir, "routes.ts");
|
|
731
|
-
import_node_fs2.default.mkdirSync(Path3.dirname(newTypes), { recursive: true });
|
|
732
|
-
import_node_fs2.default.writeFileSync(
|
|
733
|
-
newTypes,
|
|
734
|
-
formattedPaths + `
|
|
735
|
-
|
|
736
|
-
type Routes = {
|
|
737
|
-
${routes2.map(formatRoute).join("\n")}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
` + import_dedent2.default`
|
|
741
|
-
declare module "react-router/types" {
|
|
742
|
-
interface Register {
|
|
743
|
-
paths: Paths
|
|
744
|
-
routes: Routes
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
export {}
|
|
749
|
-
`
|
|
750
|
-
);
|
|
818
|
+
import_node_fs3.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
751
819
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
752
820
|
const typesPath = getTypesPath(ctx, route);
|
|
753
|
-
const content = generate(route);
|
|
754
|
-
|
|
755
|
-
|
|
821
|
+
const content = generate(ctx, route);
|
|
822
|
+
import_node_fs3.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
823
|
+
import_node_fs3.default.writeFileSync(typesPath, content);
|
|
756
824
|
});
|
|
757
825
|
}
|
|
758
|
-
|
|
759
|
-
const result = [];
|
|
760
|
-
while (route) {
|
|
761
|
-
result.push(route);
|
|
762
|
-
if (!route.parentId) break;
|
|
763
|
-
route = routes2[route.parentId];
|
|
764
|
-
}
|
|
765
|
-
result.reverse();
|
|
766
|
-
return result;
|
|
767
|
-
}
|
|
768
|
-
function parseParams(urlpath) {
|
|
769
|
-
const result = {};
|
|
770
|
-
let segments = urlpath.split("/");
|
|
771
|
-
segments.forEach((segment) => {
|
|
772
|
-
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
773
|
-
if (!match) return;
|
|
774
|
-
const param = match[1];
|
|
775
|
-
const isRequired = match[2] === void 0;
|
|
776
|
-
result[param] ||= isRequired;
|
|
777
|
-
return;
|
|
778
|
-
});
|
|
779
|
-
const hasSplat = segments.at(-1) === "*";
|
|
780
|
-
if (hasSplat) result["*"] = true;
|
|
781
|
-
return result;
|
|
782
|
-
}
|
|
783
|
-
var import_node_fs2, import_dedent2, Path3, import_picocolors2;
|
|
826
|
+
var import_node_fs3, Path4, import_picocolors3;
|
|
784
827
|
var init_typegen = __esm({
|
|
785
828
|
"typegen/index.ts"() {
|
|
786
829
|
"use strict";
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
import_picocolors2 = __toESM(require("picocolors"));
|
|
830
|
+
import_node_fs3 = __toESM(require("fs"));
|
|
831
|
+
Path4 = __toESM(require("pathe"));
|
|
832
|
+
import_picocolors3 = __toESM(require("picocolors"));
|
|
791
833
|
init_config();
|
|
792
834
|
init_generate();
|
|
793
835
|
init_paths();
|
|
@@ -820,21 +862,21 @@ var init_node_adapter = __esm({
|
|
|
820
862
|
});
|
|
821
863
|
|
|
822
864
|
// vite/resolve-file-url.ts
|
|
823
|
-
var
|
|
865
|
+
var path5;
|
|
824
866
|
var init_resolve_file_url = __esm({
|
|
825
867
|
"vite/resolve-file-url.ts"() {
|
|
826
868
|
"use strict";
|
|
827
|
-
|
|
869
|
+
path5 = __toESM(require("path"));
|
|
828
870
|
init_vite();
|
|
829
871
|
}
|
|
830
872
|
});
|
|
831
873
|
|
|
832
874
|
// vite/styles.ts
|
|
833
|
-
var
|
|
875
|
+
var path6, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
834
876
|
var init_styles = __esm({
|
|
835
877
|
"vite/styles.ts"() {
|
|
836
878
|
"use strict";
|
|
837
|
-
|
|
879
|
+
path6 = __toESM(require("path"));
|
|
838
880
|
import_react_router = require("react-router");
|
|
839
881
|
init_resolve_file_url();
|
|
840
882
|
init_vite();
|
|
@@ -875,12 +917,43 @@ var init_remove_exports = __esm({
|
|
|
875
917
|
}
|
|
876
918
|
});
|
|
877
919
|
|
|
920
|
+
// vite/cache.ts
|
|
921
|
+
var init_cache = __esm({
|
|
922
|
+
"vite/cache.ts"() {
|
|
923
|
+
"use strict";
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
// vite/route-chunks.ts
|
|
928
|
+
var routeChunkExportNames, routeChunkNames, routeChunkQueryStringPrefix, routeChunkQueryStrings;
|
|
929
|
+
var init_route_chunks = __esm({
|
|
930
|
+
"vite/route-chunks.ts"() {
|
|
931
|
+
"use strict";
|
|
932
|
+
init_invariant();
|
|
933
|
+
init_cache();
|
|
934
|
+
init_babel();
|
|
935
|
+
routeChunkExportNames = [
|
|
936
|
+
"clientAction",
|
|
937
|
+
"clientLoader",
|
|
938
|
+
"HydrateFallback"
|
|
939
|
+
];
|
|
940
|
+
routeChunkNames = ["main", ...routeChunkExportNames];
|
|
941
|
+
routeChunkQueryStringPrefix = "?route-chunk=";
|
|
942
|
+
routeChunkQueryStrings = {
|
|
943
|
+
main: `${routeChunkQueryStringPrefix}main`,
|
|
944
|
+
clientAction: `${routeChunkQueryStringPrefix}clientAction`,
|
|
945
|
+
clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
|
|
946
|
+
HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
|
|
878
951
|
// vite/with-props.ts
|
|
879
|
-
var
|
|
952
|
+
var import_dedent2, vmod;
|
|
880
953
|
var init_with_props = __esm({
|
|
881
954
|
"vite/with-props.ts"() {
|
|
882
955
|
"use strict";
|
|
883
|
-
|
|
956
|
+
import_dedent2 = __toESM(require("dedent"));
|
|
884
957
|
init_babel();
|
|
885
958
|
init_virtual_module();
|
|
886
959
|
vmod = create("with-props");
|
|
@@ -911,56 +984,19 @@ async function resolveViteConfig({
|
|
|
911
984
|
async function extractPluginContext(viteConfig) {
|
|
912
985
|
return viteConfig["__reactRouterPluginContext"];
|
|
913
986
|
}
|
|
914
|
-
|
|
915
|
-
configFile,
|
|
916
|
-
root
|
|
917
|
-
}) {
|
|
918
|
-
if (!root) {
|
|
919
|
-
root = process.env.REACT_ROUTER_ROOT || process.cwd();
|
|
920
|
-
}
|
|
921
|
-
configFile = configFile ?? findConfig(root, "vite.config", [
|
|
922
|
-
".ts",
|
|
923
|
-
".cts",
|
|
924
|
-
".mts",
|
|
925
|
-
".js",
|
|
926
|
-
".cjs",
|
|
927
|
-
".mjs"
|
|
928
|
-
]);
|
|
929
|
-
if (!configFile) {
|
|
930
|
-
console.error(import_picocolors3.default.red("Vite config file not found"));
|
|
931
|
-
process.exit(1);
|
|
932
|
-
}
|
|
933
|
-
let viteConfig = await resolveViteConfig({ configFile, root });
|
|
934
|
-
let ctx = await extractPluginContext(viteConfig);
|
|
935
|
-
if (!ctx) {
|
|
936
|
-
console.error(
|
|
937
|
-
import_picocolors3.default.red("React Router Vite plugin not found in Vite config")
|
|
938
|
-
);
|
|
939
|
-
process.exit(1);
|
|
940
|
-
}
|
|
941
|
-
return ctx;
|
|
942
|
-
}
|
|
943
|
-
function findConfig(dir, basename2, extensions) {
|
|
944
|
-
for (let ext of extensions) {
|
|
945
|
-
let name = basename2 + ext;
|
|
946
|
-
let file = path6.join(dir, name);
|
|
947
|
-
if (fse.existsSync(file)) return file;
|
|
948
|
-
}
|
|
949
|
-
return void 0;
|
|
950
|
-
}
|
|
951
|
-
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;
|
|
987
|
+
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;
|
|
952
988
|
var init_plugin = __esm({
|
|
953
989
|
"vite/plugin.ts"() {
|
|
954
990
|
"use strict";
|
|
955
991
|
import_node_crypto = require("crypto");
|
|
956
|
-
|
|
992
|
+
path7 = __toESM(require("path"));
|
|
957
993
|
url = __toESM(require("url"));
|
|
958
994
|
fse = __toESM(require("fs-extra"));
|
|
959
|
-
|
|
995
|
+
babel2 = __toESM(require("@babel/core"));
|
|
960
996
|
import_react_router2 = require("react-router");
|
|
961
997
|
import_es_module_lexer = require("es-module-lexer");
|
|
962
998
|
import_jsesc = __toESM(require("jsesc"));
|
|
963
|
-
|
|
999
|
+
import_picocolors4 = __toESM(require("picocolors"));
|
|
964
1000
|
init_typegen();
|
|
965
1001
|
init_invariant();
|
|
966
1002
|
init_babel();
|
|
@@ -970,6 +1006,7 @@ var init_plugin = __esm({
|
|
|
970
1006
|
init_resolve_file_url();
|
|
971
1007
|
init_combine_urls();
|
|
972
1008
|
init_remove_exports();
|
|
1009
|
+
init_route_chunks();
|
|
973
1010
|
init_vite();
|
|
974
1011
|
init_config();
|
|
975
1012
|
init_with_props();
|
|
@@ -980,18 +1017,18 @@ var init_plugin = __esm({
|
|
|
980
1017
|
serverManifest: create("server-manifest"),
|
|
981
1018
|
browserManifest: create("browser-manifest")
|
|
982
1019
|
};
|
|
983
|
-
getServerBuildDirectory = (ctx) =>
|
|
1020
|
+
getServerBuildDirectory = (ctx) => path7.join(
|
|
984
1021
|
ctx.reactRouterConfig.buildDirectory,
|
|
985
1022
|
"server",
|
|
986
1023
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
987
1024
|
);
|
|
988
|
-
defaultEntriesDir =
|
|
989
|
-
|
|
1025
|
+
defaultEntriesDir = path7.resolve(
|
|
1026
|
+
path7.dirname(require.resolve("@react-router/dev/package.json")),
|
|
990
1027
|
"dist",
|
|
991
1028
|
"config",
|
|
992
1029
|
"defaults"
|
|
993
1030
|
);
|
|
994
|
-
defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
1031
|
+
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path7.join(defaultEntriesDir, filename3));
|
|
995
1032
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
996
1033
|
REACT_REFRESH_HEADER = `
|
|
997
1034
|
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
@@ -1017,45 +1054,6 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
1017
1054
|
}
|
|
1018
1055
|
});
|
|
1019
1056
|
|
|
1020
|
-
// vite/profiler.ts
|
|
1021
|
-
var import_node_fs3, import_node_path, import_picocolors4, getSession, start, profileCount, stop;
|
|
1022
|
-
var init_profiler = __esm({
|
|
1023
|
-
"vite/profiler.ts"() {
|
|
1024
|
-
"use strict";
|
|
1025
|
-
import_node_fs3 = __toESM(require("fs"));
|
|
1026
|
-
import_node_path = __toESM(require("path"));
|
|
1027
|
-
import_picocolors4 = __toESM(require("picocolors"));
|
|
1028
|
-
getSession = () => global.__reactRouter_profile_session;
|
|
1029
|
-
start = async (callback) => {
|
|
1030
|
-
let inspector = await import("inspector").then((r) => r.default);
|
|
1031
|
-
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
1032
|
-
session.connect();
|
|
1033
|
-
session.post("Profiler.enable", () => {
|
|
1034
|
-
session.post("Profiler.start", callback);
|
|
1035
|
-
});
|
|
1036
|
-
};
|
|
1037
|
-
profileCount = 0;
|
|
1038
|
-
stop = (log) => {
|
|
1039
|
-
let session = getSession();
|
|
1040
|
-
if (!session) return;
|
|
1041
|
-
return new Promise((res, rej) => {
|
|
1042
|
-
session.post("Profiler.stop", (err2, { profile }) => {
|
|
1043
|
-
if (err2) return rej(err2);
|
|
1044
|
-
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
1045
|
-
import_node_fs3.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
1046
|
-
log(
|
|
1047
|
-
import_picocolors4.default.yellow(
|
|
1048
|
-
`CPU profile written to ${import_picocolors4.default.white(import_picocolors4.default.dim(outPath))}`
|
|
1049
|
-
)
|
|
1050
|
-
);
|
|
1051
|
-
global.__reactRouter_profile_session = void 0;
|
|
1052
|
-
res();
|
|
1053
|
-
});
|
|
1054
|
-
});
|
|
1055
|
-
};
|
|
1056
|
-
}
|
|
1057
|
-
});
|
|
1058
|
-
|
|
1059
1057
|
// vite/build.ts
|
|
1060
1058
|
var build_exports = {};
|
|
1061
1059
|
__export(build_exports, {
|
|
@@ -1355,6 +1353,8 @@ var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
|
1355
1353
|
var import_package_json2 = __toESM(require("@npmcli/package-json"));
|
|
1356
1354
|
var import_exit_hook = __toESM(require("exit-hook"));
|
|
1357
1355
|
var import_picocolors7 = __toESM(require("picocolors"));
|
|
1356
|
+
var import_react_router3 = require("react-router");
|
|
1357
|
+
init_config();
|
|
1358
1358
|
|
|
1359
1359
|
// config/format.ts
|
|
1360
1360
|
function formatRoutes(routeManifest, format) {
|
|
@@ -1412,16 +1412,13 @@ function formatRoutesAsJsx(routeManifest) {
|
|
|
1412
1412
|
return output;
|
|
1413
1413
|
}
|
|
1414
1414
|
|
|
1415
|
-
// cli/commands.ts
|
|
1416
|
-
init_plugin();
|
|
1417
|
-
|
|
1418
1415
|
// cli/useJavascript.ts
|
|
1419
|
-
var
|
|
1416
|
+
var babel = __toESM(require("@babel/core"));
|
|
1420
1417
|
var import_plugin_syntax_jsx = __toESM(require("@babel/plugin-syntax-jsx"));
|
|
1421
1418
|
var import_preset_typescript = __toESM(require("@babel/preset-typescript"));
|
|
1422
1419
|
var import_prettier = __toESM(require("prettier"));
|
|
1423
1420
|
function transpile(tsx, options = {}) {
|
|
1424
|
-
let mjs =
|
|
1421
|
+
let mjs = babel.transformSync(tsx, {
|
|
1425
1422
|
compact: false,
|
|
1426
1423
|
cwd: options.cwd,
|
|
1427
1424
|
filename: options.filename,
|
|
@@ -1438,18 +1435,14 @@ init_profiler();
|
|
|
1438
1435
|
init_typegen();
|
|
1439
1436
|
init_vite();
|
|
1440
1437
|
async function routes(reactRouterRoot, flags = {}) {
|
|
1441
|
-
let
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
if (!ctx) {
|
|
1446
|
-
console.error(
|
|
1447
|
-
import_picocolors7.default.red("React Router Vite plugin not found in Vite config")
|
|
1448
|
-
);
|
|
1438
|
+
let rootDirectory = reactRouterRoot ?? process.cwd();
|
|
1439
|
+
let configResult = await loadConfig({ rootDirectory });
|
|
1440
|
+
if (!configResult.ok) {
|
|
1441
|
+
console.error(import_picocolors7.default.red(configResult.error));
|
|
1449
1442
|
process.exit(1);
|
|
1450
1443
|
}
|
|
1451
1444
|
let format = flags.json ? "json" : "jsx";
|
|
1452
|
-
console.log(formatRoutes(
|
|
1445
|
+
console.log(formatRoutes(configResult.value.routes, format));
|
|
1453
1446
|
}
|
|
1454
1447
|
async function build2(root, options = {}) {
|
|
1455
1448
|
if (!root) {
|
|
@@ -1483,17 +1476,18 @@ var conjunctionListFormat = new Intl.ListFormat("en", {
|
|
|
1483
1476
|
type: "conjunction"
|
|
1484
1477
|
});
|
|
1485
1478
|
async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
1486
|
-
let ctx = await loadPluginContext({
|
|
1487
|
-
root: reactRouterRoot,
|
|
1488
|
-
configFile: flags.config
|
|
1489
|
-
});
|
|
1490
|
-
let rootDirectory = ctx.rootDirectory;
|
|
1491
|
-
let appDirectory = ctx.reactRouterConfig.appDirectory;
|
|
1492
1479
|
if (!entry) {
|
|
1493
1480
|
await generateEntry("entry.client", reactRouterRoot, flags);
|
|
1494
1481
|
await generateEntry("entry.server", reactRouterRoot, flags);
|
|
1495
1482
|
return;
|
|
1496
1483
|
}
|
|
1484
|
+
let rootDirectory = reactRouterRoot ?? process.cwd();
|
|
1485
|
+
let configResult = await loadConfig({ rootDirectory });
|
|
1486
|
+
if (!configResult.ok) {
|
|
1487
|
+
console.error(import_picocolors7.default.red(configResult.error));
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
let appDirectory = configResult.value.appDirectory;
|
|
1497
1491
|
if (!entries.includes(entry)) {
|
|
1498
1492
|
let entriesArray = Array.from(entries);
|
|
1499
1493
|
let list = conjunctionListFormat.format(entriesArray);
|
|
@@ -1548,8 +1542,8 @@ async function checkForEntry(rootDirectory, appDirectory, entries2) {
|
|
|
1548
1542
|
let entryPath = path9.resolve(appDirectory, entry);
|
|
1549
1543
|
let exists = await import_fs_extra2.default.pathExists(entryPath);
|
|
1550
1544
|
if (exists) {
|
|
1551
|
-
let
|
|
1552
|
-
console.error(import_picocolors7.default.red(`Entry file ${
|
|
1545
|
+
let relative8 = path9.relative(rootDirectory, entryPath);
|
|
1546
|
+
console.error(import_picocolors7.default.red(`Entry file ${relative8} already exists.`));
|
|
1553
1547
|
return process.exit(1);
|
|
1554
1548
|
}
|
|
1555
1549
|
}
|
|
@@ -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
|
@@ -38,6 +38,10 @@ type ServerBundlesBuildManifest = BaseBuildManifest & {
|
|
|
38
38
|
type ServerModuleFormat = "esm" | "cjs";
|
|
39
39
|
interface FutureConfig {
|
|
40
40
|
unstable_optimizeDeps: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Automatically split route modules into multiple chunks when possible.
|
|
43
|
+
*/
|
|
44
|
+
unstable_splitRouteModules?: boolean | "enforce";
|
|
41
45
|
}
|
|
42
46
|
type BuildManifest = DefaultBuildManifest | ServerBundlesBuildManifest;
|
|
43
47
|
type BuildEndHook = (args: {
|
|
@@ -129,7 +133,7 @@ type ResolvedReactRouterConfig = Readonly<{
|
|
|
129
133
|
/**
|
|
130
134
|
* Enabled future flags
|
|
131
135
|
*/
|
|
132
|
-
future: FutureConfig
|
|
136
|
+
future: Required<FutureConfig>;
|
|
133
137
|
/**
|
|
134
138
|
* An array of URLs to prerender to HTML files at build time. Can also be a
|
|
135
139
|
* function returning an array to dynamically generate URLs.
|