@react-router/dev 0.0.0-experimental-9ea41ead4 → 0.0.0-experimental-759a11a62
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 +244 -233
- package/dist/config/defaults/entry.server.node.tsx +1 -1
- package/dist/config.d.ts +0 -4
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +177 -1079
- package/package.json +6 -14
- package/module-sync-enabled/false.cjs +0 -1
- package/module-sync-enabled/index.d.mts +0 -2
- package/module-sync-enabled/index.mjs +0 -4
- package/module-sync-enabled/true.mjs +0 -2
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-759a11a62
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -389,8 +389,7 @@ async function resolveConfig({
|
|
|
389
389
|
);
|
|
390
390
|
}
|
|
391
391
|
let future = {
|
|
392
|
-
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
393
|
-
unstable_splitRouteModules: reactRouterUserConfig.future?.unstable_splitRouteModules ?? false
|
|
392
|
+
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
394
393
|
};
|
|
395
394
|
let reactRouterConfig = deepFreeze({
|
|
396
395
|
appDirectory,
|
|
@@ -497,15 +496,6 @@ async function createConfigLoader({
|
|
|
497
496
|
}
|
|
498
497
|
};
|
|
499
498
|
}
|
|
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
|
-
}
|
|
509
499
|
function findEntry(dir, basename2, options) {
|
|
510
500
|
for (let ext of entryExts) {
|
|
511
501
|
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
@@ -596,42 +586,46 @@ var init_config = __esm({
|
|
|
596
586
|
}
|
|
597
587
|
});
|
|
598
588
|
|
|
599
|
-
//
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
589
|
+
// typegen/generate.ts
|
|
590
|
+
function generate(route) {
|
|
591
|
+
return import_dedent.default`
|
|
592
|
+
// React Router generated types for route:
|
|
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"() {
|
|
603
627
|
"use strict";
|
|
604
|
-
|
|
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
|
-
};
|
|
628
|
+
import_dedent = __toESM(require("dedent"));
|
|
635
629
|
}
|
|
636
630
|
});
|
|
637
631
|
|
|
@@ -656,119 +650,6 @@ var init_paths = __esm({
|
|
|
656
650
|
}
|
|
657
651
|
});
|
|
658
652
|
|
|
659
|
-
// typegen/generate.ts
|
|
660
|
-
function generate(ctx, route) {
|
|
661
|
-
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
662
|
-
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
663
|
-
const typesPath = getTypesPath(ctx, route);
|
|
664
|
-
const parents = lineage.slice(0, -1);
|
|
665
|
-
const parentTypeImports = parents.map((parent, i) => {
|
|
666
|
-
const rel = Path3.relative(
|
|
667
|
-
Path3.dirname(typesPath),
|
|
668
|
-
getTypesPath(ctx, parent)
|
|
669
|
-
);
|
|
670
|
-
const indent = i === 0 ? "" : " ".repeat(2);
|
|
671
|
-
let source = noExtension(rel);
|
|
672
|
-
if (!source.startsWith("../")) source = "./" + source;
|
|
673
|
-
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
674
|
-
}).join("\n");
|
|
675
|
-
return import_dedent.default`
|
|
676
|
-
// React Router generated types for route:
|
|
677
|
-
// ${route.file}
|
|
678
|
-
|
|
679
|
-
import type * as T from "react-router/route-module"
|
|
680
|
-
|
|
681
|
-
${parentTypeImports}
|
|
682
|
-
|
|
683
|
-
type Module = typeof import("../${Pathe2.filename(route.file)}.js")
|
|
684
|
-
|
|
685
|
-
export type Info = {
|
|
686
|
-
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
687
|
-
id: "${route.id}"
|
|
688
|
-
file: "${route.file}"
|
|
689
|
-
path: "${route.path}"
|
|
690
|
-
params: {${formatParamProperties(
|
|
691
|
-
urlpath
|
|
692
|
-
)}} & { [key: string]: string | undefined }
|
|
693
|
-
module: Module
|
|
694
|
-
loaderData: T.CreateLoaderData<Module>
|
|
695
|
-
actionData: T.CreateActionData<Module>
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
export namespace Route {
|
|
699
|
-
export type LinkDescriptors = T.LinkDescriptors
|
|
700
|
-
export type LinksFunction = () => LinkDescriptors
|
|
701
|
-
|
|
702
|
-
export type MetaArgs = T.CreateMetaArgs<Info>
|
|
703
|
-
export type MetaDescriptors = T.MetaDescriptors
|
|
704
|
-
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
705
|
-
|
|
706
|
-
export type HeadersArgs = T.HeadersArgs
|
|
707
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
708
|
-
|
|
709
|
-
export type LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
710
|
-
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
711
|
-
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
712
|
-
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
713
|
-
|
|
714
|
-
export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
|
|
715
|
-
export type ComponentProps = T.CreateComponentProps<Info>
|
|
716
|
-
export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
|
|
717
|
-
}
|
|
718
|
-
`;
|
|
719
|
-
}
|
|
720
|
-
function getRouteLineage(routes2, route) {
|
|
721
|
-
const result = [];
|
|
722
|
-
while (route) {
|
|
723
|
-
result.push(route);
|
|
724
|
-
if (!route.parentId) break;
|
|
725
|
-
route = routes2[route.parentId];
|
|
726
|
-
}
|
|
727
|
-
result.reverse();
|
|
728
|
-
return result;
|
|
729
|
-
}
|
|
730
|
-
function formatParamProperties(urlpath) {
|
|
731
|
-
const params = parseParams(urlpath);
|
|
732
|
-
const properties = Object.entries(params).map(([name, values]) => {
|
|
733
|
-
if (values.length === 1) {
|
|
734
|
-
const isOptional = values[0];
|
|
735
|
-
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
736
|
-
}
|
|
737
|
-
const items = values.map(
|
|
738
|
-
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
739
|
-
);
|
|
740
|
-
return `"${name}": [${items.join(", ")}]`;
|
|
741
|
-
});
|
|
742
|
-
return properties.join("; ");
|
|
743
|
-
}
|
|
744
|
-
function parseParams(urlpath) {
|
|
745
|
-
const result = {};
|
|
746
|
-
let segments = urlpath.split("/");
|
|
747
|
-
segments.forEach((segment) => {
|
|
748
|
-
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
749
|
-
if (!match) return;
|
|
750
|
-
const param = match[1];
|
|
751
|
-
const isOptional = match[2] !== void 0;
|
|
752
|
-
result[param] ??= [];
|
|
753
|
-
result[param].push(isOptional);
|
|
754
|
-
return;
|
|
755
|
-
});
|
|
756
|
-
const hasSplat = segments.at(-1) === "*";
|
|
757
|
-
if (hasSplat) result["*"] = [false];
|
|
758
|
-
return result;
|
|
759
|
-
}
|
|
760
|
-
var import_dedent, Path3, Pathe2, noExtension;
|
|
761
|
-
var init_generate = __esm({
|
|
762
|
-
"typegen/generate.ts"() {
|
|
763
|
-
"use strict";
|
|
764
|
-
import_dedent = __toESM(require("dedent"));
|
|
765
|
-
Path3 = __toESM(require("pathe"));
|
|
766
|
-
Pathe2 = __toESM(require("pathe/utils"));
|
|
767
|
-
init_paths();
|
|
768
|
-
noExtension = (path10) => Path3.join(Path3.dirname(path10), Pathe2.filename(path10));
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
|
|
772
653
|
// typegen/index.ts
|
|
773
654
|
async function run(rootDirectory) {
|
|
774
655
|
const ctx = await createContext2({ rootDirectory, watch: false });
|
|
@@ -777,16 +658,16 @@ async function run(rootDirectory) {
|
|
|
777
658
|
async function watch(rootDirectory, { logger } = {}) {
|
|
778
659
|
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
779
660
|
await writeAll(ctx);
|
|
780
|
-
logger?.info(
|
|
661
|
+
logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
|
|
781
662
|
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
782
663
|
if (!result.ok) {
|
|
783
|
-
logger?.error(
|
|
664
|
+
logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
|
|
784
665
|
return;
|
|
785
666
|
}
|
|
786
667
|
ctx.config = result.value;
|
|
787
668
|
if (routeConfigChanged) {
|
|
788
669
|
await writeAll(ctx);
|
|
789
|
-
logger?.info(
|
|
670
|
+
logger?.info(import_picocolors2.default.green("regenerated types"), {
|
|
790
671
|
timestamp: true,
|
|
791
672
|
clear: true
|
|
792
673
|
});
|
|
@@ -812,23 +693,105 @@ async function createContext2({
|
|
|
812
693
|
config
|
|
813
694
|
};
|
|
814
695
|
}
|
|
696
|
+
function asJS(path10) {
|
|
697
|
+
return path10.replace(/\.(js|ts)x?$/, ".js");
|
|
698
|
+
}
|
|
699
|
+
function formatRoute(ctx, { id, path: path10, file, parentId }) {
|
|
700
|
+
const modulePath = Path3.relative(
|
|
701
|
+
ctx.rootDirectory,
|
|
702
|
+
Path3.join(ctx.config.appDirectory, file)
|
|
703
|
+
);
|
|
704
|
+
return [
|
|
705
|
+
`"${id}": {`,
|
|
706
|
+
` parentId: ${JSON.stringify(parentId)}`,
|
|
707
|
+
` path: ${JSON.stringify(path10)}`,
|
|
708
|
+
` module: typeof import("${asJS(modulePath)}")`,
|
|
709
|
+
`}`
|
|
710
|
+
].map((line) => ` ${line}`).join("\n");
|
|
711
|
+
}
|
|
815
712
|
async function writeAll(ctx) {
|
|
713
|
+
let routes2 = Object.values(ctx.config.routes);
|
|
714
|
+
let pathsToParams = /* @__PURE__ */ new Map();
|
|
715
|
+
for (let route of routes2) {
|
|
716
|
+
if (route.path === void 0) continue;
|
|
717
|
+
let lineage = getRouteLineage(ctx.config.routes, route);
|
|
718
|
+
let path10 = lineage.filter((route2) => route2.path !== void 0).map((route2) => route2.path).join("/");
|
|
719
|
+
if (path10 === "") path10 = "/";
|
|
720
|
+
pathsToParams.set(path10, parseParams(path10));
|
|
721
|
+
}
|
|
722
|
+
let formattedPaths = `type Paths = {`;
|
|
723
|
+
for (let [path10, params] of pathsToParams.entries()) {
|
|
724
|
+
let formattedParams = Object.entries(params).map(
|
|
725
|
+
([param, required]) => `"${param}"${required ? "" : "?"}: string`
|
|
726
|
+
);
|
|
727
|
+
let formattedEntry = `"${path10}": {${formattedParams.join(",")}},
|
|
728
|
+
`;
|
|
729
|
+
formattedPaths += formattedEntry;
|
|
730
|
+
}
|
|
731
|
+
formattedPaths += `}`;
|
|
816
732
|
const typegenDir = getTypesDir(ctx);
|
|
817
|
-
|
|
733
|
+
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
734
|
+
const newTypes = Path3.join(typegenDir, "routes.ts");
|
|
735
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(newTypes), { recursive: true });
|
|
736
|
+
import_node_fs2.default.writeFileSync(
|
|
737
|
+
newTypes,
|
|
738
|
+
formattedPaths + `
|
|
739
|
+
|
|
740
|
+
type Routes = {
|
|
741
|
+
${routes2.map((route) => formatRoute(ctx, route)).join("\n")}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
` + import_dedent2.default`
|
|
745
|
+
declare module "react-router/types" {
|
|
746
|
+
interface Register {
|
|
747
|
+
paths: Paths
|
|
748
|
+
routes: Routes
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
export {}
|
|
753
|
+
`
|
|
754
|
+
);
|
|
818
755
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
819
756
|
const typesPath = getTypesPath(ctx, route);
|
|
820
|
-
const content = generate(
|
|
821
|
-
|
|
822
|
-
|
|
757
|
+
const content = generate(route);
|
|
758
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(typesPath), { recursive: true });
|
|
759
|
+
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
823
760
|
});
|
|
824
761
|
}
|
|
825
|
-
|
|
762
|
+
function getRouteLineage(routes2, route) {
|
|
763
|
+
const result = [];
|
|
764
|
+
while (route) {
|
|
765
|
+
result.push(route);
|
|
766
|
+
if (!route.parentId) break;
|
|
767
|
+
route = routes2[route.parentId];
|
|
768
|
+
}
|
|
769
|
+
result.reverse();
|
|
770
|
+
return result;
|
|
771
|
+
}
|
|
772
|
+
function parseParams(urlpath) {
|
|
773
|
+
const result = {};
|
|
774
|
+
let segments = urlpath.split("/");
|
|
775
|
+
segments.forEach((segment) => {
|
|
776
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
777
|
+
if (!match) return;
|
|
778
|
+
const param = match[1];
|
|
779
|
+
const isRequired = match[2] === void 0;
|
|
780
|
+
result[param] ||= isRequired;
|
|
781
|
+
return;
|
|
782
|
+
});
|
|
783
|
+
const hasSplat = segments.at(-1) === "*";
|
|
784
|
+
if (hasSplat) result["*"] = true;
|
|
785
|
+
return result;
|
|
786
|
+
}
|
|
787
|
+
var import_node_fs2, import_dedent2, Path3, import_picocolors2;
|
|
826
788
|
var init_typegen = __esm({
|
|
827
789
|
"typegen/index.ts"() {
|
|
828
790
|
"use strict";
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
791
|
+
import_node_fs2 = __toESM(require("fs"));
|
|
792
|
+
import_dedent2 = __toESM(require("dedent"));
|
|
793
|
+
Path3 = __toESM(require("pathe"));
|
|
794
|
+
import_picocolors2 = __toESM(require("picocolors"));
|
|
832
795
|
init_config();
|
|
833
796
|
init_generate();
|
|
834
797
|
init_paths();
|
|
@@ -861,21 +824,21 @@ var init_node_adapter = __esm({
|
|
|
861
824
|
});
|
|
862
825
|
|
|
863
826
|
// vite/resolve-file-url.ts
|
|
864
|
-
var
|
|
827
|
+
var path4;
|
|
865
828
|
var init_resolve_file_url = __esm({
|
|
866
829
|
"vite/resolve-file-url.ts"() {
|
|
867
830
|
"use strict";
|
|
868
|
-
|
|
831
|
+
path4 = __toESM(require("path"));
|
|
869
832
|
init_vite();
|
|
870
833
|
}
|
|
871
834
|
});
|
|
872
835
|
|
|
873
836
|
// vite/styles.ts
|
|
874
|
-
var
|
|
837
|
+
var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
875
838
|
var init_styles = __esm({
|
|
876
839
|
"vite/styles.ts"() {
|
|
877
840
|
"use strict";
|
|
878
|
-
|
|
841
|
+
path5 = __toESM(require("path"));
|
|
879
842
|
import_react_router = require("react-router");
|
|
880
843
|
init_resolve_file_url();
|
|
881
844
|
init_vite();
|
|
@@ -916,43 +879,12 @@ var init_remove_exports = __esm({
|
|
|
916
879
|
}
|
|
917
880
|
});
|
|
918
881
|
|
|
919
|
-
// vite/cache.ts
|
|
920
|
-
var init_cache = __esm({
|
|
921
|
-
"vite/cache.ts"() {
|
|
922
|
-
"use strict";
|
|
923
|
-
}
|
|
924
|
-
});
|
|
925
|
-
|
|
926
|
-
// vite/route-chunks.ts
|
|
927
|
-
var routeChunkExportNames, routeChunkNames, routeChunkQueryStringPrefix, routeChunkQueryStrings;
|
|
928
|
-
var init_route_chunks = __esm({
|
|
929
|
-
"vite/route-chunks.ts"() {
|
|
930
|
-
"use strict";
|
|
931
|
-
init_invariant();
|
|
932
|
-
init_cache();
|
|
933
|
-
init_babel();
|
|
934
|
-
routeChunkExportNames = [
|
|
935
|
-
"clientAction",
|
|
936
|
-
"clientLoader",
|
|
937
|
-
"HydrateFallback"
|
|
938
|
-
];
|
|
939
|
-
routeChunkNames = ["main", ...routeChunkExportNames];
|
|
940
|
-
routeChunkQueryStringPrefix = "?route-chunk=";
|
|
941
|
-
routeChunkQueryStrings = {
|
|
942
|
-
main: `${routeChunkQueryStringPrefix}main`,
|
|
943
|
-
clientAction: `${routeChunkQueryStringPrefix}clientAction`,
|
|
944
|
-
clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
|
|
945
|
-
HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
});
|
|
949
|
-
|
|
950
882
|
// vite/with-props.ts
|
|
951
|
-
var
|
|
883
|
+
var import_dedent3, vmod;
|
|
952
884
|
var init_with_props = __esm({
|
|
953
885
|
"vite/with-props.ts"() {
|
|
954
886
|
"use strict";
|
|
955
|
-
|
|
887
|
+
import_dedent3 = __toESM(require("dedent"));
|
|
956
888
|
init_babel();
|
|
957
889
|
init_virtual_module();
|
|
958
890
|
vmod = create("with-props");
|
|
@@ -983,19 +915,56 @@ async function resolveViteConfig({
|
|
|
983
915
|
async function extractPluginContext(viteConfig) {
|
|
984
916
|
return viteConfig["__reactRouterPluginContext"];
|
|
985
917
|
}
|
|
986
|
-
|
|
918
|
+
async function loadPluginContext({
|
|
919
|
+
configFile,
|
|
920
|
+
root
|
|
921
|
+
}) {
|
|
922
|
+
if (!root) {
|
|
923
|
+
root = process.env.REACT_ROUTER_ROOT || process.cwd();
|
|
924
|
+
}
|
|
925
|
+
configFile = configFile ?? findConfig(root, "vite.config", [
|
|
926
|
+
".ts",
|
|
927
|
+
".cts",
|
|
928
|
+
".mts",
|
|
929
|
+
".js",
|
|
930
|
+
".cjs",
|
|
931
|
+
".mjs"
|
|
932
|
+
]);
|
|
933
|
+
if (!configFile) {
|
|
934
|
+
console.error(import_picocolors3.default.red("Vite config file not found"));
|
|
935
|
+
process.exit(1);
|
|
936
|
+
}
|
|
937
|
+
let viteConfig = await resolveViteConfig({ configFile, root });
|
|
938
|
+
let ctx = await extractPluginContext(viteConfig);
|
|
939
|
+
if (!ctx) {
|
|
940
|
+
console.error(
|
|
941
|
+
import_picocolors3.default.red("React Router Vite plugin not found in Vite config")
|
|
942
|
+
);
|
|
943
|
+
process.exit(1);
|
|
944
|
+
}
|
|
945
|
+
return ctx;
|
|
946
|
+
}
|
|
947
|
+
function findConfig(dir, basename2, extensions) {
|
|
948
|
+
for (let ext of extensions) {
|
|
949
|
+
let name = basename2 + ext;
|
|
950
|
+
let file = path6.join(dir, name);
|
|
951
|
+
if (fse.existsSync(file)) return file;
|
|
952
|
+
}
|
|
953
|
+
return void 0;
|
|
954
|
+
}
|
|
955
|
+
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
956
|
var init_plugin = __esm({
|
|
988
957
|
"vite/plugin.ts"() {
|
|
989
958
|
"use strict";
|
|
990
959
|
import_node_crypto = require("crypto");
|
|
991
|
-
|
|
960
|
+
path6 = __toESM(require("path"));
|
|
992
961
|
url = __toESM(require("url"));
|
|
993
962
|
fse = __toESM(require("fs-extra"));
|
|
994
|
-
|
|
963
|
+
babel = __toESM(require("@babel/core"));
|
|
995
964
|
import_react_router2 = require("react-router");
|
|
996
965
|
import_es_module_lexer = require("es-module-lexer");
|
|
997
966
|
import_jsesc = __toESM(require("jsesc"));
|
|
998
|
-
|
|
967
|
+
import_picocolors3 = __toESM(require("picocolors"));
|
|
999
968
|
init_typegen();
|
|
1000
969
|
init_invariant();
|
|
1001
970
|
init_babel();
|
|
@@ -1005,7 +974,6 @@ var init_plugin = __esm({
|
|
|
1005
974
|
init_resolve_file_url();
|
|
1006
975
|
init_combine_urls();
|
|
1007
976
|
init_remove_exports();
|
|
1008
|
-
init_route_chunks();
|
|
1009
977
|
init_vite();
|
|
1010
978
|
init_config();
|
|
1011
979
|
init_with_props();
|
|
@@ -1016,18 +984,18 @@ var init_plugin = __esm({
|
|
|
1016
984
|
serverManifest: create("server-manifest"),
|
|
1017
985
|
browserManifest: create("browser-manifest")
|
|
1018
986
|
};
|
|
1019
|
-
getServerBuildDirectory = (ctx) =>
|
|
987
|
+
getServerBuildDirectory = (ctx) => path6.join(
|
|
1020
988
|
ctx.reactRouterConfig.buildDirectory,
|
|
1021
989
|
"server",
|
|
1022
990
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
1023
991
|
);
|
|
1024
|
-
defaultEntriesDir =
|
|
1025
|
-
|
|
992
|
+
defaultEntriesDir = path6.resolve(
|
|
993
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1026
994
|
"dist",
|
|
1027
995
|
"config",
|
|
1028
996
|
"defaults"
|
|
1029
997
|
);
|
|
1030
|
-
defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
998
|
+
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path6.join(defaultEntriesDir, filename2));
|
|
1031
999
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1032
1000
|
REACT_REFRESH_HEADER = `
|
|
1033
1001
|
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
@@ -1053,6 +1021,45 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
1053
1021
|
}
|
|
1054
1022
|
});
|
|
1055
1023
|
|
|
1024
|
+
// vite/profiler.ts
|
|
1025
|
+
var import_node_fs3, import_node_path, import_picocolors4, getSession, start, profileCount, stop;
|
|
1026
|
+
var init_profiler = __esm({
|
|
1027
|
+
"vite/profiler.ts"() {
|
|
1028
|
+
"use strict";
|
|
1029
|
+
import_node_fs3 = __toESM(require("fs"));
|
|
1030
|
+
import_node_path = __toESM(require("path"));
|
|
1031
|
+
import_picocolors4 = __toESM(require("picocolors"));
|
|
1032
|
+
getSession = () => global.__reactRouter_profile_session;
|
|
1033
|
+
start = async (callback) => {
|
|
1034
|
+
let inspector = await import("inspector").then((r) => r.default);
|
|
1035
|
+
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
1036
|
+
session.connect();
|
|
1037
|
+
session.post("Profiler.enable", () => {
|
|
1038
|
+
session.post("Profiler.start", callback);
|
|
1039
|
+
});
|
|
1040
|
+
};
|
|
1041
|
+
profileCount = 0;
|
|
1042
|
+
stop = (log) => {
|
|
1043
|
+
let session = getSession();
|
|
1044
|
+
if (!session) return;
|
|
1045
|
+
return new Promise((res, rej) => {
|
|
1046
|
+
session.post("Profiler.stop", (err2, { profile }) => {
|
|
1047
|
+
if (err2) return rej(err2);
|
|
1048
|
+
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
1049
|
+
import_node_fs3.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
1050
|
+
log(
|
|
1051
|
+
import_picocolors4.default.yellow(
|
|
1052
|
+
`CPU profile written to ${import_picocolors4.default.white(import_picocolors4.default.dim(outPath))}`
|
|
1053
|
+
)
|
|
1054
|
+
);
|
|
1055
|
+
global.__reactRouter_profile_session = void 0;
|
|
1056
|
+
res();
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1056
1063
|
// vite/build.ts
|
|
1057
1064
|
var build_exports = {};
|
|
1058
1065
|
__export(build_exports, {
|
|
@@ -1352,8 +1359,6 @@ var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
|
1352
1359
|
var import_package_json2 = __toESM(require("@npmcli/package-json"));
|
|
1353
1360
|
var import_exit_hook = __toESM(require("exit-hook"));
|
|
1354
1361
|
var import_picocolors7 = __toESM(require("picocolors"));
|
|
1355
|
-
var import_react_router3 = require("react-router");
|
|
1356
|
-
init_config();
|
|
1357
1362
|
|
|
1358
1363
|
// config/format.ts
|
|
1359
1364
|
function formatRoutes(routeManifest, format) {
|
|
@@ -1411,13 +1416,16 @@ function formatRoutesAsJsx(routeManifest) {
|
|
|
1411
1416
|
return output;
|
|
1412
1417
|
}
|
|
1413
1418
|
|
|
1419
|
+
// cli/commands.ts
|
|
1420
|
+
init_plugin();
|
|
1421
|
+
|
|
1414
1422
|
// cli/useJavascript.ts
|
|
1415
|
-
var
|
|
1423
|
+
var babel2 = __toESM(require("@babel/core"));
|
|
1416
1424
|
var import_plugin_syntax_jsx = __toESM(require("@babel/plugin-syntax-jsx"));
|
|
1417
1425
|
var import_preset_typescript = __toESM(require("@babel/preset-typescript"));
|
|
1418
1426
|
var import_prettier = __toESM(require("prettier"));
|
|
1419
1427
|
function transpile(tsx, options = {}) {
|
|
1420
|
-
let mjs =
|
|
1428
|
+
let mjs = babel2.transformSync(tsx, {
|
|
1421
1429
|
compact: false,
|
|
1422
1430
|
cwd: options.cwd,
|
|
1423
1431
|
filename: options.filename,
|
|
@@ -1434,14 +1442,18 @@ init_profiler();
|
|
|
1434
1442
|
init_typegen();
|
|
1435
1443
|
init_vite();
|
|
1436
1444
|
async function routes(reactRouterRoot, flags = {}) {
|
|
1437
|
-
let
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1445
|
+
let ctx = await loadPluginContext({
|
|
1446
|
+
root: reactRouterRoot,
|
|
1447
|
+
configFile: flags.config
|
|
1448
|
+
});
|
|
1449
|
+
if (!ctx) {
|
|
1450
|
+
console.error(
|
|
1451
|
+
import_picocolors7.default.red("React Router Vite plugin not found in Vite config")
|
|
1452
|
+
);
|
|
1441
1453
|
process.exit(1);
|
|
1442
1454
|
}
|
|
1443
1455
|
let format = flags.json ? "json" : "jsx";
|
|
1444
|
-
console.log(formatRoutes(
|
|
1456
|
+
console.log(formatRoutes(ctx.reactRouterConfig.routes, format));
|
|
1445
1457
|
}
|
|
1446
1458
|
async function build2(root, options = {}) {
|
|
1447
1459
|
if (!root) {
|
|
@@ -1475,18 +1487,17 @@ var conjunctionListFormat = new Intl.ListFormat("en", {
|
|
|
1475
1487
|
type: "conjunction"
|
|
1476
1488
|
});
|
|
1477
1489
|
async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
1490
|
+
let ctx = await loadPluginContext({
|
|
1491
|
+
root: reactRouterRoot,
|
|
1492
|
+
configFile: flags.config
|
|
1493
|
+
});
|
|
1494
|
+
let rootDirectory = ctx.rootDirectory;
|
|
1495
|
+
let appDirectory = ctx.reactRouterConfig.appDirectory;
|
|
1478
1496
|
if (!entry) {
|
|
1479
1497
|
await generateEntry("entry.client", reactRouterRoot, flags);
|
|
1480
1498
|
await generateEntry("entry.server", reactRouterRoot, flags);
|
|
1481
1499
|
return;
|
|
1482
1500
|
}
|
|
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;
|
|
1490
1501
|
if (!entries.includes(entry)) {
|
|
1491
1502
|
let entriesArray = Array.from(entries);
|
|
1492
1503
|
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 tine to
|
|
65
65
|
// flush down the rejected boundaries
|
|
66
66
|
setTimeout(abort, streamTimeout + 1000);
|
|
67
67
|
});
|
package/dist/config.d.ts
CHANGED
|
@@ -38,10 +38,6 @@ 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";
|
|
45
41
|
}
|
|
46
42
|
type BuildManifest = DefaultBuildManifest | ServerBundlesBuildManifest;
|
|
47
43
|
type BuildEndHook = (args: {
|
package/dist/config.js
CHANGED
package/dist/routes.js
CHANGED
package/dist/vite/cloudflare.js
CHANGED