@react-router/dev 0.0.0-experimental-2bfe0a2f2 → 0.0.0-experimental-345f1da12
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 +30 -0
- package/bin.js +13 -0
- package/dist/cli/index.js +255 -233
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +48 -7
- package/dist/vite.js +473 -410
- package/package.json +10 -10
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-345f1da12
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -55,26 +55,55 @@ var init_invariant = __esm({
|
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
// config/is-react-router-repo.ts
|
|
59
|
+
function isReactRouterRepo() {
|
|
60
|
+
let serverRuntimePath = import_pathe.default.dirname(
|
|
61
|
+
require.resolve("@react-router/node/package.json")
|
|
62
|
+
);
|
|
63
|
+
let serverRuntimeParentDir = import_pathe.default.basename(
|
|
64
|
+
import_pathe.default.resolve(serverRuntimePath, "..")
|
|
65
|
+
);
|
|
66
|
+
return serverRuntimeParentDir === "packages";
|
|
67
|
+
}
|
|
68
|
+
var import_pathe;
|
|
69
|
+
var init_is_react_router_repo = __esm({
|
|
70
|
+
"config/is-react-router-repo.ts"() {
|
|
71
|
+
"use strict";
|
|
72
|
+
import_pathe = __toESM(require("pathe"));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// vite/vite.ts
|
|
77
|
+
async function preloadVite() {
|
|
78
|
+
vite = await import(viteImportSpecifier);
|
|
61
79
|
}
|
|
62
|
-
function
|
|
63
|
-
invariant(vite, "
|
|
80
|
+
function getVite() {
|
|
81
|
+
invariant(vite, "getVite() called before preloadVite()");
|
|
64
82
|
return vite;
|
|
65
83
|
}
|
|
66
|
-
var vite;
|
|
67
|
-
var
|
|
68
|
-
"vite/
|
|
84
|
+
var import_pathe2, vite, viteImportSpecifier;
|
|
85
|
+
var init_vite = __esm({
|
|
86
|
+
"vite/vite.ts"() {
|
|
69
87
|
"use strict";
|
|
88
|
+
import_pathe2 = __toESM(require("pathe"));
|
|
70
89
|
init_invariant();
|
|
90
|
+
init_is_react_router_repo();
|
|
91
|
+
viteImportSpecifier = isReactRouterRepo() ? (
|
|
92
|
+
// Support testing against different versions of Vite by ensuring that Vite
|
|
93
|
+
// is resolved from the current working directory when running within this
|
|
94
|
+
// repo. If we don't do this, Vite will always be imported relative to this
|
|
95
|
+
// file, which means that it will always resolve to Vite 6.
|
|
96
|
+
`file:///${import_pathe2.default.normalize(
|
|
97
|
+
require.resolve("vite/package.json", { paths: [process.cwd()] })
|
|
98
|
+
).replace("package.json", "dist/node/index.js")}`
|
|
99
|
+
) : "vite";
|
|
71
100
|
}
|
|
72
101
|
});
|
|
73
102
|
|
|
74
103
|
// vite/vite-node.ts
|
|
75
104
|
async function createContext(viteConfig = {}) {
|
|
76
|
-
await
|
|
77
|
-
const vite2 =
|
|
105
|
+
await preloadVite();
|
|
106
|
+
const vite2 = getVite();
|
|
78
107
|
const devServer = await vite2.createServer(
|
|
79
108
|
vite2.mergeConfig(
|
|
80
109
|
{
|
|
@@ -100,11 +129,11 @@ async function createContext(viteConfig = {}) {
|
|
|
100
129
|
const runner = new import_client.ViteNodeRunner({
|
|
101
130
|
root: devServer.config.root,
|
|
102
131
|
base: devServer.config.base,
|
|
103
|
-
fetchModule(
|
|
104
|
-
return server.fetchModule(
|
|
132
|
+
fetchModule(id) {
|
|
133
|
+
return server.fetchModule(id);
|
|
105
134
|
},
|
|
106
|
-
resolveId(
|
|
107
|
-
return server.resolveId(
|
|
135
|
+
resolveId(id, importer) {
|
|
136
|
+
return server.resolveId(id, importer);
|
|
108
137
|
}
|
|
109
138
|
});
|
|
110
139
|
return { devServer, server, runner };
|
|
@@ -116,7 +145,7 @@ var init_vite_node = __esm({
|
|
|
116
145
|
import_server = require("vite-node/server");
|
|
117
146
|
import_client = require("vite-node/client");
|
|
118
147
|
import_source_map = require("vite-node/source-map");
|
|
119
|
-
|
|
148
|
+
init_vite();
|
|
120
149
|
}
|
|
121
150
|
});
|
|
122
151
|
|
|
@@ -149,7 +178,7 @@ function validateRouteConfig({
|
|
|
149
178
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
150
179
|
root ? `${root}` : [],
|
|
151
180
|
nested ? Object.entries(nested).map(
|
|
152
|
-
([
|
|
181
|
+
([path10, message]) => `Path: routes.${path10}
|
|
153
182
|
${message}`
|
|
154
183
|
) : []
|
|
155
184
|
].flat().join("\n\n")
|
|
@@ -160,24 +189,24 @@ ${message}`
|
|
|
160
189
|
function configRoutesToRouteManifest(appDirectory, routes2, rootId = "root") {
|
|
161
190
|
let routeManifest = {};
|
|
162
191
|
function walk(route, parentId) {
|
|
163
|
-
let
|
|
192
|
+
let id = route.id || createRouteId(route.file);
|
|
164
193
|
let manifestItem = {
|
|
165
|
-
id
|
|
194
|
+
id,
|
|
166
195
|
parentId,
|
|
167
196
|
file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
|
|
168
197
|
path: route.path,
|
|
169
198
|
index: route.index,
|
|
170
199
|
caseSensitive: route.caseSensitive
|
|
171
200
|
};
|
|
172
|
-
if (routeManifest.hasOwnProperty(
|
|
201
|
+
if (routeManifest.hasOwnProperty(id)) {
|
|
173
202
|
throw new Error(
|
|
174
|
-
`Unable to define routes with duplicate route id: "${
|
|
203
|
+
`Unable to define routes with duplicate route id: "${id}"`
|
|
175
204
|
);
|
|
176
205
|
}
|
|
177
|
-
routeManifest[
|
|
206
|
+
routeManifest[id] = manifestItem;
|
|
178
207
|
if (route.children) {
|
|
179
208
|
for (let child of route.children) {
|
|
180
|
-
walk(child,
|
|
209
|
+
walk(child, id);
|
|
181
210
|
}
|
|
182
211
|
}
|
|
183
212
|
}
|
|
@@ -307,13 +336,13 @@ async function resolveConfig({
|
|
|
307
336
|
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
308
337
|
);
|
|
309
338
|
}
|
|
310
|
-
let appDirectory =
|
|
311
|
-
let buildDirectory =
|
|
339
|
+
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
340
|
+
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
312
341
|
let rootRouteFile = findEntry(appDirectory, "root");
|
|
313
342
|
if (!rootRouteFile) {
|
|
314
|
-
let rootRouteDisplayPath =
|
|
343
|
+
let rootRouteDisplayPath = import_pathe3.default.relative(
|
|
315
344
|
root,
|
|
316
|
-
|
|
345
|
+
import_pathe3.default.join(appDirectory, "root.tsx")
|
|
317
346
|
);
|
|
318
347
|
return err(
|
|
319
348
|
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
@@ -325,15 +354,15 @@ async function resolveConfig({
|
|
|
325
354
|
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
326
355
|
try {
|
|
327
356
|
if (!routeConfigFile) {
|
|
328
|
-
let routeConfigDisplayPath =
|
|
357
|
+
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
329
358
|
root,
|
|
330
|
-
|
|
359
|
+
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
331
360
|
);
|
|
332
361
|
return err(`Route config file not found at "${routeConfigDisplayPath}".`);
|
|
333
362
|
}
|
|
334
363
|
setAppDirectory(appDirectory);
|
|
335
364
|
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
336
|
-
|
|
365
|
+
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
337
366
|
)).default;
|
|
338
367
|
let routeConfig = await routeConfigExport;
|
|
339
368
|
let result = validateRouteConfig({
|
|
@@ -353,7 +382,7 @@ async function resolveConfig({
|
|
|
353
382
|
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
354
383
|
"",
|
|
355
384
|
error.loc?.file && error.loc?.column && error.frame ? [
|
|
356
|
-
|
|
385
|
+
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
357
386
|
error.frame.trim?.()
|
|
358
387
|
] : error.stack
|
|
359
388
|
].flat().join("\n")
|
|
@@ -425,8 +454,8 @@ async function createConfigLoader({
|
|
|
425
454
|
);
|
|
426
455
|
fsWatcher.on("all", async (...args) => {
|
|
427
456
|
let [event, rawFilepath] = args;
|
|
428
|
-
let filepath =
|
|
429
|
-
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(
|
|
457
|
+
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
458
|
+
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
430
459
|
let configCodeUpdated = Boolean(
|
|
431
460
|
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
432
461
|
);
|
|
@@ -467,25 +496,16 @@ async function createConfigLoader({
|
|
|
467
496
|
}
|
|
468
497
|
};
|
|
469
498
|
}
|
|
470
|
-
function isInReactRouterMonorepo() {
|
|
471
|
-
let serverRuntimePath = import_pathe.default.dirname(
|
|
472
|
-
require.resolve("@react-router/node/package.json")
|
|
473
|
-
);
|
|
474
|
-
let serverRuntimeParentDir = import_pathe.default.basename(
|
|
475
|
-
import_pathe.default.resolve(serverRuntimePath, "..")
|
|
476
|
-
);
|
|
477
|
-
return serverRuntimeParentDir === "packages";
|
|
478
|
-
}
|
|
479
499
|
function findEntry(dir, basename2, options) {
|
|
480
500
|
for (let ext of entryExts) {
|
|
481
|
-
let file =
|
|
501
|
+
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
482
502
|
if (import_node_fs.default.existsSync(file)) {
|
|
483
|
-
return options?.absolute ?? false ? file :
|
|
503
|
+
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
484
504
|
}
|
|
485
505
|
}
|
|
486
506
|
return void 0;
|
|
487
507
|
}
|
|
488
|
-
var import_node_fs, import_node_child_process, import_package_json,
|
|
508
|
+
var import_node_fs, import_node_child_process, import_package_json, import_pathe3, import_chokidar, import_picocolors, import_pick2, import_omit, import_cloneDeep, import_isEqual, excludedConfigPresetKeys, branchRouteProperties, configRouteToBranchRoute, mergeReactRouterConfig, deepFreeze, ssrExternals, entryExts;
|
|
489
509
|
var init_config = __esm({
|
|
490
510
|
"config/config.ts"() {
|
|
491
511
|
"use strict";
|
|
@@ -493,7 +513,7 @@ var init_config = __esm({
|
|
|
493
513
|
import_node_child_process = require("child_process");
|
|
494
514
|
import_package_json = __toESM(require("@npmcli/package-json"));
|
|
495
515
|
init_vite_node();
|
|
496
|
-
|
|
516
|
+
import_pathe3 = __toESM(require("pathe"));
|
|
497
517
|
import_chokidar = __toESM(require("chokidar"));
|
|
498
518
|
import_picocolors = __toESM(require("picocolors"));
|
|
499
519
|
import_pick2 = __toESM(require("lodash/pick"));
|
|
@@ -502,6 +522,7 @@ var init_config = __esm({
|
|
|
502
522
|
import_isEqual = __toESM(require("lodash/isEqual"));
|
|
503
523
|
init_routes();
|
|
504
524
|
init_detectPackageManager();
|
|
525
|
+
init_is_react_router_repo();
|
|
505
526
|
excludedConfigPresetKeys = ["presets"];
|
|
506
527
|
branchRouteProperties = [
|
|
507
528
|
"id",
|
|
@@ -548,7 +569,7 @@ var init_config = __esm({
|
|
|
548
569
|
});
|
|
549
570
|
return o;
|
|
550
571
|
};
|
|
551
|
-
ssrExternals =
|
|
572
|
+
ssrExternals = isReactRouterRepo() ? [
|
|
552
573
|
// This is only needed within this repo because these packages
|
|
553
574
|
// are linked to a directory outside of node_modules so Vite
|
|
554
575
|
// treats them as internal code by default.
|
|
@@ -565,139 +586,67 @@ var init_config = __esm({
|
|
|
565
586
|
}
|
|
566
587
|
});
|
|
567
588
|
|
|
568
|
-
// typegen/paths.ts
|
|
569
|
-
function getTypesDir(ctx) {
|
|
570
|
-
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
571
|
-
}
|
|
572
|
-
function getTypesPath(ctx, route) {
|
|
573
|
-
return Path2.join(
|
|
574
|
-
getTypesDir(ctx),
|
|
575
|
-
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
576
|
-
Path2.dirname(route.file),
|
|
577
|
-
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
|
-
var Path2, Pathe;
|
|
581
|
-
var init_paths = __esm({
|
|
582
|
-
"typegen/paths.ts"() {
|
|
583
|
-
"use strict";
|
|
584
|
-
Path2 = __toESM(require("pathe"));
|
|
585
|
-
Pathe = __toESM(require("pathe/utils"));
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
|
|
589
589
|
// typegen/generate.ts
|
|
590
|
-
function generate(
|
|
591
|
-
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
592
|
-
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
593
|
-
const typesPath = getTypesPath(ctx, route);
|
|
594
|
-
const parents = lineage.slice(0, -1);
|
|
595
|
-
const parentTypeImports = parents.map((parent, i) => {
|
|
596
|
-
const rel = Path3.relative(
|
|
597
|
-
Path3.dirname(typesPath),
|
|
598
|
-
getTypesPath(ctx, parent)
|
|
599
|
-
);
|
|
600
|
-
const indent = i === 0 ? "" : " ".repeat(2);
|
|
601
|
-
let source = noExtension(rel);
|
|
602
|
-
if (!source.startsWith("../")) source = "./" + source;
|
|
603
|
-
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
604
|
-
}).join("\n");
|
|
590
|
+
function generate(route) {
|
|
605
591
|
return import_dedent.default`
|
|
606
592
|
// React Router generated types for route:
|
|
607
593
|
// ${route.file}
|
|
608
594
|
|
|
609
|
-
import type
|
|
610
|
-
|
|
611
|
-
${parentTypeImports}
|
|
595
|
+
import type { RouteExports, Routes } from "react-router/types";
|
|
612
596
|
|
|
613
|
-
type
|
|
597
|
+
type RouteId = "${route.id}"
|
|
598
|
+
export type Info = Routes[RouteId];
|
|
614
599
|
|
|
615
|
-
|
|
616
|
-
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
617
|
-
id: "${route.id}"
|
|
618
|
-
file: "${route.file}"
|
|
619
|
-
path: "${route.path}"
|
|
620
|
-
params: {${formatParamProperties(
|
|
621
|
-
urlpath
|
|
622
|
-
)}} & { [key: string]: string | undefined }
|
|
623
|
-
module: Module
|
|
624
|
-
loaderData: T.CreateLoaderData<Module>
|
|
625
|
-
actionData: T.CreateActionData<Module>
|
|
626
|
-
}
|
|
600
|
+
type Exports = RouteExports[RouteId];
|
|
627
601
|
|
|
628
602
|
export namespace Route {
|
|
629
|
-
export type LinkDescriptors =
|
|
630
|
-
export type LinksFunction = () => LinkDescriptors
|
|
603
|
+
export type LinkDescriptors = Exports["links"]["return"];
|
|
604
|
+
export type LinksFunction = () => LinkDescriptors;
|
|
631
605
|
|
|
632
|
-
export type MetaArgs =
|
|
633
|
-
export type MetaDescriptors =
|
|
634
|
-
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
606
|
+
export type MetaArgs = Exports["meta"]["args"];
|
|
607
|
+
export type MetaDescriptors = Exports["meta"]["return"];
|
|
608
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors;
|
|
635
609
|
|
|
636
|
-
export type HeadersArgs =
|
|
637
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
610
|
+
export type HeadersArgs = Exports["headers"]["args"];
|
|
611
|
+
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit;
|
|
638
612
|
|
|
639
|
-
export type
|
|
640
|
-
export type
|
|
641
|
-
export type
|
|
642
|
-
export type
|
|
643
|
-
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
644
|
-
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
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"];
|
|
645
617
|
|
|
646
|
-
export type HydrateFallbackProps =
|
|
647
|
-
export type ComponentProps =
|
|
648
|
-
export type ErrorBoundaryProps =
|
|
618
|
+
export type HydrateFallbackProps = Exports["HydrateFallback"]["args"];
|
|
619
|
+
export type ComponentProps = Exports["default"]["args"];
|
|
620
|
+
export type ErrorBoundaryProps = Exports["ErrorBoundary"]["args"];
|
|
649
621
|
}
|
|
650
622
|
`;
|
|
651
623
|
}
|
|
652
|
-
|
|
653
|
-
const result = [];
|
|
654
|
-
while (route) {
|
|
655
|
-
result.push(route);
|
|
656
|
-
if (!route.parentId) break;
|
|
657
|
-
route = routes2[route.parentId];
|
|
658
|
-
}
|
|
659
|
-
result.reverse();
|
|
660
|
-
return result;
|
|
661
|
-
}
|
|
662
|
-
function formatParamProperties(urlpath) {
|
|
663
|
-
const params = parseParams(urlpath);
|
|
664
|
-
const properties = Object.entries(params).map(([name, values]) => {
|
|
665
|
-
if (values.length === 1) {
|
|
666
|
-
const isOptional = values[0];
|
|
667
|
-
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
668
|
-
}
|
|
669
|
-
const items = values.map(
|
|
670
|
-
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
671
|
-
);
|
|
672
|
-
return `"${name}": [${items.join(", ")}]`;
|
|
673
|
-
});
|
|
674
|
-
return properties.join("; ");
|
|
675
|
-
}
|
|
676
|
-
function parseParams(urlpath) {
|
|
677
|
-
const result = {};
|
|
678
|
-
let segments = urlpath.split("/");
|
|
679
|
-
segments.forEach((segment) => {
|
|
680
|
-
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
681
|
-
if (!match) return;
|
|
682
|
-
const param = match[1];
|
|
683
|
-
const isOptional = match[2] !== void 0;
|
|
684
|
-
result[param] ??= [];
|
|
685
|
-
result[param].push(isOptional);
|
|
686
|
-
return;
|
|
687
|
-
});
|
|
688
|
-
const hasSplat = segments.at(-1) === "*";
|
|
689
|
-
if (hasSplat) result["*"] = [false];
|
|
690
|
-
return result;
|
|
691
|
-
}
|
|
692
|
-
var import_dedent, Path3, Pathe2, noExtension;
|
|
624
|
+
var import_dedent;
|
|
693
625
|
var init_generate = __esm({
|
|
694
626
|
"typegen/generate.ts"() {
|
|
695
627
|
"use strict";
|
|
696
628
|
import_dedent = __toESM(require("dedent"));
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// typegen/paths.ts
|
|
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
|
+
var Path2, Pathe;
|
|
645
|
+
var init_paths = __esm({
|
|
646
|
+
"typegen/paths.ts"() {
|
|
647
|
+
"use strict";
|
|
648
|
+
Path2 = __toESM(require("pathe"));
|
|
649
|
+
Pathe = __toESM(require("pathe/utils"));
|
|
701
650
|
}
|
|
702
651
|
});
|
|
703
652
|
|
|
@@ -744,22 +693,100 @@ async function createContext2({
|
|
|
744
693
|
config
|
|
745
694
|
};
|
|
746
695
|
}
|
|
696
|
+
function asJS(path10) {
|
|
697
|
+
return path10.replace(/\.(js|ts)x?$/, ".js");
|
|
698
|
+
}
|
|
699
|
+
function formatRoute({ id, path: path10, file, parentId }) {
|
|
700
|
+
return [
|
|
701
|
+
`"${id}": {`,
|
|
702
|
+
` parentId: ${JSON.stringify(parentId)}`,
|
|
703
|
+
` path: ${JSON.stringify(path10)}`,
|
|
704
|
+
` module: typeof import("./app/${asJS(file)}")`,
|
|
705
|
+
`}`
|
|
706
|
+
].map((line) => ` ${line}`).join("\n");
|
|
707
|
+
}
|
|
747
708
|
async function writeAll(ctx) {
|
|
709
|
+
let routes2 = Object.values(ctx.config.routes);
|
|
710
|
+
let pathsToParams = /* @__PURE__ */ new Map();
|
|
711
|
+
for (let route of routes2) {
|
|
712
|
+
if (route.path === void 0) continue;
|
|
713
|
+
let lineage = getRouteLineage(ctx.config.routes, route);
|
|
714
|
+
let path10 = lineage.filter((route2) => route2.path !== void 0).map((route2) => route2.path).join("/");
|
|
715
|
+
if (path10 === "") path10 = "/";
|
|
716
|
+
pathsToParams.set(path10, parseParams(path10));
|
|
717
|
+
}
|
|
718
|
+
let formattedPaths = `type Paths = {`;
|
|
719
|
+
for (let [path10, params] of pathsToParams.entries()) {
|
|
720
|
+
let formattedParams = Object.entries(params).map(
|
|
721
|
+
([param, required]) => `"${param}"${required ? "" : "?"}: string`
|
|
722
|
+
);
|
|
723
|
+
let formattedEntry = `"${path10}": {${formattedParams.join(",")}},
|
|
724
|
+
`;
|
|
725
|
+
formattedPaths += formattedEntry;
|
|
726
|
+
}
|
|
727
|
+
formattedPaths += `}`;
|
|
748
728
|
const typegenDir = getTypesDir(ctx);
|
|
749
729
|
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
730
|
+
const newTypes = Path3.join(typegenDir, "routes.ts");
|
|
731
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(newTypes), { recursive: true });
|
|
732
|
+
import_node_fs2.default.writeFileSync(
|
|
733
|
+
newTypes,
|
|
734
|
+
formattedPaths + `
|
|
735
|
+
|
|
736
|
+
type Routes = {
|
|
737
|
+
${routes2.map(formatRoute).join("\n")}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
` + import_dedent2.default`
|
|
741
|
+
declare module "react-router/types" {
|
|
742
|
+
interface Register {
|
|
743
|
+
paths: Paths
|
|
744
|
+
routes: Routes
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export {}
|
|
749
|
+
`
|
|
750
|
+
);
|
|
750
751
|
Object.values(ctx.config.routes).forEach((route) => {
|
|
751
752
|
const typesPath = getTypesPath(ctx, route);
|
|
752
|
-
const content = generate(
|
|
753
|
-
import_node_fs2.default.mkdirSync(
|
|
753
|
+
const content = generate(route);
|
|
754
|
+
import_node_fs2.default.mkdirSync(Path3.dirname(typesPath), { recursive: true });
|
|
754
755
|
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
755
756
|
});
|
|
756
757
|
}
|
|
757
|
-
|
|
758
|
+
function getRouteLineage(routes2, route) {
|
|
759
|
+
const result = [];
|
|
760
|
+
while (route) {
|
|
761
|
+
result.push(route);
|
|
762
|
+
if (!route.parentId) break;
|
|
763
|
+
route = routes2[route.parentId];
|
|
764
|
+
}
|
|
765
|
+
result.reverse();
|
|
766
|
+
return result;
|
|
767
|
+
}
|
|
768
|
+
function parseParams(urlpath) {
|
|
769
|
+
const result = {};
|
|
770
|
+
let segments = urlpath.split("/");
|
|
771
|
+
segments.forEach((segment) => {
|
|
772
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
773
|
+
if (!match) return;
|
|
774
|
+
const param = match[1];
|
|
775
|
+
const isRequired = match[2] === void 0;
|
|
776
|
+
result[param] ||= isRequired;
|
|
777
|
+
return;
|
|
778
|
+
});
|
|
779
|
+
const hasSplat = segments.at(-1) === "*";
|
|
780
|
+
if (hasSplat) result["*"] = true;
|
|
781
|
+
return result;
|
|
782
|
+
}
|
|
783
|
+
var import_node_fs2, import_dedent2, Path3, import_picocolors2;
|
|
758
784
|
var init_typegen = __esm({
|
|
759
785
|
"typegen/index.ts"() {
|
|
760
786
|
"use strict";
|
|
761
787
|
import_node_fs2 = __toESM(require("fs"));
|
|
762
|
-
|
|
788
|
+
import_dedent2 = __toESM(require("dedent"));
|
|
789
|
+
Path3 = __toESM(require("pathe"));
|
|
763
790
|
import_picocolors2 = __toESM(require("picocolors"));
|
|
764
791
|
init_config();
|
|
765
792
|
init_generate();
|
|
@@ -793,34 +820,41 @@ var init_node_adapter = __esm({
|
|
|
793
820
|
});
|
|
794
821
|
|
|
795
822
|
// vite/resolve-file-url.ts
|
|
796
|
-
var
|
|
823
|
+
var path4;
|
|
797
824
|
var init_resolve_file_url = __esm({
|
|
798
825
|
"vite/resolve-file-url.ts"() {
|
|
799
826
|
"use strict";
|
|
800
|
-
|
|
801
|
-
|
|
827
|
+
path4 = __toESM(require("path"));
|
|
828
|
+
init_vite();
|
|
802
829
|
}
|
|
803
830
|
});
|
|
804
831
|
|
|
805
832
|
// vite/styles.ts
|
|
806
|
-
var
|
|
833
|
+
var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
807
834
|
var init_styles = __esm({
|
|
808
835
|
"vite/styles.ts"() {
|
|
809
836
|
"use strict";
|
|
810
|
-
|
|
837
|
+
path5 = __toESM(require("path"));
|
|
811
838
|
import_react_router = require("react-router");
|
|
812
839
|
init_resolve_file_url();
|
|
840
|
+
init_vite();
|
|
813
841
|
cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
814
842
|
cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
815
843
|
}
|
|
816
844
|
});
|
|
817
845
|
|
|
818
|
-
// vite/
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
846
|
+
// vite/virtual-module.ts
|
|
847
|
+
function create(name) {
|
|
848
|
+
let id = `virtual:react-router/${name}`;
|
|
849
|
+
return {
|
|
850
|
+
id,
|
|
851
|
+
resolvedId: `\0${id}`,
|
|
852
|
+
url: `/@id/__x00__${id}`
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
var init_virtual_module = __esm({
|
|
856
|
+
"vite/virtual-module.ts"() {
|
|
822
857
|
"use strict";
|
|
823
|
-
id = (name) => `virtual:react-router/${name}`;
|
|
824
858
|
}
|
|
825
859
|
});
|
|
826
860
|
|
|
@@ -842,14 +876,14 @@ var init_remove_exports = __esm({
|
|
|
842
876
|
});
|
|
843
877
|
|
|
844
878
|
// vite/with-props.ts
|
|
845
|
-
var
|
|
879
|
+
var import_dedent3, vmod;
|
|
846
880
|
var init_with_props = __esm({
|
|
847
881
|
"vite/with-props.ts"() {
|
|
848
882
|
"use strict";
|
|
849
|
-
|
|
883
|
+
import_dedent3 = __toESM(require("dedent"));
|
|
850
884
|
init_babel();
|
|
851
|
-
|
|
852
|
-
|
|
885
|
+
init_virtual_module();
|
|
886
|
+
vmod = create("with-props");
|
|
853
887
|
}
|
|
854
888
|
});
|
|
855
889
|
|
|
@@ -859,7 +893,7 @@ async function resolveViteConfig({
|
|
|
859
893
|
mode,
|
|
860
894
|
root
|
|
861
895
|
}) {
|
|
862
|
-
let vite2 =
|
|
896
|
+
let vite2 = getVite();
|
|
863
897
|
let viteConfig = await vite2.resolveConfig(
|
|
864
898
|
{ mode, configFile, root },
|
|
865
899
|
"build",
|
|
@@ -909,17 +943,17 @@ async function loadPluginContext({
|
|
|
909
943
|
function findConfig(dir, basename2, extensions) {
|
|
910
944
|
for (let ext of extensions) {
|
|
911
945
|
let name = basename2 + ext;
|
|
912
|
-
let file =
|
|
946
|
+
let file = path6.join(dir, name);
|
|
913
947
|
if (fse.existsSync(file)) return file;
|
|
914
948
|
}
|
|
915
949
|
return void 0;
|
|
916
950
|
}
|
|
917
|
-
var import_node_crypto,
|
|
951
|
+
var import_node_crypto, path6, url, fse, babel, import_react_router2, import_es_module_lexer, import_jsesc, import_picocolors3, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
|
|
918
952
|
var init_plugin = __esm({
|
|
919
953
|
"vite/plugin.ts"() {
|
|
920
954
|
"use strict";
|
|
921
955
|
import_node_crypto = require("crypto");
|
|
922
|
-
|
|
956
|
+
path6 = __toESM(require("path"));
|
|
923
957
|
url = __toESM(require("url"));
|
|
924
958
|
fse = __toESM(require("fs-extra"));
|
|
925
959
|
babel = __toESM(require("@babel/core"));
|
|
@@ -932,33 +966,35 @@ var init_plugin = __esm({
|
|
|
932
966
|
init_babel();
|
|
933
967
|
init_node_adapter();
|
|
934
968
|
init_styles();
|
|
935
|
-
|
|
969
|
+
init_virtual_module();
|
|
936
970
|
init_resolve_file_url();
|
|
937
971
|
init_combine_urls();
|
|
938
972
|
init_remove_exports();
|
|
939
|
-
|
|
973
|
+
init_vite();
|
|
940
974
|
init_config();
|
|
941
975
|
init_with_props();
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
976
|
+
virtualHmrRuntime = create("hmr-runtime");
|
|
977
|
+
virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
978
|
+
virtual = {
|
|
979
|
+
serverBuild: create("server-build"),
|
|
980
|
+
serverManifest: create("server-manifest"),
|
|
981
|
+
browserManifest: create("browser-manifest")
|
|
982
|
+
};
|
|
983
|
+
getServerBuildDirectory = (ctx) => path6.join(
|
|
948
984
|
ctx.reactRouterConfig.buildDirectory,
|
|
949
985
|
"server",
|
|
950
986
|
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
951
987
|
);
|
|
952
|
-
defaultEntriesDir =
|
|
953
|
-
|
|
988
|
+
defaultEntriesDir = path6.resolve(
|
|
989
|
+
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
954
990
|
"dist",
|
|
955
991
|
"config",
|
|
956
992
|
"defaults"
|
|
957
993
|
);
|
|
958
|
-
defaultEntries = fse.readdirSync(defaultEntriesDir).map((
|
|
994
|
+
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path6.join(defaultEntriesDir, filename2));
|
|
959
995
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
960
996
|
REACT_REFRESH_HEADER = `
|
|
961
|
-
import RefreshRuntime from "${
|
|
997
|
+
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
962
998
|
|
|
963
999
|
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
964
1000
|
let prevRefreshReg;
|
|
@@ -977,21 +1013,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
977
1013
|
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
978
1014
|
};
|
|
979
1015
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
980
|
-
}`.
|
|
981
|
-
REACT_REFRESH_FOOTER = `
|
|
982
|
-
if (import.meta.hot && !inWebWorker) {
|
|
983
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
984
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
985
|
-
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
986
|
-
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
|
|
987
|
-
import.meta.hot.accept((nextExports) => {
|
|
988
|
-
if (!nextExports) return;
|
|
989
|
-
__ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
|
|
990
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
|
|
991
|
-
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
992
|
-
});
|
|
993
|
-
});
|
|
994
|
-
}`.trim();
|
|
1016
|
+
}`.replaceAll("\n", "");
|
|
995
1017
|
}
|
|
996
1018
|
});
|
|
997
1019
|
|
|
@@ -1041,8 +1063,8 @@ __export(build_exports, {
|
|
|
1041
1063
|
});
|
|
1042
1064
|
function getAddressableRoutes(routes2) {
|
|
1043
1065
|
let nonAddressableIds = /* @__PURE__ */ new Set();
|
|
1044
|
-
for (let
|
|
1045
|
-
let route = routes2[
|
|
1066
|
+
for (let id in routes2) {
|
|
1067
|
+
let route = routes2[id];
|
|
1046
1068
|
if (route.index) {
|
|
1047
1069
|
invariant(
|
|
1048
1070
|
route.parentId,
|
|
@@ -1051,7 +1073,7 @@ function getAddressableRoutes(routes2) {
|
|
|
1051
1073
|
nonAddressableIds.add(route.parentId);
|
|
1052
1074
|
}
|
|
1053
1075
|
if (typeof route.path !== "string" && !route.index) {
|
|
1054
|
-
nonAddressableIds.add(
|
|
1076
|
+
nonAddressableIds.add(id);
|
|
1055
1077
|
}
|
|
1056
1078
|
}
|
|
1057
1079
|
return Object.values(routes2).filter(
|
|
@@ -1082,12 +1104,12 @@ async function getServerBuilds(ctx) {
|
|
|
1082
1104
|
let { normalizePath } = await import("vite");
|
|
1083
1105
|
let resolvedAppDirectory = import_node_path2.default.resolve(rootDirectory, appDirectory);
|
|
1084
1106
|
let rootRelativeRoutes = Object.fromEntries(
|
|
1085
|
-
Object.entries(routes2).map(([
|
|
1107
|
+
Object.entries(routes2).map(([id, route]) => {
|
|
1086
1108
|
let filePath = import_node_path2.default.join(resolvedAppDirectory, route.file);
|
|
1087
1109
|
let rootRelativeFilePath = normalizePath(
|
|
1088
1110
|
import_node_path2.default.relative(rootDirectory, filePath)
|
|
1089
1111
|
);
|
|
1090
|
-
return [
|
|
1112
|
+
return [id, { ...route, file: rootRelativeFilePath }];
|
|
1091
1113
|
})
|
|
1092
1114
|
);
|
|
1093
1115
|
let buildManifest = {
|
|
@@ -1188,7 +1210,7 @@ async function build(root, {
|
|
|
1188
1210
|
sourcemapClient,
|
|
1189
1211
|
sourcemapServer
|
|
1190
1212
|
}) {
|
|
1191
|
-
await
|
|
1213
|
+
await preloadVite();
|
|
1192
1214
|
let viteConfig = await resolveViteConfig({ configFile, mode, root });
|
|
1193
1215
|
const ctx = await extractPluginContext(viteConfig);
|
|
1194
1216
|
if (!ctx) {
|
|
@@ -1198,7 +1220,7 @@ async function build(root, {
|
|
|
1198
1220
|
process.exit(1);
|
|
1199
1221
|
}
|
|
1200
1222
|
let { reactRouterConfig } = ctx;
|
|
1201
|
-
let vite2 =
|
|
1223
|
+
let vite2 = getVite();
|
|
1202
1224
|
async function viteBuild({
|
|
1203
1225
|
ssr,
|
|
1204
1226
|
serverBundleBuildConfig
|
|
@@ -1255,7 +1277,7 @@ var init_build = __esm({
|
|
|
1255
1277
|
init_plugin();
|
|
1256
1278
|
init_config();
|
|
1257
1279
|
init_invariant();
|
|
1258
|
-
|
|
1280
|
+
init_vite();
|
|
1259
1281
|
}
|
|
1260
1282
|
});
|
|
1261
1283
|
|
|
@@ -1276,8 +1298,8 @@ async function dev(root, {
|
|
|
1276
1298
|
port,
|
|
1277
1299
|
strictPort
|
|
1278
1300
|
}) {
|
|
1279
|
-
await
|
|
1280
|
-
let vite2 =
|
|
1301
|
+
await preloadVite();
|
|
1302
|
+
let vite2 = getVite();
|
|
1281
1303
|
let server = await vite2.createServer({
|
|
1282
1304
|
root,
|
|
1283
1305
|
mode,
|
|
@@ -1317,7 +1339,7 @@ var init_dev = __esm({
|
|
|
1317
1339
|
"vite/dev.ts"() {
|
|
1318
1340
|
"use strict";
|
|
1319
1341
|
import_picocolors6 = __toESM(require("picocolors"));
|
|
1320
|
-
|
|
1342
|
+
init_vite();
|
|
1321
1343
|
init_profiler();
|
|
1322
1344
|
}
|
|
1323
1345
|
});
|
|
@@ -1328,7 +1350,7 @@ var import_semver = __toESM(require("semver"));
|
|
|
1328
1350
|
var import_picocolors8 = __toESM(require("picocolors"));
|
|
1329
1351
|
|
|
1330
1352
|
// cli/commands.ts
|
|
1331
|
-
var
|
|
1353
|
+
var path9 = __toESM(require("path"));
|
|
1332
1354
|
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
1333
1355
|
var import_package_json2 = __toESM(require("@npmcli/package-json"));
|
|
1334
1356
|
var import_exit_hook = __toESM(require("exit-hook"));
|
|
@@ -1414,7 +1436,7 @@ function transpile(tsx, options = {}) {
|
|
|
1414
1436
|
// cli/commands.ts
|
|
1415
1437
|
init_profiler();
|
|
1416
1438
|
init_typegen();
|
|
1417
|
-
|
|
1439
|
+
init_vite();
|
|
1418
1440
|
async function routes(reactRouterRoot, flags = {}) {
|
|
1419
1441
|
let ctx = await loadPluginContext({
|
|
1420
1442
|
root: reactRouterRoot,
|
|
@@ -1486,14 +1508,14 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1486
1508
|
console.error(import_picocolors7.default.red(`No default server entry detected.`));
|
|
1487
1509
|
return;
|
|
1488
1510
|
}
|
|
1489
|
-
let defaultsDirectory =
|
|
1490
|
-
|
|
1511
|
+
let defaultsDirectory = path9.resolve(
|
|
1512
|
+
path9.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1491
1513
|
"dist",
|
|
1492
1514
|
"config",
|
|
1493
1515
|
"defaults"
|
|
1494
1516
|
);
|
|
1495
|
-
let defaultEntryClient =
|
|
1496
|
-
let defaultEntryServer =
|
|
1517
|
+
let defaultEntryClient = path9.resolve(defaultsDirectory, "entry.client.tsx");
|
|
1518
|
+
let defaultEntryServer = path9.resolve(
|
|
1497
1519
|
defaultsDirectory,
|
|
1498
1520
|
`entry.server.node.tsx`
|
|
1499
1521
|
);
|
|
@@ -1502,7 +1524,7 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1502
1524
|
let useTypeScript = flags.typescript ?? true;
|
|
1503
1525
|
let outputExtension = useTypeScript ? "tsx" : "jsx";
|
|
1504
1526
|
let outputEntry = `${entry}.${outputExtension}`;
|
|
1505
|
-
let outputFile2 =
|
|
1527
|
+
let outputFile2 = path9.resolve(appDirectory, outputEntry);
|
|
1506
1528
|
if (!useTypeScript) {
|
|
1507
1529
|
let javascript = transpile(contents, {
|
|
1508
1530
|
cwd: rootDirectory,
|
|
@@ -1514,7 +1536,7 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1514
1536
|
}
|
|
1515
1537
|
console.log(
|
|
1516
1538
|
import_picocolors7.default.blue(
|
|
1517
|
-
`Entry file ${entry} created at ${
|
|
1539
|
+
`Entry file ${entry} created at ${path9.relative(
|
|
1518
1540
|
rootDirectory,
|
|
1519
1541
|
outputFile2
|
|
1520
1542
|
)}.`
|
|
@@ -1523,11 +1545,11 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1523
1545
|
}
|
|
1524
1546
|
async function checkForEntry(rootDirectory, appDirectory, entries2) {
|
|
1525
1547
|
for (let entry of entries2) {
|
|
1526
|
-
let entryPath =
|
|
1548
|
+
let entryPath = path9.resolve(appDirectory, entry);
|
|
1527
1549
|
let exists = await import_fs_extra2.default.pathExists(entryPath);
|
|
1528
1550
|
if (exists) {
|
|
1529
|
-
let
|
|
1530
|
-
console.error(import_picocolors7.default.red(`Entry file ${
|
|
1551
|
+
let relative7 = path9.relative(rootDirectory, entryPath);
|
|
1552
|
+
console.error(import_picocolors7.default.red(`Entry file ${relative7} already exists.`));
|
|
1531
1553
|
return process.exit(1);
|
|
1532
1554
|
}
|
|
1533
1555
|
}
|
|
@@ -1545,8 +1567,8 @@ async function createClientEntry(rootDirectory, appDirectory, inputFile) {
|
|
|
1545
1567
|
async function typegen(root, flags) {
|
|
1546
1568
|
root ??= process.cwd();
|
|
1547
1569
|
if (flags.watch) {
|
|
1548
|
-
await
|
|
1549
|
-
const vite2 =
|
|
1570
|
+
await preloadVite();
|
|
1571
|
+
const vite2 = getVite();
|
|
1550
1572
|
const logger = vite2.createLogger("info", { prefix: "[react-router]" });
|
|
1551
1573
|
await watch(root, { logger });
|
|
1552
1574
|
await new Promise(() => {
|