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