@react-router/dev 7.16.0 → 8.0.0-pre.0
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 +0 -2
- package/bin.cjs +20 -0
- package/dist/build-DM91F_L-.js +41 -0
- package/dist/cli/index.d.ts +2 -1
- package/dist/cli/index.js +378 -2638
- package/dist/config-DvmRcD4Z.d.ts +279 -0
- package/dist/config.d.ts +2 -280
- package/dist/config.js +2 -19
- package/dist/dev-CNEgIjT-.js +53 -0
- package/dist/routes-DXogguGb.js +194 -0
- package/dist/{routes-CZR-bKRt.d.ts → routes-Kx8VZRs3.d.ts} +63 -62
- package/dist/routes.d.ts +3 -2
- package/dist/routes.js +3 -190
- package/dist/typegen-BLMwBSoM.js +859 -0
- package/dist/vite.d.ts +7 -6
- package/dist/vite.js +3225 -6539
- package/module-sync-enabled/index.mjs +2 -2
- package/package.json +53 -59
- package/bin.js +0 -15
- package/dist/vite/cloudflare.d.ts +0 -24
- package/dist/vite/cloudflare.js +0 -938
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/dev
|
|
3
|
+
* @react-router/dev v8.0.0-pre.0
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -9,2554 +9,307 @@
|
|
|
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/ssr-externals.ts
|
|
104
|
-
var ssrExternals;
|
|
105
|
-
var init_ssr_externals = __esm({
|
|
106
|
-
"vite/ssr-externals.ts"() {
|
|
107
|
-
"use strict";
|
|
108
|
-
init_is_react_router_repo();
|
|
109
|
-
ssrExternals = isReactRouterRepo() ? [
|
|
110
|
-
// This is only needed within this repo because these packages
|
|
111
|
-
// are linked to a directory outside of node_modules so Vite
|
|
112
|
-
// treats them as internal code by default.
|
|
113
|
-
"react-router",
|
|
114
|
-
"react-router-dom",
|
|
115
|
-
"@react-router/architect",
|
|
116
|
-
"@react-router/cloudflare",
|
|
117
|
-
"@react-router/dev",
|
|
118
|
-
"@react-router/express",
|
|
119
|
-
"@react-router/node",
|
|
120
|
-
"@react-router/serve"
|
|
121
|
-
] : void 0;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// vite/vite-node.ts
|
|
126
|
-
async function createContext({
|
|
127
|
-
root,
|
|
128
|
-
mode,
|
|
129
|
-
customLogger
|
|
130
|
-
}) {
|
|
131
|
-
await preloadVite();
|
|
132
|
-
const vite2 = getVite();
|
|
133
|
-
const [{ ViteNodeServer }, { ViteNodeRunner }, { installSourcemapsSupport }] = await Promise.all([
|
|
134
|
-
import("vite-node/server"),
|
|
135
|
-
import("vite-node/client"),
|
|
136
|
-
import("vite-node/source-map")
|
|
137
|
-
]);
|
|
138
|
-
const devServer = await vite2.createServer({
|
|
139
|
-
root,
|
|
140
|
-
mode,
|
|
141
|
-
customLogger,
|
|
142
|
-
server: {
|
|
143
|
-
preTransformRequests: false,
|
|
144
|
-
hmr: false,
|
|
145
|
-
watch: null
|
|
146
|
-
},
|
|
147
|
-
ssr: {
|
|
148
|
-
external: ssrExternals
|
|
149
|
-
},
|
|
150
|
-
optimizeDeps: {
|
|
151
|
-
noDiscovery: true
|
|
152
|
-
},
|
|
153
|
-
css: {
|
|
154
|
-
// This empty PostCSS config object prevents the PostCSS config file from
|
|
155
|
-
// being loaded. We don't need it in a React Router config context, and
|
|
156
|
-
// there's also an issue in Vite 5 when using a .ts PostCSS config file in
|
|
157
|
-
// an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
|
|
158
|
-
// can work around this in their own Vite config file, but they can't
|
|
159
|
-
// configure this internal usage of vite-node.
|
|
160
|
-
postcss: {}
|
|
161
|
-
},
|
|
162
|
-
configFile: false,
|
|
163
|
-
envFile: false,
|
|
164
|
-
plugins: []
|
|
165
|
-
});
|
|
166
|
-
await devServer.pluginContainer.buildStart({});
|
|
167
|
-
const server = new ViteNodeServer(devServer);
|
|
168
|
-
installSourcemapsSupport({
|
|
169
|
-
getSourceMap: (source) => server.getSourceMap(source)
|
|
170
|
-
});
|
|
171
|
-
const runner = new ViteNodeRunner({
|
|
172
|
-
root: devServer.config.root,
|
|
173
|
-
base: devServer.config.base,
|
|
174
|
-
fetchModule(id) {
|
|
175
|
-
return server.fetchModule(id);
|
|
176
|
-
},
|
|
177
|
-
resolveId(id, importer) {
|
|
178
|
-
return server.resolveId(id, importer);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
return { devServer, server, runner };
|
|
182
|
-
}
|
|
183
|
-
var init_vite_node = __esm({
|
|
184
|
-
"vite/vite-node.ts"() {
|
|
185
|
-
"use strict";
|
|
186
|
-
init_vite();
|
|
187
|
-
init_ssr_externals();
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// config/routes.ts
|
|
192
|
-
function setAppDirectory(directory) {
|
|
193
|
-
globalThis.__reactRouterAppDirectory = directory;
|
|
194
|
-
}
|
|
195
|
-
function validateRouteConfig({
|
|
196
|
-
routeConfigFile,
|
|
197
|
-
routeConfig
|
|
198
|
-
}) {
|
|
199
|
-
if (!routeConfig) {
|
|
200
|
-
return {
|
|
201
|
-
valid: false,
|
|
202
|
-
message: `Route config must be the default export in "${routeConfigFile}".`
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
if (!Array.isArray(routeConfig)) {
|
|
206
|
-
return {
|
|
207
|
-
valid: false,
|
|
208
|
-
message: `Route config in "${routeConfigFile}" must be an array.`
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
let { issues } = v.safeParse(resolvedRouteConfigSchema, routeConfig);
|
|
212
|
-
if (issues?.length) {
|
|
213
|
-
let { root, nested } = v.flatten(issues);
|
|
214
|
-
return {
|
|
215
|
-
valid: false,
|
|
216
|
-
message: [
|
|
217
|
-
`Route config in "${routeConfigFile}" is invalid.`,
|
|
218
|
-
root ? `${root}` : [],
|
|
219
|
-
nested ? Object.entries(nested).map(
|
|
220
|
-
([path10, message]) => `Path: routes.${path10}
|
|
221
|
-
${message}`
|
|
222
|
-
) : []
|
|
223
|
-
].flat().join("\n\n")
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
valid: true,
|
|
228
|
-
routeConfig
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function configRoutesToRouteManifest(appDirectory, routes2) {
|
|
232
|
-
let routeManifest = {};
|
|
233
|
-
function walk(route, parentId) {
|
|
234
|
-
let id = route.id || createRouteId(route.file);
|
|
235
|
-
let manifestItem = {
|
|
236
|
-
id,
|
|
237
|
-
parentId,
|
|
238
|
-
file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
|
|
239
|
-
path: route.path,
|
|
240
|
-
index: route.index,
|
|
241
|
-
caseSensitive: route.caseSensitive
|
|
242
|
-
};
|
|
243
|
-
if (routeManifest.hasOwnProperty(id)) {
|
|
244
|
-
throw new Error(
|
|
245
|
-
`Unable to define routes with duplicate route id: "${id}"`
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
routeManifest[id] = manifestItem;
|
|
249
|
-
if (route.children) {
|
|
250
|
-
for (let child of route.children) {
|
|
251
|
-
walk(child, id);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
for (let route of routes2) {
|
|
256
|
-
walk(route);
|
|
257
|
-
}
|
|
258
|
-
return routeManifest;
|
|
259
|
-
}
|
|
260
|
-
function createRouteId(file) {
|
|
261
|
-
return Path.normalize(stripFileExtension(file));
|
|
262
|
-
}
|
|
263
|
-
function stripFileExtension(file) {
|
|
264
|
-
return file.replace(/\.[a-z0-9]+$/i, "");
|
|
265
|
-
}
|
|
266
|
-
var Path, v, import_pick, routeConfigEntrySchema, resolvedRouteConfigSchema;
|
|
267
|
-
var init_routes = __esm({
|
|
268
|
-
"config/routes.ts"() {
|
|
269
|
-
"use strict";
|
|
270
|
-
Path = __toESM(require("pathe"));
|
|
271
|
-
v = __toESM(require("valibot"));
|
|
272
|
-
import_pick = __toESM(require("lodash/pick"));
|
|
273
|
-
init_invariant();
|
|
274
|
-
routeConfigEntrySchema = v.pipe(
|
|
275
|
-
v.custom((value) => {
|
|
276
|
-
return !(typeof value === "object" && value !== null && "then" in value && "catch" in value);
|
|
277
|
-
}, "Invalid type: Expected object but received a promise. Did you forget to await?"),
|
|
278
|
-
v.object({
|
|
279
|
-
id: v.optional(
|
|
280
|
-
v.pipe(
|
|
281
|
-
v.string(),
|
|
282
|
-
v.notValue("root", "A route cannot use the reserved id 'root'.")
|
|
283
|
-
)
|
|
284
|
-
),
|
|
285
|
-
path: v.optional(v.string()),
|
|
286
|
-
index: v.optional(v.boolean()),
|
|
287
|
-
caseSensitive: v.optional(v.boolean()),
|
|
288
|
-
file: v.string(),
|
|
289
|
-
children: v.optional(v.array(v.lazy(() => routeConfigEntrySchema)))
|
|
290
|
-
})
|
|
291
|
-
);
|
|
292
|
-
resolvedRouteConfigSchema = v.array(routeConfigEntrySchema);
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
// cli/detectPackageManager.ts
|
|
297
|
-
var init_detectPackageManager = __esm({
|
|
298
|
-
"cli/detectPackageManager.ts"() {
|
|
299
|
-
"use strict";
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
// config/config.ts
|
|
304
|
-
function ok(value) {
|
|
305
|
-
return { ok: true, value };
|
|
306
|
-
}
|
|
307
|
-
function err(error) {
|
|
308
|
-
return { ok: false, error };
|
|
309
|
-
}
|
|
310
|
-
async function resolveConfig({
|
|
311
|
-
root,
|
|
312
|
-
viteNodeContext,
|
|
313
|
-
reactRouterConfigFile,
|
|
314
|
-
skipRoutes,
|
|
315
|
-
validateConfig
|
|
316
|
-
}) {
|
|
317
|
-
let reactRouterUserConfig = {};
|
|
318
|
-
if (reactRouterConfigFile) {
|
|
319
|
-
try {
|
|
320
|
-
if (!import_node_fs.default.existsSync(reactRouterConfigFile)) {
|
|
321
|
-
return err(`${reactRouterConfigFile} no longer exists`);
|
|
322
|
-
}
|
|
323
|
-
let configModule = await viteNodeContext.runner.executeFile(
|
|
324
|
-
reactRouterConfigFile
|
|
325
|
-
);
|
|
326
|
-
if (configModule.default === void 0) {
|
|
327
|
-
return err(`${reactRouterConfigFile} must provide a default export`);
|
|
328
|
-
}
|
|
329
|
-
if (typeof configModule.default !== "object") {
|
|
330
|
-
return err(`${reactRouterConfigFile} must export a config`);
|
|
331
|
-
}
|
|
332
|
-
reactRouterUserConfig = configModule.default;
|
|
333
|
-
if (validateConfig) {
|
|
334
|
-
const error = validateConfig(reactRouterUserConfig);
|
|
335
|
-
if (error) {
|
|
336
|
-
return err(error);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
} catch (error) {
|
|
340
|
-
return err(`Error loading ${reactRouterConfigFile}: ${error}`);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
reactRouterUserConfig = deepFreeze((0, import_cloneDeep.default)(reactRouterUserConfig));
|
|
344
|
-
let presets = (await Promise.all(
|
|
345
|
-
(reactRouterUserConfig.presets ?? []).map(async (preset) => {
|
|
346
|
-
if (!preset.name) {
|
|
347
|
-
throw new Error(
|
|
348
|
-
"React Router presets must have a `name` property defined."
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
if (!preset.reactRouterConfig) {
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
let configPreset = (0, import_omit.default)(
|
|
355
|
-
await preset.reactRouterConfig({ reactRouterUserConfig }),
|
|
356
|
-
excludedConfigPresetKeys
|
|
357
|
-
);
|
|
358
|
-
return configPreset;
|
|
359
|
-
})
|
|
360
|
-
)).filter(function isNotNull(value) {
|
|
361
|
-
return value !== null;
|
|
362
|
-
});
|
|
363
|
-
let defaults = {
|
|
364
|
-
basename: "/",
|
|
365
|
-
buildDirectory: "build",
|
|
366
|
-
serverBuildFile: "index.js",
|
|
367
|
-
serverModuleFormat: "esm",
|
|
368
|
-
ssr: true
|
|
369
|
-
};
|
|
370
|
-
let userAndPresetConfigs = mergeReactRouterConfig(
|
|
371
|
-
...presets,
|
|
372
|
-
reactRouterUserConfig
|
|
373
|
-
);
|
|
374
|
-
let {
|
|
375
|
-
appDirectory: userAppDirectory,
|
|
376
|
-
basename: basename3,
|
|
377
|
-
buildDirectory: userBuildDirectory,
|
|
378
|
-
buildEnd,
|
|
379
|
-
prerender: prerender2,
|
|
380
|
-
routeDiscovery: userRouteDiscovery,
|
|
381
|
-
serverBuildFile,
|
|
382
|
-
serverBundles,
|
|
383
|
-
serverModuleFormat,
|
|
384
|
-
ssr
|
|
385
|
-
} = {
|
|
386
|
-
...defaults,
|
|
387
|
-
// Default values should be completely overridden by user/preset config, not merged
|
|
388
|
-
...userAndPresetConfigs
|
|
389
|
-
};
|
|
390
|
-
if (!ssr && serverBundles) {
|
|
391
|
-
serverBundles = void 0;
|
|
392
|
-
}
|
|
393
|
-
if (prerender2) {
|
|
394
|
-
let isValidPrerenderPathsConfig = (p) => typeof p === "boolean" || typeof p === "function" || Array.isArray(p);
|
|
395
|
-
let isValidPrerenderConfig = isValidPrerenderPathsConfig(prerender2) || typeof prerender2 === "object" && "paths" in prerender2 && isValidPrerenderPathsConfig(prerender2.paths);
|
|
396
|
-
if (!isValidPrerenderConfig) {
|
|
397
|
-
return err(
|
|
398
|
-
"The `prerender`/`prerender.paths` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths."
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
if (typeof prerender2 === "object" && "unstable_concurrency" in prerender2) {
|
|
402
|
-
return err(
|
|
403
|
-
"The `prerender.unstable_concurrency` config field has been stabilized as `prerender.concurrency`"
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
let isValidConcurrencyConfig = typeof prerender2 != "object" || !("concurrency" in prerender2) || typeof prerender2.concurrency === "number" && Number.isInteger(prerender2.concurrency) && prerender2.concurrency > 0;
|
|
407
|
-
if (!isValidConcurrencyConfig) {
|
|
408
|
-
return err(
|
|
409
|
-
"The `prerender.concurrency` config must be a positive integer if specified."
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
let routeDiscovery;
|
|
414
|
-
if (userRouteDiscovery == null) {
|
|
415
|
-
if (ssr) {
|
|
416
|
-
routeDiscovery = {
|
|
417
|
-
mode: "lazy",
|
|
418
|
-
manifestPath: "/__manifest"
|
|
419
|
-
};
|
|
420
|
-
} else {
|
|
421
|
-
routeDiscovery = { mode: "initial" };
|
|
422
|
-
}
|
|
423
|
-
} else if (userRouteDiscovery.mode === "initial") {
|
|
424
|
-
routeDiscovery = userRouteDiscovery;
|
|
425
|
-
} else if (userRouteDiscovery.mode === "lazy") {
|
|
426
|
-
if (!ssr) {
|
|
427
|
-
return err(
|
|
428
|
-
'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
let { manifestPath } = userRouteDiscovery;
|
|
432
|
-
if (manifestPath != null && !manifestPath.startsWith("/")) {
|
|
433
|
-
return err(
|
|
434
|
-
'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
routeDiscovery = userRouteDiscovery;
|
|
438
|
-
}
|
|
439
|
-
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
440
|
-
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
441
|
-
let rootRouteFile = findEntry(appDirectory, "root", { absolute: true });
|
|
442
|
-
if (!rootRouteFile) {
|
|
443
|
-
let rootRouteDisplayPath = import_pathe3.default.relative(
|
|
444
|
-
root,
|
|
445
|
-
import_pathe3.default.join(appDirectory, "root.tsx")
|
|
446
|
-
);
|
|
447
|
-
return err(
|
|
448
|
-
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
let routes2;
|
|
452
|
-
let routeConfig = [];
|
|
453
|
-
if (skipRoutes) {
|
|
454
|
-
routes2 = {};
|
|
455
|
-
} else {
|
|
456
|
-
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
457
|
-
try {
|
|
458
|
-
if (!routeConfigFile) {
|
|
459
|
-
let routeConfigDisplayPath = import_pathe3.default.relative(
|
|
460
|
-
root,
|
|
461
|
-
import_pathe3.default.join(appDirectory, "routes.ts")
|
|
462
|
-
);
|
|
463
|
-
return err(
|
|
464
|
-
`Route config file not found at "${routeConfigDisplayPath}".`
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
setAppDirectory(appDirectory);
|
|
468
|
-
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
469
|
-
import_pathe3.default.join(appDirectory, routeConfigFile)
|
|
470
|
-
)).default;
|
|
471
|
-
let result = validateRouteConfig({
|
|
472
|
-
routeConfigFile,
|
|
473
|
-
routeConfig: await routeConfigExport
|
|
474
|
-
});
|
|
475
|
-
if (!result.valid) {
|
|
476
|
-
return err(result.message);
|
|
477
|
-
}
|
|
478
|
-
routeConfig = [
|
|
479
|
-
{
|
|
480
|
-
id: "root",
|
|
481
|
-
path: "",
|
|
482
|
-
file: import_pathe3.default.relative(appDirectory, rootRouteFile),
|
|
483
|
-
children: result.routeConfig
|
|
484
|
-
}
|
|
485
|
-
];
|
|
486
|
-
routes2 = configRoutesToRouteManifest(appDirectory, routeConfig);
|
|
487
|
-
} catch (error) {
|
|
488
|
-
return err(
|
|
489
|
-
[
|
|
490
|
-
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
491
|
-
"",
|
|
492
|
-
error.loc?.file && error.loc?.column && error.frame ? [
|
|
493
|
-
import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
494
|
-
error.frame.trim?.()
|
|
495
|
-
] : error.stack
|
|
496
|
-
].flat().join("\n")
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
let futureConfig = userAndPresetConfigs.future;
|
|
501
|
-
if (futureConfig) {
|
|
502
|
-
if ("unstable_splitRouteModules" in futureConfig) {
|
|
503
|
-
return err(
|
|
504
|
-
"The `future.unstable_splitRouteModules` flag has been stabilized as `future.v8_splitRouteModules`"
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
if ("unstable_viteEnvironmentApi" in futureConfig) {
|
|
508
|
-
return err(
|
|
509
|
-
"The `future.unstable_viteEnvironmentApi` flag has been stabilized as `future.v8_viteEnvironmentApi`"
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
if ("unstable_passThroughRequests" in futureConfig) {
|
|
513
|
-
return err(
|
|
514
|
-
"The `future.unstable_passThroughRequests` flag has been stabilized as `future.v8_passThroughRequests`"
|
|
515
|
-
);
|
|
516
|
-
}
|
|
517
|
-
if ("unstable_trailingSlashAwareDataRequests" in futureConfig) {
|
|
518
|
-
return err(
|
|
519
|
-
"The `future.unstable_trailingSlashAwareDataRequests` flag has been stabilized as `future.v8_trailingSlashAwareDataRequests`"
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
if ("unstable_subResourceIntegrity" in futureConfig) {
|
|
523
|
-
return err(
|
|
524
|
-
"The `future.unstable_subResourceIntegrity` flag has been stabilized and moved to a top-level `config.subResourceIntegrity` field"
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
let future = {
|
|
529
|
-
unstable_optimizeDeps: userAndPresetConfigs.future?.unstable_optimizeDeps ?? false,
|
|
530
|
-
v8_passThroughRequests: userAndPresetConfigs.future?.v8_passThroughRequests ?? false,
|
|
531
|
-
v8_trailingSlashAwareDataRequests: userAndPresetConfigs.future?.v8_trailingSlashAwareDataRequests ?? false,
|
|
532
|
-
unstable_previewServerPrerendering: userAndPresetConfigs.future?.unstable_previewServerPrerendering ?? false,
|
|
533
|
-
v8_middleware: userAndPresetConfigs.future?.v8_middleware ?? false,
|
|
534
|
-
v8_splitRouteModules: userAndPresetConfigs.future?.v8_splitRouteModules ?? false,
|
|
535
|
-
v8_viteEnvironmentApi: (userAndPresetConfigs.future?.v8_viteEnvironmentApi || userAndPresetConfigs.future?.unstable_previewServerPrerendering) ?? false
|
|
536
|
-
};
|
|
537
|
-
let allowedActionOrigins = userAndPresetConfigs.allowedActionOrigins ?? false;
|
|
538
|
-
let subResourceIntegrity = userAndPresetConfigs.subResourceIntegrity ?? false;
|
|
539
|
-
let reactRouterConfig = deepFreeze({
|
|
540
|
-
appDirectory,
|
|
541
|
-
basename: basename3,
|
|
542
|
-
buildDirectory,
|
|
543
|
-
buildEnd,
|
|
544
|
-
future,
|
|
545
|
-
prerender: prerender2,
|
|
546
|
-
routes: routes2,
|
|
547
|
-
routeDiscovery,
|
|
548
|
-
serverBuildFile,
|
|
549
|
-
serverBundles,
|
|
550
|
-
serverModuleFormat,
|
|
551
|
-
ssr,
|
|
552
|
-
subResourceIntegrity,
|
|
553
|
-
allowedActionOrigins,
|
|
554
|
-
unstable_routeConfig: routeConfig
|
|
555
|
-
});
|
|
556
|
-
for (let preset of reactRouterUserConfig.presets ?? []) {
|
|
557
|
-
await preset.reactRouterConfigResolved?.({ reactRouterConfig });
|
|
558
|
-
}
|
|
559
|
-
logFutureFlagWarnings(userAndPresetConfigs.future || {});
|
|
560
|
-
return ok(reactRouterConfig);
|
|
561
|
-
}
|
|
562
|
-
function logFutureFlagWarning(flag, message) {
|
|
563
|
-
console.log(
|
|
564
|
-
import_picocolors.default.yellow(
|
|
565
|
-
` \u26A0\uFE0F Future Flag Warning: ${message}
|
|
566
|
-
You can use the \`future.${flag}\` flag to opt in early.
|
|
567
|
-
-> https://reactrouter.com/upgrading/future-flags#${flag}`
|
|
568
|
-
)
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
function logFutureFlagWarnings(future) {
|
|
572
|
-
if (future.v8_middleware === void 0) {
|
|
573
|
-
logFutureFlagWarning(
|
|
574
|
-
"v8_middleware",
|
|
575
|
-
"Route middleware support is changing in React Router v8."
|
|
576
|
-
);
|
|
577
|
-
}
|
|
578
|
-
if (future.v8_splitRouteModules === void 0) {
|
|
579
|
-
logFutureFlagWarning(
|
|
580
|
-
"v8_splitRouteModules",
|
|
581
|
-
"Route module splitting behavior is changing in React Router v8."
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
if (future.v8_viteEnvironmentApi === void 0) {
|
|
585
|
-
logFutureFlagWarning(
|
|
586
|
-
"v8_viteEnvironmentApi",
|
|
587
|
-
"Vite Environment API usage is changing in React Router v8."
|
|
588
|
-
);
|
|
589
|
-
}
|
|
590
|
-
if (future.v8_passThroughRequests === void 0) {
|
|
591
|
-
logFutureFlagWarning(
|
|
592
|
-
"v8_passThroughRequests",
|
|
593
|
-
"Request handling behavior is changing in React Router v8."
|
|
594
|
-
);
|
|
595
|
-
}
|
|
596
|
-
if (future.v8_trailingSlashAwareDataRequests === void 0) {
|
|
597
|
-
logFutureFlagWarning(
|
|
598
|
-
"v8_trailingSlashAwareDataRequests",
|
|
599
|
-
"Data request URL formats are changing in React Router v8."
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
async function createConfigLoader({
|
|
604
|
-
rootDirectory: root,
|
|
605
|
-
watch: watch2,
|
|
606
|
-
mode,
|
|
607
|
-
skipRoutes,
|
|
608
|
-
validateConfig
|
|
609
|
-
}) {
|
|
610
|
-
root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
|
|
611
|
-
let vite2 = await import("vite");
|
|
612
|
-
let viteNodeContext = await createContext({
|
|
613
|
-
root,
|
|
614
|
-
mode,
|
|
615
|
-
// Filter out any info level logs from vite-node
|
|
616
|
-
customLogger: vite2.createLogger("warn", {
|
|
617
|
-
prefix: "[react-router]"
|
|
618
|
-
})
|
|
619
|
-
});
|
|
620
|
-
let reactRouterConfigFile;
|
|
621
|
-
let updateReactRouterConfigFile = () => {
|
|
622
|
-
reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
623
|
-
absolute: true
|
|
624
|
-
});
|
|
625
|
-
};
|
|
626
|
-
updateReactRouterConfigFile();
|
|
627
|
-
let getConfig = () => resolveConfig({
|
|
628
|
-
root,
|
|
629
|
-
viteNodeContext,
|
|
630
|
-
reactRouterConfigFile,
|
|
631
|
-
skipRoutes,
|
|
632
|
-
validateConfig
|
|
633
|
-
});
|
|
634
|
-
let appDirectory;
|
|
635
|
-
let initialConfigResult = await getConfig();
|
|
636
|
-
if (!initialConfigResult.ok) {
|
|
637
|
-
throw new Error(initialConfigResult.error);
|
|
638
|
-
}
|
|
639
|
-
appDirectory = import_pathe3.default.normalize(initialConfigResult.value.appDirectory);
|
|
640
|
-
let currentConfig = initialConfigResult.value;
|
|
641
|
-
let fsWatcher;
|
|
642
|
-
let changeHandlers = [];
|
|
643
|
-
return {
|
|
644
|
-
getConfig,
|
|
645
|
-
onChange: (handler) => {
|
|
646
|
-
if (!watch2) {
|
|
647
|
-
throw new Error(
|
|
648
|
-
"onChange is not supported when watch mode is disabled"
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
changeHandlers.push(handler);
|
|
652
|
-
if (!fsWatcher) {
|
|
653
|
-
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
654
|
-
ignoreInitial: true,
|
|
655
|
-
ignored: (path10) => isIgnoredByWatcher(path10, { root, appDirectory })
|
|
656
|
-
});
|
|
657
|
-
fsWatcher.on("error", (error) => {
|
|
658
|
-
let message = error instanceof Error ? error.message : String(error);
|
|
659
|
-
console.warn(import_picocolors.default.yellow(`File watcher error: ${message}`));
|
|
660
|
-
});
|
|
661
|
-
fsWatcher.on("all", async (...args) => {
|
|
662
|
-
let [event, rawFilepath] = args;
|
|
663
|
-
let filepath = import_pathe3.default.normalize(rawFilepath);
|
|
664
|
-
let fileAddedOrRemoved = event === "add" || event === "unlink";
|
|
665
|
-
let appFileAddedOrRemoved = fileAddedOrRemoved && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
|
|
666
|
-
let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
|
|
667
|
-
let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
|
|
668
|
-
if (configFileAddedOrRemoved) {
|
|
669
|
-
updateReactRouterConfigFile();
|
|
670
|
-
}
|
|
671
|
-
let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
|
|
672
|
-
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
673
|
-
);
|
|
674
|
-
if (!moduleGraphChanged && !appFileAddedOrRemoved) {
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
678
|
-
viteNodeContext.runner?.moduleCache.clear();
|
|
679
|
-
let result = await getConfig();
|
|
680
|
-
let prevAppDirectory = appDirectory;
|
|
681
|
-
appDirectory = import_pathe3.default.normalize(
|
|
682
|
-
(result.value ?? currentConfig).appDirectory
|
|
683
|
-
);
|
|
684
|
-
if (appDirectory !== prevAppDirectory) {
|
|
685
|
-
fsWatcher.unwatch(prevAppDirectory);
|
|
686
|
-
fsWatcher.add(appDirectory);
|
|
687
|
-
}
|
|
688
|
-
let configCodeChanged = configFileAddedOrRemoved || reactRouterConfigFile !== void 0 && isEntryFileDependency(
|
|
689
|
-
viteNodeContext.devServer.moduleGraph,
|
|
690
|
-
reactRouterConfigFile,
|
|
691
|
-
filepath
|
|
692
|
-
);
|
|
693
|
-
let routeConfigFile = !skipRoutes ? findEntry(appDirectory, "routes", {
|
|
694
|
-
absolute: true
|
|
695
|
-
}) : void 0;
|
|
696
|
-
let routeConfigCodeChanged = routeConfigFile !== void 0 && isEntryFileDependency(
|
|
697
|
-
viteNodeContext.devServer.moduleGraph,
|
|
698
|
-
routeConfigFile,
|
|
699
|
-
filepath
|
|
700
|
-
);
|
|
701
|
-
let configChanged = result.ok && !(0, import_isEqual.default)(omitRoutes(currentConfig), omitRoutes(result.value));
|
|
702
|
-
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(currentConfig?.routes, result.value.routes);
|
|
703
|
-
for (let handler2 of changeHandlers) {
|
|
704
|
-
handler2({
|
|
705
|
-
result,
|
|
706
|
-
configCodeChanged,
|
|
707
|
-
routeConfigCodeChanged,
|
|
708
|
-
configChanged,
|
|
709
|
-
routeConfigChanged,
|
|
710
|
-
path: filepath,
|
|
711
|
-
event
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
if (result.ok) {
|
|
715
|
-
currentConfig = result.value;
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
return () => {
|
|
720
|
-
changeHandlers = changeHandlers.filter(
|
|
721
|
-
(changeHandler) => changeHandler !== handler
|
|
722
|
-
);
|
|
723
|
-
};
|
|
724
|
-
},
|
|
725
|
-
close: async () => {
|
|
726
|
-
changeHandlers = [];
|
|
727
|
-
await viteNodeContext.devServer.close();
|
|
728
|
-
await fsWatcher?.close();
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
async function loadConfig({
|
|
733
|
-
rootDirectory,
|
|
734
|
-
mode,
|
|
735
|
-
skipRoutes
|
|
736
|
-
}) {
|
|
737
|
-
let configLoader = await createConfigLoader({
|
|
738
|
-
rootDirectory,
|
|
739
|
-
mode,
|
|
740
|
-
skipRoutes,
|
|
741
|
-
watch: false
|
|
742
|
-
});
|
|
743
|
-
let config = await configLoader.getConfig();
|
|
744
|
-
await configLoader.close();
|
|
745
|
-
return config;
|
|
746
|
-
}
|
|
747
|
-
function omitRoutes(config) {
|
|
748
|
-
return {
|
|
749
|
-
...config,
|
|
750
|
-
routes: {}
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
function isEntryFile(entryBasename, filename2) {
|
|
754
|
-
return entryExts.some((ext) => filename2 === `${entryBasename}${ext}`);
|
|
755
|
-
}
|
|
756
|
-
function findEntry(dir, basename3, options) {
|
|
757
|
-
let currentDir = import_pathe3.default.resolve(dir);
|
|
758
|
-
let { root } = import_pathe3.default.parse(currentDir);
|
|
759
|
-
while (true) {
|
|
760
|
-
for (let ext of options?.extensions ?? entryExts) {
|
|
761
|
-
let file = import_pathe3.default.resolve(currentDir, basename3 + ext);
|
|
762
|
-
if (import_node_fs.default.existsSync(file)) {
|
|
763
|
-
return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
if (!options?.walkParents) {
|
|
767
|
-
return void 0;
|
|
768
|
-
}
|
|
769
|
-
let parentDir = import_pathe3.default.dirname(currentDir);
|
|
770
|
-
if (currentDir === root || parentDir === currentDir) {
|
|
771
|
-
return void 0;
|
|
772
|
-
}
|
|
773
|
-
currentDir = parentDir;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
|
|
777
|
-
entryFilepath = import_pathe3.default.normalize(entryFilepath);
|
|
778
|
-
filepath = import_pathe3.default.normalize(filepath);
|
|
779
|
-
if (visited.has(filepath)) {
|
|
780
|
-
return false;
|
|
781
|
-
}
|
|
782
|
-
visited.add(filepath);
|
|
783
|
-
if (filepath === entryFilepath) {
|
|
784
|
-
return true;
|
|
785
|
-
}
|
|
786
|
-
let mod = moduleGraph.getModuleById(filepath);
|
|
787
|
-
if (!mod) {
|
|
788
|
-
return false;
|
|
789
|
-
}
|
|
790
|
-
for (let importer of mod.importers) {
|
|
791
|
-
if (!importer.id) {
|
|
792
|
-
continue;
|
|
793
|
-
}
|
|
794
|
-
if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
|
|
795
|
-
return true;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
return false;
|
|
799
|
-
}
|
|
800
|
-
function isIgnoredByWatcher(path10, { root, appDirectory }) {
|
|
801
|
-
let dirname5 = import_pathe3.default.dirname(path10);
|
|
802
|
-
let ignoredByPath = !dirname5.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
803
|
-
// that are at the root level, not nested in subdirectories
|
|
804
|
-
path10 !== root && // Watch the root directory itself
|
|
805
|
-
dirname5 !== root;
|
|
806
|
-
if (ignoredByPath) {
|
|
807
|
-
return true;
|
|
808
|
-
}
|
|
809
|
-
try {
|
|
810
|
-
let stat = import_node_fs.default.statSync(path10, { throwIfNoEntry: false });
|
|
811
|
-
if (stat && !stat.isFile() && !stat.isDirectory()) {
|
|
812
|
-
return true;
|
|
813
|
-
}
|
|
814
|
-
} catch {
|
|
815
|
-
return true;
|
|
816
|
-
}
|
|
817
|
-
return false;
|
|
818
|
-
}
|
|
819
|
-
var import_node_fs, import_node_child_process, import_pathe3, import_chokidar, import_picocolors, import_pick2, import_omit, import_cloneDeep, import_isEqual, excludedConfigPresetKeys, mergeReactRouterConfig, deepFreeze, entryExts;
|
|
820
|
-
var init_config = __esm({
|
|
821
|
-
"config/config.ts"() {
|
|
822
|
-
"use strict";
|
|
823
|
-
import_node_fs = __toESM(require("fs"));
|
|
824
|
-
import_node_child_process = require("child_process");
|
|
825
|
-
init_vite_node();
|
|
826
|
-
import_pathe3 = __toESM(require("pathe"));
|
|
827
|
-
import_chokidar = __toESM(require("chokidar"));
|
|
828
|
-
import_picocolors = __toESM(require("picocolors"));
|
|
829
|
-
import_pick2 = __toESM(require("lodash/pick"));
|
|
830
|
-
import_omit = __toESM(require("lodash/omit"));
|
|
831
|
-
import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
832
|
-
import_isEqual = __toESM(require("lodash/isEqual"));
|
|
833
|
-
init_routes();
|
|
834
|
-
init_detectPackageManager();
|
|
835
|
-
excludedConfigPresetKeys = ["presets"];
|
|
836
|
-
mergeReactRouterConfig = (...configs) => {
|
|
837
|
-
let reducer = (configA, configB) => {
|
|
838
|
-
let mergeRequired = (key) => configA[key] !== void 0 && configB[key] !== void 0;
|
|
839
|
-
return {
|
|
840
|
-
...configA,
|
|
841
|
-
...configB,
|
|
842
|
-
...mergeRequired("buildEnd") ? {
|
|
843
|
-
buildEnd: async (...args) => {
|
|
844
|
-
await Promise.all([
|
|
845
|
-
configA.buildEnd?.(...args),
|
|
846
|
-
configB.buildEnd?.(...args)
|
|
847
|
-
]);
|
|
848
|
-
}
|
|
849
|
-
} : {},
|
|
850
|
-
...mergeRequired("future") ? {
|
|
851
|
-
future: {
|
|
852
|
-
...configA.future,
|
|
853
|
-
...configB.future
|
|
854
|
-
}
|
|
855
|
-
} : {},
|
|
856
|
-
...mergeRequired("presets") ? {
|
|
857
|
-
presets: [...configA.presets ?? [], ...configB.presets ?? []]
|
|
858
|
-
} : {}
|
|
859
|
-
};
|
|
860
|
-
};
|
|
861
|
-
return configs.reduce(reducer, {});
|
|
862
|
-
};
|
|
863
|
-
deepFreeze = (o) => {
|
|
864
|
-
Object.freeze(o);
|
|
865
|
-
let oIsFunction = typeof o === "function";
|
|
866
|
-
let hasOwnProp = Object.prototype.hasOwnProperty;
|
|
867
|
-
Object.getOwnPropertyNames(o).forEach(function(prop) {
|
|
868
|
-
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])) {
|
|
869
|
-
deepFreeze(o[prop]);
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
return o;
|
|
873
|
-
};
|
|
874
|
-
entryExts = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".mts"];
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
// vite/profiler.ts
|
|
879
|
-
var import_node_fs2, import_node_path, import_picocolors2, getSession, start, profileCount, stop;
|
|
880
|
-
var init_profiler = __esm({
|
|
881
|
-
"vite/profiler.ts"() {
|
|
882
|
-
"use strict";
|
|
883
|
-
import_node_fs2 = __toESM(require("fs"));
|
|
884
|
-
import_node_path = __toESM(require("path"));
|
|
885
|
-
import_picocolors2 = __toESM(require("picocolors"));
|
|
886
|
-
getSession = () => global.__reactRouter_profile_session;
|
|
887
|
-
start = async (callback) => {
|
|
888
|
-
let inspector = await import("inspector").then((r) => r.default);
|
|
889
|
-
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
890
|
-
session.connect();
|
|
891
|
-
session.post("Profiler.enable", () => {
|
|
892
|
-
session.post("Profiler.start", callback);
|
|
893
|
-
});
|
|
894
|
-
};
|
|
895
|
-
profileCount = 0;
|
|
896
|
-
stop = (log) => {
|
|
897
|
-
let session = getSession();
|
|
898
|
-
if (!session) return;
|
|
899
|
-
return new Promise((res, rej) => {
|
|
900
|
-
session.post("Profiler.stop", (err2, { profile }) => {
|
|
901
|
-
if (err2) return rej(err2);
|
|
902
|
-
let outPath = import_node_path.default.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
903
|
-
import_node_fs2.default.writeFileSync(outPath, JSON.stringify(profile));
|
|
904
|
-
log(
|
|
905
|
-
import_picocolors2.default.yellow(
|
|
906
|
-
`CPU profile written to ${import_picocolors2.default.white(import_picocolors2.default.dim(outPath))}`
|
|
907
|
-
)
|
|
908
|
-
);
|
|
909
|
-
global.__reactRouter_profile_session = void 0;
|
|
910
|
-
res();
|
|
911
|
-
});
|
|
912
|
-
});
|
|
913
|
-
};
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
|
|
917
|
-
// typegen/context.ts
|
|
918
|
-
async function createContext2({
|
|
919
|
-
rootDirectory,
|
|
920
|
-
watch: watch2,
|
|
921
|
-
mode,
|
|
922
|
-
rsc
|
|
923
|
-
}) {
|
|
924
|
-
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
925
|
-
const configResult = await configLoader.getConfig();
|
|
926
|
-
if (!configResult.ok) {
|
|
927
|
-
throw new Error(configResult.error);
|
|
928
|
-
}
|
|
929
|
-
const config = configResult.value;
|
|
930
|
-
return {
|
|
931
|
-
configLoader,
|
|
932
|
-
rootDirectory,
|
|
933
|
-
config,
|
|
934
|
-
rsc
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
var init_context = __esm({
|
|
938
|
-
"typegen/context.ts"() {
|
|
939
|
-
"use strict";
|
|
940
|
-
init_config();
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
|
|
944
|
-
// vite/babel.ts
|
|
945
|
-
var babel_exports = {};
|
|
946
|
-
__export(babel_exports, {
|
|
947
|
-
generate: () => generate,
|
|
948
|
-
parse: () => import_parser.parse,
|
|
949
|
-
t: () => t,
|
|
950
|
-
traverse: () => traverse
|
|
951
|
-
});
|
|
952
|
-
var import_parser, t, traverse, generate;
|
|
953
|
-
var init_babel = __esm({
|
|
954
|
-
"vite/babel.ts"() {
|
|
955
|
-
"use strict";
|
|
956
|
-
import_parser = require("@babel/parser");
|
|
957
|
-
t = __toESM(require("@babel/types"));
|
|
958
|
-
traverse = require("@babel/traverse").default;
|
|
959
|
-
generate = require("@babel/generator").default;
|
|
960
|
-
}
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
// typegen/params.ts
|
|
964
|
-
function parse2(fullpath2) {
|
|
965
|
-
const result = {};
|
|
966
|
-
let segments = fullpath2.split("/");
|
|
967
|
-
segments.forEach((segment) => {
|
|
968
|
-
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
969
|
-
if (!match) return;
|
|
970
|
-
const param = match[1];
|
|
971
|
-
const isRequired = match[2] === void 0;
|
|
972
|
-
result[param] ||= isRequired;
|
|
973
|
-
return;
|
|
974
|
-
});
|
|
975
|
-
const hasSplat = segments.at(-1) === "*";
|
|
976
|
-
if (hasSplat) result["*"] = true;
|
|
977
|
-
return result;
|
|
978
|
-
}
|
|
979
|
-
var init_params = __esm({
|
|
980
|
-
"typegen/params.ts"() {
|
|
981
|
-
"use strict";
|
|
982
|
-
}
|
|
983
|
-
});
|
|
984
|
-
|
|
985
|
-
// typegen/route.ts
|
|
986
|
-
function lineage(routes2, route) {
|
|
987
|
-
const result = [];
|
|
988
|
-
while (route) {
|
|
989
|
-
result.push(route);
|
|
990
|
-
if (!route.parentId) break;
|
|
991
|
-
route = routes2[route.parentId];
|
|
992
|
-
}
|
|
993
|
-
result.reverse();
|
|
994
|
-
return result;
|
|
995
|
-
}
|
|
996
|
-
function fullpath(lineage2) {
|
|
997
|
-
const route = lineage2.at(-1);
|
|
998
|
-
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
999
|
-
const isLayout = route && route.index !== true && route.path === void 0;
|
|
1000
|
-
if (isLayout) return void 0;
|
|
1001
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path10) => path10 !== void 0 && path10 !== "").join("/");
|
|
1002
|
-
}
|
|
1003
|
-
var init_route = __esm({
|
|
1004
|
-
"typegen/route.ts"() {
|
|
1005
|
-
"use strict";
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
|
|
1009
|
-
// typegen/generate.ts
|
|
1010
|
-
function typesDirectory(ctx) {
|
|
1011
|
-
return Path3.join(ctx.rootDirectory, ".react-router/types");
|
|
1012
|
-
}
|
|
1013
|
-
function generateFuture(ctx) {
|
|
1014
|
-
const filename2 = Path3.join(typesDirectory(ctx), "+future.ts");
|
|
1015
|
-
const content = import_dedent.default`
|
|
1016
|
-
// Generated by React Router
|
|
1017
|
-
|
|
1018
|
-
import "react-router";
|
|
1019
|
-
|
|
1020
|
-
declare module "react-router" {
|
|
1021
|
-
interface Future {
|
|
1022
|
-
v8_middleware: ${ctx.config.future.v8_middleware}
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
`;
|
|
1026
|
-
return { filename: filename2, content };
|
|
1027
|
-
}
|
|
1028
|
-
function generateServerBuild(ctx) {
|
|
1029
|
-
const filename2 = Path3.join(typesDirectory(ctx), "+server-build.d.ts");
|
|
1030
|
-
const content = import_dedent.default`
|
|
1031
|
-
// Generated by React Router
|
|
1032
|
-
|
|
1033
|
-
declare module "virtual:react-router/server-build" {
|
|
1034
|
-
import { ServerBuild } from "react-router";
|
|
1035
|
-
export const assets: ServerBuild["assets"];
|
|
1036
|
-
export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
|
|
1037
|
-
export const basename: ServerBuild["basename"];
|
|
1038
|
-
export const entry: ServerBuild["entry"];
|
|
1039
|
-
export const future: ServerBuild["future"];
|
|
1040
|
-
export const isSpaMode: ServerBuild["isSpaMode"];
|
|
1041
|
-
export const prerender: ServerBuild["prerender"];
|
|
1042
|
-
export const publicPath: ServerBuild["publicPath"];
|
|
1043
|
-
export const routeDiscovery: ServerBuild["routeDiscovery"];
|
|
1044
|
-
export const routes: ServerBuild["routes"];
|
|
1045
|
-
export const ssr: ServerBuild["ssr"];
|
|
1046
|
-
export const allowedActionOrigins: ServerBuild["allowedActionOrigins"];
|
|
1047
|
-
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
1048
|
-
}
|
|
1049
|
-
`;
|
|
1050
|
-
return { filename: filename2, content };
|
|
1051
|
-
}
|
|
1052
|
-
function generateRoutes(ctx) {
|
|
1053
|
-
const fileToRoutes = /* @__PURE__ */ new Map();
|
|
1054
|
-
const lineages = /* @__PURE__ */ new Map();
|
|
1055
|
-
const allPages = /* @__PURE__ */ new Set();
|
|
1056
|
-
const routeToPages = /* @__PURE__ */ new Map();
|
|
1057
|
-
for (const route of Object.values(ctx.config.routes)) {
|
|
1058
|
-
let routeIds = fileToRoutes.get(route.file);
|
|
1059
|
-
if (!routeIds) {
|
|
1060
|
-
routeIds = /* @__PURE__ */ new Set();
|
|
1061
|
-
fileToRoutes.set(route.file, routeIds);
|
|
1062
|
-
}
|
|
1063
|
-
routeIds.add(route.id);
|
|
1064
|
-
const lineage2 = lineage(ctx.config.routes, route);
|
|
1065
|
-
lineages.set(route.id, lineage2);
|
|
1066
|
-
const fullpath2 = fullpath(lineage2);
|
|
1067
|
-
if (!fullpath2) continue;
|
|
1068
|
-
const pages = expand(fullpath2);
|
|
1069
|
-
pages.forEach((page) => allPages.add(page));
|
|
1070
|
-
lineage2.forEach(({ id }) => {
|
|
1071
|
-
let routePages = routeToPages.get(id);
|
|
1072
|
-
if (!routePages) {
|
|
1073
|
-
routePages = /* @__PURE__ */ new Set();
|
|
1074
|
-
routeToPages.set(id, routePages);
|
|
1075
|
-
}
|
|
1076
|
-
pages.forEach((page) => routePages.add(page));
|
|
1077
|
-
});
|
|
1078
|
-
}
|
|
1079
|
-
const routesTs = {
|
|
1080
|
-
filename: Path3.join(typesDirectory(ctx), "+routes.ts"),
|
|
1081
|
-
content: import_dedent.default`
|
|
1082
|
-
// Generated by React Router
|
|
1083
|
-
|
|
1084
|
-
import "react-router"
|
|
1085
|
-
|
|
1086
|
-
declare module "react-router" {
|
|
1087
|
-
interface Register {
|
|
1088
|
-
pages: Pages
|
|
1089
|
-
routeFiles: RouteFiles
|
|
1090
|
-
routeModules: RouteModules
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
` + "\n\n" + generate(pagesType(allPages)).code + "\n\n" + generate(routeFilesType({ fileToRoutes, routeToPages })).code + "\n\n" + generate(routeModulesType(ctx)).code
|
|
1094
|
-
};
|
|
1095
|
-
const allAnnotations = Array.from(fileToRoutes.entries()).filter(([file]) => isInAppDirectory(ctx, file)).map(
|
|
1096
|
-
([file, routeIds]) => getRouteAnnotations({ ctx, file, routeIds, lineages })
|
|
1097
|
-
);
|
|
1098
|
-
return [routesTs, ...allAnnotations];
|
|
1099
|
-
}
|
|
1100
|
-
function pagesType(pages) {
|
|
1101
|
-
return t2.tsTypeAliasDeclaration(
|
|
1102
|
-
t2.identifier("Pages"),
|
|
1103
|
-
null,
|
|
1104
|
-
t2.tsTypeLiteral(
|
|
1105
|
-
Array.from(pages).map((page) => {
|
|
1106
|
-
return t2.tsPropertySignature(
|
|
1107
|
-
t2.stringLiteral(page),
|
|
1108
|
-
t2.tsTypeAnnotation(
|
|
1109
|
-
t2.tsTypeLiteral([
|
|
1110
|
-
t2.tsPropertySignature(
|
|
1111
|
-
t2.identifier("params"),
|
|
1112
|
-
t2.tsTypeAnnotation(paramsType(page))
|
|
1113
|
-
)
|
|
1114
|
-
])
|
|
1115
|
-
)
|
|
1116
|
-
);
|
|
1117
|
-
})
|
|
1118
|
-
)
|
|
1119
|
-
);
|
|
1120
|
-
}
|
|
1121
|
-
function routeFilesType({
|
|
1122
|
-
fileToRoutes,
|
|
1123
|
-
routeToPages
|
|
1124
|
-
}) {
|
|
1125
|
-
return t2.tsTypeAliasDeclaration(
|
|
1126
|
-
t2.identifier("RouteFiles"),
|
|
1127
|
-
null,
|
|
1128
|
-
t2.tsTypeLiteral(
|
|
1129
|
-
Array.from(fileToRoutes).map(
|
|
1130
|
-
([file, routeIds]) => t2.tsPropertySignature(
|
|
1131
|
-
t2.stringLiteral(file),
|
|
1132
|
-
t2.tsTypeAnnotation(
|
|
1133
|
-
t2.tsUnionType(
|
|
1134
|
-
Array.from(routeIds).map((routeId) => {
|
|
1135
|
-
const pages = routeToPages.get(routeId) ?? /* @__PURE__ */ new Set();
|
|
1136
|
-
return t2.tsTypeLiteral([
|
|
1137
|
-
t2.tsPropertySignature(
|
|
1138
|
-
t2.identifier("id"),
|
|
1139
|
-
t2.tsTypeAnnotation(
|
|
1140
|
-
t2.tsLiteralType(t2.stringLiteral(routeId))
|
|
1141
|
-
)
|
|
1142
|
-
),
|
|
1143
|
-
t2.tsPropertySignature(
|
|
1144
|
-
t2.identifier("page"),
|
|
1145
|
-
t2.tsTypeAnnotation(
|
|
1146
|
-
pages.size > 0 ? t2.tsUnionType(
|
|
1147
|
-
Array.from(pages).map(
|
|
1148
|
-
(page) => t2.tsLiteralType(t2.stringLiteral(page))
|
|
1149
|
-
)
|
|
1150
|
-
) : t2.tsNeverKeyword()
|
|
1151
|
-
)
|
|
1152
|
-
)
|
|
1153
|
-
]);
|
|
1154
|
-
})
|
|
1155
|
-
)
|
|
1156
|
-
)
|
|
1157
|
-
)
|
|
1158
|
-
)
|
|
1159
|
-
)
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
|
-
function routeModulesType(ctx) {
|
|
1163
|
-
return t2.tsTypeAliasDeclaration(
|
|
1164
|
-
t2.identifier("RouteModules"),
|
|
1165
|
-
null,
|
|
1166
|
-
t2.tsTypeLiteral(
|
|
1167
|
-
Object.values(ctx.config.routes).map(
|
|
1168
|
-
(route) => t2.tsPropertySignature(
|
|
1169
|
-
t2.stringLiteral(route.id),
|
|
1170
|
-
t2.tsTypeAnnotation(
|
|
1171
|
-
isInAppDirectory(ctx, route.file) ? t2.tsTypeQuery(
|
|
1172
|
-
t2.tsImportType(
|
|
1173
|
-
t2.stringLiteral(
|
|
1174
|
-
`./${Path3.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`
|
|
1175
|
-
)
|
|
1176
|
-
)
|
|
1177
|
-
) : t2.tsUnknownKeyword()
|
|
1178
|
-
)
|
|
1179
|
-
)
|
|
1180
|
-
)
|
|
1181
|
-
)
|
|
1182
|
-
);
|
|
1183
|
-
}
|
|
1184
|
-
function isInAppDirectory(ctx, routeFile) {
|
|
1185
|
-
const path10 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1186
|
-
return path10.startsWith(ctx.config.appDirectory);
|
|
1187
|
-
}
|
|
1188
|
-
function getRouteAnnotations({
|
|
1189
|
-
ctx,
|
|
1190
|
-
file,
|
|
1191
|
-
routeIds,
|
|
1192
|
-
lineages
|
|
1193
|
-
}) {
|
|
1194
|
-
const filename2 = Path3.join(
|
|
1195
|
-
typesDirectory(ctx),
|
|
1196
|
-
Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
1197
|
-
Path3.dirname(file),
|
|
1198
|
-
"+types",
|
|
1199
|
-
Pathe.filename(file) + ".ts"
|
|
1200
|
-
);
|
|
1201
|
-
const matchesType = t2.tsTypeAliasDeclaration(
|
|
1202
|
-
t2.identifier("Matches"),
|
|
1203
|
-
null,
|
|
1204
|
-
t2.tsUnionType(
|
|
1205
|
-
Array.from(routeIds).map((routeId) => {
|
|
1206
|
-
const lineage2 = lineages.get(routeId);
|
|
1207
|
-
return t2.tsTupleType(
|
|
1208
|
-
lineage2.map(
|
|
1209
|
-
(route) => t2.tsTypeLiteral([
|
|
1210
|
-
t2.tsPropertySignature(
|
|
1211
|
-
t2.identifier("id"),
|
|
1212
|
-
t2.tsTypeAnnotation(t2.tsLiteralType(t2.stringLiteral(route.id)))
|
|
1213
|
-
),
|
|
1214
|
-
t2.tsPropertySignature(
|
|
1215
|
-
t2.identifier("module"),
|
|
1216
|
-
t2.tsTypeAnnotation(
|
|
1217
|
-
t2.tsTypeQuery(
|
|
1218
|
-
t2.tsImportType(
|
|
1219
|
-
t2.stringLiteral(
|
|
1220
|
-
relativeImportSource(
|
|
1221
|
-
rootDirsPath(ctx, filename2),
|
|
1222
|
-
Path3.resolve(ctx.config.appDirectory, route.file)
|
|
1223
|
-
)
|
|
1224
|
-
)
|
|
1225
|
-
)
|
|
1226
|
-
)
|
|
1227
|
-
)
|
|
1228
|
-
)
|
|
1229
|
-
])
|
|
1230
|
-
)
|
|
1231
|
-
);
|
|
1232
|
-
})
|
|
1233
|
-
)
|
|
1234
|
-
);
|
|
1235
|
-
const routeImportSource = relativeImportSource(
|
|
1236
|
-
rootDirsPath(ctx, filename2),
|
|
1237
|
-
Path3.resolve(ctx.config.appDirectory, file)
|
|
1238
|
-
);
|
|
1239
|
-
const content = import_dedent.default`
|
|
1240
|
-
// Generated by React Router
|
|
1241
|
-
|
|
1242
|
-
import type { GetInfo, GetAnnotations } from "react-router/internal";
|
|
1243
|
-
|
|
1244
|
-
type Module = typeof import("${routeImportSource}")
|
|
1245
|
-
|
|
1246
|
-
type Info = GetInfo<{
|
|
1247
|
-
file: "${file}",
|
|
1248
|
-
module: Module
|
|
1249
|
-
}>
|
|
1250
|
-
` + "\n\n" + generate(matchesType).code + "\n\n" + import_dedent.default`
|
|
1251
|
-
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }>;
|
|
1252
|
-
|
|
1253
|
-
export namespace Route {
|
|
1254
|
-
// links
|
|
1255
|
-
export type LinkDescriptors = Annotations["LinkDescriptors"];
|
|
1256
|
-
export type LinksFunction = Annotations["LinksFunction"];
|
|
1257
|
-
|
|
1258
|
-
// meta
|
|
1259
|
-
export type MetaArgs = Annotations["MetaArgs"];
|
|
1260
|
-
export type MetaDescriptors = Annotations["MetaDescriptors"];
|
|
1261
|
-
export type MetaFunction = Annotations["MetaFunction"];
|
|
1262
|
-
|
|
1263
|
-
// headers
|
|
1264
|
-
export type HeadersArgs = Annotations["HeadersArgs"];
|
|
1265
|
-
export type HeadersFunction = Annotations["HeadersFunction"];
|
|
1266
|
-
|
|
1267
|
-
// middleware
|
|
1268
|
-
export type MiddlewareFunction = Annotations["MiddlewareFunction"];
|
|
1269
|
-
|
|
1270
|
-
// clientMiddleware
|
|
1271
|
-
export type ClientMiddlewareFunction = Annotations["ClientMiddlewareFunction"];
|
|
1272
|
-
|
|
1273
|
-
// loader
|
|
1274
|
-
export type LoaderArgs = Annotations["LoaderArgs"];
|
|
1275
|
-
|
|
1276
|
-
// clientLoader
|
|
1277
|
-
export type ClientLoaderArgs = Annotations["ClientLoaderArgs"];
|
|
1278
|
-
|
|
1279
|
-
// action
|
|
1280
|
-
export type ActionArgs = Annotations["ActionArgs"];
|
|
1281
|
-
|
|
1282
|
-
// clientAction
|
|
1283
|
-
export type ClientActionArgs = Annotations["ClientActionArgs"];
|
|
1284
|
-
|
|
1285
|
-
// HydrateFallback
|
|
1286
|
-
export type HydrateFallbackProps = Annotations["HydrateFallbackProps"];
|
|
1287
|
-
|
|
1288
|
-
// ServerHydrateFallback
|
|
1289
|
-
export type ServerHydrateFallbackProps = Annotations["ServerHydrateFallbackProps"];
|
|
1290
|
-
|
|
1291
|
-
// Component
|
|
1292
|
-
export type ComponentProps = Annotations["ComponentProps"];
|
|
1293
|
-
|
|
1294
|
-
// ServerComponent
|
|
1295
|
-
export type ServerComponentProps = Annotations["ServerComponentProps"];
|
|
1296
|
-
|
|
1297
|
-
// ErrorBoundary
|
|
1298
|
-
export type ErrorBoundaryProps = Annotations["ErrorBoundaryProps"];
|
|
1299
|
-
|
|
1300
|
-
// ServerErrorBoundary
|
|
1301
|
-
export type ServerErrorBoundaryProps = Annotations["ServerErrorBoundaryProps"];
|
|
1302
|
-
}
|
|
1303
|
-
`;
|
|
1304
|
-
return { filename: filename2, content };
|
|
1305
|
-
}
|
|
1306
|
-
function relativeImportSource(from, to) {
|
|
1307
|
-
let path10 = Path3.relative(Path3.dirname(from), to);
|
|
1308
|
-
let extension = Path3.extname(path10);
|
|
1309
|
-
path10 = Path3.join(Path3.dirname(path10), Pathe.filename(path10));
|
|
1310
|
-
if (!path10.startsWith("../")) path10 = "./" + path10;
|
|
1311
|
-
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1312
|
-
extension = ".js";
|
|
1313
|
-
}
|
|
1314
|
-
return path10 + extension;
|
|
1315
|
-
}
|
|
1316
|
-
function rootDirsPath(ctx, typesPath) {
|
|
1317
|
-
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1318
|
-
return Path3.join(ctx.rootDirectory, rel);
|
|
1319
|
-
}
|
|
1320
|
-
function paramsType(path10) {
|
|
1321
|
-
const params = parse2(path10);
|
|
1322
|
-
return t2.tsTypeLiteral(
|
|
1323
|
-
Object.entries(params).map(([param, isRequired]) => {
|
|
1324
|
-
const property = t2.tsPropertySignature(
|
|
1325
|
-
t2.stringLiteral(param),
|
|
1326
|
-
t2.tsTypeAnnotation(t2.tsStringKeyword())
|
|
1327
|
-
);
|
|
1328
|
-
property.optional = !isRequired;
|
|
1329
|
-
return property;
|
|
1330
|
-
})
|
|
1331
|
-
);
|
|
1332
|
-
}
|
|
1333
|
-
function expand(fullpath2) {
|
|
1334
|
-
function recurse(segments2, index) {
|
|
1335
|
-
if (index === segments2.length) return [""];
|
|
1336
|
-
const segment = segments2[index];
|
|
1337
|
-
const isOptional = segment.endsWith("?");
|
|
1338
|
-
const isDynamic = segment.startsWith(":");
|
|
1339
|
-
const required = segment.replace(/\?$/, "");
|
|
1340
|
-
const keep = !isOptional || isDynamic;
|
|
1341
|
-
const kept = isDynamic ? segment : required;
|
|
1342
|
-
const withoutSegment = recurse(segments2, index + 1);
|
|
1343
|
-
const withSegment = withoutSegment.map((rest) => [kept, rest].join("/"));
|
|
1344
|
-
if (keep) return withSegment;
|
|
1345
|
-
return [...withoutSegment, ...withSegment];
|
|
1346
|
-
}
|
|
1347
|
-
const segments = fullpath2.split("/");
|
|
1348
|
-
const expanded = /* @__PURE__ */ new Set();
|
|
1349
|
-
for (let result of recurse(segments, 0)) {
|
|
1350
|
-
if (result !== "/") result = result.replace(/\/$/, "");
|
|
1351
|
-
expanded.add(result);
|
|
1352
|
-
}
|
|
1353
|
-
return expanded;
|
|
1354
|
-
}
|
|
1355
|
-
var import_dedent, Path3, Pathe, t2;
|
|
1356
|
-
var init_generate = __esm({
|
|
1357
|
-
"typegen/generate.ts"() {
|
|
1358
|
-
"use strict";
|
|
1359
|
-
import_dedent = __toESM(require("dedent"));
|
|
1360
|
-
Path3 = __toESM(require("pathe"));
|
|
1361
|
-
Pathe = __toESM(require("pathe/utils"));
|
|
1362
|
-
init_babel();
|
|
1363
|
-
init_params();
|
|
1364
|
-
init_route();
|
|
1365
|
-
({ t: t2 } = babel_exports);
|
|
1366
|
-
}
|
|
1367
|
-
});
|
|
1368
|
-
|
|
1369
|
-
// typegen/index.ts
|
|
1370
|
-
async function clearRouteModuleAnnotations(ctx) {
|
|
1371
|
-
await import_promises.default.rm(
|
|
1372
|
-
Path4.join(typesDirectory(ctx), Path4.basename(ctx.config.appDirectory)),
|
|
1373
|
-
{ recursive: true, force: true }
|
|
1374
|
-
);
|
|
1375
|
-
}
|
|
1376
|
-
async function write(...files) {
|
|
1377
|
-
return Promise.all(
|
|
1378
|
-
files.map(async ({ filename: filename2, content }) => {
|
|
1379
|
-
await import_promises.default.mkdir(Path4.dirname(filename2), { recursive: true });
|
|
1380
|
-
await import_promises.default.writeFile(filename2, content);
|
|
1381
|
-
})
|
|
1382
|
-
);
|
|
1383
|
-
}
|
|
1384
|
-
async function run(rootDirectory, { mode, rsc }) {
|
|
1385
|
-
const ctx = await createContext2({ rootDirectory, mode, rsc, watch: false });
|
|
1386
|
-
await import_promises.default.rm(typesDirectory(ctx), { recursive: true, force: true });
|
|
1387
|
-
await write(
|
|
1388
|
-
generateFuture(ctx),
|
|
1389
|
-
generateServerBuild(ctx),
|
|
1390
|
-
...generateRoutes(ctx)
|
|
1391
|
-
);
|
|
1392
|
-
}
|
|
1393
|
-
async function watch(rootDirectory, { mode, logger, rsc }) {
|
|
1394
|
-
const ctx = await createContext2({ rootDirectory, mode, rsc, watch: true });
|
|
1395
|
-
await import_promises.default.rm(typesDirectory(ctx), { recursive: true, force: true });
|
|
1396
|
-
await write(
|
|
1397
|
-
generateFuture(ctx),
|
|
1398
|
-
generateServerBuild(ctx),
|
|
1399
|
-
...generateRoutes(ctx)
|
|
1400
|
-
);
|
|
1401
|
-
logger?.info((0, import_picocolors3.green)("generated types"), { timestamp: true, clear: true });
|
|
1402
|
-
ctx.configLoader.onChange(
|
|
1403
|
-
async ({ result, configChanged, routeConfigChanged }) => {
|
|
1404
|
-
if (!result.ok) {
|
|
1405
|
-
logger?.error((0, import_picocolors3.red)(result.error), { timestamp: true, clear: true });
|
|
1406
|
-
return;
|
|
1407
|
-
}
|
|
1408
|
-
ctx.config = result.value;
|
|
1409
|
-
if (configChanged) {
|
|
1410
|
-
await write(generateFuture(ctx));
|
|
1411
|
-
logger?.info((0, import_picocolors3.green)("regenerated types"), {
|
|
1412
|
-
timestamp: true,
|
|
1413
|
-
clear: true
|
|
1414
|
-
});
|
|
1415
|
-
}
|
|
1416
|
-
if (routeConfigChanged) {
|
|
1417
|
-
await clearRouteModuleAnnotations(ctx);
|
|
1418
|
-
await write(...generateRoutes(ctx));
|
|
1419
|
-
logger?.info((0, import_picocolors3.green)("regenerated types"), {
|
|
1420
|
-
timestamp: true,
|
|
1421
|
-
clear: true
|
|
1422
|
-
});
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
);
|
|
1426
|
-
return {
|
|
1427
|
-
close: async () => await ctx.configLoader.close()
|
|
1428
|
-
};
|
|
1429
|
-
}
|
|
1430
|
-
var import_promises, Path4, import_picocolors3;
|
|
1431
|
-
var init_typegen = __esm({
|
|
1432
|
-
"typegen/index.ts"() {
|
|
1433
|
-
"use strict";
|
|
1434
|
-
import_promises = __toESM(require("fs/promises"));
|
|
1435
|
-
Path4 = __toESM(require("pathe"));
|
|
1436
|
-
import_picocolors3 = require("picocolors");
|
|
1437
|
-
init_context();
|
|
1438
|
-
init_generate();
|
|
1439
|
-
}
|
|
1440
|
-
});
|
|
1441
|
-
|
|
1442
|
-
// vite/has-rsc-plugin.ts
|
|
1443
|
-
async function hasReactRouterRscPlugin({
|
|
1444
|
-
root,
|
|
1445
|
-
viteBuildOptions: { config, logLevel, mode }
|
|
1446
|
-
}) {
|
|
1447
|
-
await preloadVite();
|
|
1448
|
-
const vite2 = getVite();
|
|
1449
|
-
const viteConfig = await vite2.resolveConfig(
|
|
1450
|
-
{
|
|
1451
|
-
configFile: config,
|
|
1452
|
-
logLevel,
|
|
1453
|
-
mode: mode ?? "production",
|
|
1454
|
-
root
|
|
1455
|
-
},
|
|
1456
|
-
"build",
|
|
1457
|
-
// command
|
|
1458
|
-
"production",
|
|
1459
|
-
// default mode
|
|
1460
|
-
"production"
|
|
1461
|
-
// default NODE_ENV
|
|
1462
|
-
);
|
|
1463
|
-
return viteConfig.plugins.some(
|
|
1464
|
-
(plugin) => plugin?.name === "react-router/rsc"
|
|
1465
|
-
);
|
|
1466
|
-
}
|
|
1467
|
-
var init_has_rsc_plugin = __esm({
|
|
1468
|
-
"vite/has-rsc-plugin.ts"() {
|
|
1469
|
-
"use strict";
|
|
1470
|
-
init_vite();
|
|
1471
|
-
}
|
|
1472
|
-
});
|
|
1473
|
-
|
|
1474
|
-
// vite/node-adapter.ts
|
|
1475
|
-
var init_node_adapter = __esm({
|
|
1476
|
-
"vite/node-adapter.ts"() {
|
|
1477
|
-
"use strict";
|
|
1478
|
-
init_invariant();
|
|
1479
|
-
}
|
|
1480
|
-
});
|
|
1481
|
-
|
|
1482
|
-
// vite/resolve-file-url.ts
|
|
1483
|
-
var path4;
|
|
1484
|
-
var init_resolve_file_url = __esm({
|
|
1485
|
-
"vite/resolve-file-url.ts"() {
|
|
1486
|
-
"use strict";
|
|
1487
|
-
path4 = __toESM(require("path"));
|
|
1488
|
-
init_vite();
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
|
|
1492
|
-
// vite/styles.ts
|
|
1493
|
-
var path5, import_react_router, cssFileRegExp, cssModulesRegExp;
|
|
1494
|
-
var init_styles = __esm({
|
|
1495
|
-
"vite/styles.ts"() {
|
|
1496
|
-
"use strict";
|
|
1497
|
-
path5 = __toESM(require("path"));
|
|
1498
|
-
import_react_router = require("react-router");
|
|
1499
|
-
init_resolve_file_url();
|
|
1500
|
-
init_babel();
|
|
1501
|
-
cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
1502
|
-
cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
1503
|
-
}
|
|
1504
|
-
});
|
|
1505
|
-
|
|
1506
|
-
// vite/virtual-module.ts
|
|
1507
|
-
function create(name) {
|
|
1508
|
-
let id = `virtual:react-router/${name}`;
|
|
1509
|
-
return {
|
|
1510
|
-
id,
|
|
1511
|
-
resolvedId: `\0${id}`,
|
|
1512
|
-
url: `/@id/__x00__${id}`
|
|
1513
|
-
};
|
|
1514
|
-
}
|
|
1515
|
-
var init_virtual_module = __esm({
|
|
1516
|
-
"vite/virtual-module.ts"() {
|
|
1517
|
-
"use strict";
|
|
1518
|
-
}
|
|
1519
|
-
});
|
|
1520
|
-
|
|
1521
|
-
// vite/resolve-relative-route-file-path.ts
|
|
1522
|
-
var import_pathe4;
|
|
1523
|
-
var init_resolve_relative_route_file_path = __esm({
|
|
1524
|
-
"vite/resolve-relative-route-file-path.ts"() {
|
|
1525
|
-
"use strict";
|
|
1526
|
-
import_pathe4 = __toESM(require("pathe"));
|
|
1527
|
-
init_vite();
|
|
1528
|
-
}
|
|
1529
|
-
});
|
|
1530
|
-
|
|
1531
|
-
// vite/combine-urls.ts
|
|
1532
|
-
var init_combine_urls = __esm({
|
|
1533
|
-
"vite/combine-urls.ts"() {
|
|
1534
|
-
"use strict";
|
|
1535
|
-
}
|
|
1536
|
-
});
|
|
1537
|
-
|
|
1538
|
-
// vite/remove-exports.ts
|
|
1539
|
-
var import_babel_dead_code_elimination;
|
|
1540
|
-
var init_remove_exports = __esm({
|
|
1541
|
-
"vite/remove-exports.ts"() {
|
|
1542
|
-
"use strict";
|
|
1543
|
-
import_babel_dead_code_elimination = require("babel-dead-code-elimination");
|
|
1544
|
-
init_babel();
|
|
1545
|
-
}
|
|
1546
|
-
});
|
|
1547
|
-
|
|
1548
|
-
// vite/has-dependency.ts
|
|
1549
|
-
var init_has_dependency = __esm({
|
|
1550
|
-
"vite/has-dependency.ts"() {
|
|
1551
|
-
"use strict";
|
|
1552
|
-
}
|
|
1553
|
-
});
|
|
1554
|
-
|
|
1555
|
-
// vite/cache.ts
|
|
1556
|
-
var init_cache = __esm({
|
|
1557
|
-
"vite/cache.ts"() {
|
|
1558
|
-
"use strict";
|
|
1559
|
-
}
|
|
1560
|
-
});
|
|
1561
|
-
|
|
1562
|
-
// vite/route-chunks.ts
|
|
1563
|
-
function getRouteChunkModuleId(filePath, chunkName) {
|
|
1564
|
-
return `${filePath}${routeChunkQueryStrings[chunkName]}`;
|
|
1565
|
-
}
|
|
1566
|
-
function isRouteChunkModuleId(id) {
|
|
1567
|
-
return Object.values(routeChunkQueryStrings).some(
|
|
1568
|
-
(queryString) => id.endsWith(queryString)
|
|
1569
|
-
);
|
|
1570
|
-
}
|
|
1571
|
-
function isRouteChunkName(name) {
|
|
1572
|
-
return name === mainChunkName || routeChunkExportNames.includes(name);
|
|
1573
|
-
}
|
|
1574
|
-
function getRouteChunkNameFromModuleId(id) {
|
|
1575
|
-
if (!isRouteChunkModuleId(id)) {
|
|
1576
|
-
return null;
|
|
1577
|
-
}
|
|
1578
|
-
let chunkName = id.split(routeChunkQueryStringPrefix)[1].split("&")[0];
|
|
1579
|
-
if (!isRouteChunkName(chunkName)) {
|
|
1580
|
-
return null;
|
|
1581
|
-
}
|
|
1582
|
-
return chunkName;
|
|
1583
|
-
}
|
|
1584
|
-
var routeChunkExportNames, mainChunkName, routeChunkNames, routeChunkQueryStringPrefix, routeChunkQueryStrings;
|
|
1585
|
-
var init_route_chunks = __esm({
|
|
1586
|
-
"vite/route-chunks.ts"() {
|
|
1587
|
-
"use strict";
|
|
1588
|
-
init_invariant();
|
|
1589
|
-
init_cache();
|
|
1590
|
-
init_babel();
|
|
1591
|
-
routeChunkExportNames = [
|
|
1592
|
-
"clientAction",
|
|
1593
|
-
"clientLoader",
|
|
1594
|
-
"clientMiddleware",
|
|
1595
|
-
"HydrateFallback"
|
|
1596
|
-
];
|
|
1597
|
-
mainChunkName = "main";
|
|
1598
|
-
routeChunkNames = ["main", ...routeChunkExportNames];
|
|
1599
|
-
routeChunkQueryStringPrefix = "?route-chunk=";
|
|
1600
|
-
routeChunkQueryStrings = {
|
|
1601
|
-
main: `${routeChunkQueryStringPrefix}main`,
|
|
1602
|
-
clientAction: `${routeChunkQueryStringPrefix}clientAction`,
|
|
1603
|
-
clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
|
|
1604
|
-
clientMiddleware: `${routeChunkQueryStringPrefix}clientMiddleware`,
|
|
1605
|
-
HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
|
|
1606
|
-
};
|
|
1607
|
-
}
|
|
1608
|
-
});
|
|
1609
|
-
|
|
1610
|
-
// vite/optimize-deps-entries.ts
|
|
1611
|
-
var import_tinyglobby;
|
|
1612
|
-
var init_optimize_deps_entries = __esm({
|
|
1613
|
-
"vite/optimize-deps-entries.ts"() {
|
|
1614
|
-
"use strict";
|
|
1615
|
-
import_tinyglobby = require("tinyglobby");
|
|
1616
|
-
init_resolve_relative_route_file_path();
|
|
1617
|
-
init_vite();
|
|
1618
|
-
}
|
|
1619
|
-
});
|
|
1620
|
-
|
|
1621
|
-
// vite/with-props.ts
|
|
1622
|
-
var init_with_props = __esm({
|
|
1623
|
-
"vite/with-props.ts"() {
|
|
1624
|
-
"use strict";
|
|
1625
|
-
init_babel();
|
|
1626
|
-
}
|
|
1627
|
-
});
|
|
1628
|
-
|
|
1629
|
-
// vite/load-dotenv.ts
|
|
1630
|
-
var init_load_dotenv = __esm({
|
|
1631
|
-
"vite/load-dotenv.ts"() {
|
|
1632
|
-
"use strict";
|
|
1633
|
-
}
|
|
1634
|
-
});
|
|
1635
|
-
|
|
1636
|
-
// vite/plugins/validate-plugin-order.ts
|
|
1637
|
-
var init_validate_plugin_order = __esm({
|
|
1638
|
-
"vite/plugins/validate-plugin-order.ts"() {
|
|
1639
|
-
"use strict";
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
|
|
1643
|
-
// vite/plugins/warn-on-client-source-maps.ts
|
|
1644
|
-
var import_picocolors4;
|
|
1645
|
-
var init_warn_on_client_source_maps = __esm({
|
|
1646
|
-
"vite/plugins/warn-on-client-source-maps.ts"() {
|
|
1647
|
-
"use strict";
|
|
1648
|
-
import_picocolors4 = __toESM(require("picocolors"));
|
|
1649
|
-
init_invariant();
|
|
1650
|
-
}
|
|
1651
|
-
});
|
|
1652
|
-
|
|
1653
|
-
// vite/plugins/prerender.ts
|
|
1654
|
-
var import_promises2, import_node_path2;
|
|
1655
|
-
var init_prerender = __esm({
|
|
1656
|
-
"vite/plugins/prerender.ts"() {
|
|
1657
|
-
"use strict";
|
|
1658
|
-
import_promises2 = require("fs/promises");
|
|
1659
|
-
import_node_path2 = __toESM(require("path"));
|
|
1660
|
-
}
|
|
1661
|
-
});
|
|
1662
|
-
|
|
1663
|
-
// vite/plugin.ts
|
|
1664
|
-
async function resolveViteConfig({
|
|
1665
|
-
configFile,
|
|
1666
|
-
mode,
|
|
1667
|
-
root,
|
|
1668
|
-
plugins
|
|
1669
|
-
}) {
|
|
1670
|
-
let vite2 = getVite();
|
|
1671
|
-
let viteConfig = await vite2.resolveConfig(
|
|
1672
|
-
{ mode, configFile, root, plugins },
|
|
1673
|
-
"build",
|
|
1674
|
-
// command
|
|
1675
|
-
"production",
|
|
1676
|
-
// default mode
|
|
1677
|
-
"production"
|
|
1678
|
-
// default NODE_ENV
|
|
1679
|
-
);
|
|
1680
|
-
if (typeof viteConfig.build.manifest === "string") {
|
|
1681
|
-
throw new Error("Custom Vite manifest paths are not supported");
|
|
1682
|
-
}
|
|
1683
|
-
return viteConfig;
|
|
1684
|
-
}
|
|
1685
|
-
function extractPluginContext(viteConfig) {
|
|
1686
|
-
return viteConfig["__reactRouterPluginContext"];
|
|
1687
|
-
}
|
|
1688
|
-
function isSsrBundleEnvironmentName(name) {
|
|
1689
|
-
return name.startsWith(SSR_BUNDLE_PREFIX);
|
|
1690
|
-
}
|
|
1691
|
-
function getServerEnvironmentEntries(ctx, record) {
|
|
1692
|
-
return Object.entries(record).filter(
|
|
1693
|
-
([name]) => ctx.buildManifest?.serverBundles ? isSsrBundleEnvironmentName(name) : name === "ssr"
|
|
1694
|
-
);
|
|
1695
|
-
}
|
|
1696
|
-
function getServerEnvironmentKeys(ctx, record) {
|
|
1697
|
-
return getServerEnvironmentEntries(ctx, record).map(([key]) => key);
|
|
1698
|
-
}
|
|
1699
|
-
function getServerBundleIds(ctx) {
|
|
1700
|
-
return ctx.buildManifest?.serverBundles ? Object.keys(ctx.buildManifest.serverBundles) : void 0;
|
|
1701
|
-
}
|
|
1702
|
-
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
1703
|
-
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
1704
|
-
let isWithinRoot = () => {
|
|
1705
|
-
let relativePath = path8.relative(ctx.rootDirectory, buildDirectory);
|
|
1706
|
-
return !relativePath.startsWith("..") && !path8.isAbsolute(relativePath);
|
|
1707
|
-
};
|
|
1708
|
-
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
1709
|
-
await (0, import_promises3.rm)(buildDirectory, { force: true, recursive: true });
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
async function cleanViteManifests(environmentsOptions, ctx) {
|
|
1713
|
-
let viteManifestPaths = Object.entries(environmentsOptions).map(
|
|
1714
|
-
([environmentName, options]) => {
|
|
1715
|
-
let outDir = options.build?.outDir;
|
|
1716
|
-
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
1717
|
-
return path8.join(outDir, ".vite/manifest.json");
|
|
1718
|
-
}
|
|
1719
|
-
);
|
|
1720
|
-
await Promise.all(
|
|
1721
|
-
viteManifestPaths.map(async (viteManifestPath) => {
|
|
1722
|
-
let manifestExists = (0, import_node_fs3.existsSync)(viteManifestPath);
|
|
1723
|
-
if (!manifestExists) return;
|
|
1724
|
-
if (!ctx.viteManifestEnabled) {
|
|
1725
|
-
await (0, import_promises3.rm)(viteManifestPath, { force: true, recursive: true });
|
|
1726
|
-
}
|
|
1727
|
-
let viteDir = path8.dirname(viteManifestPath);
|
|
1728
|
-
let viteDirFiles = await (0, import_promises3.readdir)(viteDir, { recursive: true });
|
|
1729
|
-
if (viteDirFiles.length === 0) {
|
|
1730
|
-
await (0, import_promises3.rm)(viteDir, { force: true, recursive: true });
|
|
1731
|
-
}
|
|
1732
|
-
})
|
|
1733
|
-
);
|
|
1734
|
-
}
|
|
1735
|
-
function mergeEnvironmentOptions(base, ...overrides) {
|
|
1736
|
-
let vite2 = getVite();
|
|
1737
|
-
return overrides.reduce(
|
|
1738
|
-
(merged, override) => vite2.mergeConfig(merged, override, false),
|
|
1739
|
-
base
|
|
1740
|
-
);
|
|
1741
|
-
}
|
|
1742
|
-
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
1743
|
-
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
1744
|
-
let packageRoot = path8.dirname(
|
|
1745
|
-
require.resolve("@react-router/dev/package.json")
|
|
1746
|
-
);
|
|
1747
|
-
let { moduleSyncEnabled } = await import(`file:///${path8.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
1748
|
-
let vite2 = getVite();
|
|
1749
|
-
function getBaseOptions({
|
|
1750
|
-
viteUserConfig
|
|
1751
|
-
}) {
|
|
1752
|
-
const rollupOptions = {
|
|
1753
|
-
preserveEntrySignatures: "exports-only",
|
|
1754
|
-
// Silence Rollup "use client" warnings
|
|
1755
|
-
// Adapted from https://github.com/vitejs/vite-plugin-react/pull/144
|
|
1756
|
-
onwarn(warning, defaultHandler) {
|
|
1757
|
-
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
|
1758
|
-
return;
|
|
1759
|
-
}
|
|
1760
|
-
let userHandler = viteUserConfig.build?.rollupOptions?.onwarn;
|
|
1761
|
-
if (userHandler) {
|
|
1762
|
-
userHandler(warning, defaultHandler);
|
|
1763
|
-
} else {
|
|
1764
|
-
defaultHandler(warning);
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
};
|
|
1768
|
-
return {
|
|
1769
|
-
build: {
|
|
1770
|
-
cssMinify: viteUserConfig.build?.cssMinify ?? true,
|
|
1771
|
-
manifest: true,
|
|
1772
|
-
// The manifest is enabled for all builds to detect SSR-only assets
|
|
1773
|
-
rollupOptions
|
|
1774
|
-
}
|
|
1775
|
-
};
|
|
1776
|
-
}
|
|
1777
|
-
function getBaseServerOptions({
|
|
1778
|
-
viteUserConfig
|
|
1779
|
-
}) {
|
|
1780
|
-
let maybeModuleSyncConditions = [
|
|
1781
|
-
...moduleSyncEnabled ? ["module-sync"] : []
|
|
1782
|
-
];
|
|
1783
|
-
let maybeDevelopmentConditions = viteCommand === "build" ? [] : ["development"];
|
|
1784
|
-
let maybeDefaultServerConditions = vite2.defaultServerConditions || [];
|
|
1785
|
-
let defaultExternalConditions = ["node"];
|
|
1786
|
-
let baseConditions = [
|
|
1787
|
-
...maybeDevelopmentConditions,
|
|
1788
|
-
...maybeModuleSyncConditions
|
|
1789
|
-
];
|
|
1790
|
-
return mergeEnvironmentOptions(getBaseOptions({ viteUserConfig }), {
|
|
1791
|
-
resolve: {
|
|
1792
|
-
external: (
|
|
1793
|
-
// If `v8_viteEnvironmentApi` is `true`, `resolve.external` is set in the `configEnvironment` hook
|
|
1794
|
-
ctx.reactRouterConfig.future.v8_viteEnvironmentApi ? void 0 : ssrExternals
|
|
1795
|
-
),
|
|
1796
|
-
conditions: [...baseConditions, ...maybeDefaultServerConditions],
|
|
1797
|
-
externalConditions: [...baseConditions, ...defaultExternalConditions]
|
|
1798
|
-
},
|
|
1799
|
-
build: {
|
|
1800
|
-
// We move SSR-only assets to client assets. Note that the
|
|
1801
|
-
// SSR build can also emit code-split JS files (e.g., by
|
|
1802
|
-
// dynamic import) under the same assets directory
|
|
1803
|
-
// regardless of "ssrEmitAssets" option, so we also need to
|
|
1804
|
-
// keep these JS files to be kept as-is.
|
|
1805
|
-
ssrEmitAssets: true,
|
|
1806
|
-
copyPublicDir: false,
|
|
1807
|
-
// The client only uses assets in the public directory
|
|
1808
|
-
rollupOptions: {
|
|
1809
|
-
input: (ctx.reactRouterConfig.future.v8_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual.serverBuild.id,
|
|
1810
|
-
output: {
|
|
1811
|
-
entryFileNames: serverBuildFile,
|
|
1812
|
-
format: serverModuleFormat
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
});
|
|
1817
|
-
}
|
|
1818
|
-
let environmentOptionsResolvers = {
|
|
1819
|
-
client: ({ viteUserConfig }) => mergeEnvironmentOptions(getBaseOptions({ viteUserConfig }), {
|
|
1820
|
-
build: {
|
|
1821
|
-
rollupOptions: {
|
|
1822
|
-
input: [
|
|
1823
|
-
ctx.entryClientFilePath,
|
|
1824
|
-
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
1825
|
-
(route) => {
|
|
1826
|
-
let routeFilePath = path8.resolve(
|
|
1827
|
-
ctx.reactRouterConfig.appDirectory,
|
|
1828
|
-
route.file
|
|
1829
|
-
);
|
|
1830
|
-
let isRootRoute = route.file === ctx.reactRouterConfig.routes.root.file;
|
|
1831
|
-
let code = (0, import_node_fs3.readFileSync)(routeFilePath, "utf-8");
|
|
1832
|
-
return [
|
|
1833
|
-
`${routeFilePath}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
|
|
1834
|
-
...ctx.reactRouterConfig.future.v8_splitRouteModules && !isRootRoute ? routeChunkExportNames.map(
|
|
1835
|
-
(exportName) => code.includes(exportName) ? getRouteChunkModuleId(routeFilePath, exportName) : null
|
|
1836
|
-
) : []
|
|
1837
|
-
].filter(isNonNullable);
|
|
1838
|
-
}
|
|
1839
|
-
)
|
|
1840
|
-
],
|
|
1841
|
-
output: (ctx.reactRouterConfig.future.v8_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.rollupOptions?.output : viteUserConfig?.build?.rollupOptions?.output) ?? {
|
|
1842
|
-
entryFileNames: ({ moduleIds }) => {
|
|
1843
|
-
let routeChunkModuleId = moduleIds.find(isRouteChunkModuleId);
|
|
1844
|
-
let routeChunkName = routeChunkModuleId ? getRouteChunkNameFromModuleId(routeChunkModuleId)?.replace(
|
|
1845
|
-
"unstable_",
|
|
1846
|
-
""
|
|
1847
|
-
) : null;
|
|
1848
|
-
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
1849
|
-
let assetsDir = (ctx.reactRouterConfig.future.v8_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
1850
|
-
return path8.posix.join(
|
|
1851
|
-
assetsDir,
|
|
1852
|
-
`[name]${routeChunkSuffix}-[hash].js`
|
|
1853
|
-
);
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
},
|
|
1857
|
-
outDir: getClientBuildDirectory(ctx.reactRouterConfig)
|
|
1858
|
-
}
|
|
1859
|
-
})
|
|
1860
|
-
};
|
|
1861
|
-
let serverBundleIds = getServerBundleIds(ctx);
|
|
1862
|
-
if (serverBundleIds) {
|
|
1863
|
-
for (let serverBundleId of serverBundleIds) {
|
|
1864
|
-
const environmentName = `${SSR_BUNDLE_PREFIX}${serverBundleId}`;
|
|
1865
|
-
environmentOptionsResolvers[environmentName] = ({ viteUserConfig }) => mergeEnvironmentOptions(
|
|
1866
|
-
getBaseServerOptions({ viteUserConfig }),
|
|
1867
|
-
{
|
|
1868
|
-
build: {
|
|
1869
|
-
outDir: getServerBuildDirectory(ctx.reactRouterConfig, {
|
|
1870
|
-
serverBundleId
|
|
1871
|
-
})
|
|
1872
|
-
}
|
|
1873
|
-
},
|
|
1874
|
-
// Ensure server bundle environments extend the user's SSR
|
|
1875
|
-
// environment config if it exists
|
|
1876
|
-
viteUserConfig.environments?.ssr ?? {}
|
|
1877
|
-
);
|
|
1878
|
-
}
|
|
1879
|
-
} else {
|
|
1880
|
-
environmentOptionsResolvers.ssr = ({ viteUserConfig }) => mergeEnvironmentOptions(getBaseServerOptions({ viteUserConfig }), {
|
|
1881
|
-
build: {
|
|
1882
|
-
outDir: getServerBuildDirectory(ctx.reactRouterConfig)
|
|
1883
|
-
}
|
|
1884
|
-
});
|
|
1885
|
-
}
|
|
1886
|
-
return environmentOptionsResolvers;
|
|
1887
|
-
}
|
|
1888
|
-
function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {
|
|
1889
|
-
let environmentOptions = {};
|
|
1890
|
-
for (let [environmentName, resolver] of Object.entries(
|
|
1891
|
-
environmentResolvers
|
|
1892
|
-
)) {
|
|
1893
|
-
environmentOptions[environmentName] = resolver(resolverOptions);
|
|
1894
|
-
}
|
|
1895
|
-
return environmentOptions;
|
|
1896
|
-
}
|
|
1897
|
-
function isNonNullable(x) {
|
|
1898
|
-
return x != null;
|
|
1899
|
-
}
|
|
1900
|
-
var import_node_crypto, import_node_fs3, import_promises3, path8, url, babel2, import_react_router2, import_es_module_lexer, import_pick3, import_jsesc, import_picocolors5, import_kebabCase, CLIENT_NON_COMPONENT_EXPORTS, CLIENT_ROUTE_EXPORTS, BUILD_CLIENT_ROUTE_QUERY_STRING, SSR_BUNDLE_PREFIX, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, getClientBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
|
|
1901
|
-
var init_plugin = __esm({
|
|
1902
|
-
"vite/plugin.ts"() {
|
|
1903
|
-
"use strict";
|
|
1904
|
-
import_node_crypto = require("crypto");
|
|
1905
|
-
import_node_fs3 = require("fs");
|
|
1906
|
-
import_promises3 = require("fs/promises");
|
|
1907
|
-
path8 = __toESM(require("path"));
|
|
1908
|
-
url = __toESM(require("url"));
|
|
1909
|
-
babel2 = __toESM(require("@babel/core"));
|
|
1910
|
-
import_react_router2 = require("react-router");
|
|
1911
|
-
import_es_module_lexer = require("es-module-lexer");
|
|
1912
|
-
import_pick3 = __toESM(require("lodash/pick"));
|
|
1913
|
-
import_jsesc = __toESM(require("jsesc"));
|
|
1914
|
-
import_picocolors5 = __toESM(require("picocolors"));
|
|
1915
|
-
import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
1916
|
-
init_typegen();
|
|
1917
|
-
init_invariant();
|
|
1918
|
-
init_babel();
|
|
1919
|
-
init_node_adapter();
|
|
1920
|
-
init_styles();
|
|
1921
|
-
init_virtual_module();
|
|
1922
|
-
init_resolve_file_url();
|
|
1923
|
-
init_resolve_relative_route_file_path();
|
|
1924
|
-
init_combine_urls();
|
|
1925
|
-
init_remove_exports();
|
|
1926
|
-
init_ssr_externals();
|
|
1927
|
-
init_has_dependency();
|
|
1928
|
-
init_route_chunks();
|
|
1929
|
-
init_vite();
|
|
1930
|
-
init_config();
|
|
1931
|
-
init_optimize_deps_entries();
|
|
1932
|
-
init_with_props();
|
|
1933
|
-
init_load_dotenv();
|
|
1934
|
-
init_validate_plugin_order();
|
|
1935
|
-
init_warn_on_client_source_maps();
|
|
1936
|
-
init_prerender();
|
|
1937
|
-
CLIENT_NON_COMPONENT_EXPORTS = [
|
|
1938
|
-
"clientAction",
|
|
1939
|
-
"clientLoader",
|
|
1940
|
-
"clientMiddleware",
|
|
1941
|
-
"handle",
|
|
1942
|
-
"meta",
|
|
1943
|
-
"links",
|
|
1944
|
-
"shouldRevalidate"
|
|
1945
|
-
];
|
|
1946
|
-
CLIENT_ROUTE_EXPORTS = [
|
|
1947
|
-
...CLIENT_NON_COMPONENT_EXPORTS,
|
|
1948
|
-
"default",
|
|
1949
|
-
"ErrorBoundary",
|
|
1950
|
-
"HydrateFallback",
|
|
1951
|
-
"Layout"
|
|
1952
|
-
];
|
|
1953
|
-
BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
|
|
1954
|
-
SSR_BUNDLE_PREFIX = "ssrBundle_";
|
|
1955
|
-
virtualHmrRuntime = create("hmr-runtime");
|
|
1956
|
-
virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
1957
|
-
virtual = {
|
|
1958
|
-
serverBuild: create("server-build"),
|
|
1959
|
-
serverManifest: create("server-manifest"),
|
|
1960
|
-
browserManifest: create("browser-manifest")
|
|
1961
|
-
};
|
|
1962
|
-
getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path8.join(
|
|
1963
|
-
reactRouterConfig.buildDirectory,
|
|
1964
|
-
"server",
|
|
1965
|
-
...serverBundleId ? [serverBundleId] : []
|
|
1966
|
-
);
|
|
1967
|
-
getClientBuildDirectory = (reactRouterConfig) => path8.join(reactRouterConfig.buildDirectory, "client");
|
|
1968
|
-
defaultEntriesDir = path8.resolve(
|
|
1969
|
-
path8.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1970
|
-
"dist",
|
|
1971
|
-
"config",
|
|
1972
|
-
"defaults"
|
|
1973
|
-
);
|
|
1974
|
-
defaultEntries = (0, import_node_fs3.readdirSync)(defaultEntriesDir).map(
|
|
1975
|
-
(filename2) => path8.join(defaultEntriesDir, filename2)
|
|
1976
|
-
);
|
|
1977
|
-
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1978
|
-
REACT_REFRESH_HEADER = `
|
|
1979
|
-
import RefreshRuntime from "${virtualHmrRuntime.id}";
|
|
1980
|
-
|
|
1981
|
-
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
1982
|
-
let prevRefreshReg;
|
|
1983
|
-
let prevRefreshSig;
|
|
1984
|
-
|
|
1985
|
-
if (import.meta.hot && !inWebWorker) {
|
|
1986
|
-
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
1987
|
-
throw new Error(
|
|
1988
|
-
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
1989
|
-
);
|
|
1990
|
-
}
|
|
1991
|
-
|
|
1992
|
-
prevRefreshReg = window.$RefreshReg$;
|
|
1993
|
-
prevRefreshSig = window.$RefreshSig$;
|
|
1994
|
-
window.$RefreshReg$ = (type, id) => {
|
|
1995
|
-
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
1996
|
-
};
|
|
1997
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
1998
|
-
}`.replaceAll("\n", "");
|
|
1999
|
-
}
|
|
2000
|
-
});
|
|
2001
|
-
|
|
2002
|
-
// vite/build.ts
|
|
2003
|
-
var build_exports = {};
|
|
2004
|
-
__export(build_exports, {
|
|
2005
|
-
build: () => build
|
|
2006
|
-
});
|
|
2007
|
-
async function build(root, viteBuildOptions) {
|
|
2008
|
-
await preloadVite();
|
|
2009
|
-
let vite2 = getVite();
|
|
2010
|
-
let configResult = await loadConfig({
|
|
2011
|
-
rootDirectory: root,
|
|
2012
|
-
mode: viteBuildOptions.mode ?? "production",
|
|
2013
|
-
// In this scope we only need future flags, so we can skip evaluating
|
|
2014
|
-
// routes.ts until we're within the Vite build context
|
|
2015
|
-
skipRoutes: true
|
|
2016
|
-
});
|
|
2017
|
-
if (!configResult.ok) {
|
|
2018
|
-
throw new Error(configResult.error);
|
|
2019
|
-
}
|
|
2020
|
-
let config = configResult.value;
|
|
2021
|
-
let viteMajor = parseInt(vite2.version.split(".")[0], 10);
|
|
2022
|
-
if (config.future.v8_viteEnvironmentApi && viteMajor === 5) {
|
|
2023
|
-
throw new Error(
|
|
2024
|
-
"The future.v8_viteEnvironmentApi option is not supported in Vite 5"
|
|
2025
|
-
);
|
|
2026
|
-
}
|
|
2027
|
-
const useViteEnvironmentApi = config.future.v8_viteEnvironmentApi || await hasReactRouterRscPlugin({ root, viteBuildOptions });
|
|
2028
|
-
return await (useViteEnvironmentApi ? viteAppBuild(root, viteBuildOptions) : viteBuild(root, viteBuildOptions));
|
|
2029
|
-
}
|
|
2030
|
-
async function viteAppBuild(root, {
|
|
2031
|
-
assetsInlineLimit,
|
|
2032
|
-
clearScreen,
|
|
2033
|
-
config: configFile,
|
|
2034
|
-
emptyOutDir,
|
|
2035
|
-
force,
|
|
2036
|
-
logLevel,
|
|
2037
|
-
minify,
|
|
2038
|
-
mode,
|
|
2039
|
-
sourcemapClient,
|
|
2040
|
-
sourcemapServer
|
|
2041
|
-
}) {
|
|
2042
|
-
let vite2 = getVite();
|
|
2043
|
-
let builder = await vite2.createBuilder({
|
|
2044
|
-
root,
|
|
2045
|
-
mode,
|
|
2046
|
-
configFile,
|
|
2047
|
-
build: {
|
|
2048
|
-
assetsInlineLimit,
|
|
2049
|
-
emptyOutDir,
|
|
2050
|
-
minify
|
|
2051
|
-
},
|
|
2052
|
-
optimizeDeps: { force },
|
|
2053
|
-
clearScreen,
|
|
2054
|
-
logLevel,
|
|
2055
|
-
plugins: [
|
|
2056
|
-
{
|
|
2057
|
-
name: "react-router:cli-config",
|
|
2058
|
-
configEnvironment(name) {
|
|
2059
|
-
if (sourcemapClient && name === "client") {
|
|
2060
|
-
return {
|
|
2061
|
-
build: {
|
|
2062
|
-
sourcemap: sourcemapClient
|
|
2063
|
-
}
|
|
2064
|
-
};
|
|
2065
|
-
}
|
|
2066
|
-
if (sourcemapServer && name !== "client") {
|
|
2067
|
-
return {
|
|
2068
|
-
build: {
|
|
2069
|
-
sourcemap: sourcemapServer
|
|
2070
|
-
}
|
|
2071
|
-
};
|
|
2072
|
-
}
|
|
2073
|
-
},
|
|
2074
|
-
configResolved(config) {
|
|
2075
|
-
let hasReactRouterPlugin = config.plugins.find(
|
|
2076
|
-
(plugin) => plugin.name === "react-router" || plugin.name === "react-router/rsc"
|
|
2077
|
-
);
|
|
2078
|
-
if (!hasReactRouterPlugin) {
|
|
2079
|
-
throw new Error(
|
|
2080
|
-
"React Router Vite plugin not found in Vite config"
|
|
2081
|
-
);
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
]
|
|
2086
|
-
});
|
|
2087
|
-
await builder.buildApp();
|
|
2088
|
-
}
|
|
2089
|
-
async function viteBuild(root, {
|
|
2090
|
-
assetsInlineLimit,
|
|
2091
|
-
clearScreen,
|
|
2092
|
-
config: configFile,
|
|
2093
|
-
emptyOutDir,
|
|
2094
|
-
force,
|
|
2095
|
-
logLevel,
|
|
2096
|
-
minify,
|
|
2097
|
-
mode,
|
|
2098
|
-
sourcemapClient,
|
|
2099
|
-
sourcemapServer
|
|
2100
|
-
}) {
|
|
2101
|
-
let viteUserConfig = {};
|
|
2102
|
-
let viteConfig = await resolveViteConfig({
|
|
2103
|
-
configFile,
|
|
2104
|
-
mode,
|
|
2105
|
-
root,
|
|
2106
|
-
plugins: [
|
|
2107
|
-
{
|
|
2108
|
-
name: "react-router:extract-vite-user-config",
|
|
2109
|
-
config(config) {
|
|
2110
|
-
viteUserConfig = config;
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
]
|
|
2114
|
-
});
|
|
2115
|
-
let ctx = extractPluginContext(viteConfig);
|
|
2116
|
-
if (!ctx) {
|
|
2117
|
-
console.error(
|
|
2118
|
-
import_picocolors6.default.red("React Router Vite plugin not found in Vite config")
|
|
2119
|
-
);
|
|
2120
|
-
process.exit(1);
|
|
2121
|
-
}
|
|
2122
|
-
async function buildEnvironment(environmentName) {
|
|
2123
|
-
let vite2 = getVite();
|
|
2124
|
-
let ssr = environmentName !== "client";
|
|
2125
|
-
let resolveOptions = environmentOptionsResolvers[environmentName];
|
|
2126
|
-
invariant(resolveOptions);
|
|
2127
|
-
let environmentBuildContext = {
|
|
2128
|
-
name: environmentName,
|
|
2129
|
-
resolveOptions
|
|
2130
|
-
};
|
|
2131
|
-
await vite2.build({
|
|
2132
|
-
root,
|
|
2133
|
-
mode,
|
|
2134
|
-
configFile,
|
|
2135
|
-
build: {
|
|
2136
|
-
assetsInlineLimit,
|
|
2137
|
-
emptyOutDir,
|
|
2138
|
-
minify,
|
|
2139
|
-
ssr,
|
|
2140
|
-
sourcemap: ssr ? sourcemapServer : sourcemapClient
|
|
2141
|
-
},
|
|
2142
|
-
optimizeDeps: { force },
|
|
2143
|
-
clearScreen,
|
|
2144
|
-
logLevel,
|
|
2145
|
-
...{
|
|
2146
|
-
__reactRouterPluginContext: ctx,
|
|
2147
|
-
__reactRouterEnvironmentBuildContext: environmentBuildContext
|
|
2148
|
-
}
|
|
2149
|
-
});
|
|
2150
|
-
}
|
|
2151
|
-
let { reactRouterConfig, buildManifest } = ctx;
|
|
2152
|
-
invariant(buildManifest, "Expected build manifest to be present");
|
|
2153
|
-
let environmentOptionsResolvers = await getEnvironmentOptionsResolvers(
|
|
2154
|
-
ctx,
|
|
2155
|
-
"build"
|
|
2156
|
-
);
|
|
2157
|
-
let environmentsOptions = resolveEnvironmentsOptions(
|
|
2158
|
-
environmentOptionsResolvers,
|
|
2159
|
-
{ viteUserConfig }
|
|
2160
|
-
);
|
|
2161
|
-
await cleanBuildDirectory(viteConfig, ctx);
|
|
2162
|
-
await buildEnvironment("client");
|
|
2163
|
-
let serverEnvironmentNames = getServerEnvironmentKeys(
|
|
2164
|
-
ctx,
|
|
2165
|
-
environmentOptionsResolvers
|
|
2166
|
-
);
|
|
2167
|
-
await Promise.all(serverEnvironmentNames.map(buildEnvironment));
|
|
2168
|
-
await cleanViteManifests(environmentsOptions, ctx);
|
|
2169
|
-
await reactRouterConfig.buildEnd?.({
|
|
2170
|
-
buildManifest,
|
|
2171
|
-
reactRouterConfig,
|
|
2172
|
-
viteConfig
|
|
2173
|
-
});
|
|
2174
|
-
}
|
|
2175
|
-
var import_picocolors6;
|
|
2176
|
-
var init_build = __esm({
|
|
2177
|
-
"vite/build.ts"() {
|
|
2178
|
-
"use strict";
|
|
2179
|
-
import_picocolors6 = __toESM(require("picocolors"));
|
|
2180
|
-
init_config();
|
|
2181
|
-
init_plugin();
|
|
2182
|
-
init_invariant();
|
|
2183
|
-
init_vite();
|
|
2184
|
-
init_has_rsc_plugin();
|
|
2185
|
-
}
|
|
2186
|
-
});
|
|
2187
|
-
|
|
2188
|
-
// vite/dev.ts
|
|
2189
|
-
var dev_exports = {};
|
|
2190
|
-
__export(dev_exports, {
|
|
2191
|
-
dev: () => dev
|
|
2192
|
-
});
|
|
2193
|
-
async function dev(root, {
|
|
2194
|
-
clearScreen,
|
|
2195
|
-
config: configFile,
|
|
2196
|
-
cors,
|
|
2197
|
-
force,
|
|
2198
|
-
host,
|
|
2199
|
-
logLevel,
|
|
2200
|
-
mode,
|
|
2201
|
-
open,
|
|
2202
|
-
port,
|
|
2203
|
-
strictPort
|
|
2204
|
-
}) {
|
|
2205
|
-
await preloadVite();
|
|
2206
|
-
let vite2 = getVite();
|
|
2207
|
-
let server = await vite2.createServer({
|
|
2208
|
-
root,
|
|
2209
|
-
mode,
|
|
2210
|
-
configFile,
|
|
2211
|
-
server: { open, cors, host, port, strictPort },
|
|
2212
|
-
optimizeDeps: { force },
|
|
2213
|
-
clearScreen,
|
|
2214
|
-
logLevel
|
|
2215
|
-
});
|
|
2216
|
-
if (!server.config.plugins.find(
|
|
2217
|
-
(plugin) => plugin.name === "react-router" || plugin.name === "react-router/rsc"
|
|
2218
|
-
)) {
|
|
2219
|
-
console.error(
|
|
2220
|
-
import_picocolors7.default.red("React Router Vite plugin not found in Vite config")
|
|
2221
|
-
);
|
|
2222
|
-
process.exit(1);
|
|
2223
|
-
}
|
|
2224
|
-
await server.listen();
|
|
2225
|
-
server.printUrls();
|
|
2226
|
-
let customShortcuts = [
|
|
2227
|
-
{
|
|
2228
|
-
key: "p",
|
|
2229
|
-
description: "start/stop the profiler",
|
|
2230
|
-
async action(server2) {
|
|
2231
|
-
if (getSession()) {
|
|
2232
|
-
await stop(server2.config.logger.info);
|
|
2233
|
-
} else {
|
|
2234
|
-
await start(() => {
|
|
2235
|
-
server2.config.logger.info("Profiler started");
|
|
2236
|
-
});
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
2240
|
-
];
|
|
2241
|
-
server.bindCLIShortcuts({ print: true, customShortcuts });
|
|
2242
|
-
}
|
|
2243
|
-
var import_picocolors7;
|
|
2244
|
-
var init_dev = __esm({
|
|
2245
|
-
"vite/dev.ts"() {
|
|
2246
|
-
"use strict";
|
|
2247
|
-
import_picocolors7 = __toESM(require("picocolors"));
|
|
2248
|
-
init_vite();
|
|
2249
|
-
init_profiler();
|
|
2250
|
-
}
|
|
2251
|
-
});
|
|
2252
|
-
|
|
2253
|
-
// cli/run.ts
|
|
2254
|
-
var import_arg = __toESM(require("arg"));
|
|
2255
|
-
var import_semver = __toESM(require("semver"));
|
|
2256
|
-
var import_picocolors9 = __toESM(require("picocolors"));
|
|
2257
|
-
|
|
2258
|
-
// cli/commands.ts
|
|
2259
|
-
var import_node_fs4 = require("fs");
|
|
2260
|
-
var import_promises4 = require("fs/promises");
|
|
2261
|
-
var path9 = __toESM(require("path"));
|
|
2262
|
-
var import_exit_hook = __toESM(require("exit-hook"));
|
|
2263
|
-
var import_picocolors8 = __toESM(require("picocolors"));
|
|
2264
|
-
var import_react_router3 = require("react-router");
|
|
2265
|
-
init_config();
|
|
2266
|
-
|
|
2267
|
-
// config/format.ts
|
|
12
|
+
import { g as preloadVite, h as getVite, l as loadConfig, n as watch, t as run$1 } from "../typegen-BLMwBSoM.js";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import fs, { existsSync } from "node:fs";
|
|
15
|
+
import * as path$1 from "node:path";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import arg from "arg";
|
|
18
|
+
import semver from "semver";
|
|
19
|
+
import colors from "picocolors";
|
|
20
|
+
import { copyFile, readFile, writeFile } from "node:fs/promises";
|
|
21
|
+
import exitHook from "exit-hook";
|
|
22
|
+
import { readPackageJSON } from "pkg-types";
|
|
23
|
+
import "react-router";
|
|
24
|
+
import * as babel from "@babel/core";
|
|
25
|
+
import babelPluginSyntaxJSX from "@babel/plugin-syntax-jsx";
|
|
26
|
+
import babelPresetTypeScript from "@babel/preset-typescript";
|
|
27
|
+
import prettier from "prettier";
|
|
28
|
+
import packageJson from "@react-router/dev/package.json" with { type: "json" };
|
|
29
|
+
//#region config/format.ts
|
|
2268
30
|
function formatRoutes(routeManifest, format) {
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
return formatRoutesAsJsx(routeManifest);
|
|
2274
|
-
}
|
|
31
|
+
switch (format) {
|
|
32
|
+
case "json": return formatRoutesAsJson(routeManifest);
|
|
33
|
+
case "jsx": return formatRoutesAsJsx(routeManifest);
|
|
34
|
+
}
|
|
2275
35
|
}
|
|
2276
36
|
function formatRoutesAsJson(routeManifest) {
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
}
|
|
2292
|
-
if (children.length > 0) {
|
|
2293
|
-
return children;
|
|
2294
|
-
}
|
|
2295
|
-
return void 0;
|
|
2296
|
-
}
|
|
2297
|
-
return JSON.stringify(handleRoutesRecursive() || null, null, 2);
|
|
37
|
+
function handleRoutesRecursive(parentId) {
|
|
38
|
+
let routes = Object.values(routeManifest).filter((route) => route.parentId === parentId);
|
|
39
|
+
let children = [];
|
|
40
|
+
for (let route of routes) children.push({
|
|
41
|
+
id: route.id,
|
|
42
|
+
index: route.index,
|
|
43
|
+
path: route.path,
|
|
44
|
+
caseSensitive: route.caseSensitive,
|
|
45
|
+
file: route.file,
|
|
46
|
+
children: handleRoutesRecursive(route.id)
|
|
47
|
+
});
|
|
48
|
+
if (children.length > 0) return children;
|
|
49
|
+
}
|
|
50
|
+
return JSON.stringify(handleRoutesRecursive() || null, null, 2);
|
|
2298
51
|
}
|
|
2299
52
|
function formatRoutesAsJsx(routeManifest) {
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
return output;
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
// cli/useJavascript.ts
|
|
2324
|
-
var babel = __toESM(require("@babel/core"));
|
|
2325
|
-
var import_plugin_syntax_jsx = __toESM(require("@babel/plugin-syntax-jsx"));
|
|
2326
|
-
var import_preset_typescript = __toESM(require("@babel/preset-typescript"));
|
|
2327
|
-
var import_prettier = __toESM(require("prettier"));
|
|
53
|
+
let output = "<Routes>";
|
|
54
|
+
function handleRoutesRecursive(parentId, level = 1) {
|
|
55
|
+
let routes = Object.values(routeManifest).filter((route) => route.parentId === parentId);
|
|
56
|
+
let indent = Array(level * 2).fill(" ").join("");
|
|
57
|
+
for (let route of routes) {
|
|
58
|
+
output += "\n" + indent;
|
|
59
|
+
output += `<Route${route.path ? ` path=${JSON.stringify(route.path)}` : ""}${route.index ? " index" : ""}${route.file ? ` file=${JSON.stringify(route.file)}` : ""}>`;
|
|
60
|
+
if (handleRoutesRecursive(route.id, level + 1)) {
|
|
61
|
+
output += "\n" + indent;
|
|
62
|
+
output += "</Route>";
|
|
63
|
+
} else output = output.slice(0, -1) + " />";
|
|
64
|
+
}
|
|
65
|
+
return routes.length > 0;
|
|
66
|
+
}
|
|
67
|
+
handleRoutesRecursive();
|
|
68
|
+
output += "\n</Routes>";
|
|
69
|
+
return output;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region cli/useJavascript.ts
|
|
2328
73
|
async function transpile(tsx, options = {}) {
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
74
|
+
let mjs = babel.transformSync(tsx, {
|
|
75
|
+
compact: false,
|
|
76
|
+
cwd: options.cwd,
|
|
77
|
+
filename: options.filename,
|
|
78
|
+
plugins: [babelPluginSyntaxJSX],
|
|
79
|
+
presets: [[babelPresetTypeScript, { jsx: "preserve" }]],
|
|
80
|
+
retainLines: true
|
|
81
|
+
});
|
|
82
|
+
if (!mjs || !mjs.code) throw new Error("Could not parse TypeScript");
|
|
83
|
+
/**
|
|
84
|
+
* Babel's `compact` and `retainLines` options are both bad at formatting code.
|
|
85
|
+
* Use Prettier for nicer formatting.
|
|
86
|
+
*/
|
|
87
|
+
return await prettier.format(mjs.code, { parser: "babel" });
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region vite/profiler.ts
|
|
91
|
+
const getSession = () => global.__reactRouter_profile_session;
|
|
92
|
+
const start = async (callback) => {
|
|
93
|
+
let inspector = await import("node:inspector").then((r) => r.default);
|
|
94
|
+
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
95
|
+
session.connect();
|
|
96
|
+
session.post("Profiler.enable", () => {
|
|
97
|
+
session.post("Profiler.start", callback);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
let profileCount = 0;
|
|
101
|
+
const stop = (log) => {
|
|
102
|
+
let session = getSession();
|
|
103
|
+
if (!session) return;
|
|
104
|
+
return new Promise((res, rej) => {
|
|
105
|
+
session.post("Profiler.stop", (err, { profile }) => {
|
|
106
|
+
if (err) return rej(err);
|
|
107
|
+
let outPath = path.resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
108
|
+
fs.writeFileSync(outPath, JSON.stringify(profile));
|
|
109
|
+
log(colors.yellow(`CPU profile written to ${colors.white(colors.dim(outPath))}`));
|
|
110
|
+
global.__reactRouter_profile_session = void 0;
|
|
111
|
+
res();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region vite/has-rsc-plugin.ts
|
|
117
|
+
async function hasReactRouterRscPlugin({ root, viteBuildOptions: { config, logLevel, mode } }) {
|
|
118
|
+
await preloadVite();
|
|
119
|
+
return (await getVite().resolveConfig({
|
|
120
|
+
configFile: config,
|
|
121
|
+
logLevel,
|
|
122
|
+
mode: mode ?? "production",
|
|
123
|
+
root
|
|
124
|
+
}, "build", "production", "production")).plugins.some((plugin) => plugin?.name === "react-router/rsc");
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region cli/commands.ts
|
|
128
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
2346
129
|
async function routes(rootDirectory, flags = {}) {
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
}
|
|
2359
|
-
async function
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
}
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
130
|
+
rootDirectory = resolveRootDirectory(rootDirectory, flags);
|
|
131
|
+
let configResult = await loadConfig({
|
|
132
|
+
rootDirectory,
|
|
133
|
+
mode: flags.mode ?? "production"
|
|
134
|
+
});
|
|
135
|
+
if (!configResult.ok) {
|
|
136
|
+
console.error(colors.red(configResult.error));
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
let format = flags.json ? "json" : "jsx";
|
|
140
|
+
console.log(formatRoutes(configResult.value.routes, format));
|
|
141
|
+
}
|
|
142
|
+
async function build(root, options = {}) {
|
|
143
|
+
root = resolveRootDirectory(root, options);
|
|
144
|
+
let { build } = await import("../build-DM91F_L-.js");
|
|
145
|
+
if (options.profile) await start();
|
|
146
|
+
try {
|
|
147
|
+
await build(root, options);
|
|
148
|
+
} finally {
|
|
149
|
+
await stop(console.info);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function dev(root, options = {}) {
|
|
153
|
+
let { dev } = await import("../dev-CNEgIjT-.js");
|
|
154
|
+
if (options.profile) await start();
|
|
155
|
+
exitHook(() => stop(console.info));
|
|
156
|
+
root = resolveRootDirectory(root, options);
|
|
157
|
+
await dev(root, options);
|
|
158
|
+
await new Promise(() => {});
|
|
159
|
+
}
|
|
160
|
+
let clientEntries = [
|
|
161
|
+
"entry.client.tsx",
|
|
162
|
+
"entry.client.js",
|
|
163
|
+
"entry.client.jsx"
|
|
164
|
+
];
|
|
165
|
+
let serverEntries = [
|
|
166
|
+
"entry.server.tsx",
|
|
167
|
+
"entry.server.js",
|
|
168
|
+
"entry.server.jsx"
|
|
169
|
+
];
|
|
170
|
+
let entries = ["entry.client", "entry.server"];
|
|
171
|
+
let rscEntries = [
|
|
172
|
+
"entry.client",
|
|
173
|
+
"entry.rsc",
|
|
174
|
+
"entry.ssr"
|
|
175
|
+
];
|
|
176
|
+
let conjunctionListFormat = new Intl.ListFormat("en", {
|
|
177
|
+
style: "long",
|
|
178
|
+
type: "conjunction"
|
|
2389
179
|
});
|
|
2390
180
|
async function generateEntry(entry, rootDirectory, flags = {}) {
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
`entry.server.node.tsx`
|
|
2465
|
-
);
|
|
2466
|
-
let isServerEntry = entry === "entry.server";
|
|
2467
|
-
let contents = isServerEntry ? await createServerEntry(rootDirectory, appDirectory, defaultEntryServer) : await createClientEntry(
|
|
2468
|
-
rootDirectory,
|
|
2469
|
-
appDirectory,
|
|
2470
|
-
defaultEntryClient
|
|
2471
|
-
);
|
|
2472
|
-
let useTypeScript = flags.typescript ?? true;
|
|
2473
|
-
let outputExtension = useTypeScript ? "tsx" : "jsx";
|
|
2474
|
-
let outputEntry = `${entry}.${outputExtension}`;
|
|
2475
|
-
outputFile = path9.resolve(appDirectory, outputEntry);
|
|
2476
|
-
if (!useTypeScript) {
|
|
2477
|
-
let javascript = await transpile(contents, {
|
|
2478
|
-
cwd: rootDirectory,
|
|
2479
|
-
filename: isServerEntry ? defaultEntryServer : defaultEntryClient
|
|
2480
|
-
});
|
|
2481
|
-
await (0, import_promises4.writeFile)(outputFile, javascript, "utf-8");
|
|
2482
|
-
} else {
|
|
2483
|
-
await (0, import_promises4.writeFile)(outputFile, contents, "utf-8");
|
|
2484
|
-
}
|
|
2485
|
-
}
|
|
2486
|
-
console.log(
|
|
2487
|
-
import_picocolors8.default.blue(
|
|
2488
|
-
`Entry file ${entry} created at ${path9.relative(
|
|
2489
|
-
rootDirectory,
|
|
2490
|
-
outputFile
|
|
2491
|
-
)}.`
|
|
2492
|
-
)
|
|
2493
|
-
);
|
|
181
|
+
rootDirectory = resolveRootDirectory(rootDirectory, flags);
|
|
182
|
+
let configDir = "defaults";
|
|
183
|
+
let entriesToUse = entries;
|
|
184
|
+
let isRsc = false;
|
|
185
|
+
if (await hasReactRouterRscPlugin({
|
|
186
|
+
root: rootDirectory,
|
|
187
|
+
viteBuildOptions: {
|
|
188
|
+
config: flags.config,
|
|
189
|
+
mode: flags.mode
|
|
190
|
+
}
|
|
191
|
+
})) {
|
|
192
|
+
if (!entry) {
|
|
193
|
+
await generateEntry("entry.client", rootDirectory, flags);
|
|
194
|
+
await generateEntry("entry.rsc", rootDirectory, flags);
|
|
195
|
+
await generateEntry("entry.ssr", rootDirectory, flags);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
configDir = "default-rsc-entries";
|
|
199
|
+
entriesToUse = rscEntries;
|
|
200
|
+
isRsc = true;
|
|
201
|
+
}
|
|
202
|
+
if (!entry) {
|
|
203
|
+
await generateEntry("entry.client", rootDirectory, flags);
|
|
204
|
+
await generateEntry("entry.server", rootDirectory, flags);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
let configResult = await loadConfig({
|
|
208
|
+
rootDirectory,
|
|
209
|
+
mode: flags.mode ?? "production"
|
|
210
|
+
});
|
|
211
|
+
if (!configResult.ok) {
|
|
212
|
+
console.error(colors.red(configResult.error));
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
let appDirectory = configResult.value.appDirectory;
|
|
216
|
+
if (!entriesToUse.includes(entry)) {
|
|
217
|
+
let entriesArray = Array.from(entriesToUse);
|
|
218
|
+
let list = conjunctionListFormat.format(entriesArray);
|
|
219
|
+
console.error(colors.red(`Invalid entry file. Valid entry files are ${list}`));
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
let defaultsDirectory = path$1.resolve(path$1.dirname(nodeRequire.resolve("@react-router/dev/package.json")), "dist", "config", configDir);
|
|
223
|
+
let outputFile;
|
|
224
|
+
if (isRsc) {
|
|
225
|
+
let defaultEntry = path$1.resolve(defaultsDirectory, `${entry}.tsx`);
|
|
226
|
+
outputFile = path$1.resolve(appDirectory, `${entry}.tsx`);
|
|
227
|
+
if (existsSync(outputFile)) {
|
|
228
|
+
let relative = path$1.relative(rootDirectory, outputFile);
|
|
229
|
+
console.error(colors.red(`Entry file ${relative} already exists.`));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
await copyFile(defaultEntry, outputFile);
|
|
233
|
+
} else {
|
|
234
|
+
if (!((await readPackageJSON(rootDirectory)).dependencies ?? {})["@react-router/node"]) {
|
|
235
|
+
console.error(colors.red(`No default server entry detected.`));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
let defaultEntryClient = path$1.resolve(defaultsDirectory, "entry.client.tsx");
|
|
239
|
+
let defaultEntryServer = path$1.resolve(defaultsDirectory, `entry.server.node.tsx`);
|
|
240
|
+
let isServerEntry = entry === "entry.server";
|
|
241
|
+
let contents = isServerEntry ? await createServerEntry(rootDirectory, appDirectory, defaultEntryServer) : await createClientEntry(rootDirectory, appDirectory, defaultEntryClient);
|
|
242
|
+
let useTypeScript = flags.typescript ?? true;
|
|
243
|
+
let outputEntry = `${entry}.${useTypeScript ? "tsx" : "jsx"}`;
|
|
244
|
+
outputFile = path$1.resolve(appDirectory, outputEntry);
|
|
245
|
+
if (!useTypeScript) {
|
|
246
|
+
let javascript = await transpile(contents, {
|
|
247
|
+
cwd: rootDirectory,
|
|
248
|
+
filename: isServerEntry ? defaultEntryServer : defaultEntryClient
|
|
249
|
+
});
|
|
250
|
+
await writeFile(outputFile, javascript, "utf-8");
|
|
251
|
+
} else await writeFile(outputFile, contents, "utf-8");
|
|
252
|
+
}
|
|
253
|
+
console.log(colors.blue(`Entry file ${entry} created at ${path$1.relative(rootDirectory, outputFile)}.`));
|
|
2494
254
|
}
|
|
2495
255
|
function resolveRootDirectory(root, flags) {
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
return process.exit(1);
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
256
|
+
if (root) return path$1.resolve(root);
|
|
257
|
+
return process.env.REACT_ROUTER_ROOT || (flags?.config ? path$1.dirname(path$1.resolve(flags.config)) : process.cwd());
|
|
258
|
+
}
|
|
259
|
+
async function checkForEntry(rootDirectory, appDirectory, entries) {
|
|
260
|
+
for (let entry of entries) {
|
|
261
|
+
let entryPath = path$1.resolve(appDirectory, entry);
|
|
262
|
+
if (existsSync(entryPath)) {
|
|
263
|
+
let relative = path$1.relative(rootDirectory, entryPath);
|
|
264
|
+
console.error(colors.red(`Entry file ${relative} already exists.`));
|
|
265
|
+
return process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
2511
268
|
}
|
|
2512
269
|
async function createServerEntry(rootDirectory, appDirectory, inputFile) {
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
return contents;
|
|
270
|
+
await checkForEntry(rootDirectory, appDirectory, serverEntries);
|
|
271
|
+
return await readFile(inputFile, "utf-8");
|
|
2516
272
|
}
|
|
2517
273
|
async function createClientEntry(rootDirectory, appDirectory, inputFile) {
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
return contents;
|
|
274
|
+
await checkForEntry(rootDirectory, appDirectory, clientEntries);
|
|
275
|
+
return await readFile(inputFile, "utf-8");
|
|
2521
276
|
}
|
|
2522
277
|
async function typegen(root, flags) {
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
${
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
$ react-router
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
${import_picocolors9.default.underline("Options")}:
|
|
278
|
+
root = resolveRootDirectory(root, flags);
|
|
279
|
+
const rsc = await hasReactRouterRscPlugin({
|
|
280
|
+
root,
|
|
281
|
+
viteBuildOptions: {
|
|
282
|
+
config: flags.config,
|
|
283
|
+
mode: flags.mode
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
if (flags.watch) {
|
|
287
|
+
await preloadVite();
|
|
288
|
+
const logger = getVite().createLogger("info", { prefix: "[react-router]" });
|
|
289
|
+
await watch(root, {
|
|
290
|
+
mode: flags.mode ?? "development",
|
|
291
|
+
rsc,
|
|
292
|
+
logger
|
|
293
|
+
});
|
|
294
|
+
await new Promise(() => {});
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
await run$1(root, {
|
|
298
|
+
mode: flags.mode ?? "production",
|
|
299
|
+
rsc
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region cli/run.ts
|
|
304
|
+
const helpText = `
|
|
305
|
+
${colors.blueBright("react-router")}
|
|
306
|
+
|
|
307
|
+
${colors.underline("Usage")}:
|
|
308
|
+
$ react-router build [${colors.yellowBright("projectDir")}]
|
|
309
|
+
$ react-router dev [${colors.yellowBright("projectDir")}]
|
|
310
|
+
$ react-router routes [${colors.yellowBright("projectDir")}]
|
|
311
|
+
|
|
312
|
+
${colors.underline("Options")}:
|
|
2560
313
|
--help, -h Print this help message and exit
|
|
2561
314
|
--version, -v Print the CLI version and exit
|
|
2562
315
|
--no-color Disable ANSI colors in console output
|
|
@@ -2592,22 +345,22 @@ ${import_picocolors9.default.blueBright("react-router")}
|
|
|
2592
345
|
\`typegen\` Options:
|
|
2593
346
|
--watch Automatically regenerate types whenever route config (\`routes.ts\`) or route modules change
|
|
2594
347
|
|
|
2595
|
-
${
|
|
348
|
+
${colors.underline("Build your project")}:
|
|
2596
349
|
|
|
2597
350
|
$ react-router build
|
|
2598
351
|
|
|
2599
|
-
${
|
|
352
|
+
${colors.underline("Run your project locally in development")}:
|
|
2600
353
|
|
|
2601
354
|
$ react-router dev
|
|
2602
355
|
|
|
2603
|
-
${
|
|
356
|
+
${colors.underline("Show all routes in your app")}:
|
|
2604
357
|
|
|
2605
358
|
$ react-router routes
|
|
2606
359
|
$ react-router routes my-app
|
|
2607
360
|
$ react-router routes --json
|
|
2608
361
|
$ react-router routes --config vite.react-router.config.ts
|
|
2609
362
|
|
|
2610
|
-
${
|
|
363
|
+
${colors.underline("Reveal the used entry point")}:
|
|
2611
364
|
|
|
2612
365
|
$ react-router reveal entry.client
|
|
2613
366
|
$ react-router reveal entry.server
|
|
@@ -2615,109 +368,96 @@ ${import_picocolors9.default.blueBright("react-router")}
|
|
|
2615
368
|
$ react-router reveal entry.server --no-typescript
|
|
2616
369
|
$ react-router reveal entry.server --config vite.react-router.config.ts
|
|
2617
370
|
|
|
2618
|
-
${
|
|
371
|
+
${colors.underline("Generate types for route modules")}:
|
|
2619
372
|
|
|
2620
373
|
$ react-router typegen
|
|
2621
374
|
$ react-router typegen --watch
|
|
2622
375
|
`;
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
// cli/index.ts
|
|
2715
|
-
run2().then(
|
|
2716
|
-
() => {
|
|
2717
|
-
process.exit(0);
|
|
2718
|
-
},
|
|
2719
|
-
(error) => {
|
|
2720
|
-
if (error) console.error(error);
|
|
2721
|
-
process.exit(1);
|
|
2722
|
-
}
|
|
2723
|
-
);
|
|
376
|
+
/**
|
|
377
|
+
* Programmatic interface for running the react-router CLI with the given command line
|
|
378
|
+
* arguments.
|
|
379
|
+
*/
|
|
380
|
+
async function run(argv = process.argv.slice(2), { isMain = false } = {}) {
|
|
381
|
+
let versions = process.versions;
|
|
382
|
+
let MINIMUM_NODE_VERSION = "22.12.0";
|
|
383
|
+
if (versions && versions.node && semver.lt(versions.node, MINIMUM_NODE_VERSION)) console.warn(`️⚠️ Oops, Node v${versions.node} detected. react-router requires a Node version greater than ${MINIMUM_NODE_VERSION}.`);
|
|
384
|
+
let isBooleanFlag = (arg) => {
|
|
385
|
+
let nextArg = argv[argv.indexOf(arg) + 1];
|
|
386
|
+
return !nextArg || nextArg.startsWith("-");
|
|
387
|
+
};
|
|
388
|
+
let args = arg({
|
|
389
|
+
"--force": Boolean,
|
|
390
|
+
"--help": Boolean,
|
|
391
|
+
"-h": "--help",
|
|
392
|
+
"--json": Boolean,
|
|
393
|
+
"--token": String,
|
|
394
|
+
"--typescript": Boolean,
|
|
395
|
+
"--no-typescript": Boolean,
|
|
396
|
+
"--version": Boolean,
|
|
397
|
+
"-v": "--version",
|
|
398
|
+
"--port": Number,
|
|
399
|
+
"-p": "--port",
|
|
400
|
+
"--config": String,
|
|
401
|
+
"-c": "--config",
|
|
402
|
+
"--assetsInlineLimit": Number,
|
|
403
|
+
"--clearScreen": Boolean,
|
|
404
|
+
"--cors": Boolean,
|
|
405
|
+
"--emptyOutDir": Boolean,
|
|
406
|
+
"--host": isBooleanFlag("--host") ? Boolean : String,
|
|
407
|
+
"--logLevel": String,
|
|
408
|
+
"-l": "--logLevel",
|
|
409
|
+
"--minify": String,
|
|
410
|
+
"--mode": String,
|
|
411
|
+
"-m": "--mode",
|
|
412
|
+
"--open": isBooleanFlag("--open") ? Boolean : String,
|
|
413
|
+
"--strictPort": Boolean,
|
|
414
|
+
"--profile": Boolean,
|
|
415
|
+
"--sourcemapClient": isBooleanFlag("--sourcemapClient") ? Boolean : String,
|
|
416
|
+
"--sourcemapServer": isBooleanFlag("--sourcemapServer") ? Boolean : String,
|
|
417
|
+
"--watch": Boolean
|
|
418
|
+
}, { argv });
|
|
419
|
+
let input = args._;
|
|
420
|
+
let flags = Object.entries(args).reduce((acc, [key, value]) => {
|
|
421
|
+
key = key.replace(/^--/, "");
|
|
422
|
+
acc[key] = value;
|
|
423
|
+
return acc;
|
|
424
|
+
}, {});
|
|
425
|
+
if (flags.help) {
|
|
426
|
+
console.log(helpText);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (flags.version) {
|
|
430
|
+
console.log(packageJson.version);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
flags.interactive = flags.interactive ?? isMain;
|
|
434
|
+
if (args["--no-typescript"]) flags.typescript = false;
|
|
435
|
+
switch (input[0]) {
|
|
436
|
+
case "routes":
|
|
437
|
+
await routes(input[1], flags);
|
|
438
|
+
break;
|
|
439
|
+
case "build":
|
|
440
|
+
await build(input[1], flags);
|
|
441
|
+
break;
|
|
442
|
+
case "reveal":
|
|
443
|
+
await generateEntry(input[1], input[2], flags);
|
|
444
|
+
break;
|
|
445
|
+
case "dev":
|
|
446
|
+
await dev(input[1], flags);
|
|
447
|
+
break;
|
|
448
|
+
case "typegen":
|
|
449
|
+
await typegen(input[1], flags);
|
|
450
|
+
break;
|
|
451
|
+
default: await dev(input[0], flags);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region cli/index.ts
|
|
456
|
+
run(void 0, { isMain: true }).then(() => {
|
|
457
|
+
process.exit(0);
|
|
458
|
+
}, (error) => {
|
|
459
|
+
if (error) console.error(error);
|
|
460
|
+
process.exit(1);
|
|
461
|
+
});
|
|
462
|
+
//#endregion
|
|
463
|
+
export { start as n, stop as r, getSession as t };
|