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