@react-router/dev 0.0.0-experimental-4d16b23b6 → 0.0.0-experimental-4d6793aa7
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/bin.js +4 -2
- package/dist/build-VA3X4T4U.js +239 -0
- package/dist/chunk-B25E3JGK.js +2624 -0
- package/dist/chunk-B3M3SF27.js +219 -0
- package/dist/chunk-HICCFFJA.js +81 -0
- package/dist/chunk-VTJ3CG32.js +49 -0
- package/dist/chunk-X234P535.js +57 -0
- package/dist/chunk-XJYIKBPH.js +31 -0
- package/dist/cli/index.js +83 -1396
- package/dist/config.js +1 -19
- package/dist/dev-SLPL2UHO.js +74 -0
- package/dist/routes.js +12 -179
- package/dist/vite/cloudflare.js +17 -155
- package/dist/vite.js +10 -2737
- package/package.json +7 -6
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/dev v0.0.0-experimental-
|
|
3
|
+
* @react-router/dev v0.0.0-experimental-4d6793aa7
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -9,1344 +9,37 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
-
}
|
|
32
|
-
return to;
|
|
33
|
-
};
|
|
34
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
-
mod
|
|
41
|
-
));
|
|
42
|
-
|
|
43
|
-
// invariant.ts
|
|
44
|
-
function invariant(value, message) {
|
|
45
|
-
if (value === false || value === null || typeof value === "undefined") {
|
|
46
|
-
console.error(
|
|
47
|
-
"The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose"
|
|
48
|
-
);
|
|
49
|
-
throw new Error(message);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
var init_invariant = __esm({
|
|
53
|
-
"invariant.ts"() {
|
|
54
|
-
"use strict";
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
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);
|
|
79
|
-
}
|
|
80
|
-
function getVite() {
|
|
81
|
-
invariant(vite, "getVite() called before preloadVite()");
|
|
82
|
-
return vite;
|
|
83
|
-
}
|
|
84
|
-
var import_pathe2, vite, viteImportSpecifier;
|
|
85
|
-
var init_vite = __esm({
|
|
86
|
-
"vite/vite.ts"() {
|
|
87
|
-
"use strict";
|
|
88
|
-
import_pathe2 = __toESM(require("pathe"));
|
|
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";
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// vite/vite-node.ts
|
|
104
|
-
async function createContext(viteConfig = {}) {
|
|
105
|
-
await preloadVite();
|
|
106
|
-
const vite2 = getVite();
|
|
107
|
-
const devServer = await vite2.createServer(
|
|
108
|
-
vite2.mergeConfig(
|
|
109
|
-
{
|
|
110
|
-
server: {
|
|
111
|
-
preTransformRequests: false,
|
|
112
|
-
hmr: false
|
|
113
|
-
},
|
|
114
|
-
optimizeDeps: {
|
|
115
|
-
noDiscovery: true
|
|
116
|
-
},
|
|
117
|
-
configFile: false,
|
|
118
|
-
envFile: false,
|
|
119
|
-
plugins: []
|
|
120
|
-
},
|
|
121
|
-
viteConfig
|
|
122
|
-
)
|
|
123
|
-
);
|
|
124
|
-
await devServer.pluginContainer.buildStart({});
|
|
125
|
-
const server = new import_server.ViteNodeServer(devServer);
|
|
126
|
-
(0, import_source_map.installSourcemapsSupport)({
|
|
127
|
-
getSourceMap: (source) => server.getSourceMap(source)
|
|
128
|
-
});
|
|
129
|
-
const runner = new import_client.ViteNodeRunner({
|
|
130
|
-
root: devServer.config.root,
|
|
131
|
-
base: devServer.config.base,
|
|
132
|
-
fetchModule(id) {
|
|
133
|
-
return server.fetchModule(id);
|
|
134
|
-
},
|
|
135
|
-
resolveId(id, importer) {
|
|
136
|
-
return server.resolveId(id, importer);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
return { devServer, server, runner };
|
|
140
|
-
}
|
|
141
|
-
var import_server, import_client, import_source_map;
|
|
142
|
-
var init_vite_node = __esm({
|
|
143
|
-
"vite/vite-node.ts"() {
|
|
144
|
-
"use strict";
|
|
145
|
-
import_server = require("vite-node/server");
|
|
146
|
-
import_client = require("vite-node/client");
|
|
147
|
-
import_source_map = require("vite-node/source-map");
|
|
148
|
-
init_vite();
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// config/routes.ts
|
|
153
|
-
function setAppDirectory(directory) {
|
|
154
|
-
globalThis.__reactRouterAppDirectory = directory;
|
|
155
|
-
}
|
|
156
|
-
function validateRouteConfig({
|
|
157
|
-
routeConfigFile,
|
|
158
|
-
routeConfig
|
|
159
|
-
}) {
|
|
160
|
-
if (!routeConfig) {
|
|
161
|
-
return {
|
|
162
|
-
valid: false,
|
|
163
|
-
message: `Route config must be the default export in "${routeConfigFile}".`
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (!Array.isArray(routeConfig)) {
|
|
167
|
-
return {
|
|
168
|
-
valid: false,
|
|
169
|
-
message: `Route config in "${routeConfigFile}" must be an array.`
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
let { issues } = v.safeParse(resolvedRouteConfigSchema, routeConfig);
|
|
173
|
-
if (issues?.length) {
|
|
174
|
-
let { root, nested } = v.flatten(issues);
|
|
175
|
-
return {
|
|
176
|
-
valid: false,
|
|
177
|
-
message: [
|
|
178
|
-
`Route config in "${routeConfigFile}" is invalid.`,
|
|
179
|
-
root ? `${root}` : [],
|
|
180
|
-
nested ? Object.entries(nested).map(
|
|
181
|
-
([path10, message]) => `Path: routes.${path10}
|
|
182
|
-
${message}`
|
|
183
|
-
) : []
|
|
184
|
-
].flat().join("\n\n")
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
return { valid: true };
|
|
188
|
-
}
|
|
189
|
-
function configRoutesToRouteManifest(appDirectory, routes2, rootId = "root") {
|
|
190
|
-
let routeManifest = {};
|
|
191
|
-
function walk(route, parentId) {
|
|
192
|
-
let id = route.id || createRouteId(route.file);
|
|
193
|
-
let manifestItem = {
|
|
194
|
-
id,
|
|
195
|
-
parentId,
|
|
196
|
-
file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
|
|
197
|
-
path: route.path,
|
|
198
|
-
index: route.index,
|
|
199
|
-
caseSensitive: route.caseSensitive
|
|
200
|
-
};
|
|
201
|
-
if (routeManifest.hasOwnProperty(id)) {
|
|
202
|
-
throw new Error(
|
|
203
|
-
`Unable to define routes with duplicate route id: "${id}"`
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
routeManifest[id] = manifestItem;
|
|
207
|
-
if (route.children) {
|
|
208
|
-
for (let child of route.children) {
|
|
209
|
-
walk(child, id);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
for (let route of routes2) {
|
|
214
|
-
walk(route, rootId);
|
|
215
|
-
}
|
|
216
|
-
return routeManifest;
|
|
217
|
-
}
|
|
218
|
-
function createRouteId(file) {
|
|
219
|
-
return Path.normalize(stripFileExtension(file));
|
|
220
|
-
}
|
|
221
|
-
function stripFileExtension(file) {
|
|
222
|
-
return file.replace(/\.[a-z0-9]+$/i, "");
|
|
223
|
-
}
|
|
224
|
-
var Path, v, import_pick, routeConfigEntrySchema, resolvedRouteConfigSchema;
|
|
225
|
-
var init_routes = __esm({
|
|
226
|
-
"config/routes.ts"() {
|
|
227
|
-
"use strict";
|
|
228
|
-
Path = __toESM(require("pathe"));
|
|
229
|
-
v = __toESM(require("valibot"));
|
|
230
|
-
import_pick = __toESM(require("lodash/pick"));
|
|
231
|
-
init_invariant();
|
|
232
|
-
routeConfigEntrySchema = v.pipe(
|
|
233
|
-
v.custom((value) => {
|
|
234
|
-
return !(typeof value === "object" && value !== null && "then" in value && "catch" in value);
|
|
235
|
-
}, "Invalid type: Expected object but received a promise. Did you forget to await?"),
|
|
236
|
-
v.object({
|
|
237
|
-
id: v.optional(v.string()),
|
|
238
|
-
path: v.optional(v.string()),
|
|
239
|
-
index: v.optional(v.boolean()),
|
|
240
|
-
caseSensitive: v.optional(v.boolean()),
|
|
241
|
-
file: v.string(),
|
|
242
|
-
children: v.optional(v.array(v.lazy(() => routeConfigEntrySchema)))
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
resolvedRouteConfigSchema = v.array(routeConfigEntrySchema);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
// cli/detectPackageManager.ts
|
|
250
|
-
var init_detectPackageManager = __esm({
|
|
251
|
-
"cli/detectPackageManager.ts"() {
|
|
252
|
-
"use strict";
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
// config/config.ts
|
|
257
|
-
function ok(value) {
|
|
258
|
-
return { ok: true, value };
|
|
259
|
-
}
|
|
260
|
-
function err(error) {
|
|
261
|
-
return { ok: false, error };
|
|
262
|
-
}
|
|
263
|
-
async function resolveConfig({
|
|
264
|
-
root,
|
|
265
|
-
viteNodeContext,
|
|
266
|
-
reactRouterConfigFile
|
|
267
|
-
}) {
|
|
268
|
-
let reactRouterUserConfig = {};
|
|
269
|
-
if (reactRouterConfigFile) {
|
|
270
|
-
try {
|
|
271
|
-
if (!import_node_fs.default.existsSync(reactRouterConfigFile)) {
|
|
272
|
-
return err(`${reactRouterConfigFile} no longer exists`);
|
|
273
|
-
}
|
|
274
|
-
let configModule = await viteNodeContext.runner.executeFile(
|
|
275
|
-
reactRouterConfigFile
|
|
276
|
-
);
|
|
277
|
-
if (configModule.default === void 0) {
|
|
278
|
-
return err(`${reactRouterConfigFile} must provide a default export`);
|
|
279
|
-
}
|
|
280
|
-
if (typeof configModule.default !== "object") {
|
|
281
|
-
return err(`${reactRouterConfigFile} must export a config`);
|
|
282
|
-
}
|
|
283
|
-
reactRouterUserConfig = configModule.default;
|
|
284
|
-
} catch (error) {
|
|
285
|
-
return err(`Error loading ${reactRouterConfigFile}: ${error}`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
reactRouterUserConfig = deepFreeze((0, import_cloneDeep.default)(reactRouterUserConfig));
|
|
289
|
-
let presets = (await Promise.all(
|
|
290
|
-
(reactRouterUserConfig.presets ?? []).map(async (preset) => {
|
|
291
|
-
if (!preset.name) {
|
|
292
|
-
throw new Error(
|
|
293
|
-
"React Router presets must have a `name` property defined."
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
if (!preset.reactRouterConfig) {
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
let configPreset = (0, import_omit.default)(
|
|
300
|
-
await preset.reactRouterConfig({ reactRouterUserConfig }),
|
|
301
|
-
excludedConfigPresetKeys
|
|
302
|
-
);
|
|
303
|
-
return configPreset;
|
|
304
|
-
})
|
|
305
|
-
)).filter(function isNotNull(value) {
|
|
306
|
-
return value !== null;
|
|
307
|
-
});
|
|
308
|
-
let defaults = {
|
|
309
|
-
basename: "/",
|
|
310
|
-
buildDirectory: "build",
|
|
311
|
-
serverBuildFile: "index.js",
|
|
312
|
-
serverModuleFormat: "esm",
|
|
313
|
-
ssr: true
|
|
314
|
-
};
|
|
315
|
-
let {
|
|
316
|
-
appDirectory: userAppDirectory,
|
|
317
|
-
basename: basename2,
|
|
318
|
-
buildDirectory: userBuildDirectory,
|
|
319
|
-
buildEnd,
|
|
320
|
-
prerender,
|
|
321
|
-
serverBuildFile,
|
|
322
|
-
serverBundles,
|
|
323
|
-
serverModuleFormat,
|
|
324
|
-
ssr
|
|
325
|
-
} = {
|
|
326
|
-
...defaults,
|
|
327
|
-
// Default values should be completely overridden by user/preset config, not merged
|
|
328
|
-
...mergeReactRouterConfig(...presets, reactRouterUserConfig)
|
|
329
|
-
};
|
|
330
|
-
if (!ssr && serverBundles) {
|
|
331
|
-
serverBundles = void 0;
|
|
332
|
-
}
|
|
333
|
-
let isValidPrerenderConfig = prerender == null || typeof prerender === "boolean" || Array.isArray(prerender) || typeof prerender === "function";
|
|
334
|
-
if (!isValidPrerenderConfig) {
|
|
335
|
-
return err(
|
|
336
|
-
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
340
|
-
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
341
|
-
let rootRouteFile = findEntry(appDirectory, "root");
|
|
342
|
-
if (!rootRouteFile) {
|
|
343
|
-
let rootRouteDisplayPath = import_pathe3.default.relative(
|
|
344
|
-
root,
|
|
345
|
-
import_pathe3.default.join(appDirectory, "root.tsx")
|
|
346
|
-
);
|
|
347
|
-
return err(
|
|
348
|
-
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
let routes2 = {
|
|
352
|
-
root: { path: "", id: "root", file: rootRouteFile }
|
|
353
|
-
};
|
|
354
|
-
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
355
|
-
try {
|
|
356
|
-
if (!routeConfigFile) {
|
|
357
|
-
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
358
|
-
root,
|
|
359
|
-
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
360
|
-
);
|
|
361
|
-
return err(`Route config file not found at "${routeConfigDisplayPath}".`);
|
|
362
|
-
}
|
|
363
|
-
setAppDirectory(appDirectory);
|
|
364
|
-
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
365
|
-
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
366
|
-
)).default;
|
|
367
|
-
let routeConfig = await routeConfigExport;
|
|
368
|
-
let result = validateRouteConfig({
|
|
369
|
-
routeConfigFile,
|
|
370
|
-
routeConfig
|
|
371
|
-
});
|
|
372
|
-
if (!result.valid) {
|
|
373
|
-
return err(result.message);
|
|
374
|
-
}
|
|
375
|
-
routes2 = {
|
|
376
|
-
...routes2,
|
|
377
|
-
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
378
|
-
};
|
|
379
|
-
} catch (error) {
|
|
380
|
-
return err(
|
|
381
|
-
[
|
|
382
|
-
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
383
|
-
"",
|
|
384
|
-
error.loc?.file && error.loc?.column && error.frame ? [
|
|
385
|
-
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
386
|
-
error.frame.trim?.()
|
|
387
|
-
] : error.stack
|
|
388
|
-
].flat().join("\n")
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
let future = {
|
|
392
|
-
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
393
|
-
};
|
|
394
|
-
let reactRouterConfig = deepFreeze({
|
|
395
|
-
appDirectory,
|
|
396
|
-
basename: basename2,
|
|
397
|
-
buildDirectory,
|
|
398
|
-
buildEnd,
|
|
399
|
-
future,
|
|
400
|
-
prerender,
|
|
401
|
-
routes: routes2,
|
|
402
|
-
serverBuildFile,
|
|
403
|
-
serverBundles,
|
|
404
|
-
serverModuleFormat,
|
|
405
|
-
ssr
|
|
406
|
-
});
|
|
407
|
-
for (let preset of reactRouterUserConfig.presets ?? []) {
|
|
408
|
-
await preset.reactRouterConfigResolved?.({ reactRouterConfig });
|
|
409
|
-
}
|
|
410
|
-
return ok(reactRouterConfig);
|
|
411
|
-
}
|
|
412
|
-
async function createConfigLoader({
|
|
413
|
-
rootDirectory: root,
|
|
414
|
-
watch: watch2
|
|
415
|
-
}) {
|
|
416
|
-
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
417
|
-
let viteNodeContext = await createContext({
|
|
418
|
-
root,
|
|
419
|
-
mode: watch2 ? "development" : "production",
|
|
420
|
-
server: !watch2 ? { watch: null } : {},
|
|
421
|
-
ssr: {
|
|
422
|
-
external: ssrExternals
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
426
|
-
absolute: true
|
|
427
|
-
});
|
|
428
|
-
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
|
|
429
|
-
let appDirectory;
|
|
430
|
-
let initialConfigResult = await getConfig();
|
|
431
|
-
if (!initialConfigResult.ok) {
|
|
432
|
-
throw new Error(initialConfigResult.error);
|
|
433
|
-
}
|
|
434
|
-
appDirectory = initialConfigResult.value.appDirectory;
|
|
435
|
-
let lastConfig = initialConfigResult.value;
|
|
436
|
-
let fsWatcher;
|
|
437
|
-
let changeHandlers = [];
|
|
438
|
-
return {
|
|
439
|
-
getConfig,
|
|
440
|
-
onChange: (handler) => {
|
|
441
|
-
if (!watch2) {
|
|
442
|
-
throw new Error(
|
|
443
|
-
"onChange is not supported when watch mode is disabled"
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
changeHandlers.push(handler);
|
|
447
|
-
if (!fsWatcher) {
|
|
448
|
-
fsWatcher = import_chokidar.default.watch(
|
|
449
|
-
[
|
|
450
|
-
...reactRouterConfigFile ? [reactRouterConfigFile] : [],
|
|
451
|
-
appDirectory
|
|
452
|
-
],
|
|
453
|
-
{ ignoreInitial: true }
|
|
454
|
-
);
|
|
455
|
-
fsWatcher.on("all", async (...args) => {
|
|
456
|
-
let [event, rawFilepath] = args;
|
|
457
|
-
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
458
|
-
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
459
|
-
let configCodeUpdated = Boolean(
|
|
460
|
-
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
461
|
-
);
|
|
462
|
-
if (configCodeUpdated || appFileAddedOrRemoved) {
|
|
463
|
-
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
464
|
-
viteNodeContext.runner?.moduleCache.clear();
|
|
465
|
-
}
|
|
466
|
-
if (appFileAddedOrRemoved || configCodeUpdated) {
|
|
467
|
-
let result = await getConfig();
|
|
468
|
-
let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
|
|
469
|
-
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
|
|
470
|
-
for (let handler2 of changeHandlers) {
|
|
471
|
-
handler2({
|
|
472
|
-
result,
|
|
473
|
-
configCodeUpdated,
|
|
474
|
-
configChanged,
|
|
475
|
-
routeConfigChanged,
|
|
476
|
-
path: filepath,
|
|
477
|
-
event
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
if (result.ok) {
|
|
481
|
-
lastConfig = result.value;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
return () => {
|
|
487
|
-
changeHandlers = changeHandlers.filter(
|
|
488
|
-
(changeHandler) => changeHandler !== handler
|
|
489
|
-
);
|
|
490
|
-
};
|
|
491
|
-
},
|
|
492
|
-
close: async () => {
|
|
493
|
-
changeHandlers = [];
|
|
494
|
-
await viteNodeContext.devServer.close();
|
|
495
|
-
await fsWatcher?.close();
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
function findEntry(dir, basename2, options) {
|
|
500
|
-
for (let ext of entryExts) {
|
|
501
|
-
let file = import_pathe3.default.resolve(dir, basename2 + ext);
|
|
502
|
-
if (import_node_fs.default.existsSync(file)) {
|
|
503
|
-
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return void 0;
|
|
507
|
-
}
|
|
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;
|
|
509
|
-
var init_config = __esm({
|
|
510
|
-
"config/config.ts"() {
|
|
511
|
-
"use strict";
|
|
512
|
-
import_node_fs = __toESM(require("fs"));
|
|
513
|
-
import_node_child_process = require("child_process");
|
|
514
|
-
import_package_json = __toESM(require("@npmcli/package-json"));
|
|
515
|
-
init_vite_node();
|
|
516
|
-
import_pathe3 = __toESM(require("pathe"));
|
|
517
|
-
import_chokidar = __toESM(require("chokidar"));
|
|
518
|
-
import_picocolors = __toESM(require("picocolors"));
|
|
519
|
-
import_pick2 = __toESM(require("lodash/pick"));
|
|
520
|
-
import_omit = __toESM(require("lodash/omit"));
|
|
521
|
-
import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
522
|
-
import_isEqual = __toESM(require("lodash/isEqual"));
|
|
523
|
-
init_routes();
|
|
524
|
-
init_detectPackageManager();
|
|
525
|
-
init_is_react_router_repo();
|
|
526
|
-
excludedConfigPresetKeys = ["presets"];
|
|
527
|
-
branchRouteProperties = [
|
|
528
|
-
"id",
|
|
529
|
-
"path",
|
|
530
|
-
"file",
|
|
531
|
-
"index"
|
|
532
|
-
];
|
|
533
|
-
configRouteToBranchRoute = (configRoute) => (0, import_pick2.default)(configRoute, branchRouteProperties);
|
|
534
|
-
mergeReactRouterConfig = (...configs) => {
|
|
535
|
-
let reducer = (configA, configB) => {
|
|
536
|
-
let mergeRequired = (key) => configA[key] !== void 0 && configB[key] !== void 0;
|
|
537
|
-
return {
|
|
538
|
-
...configA,
|
|
539
|
-
...configB,
|
|
540
|
-
...mergeRequired("buildEnd") ? {
|
|
541
|
-
buildEnd: async (...args) => {
|
|
542
|
-
await Promise.all([
|
|
543
|
-
configA.buildEnd?.(...args),
|
|
544
|
-
configB.buildEnd?.(...args)
|
|
545
|
-
]);
|
|
546
|
-
}
|
|
547
|
-
} : {},
|
|
548
|
-
...mergeRequired("future") ? {
|
|
549
|
-
future: {
|
|
550
|
-
...configA.future,
|
|
551
|
-
...configB.future
|
|
552
|
-
}
|
|
553
|
-
} : {},
|
|
554
|
-
...mergeRequired("presets") ? {
|
|
555
|
-
presets: [...configA.presets ?? [], ...configB.presets ?? []]
|
|
556
|
-
} : {}
|
|
557
|
-
};
|
|
558
|
-
};
|
|
559
|
-
return configs.reduce(reducer, {});
|
|
560
|
-
};
|
|
561
|
-
deepFreeze = (o) => {
|
|
562
|
-
Object.freeze(o);
|
|
563
|
-
let oIsFunction = typeof o === "function";
|
|
564
|
-
let hasOwnProp = Object.prototype.hasOwnProperty;
|
|
565
|
-
Object.getOwnPropertyNames(o).forEach(function(prop) {
|
|
566
|
-
if (hasOwnProp.call(o, prop) && (oIsFunction ? prop !== "caller" && prop !== "callee" && prop !== "arguments" : true) && o[prop] !== null && (typeof o[prop] === "object" || typeof o[prop] === "function") && !Object.isFrozen(o[prop])) {
|
|
567
|
-
deepFreeze(o[prop]);
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
return o;
|
|
571
|
-
};
|
|
572
|
-
ssrExternals = isReactRouterRepo() ? [
|
|
573
|
-
// This is only needed within this repo because these packages
|
|
574
|
-
// are linked to a directory outside of node_modules so Vite
|
|
575
|
-
// treats them as internal code by default.
|
|
576
|
-
"react-router",
|
|
577
|
-
"react-router-dom",
|
|
578
|
-
"@react-router/architect",
|
|
579
|
-
"@react-router/cloudflare",
|
|
580
|
-
"@react-router/dev",
|
|
581
|
-
"@react-router/express",
|
|
582
|
-
"@react-router/node",
|
|
583
|
-
"@react-router/serve"
|
|
584
|
-
] : void 0;
|
|
585
|
-
entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
// typegen/paths.ts
|
|
590
|
-
function getTypesDir(ctx) {
|
|
591
|
-
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
592
|
-
}
|
|
593
|
-
function getTypesPath(ctx, route) {
|
|
594
|
-
return Path2.join(
|
|
595
|
-
getTypesDir(ctx),
|
|
596
|
-
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
597
|
-
Path2.dirname(route.file),
|
|
598
|
-
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
var Path2, Pathe;
|
|
602
|
-
var init_paths = __esm({
|
|
603
|
-
"typegen/paths.ts"() {
|
|
604
|
-
"use strict";
|
|
605
|
-
Path2 = __toESM(require("pathe"));
|
|
606
|
-
Pathe = __toESM(require("pathe/utils"));
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
// typegen/generate.ts
|
|
611
|
-
function generate(ctx, route) {
|
|
612
|
-
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
613
|
-
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
614
|
-
const typesPath = getTypesPath(ctx, route);
|
|
615
|
-
const parents = lineage.slice(0, -1);
|
|
616
|
-
const parentTypeImports = parents.map((parent, i) => {
|
|
617
|
-
const rel = Path3.relative(
|
|
618
|
-
Path3.dirname(typesPath),
|
|
619
|
-
getTypesPath(ctx, parent)
|
|
620
|
-
);
|
|
621
|
-
const indent = i === 0 ? "" : " ".repeat(2);
|
|
622
|
-
let source = noExtension(rel);
|
|
623
|
-
if (!source.startsWith("../")) source = "./" + source;
|
|
624
|
-
return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
|
|
625
|
-
}).join("\n");
|
|
626
|
-
return import_dedent.default`
|
|
627
|
-
// React Router generated types for route:
|
|
628
|
-
// ${route.file}
|
|
629
|
-
|
|
630
|
-
import type * as T from "react-router/route-module"
|
|
631
|
-
|
|
632
|
-
${parentTypeImports}
|
|
633
|
-
|
|
634
|
-
type Module = typeof import("../${Pathe2.filename(route.file)}.js")
|
|
635
|
-
|
|
636
|
-
export type Info = {
|
|
637
|
-
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
638
|
-
id: "${route.id}"
|
|
639
|
-
file: "${route.file}"
|
|
640
|
-
path: "${route.path}"
|
|
641
|
-
params: {${formatParamProperties(
|
|
642
|
-
urlpath
|
|
643
|
-
)}} & { [key: string]: string | undefined }
|
|
644
|
-
module: Module
|
|
645
|
-
loaderData: T.CreateLoaderData<Module>
|
|
646
|
-
actionData: T.CreateActionData<Module>
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
export namespace Route {
|
|
650
|
-
export type LinkDescriptors = T.LinkDescriptors
|
|
651
|
-
export type LinksFunction = () => LinkDescriptors
|
|
652
|
-
|
|
653
|
-
export type MetaArgs = T.CreateMetaArgs<Info>
|
|
654
|
-
export type MetaDescriptors = T.MetaDescriptors
|
|
655
|
-
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
656
|
-
|
|
657
|
-
export type HeadersArgs = T.HeadersArgs
|
|
658
|
-
export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
|
|
659
|
-
|
|
660
|
-
export type LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
661
|
-
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
662
|
-
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
663
|
-
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
664
|
-
|
|
665
|
-
export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
|
|
666
|
-
export type ComponentProps = T.CreateComponentProps<Info>
|
|
667
|
-
export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
|
|
668
|
-
}
|
|
669
|
-
`;
|
|
670
|
-
}
|
|
671
|
-
function getRouteLineage(routes2, route) {
|
|
672
|
-
const result = [];
|
|
673
|
-
while (route) {
|
|
674
|
-
result.push(route);
|
|
675
|
-
if (!route.parentId) break;
|
|
676
|
-
route = routes2[route.parentId];
|
|
677
|
-
}
|
|
678
|
-
result.reverse();
|
|
679
|
-
return result;
|
|
680
|
-
}
|
|
681
|
-
function formatParamProperties(urlpath) {
|
|
682
|
-
const params = parseParams(urlpath);
|
|
683
|
-
const properties = Object.entries(params).map(([name, values]) => {
|
|
684
|
-
if (values.length === 1) {
|
|
685
|
-
const isOptional = values[0];
|
|
686
|
-
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
687
|
-
}
|
|
688
|
-
const items = values.map(
|
|
689
|
-
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
690
|
-
);
|
|
691
|
-
return `"${name}": [${items.join(", ")}]`;
|
|
692
|
-
});
|
|
693
|
-
return properties.join("; ");
|
|
694
|
-
}
|
|
695
|
-
function parseParams(urlpath) {
|
|
696
|
-
const result = {};
|
|
697
|
-
let segments = urlpath.split("/");
|
|
698
|
-
segments.forEach((segment) => {
|
|
699
|
-
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
700
|
-
if (!match) return;
|
|
701
|
-
const param = match[1];
|
|
702
|
-
const isOptional = match[2] !== void 0;
|
|
703
|
-
result[param] ??= [];
|
|
704
|
-
result[param].push(isOptional);
|
|
705
|
-
return;
|
|
706
|
-
});
|
|
707
|
-
const hasSplat = segments.at(-1) === "*";
|
|
708
|
-
if (hasSplat) result["*"] = [false];
|
|
709
|
-
return result;
|
|
710
|
-
}
|
|
711
|
-
var import_dedent, Path3, Pathe2, noExtension;
|
|
712
|
-
var init_generate = __esm({
|
|
713
|
-
"typegen/generate.ts"() {
|
|
714
|
-
"use strict";
|
|
715
|
-
import_dedent = __toESM(require("dedent"));
|
|
716
|
-
Path3 = __toESM(require("pathe"));
|
|
717
|
-
Pathe2 = __toESM(require("pathe/utils"));
|
|
718
|
-
init_paths();
|
|
719
|
-
noExtension = (path10) => Path3.join(Path3.dirname(path10), Pathe2.filename(path10));
|
|
720
|
-
}
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
// typegen/index.ts
|
|
724
|
-
async function run(rootDirectory) {
|
|
725
|
-
const ctx = await createContext2({ rootDirectory, watch: false });
|
|
726
|
-
await writeAll(ctx);
|
|
727
|
-
}
|
|
728
|
-
async function watch(rootDirectory, { logger } = {}) {
|
|
729
|
-
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
730
|
-
await writeAll(ctx);
|
|
731
|
-
logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
|
|
732
|
-
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
733
|
-
if (!result.ok) {
|
|
734
|
-
logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
ctx.config = result.value;
|
|
738
|
-
if (routeConfigChanged) {
|
|
739
|
-
await writeAll(ctx);
|
|
740
|
-
logger?.info(import_picocolors2.default.green("regenerated types"), {
|
|
741
|
-
timestamp: true,
|
|
742
|
-
clear: true
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
});
|
|
746
|
-
return {
|
|
747
|
-
close: async () => await ctx.configLoader.close()
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
async function createContext2({
|
|
751
|
-
rootDirectory,
|
|
752
|
-
watch: watch2
|
|
753
|
-
}) {
|
|
754
|
-
const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
|
|
755
|
-
const configResult = await configLoader.getConfig();
|
|
756
|
-
if (!configResult.ok) {
|
|
757
|
-
throw new Error(configResult.error);
|
|
758
|
-
}
|
|
759
|
-
const config = configResult.value;
|
|
760
|
-
return {
|
|
761
|
-
configLoader,
|
|
762
|
-
rootDirectory,
|
|
763
|
-
config
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
async function writeAll(ctx) {
|
|
767
|
-
const typegenDir = getTypesDir(ctx);
|
|
768
|
-
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
769
|
-
Object.values(ctx.config.routes).forEach((route) => {
|
|
770
|
-
const typesPath = getTypesPath(ctx, route);
|
|
771
|
-
const content = generate(ctx, route);
|
|
772
|
-
import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
773
|
-
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
var import_node_fs2, Path4, import_picocolors2;
|
|
777
|
-
var init_typegen = __esm({
|
|
778
|
-
"typegen/index.ts"() {
|
|
779
|
-
"use strict";
|
|
780
|
-
import_node_fs2 = __toESM(require("fs"));
|
|
781
|
-
Path4 = __toESM(require("pathe"));
|
|
782
|
-
import_picocolors2 = __toESM(require("picocolors"));
|
|
783
|
-
init_config();
|
|
784
|
-
init_generate();
|
|
785
|
-
init_paths();
|
|
786
|
-
}
|
|
787
|
-
});
|
|
788
|
-
|
|
789
|
-
// vite/babel.ts
|
|
790
|
-
var import_parser, t, traverse, generate2;
|
|
791
|
-
var init_babel = __esm({
|
|
792
|
-
"vite/babel.ts"() {
|
|
793
|
-
"use strict";
|
|
794
|
-
import_parser = require("@babel/parser");
|
|
795
|
-
t = __toESM(require("@babel/types"));
|
|
796
|
-
traverse = require("@babel/traverse").default;
|
|
797
|
-
generate2 = require("@babel/generator").default;
|
|
798
|
-
}
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
// vite/node-adapter.ts
|
|
802
|
-
var import_node_events, import_node_stream, import_set_cookie_parser, import_node;
|
|
803
|
-
var init_node_adapter = __esm({
|
|
804
|
-
"vite/node-adapter.ts"() {
|
|
805
|
-
"use strict";
|
|
806
|
-
import_node_events = require("events");
|
|
807
|
-
import_node_stream = require("stream");
|
|
808
|
-
import_set_cookie_parser = require("set-cookie-parser");
|
|
809
|
-
import_node = require("@react-router/node");
|
|
810
|
-
init_invariant();
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
|
|
814
|
-
// vite/resolve-file-url.ts
|
|
815
|
-
var path4;
|
|
816
|
-
var init_resolve_file_url = __esm({
|
|
817
|
-
"vite/resolve-file-url.ts"() {
|
|
818
|
-
"use strict";
|
|
819
|
-
path4 = __toESM(require("path"));
|
|
820
|
-
init_vite();
|
|
821
|
-
}
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
// vite/styles.ts
|
|
825
|
-
var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
826
|
-
var init_styles = __esm({
|
|
827
|
-
"vite/styles.ts"() {
|
|
828
|
-
"use strict";
|
|
829
|
-
path5 = __toESM(require("path"));
|
|
830
|
-
import_react_router = require("react-router");
|
|
831
|
-
init_resolve_file_url();
|
|
832
|
-
init_vite();
|
|
833
|
-
cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
834
|
-
cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
835
|
-
}
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
// vite/virtual-module.ts
|
|
839
|
-
function create(name) {
|
|
840
|
-
let id = `virtual:react-router/${name}`;
|
|
841
|
-
return {
|
|
842
|
-
id,
|
|
843
|
-
resolvedId: `\0${id}`,
|
|
844
|
-
url: `/@id/__x00__${id}`
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
var init_virtual_module = __esm({
|
|
848
|
-
"vite/virtual-module.ts"() {
|
|
849
|
-
"use strict";
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
|
|
853
|
-
// vite/combine-urls.ts
|
|
854
|
-
var init_combine_urls = __esm({
|
|
855
|
-
"vite/combine-urls.ts"() {
|
|
856
|
-
"use strict";
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
// vite/remove-exports.ts
|
|
861
|
-
var import_babel_dead_code_elimination;
|
|
862
|
-
var init_remove_exports = __esm({
|
|
863
|
-
"vite/remove-exports.ts"() {
|
|
864
|
-
"use strict";
|
|
865
|
-
import_babel_dead_code_elimination = require("babel-dead-code-elimination");
|
|
866
|
-
init_babel();
|
|
867
|
-
}
|
|
868
|
-
});
|
|
869
|
-
|
|
870
|
-
// vite/with-props.ts
|
|
871
|
-
var import_dedent2, vmod;
|
|
872
|
-
var init_with_props = __esm({
|
|
873
|
-
"vite/with-props.ts"() {
|
|
874
|
-
"use strict";
|
|
875
|
-
import_dedent2 = __toESM(require("dedent"));
|
|
876
|
-
init_babel();
|
|
877
|
-
init_virtual_module();
|
|
878
|
-
vmod = create("with-props");
|
|
879
|
-
}
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
// vite/plugin.ts
|
|
883
|
-
async function resolveViteConfig({
|
|
884
|
-
configFile,
|
|
885
|
-
mode,
|
|
886
|
-
root
|
|
887
|
-
}) {
|
|
888
|
-
let vite2 = getVite();
|
|
889
|
-
let viteConfig = await vite2.resolveConfig(
|
|
890
|
-
{ mode, configFile, root },
|
|
891
|
-
"build",
|
|
892
|
-
// command
|
|
893
|
-
"production",
|
|
894
|
-
// default mode
|
|
895
|
-
"production"
|
|
896
|
-
// default NODE_ENV
|
|
897
|
-
);
|
|
898
|
-
if (typeof viteConfig.build.manifest === "string") {
|
|
899
|
-
throw new Error("Custom Vite manifest paths are not supported");
|
|
900
|
-
}
|
|
901
|
-
return viteConfig;
|
|
902
|
-
}
|
|
903
|
-
async function extractPluginContext(viteConfig) {
|
|
904
|
-
return viteConfig["__reactRouterPluginContext"];
|
|
905
|
-
}
|
|
906
|
-
async function loadPluginContext({
|
|
907
|
-
configFile,
|
|
908
|
-
root
|
|
909
|
-
}) {
|
|
910
|
-
if (!root) {
|
|
911
|
-
root = process.env.REACT_ROUTER_ROOT || process.cwd();
|
|
912
|
-
}
|
|
913
|
-
configFile = configFile ?? findConfig(root, "vite.config", [
|
|
914
|
-
".ts",
|
|
915
|
-
".cts",
|
|
916
|
-
".mts",
|
|
917
|
-
".js",
|
|
918
|
-
".cjs",
|
|
919
|
-
".mjs"
|
|
920
|
-
]);
|
|
921
|
-
if (!configFile) {
|
|
922
|
-
console.error(import_picocolors3.default.red("Vite config file not found"));
|
|
923
|
-
process.exit(1);
|
|
924
|
-
}
|
|
925
|
-
let viteConfig = await resolveViteConfig({ configFile, root });
|
|
926
|
-
let ctx = await extractPluginContext(viteConfig);
|
|
927
|
-
if (!ctx) {
|
|
928
|
-
console.error(
|
|
929
|
-
import_picocolors3.default.red("React Router Vite plugin not found in Vite config")
|
|
930
|
-
);
|
|
931
|
-
process.exit(1);
|
|
932
|
-
}
|
|
933
|
-
return ctx;
|
|
934
|
-
}
|
|
935
|
-
function findConfig(dir, basename2, extensions) {
|
|
936
|
-
for (let ext of extensions) {
|
|
937
|
-
let name = basename2 + ext;
|
|
938
|
-
let file = path6.join(dir, name);
|
|
939
|
-
if (fse.existsSync(file)) return file;
|
|
940
|
-
}
|
|
941
|
-
return void 0;
|
|
942
|
-
}
|
|
943
|
-
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;
|
|
944
|
-
var init_plugin = __esm({
|
|
945
|
-
"vite/plugin.ts"() {
|
|
946
|
-
"use strict";
|
|
947
|
-
import_node_crypto = require("crypto");
|
|
948
|
-
path6 = __toESM(require("path"));
|
|
949
|
-
url = __toESM(require("url"));
|
|
950
|
-
fse = __toESM(require("fs-extra"));
|
|
951
|
-
babel = __toESM(require("@babel/core"));
|
|
952
|
-
import_react_router2 = require("react-router");
|
|
953
|
-
import_es_module_lexer = require("es-module-lexer");
|
|
954
|
-
import_jsesc = __toESM(require("jsesc"));
|
|
955
|
-
import_picocolors3 = __toESM(require("picocolors"));
|
|
956
|
-
init_typegen();
|
|
957
|
-
init_invariant();
|
|
958
|
-
init_babel();
|
|
959
|
-
init_node_adapter();
|
|
960
|
-
init_styles();
|
|
961
|
-
init_virtual_module();
|
|
962
|
-
init_resolve_file_url();
|
|
963
|
-
init_combine_urls();
|
|
964
|
-
init_remove_exports();
|
|
965
|
-
init_vite();
|
|
966
|
-
init_config();
|
|
967
|
-
init_with_props();
|
|
968
|
-
virtualHmrRuntime = create("hmr-runtime");
|
|
969
|
-
virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
970
|
-
virtual = {
|
|
971
|
-
serverBuild: create("server-build"),
|
|
972
|
-
serverManifest: create("server-manifest"),
|
|
973
|
-
browserManifest: create("browser-manifest")
|
|
974
|
-
};
|
|
975
|
-
getServerBuildDirectory = (ctx) => path6.join(
|
|
976
|
-
ctx.reactRouterConfig.buildDirectory,
|
|
977
|
-
"server",
|
|
978
|
-
...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
|
|
979
|
-
);
|
|
980
|
-
defaultEntriesDir = path6.resolve(
|
|
981
|
-
path6.dirname(require.resolve("@react-router/dev/package.json")),
|
|
982
|
-
"dist",
|
|
983
|
-
"config",
|
|
984
|
-
"defaults"
|
|
985
|
-
);
|
|
986
|
-
defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
|
|
987
|
-
invariant(defaultEntries.length > 0, "No default entries found");
|
|
988
|
-
REACT_REFRESH_HEADER = `
|
|
989
|
-
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
990
|
-
|
|
991
|
-
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
992
|
-
let prevRefreshReg;
|
|
993
|
-
let prevRefreshSig;
|
|
994
|
-
|
|
995
|
-
if (import.meta.hot && !inWebWorker) {
|
|
996
|
-
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
997
|
-
throw new Error(
|
|
998
|
-
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
999
|
-
);
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
prevRefreshReg = window.$RefreshReg$;
|
|
1003
|
-
prevRefreshSig = window.$RefreshSig$;
|
|
1004
|
-
window.$RefreshReg$ = (type, id) => {
|
|
1005
|
-
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
1006
|
-
};
|
|
1007
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
1008
|
-
}`.replaceAll("\n", "");
|
|
1009
|
-
}
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
|
-
// vite/profiler.ts
|
|
1013
|
-
var import_node_fs3, import_node_path, import_picocolors4, getSession, start, profileCount, stop;
|
|
1014
|
-
var init_profiler = __esm({
|
|
1015
|
-
"vite/profiler.ts"() {
|
|
1016
|
-
"use strict";
|
|
1017
|
-
import_node_fs3 = __toESM(require("fs"));
|
|
1018
|
-
import_node_path = __toESM(require("path"));
|
|
1019
|
-
import_picocolors4 = __toESM(require("picocolors"));
|
|
1020
|
-
getSession = () => global.__reactRouter_profile_session;
|
|
1021
|
-
start = async (callback) => {
|
|
1022
|
-
let inspector = await import("inspector").then((r) => r.default);
|
|
1023
|
-
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
1024
|
-
session.connect();
|
|
1025
|
-
session.post("Profiler.enable", () => {
|
|
1026
|
-
session.post("Profiler.start", callback);
|
|
1027
|
-
});
|
|
1028
|
-
};
|
|
1029
|
-
profileCount = 0;
|
|
1030
|
-
stop = (log) => {
|
|
1031
|
-
let session = getSession();
|
|
1032
|
-
if (!session) return;
|
|
1033
|
-
return new Promise((res, rej) => {
|
|
1034
|
-
session.post("Profiler.stop", (err2, { profile }) => {
|
|
1035
|
-
if (err2) return rej(err2);
|
|
1036
|
-
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
1037
|
-
import_node_fs3.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
1038
|
-
log(
|
|
1039
|
-
import_picocolors4.default.yellow(
|
|
1040
|
-
`CPU profile written to ${import_picocolors4.default.white(import_picocolors4.default.dim(outPath))}`
|
|
1041
|
-
)
|
|
1042
|
-
);
|
|
1043
|
-
global.__reactRouter_profile_session = void 0;
|
|
1044
|
-
res();
|
|
1045
|
-
});
|
|
1046
|
-
});
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
});
|
|
1050
|
-
|
|
1051
|
-
// vite/build.ts
|
|
1052
|
-
var build_exports = {};
|
|
1053
|
-
__export(build_exports, {
|
|
1054
|
-
build: () => build
|
|
1055
|
-
});
|
|
1056
|
-
function getAddressableRoutes(routes2) {
|
|
1057
|
-
let nonAddressableIds = /* @__PURE__ */ new Set();
|
|
1058
|
-
for (let id in routes2) {
|
|
1059
|
-
let route = routes2[id];
|
|
1060
|
-
if (route.index) {
|
|
1061
|
-
invariant(
|
|
1062
|
-
route.parentId,
|
|
1063
|
-
`Expected index route "${route.id}" to have "parentId" set`
|
|
1064
|
-
);
|
|
1065
|
-
nonAddressableIds.add(route.parentId);
|
|
1066
|
-
}
|
|
1067
|
-
if (typeof route.path !== "string" && !route.index) {
|
|
1068
|
-
nonAddressableIds.add(id);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
return Object.values(routes2).filter(
|
|
1072
|
-
(route) => !nonAddressableIds.has(route.id)
|
|
1073
|
-
);
|
|
1074
|
-
}
|
|
1075
|
-
function getRouteBranch(routes2, routeId) {
|
|
1076
|
-
let branch = [];
|
|
1077
|
-
let currentRouteId = routeId;
|
|
1078
|
-
while (currentRouteId) {
|
|
1079
|
-
let route = routes2[currentRouteId];
|
|
1080
|
-
invariant(route, `Missing route for ${currentRouteId}`);
|
|
1081
|
-
branch.push(route);
|
|
1082
|
-
currentRouteId = route.parentId;
|
|
1083
|
-
}
|
|
1084
|
-
return branch.reverse();
|
|
1085
|
-
}
|
|
1086
|
-
async function getServerBuilds(ctx) {
|
|
1087
|
-
let { rootDirectory } = ctx;
|
|
1088
|
-
const { routes: routes2, serverBuildFile, serverBundles, appDirectory } = ctx.reactRouterConfig;
|
|
1089
|
-
let serverBuildDirectory = getServerBuildDirectory(ctx);
|
|
1090
|
-
if (!serverBundles) {
|
|
1091
|
-
return {
|
|
1092
|
-
serverBuilds: [{ ssr: true }],
|
|
1093
|
-
buildManifest: { routes: routes2 }
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
let { normalizePath } = await import("vite");
|
|
1097
|
-
let resolvedAppDirectory = import_node_path2.default.resolve(rootDirectory, appDirectory);
|
|
1098
|
-
let rootRelativeRoutes = Object.fromEntries(
|
|
1099
|
-
Object.entries(routes2).map(([id, route]) => {
|
|
1100
|
-
let filePath = import_node_path2.default.join(resolvedAppDirectory, route.file);
|
|
1101
|
-
let rootRelativeFilePath = normalizePath(
|
|
1102
|
-
import_node_path2.default.relative(rootDirectory, filePath)
|
|
1103
|
-
);
|
|
1104
|
-
return [id, { ...route, file: rootRelativeFilePath }];
|
|
1105
|
-
})
|
|
1106
|
-
);
|
|
1107
|
-
let buildManifest = {
|
|
1108
|
-
serverBundles: {},
|
|
1109
|
-
routeIdToServerBundleId: {},
|
|
1110
|
-
routes: rootRelativeRoutes
|
|
1111
|
-
};
|
|
1112
|
-
let serverBundleBuildConfigById = /* @__PURE__ */ new Map();
|
|
1113
|
-
await Promise.all(
|
|
1114
|
-
getAddressableRoutes(routes2).map(async (route) => {
|
|
1115
|
-
let branch = getRouteBranch(routes2, route.id);
|
|
1116
|
-
let serverBundleId = await serverBundles({
|
|
1117
|
-
branch: branch.map(
|
|
1118
|
-
(route2) => configRouteToBranchRoute({
|
|
1119
|
-
...route2,
|
|
1120
|
-
// Ensure absolute paths are passed to the serverBundles function
|
|
1121
|
-
file: import_node_path2.default.join(resolvedAppDirectory, route2.file)
|
|
1122
|
-
})
|
|
1123
|
-
)
|
|
1124
|
-
});
|
|
1125
|
-
if (typeof serverBundleId !== "string") {
|
|
1126
|
-
throw new Error(`The "serverBundles" function must return a string`);
|
|
1127
|
-
}
|
|
1128
|
-
if (!/^[a-zA-Z0-9-_]+$/.test(serverBundleId)) {
|
|
1129
|
-
throw new Error(
|
|
1130
|
-
`The "serverBundles" function must only return strings containing alphanumeric characters, hyphens and underscores.`
|
|
1131
|
-
);
|
|
1132
|
-
}
|
|
1133
|
-
buildManifest.routeIdToServerBundleId[route.id] = serverBundleId;
|
|
1134
|
-
let relativeServerBundleDirectory = import_node_path2.default.relative(
|
|
1135
|
-
rootDirectory,
|
|
1136
|
-
import_node_path2.default.join(serverBuildDirectory, serverBundleId)
|
|
1137
|
-
);
|
|
1138
|
-
let serverBuildConfig = serverBundleBuildConfigById.get(serverBundleId);
|
|
1139
|
-
if (!serverBuildConfig) {
|
|
1140
|
-
buildManifest.serverBundles[serverBundleId] = {
|
|
1141
|
-
id: serverBundleId,
|
|
1142
|
-
file: normalizePath(
|
|
1143
|
-
import_node_path2.default.join(relativeServerBundleDirectory, serverBuildFile)
|
|
1144
|
-
)
|
|
1145
|
-
};
|
|
1146
|
-
serverBuildConfig = {
|
|
1147
|
-
routes: {},
|
|
1148
|
-
serverBundleId
|
|
1149
|
-
};
|
|
1150
|
-
serverBundleBuildConfigById.set(serverBundleId, serverBuildConfig);
|
|
1151
|
-
}
|
|
1152
|
-
for (let route2 of branch) {
|
|
1153
|
-
serverBuildConfig.routes[route2.id] = route2;
|
|
1154
|
-
}
|
|
1155
|
-
})
|
|
1156
|
-
);
|
|
1157
|
-
let serverBuilds = Array.from(serverBundleBuildConfigById.values()).map(
|
|
1158
|
-
(serverBundleBuildConfig) => {
|
|
1159
|
-
let serverBuild = {
|
|
1160
|
-
ssr: true,
|
|
1161
|
-
serverBundleBuildConfig
|
|
1162
|
-
};
|
|
1163
|
-
return serverBuild;
|
|
1164
|
-
}
|
|
1165
|
-
);
|
|
1166
|
-
return {
|
|
1167
|
-
serverBuilds,
|
|
1168
|
-
buildManifest
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
1172
|
-
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
1173
|
-
let isWithinRoot = () => {
|
|
1174
|
-
let relativePath = import_node_path2.default.relative(ctx.rootDirectory, buildDirectory);
|
|
1175
|
-
return !relativePath.startsWith("..") && !import_node_path2.default.isAbsolute(relativePath);
|
|
1176
|
-
};
|
|
1177
|
-
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
1178
|
-
await import_fs_extra.default.remove(buildDirectory);
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
function getViteManifestPaths(ctx, serverBuilds) {
|
|
1182
|
-
let buildRelative = (pathname) => import_node_path2.default.resolve(ctx.reactRouterConfig.buildDirectory, pathname);
|
|
1183
|
-
let viteManifestPaths = [
|
|
1184
|
-
"client/.vite/manifest.json",
|
|
1185
|
-
...serverBuilds.map(({ serverBundleBuildConfig }) => {
|
|
1186
|
-
let serverBundleId = serverBundleBuildConfig?.serverBundleId;
|
|
1187
|
-
let serverBundlePath = serverBundleId ? serverBundleId + "/" : "";
|
|
1188
|
-
return `server/${serverBundlePath}.vite/manifest.json`;
|
|
1189
|
-
})
|
|
1190
|
-
].map((srcPath) => buildRelative(srcPath));
|
|
1191
|
-
return viteManifestPaths;
|
|
1192
|
-
}
|
|
1193
|
-
async function build(root, {
|
|
1194
|
-
assetsInlineLimit,
|
|
1195
|
-
clearScreen,
|
|
1196
|
-
config: configFile,
|
|
1197
|
-
emptyOutDir,
|
|
1198
|
-
force,
|
|
1199
|
-
logLevel,
|
|
1200
|
-
minify,
|
|
1201
|
-
mode,
|
|
1202
|
-
sourcemapClient,
|
|
1203
|
-
sourcemapServer
|
|
1204
|
-
}) {
|
|
1205
|
-
await preloadVite();
|
|
1206
|
-
let viteConfig = await resolveViteConfig({ configFile, mode, root });
|
|
1207
|
-
const ctx = await extractPluginContext(viteConfig);
|
|
1208
|
-
if (!ctx) {
|
|
1209
|
-
console.error(
|
|
1210
|
-
import_picocolors5.default.red("React Router Vite plugin not found in Vite config")
|
|
1211
|
-
);
|
|
1212
|
-
process.exit(1);
|
|
1213
|
-
}
|
|
1214
|
-
let { reactRouterConfig } = ctx;
|
|
1215
|
-
let vite2 = getVite();
|
|
1216
|
-
async function viteBuild({
|
|
1217
|
-
ssr,
|
|
1218
|
-
serverBundleBuildConfig
|
|
1219
|
-
}) {
|
|
1220
|
-
await vite2.build({
|
|
1221
|
-
root,
|
|
1222
|
-
mode,
|
|
1223
|
-
configFile,
|
|
1224
|
-
build: {
|
|
1225
|
-
assetsInlineLimit,
|
|
1226
|
-
emptyOutDir,
|
|
1227
|
-
minify,
|
|
1228
|
-
ssr,
|
|
1229
|
-
sourcemap: ssr ? sourcemapServer : sourcemapClient
|
|
1230
|
-
},
|
|
1231
|
-
optimizeDeps: { force },
|
|
1232
|
-
clearScreen,
|
|
1233
|
-
logLevel,
|
|
1234
|
-
...serverBundleBuildConfig ? { __reactRouterServerBundleBuildConfig: serverBundleBuildConfig } : {}
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
await cleanBuildDirectory(viteConfig, ctx);
|
|
1238
|
-
await viteBuild({ ssr: false });
|
|
1239
|
-
let { serverBuilds, buildManifest } = await getServerBuilds(ctx);
|
|
1240
|
-
await Promise.all(serverBuilds.map(viteBuild));
|
|
1241
|
-
let viteManifestPaths = getViteManifestPaths(ctx, serverBuilds);
|
|
1242
|
-
await Promise.all(
|
|
1243
|
-
viteManifestPaths.map(async (viteManifestPath) => {
|
|
1244
|
-
let manifestExists = await import_fs_extra.default.pathExists(viteManifestPath);
|
|
1245
|
-
if (!manifestExists) return;
|
|
1246
|
-
if (!ctx.viteManifestEnabled) {
|
|
1247
|
-
await import_fs_extra.default.remove(viteManifestPath);
|
|
1248
|
-
}
|
|
1249
|
-
let viteDir = import_node_path2.default.dirname(viteManifestPath);
|
|
1250
|
-
let viteDirFiles = await import_fs_extra.default.readdir(viteDir);
|
|
1251
|
-
if (viteDirFiles.length === 0) {
|
|
1252
|
-
await import_fs_extra.default.remove(viteDir);
|
|
1253
|
-
}
|
|
1254
|
-
})
|
|
1255
|
-
);
|
|
1256
|
-
await reactRouterConfig.buildEnd?.({
|
|
1257
|
-
buildManifest,
|
|
1258
|
-
reactRouterConfig,
|
|
1259
|
-
viteConfig
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1262
|
-
var import_node_path2, import_fs_extra, import_picocolors5;
|
|
1263
|
-
var init_build = __esm({
|
|
1264
|
-
"vite/build.ts"() {
|
|
1265
|
-
"use strict";
|
|
1266
|
-
import_node_path2 = __toESM(require("path"));
|
|
1267
|
-
import_fs_extra = __toESM(require("fs-extra"));
|
|
1268
|
-
import_picocolors5 = __toESM(require("picocolors"));
|
|
1269
|
-
init_plugin();
|
|
1270
|
-
init_config();
|
|
1271
|
-
init_invariant();
|
|
1272
|
-
init_vite();
|
|
1273
|
-
}
|
|
1274
|
-
});
|
|
1275
|
-
|
|
1276
|
-
// vite/dev.ts
|
|
1277
|
-
var dev_exports = {};
|
|
1278
|
-
__export(dev_exports, {
|
|
1279
|
-
dev: () => dev
|
|
1280
|
-
});
|
|
1281
|
-
async function dev(root, {
|
|
1282
|
-
clearScreen,
|
|
1283
|
-
config: configFile,
|
|
1284
|
-
cors,
|
|
1285
|
-
force,
|
|
1286
|
-
host,
|
|
1287
|
-
logLevel,
|
|
1288
|
-
mode,
|
|
1289
|
-
open,
|
|
1290
|
-
port,
|
|
1291
|
-
strictPort
|
|
1292
|
-
}) {
|
|
1293
|
-
await preloadVite();
|
|
1294
|
-
let vite2 = getVite();
|
|
1295
|
-
let server = await vite2.createServer({
|
|
1296
|
-
root,
|
|
1297
|
-
mode,
|
|
1298
|
-
configFile,
|
|
1299
|
-
server: { open, cors, host, port, strictPort },
|
|
1300
|
-
optimizeDeps: { force },
|
|
1301
|
-
clearScreen,
|
|
1302
|
-
logLevel
|
|
1303
|
-
});
|
|
1304
|
-
if (!server.config.plugins.find((plugin2) => plugin2.name === "react-router")) {
|
|
1305
|
-
console.error(
|
|
1306
|
-
import_picocolors6.default.red("React Router Vite plugin not found in Vite config")
|
|
1307
|
-
);
|
|
1308
|
-
process.exit(1);
|
|
1309
|
-
}
|
|
1310
|
-
await server.listen();
|
|
1311
|
-
server.printUrls();
|
|
1312
|
-
let customShortcuts = [
|
|
1313
|
-
{
|
|
1314
|
-
key: "p",
|
|
1315
|
-
description: "start/stop the profiler",
|
|
1316
|
-
async action(server2) {
|
|
1317
|
-
if (getSession()) {
|
|
1318
|
-
await stop(server2.config.logger.info);
|
|
1319
|
-
} else {
|
|
1320
|
-
await start(() => {
|
|
1321
|
-
server2.config.logger.info("Profiler started");
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
];
|
|
1327
|
-
server.bindCLIShortcuts({ print: true, customShortcuts });
|
|
1328
|
-
}
|
|
1329
|
-
var import_picocolors6;
|
|
1330
|
-
var init_dev = __esm({
|
|
1331
|
-
"vite/dev.ts"() {
|
|
1332
|
-
"use strict";
|
|
1333
|
-
import_picocolors6 = __toESM(require("picocolors"));
|
|
1334
|
-
init_vite();
|
|
1335
|
-
init_profiler();
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
12
|
+
import {
|
|
13
|
+
loadPluginContext,
|
|
14
|
+
run,
|
|
15
|
+
watch
|
|
16
|
+
} from "../chunk-B25E3JGK.js";
|
|
17
|
+
import "../chunk-B3M3SF27.js";
|
|
18
|
+
import "../chunk-HICCFFJA.js";
|
|
19
|
+
import {
|
|
20
|
+
start,
|
|
21
|
+
stop
|
|
22
|
+
} from "../chunk-VTJ3CG32.js";
|
|
23
|
+
import {
|
|
24
|
+
getVite,
|
|
25
|
+
preloadVite
|
|
26
|
+
} from "../chunk-X234P535.js";
|
|
27
|
+
import {
|
|
28
|
+
__require
|
|
29
|
+
} from "../chunk-XJYIKBPH.js";
|
|
1338
30
|
|
|
1339
31
|
// cli/run.ts
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
32
|
+
import url from "node:url";
|
|
33
|
+
import arg from "arg";
|
|
34
|
+
import semver from "semver";
|
|
35
|
+
import colors2 from "picocolors";
|
|
1343
36
|
|
|
1344
37
|
// cli/commands.ts
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
38
|
+
import * as path from "node:path";
|
|
39
|
+
import fse from "fs-extra";
|
|
40
|
+
import PackageJson from "@npmcli/package-json";
|
|
41
|
+
import exitHook from "exit-hook";
|
|
42
|
+
import colors from "picocolors";
|
|
1350
43
|
|
|
1351
44
|
// config/format.ts
|
|
1352
45
|
function formatRoutes(routeManifest, format) {
|
|
@@ -1404,31 +97,25 @@ function formatRoutesAsJsx(routeManifest) {
|
|
|
1404
97
|
return output;
|
|
1405
98
|
}
|
|
1406
99
|
|
|
1407
|
-
// cli/commands.ts
|
|
1408
|
-
init_plugin();
|
|
1409
|
-
|
|
1410
100
|
// cli/useJavascript.ts
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
101
|
+
import * as babel from "@babel/core";
|
|
102
|
+
import babelPluginSyntaxJSX from "@babel/plugin-syntax-jsx";
|
|
103
|
+
import babelPresetTypeScript from "@babel/preset-typescript";
|
|
104
|
+
import prettier from "prettier";
|
|
1415
105
|
function transpile(tsx, options = {}) {
|
|
1416
|
-
let mjs =
|
|
106
|
+
let mjs = babel.transformSync(tsx, {
|
|
1417
107
|
compact: false,
|
|
1418
108
|
cwd: options.cwd,
|
|
1419
109
|
filename: options.filename,
|
|
1420
|
-
plugins: [
|
|
1421
|
-
presets: [[
|
|
110
|
+
plugins: [babelPluginSyntaxJSX],
|
|
111
|
+
presets: [[babelPresetTypeScript, { jsx: "preserve" }]],
|
|
1422
112
|
retainLines: true
|
|
1423
113
|
});
|
|
1424
114
|
if (!mjs || !mjs.code) throw new Error("Could not parse TypeScript");
|
|
1425
|
-
return
|
|
115
|
+
return prettier.format(mjs.code, { parser: "babel" });
|
|
1426
116
|
}
|
|
1427
117
|
|
|
1428
118
|
// cli/commands.ts
|
|
1429
|
-
init_profiler();
|
|
1430
|
-
init_typegen();
|
|
1431
|
-
init_vite();
|
|
1432
119
|
async function routes(reactRouterRoot, flags = {}) {
|
|
1433
120
|
let ctx = await loadPluginContext({
|
|
1434
121
|
root: reactRouterRoot,
|
|
@@ -1436,34 +123,34 @@ async function routes(reactRouterRoot, flags = {}) {
|
|
|
1436
123
|
});
|
|
1437
124
|
if (!ctx) {
|
|
1438
125
|
console.error(
|
|
1439
|
-
|
|
126
|
+
colors.red("React Router Vite plugin not found in Vite config")
|
|
1440
127
|
);
|
|
1441
128
|
process.exit(1);
|
|
1442
129
|
}
|
|
1443
130
|
let format = flags.json ? "json" : "jsx";
|
|
1444
131
|
console.log(formatRoutes(ctx.reactRouterConfig.routes, format));
|
|
1445
132
|
}
|
|
1446
|
-
async function
|
|
133
|
+
async function build(root, options = {}) {
|
|
1447
134
|
if (!root) {
|
|
1448
135
|
root = process.env.REACT_ROUTER_ROOT || process.cwd();
|
|
1449
136
|
}
|
|
1450
|
-
let { build:
|
|
137
|
+
let { build: build2 } = await import("../build-VA3X4T4U.js");
|
|
1451
138
|
if (options.profile) {
|
|
1452
139
|
await start();
|
|
1453
140
|
}
|
|
1454
141
|
try {
|
|
1455
|
-
await
|
|
142
|
+
await build2(root, options);
|
|
1456
143
|
} finally {
|
|
1457
144
|
await stop(console.info);
|
|
1458
145
|
}
|
|
1459
146
|
}
|
|
1460
|
-
async function
|
|
1461
|
-
let { dev:
|
|
147
|
+
async function dev(root, options = {}) {
|
|
148
|
+
let { dev: dev2 } = await import("../dev-SLPL2UHO.js");
|
|
1462
149
|
if (options.profile) {
|
|
1463
150
|
await start();
|
|
1464
151
|
}
|
|
1465
|
-
(
|
|
1466
|
-
await
|
|
152
|
+
exitHook(() => stop(console.info));
|
|
153
|
+
await dev2(root, options);
|
|
1467
154
|
await new Promise(() => {
|
|
1468
155
|
});
|
|
1469
156
|
}
|
|
@@ -1490,24 +177,24 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1490
177
|
let entriesArray = Array.from(entries);
|
|
1491
178
|
let list = conjunctionListFormat.format(entriesArray);
|
|
1492
179
|
console.error(
|
|
1493
|
-
|
|
180
|
+
colors.red(`Invalid entry file. Valid entry files are ${list}`)
|
|
1494
181
|
);
|
|
1495
182
|
return;
|
|
1496
183
|
}
|
|
1497
|
-
let pkgJson = await
|
|
184
|
+
let pkgJson = await PackageJson.load(rootDirectory);
|
|
1498
185
|
let deps = pkgJson.content.dependencies ?? {};
|
|
1499
186
|
if (!deps["@react-router/node"]) {
|
|
1500
|
-
console.error(
|
|
187
|
+
console.error(colors.red(`No default server entry detected.`));
|
|
1501
188
|
return;
|
|
1502
189
|
}
|
|
1503
|
-
let defaultsDirectory =
|
|
1504
|
-
|
|
190
|
+
let defaultsDirectory = path.resolve(
|
|
191
|
+
path.dirname(__require.resolve("@react-router/dev/package.json")),
|
|
1505
192
|
"dist",
|
|
1506
193
|
"config",
|
|
1507
194
|
"defaults"
|
|
1508
195
|
);
|
|
1509
|
-
let defaultEntryClient =
|
|
1510
|
-
let defaultEntryServer =
|
|
196
|
+
let defaultEntryClient = path.resolve(defaultsDirectory, "entry.client.tsx");
|
|
197
|
+
let defaultEntryServer = path.resolve(
|
|
1511
198
|
defaultsDirectory,
|
|
1512
199
|
`entry.server.node.tsx`
|
|
1513
200
|
);
|
|
@@ -1516,52 +203,52 @@ async function generateEntry(entry, reactRouterRoot, flags = {}) {
|
|
|
1516
203
|
let useTypeScript = flags.typescript ?? true;
|
|
1517
204
|
let outputExtension = useTypeScript ? "tsx" : "jsx";
|
|
1518
205
|
let outputEntry = `${entry}.${outputExtension}`;
|
|
1519
|
-
let
|
|
206
|
+
let outputFile = path.resolve(appDirectory, outputEntry);
|
|
1520
207
|
if (!useTypeScript) {
|
|
1521
208
|
let javascript = transpile(contents, {
|
|
1522
209
|
cwd: rootDirectory,
|
|
1523
210
|
filename: isServerEntry ? defaultEntryServer : defaultEntryClient
|
|
1524
211
|
});
|
|
1525
|
-
await
|
|
212
|
+
await fse.writeFile(outputFile, javascript, "utf-8");
|
|
1526
213
|
} else {
|
|
1527
|
-
await
|
|
214
|
+
await fse.writeFile(outputFile, contents, "utf-8");
|
|
1528
215
|
}
|
|
1529
216
|
console.log(
|
|
1530
|
-
|
|
1531
|
-
`Entry file ${entry} created at ${
|
|
217
|
+
colors.blue(
|
|
218
|
+
`Entry file ${entry} created at ${path.relative(
|
|
1532
219
|
rootDirectory,
|
|
1533
|
-
|
|
220
|
+
outputFile
|
|
1534
221
|
)}.`
|
|
1535
222
|
)
|
|
1536
223
|
);
|
|
1537
224
|
}
|
|
1538
225
|
async function checkForEntry(rootDirectory, appDirectory, entries2) {
|
|
1539
226
|
for (let entry of entries2) {
|
|
1540
|
-
let entryPath =
|
|
1541
|
-
let exists = await
|
|
227
|
+
let entryPath = path.resolve(appDirectory, entry);
|
|
228
|
+
let exists = await fse.pathExists(entryPath);
|
|
1542
229
|
if (exists) {
|
|
1543
|
-
let
|
|
1544
|
-
console.error(
|
|
230
|
+
let relative2 = path.relative(rootDirectory, entryPath);
|
|
231
|
+
console.error(colors.red(`Entry file ${relative2} already exists.`));
|
|
1545
232
|
return process.exit(1);
|
|
1546
233
|
}
|
|
1547
234
|
}
|
|
1548
235
|
}
|
|
1549
236
|
async function createServerEntry(rootDirectory, appDirectory, inputFile) {
|
|
1550
237
|
await checkForEntry(rootDirectory, appDirectory, serverEntries);
|
|
1551
|
-
let contents = await
|
|
238
|
+
let contents = await fse.readFile(inputFile, "utf-8");
|
|
1552
239
|
return contents;
|
|
1553
240
|
}
|
|
1554
241
|
async function createClientEntry(rootDirectory, appDirectory, inputFile) {
|
|
1555
242
|
await checkForEntry(rootDirectory, appDirectory, clientEntries);
|
|
1556
|
-
let contents = await
|
|
243
|
+
let contents = await fse.readFile(inputFile, "utf-8");
|
|
1557
244
|
return contents;
|
|
1558
245
|
}
|
|
1559
246
|
async function typegen(root, flags) {
|
|
1560
247
|
root ??= process.cwd();
|
|
1561
248
|
if (flags.watch) {
|
|
1562
249
|
await preloadVite();
|
|
1563
|
-
const
|
|
1564
|
-
const logger =
|
|
250
|
+
const vite = getVite();
|
|
251
|
+
const logger = vite.createLogger("info", { prefix: "[react-router]" });
|
|
1565
252
|
await watch(root, { logger });
|
|
1566
253
|
await new Promise(() => {
|
|
1567
254
|
});
|
|
@@ -1572,14 +259,14 @@ async function typegen(root, flags) {
|
|
|
1572
259
|
|
|
1573
260
|
// cli/run.ts
|
|
1574
261
|
var helpText = `
|
|
1575
|
-
${
|
|
262
|
+
${colors2.blueBright("react-router")}
|
|
1576
263
|
|
|
1577
|
-
${
|
|
1578
|
-
$ react-router build [${
|
|
1579
|
-
$ react-router dev [${
|
|
1580
|
-
$ react-router routes [${
|
|
264
|
+
${colors2.underline("Usage")}:
|
|
265
|
+
$ react-router build [${colors2.yellowBright("projectDir")}]
|
|
266
|
+
$ react-router dev [${colors2.yellowBright("projectDir")}]
|
|
267
|
+
$ react-router routes [${colors2.yellowBright("projectDir")}]
|
|
1581
268
|
|
|
1582
|
-
${
|
|
269
|
+
${colors2.underline("Options")}:
|
|
1583
270
|
--help, -h Print this help message and exit
|
|
1584
271
|
--version, -v Print the CLI version and exit
|
|
1585
272
|
--no-color Disable ANSI colors in console output
|
|
@@ -1615,22 +302,22 @@ ${import_picocolors8.default.blueBright("react-router")}
|
|
|
1615
302
|
\`typegen\` Options:
|
|
1616
303
|
--watch Automatically regenerate types whenever route config (\`routes.ts\`) or route modules change
|
|
1617
304
|
|
|
1618
|
-
${
|
|
305
|
+
${colors2.underline("Build your project")}:
|
|
1619
306
|
|
|
1620
307
|
$ react-router build
|
|
1621
308
|
|
|
1622
|
-
${
|
|
309
|
+
${colors2.underline("Run your project locally in development")}:
|
|
1623
310
|
|
|
1624
311
|
$ react-router dev
|
|
1625
312
|
|
|
1626
|
-
${
|
|
313
|
+
${colors2.underline("Show all routes in your app")}:
|
|
1627
314
|
|
|
1628
315
|
$ react-router routes
|
|
1629
316
|
$ react-router routes my-app
|
|
1630
317
|
$ react-router routes --json
|
|
1631
318
|
$ react-router routes --config vite.react-router.config.ts
|
|
1632
319
|
|
|
1633
|
-
${
|
|
320
|
+
${colors2.underline("Reveal the used entry point")}:
|
|
1634
321
|
|
|
1635
322
|
$ react-router reveal entry.client
|
|
1636
323
|
$ react-router reveal entry.server
|
|
@@ -1638,7 +325,7 @@ ${import_picocolors8.default.blueBright("react-router")}
|
|
|
1638
325
|
$ react-router reveal entry.server --no-typescript
|
|
1639
326
|
$ react-router reveal entry.server --config vite.react-router.config.ts
|
|
1640
327
|
|
|
1641
|
-
${
|
|
328
|
+
${colors2.underline("Generate types for route modules")}:
|
|
1642
329
|
|
|
1643
330
|
$ react-router typegen
|
|
1644
331
|
$ react-router typegen --watch
|
|
@@ -1646,7 +333,7 @@ ${import_picocolors8.default.blueBright("react-router")}
|
|
|
1646
333
|
async function run2(argv = process.argv.slice(2)) {
|
|
1647
334
|
let versions = process.versions;
|
|
1648
335
|
let MINIMUM_NODE_VERSION = 20;
|
|
1649
|
-
if (versions && versions.node &&
|
|
336
|
+
if (versions && versions.node && semver.major(versions.node) < MINIMUM_NODE_VERSION) {
|
|
1650
337
|
console.warn(
|
|
1651
338
|
`\uFE0F\u26A0\uFE0F Oops, Node v${versions.node} detected. react-router requires a Node version greater than ${MINIMUM_NODE_VERSION}.`
|
|
1652
339
|
);
|
|
@@ -1656,7 +343,7 @@ async function run2(argv = process.argv.slice(2)) {
|
|
|
1656
343
|
let nextArg = argv[index + 1];
|
|
1657
344
|
return !nextArg || nextArg.startsWith("-");
|
|
1658
345
|
};
|
|
1659
|
-
let args = (
|
|
346
|
+
let args = arg(
|
|
1660
347
|
{
|
|
1661
348
|
"--force": Boolean,
|
|
1662
349
|
"--help": Boolean,
|
|
@@ -1703,11 +390,11 @@ async function run2(argv = process.argv.slice(2)) {
|
|
|
1703
390
|
return;
|
|
1704
391
|
}
|
|
1705
392
|
if (flags.version) {
|
|
1706
|
-
let version =
|
|
393
|
+
let version = __require("../package.json").version;
|
|
1707
394
|
console.log(version);
|
|
1708
395
|
return;
|
|
1709
396
|
}
|
|
1710
|
-
flags.interactive = flags.interactive ??
|
|
397
|
+
flags.interactive = flags.interactive ?? import.meta.url === url.pathToFileURL(process.argv[1]).href;
|
|
1711
398
|
if (args["--no-typescript"]) {
|
|
1712
399
|
flags.typescript = false;
|
|
1713
400
|
}
|
|
@@ -1717,20 +404,20 @@ async function run2(argv = process.argv.slice(2)) {
|
|
|
1717
404
|
await routes(input[1], flags);
|
|
1718
405
|
break;
|
|
1719
406
|
case "build":
|
|
1720
|
-
await
|
|
407
|
+
await build(input[1], flags);
|
|
1721
408
|
break;
|
|
1722
409
|
case "reveal": {
|
|
1723
410
|
await generateEntry(input[1], input[2], flags);
|
|
1724
411
|
break;
|
|
1725
412
|
}
|
|
1726
413
|
case "dev":
|
|
1727
|
-
await
|
|
414
|
+
await dev(input[1], flags);
|
|
1728
415
|
break;
|
|
1729
416
|
case "typegen":
|
|
1730
417
|
await typegen(input[1], flags);
|
|
1731
418
|
break;
|
|
1732
419
|
default:
|
|
1733
|
-
await
|
|
420
|
+
await dev(input[0], flags);
|
|
1734
421
|
}
|
|
1735
422
|
}
|
|
1736
423
|
|