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