@react-router/dev 0.0.0-experimental-df6bc686c → 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 -234
- package/dist/config/defaults/entry.server.node.tsx +1 -1
- package/dist/config.d.ts +1 -5
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/static/refresh-utils.cjs +0 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +177 -1074
- 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
|
*
|
|
@@ -317,7 +317,6 @@ async function resolveConfig({
|
|
|
317
317
|
basename: basename2,
|
|
318
318
|
buildDirectory: userBuildDirectory,
|
|
319
319
|
buildEnd,
|
|
320
|
-
future: userFuture,
|
|
321
320
|
prerender,
|
|
322
321
|
serverBuildFile,
|
|
323
322
|
serverBundles,
|
|
@@ -390,8 +389,7 @@ async function resolveConfig({
|
|
|
390
389
|
);
|
|
391
390
|
}
|
|
392
391
|
let future = {
|
|
393
|
-
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
394
|
-
unstable_splitRouteModules: userFuture?.unstable_splitRouteModules ?? false
|
|
392
|
+
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
395
393
|
};
|
|
396
394
|
let reactRouterConfig = deepFreeze({
|
|
397
395
|
appDirectory,
|
|
@@ -498,15 +496,6 @@ async function createConfigLoader({
|
|
|
498
496
|
}
|
|
499
497
|
};
|
|
500
498
|
}
|
|
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
|
-
}
|
|
510
499
|
function findEntry(dir, basename2, options) {
|
|
511
500
|
for (let ext of entryExts) {
|
|
512
501
|
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
@@ -597,42 +586,46 @@ var init_config = __esm({
|
|
|
597
586
|
}
|
|
598
587
|
});
|
|
599
588
|
|
|
600
|
-
//
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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"() {
|
|
604
627
|
"use strict";
|
|
605
|
-
|
|
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
|
-
};
|
|
628
|
+
import_dedent = __toESM(require("dedent"));
|
|
636
629
|
}
|
|
637
630
|
});
|
|
638
631
|
|
|
@@ -657,119 +650,6 @@ var init_paths = __esm({
|
|
|
657
650
|
}
|
|
658
651
|
});
|
|
659
652
|
|
|
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
|
-
|
|
773
653
|
// typegen/index.ts
|
|
774
654
|
async function run(rootDirectory) {
|
|
775
655
|
const ctx = await createContext2({ rootDirectory, watch: false });
|
|
@@ -778,16 +658,16 @@ async function run(rootDirectory) {
|
|
|
778
658
|
async function watch(rootDirectory, { logger } = {}) {
|
|
779
659
|
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
780
660
|
await writeAll(ctx);
|
|
781
|
-
logger?.info(
|
|
661
|
+
logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
|
|
782
662
|
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
783
663
|
if (!result.ok) {
|
|
784
|
-
logger?.error(
|
|
664
|
+
logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
|
|
785
665
|
return;
|
|
786
666
|
}
|
|
787
667
|
ctx.config = result.value;
|
|
788
668
|
if (routeConfigChanged) {
|
|
789
669
|
await writeAll(ctx);
|
|
790
|
-
logger?.info(
|
|
670
|
+
logger?.info(import_picocolors2.default.green("regenerated types"), {
|
|
791
671
|
timestamp: true,
|
|
792
672
|
clear: true
|
|
793
673
|
});
|
|
@@ -813,23 +693,105 @@ async function createContext2({
|
|
|
813
693
|
config
|
|
814
694
|
};
|
|
815
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
|
+
}
|
|
816
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 += `}`;
|
|
817
732
|
const typegenDir = getTypesDir(ctx);
|
|
818
|
-
|
|
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
|
+
);
|
|
819
755
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
820
756
|
const typesPath = getTypesPath(ctx, route);
|
|
821
|
-
const content = generate(
|
|
822
|
-
|
|
823
|
-
|
|
757
|
+
const content = generate(route);
|
|
758
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(typesPath), { recursive: true });
|
|
759
|
+
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
824
760
|
});
|
|
825
761
|
}
|
|
826
|
-
|
|
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;
|
|
827
788
|
var init_typegen = __esm({
|
|
828
789
|
"typegen/index.ts"() {
|
|
829
790
|
"use strict";
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
791
|
+
import_node_fs2 = __toESM(require("fs"));
|
|
792
|
+
import_dedent2 = __toESM(require("dedent"));
|
|
793
|
+
Path3 = __toESM(require("pathe"));
|
|
794
|
+
import_picocolors2 = __toESM(require("picocolors"));
|
|
833
795
|
init_config();
|
|
834
796
|
init_generate();
|
|
835
797
|
init_paths();
|
|
@@ -862,21 +824,21 @@ var init_node_adapter = __esm({
|
|
|
862
824
|
});
|
|
863
825
|
|
|
864
826
|
// vite/resolve-file-url.ts
|
|
865
|
-
var
|
|
827
|
+
var path4;
|
|
866
828
|
var init_resolve_file_url = __esm({
|
|
867
829
|
"vite/resolve-file-url.ts"() {
|
|
868
830
|
"use strict";
|
|
869
|
-
|
|
831
|
+
path4 = __toESM(require("path"));
|
|
870
832
|
init_vite();
|
|
871
833
|
}
|
|
872
834
|
});
|
|
873
835
|
|
|
874
836
|
// vite/styles.ts
|
|
875
|
-
var
|
|
837
|
+
var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
876
838
|
var init_styles = __esm({
|
|
877
839
|
"vite/styles.ts"() {
|
|
878
840
|
"use strict";
|
|
879
|
-
|
|
841
|
+
path5 = __toESM(require("path"));
|
|
880
842
|
import_react_router = require("react-router");
|
|
881
843
|
init_resolve_file_url();
|
|
882
844
|
init_vite();
|
|
@@ -917,43 +879,12 @@ var init_remove_exports = __esm({
|
|
|
917
879
|
}
|
|
918
880
|
});
|
|
919
881
|
|
|
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
|
-
|
|
951
882
|
// vite/with-props.ts
|
|
952
|
-
var
|
|
883
|
+
var import_dedent3, vmod;
|
|
953
884
|
var init_with_props = __esm({
|
|
954
885
|
"vite/with-props.ts"() {
|
|
955
886
|
"use strict";
|
|
956
|
-
|
|
887
|
+
import_dedent3 = __toESM(require("dedent"));
|
|
957
888
|
init_babel();
|
|
958
889
|
init_virtual_module();
|
|
959
890
|
vmod = create("with-props");
|
|
@@ -984,19 +915,56 @@ async function resolveViteConfig({
|
|
|
984
915
|
async function extractPluginContext(viteConfig) {
|
|
985
916
|
return viteConfig["__reactRouterPluginContext"];
|
|
986
917
|
}
|
|
987
|
-
|
|
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;
|
|
988
956
|
var init_plugin = __esm({
|
|
989
957
|
"vite/plugin.ts"() {
|
|
990
958
|
"use strict";
|
|
991
959
|
import_node_crypto = require("crypto");
|
|
992
|
-
|
|
960
|
+
path6 = __toESM(require("path"));
|
|
993
961
|
url = __toESM(require("url"));
|
|
994
962
|
fse = __toESM(require("fs-extra"));
|
|
995
|
-
|
|
963
|
+
babel = __toESM(require("@babel/core"));
|
|
996
964
|
import_react_router2 = require("react-router");
|
|
997
965
|
import_es_module_lexer = require("es-module-lexer");
|
|
998
966
|
import_jsesc = __toESM(require("jsesc"));
|
|
999
|
-
|
|
967
|
+
import_picocolors3 = __toESM(require("picocolors"));
|
|
1000
968
|
init_typegen();
|
|
1001
969
|
init_invariant();
|
|
1002
970
|
init_babel();
|
|
@@ -1006,7 +974,6 @@ var init_plugin = __esm({
|
|
|
1006
974
|
init_resolve_file_url();
|
|
1007
975
|
init_combine_urls();
|
|
1008
976
|
init_remove_exports();
|
|
1009
|
-
init_route_chunks();
|
|
1010
977
|
init_vite();
|
|
1011
978
|
init_config();
|
|
1012
979
|
init_with_props();
|
|
@@ -1017,18 +984,18 @@ var init_plugin = __esm({
|
|
|
1017
984
|
serverManifest: create("server-manifest"),
|
|
1018
985
|
browserManifest: create("browser-manifest")
|
|
1019
986
|
};
|
|
1020
|
-
getServerBuildDirectory = (ctx) =>
|
|
987
|
+
getServerBuildDirectory = (ctx) => path6.join(
|
|
1021
988
|
ctx.reactRouterConfig.buildDirectory,
|
|
1022
989
|
"server",
|
|
1023
990
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
1024
991
|
);
|
|
1025
|
-
defaultEntriesDir =
|
|
1026
|
-
|
|
992
|
+
defaultEntriesDir = path6.resolve(
|
|
993
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1027
994
|
"dist",
|
|
1028
995
|
"config",
|
|
1029
996
|
"defaults"
|
|
1030
997
|
);
|
|
1031
|
-
defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
998
|
+
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path6.join(defaultEntriesDir, filename2));
|
|
1032
999
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1033
1000
|
REACT_REFRESH_HEADER = `
|
|
1034
1001
|
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
@@ -1054,6 +1021,45 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
1054
1021
|
}
|
|
1055
1022
|
});
|
|
1056
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
|
+
|
|
1057
1063
|
// vite/build.ts
|
|
1058
1064
|
var build_exports = {};
|
|
1059
1065
|
__export(build_exports, {
|
|
@@ -1353,8 +1359,6 @@ var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
|
1353
1359
|
var import_package_json2 = __toESM(require("@npmcli/package-json"));
|
|
1354
1360
|
var import_exit_hook = __toESM(require("exit-hook"));
|
|
1355
1361
|
var import_picocolors7 = __toESM(require("picocolors"));
|
|
1356
|
-
var import_react_router3 = require("react-router");
|
|
1357
|
-
init_config();
|
|
1358
1362
|
|
|
1359
1363
|
// config/format.ts
|
|
1360
1364
|
function formatRoutes(routeManifest, format) {
|
|
@@ -1412,13 +1416,16 @@ function formatRoutesAsJsx(routeManifest) {
|
|
|
1412
1416
|
return output;
|
|
1413
1417
|
}
|
|
1414
1418
|
|
|
1419
|
+
// cli/commands.ts
|
|
1420
|
+
init_plugin();
|
|
1421
|
+
|
|
1415
1422
|
// cli/useJavascript.ts
|
|
1416
|
-
var
|
|
1423
|
+
var babel2 = __toESM(require("@babel/core"));
|
|
1417
1424
|
var import_plugin_syntax_jsx = __toESM(require("@babel/plugin-syntax-jsx"));
|
|
1418
1425
|
var import_preset_typescript = __toESM(require("@babel/preset-typescript"));
|
|
1419
1426
|
var import_prettier = __toESM(require("prettier"));
|
|
1420
1427
|
function transpile(tsx, options = {}) {
|
|
1421
|
-
let mjs =
|
|
1428
|
+
let mjs = babel2.transformSync(tsx, {
|
|
1422
1429
|
compact: false,
|
|
1423
1430
|
cwd: options.cwd,
|
|
1424
1431
|
filename: options.filename,
|
|
@@ -1435,14 +1442,18 @@ init_profiler();
|
|
|
1435
1442
|
init_typegen();
|
|
1436
1443
|
init_vite();
|
|
1437
1444
|
async function routes(reactRouterRoot, flags = {}) {
|
|
1438
|
-
let
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
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
|
+
);
|
|
1442
1453
|
process.exit(1);
|
|
1443
1454
|
}
|
|
1444
1455
|
let format = flags.json ? "json" : "jsx";
|
|
1445
|
-
console.log(formatRoutes(
|
|
1456
|
+
console.log(formatRoutes(ctx.reactRouterConfig.routes, format));
|
|
1446
1457
|
}
|
|
1447
1458
|
async function build2(root, options = {}) {
|
|
1448
1459
|
if (!root) {
|
|
@@ -1476,18 +1487,17 @@ var conjunctionListFormat = new Intl.ListFormat("en", {
|
|
|
1476
1487
|
type: "conjunction"
|
|
1477
1488
|
});
|
|
1478
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;
|
|
1479
1496
|
if (!entry) {
|
|
1480
1497
|
await generateEntry("entry.client", reactRouterRoot, flags);
|
|
1481
1498
|
await generateEntry("entry.server", reactRouterRoot, flags);
|
|
1482
1499
|
return;
|
|
1483
1500
|
}
|
|
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;
|
|
1491
1501
|
if (!entries.includes(entry)) {
|
|
1492
1502
|
let entriesArray = Array.from(entries);
|
|
1493
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: {
|
|
@@ -133,7 +129,7 @@ type ResolvedReactRouterConfig = Readonly<{
|
|
|
133
129
|
/**
|
|
134
130
|
* Enabled future flags
|
|
135
131
|
*/
|
|
136
|
-
future:
|
|
132
|
+
future: FutureConfig;
|
|
137
133
|
/**
|
|
138
134
|
* An array of URLs to prerender to HTML files at build time. Can also be a
|
|
139
135
|
* function returning an array to dynamically generate URLs.
|
package/dist/config.js
CHANGED