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