@react-router/dev 0.0.0-experimental-759a11a62 → 0.0.0-experimental-beaa4f52a
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/CHANGELOG.md +23 -0
- package/dist/cli/index.js +201 -243
- package/dist/config/defaults/entry.server.node.tsx +1 -1
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +135 -136
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# `@react-router/dev`
|
|
2
2
|
|
|
3
|
+
## 7.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix `reveal` and `routes` CLI commands ([#12745](https://github.com/remix-run/react-router/pull/12745))
|
|
8
|
+
- Updated dependencies:
|
|
9
|
+
- `react-router@7.1.3`
|
|
10
|
+
- `@react-router/node@7.1.3`
|
|
11
|
+
- `@react-router/serve@7.1.3`
|
|
12
|
+
|
|
13
|
+
## 7.1.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Fix default external conditions in Vite v6. This fixes resolution issues with certain npm packages. ([#12644](https://github.com/remix-run/react-router/pull/12644))
|
|
18
|
+
- Fix mismatch in prerendering html/data files when path is missing a leading slash ([#12684](https://github.com/remix-run/react-router/pull/12684))
|
|
19
|
+
- Use `module-sync` server condition when enabled in the runtime. This fixes React context mismatches (e.g. `useHref() may be used only in the context of a <Router> component.`) during development on Node 22.10.0+ when using libraries that have a peer dependency on React Router. ([#12729](https://github.com/remix-run/react-router/pull/12729))
|
|
20
|
+
- Fix react-refresh source maps ([#12686](https://github.com/remix-run/react-router/pull/12686))
|
|
21
|
+
- Updated dependencies:
|
|
22
|
+
- `react-router@7.1.2`
|
|
23
|
+
- `@react-router/node@7.1.2`
|
|
24
|
+
- `@react-router/serve@7.1.2`
|
|
25
|
+
|
|
3
26
|
## 7.1.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
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-beaa4f52a
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -496,6 +496,15 @@ async function createConfigLoader({
|
|
|
496
496
|
}
|
|
497
497
|
};
|
|
498
498
|
}
|
|
499
|
+
async function loadConfig({ rootDirectory }) {
|
|
500
|
+
let configLoader = await createConfigLoader({
|
|
501
|
+
rootDirectory,
|
|
502
|
+
watch: false
|
|
503
|
+
});
|
|
504
|
+
let config = await configLoader.getConfig();
|
|
505
|
+
await configLoader.close();
|
|
506
|
+
return config;
|
|
507
|
+
}
|
|
499
508
|
function findEntry(dir, basename2, options) {
|
|
500
509
|
for (let ext of entryExts) {
|
|
501
510
|
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
@@ -586,46 +595,42 @@ var init_config = __esm({
|
|
|
586
595
|
}
|
|
587
596
|
});
|
|
588
597
|
|
|
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"() {
|
|
598
|
+
// vite/profiler.ts
|
|
599
|
+
var import_node_fs2, import_node_path, import_picocolors2, getSession, start, profileCount, stop;
|
|
600
|
+
var init_profiler = __esm({
|
|
601
|
+
"vite/profiler.ts"() {
|
|
627
602
|
"use strict";
|
|
628
|
-
|
|
603
|
+
import_node_fs2 = __toESM(require("fs"));
|
|
604
|
+
import_node_path = __toESM(require("path"));
|
|
605
|
+
import_picocolors2 = __toESM(require("picocolors"));
|
|
606
|
+
getSession = () => global.__reactRouter_profile_session;
|
|
607
|
+
start = async (callback) => {
|
|
608
|
+
let inspector = await import("inspector").then((r) => r.default);
|
|
609
|
+
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
610
|
+
session.connect();
|
|
611
|
+
session.post("Profiler.enable", () => {
|
|
612
|
+
session.post("Profiler.start", callback);
|
|
613
|
+
});
|
|
614
|
+
};
|
|
615
|
+
profileCount = 0;
|
|
616
|
+
stop = (log) => {
|
|
617
|
+
let session = getSession();
|
|
618
|
+
if (!session) return;
|
|
619
|
+
return new Promise((res, rej) => {
|
|
620
|
+
session.post("Profiler.stop", (err2, { profile }) => {
|
|
621
|
+
if (err2) return rej(err2);
|
|
622
|
+
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
623
|
+
import_node_fs2.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
624
|
+
log(
|
|
625
|
+
import_picocolors2.default.yellow(
|
|
626
|
+
`CPU profile written to ${import_picocolors2.default.white(import_picocolors2.default.dim(outPath))}`
|
|
627
|
+
)
|
|
628
|
+
);
|
|
629
|
+
global.__reactRouter_profile_session = void 0;
|
|
630
|
+
res();
|
|
631
|
+
});
|
|
632
|
+
});
|
|
633
|
+
};
|
|
629
634
|
}
|
|
630
635
|
});
|
|
631
636
|
|
|
@@ -650,6 +655,121 @@ var init_paths = __esm({
|
|
|
650
655
|
}
|
|
651
656
|
});
|
|
652
657
|
|
|
658
|
+
// typegen/generate.ts
|
|
659
|
+
function generate(ctx, route) {
|
|
660
|
+
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
661
|
+
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
662
|
+
const typesPath = getTypesPath(ctx, route);
|
|
663
|
+
const parents = lineage.slice(0, -1);
|
|
664
|
+
const parentTypeImports = parents.map((parent, i) => {
|
|
665
|
+
const rel = Path3.relative(
|
|
666
|
+
Path3.dirname(typesPath),
|
|
667
|
+
getTypesPath(ctx, parent)
|
|
668
|
+
);
|
|
669
|
+
const indent = i === 0 ? "" : " ".repeat(2);
|
|
670
|
+
let source = noExtension(rel);
|
|
671
|
+
if (!source.startsWith("../")) source = "./" + source;
|
|
672
|
+
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
673
|
+
}).join("\n");
|
|
674
|
+
return import_dedent.default`
|
|
675
|
+
// React Router generated types for route:
|
|
676
|
+
// ${route.file}
|
|
677
|
+
|
|
678
|
+
import type * as T from "react-router/route-module"
|
|
679
|
+
|
|
680
|
+
${parentTypeImports}
|
|
681
|
+
|
|
682
|
+
type Module = typeof import("../${Pathe2.filename(route.file)}.js")
|
|
683
|
+
|
|
684
|
+
export type Info = {
|
|
685
|
+
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
686
|
+
id: "${route.id}"
|
|
687
|
+
file: "${route.file}"
|
|
688
|
+
path: "${route.path}"
|
|
689
|
+
params: {${formatParamProperties(
|
|
690
|
+
urlpath
|
|
691
|
+
)}} & { [key: string]: string | undefined }
|
|
692
|
+
module: Module
|
|
693
|
+
loaderData: T.CreateLoaderData<Module>
|
|
694
|
+
actionData: T.CreateActionData<Module>
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
export namespace Route {
|
|
698
|
+
export type LinkDescriptors = T.LinkDescriptors
|
|
699
|
+
export type LinksFunction = () => LinkDescriptors
|
|
700
|
+
|
|
701
|
+
export type MetaArgs = T.CreateMetaArgs<Info>
|
|
702
|
+
export type MetaDescriptors = T.MetaDescriptors
|
|
703
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
704
|
+
|
|
705
|
+
export type HeadersArgs = T.HeadersArgs
|
|
706
|
+
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
707
|
+
|
|
708
|
+
export type MiddlewareArgs = T.CreateServerMiddlewareArgs<Info>
|
|
709
|
+
export type ClientMiddlewareArgs = T.CreateClientMiddlewareArgs<Info>
|
|
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,105 +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(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
|
-
}
|
|
712
816
|
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 += `}`;
|
|
732
817
|
const typegenDir = getTypesDir(ctx);
|
|
733
|
-
|
|
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
|
+
import_node_fs3.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
755
819
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
756
820
|
const typesPath = getTypesPath(ctx, route);
|
|
757
|
-
const content = generate(route);
|
|
758
|
-
|
|
759
|
-
|
|
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);
|
|
760
824
|
});
|
|
761
825
|
}
|
|
762
|
-
|
|
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
|
+
var import_node_fs3, Path4, import_picocolors3;
|
|
788
827
|
var init_typegen = __esm({
|
|
789
828
|
"typegen/index.ts"() {
|
|
790
829
|
"use strict";
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
import_picocolors2 = __toESM(require("picocolors"));
|
|
830
|
+
import_node_fs3 = __toESM(require("fs"));
|
|
831
|
+
Path4 = __toESM(require("pathe"));
|
|
832
|
+
import_picocolors3 = __toESM(require("picocolors"));
|
|
795
833
|
init_config();
|
|
796
834
|
init_generate();
|
|
797
835
|
init_paths();
|
|
@@ -824,21 +862,21 @@ var init_node_adapter = __esm({
|
|
|
824
862
|
});
|
|
825
863
|
|
|
826
864
|
// vite/resolve-file-url.ts
|
|
827
|
-
var
|
|
865
|
+
var path5;
|
|
828
866
|
var init_resolve_file_url = __esm({
|
|
829
867
|
"vite/resolve-file-url.ts"() {
|
|
830
868
|
"use strict";
|
|
831
|
-
|
|
869
|
+
path5 = __toESM(require("path"));
|
|
832
870
|
init_vite();
|
|
833
871
|
}
|
|
834
872
|
});
|
|
835
873
|
|
|
836
874
|
// vite/styles.ts
|
|
837
|
-
var
|
|
875
|
+
var path6, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
838
876
|
var init_styles = __esm({
|
|
839
877
|
"vite/styles.ts"() {
|
|
840
878
|
"use strict";
|
|
841
|
-
|
|
879
|
+
path6 = __toESM(require("path"));
|
|
842
880
|
import_react_router = require("react-router");
|
|
843
881
|
init_resolve_file_url();
|
|
844
882
|
init_vite();
|
|
@@ -880,11 +918,11 @@ var init_remove_exports = __esm({
|
|
|
880
918
|
});
|
|
881
919
|
|
|
882
920
|
// vite/with-props.ts
|
|
883
|
-
var
|
|
921
|
+
var import_dedent2, vmod;
|
|
884
922
|
var init_with_props = __esm({
|
|
885
923
|
"vite/with-props.ts"() {
|
|
886
924
|
"use strict";
|
|
887
|
-
|
|
925
|
+
import_dedent2 = __toESM(require("dedent"));
|
|
888
926
|
init_babel();
|
|
889
927
|
init_virtual_module();
|
|
890
928
|
vmod = create("with-props");
|
|
@@ -915,56 +953,19 @@ async function resolveViteConfig({
|
|
|
915
953
|
async function extractPluginContext(viteConfig) {
|
|
916
954
|
return viteConfig["__reactRouterPluginContext"];
|
|
917
955
|
}
|
|
918
|
-
|
|
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;
|
|
956
|
+
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;
|
|
956
957
|
var init_plugin = __esm({
|
|
957
958
|
"vite/plugin.ts"() {
|
|
958
959
|
"use strict";
|
|
959
960
|
import_node_crypto = require("crypto");
|
|
960
|
-
|
|
961
|
+
path7 = __toESM(require("path"));
|
|
961
962
|
url = __toESM(require("url"));
|
|
962
963
|
fse = __toESM(require("fs-extra"));
|
|
963
|
-
|
|
964
|
+
babel2 = __toESM(require("@babel/core"));
|
|
964
965
|
import_react_router2 = require("react-router");
|
|
965
966
|
import_es_module_lexer = require("es-module-lexer");
|
|
966
967
|
import_jsesc = __toESM(require("jsesc"));
|
|
967
|
-
|
|
968
|
+
import_picocolors4 = __toESM(require("picocolors"));
|
|
968
969
|
init_typegen();
|
|
969
970
|
init_invariant();
|
|
970
971
|
init_babel();
|
|
@@ -984,18 +985,18 @@ var init_plugin = __esm({
|
|
|
984
985
|
serverManifest: create("server-manifest"),
|
|
985
986
|
browserManifest: create("browser-manifest")
|
|
986
987
|
};
|
|
987
|
-
getServerBuildDirectory = (ctx) =>
|
|
988
|
+
getServerBuildDirectory = (ctx) => path7.join(
|
|
988
989
|
ctx.reactRouterConfig.buildDirectory,
|
|
989
990
|
"server",
|
|
990
991
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
991
992
|
);
|
|
992
|
-
defaultEntriesDir =
|
|
993
|
-
|
|
993
|
+
defaultEntriesDir = path7.resolve(
|
|
994
|
+
path7.dirname(require.resolve("@react-router/dev/package.json")),
|
|
994
995
|
"dist",
|
|
995
996
|
"config",
|
|
996
997
|
"defaults"
|
|
997
998
|
);
|
|
998
|
-
defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
999
|
+
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path7.join(defaultEntriesDir, filename3));
|
|
999
1000
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1000
1001
|
REACT_REFRESH_HEADER = `
|
|
1001
1002
|
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
@@ -1021,45 +1022,6 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
1021
1022
|
}
|
|
1022
1023
|
});
|
|
1023
1024
|
|
|
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
|
-
|
|
1063
1025
|
// vite/build.ts
|
|
1064
1026
|
var build_exports = {};
|
|
1065
1027
|
__export(build_exports, {
|
|
@@ -1359,6 +1321,8 @@ var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
|
1359
1321
|
var import_package_json2 = __toESM(require("@npmcli/package-json"));
|
|
1360
1322
|
var import_exit_hook = __toESM(require("exit-hook"));
|
|
1361
1323
|
var import_picocolors7 = __toESM(require("picocolors"));
|
|
1324
|
+
var import_react_router3 = require("react-router");
|
|
1325
|
+
init_config();
|
|
1362
1326
|
|
|
1363
1327
|
// config/format.ts
|
|
1364
1328
|
function formatRoutes(routeManifest, format) {
|
|
@@ -1416,16 +1380,13 @@ function formatRoutesAsJsx(routeManifest) {
|
|
|
1416
1380
|
return output;
|
|
1417
1381
|
}
|
|
1418
1382
|
|
|
1419
|
-
// cli/commands.ts
|
|
1420
|
-
init_plugin();
|
|
1421
|
-
|
|
1422
1383
|
// cli/useJavascript.ts
|
|
1423
|
-
var
|
|
1384
|
+
var babel = __toESM(require("@babel/core"));
|
|
1424
1385
|
var import_plugin_syntax_jsx = __toESM(require("@babel/plugin-syntax-jsx"));
|
|
1425
1386
|
var import_preset_typescript = __toESM(require("@babel/preset-typescript"));
|
|
1426
1387
|
var import_prettier = __toESM(require("prettier"));
|
|
1427
1388
|
function transpile(tsx, options = {}) {
|
|
1428
|
-
let mjs =
|
|
1389
|
+
let mjs = babel.transformSync(tsx, {
|
|
1429
1390
|
compact: false,
|
|
1430
1391
|
cwd: options.cwd,
|
|
1431
1392
|
filename: options.filename,
|
|
@@ -1442,18 +1403,14 @@ init_profiler();
|
|
|
1442
1403
|
init_typegen();
|
|
1443
1404
|
init_vite();
|
|
1444
1405
|
async function routes(reactRouterRoot, flags = {}) {
|
|
1445
|
-
let
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
if (!ctx) {
|
|
1450
|
-
console.error(
|
|
1451
|
-
import_picocolors7.default.red("React Router Vite plugin not found in Vite config")
|
|
1452
|
-
);
|
|
1406
|
+
let rootDirectory = reactRouterRoot ?? process.cwd();
|
|
1407
|
+
let configResult = await loadConfig({ rootDirectory });
|
|
1408
|
+
if (!configResult.ok) {
|
|
1409
|
+
console.error(import_picocolors7.default.red(configResult.error));
|
|
1453
1410
|
process.exit(1);
|
|
1454
1411
|
}
|
|
1455
1412
|
let format = flags.json ? "json" : "jsx";
|
|
1456
|
-
console.log(formatRoutes(
|
|
1413
|
+
console.log(formatRoutes(configResult.value.routes, format));
|
|
1457
1414
|
}
|
|
1458
1415
|
async function build2(root, options = {}) {
|
|
1459
1416
|
if (!root) {
|
|
@@ -1487,17 +1444,18 @@ var conjunctionListFormat = new Intl.ListFormat("en", {
|
|
|
1487
1444
|
type: "conjunction"
|
|
1488
1445
|
});
|
|
1489
1446
|
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;
|
|
1496
1447
|
if (!entry) {
|
|
1497
1448
|
await generateEntry("entry.client", reactRouterRoot, flags);
|
|
1498
1449
|
await generateEntry("entry.server", reactRouterRoot, flags);
|
|
1499
1450
|
return;
|
|
1500
1451
|
}
|
|
1452
|
+
let rootDirectory = reactRouterRoot ?? process.cwd();
|
|
1453
|
+
let configResult = await loadConfig({ rootDirectory });
|
|
1454
|
+
if (!configResult.ok) {
|
|
1455
|
+
console.error(import_picocolors7.default.red(configResult.error));
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
let appDirectory = configResult.value.appDirectory;
|
|
1501
1459
|
if (!entries.includes(entry)) {
|
|
1502
1460
|
let entriesArray = Array.from(entries);
|
|
1503
1461
|
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.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-beaa4f52a
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -57,8 +57,7 @@ var import_picocolors3 = __toESM(require("picocolors"));
|
|
|
57
57
|
|
|
58
58
|
// typegen/index.ts
|
|
59
59
|
var import_node_fs2 = __toESM(require("fs"));
|
|
60
|
-
var
|
|
61
|
-
var Path3 = __toESM(require("pathe"));
|
|
60
|
+
var Path4 = __toESM(require("pathe"));
|
|
62
61
|
var import_picocolors2 = __toESM(require("picocolors"));
|
|
63
62
|
|
|
64
63
|
// config/config.ts
|
|
@@ -625,54 +624,127 @@ function findEntry(dir, basename2, options) {
|
|
|
625
624
|
|
|
626
625
|
// typegen/generate.ts
|
|
627
626
|
var import_dedent = __toESM(require("dedent"));
|
|
628
|
-
|
|
627
|
+
var Path3 = __toESM(require("pathe"));
|
|
628
|
+
var Pathe2 = __toESM(require("pathe/utils"));
|
|
629
|
+
|
|
630
|
+
// typegen/paths.ts
|
|
631
|
+
var Path2 = __toESM(require("pathe"));
|
|
632
|
+
var Pathe = __toESM(require("pathe/utils"));
|
|
633
|
+
function getTypesDir(ctx) {
|
|
634
|
+
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
635
|
+
}
|
|
636
|
+
function getTypesPath(ctx, route) {
|
|
637
|
+
return Path2.join(
|
|
638
|
+
getTypesDir(ctx),
|
|
639
|
+
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
640
|
+
Path2.dirname(route.file),
|
|
641
|
+
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// typegen/generate.ts
|
|
646
|
+
function generate(ctx, route) {
|
|
647
|
+
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
648
|
+
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
649
|
+
const typesPath = getTypesPath(ctx, route);
|
|
650
|
+
const parents = lineage.slice(0, -1);
|
|
651
|
+
const parentTypeImports = parents.map((parent, i) => {
|
|
652
|
+
const rel = Path3.relative(
|
|
653
|
+
Path3.dirname(typesPath),
|
|
654
|
+
getTypesPath(ctx, parent)
|
|
655
|
+
);
|
|
656
|
+
const indent = i === 0 ? "" : " ".repeat(2);
|
|
657
|
+
let source = noExtension(rel);
|
|
658
|
+
if (!source.startsWith("../")) source = "./" + source;
|
|
659
|
+
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
660
|
+
}).join("\n");
|
|
629
661
|
return import_dedent.default`
|
|
630
662
|
// React Router generated types for route:
|
|
631
663
|
// ${route.file}
|
|
632
664
|
|
|
633
|
-
import type
|
|
665
|
+
import type * as T from "react-router/route-module"
|
|
634
666
|
|
|
635
|
-
|
|
636
|
-
export type Info = Routes[RouteId];
|
|
667
|
+
${parentTypeImports}
|
|
637
668
|
|
|
638
|
-
type
|
|
669
|
+
type Module = typeof import("../${Pathe2.filename(route.file)}.js")
|
|
670
|
+
|
|
671
|
+
export type Info = {
|
|
672
|
+
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
673
|
+
id: "${route.id}"
|
|
674
|
+
file: "${route.file}"
|
|
675
|
+
path: "${route.path}"
|
|
676
|
+
params: {${formatParamProperties(
|
|
677
|
+
urlpath
|
|
678
|
+
)}} & { [key: string]: string | undefined }
|
|
679
|
+
module: Module
|
|
680
|
+
loaderData: T.CreateLoaderData<Module>
|
|
681
|
+
actionData: T.CreateActionData<Module>
|
|
682
|
+
}
|
|
639
683
|
|
|
640
684
|
export namespace Route {
|
|
641
|
-
export type LinkDescriptors =
|
|
642
|
-
export type LinksFunction = () => LinkDescriptors
|
|
685
|
+
export type LinkDescriptors = T.LinkDescriptors
|
|
686
|
+
export type LinksFunction = () => LinkDescriptors
|
|
643
687
|
|
|
644
|
-
export type MetaArgs =
|
|
645
|
-
export type MetaDescriptors =
|
|
646
|
-
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
688
|
+
export type MetaArgs = T.CreateMetaArgs<Info>
|
|
689
|
+
export type MetaDescriptors = T.MetaDescriptors
|
|
690
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
647
691
|
|
|
648
|
-
export type HeadersArgs =
|
|
649
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
692
|
+
export type HeadersArgs = T.HeadersArgs
|
|
693
|
+
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
650
694
|
|
|
651
|
-
export type
|
|
652
|
-
export type
|
|
653
|
-
export type
|
|
654
|
-
export type
|
|
695
|
+
export type MiddlewareArgs = T.CreateServerMiddlewareArgs<Info>
|
|
696
|
+
export type ClientMiddlewareArgs = T.CreateClientMiddlewareArgs<Info>
|
|
697
|
+
export type LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
698
|
+
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
699
|
+
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
700
|
+
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
655
701
|
|
|
656
|
-
export type HydrateFallbackProps =
|
|
657
|
-
export type ComponentProps =
|
|
658
|
-
export type ErrorBoundaryProps =
|
|
702
|
+
export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
|
|
703
|
+
export type ComponentProps = T.CreateComponentProps<Info>
|
|
704
|
+
export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
|
|
659
705
|
}
|
|
660
706
|
`;
|
|
661
707
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
708
|
+
var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
|
|
709
|
+
function getRouteLineage(routes, route) {
|
|
710
|
+
const result = [];
|
|
711
|
+
while (route) {
|
|
712
|
+
result.push(route);
|
|
713
|
+
if (!route.parentId) break;
|
|
714
|
+
route = routes[route.parentId];
|
|
715
|
+
}
|
|
716
|
+
result.reverse();
|
|
717
|
+
return result;
|
|
668
718
|
}
|
|
669
|
-
function
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
719
|
+
function formatParamProperties(urlpath) {
|
|
720
|
+
const params = parseParams(urlpath);
|
|
721
|
+
const properties = Object.entries(params).map(([name, values]) => {
|
|
722
|
+
if (values.length === 1) {
|
|
723
|
+
const isOptional = values[0];
|
|
724
|
+
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
725
|
+
}
|
|
726
|
+
const items = values.map(
|
|
727
|
+
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
728
|
+
);
|
|
729
|
+
return `"${name}": [${items.join(", ")}]`;
|
|
730
|
+
});
|
|
731
|
+
return properties.join("; ");
|
|
732
|
+
}
|
|
733
|
+
function parseParams(urlpath) {
|
|
734
|
+
const result = {};
|
|
735
|
+
let segments = urlpath.split("/");
|
|
736
|
+
segments.forEach((segment) => {
|
|
737
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
738
|
+
if (!match) return;
|
|
739
|
+
const param = match[1];
|
|
740
|
+
const isOptional = match[2] !== void 0;
|
|
741
|
+
result[param] ??= [];
|
|
742
|
+
result[param].push(isOptional);
|
|
743
|
+
return;
|
|
744
|
+
});
|
|
745
|
+
const hasSplat = segments.at(-1) === "*";
|
|
746
|
+
if (hasSplat) result["*"] = [false];
|
|
747
|
+
return result;
|
|
676
748
|
}
|
|
677
749
|
|
|
678
750
|
// typegen/index.ts
|
|
@@ -714,97 +786,16 @@ async function createContext2({
|
|
|
714
786
|
config
|
|
715
787
|
};
|
|
716
788
|
}
|
|
717
|
-
function asJS(path7) {
|
|
718
|
-
return path7.replace(/\.(js|ts)x?$/, ".js");
|
|
719
|
-
}
|
|
720
|
-
function formatRoute(ctx, { id, path: path7, file, parentId }) {
|
|
721
|
-
const modulePath = Path3.relative(
|
|
722
|
-
ctx.rootDirectory,
|
|
723
|
-
Path3.join(ctx.config.appDirectory, file)
|
|
724
|
-
);
|
|
725
|
-
return [
|
|
726
|
-
`"${id}": {`,
|
|
727
|
-
` parentId: ${JSON.stringify(parentId)}`,
|
|
728
|
-
` path: ${JSON.stringify(path7)}`,
|
|
729
|
-
` module: typeof import("${asJS(modulePath)}")`,
|
|
730
|
-
`}`
|
|
731
|
-
].map((line) => ` ${line}`).join("\n");
|
|
732
|
-
}
|
|
733
789
|
async function writeAll(ctx) {
|
|
734
|
-
let routes = Object.values(ctx.config.routes);
|
|
735
|
-
let pathsToParams = /* @__PURE__ */ new Map();
|
|
736
|
-
for (let route of routes) {
|
|
737
|
-
if (route.path === void 0) continue;
|
|
738
|
-
let lineage = getRouteLineage(ctx.config.routes, route);
|
|
739
|
-
let path7 = lineage.filter((route2) => route2.path !== void 0).map((route2) => route2.path).join("/");
|
|
740
|
-
if (path7 === "") path7 = "/";
|
|
741
|
-
pathsToParams.set(path7, parseParams(path7));
|
|
742
|
-
}
|
|
743
|
-
let formattedPaths = `type Paths = {`;
|
|
744
|
-
for (let [path7, params] of pathsToParams.entries()) {
|
|
745
|
-
let formattedParams = Object.entries(params).map(
|
|
746
|
-
([param, required]) => `"${param}"${required ? "" : "?"}: string`
|
|
747
|
-
);
|
|
748
|
-
let formattedEntry = `"${path7}": {${formattedParams.join(",")}},
|
|
749
|
-
`;
|
|
750
|
-
formattedPaths += formattedEntry;
|
|
751
|
-
}
|
|
752
|
-
formattedPaths += `}`;
|
|
753
790
|
const typegenDir = getTypesDir(ctx);
|
|
754
791
|
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
755
|
-
const newTypes = Path3.join(typegenDir, "routes.ts");
|
|
756
|
-
import_node_fs2.default.mkdirSync(Path3.dirname(newTypes), { recursive: true });
|
|
757
|
-
import_node_fs2.default.writeFileSync(
|
|
758
|
-
newTypes,
|
|
759
|
-
formattedPaths + `
|
|
760
|
-
|
|
761
|
-
type Routes = {
|
|
762
|
-
${routes.map((route) => formatRoute(ctx, route)).join("\n")}
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
` + import_dedent2.default`
|
|
766
|
-
declare module "react-router/types" {
|
|
767
|
-
interface Register {
|
|
768
|
-
paths: Paths
|
|
769
|
-
routes: Routes
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
export {}
|
|
774
|
-
`
|
|
775
|
-
);
|
|
776
792
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
777
793
|
const typesPath = getTypesPath(ctx, route);
|
|
778
|
-
const content = generate(route);
|
|
779
|
-
import_node_fs2.default.mkdirSync(
|
|
794
|
+
const content = generate(ctx, route);
|
|
795
|
+
import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
780
796
|
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
781
797
|
});
|
|
782
798
|
}
|
|
783
|
-
function getRouteLineage(routes, route) {
|
|
784
|
-
const result = [];
|
|
785
|
-
while (route) {
|
|
786
|
-
result.push(route);
|
|
787
|
-
if (!route.parentId) break;
|
|
788
|
-
route = routes[route.parentId];
|
|
789
|
-
}
|
|
790
|
-
result.reverse();
|
|
791
|
-
return result;
|
|
792
|
-
}
|
|
793
|
-
function parseParams(urlpath) {
|
|
794
|
-
const result = {};
|
|
795
|
-
let segments = urlpath.split("/");
|
|
796
|
-
segments.forEach((segment) => {
|
|
797
|
-
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
798
|
-
if (!match) return;
|
|
799
|
-
const param = match[1];
|
|
800
|
-
const isRequired = match[2] === void 0;
|
|
801
|
-
result[param] ||= isRequired;
|
|
802
|
-
return;
|
|
803
|
-
});
|
|
804
|
-
const hasSplat = segments.at(-1) === "*";
|
|
805
|
-
if (hasSplat) result["*"] = true;
|
|
806
|
-
return result;
|
|
807
|
-
}
|
|
808
799
|
|
|
809
800
|
// vite/babel.ts
|
|
810
801
|
var import_parser = require("@babel/parser");
|
|
@@ -1171,7 +1162,7 @@ function invalidDestructureError(name) {
|
|
|
1171
1162
|
}
|
|
1172
1163
|
|
|
1173
1164
|
// vite/with-props.ts
|
|
1174
|
-
var
|
|
1165
|
+
var import_dedent2 = __toESM(require("dedent"));
|
|
1175
1166
|
var vmod = create("with-props");
|
|
1176
1167
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
1177
1168
|
var plugin = {
|
|
@@ -1182,7 +1173,7 @@ var plugin = {
|
|
|
1182
1173
|
},
|
|
1183
1174
|
async load(id) {
|
|
1184
1175
|
if (id !== vmod.resolvedId) return;
|
|
1185
|
-
return
|
|
1176
|
+
return import_dedent2.default`
|
|
1186
1177
|
import { createElement as h } from "react";
|
|
1187
1178
|
import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
|
|
1188
1179
|
|
|
@@ -1295,10 +1286,11 @@ function toFunctionExpression(decl) {
|
|
|
1295
1286
|
}
|
|
1296
1287
|
|
|
1297
1288
|
// vite/plugin.ts
|
|
1298
|
-
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "headers"];
|
|
1289
|
+
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "middleware", "headers"];
|
|
1299
1290
|
var CLIENT_ROUTE_EXPORTS = [
|
|
1300
1291
|
"clientAction",
|
|
1301
1292
|
"clientLoader",
|
|
1293
|
+
"clientMiddleware",
|
|
1302
1294
|
"default",
|
|
1303
1295
|
"ErrorBoundary",
|
|
1304
1296
|
"handle",
|
|
@@ -1447,7 +1439,7 @@ var defaultEntriesDir = path6.resolve(
|
|
|
1447
1439
|
"config",
|
|
1448
1440
|
"defaults"
|
|
1449
1441
|
);
|
|
1450
|
-
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
1442
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
|
|
1451
1443
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1452
1444
|
var reactRouterDevLoadContext = () => ({});
|
|
1453
1445
|
var reactRouterVitePlugin = () => {
|
|
@@ -1715,8 +1707,13 @@ var reactRouterVitePlugin = () => {
|
|
|
1715
1707
|
let viteClientConditions = [
|
|
1716
1708
|
...vite2.defaultClientConditions ?? []
|
|
1717
1709
|
];
|
|
1710
|
+
let packageRoot = path6.dirname(
|
|
1711
|
+
require.resolve("@react-router/dev/package.json")
|
|
1712
|
+
);
|
|
1713
|
+
let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
1718
1714
|
let viteServerConditions = [
|
|
1719
|
-
...vite2.defaultServerConditions ?? []
|
|
1715
|
+
...vite2.defaultServerConditions ?? [],
|
|
1716
|
+
...moduleSyncEnabled ? ["module-sync"] : []
|
|
1720
1717
|
];
|
|
1721
1718
|
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
1722
1719
|
prefix: "[react-router]"
|
|
@@ -1773,9 +1770,9 @@ var reactRouterVitePlugin = () => {
|
|
|
1773
1770
|
},
|
|
1774
1771
|
optimizeDeps: {
|
|
1775
1772
|
entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
|
|
1776
|
-
ctx.entryClientFilePath,
|
|
1773
|
+
vite2.normalizePath(ctx.entryClientFilePath),
|
|
1777
1774
|
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1778
|
-
(route) =>
|
|
1775
|
+
(route) => resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
1779
1776
|
)
|
|
1780
1777
|
] : [],
|
|
1781
1778
|
include: [
|
|
@@ -2073,6 +2070,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2073
2070
|
viteConfig,
|
|
2074
2071
|
ctx.reactRouterConfig,
|
|
2075
2072
|
serverBuildDirectory,
|
|
2073
|
+
ssrViteManifest[virtual.serverBuild.id].file,
|
|
2076
2074
|
clientBuildDirectory
|
|
2077
2075
|
);
|
|
2078
2076
|
}
|
|
@@ -2081,6 +2079,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2081
2079
|
viteConfig,
|
|
2082
2080
|
ctx.reactRouterConfig,
|
|
2083
2081
|
serverBuildDirectory,
|
|
2082
|
+
ssrViteManifest[virtual.serverBuild.id].file,
|
|
2084
2083
|
clientBuildDirectory
|
|
2085
2084
|
);
|
|
2086
2085
|
}
|
|
@@ -2424,6 +2423,7 @@ function addRefreshWrapper(reactRouterConfig, code, id) {
|
|
|
2424
2423
|
let acceptExports = route ? [
|
|
2425
2424
|
"clientAction",
|
|
2426
2425
|
"clientLoader",
|
|
2426
|
+
"clientMiddleware",
|
|
2427
2427
|
"handle",
|
|
2428
2428
|
"meta",
|
|
2429
2429
|
"links",
|
|
@@ -2513,11 +2513,8 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
|
|
|
2513
2513
|
};
|
|
2514
2514
|
return info;
|
|
2515
2515
|
}
|
|
2516
|
-
async function getPrerenderBuildAndHandler(viteConfig,
|
|
2517
|
-
let serverBuildPath = path6.join(
|
|
2518
|
-
serverBuildDirectory,
|
|
2519
|
-
reactRouterConfig.serverBuildFile
|
|
2520
|
-
);
|
|
2516
|
+
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
2517
|
+
let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
|
|
2521
2518
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
2522
2519
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
2523
2520
|
return {
|
|
@@ -2525,11 +2522,11 @@ async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, server
|
|
|
2525
2522
|
handler: createHandler(build, viteConfig.mode)
|
|
2526
2523
|
};
|
|
2527
2524
|
}
|
|
2528
|
-
async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
|
|
2525
|
+
async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildFile, clientBuildDirectory) {
|
|
2529
2526
|
let { handler } = await getPrerenderBuildAndHandler(
|
|
2530
2527
|
viteConfig,
|
|
2531
|
-
|
|
2532
|
-
|
|
2528
|
+
serverBuildDirectory,
|
|
2529
|
+
serverBuildFile
|
|
2533
2530
|
);
|
|
2534
2531
|
let request = new Request(`http://localhost${reactRouterConfig.basename}`);
|
|
2535
2532
|
let response = await handler(request);
|
|
@@ -2541,11 +2538,11 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
2541
2538
|
"SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path6.relative(process.cwd(), clientBuildDirectory)) + " directory"
|
|
2542
2539
|
);
|
|
2543
2540
|
}
|
|
2544
|
-
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
|
|
2541
|
+
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildPath, clientBuildDirectory) {
|
|
2545
2542
|
let { build, handler } = await getPrerenderBuildAndHandler(
|
|
2546
2543
|
viteConfig,
|
|
2547
|
-
|
|
2548
|
-
|
|
2544
|
+
serverBuildDirectory,
|
|
2545
|
+
serverBuildPath
|
|
2549
2546
|
);
|
|
2550
2547
|
let routes = createPrerenderRoutes(build.routes);
|
|
2551
2548
|
let routesToPrerender;
|
|
@@ -2741,6 +2738,8 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
|
|
|
2741
2738
|
loader: route.module.loader ? () => null : void 0,
|
|
2742
2739
|
action: void 0,
|
|
2743
2740
|
handle: route.module.handle
|
|
2741
|
+
// middleware is not necessary here since we just need to know which
|
|
2742
|
+
// routes have loaders so we know what paths to prerender
|
|
2744
2743
|
};
|
|
2745
2744
|
return route.index ? {
|
|
2746
2745
|
index: true,
|
|
@@ -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-beaa4f52a",
|
|
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-beaa4f52a"
|
|
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": "
|
|
114
|
-
"
|
|
120
|
+
"@react-router/serve": "0.0.0-experimental-beaa4f52a",
|
|
121
|
+
"react-router": "^0.0.0-experimental-beaa4f52a"
|
|
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-beaa4f52a",
|
|
128
|
+
"react-router": "^0.0.0-experimental-beaa4f52a"
|
|
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",
|