@react-router/dev 7.0.0-pre.5 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -199
- package/dist/cli/index.js +749 -444
- package/dist/config.d.ts +164 -0
- package/dist/config.js +28 -0
- package/dist/routes.js +7 -7
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.d.ts +3 -161
- package/dist/vite.js +1088 -823
- package/package.json +13 -8
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.0.0
|
|
2
|
+
* @react-router/dev v7.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -48,13 +48,28 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
48
48
|
var import_node_crypto = require("crypto");
|
|
49
49
|
var path4 = __toESM(require("path"));
|
|
50
50
|
var url2 = __toESM(require("url"));
|
|
51
|
-
var
|
|
51
|
+
var fse = __toESM(require("fs-extra"));
|
|
52
52
|
var babel = __toESM(require("@babel/core"));
|
|
53
53
|
var import_react_router2 = require("react-router");
|
|
54
54
|
var import_es_module_lexer = require("es-module-lexer");
|
|
55
55
|
var import_jsesc = __toESM(require("jsesc"));
|
|
56
|
+
var import_picocolors3 = __toESM(require("picocolors"));
|
|
57
|
+
|
|
58
|
+
// typegen/index.ts
|
|
59
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
60
|
+
var Path4 = __toESM(require("pathe"));
|
|
56
61
|
var import_picocolors2 = __toESM(require("picocolors"));
|
|
57
62
|
|
|
63
|
+
// config/config.ts
|
|
64
|
+
var import_node_fs = __toESM(require("fs"));
|
|
65
|
+
var import_node_child_process = require("child_process");
|
|
66
|
+
var import_package_json = __toESM(require("@npmcli/package-json"));
|
|
67
|
+
|
|
68
|
+
// vite/vite-node.ts
|
|
69
|
+
var import_server = require("vite-node/server");
|
|
70
|
+
var import_client = require("vite-node/client");
|
|
71
|
+
var import_source_map = require("vite-node/source-map");
|
|
72
|
+
|
|
58
73
|
// invariant.ts
|
|
59
74
|
function invariant(value, message) {
|
|
60
75
|
if (value === false || value === null || typeof value === "undefined") {
|
|
@@ -65,82 +80,6 @@ function invariant(value, message) {
|
|
|
65
80
|
}
|
|
66
81
|
}
|
|
67
82
|
|
|
68
|
-
// vite/babel.ts
|
|
69
|
-
var import_parser = require("@babel/parser");
|
|
70
|
-
var t = __toESM(require("@babel/types"));
|
|
71
|
-
var traverse = require("@babel/traverse").default;
|
|
72
|
-
var generate = require("@babel/generator").default;
|
|
73
|
-
|
|
74
|
-
// vite/node-adapter.ts
|
|
75
|
-
var import_node_events = require("events");
|
|
76
|
-
var import_node_stream = require("stream");
|
|
77
|
-
var import_set_cookie_parser = require("set-cookie-parser");
|
|
78
|
-
var import_node = require("@react-router/node");
|
|
79
|
-
function fromNodeHeaders(nodeHeaders) {
|
|
80
|
-
let headers = new Headers();
|
|
81
|
-
for (let [key, values] of Object.entries(nodeHeaders)) {
|
|
82
|
-
if (values) {
|
|
83
|
-
if (Array.isArray(values)) {
|
|
84
|
-
for (let value of values) {
|
|
85
|
-
headers.append(key, value);
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
headers.set(key, values);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return headers;
|
|
93
|
-
}
|
|
94
|
-
function fromNodeRequest(nodeReq, nodeRes) {
|
|
95
|
-
let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `http://${nodeReq.headers.host}`;
|
|
96
|
-
invariant(
|
|
97
|
-
nodeReq.originalUrl,
|
|
98
|
-
"Expected `nodeReq.originalUrl` to be defined"
|
|
99
|
-
);
|
|
100
|
-
let url3 = new URL(nodeReq.originalUrl, origin);
|
|
101
|
-
let controller = new AbortController();
|
|
102
|
-
let init = {
|
|
103
|
-
method: nodeReq.method,
|
|
104
|
-
headers: fromNodeHeaders(nodeReq.headers),
|
|
105
|
-
signal: controller.signal
|
|
106
|
-
};
|
|
107
|
-
nodeRes.on("finish", () => controller = null);
|
|
108
|
-
nodeRes.on("close", () => controller?.abort());
|
|
109
|
-
if (nodeReq.method !== "GET" && nodeReq.method !== "HEAD") {
|
|
110
|
-
init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
|
|
111
|
-
init.duplex = "half";
|
|
112
|
-
}
|
|
113
|
-
return new Request(url3.href, init);
|
|
114
|
-
}
|
|
115
|
-
async function toNodeRequest(res, nodeRes) {
|
|
116
|
-
nodeRes.statusCode = res.status;
|
|
117
|
-
nodeRes.statusMessage = res.statusText;
|
|
118
|
-
let cookiesStrings = [];
|
|
119
|
-
for (let [name, value] of res.headers) {
|
|
120
|
-
if (name === "set-cookie") {
|
|
121
|
-
cookiesStrings.push(...(0, import_set_cookie_parser.splitCookiesString)(value));
|
|
122
|
-
} else nodeRes.setHeader(name, value);
|
|
123
|
-
}
|
|
124
|
-
if (cookiesStrings.length) {
|
|
125
|
-
nodeRes.setHeader("set-cookie", cookiesStrings);
|
|
126
|
-
}
|
|
127
|
-
if (res.body) {
|
|
128
|
-
let responseBody = res.body;
|
|
129
|
-
let readable = import_node_stream.Readable.from(responseBody);
|
|
130
|
-
readable.pipe(nodeRes);
|
|
131
|
-
await (0, import_node_events.once)(readable, "end");
|
|
132
|
-
} else {
|
|
133
|
-
nodeRes.end();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// vite/styles.ts
|
|
138
|
-
var path2 = __toESM(require("path"));
|
|
139
|
-
var import_react_router = require("react-router");
|
|
140
|
-
|
|
141
|
-
// vite/resolve-file-url.ts
|
|
142
|
-
var path = __toESM(require("path"));
|
|
143
|
-
|
|
144
83
|
// vite/import-vite-esm-sync.ts
|
|
145
84
|
var vite;
|
|
146
85
|
async function preloadViteEsm() {
|
|
@@ -151,464 +90,241 @@ function importViteEsmSync() {
|
|
|
151
90
|
return vite;
|
|
152
91
|
}
|
|
153
92
|
|
|
154
|
-
// vite/
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
93
|
+
// vite/vite-node.ts
|
|
94
|
+
async function createContext(viteConfig = {}) {
|
|
95
|
+
await preloadViteEsm();
|
|
96
|
+
const vite2 = importViteEsmSync();
|
|
97
|
+
const devServer = await vite2.createServer(
|
|
98
|
+
vite2.mergeConfig(
|
|
99
|
+
{
|
|
100
|
+
server: {
|
|
101
|
+
preTransformRequests: false,
|
|
102
|
+
hmr: false
|
|
103
|
+
},
|
|
104
|
+
optimizeDeps: {
|
|
105
|
+
noDiscovery: true
|
|
106
|
+
},
|
|
107
|
+
configFile: false,
|
|
108
|
+
envFile: false,
|
|
109
|
+
plugins: []
|
|
110
|
+
},
|
|
111
|
+
viteConfig
|
|
112
|
+
)
|
|
113
|
+
);
|
|
114
|
+
await devServer.pluginContainer.buildStart({});
|
|
115
|
+
const server = new import_server.ViteNodeServer(devServer);
|
|
116
|
+
(0, import_source_map.installSourcemapsSupport)({
|
|
117
|
+
getSourceMap: (source) => server.getSourceMap(source)
|
|
118
|
+
});
|
|
119
|
+
const runner = new import_client.ViteNodeRunner({
|
|
120
|
+
root: devServer.config.root,
|
|
121
|
+
base: devServer.config.base,
|
|
122
|
+
fetchModule(id2) {
|
|
123
|
+
return server.fetchModule(id2);
|
|
124
|
+
},
|
|
125
|
+
resolveId(id2, importer) {
|
|
126
|
+
return server.resolveId(id2, importer);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return { devServer, server, runner };
|
|
130
|
+
}
|
|
164
131
|
|
|
165
|
-
//
|
|
166
|
-
var
|
|
167
|
-
var
|
|
168
|
-
var
|
|
169
|
-
var
|
|
170
|
-
var
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
132
|
+
// config/config.ts
|
|
133
|
+
var import_pathe = __toESM(require("pathe"));
|
|
134
|
+
var import_chokidar = __toESM(require("chokidar"));
|
|
135
|
+
var import_picocolors = __toESM(require("picocolors"));
|
|
136
|
+
var import_pick2 = __toESM(require("lodash/pick"));
|
|
137
|
+
var import_omit = __toESM(require("lodash/omit"));
|
|
138
|
+
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
139
|
+
var import_isEqual = __toESM(require("lodash/isEqual"));
|
|
140
|
+
|
|
141
|
+
// config/routes.ts
|
|
142
|
+
var Path = __toESM(require("pathe"));
|
|
143
|
+
var v = __toESM(require("valibot"));
|
|
144
|
+
var import_pick = __toESM(require("lodash/pick"));
|
|
145
|
+
function setAppDirectory(directory) {
|
|
146
|
+
globalThis.__reactRouterAppDirectory = directory;
|
|
147
|
+
}
|
|
148
|
+
var routeConfigEntrySchema = v.pipe(
|
|
149
|
+
v.custom((value) => {
|
|
150
|
+
return !(typeof value === "object" && value !== null && "then" in value && "catch" in value);
|
|
151
|
+
}, "Invalid type: Expected object but received a promise. Did you forget to await?"),
|
|
152
|
+
v.object({
|
|
153
|
+
id: v.optional(v.string()),
|
|
154
|
+
path: v.optional(v.string()),
|
|
155
|
+
index: v.optional(v.boolean()),
|
|
156
|
+
caseSensitive: v.optional(v.boolean()),
|
|
157
|
+
file: v.string(),
|
|
158
|
+
children: v.optional(v.array(v.lazy(() => routeConfigEntrySchema)))
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
var resolvedRouteConfigSchema = v.array(routeConfigEntrySchema);
|
|
162
|
+
function validateRouteConfig({
|
|
163
|
+
routeConfigFile,
|
|
164
|
+
routeConfig
|
|
165
|
+
}) {
|
|
166
|
+
if (!routeConfig) {
|
|
167
|
+
return {
|
|
168
|
+
valid: false,
|
|
169
|
+
message: `Route config must be the default export in "${routeConfigFile}".`
|
|
170
|
+
};
|
|
175
171
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
172
|
+
if (!Array.isArray(routeConfig)) {
|
|
173
|
+
return {
|
|
174
|
+
valid: false,
|
|
175
|
+
message: `Route config in "${routeConfigFile}" must be an array.`
|
|
176
|
+
};
|
|
184
177
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (!node) {
|
|
200
|
-
try {
|
|
201
|
-
await viteDevServer.transformRequest(
|
|
202
|
-
resolveFileUrl({ rootDirectory }, normalizedPath)
|
|
203
|
-
);
|
|
204
|
-
} catch (err) {
|
|
205
|
-
console.error(err);
|
|
206
|
-
}
|
|
207
|
-
node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
208
|
-
}
|
|
209
|
-
if (!node) {
|
|
210
|
-
console.log(`Could not resolve module for file: ${file}`);
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
await findDeps(viteDevServer, node, deps);
|
|
214
|
-
}
|
|
215
|
-
} catch (err) {
|
|
216
|
-
console.error(err);
|
|
178
|
+
let { issues } = v.safeParse(resolvedRouteConfigSchema, routeConfig);
|
|
179
|
+
if (issues?.length) {
|
|
180
|
+
let { root, nested } = v.flatten(issues);
|
|
181
|
+
return {
|
|
182
|
+
valid: false,
|
|
183
|
+
message: [
|
|
184
|
+
`Route config in "${routeConfigFile}" is invalid.`,
|
|
185
|
+
root ? `${root}` : [],
|
|
186
|
+
nested ? Object.entries(nested).map(
|
|
187
|
+
([path5, message]) => `Path: routes.${path5}
|
|
188
|
+
${message}`
|
|
189
|
+
) : []
|
|
190
|
+
].flat().join("\n\n")
|
|
191
|
+
};
|
|
217
192
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
193
|
+
return { valid: true };
|
|
194
|
+
}
|
|
195
|
+
function configRoutesToRouteManifest(appDirectory, routes, rootId = "root") {
|
|
196
|
+
let routeManifest = {};
|
|
197
|
+
function walk(route, parentId) {
|
|
198
|
+
let id2 = route.id || createRouteId(route.file);
|
|
199
|
+
let manifestItem = {
|
|
200
|
+
id: id2,
|
|
201
|
+
parentId,
|
|
202
|
+
file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
|
|
203
|
+
path: route.path,
|
|
204
|
+
index: route.index,
|
|
205
|
+
caseSensitive: route.caseSensitive
|
|
206
|
+
};
|
|
207
|
+
if (routeManifest.hasOwnProperty(id2)) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Unable to define routes with duplicate route id: "${id2}"`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
routeManifest[id2] = manifestItem;
|
|
213
|
+
if (route.children) {
|
|
214
|
+
for (let child of route.children) {
|
|
215
|
+
walk(child, id2);
|
|
228
216
|
}
|
|
229
217
|
}
|
|
230
218
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
/* ${fileName.replace(/\/\*/g, "/\\*").replace(/\*\//g, "*\\/")} */`,
|
|
234
|
-
css
|
|
235
|
-
]).flat().join("\n") || void 0;
|
|
236
|
-
};
|
|
237
|
-
var findDeps = async (vite2, node, deps) => {
|
|
238
|
-
let branches = [];
|
|
239
|
-
async function addFromNode(node2) {
|
|
240
|
-
if (!deps.has(node2)) {
|
|
241
|
-
deps.add(node2);
|
|
242
|
-
await findDeps(vite2, node2, deps);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
async function addFromUrl(url3) {
|
|
246
|
-
let node2 = await vite2.moduleGraph.getModuleByUrl(url3);
|
|
247
|
-
if (node2) {
|
|
248
|
-
await addFromNode(node2);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
if (node.ssrTransformResult) {
|
|
252
|
-
if (node.ssrTransformResult.deps) {
|
|
253
|
-
node.ssrTransformResult.deps.forEach(
|
|
254
|
-
(url3) => branches.push(addFromUrl(url3))
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
} else {
|
|
258
|
-
node.importedModules.forEach((node2) => branches.push(addFromNode(node2)));
|
|
219
|
+
for (let route of routes) {
|
|
220
|
+
walk(route, rootId);
|
|
259
221
|
}
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
var getStylesForUrl = async ({
|
|
282
|
-
viteDevServer,
|
|
283
|
-
rootDirectory,
|
|
284
|
-
reactRouterConfig,
|
|
285
|
-
entryClientFilePath,
|
|
286
|
-
cssModulesManifest,
|
|
287
|
-
build,
|
|
288
|
-
url: url3
|
|
289
|
-
}) => {
|
|
290
|
-
if (url3 === void 0 || url3.includes("?_data=")) {
|
|
222
|
+
return routeManifest;
|
|
223
|
+
}
|
|
224
|
+
function createRouteId(file) {
|
|
225
|
+
return Path.normalize(stripFileExtension(file));
|
|
226
|
+
}
|
|
227
|
+
function stripFileExtension(file) {
|
|
228
|
+
return file.replace(/\.[a-z0-9]+$/i, "");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// cli/detectPackageManager.ts
|
|
232
|
+
var detectPackageManager = () => {
|
|
233
|
+
let { npm_config_user_agent } = process.env;
|
|
234
|
+
if (!npm_config_user_agent) return void 0;
|
|
235
|
+
try {
|
|
236
|
+
let pkgManager = npm_config_user_agent.split("/")[0];
|
|
237
|
+
if (pkgManager === "npm") return "npm";
|
|
238
|
+
if (pkgManager === "pnpm") return "pnpm";
|
|
239
|
+
if (pkgManager === "yarn") return "yarn";
|
|
240
|
+
if (pkgManager === "bun") return "bun";
|
|
241
|
+
return void 0;
|
|
242
|
+
} catch {
|
|
291
243
|
return void 0;
|
|
292
244
|
}
|
|
293
|
-
let routes = createRoutes(build.routes);
|
|
294
|
-
let appPath = path2.relative(process.cwd(), reactRouterConfig.appDirectory);
|
|
295
|
-
let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url3, build.basename)?.map(
|
|
296
|
-
(match) => path2.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
|
|
297
|
-
) ?? [];
|
|
298
|
-
let styles = await getStylesForFiles({
|
|
299
|
-
viteDevServer,
|
|
300
|
-
rootDirectory,
|
|
301
|
-
cssModulesManifest,
|
|
302
|
-
files: [
|
|
303
|
-
// Always include the client entry file when crawling the module graph for CSS
|
|
304
|
-
path2.relative(rootDirectory, entryClientFilePath),
|
|
305
|
-
// Then include any styles from the matched routes
|
|
306
|
-
...documentRouteFiles
|
|
307
|
-
]
|
|
308
|
-
});
|
|
309
|
-
return styles;
|
|
310
245
|
};
|
|
311
246
|
|
|
312
|
-
//
|
|
313
|
-
var
|
|
314
|
-
var
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
let exportsFiltered = false;
|
|
327
|
-
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
328
|
-
traverse(ast, {
|
|
329
|
-
ExportDeclaration(path5) {
|
|
330
|
-
if (path5.node.type === "ExportNamedDeclaration") {
|
|
331
|
-
if (path5.node.specifiers.length) {
|
|
332
|
-
path5.node.specifiers = path5.node.specifiers.filter((specifier) => {
|
|
333
|
-
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
334
|
-
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
335
|
-
exportsFiltered = true;
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return true;
|
|
340
|
-
});
|
|
341
|
-
if (path5.node.specifiers.length === 0) {
|
|
342
|
-
markedForRemoval.add(path5);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if (path5.node.declaration?.type === "VariableDeclaration") {
|
|
346
|
-
let declaration = path5.node.declaration;
|
|
347
|
-
declaration.declarations = declaration.declarations.filter(
|
|
348
|
-
(declaration2) => {
|
|
349
|
-
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
350
|
-
exportsFiltered = true;
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
if (declaration2.id.type === "ArrayPattern" || declaration2.id.type === "ObjectPattern") {
|
|
354
|
-
validateDestructuredExports(declaration2.id, exportsToRemove);
|
|
355
|
-
}
|
|
356
|
-
return true;
|
|
357
|
-
}
|
|
358
|
-
);
|
|
359
|
-
if (declaration.declarations.length === 0) {
|
|
360
|
-
markedForRemoval.add(path5);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
if (path5.node.declaration?.type === "FunctionDeclaration") {
|
|
364
|
-
let id2 = path5.node.declaration.id;
|
|
365
|
-
if (id2 && exportsToRemove.includes(id2.name)) {
|
|
366
|
-
markedForRemoval.add(path5);
|
|
367
|
-
}
|
|
247
|
+
// config/config.ts
|
|
248
|
+
var excludedConfigPresetKeys = ["presets"];
|
|
249
|
+
var mergeReactRouterConfig = (...configs) => {
|
|
250
|
+
let reducer = (configA, configB) => {
|
|
251
|
+
let mergeRequired = (key) => configA[key] !== void 0 && configB[key] !== void 0;
|
|
252
|
+
return {
|
|
253
|
+
...configA,
|
|
254
|
+
...configB,
|
|
255
|
+
...mergeRequired("buildEnd") ? {
|
|
256
|
+
buildEnd: async (...args) => {
|
|
257
|
+
await Promise.all([
|
|
258
|
+
configA.buildEnd?.(...args),
|
|
259
|
+
configB.buildEnd?.(...args)
|
|
260
|
+
]);
|
|
368
261
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
262
|
+
} : {},
|
|
263
|
+
...mergeRequired("future") ? {
|
|
264
|
+
future: {
|
|
265
|
+
...configA.future,
|
|
266
|
+
...configB.future
|
|
374
267
|
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
268
|
+
} : {},
|
|
269
|
+
...mergeRequired("presets") ? {
|
|
270
|
+
presets: [...configA.presets ?? [], ...configB.presets ?? []]
|
|
271
|
+
} : {}
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
return configs.reduce(reducer, {});
|
|
275
|
+
};
|
|
276
|
+
var deepFreeze = (o) => {
|
|
277
|
+
Object.freeze(o);
|
|
278
|
+
let oIsFunction = typeof o === "function";
|
|
279
|
+
let hasOwnProp = Object.prototype.hasOwnProperty;
|
|
280
|
+
Object.getOwnPropertyNames(o).forEach(function(prop) {
|
|
281
|
+
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])) {
|
|
282
|
+
deepFreeze(o[prop]);
|
|
379
283
|
}
|
|
380
284
|
});
|
|
381
|
-
|
|
382
|
-
for (let path5 of markedForRemoval) {
|
|
383
|
-
path5.remove();
|
|
384
|
-
}
|
|
385
|
-
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
386
|
-
}
|
|
285
|
+
return o;
|
|
387
286
|
};
|
|
388
|
-
function
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
287
|
+
function ok(value) {
|
|
288
|
+
return { ok: true, value };
|
|
289
|
+
}
|
|
290
|
+
function err(error) {
|
|
291
|
+
return { ok: false, error };
|
|
292
|
+
}
|
|
293
|
+
async function resolveConfig({
|
|
294
|
+
root,
|
|
295
|
+
viteNodeContext,
|
|
296
|
+
reactRouterConfigFile
|
|
297
|
+
}) {
|
|
298
|
+
let reactRouterUserConfig = {};
|
|
299
|
+
if (reactRouterConfigFile) {
|
|
300
|
+
try {
|
|
301
|
+
if (!import_node_fs.default.existsSync(reactRouterConfigFile)) {
|
|
302
|
+
return err(`${reactRouterConfigFile} no longer exists`);
|
|
396
303
|
}
|
|
397
|
-
|
|
398
|
-
|
|
304
|
+
let configModule = await viteNodeContext.runner.executeFile(
|
|
305
|
+
reactRouterConfigFile
|
|
306
|
+
);
|
|
307
|
+
if (configModule.default === void 0) {
|
|
308
|
+
return err(`${reactRouterConfigFile} must provide a default export`);
|
|
399
309
|
}
|
|
400
|
-
if (
|
|
401
|
-
|
|
310
|
+
if (typeof configModule.default !== "object") {
|
|
311
|
+
return err(`${reactRouterConfigFile} must export a config`);
|
|
402
312
|
}
|
|
313
|
+
reactRouterUserConfig = configModule.default;
|
|
314
|
+
} catch (error) {
|
|
315
|
+
return err(`Error loading ${reactRouterConfigFile}: ${error}`);
|
|
403
316
|
}
|
|
404
317
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
throw invalidDestructureError(property.value.name);
|
|
413
|
-
}
|
|
414
|
-
if (property.value.type === "ArrayPattern" || property.value.type === "ObjectPattern") {
|
|
415
|
-
validateDestructuredExports(property.value, exportsToRemove);
|
|
416
|
-
}
|
|
318
|
+
reactRouterUserConfig = deepFreeze((0, import_cloneDeep.default)(reactRouterUserConfig));
|
|
319
|
+
let presets = (await Promise.all(
|
|
320
|
+
(reactRouterUserConfig.presets ?? []).map(async (preset) => {
|
|
321
|
+
if (!preset.name) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
"React Router presets must have a `name` property defined."
|
|
324
|
+
);
|
|
417
325
|
}
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
function invalidDestructureError(name) {
|
|
425
|
-
return new Error(`Cannot remove destructured export "${name}"`);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// vite/config.ts
|
|
429
|
-
var import_node_child_process = require("child_process");
|
|
430
|
-
var import_node_path2 = __toESM(require("path"));
|
|
431
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
432
|
-
var import_picocolors = __toESM(require("picocolors"));
|
|
433
|
-
var import_pick2 = __toESM(require("lodash/pick"));
|
|
434
|
-
var import_omit = __toESM(require("lodash/omit"));
|
|
435
|
-
var import_package_json = __toESM(require("@npmcli/package-json"));
|
|
436
|
-
|
|
437
|
-
// config/routes.ts
|
|
438
|
-
var import_node_path = require("path");
|
|
439
|
-
var v = __toESM(require("valibot"));
|
|
440
|
-
var import_pick = __toESM(require("lodash/pick"));
|
|
441
|
-
function setAppDirectory(directory) {
|
|
442
|
-
globalThis.__reactRouterAppDirectory = directory;
|
|
443
|
-
}
|
|
444
|
-
var routeConfigEntrySchema = v.pipe(
|
|
445
|
-
v.custom((value) => {
|
|
446
|
-
return !(typeof value === "object" && value !== null && "then" in value && "catch" in value);
|
|
447
|
-
}, "Invalid type: Expected object but received a promise. Did you forget to await?"),
|
|
448
|
-
v.object({
|
|
449
|
-
id: v.optional(v.string()),
|
|
450
|
-
path: v.optional(v.string()),
|
|
451
|
-
index: v.optional(v.boolean()),
|
|
452
|
-
caseSensitive: v.optional(v.boolean()),
|
|
453
|
-
file: v.string(),
|
|
454
|
-
children: v.optional(v.array(v.lazy(() => routeConfigEntrySchema)))
|
|
455
|
-
})
|
|
456
|
-
);
|
|
457
|
-
var resolvedRouteConfigSchema = v.array(routeConfigEntrySchema);
|
|
458
|
-
function validateRouteConfig({
|
|
459
|
-
routeConfigFile,
|
|
460
|
-
routeConfig
|
|
461
|
-
}) {
|
|
462
|
-
if (!routeConfig) {
|
|
463
|
-
return {
|
|
464
|
-
valid: false,
|
|
465
|
-
message: `No "routes" export defined in "${routeConfigFile}.`
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
if (!Array.isArray(routeConfig)) {
|
|
469
|
-
return {
|
|
470
|
-
valid: false,
|
|
471
|
-
message: `Route config in "${routeConfigFile}" must be an array.`
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
let { issues } = v.safeParse(resolvedRouteConfigSchema, routeConfig);
|
|
475
|
-
if (issues?.length) {
|
|
476
|
-
let { root, nested } = v.flatten(issues);
|
|
477
|
-
return {
|
|
478
|
-
valid: false,
|
|
479
|
-
message: [
|
|
480
|
-
`Route config in "${routeConfigFile}" is invalid.`,
|
|
481
|
-
root ? `${root}` : [],
|
|
482
|
-
nested ? Object.entries(nested).map(
|
|
483
|
-
([path5, message]) => `Path: routes.${path5}
|
|
484
|
-
${message}`
|
|
485
|
-
) : []
|
|
486
|
-
].flat().join("\n\n")
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
return { valid: true };
|
|
490
|
-
}
|
|
491
|
-
function configRoutesToRouteManifest(routes, rootId = "root") {
|
|
492
|
-
let routeManifest = {};
|
|
493
|
-
function walk(route, parentId) {
|
|
494
|
-
let id2 = route.id || createRouteId(route.file);
|
|
495
|
-
let manifestItem = {
|
|
496
|
-
id: id2,
|
|
497
|
-
parentId,
|
|
498
|
-
file: route.file,
|
|
499
|
-
path: route.path,
|
|
500
|
-
index: route.index,
|
|
501
|
-
caseSensitive: route.caseSensitive
|
|
502
|
-
};
|
|
503
|
-
if (routeManifest.hasOwnProperty(id2)) {
|
|
504
|
-
throw new Error(
|
|
505
|
-
`Unable to define routes with duplicate route id: "${id2}"`
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
routeManifest[id2] = manifestItem;
|
|
509
|
-
if (route.children) {
|
|
510
|
-
for (let child of route.children) {
|
|
511
|
-
walk(child, id2);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
for (let route of routes) {
|
|
516
|
-
walk(route, rootId);
|
|
517
|
-
}
|
|
518
|
-
return routeManifest;
|
|
519
|
-
}
|
|
520
|
-
function createRouteId(file) {
|
|
521
|
-
return normalizeSlashes(stripFileExtension(file));
|
|
522
|
-
}
|
|
523
|
-
function normalizeSlashes(file) {
|
|
524
|
-
return file.split(import_node_path.win32.sep).join("/");
|
|
525
|
-
}
|
|
526
|
-
function stripFileExtension(file) {
|
|
527
|
-
return file.replace(/\.[a-z0-9]+$/i, "");
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// cli/detectPackageManager.ts
|
|
531
|
-
var detectPackageManager = () => {
|
|
532
|
-
let { npm_config_user_agent } = process.env;
|
|
533
|
-
if (!npm_config_user_agent) return void 0;
|
|
534
|
-
try {
|
|
535
|
-
let pkgManager = npm_config_user_agent.split("/")[0];
|
|
536
|
-
if (pkgManager === "npm") return "npm";
|
|
537
|
-
if (pkgManager === "pnpm") return "pnpm";
|
|
538
|
-
if (pkgManager === "yarn") return "yarn";
|
|
539
|
-
if (pkgManager === "bun") return "bun";
|
|
540
|
-
return void 0;
|
|
541
|
-
} catch {
|
|
542
|
-
return void 0;
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
// vite/config.ts
|
|
547
|
-
var excludedConfigPresetKeys = ["presets"];
|
|
548
|
-
var mergeReactRouterConfig = (...configs) => {
|
|
549
|
-
let reducer = (configA, configB) => {
|
|
550
|
-
let mergeRequired = (key) => configA[key] !== void 0 && configB[key] !== void 0;
|
|
551
|
-
return {
|
|
552
|
-
...configA,
|
|
553
|
-
...configB,
|
|
554
|
-
...mergeRequired("buildEnd") ? {
|
|
555
|
-
buildEnd: async (...args) => {
|
|
556
|
-
await Promise.all([
|
|
557
|
-
configA.buildEnd?.(...args),
|
|
558
|
-
configB.buildEnd?.(...args)
|
|
559
|
-
]);
|
|
560
|
-
}
|
|
561
|
-
} : {},
|
|
562
|
-
...mergeRequired("future") ? {
|
|
563
|
-
future: {
|
|
564
|
-
...configA.future,
|
|
565
|
-
...configB.future
|
|
566
|
-
}
|
|
567
|
-
} : {},
|
|
568
|
-
...mergeRequired("presets") ? {
|
|
569
|
-
presets: [...configA.presets ?? [], ...configB.presets ?? []]
|
|
570
|
-
} : {}
|
|
571
|
-
};
|
|
572
|
-
};
|
|
573
|
-
return configs.reduce(reducer, {});
|
|
574
|
-
};
|
|
575
|
-
var deepFreeze = (o) => {
|
|
576
|
-
Object.freeze(o);
|
|
577
|
-
let oIsFunction = typeof o === "function";
|
|
578
|
-
let hasOwnProp = Object.prototype.hasOwnProperty;
|
|
579
|
-
Object.getOwnPropertyNames(o).forEach(function(prop) {
|
|
580
|
-
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])) {
|
|
581
|
-
deepFreeze(o[prop]);
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
return o;
|
|
585
|
-
};
|
|
586
|
-
function resolvePublicPath(viteUserConfig) {
|
|
587
|
-
return viteUserConfig.base ?? "/";
|
|
588
|
-
}
|
|
589
|
-
var isFirstLoad = true;
|
|
590
|
-
var lastValidRoutes = {};
|
|
591
|
-
async function resolveReactRouterConfig({
|
|
592
|
-
rootDirectory,
|
|
593
|
-
reactRouterUserConfig,
|
|
594
|
-
routeConfigChanged,
|
|
595
|
-
viteUserConfig,
|
|
596
|
-
viteCommand,
|
|
597
|
-
routesViteNodeContext
|
|
598
|
-
}) {
|
|
599
|
-
let vite2 = importViteEsmSync();
|
|
600
|
-
let logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
601
|
-
prefix: "[react-router]"
|
|
602
|
-
});
|
|
603
|
-
let presets = (await Promise.all(
|
|
604
|
-
(reactRouterUserConfig.presets ?? []).map(async (preset) => {
|
|
605
|
-
if (!preset.name) {
|
|
606
|
-
throw new Error(
|
|
607
|
-
"React Router presets must have a `name` property defined."
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
if (!preset.reactRouterConfig) {
|
|
611
|
-
return null;
|
|
326
|
+
if (!preset.reactRouterConfig) {
|
|
327
|
+
return null;
|
|
612
328
|
}
|
|
613
329
|
let configPreset = (0, import_omit.default)(
|
|
614
330
|
await preset.reactRouterConfig({ reactRouterUserConfig }),
|
|
@@ -642,194 +358,783 @@ async function resolveReactRouterConfig({
|
|
|
642
358
|
...mergeReactRouterConfig(...presets, reactRouterUserConfig)
|
|
643
359
|
};
|
|
644
360
|
if (!ssr && serverBundles) {
|
|
645
|
-
console.warn(
|
|
646
|
-
import_picocolors.default.yellow(
|
|
647
|
-
import_picocolors.default.bold("\u26A0\uFE0F SPA Mode: ") + "the `serverBundles` config is invalid with `ssr:false` and will be ignored`"
|
|
648
|
-
)
|
|
649
|
-
);
|
|
650
361
|
serverBundles = void 0;
|
|
651
362
|
}
|
|
652
363
|
let isValidPrerenderConfig = prerender == null || typeof prerender === "boolean" || Array.isArray(prerender) || typeof prerender === "function";
|
|
653
364
|
if (!isValidPrerenderConfig) {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
657
|
-
)
|
|
658
|
-
);
|
|
659
|
-
process.exit(1);
|
|
660
|
-
}
|
|
661
|
-
let appDirectory = import_node_path2.default.resolve(rootDirectory, userAppDirectory || "app");
|
|
662
|
-
let buildDirectory = import_node_path2.default.resolve(rootDirectory, userBuildDirectory);
|
|
663
|
-
let publicPath = resolvePublicPath(viteUserConfig);
|
|
664
|
-
if (basename2 !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !basename2.startsWith(publicPath)) {
|
|
665
|
-
logger.error(
|
|
666
|
-
import_picocolors.default.red(
|
|
667
|
-
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
668
|
-
)
|
|
365
|
+
return err(
|
|
366
|
+
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
669
367
|
);
|
|
670
|
-
process.exit(1);
|
|
671
368
|
}
|
|
369
|
+
let appDirectory = import_pathe.default.resolve(root, userAppDirectory || "app");
|
|
370
|
+
let buildDirectory = import_pathe.default.resolve(root, userBuildDirectory);
|
|
672
371
|
let rootRouteFile = findEntry(appDirectory, "root");
|
|
673
372
|
if (!rootRouteFile) {
|
|
674
|
-
let rootRouteDisplayPath =
|
|
675
|
-
|
|
676
|
-
|
|
373
|
+
let rootRouteDisplayPath = import_pathe.default.relative(
|
|
374
|
+
root,
|
|
375
|
+
import_pathe.default.join(appDirectory, "root.tsx")
|
|
677
376
|
);
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
681
|
-
)
|
|
377
|
+
return err(
|
|
378
|
+
`Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
|
|
682
379
|
);
|
|
683
|
-
process.exit(1);
|
|
684
380
|
}
|
|
685
381
|
let routes = {
|
|
686
382
|
root: { path: "", id: "root", file: rootRouteFile }
|
|
687
383
|
};
|
|
688
384
|
let routeConfigFile = findEntry(appDirectory, "routes");
|
|
689
|
-
class FriendlyError extends Error {
|
|
690
|
-
}
|
|
691
385
|
try {
|
|
692
386
|
if (!routeConfigFile) {
|
|
693
|
-
let routeConfigDisplayPath =
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
throw new FriendlyError(
|
|
697
|
-
`Route config file not found at "${routeConfigDisplayPath}".`
|
|
387
|
+
let routeConfigDisplayPath = import_pathe.default.relative(
|
|
388
|
+
root,
|
|
389
|
+
import_pathe.default.join(appDirectory, "routes.ts")
|
|
698
390
|
);
|
|
391
|
+
return err(`Route config file not found at "${routeConfigDisplayPath}".`);
|
|
699
392
|
}
|
|
700
393
|
setAppDirectory(appDirectory);
|
|
701
|
-
let routeConfigExport = (await
|
|
702
|
-
|
|
703
|
-
)).
|
|
394
|
+
let routeConfigExport = (await viteNodeContext.runner.executeFile(
|
|
395
|
+
import_pathe.default.join(appDirectory, routeConfigFile)
|
|
396
|
+
)).default;
|
|
704
397
|
let routeConfig = await routeConfigExport;
|
|
705
398
|
let result = validateRouteConfig({
|
|
706
399
|
routeConfigFile,
|
|
707
400
|
routeConfig
|
|
708
401
|
});
|
|
709
402
|
if (!result.valid) {
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
routes = { ...routes, ...configRoutesToRouteManifest(routeConfig) };
|
|
713
|
-
lastValidRoutes = routes;
|
|
714
|
-
if (routeConfigChanged) {
|
|
715
|
-
logger.info(import_picocolors.default.green("Route config changed."), {
|
|
716
|
-
clear: true,
|
|
717
|
-
timestamp: true
|
|
718
|
-
});
|
|
403
|
+
return err(result.message);
|
|
719
404
|
}
|
|
405
|
+
routes = {
|
|
406
|
+
...routes,
|
|
407
|
+
...configRoutesToRouteManifest(appDirectory, routeConfig)
|
|
408
|
+
};
|
|
720
409
|
} catch (error) {
|
|
721
|
-
|
|
722
|
-
|
|
410
|
+
return err(
|
|
411
|
+
[
|
|
723
412
|
import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
|
|
724
413
|
"",
|
|
725
414
|
error.loc?.file && error.loc?.column && error.frame ? [
|
|
726
|
-
|
|
415
|
+
import_pathe.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
|
|
727
416
|
error.frame.trim?.()
|
|
728
417
|
] : error.stack
|
|
729
|
-
].flat().join("\n")
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
418
|
+
].flat().join("\n")
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
let future = {
|
|
422
|
+
unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
|
|
423
|
+
};
|
|
424
|
+
let reactRouterConfig = deepFreeze({
|
|
425
|
+
appDirectory,
|
|
426
|
+
basename: basename2,
|
|
427
|
+
buildDirectory,
|
|
428
|
+
buildEnd,
|
|
429
|
+
future,
|
|
430
|
+
prerender,
|
|
431
|
+
routes,
|
|
432
|
+
serverBuildFile,
|
|
433
|
+
serverBundles,
|
|
434
|
+
serverModuleFormat,
|
|
435
|
+
ssr
|
|
436
|
+
});
|
|
437
|
+
for (let preset of reactRouterUserConfig.presets ?? []) {
|
|
438
|
+
await preset.reactRouterConfigResolved?.({ reactRouterConfig });
|
|
439
|
+
}
|
|
440
|
+
return ok(reactRouterConfig);
|
|
441
|
+
}
|
|
442
|
+
async function createConfigLoader({
|
|
443
|
+
rootDirectory: root,
|
|
444
|
+
watch: watch2
|
|
445
|
+
}) {
|
|
446
|
+
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
447
|
+
let viteNodeContext = await createContext({
|
|
448
|
+
root,
|
|
449
|
+
mode: watch2 ? "development" : "production",
|
|
450
|
+
server: !watch2 ? { watch: null } : {},
|
|
451
|
+
ssr: {
|
|
452
|
+
external: ssrExternals
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
456
|
+
absolute: true
|
|
457
|
+
});
|
|
458
|
+
let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
|
|
459
|
+
let appDirectory;
|
|
460
|
+
let initialConfigResult = await getConfig();
|
|
461
|
+
if (!initialConfigResult.ok) {
|
|
462
|
+
throw new Error(initialConfigResult.error);
|
|
463
|
+
}
|
|
464
|
+
appDirectory = initialConfigResult.value.appDirectory;
|
|
465
|
+
let lastConfig = initialConfigResult.value;
|
|
466
|
+
let fsWatcher;
|
|
467
|
+
let changeHandlers = [];
|
|
468
|
+
return {
|
|
469
|
+
getConfig,
|
|
470
|
+
onChange: (handler) => {
|
|
471
|
+
if (!watch2) {
|
|
472
|
+
throw new Error(
|
|
473
|
+
"onChange is not supported when watch mode is disabled"
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
changeHandlers.push(handler);
|
|
477
|
+
if (!fsWatcher) {
|
|
478
|
+
fsWatcher = import_chokidar.default.watch(
|
|
479
|
+
[
|
|
480
|
+
...reactRouterConfigFile ? [reactRouterConfigFile] : [],
|
|
481
|
+
appDirectory
|
|
482
|
+
],
|
|
483
|
+
{ ignoreInitial: true }
|
|
484
|
+
);
|
|
485
|
+
fsWatcher.on("all", async (...args) => {
|
|
486
|
+
let [event, rawFilepath] = args;
|
|
487
|
+
let filepath = import_pathe.default.normalize(rawFilepath);
|
|
488
|
+
let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe.default.normalize(appDirectory));
|
|
489
|
+
let configCodeUpdated = Boolean(
|
|
490
|
+
viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
|
|
491
|
+
);
|
|
492
|
+
if (configCodeUpdated || appFileAddedOrRemoved) {
|
|
493
|
+
viteNodeContext.devServer?.moduleGraph.invalidateAll();
|
|
494
|
+
viteNodeContext.runner?.moduleCache.clear();
|
|
495
|
+
}
|
|
496
|
+
if (appFileAddedOrRemoved || configCodeUpdated) {
|
|
497
|
+
let result = await getConfig();
|
|
498
|
+
let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
|
|
499
|
+
let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
|
|
500
|
+
for (let handler2 of changeHandlers) {
|
|
501
|
+
handler2({
|
|
502
|
+
result,
|
|
503
|
+
configCodeUpdated,
|
|
504
|
+
configChanged,
|
|
505
|
+
routeConfigChanged,
|
|
506
|
+
path: filepath,
|
|
507
|
+
event
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
if (result.ok) {
|
|
511
|
+
lastConfig = result.value;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return () => {
|
|
517
|
+
changeHandlers = changeHandlers.filter(
|
|
518
|
+
(changeHandler) => changeHandler !== handler
|
|
519
|
+
);
|
|
520
|
+
};
|
|
521
|
+
},
|
|
522
|
+
close: async () => {
|
|
523
|
+
changeHandlers = [];
|
|
524
|
+
await viteNodeContext.devServer.close();
|
|
525
|
+
await fsWatcher?.close();
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
async function resolveEntryFiles({
|
|
530
|
+
rootDirectory,
|
|
531
|
+
reactRouterConfig
|
|
532
|
+
}) {
|
|
533
|
+
let { appDirectory } = reactRouterConfig;
|
|
534
|
+
let defaultsDirectory = import_pathe.default.resolve(
|
|
535
|
+
import_pathe.default.dirname(require.resolve("@react-router/dev/package.json")),
|
|
536
|
+
"dist",
|
|
537
|
+
"config",
|
|
538
|
+
"defaults"
|
|
539
|
+
);
|
|
540
|
+
let userEntryClientFile = findEntry(appDirectory, "entry.client");
|
|
541
|
+
let userEntryServerFile = findEntry(appDirectory, "entry.server");
|
|
542
|
+
let entryServerFile;
|
|
543
|
+
let entryClientFile = userEntryClientFile || "entry.client.tsx";
|
|
544
|
+
let pkgJson = await import_package_json.default.load(rootDirectory);
|
|
545
|
+
let deps = pkgJson.content.dependencies ?? {};
|
|
546
|
+
if (userEntryServerFile) {
|
|
547
|
+
entryServerFile = userEntryServerFile;
|
|
548
|
+
} else {
|
|
549
|
+
if (!deps["@react-router/node"]) {
|
|
550
|
+
throw new Error(
|
|
551
|
+
`Could not determine server runtime. Please install @react-router/node, or provide a custom entry.server.tsx/jsx file in your app directory.`
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
if (!deps["isbot"]) {
|
|
555
|
+
console.log(
|
|
556
|
+
"adding `isbot@5` to your package.json, you should commit this change"
|
|
557
|
+
);
|
|
558
|
+
pkgJson.update({
|
|
559
|
+
dependencies: {
|
|
560
|
+
...pkgJson.content.dependencies,
|
|
561
|
+
isbot: "^5"
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
await pkgJson.save();
|
|
565
|
+
let packageManager = detectPackageManager() ?? "npm";
|
|
566
|
+
(0, import_node_child_process.execSync)(`${packageManager} install`, {
|
|
567
|
+
cwd: rootDirectory,
|
|
568
|
+
stdio: "inherit"
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
entryServerFile = `entry.server.node.tsx`;
|
|
572
|
+
}
|
|
573
|
+
let entryClientFilePath = userEntryClientFile ? import_pathe.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_pathe.default.resolve(defaultsDirectory, entryClientFile);
|
|
574
|
+
let entryServerFilePath = userEntryServerFile ? import_pathe.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe.default.resolve(defaultsDirectory, entryServerFile);
|
|
575
|
+
return { entryClientFilePath, entryServerFilePath };
|
|
576
|
+
}
|
|
577
|
+
var ssrExternals = isInReactRouterMonorepo() ? [
|
|
578
|
+
// This is only needed within this repo because these packages
|
|
579
|
+
// are linked to a directory outside of node_modules so Vite
|
|
580
|
+
// treats them as internal code by default.
|
|
581
|
+
"react-router",
|
|
582
|
+
"react-router-dom",
|
|
583
|
+
"@react-router/architect",
|
|
584
|
+
"@react-router/cloudflare",
|
|
585
|
+
"@react-router/dev",
|
|
586
|
+
"@react-router/express",
|
|
587
|
+
"@react-router/node",
|
|
588
|
+
"@react-router/serve"
|
|
589
|
+
] : void 0;
|
|
590
|
+
function isInReactRouterMonorepo() {
|
|
591
|
+
let serverRuntimePath = import_pathe.default.dirname(
|
|
592
|
+
require.resolve("@react-router/node/package.json")
|
|
593
|
+
);
|
|
594
|
+
let serverRuntimeParentDir = import_pathe.default.basename(
|
|
595
|
+
import_pathe.default.resolve(serverRuntimePath, "..")
|
|
596
|
+
);
|
|
597
|
+
return serverRuntimeParentDir === "packages";
|
|
598
|
+
}
|
|
599
|
+
var entryExts = [".js", ".jsx", ".ts", ".tsx"];
|
|
600
|
+
function findEntry(dir, basename2, options) {
|
|
601
|
+
for (let ext of entryExts) {
|
|
602
|
+
let file = import_pathe.default.resolve(dir, basename2 + ext);
|
|
603
|
+
if (import_node_fs.default.existsSync(file)) {
|
|
604
|
+
return options?.absolute ?? false ? file : import_pathe.default.relative(dir, file);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return void 0;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// typegen/generate.ts
|
|
611
|
+
var import_dedent = __toESM(require("dedent"));
|
|
612
|
+
var Path3 = __toESM(require("pathe"));
|
|
613
|
+
var Pathe2 = __toESM(require("pathe/utils"));
|
|
614
|
+
|
|
615
|
+
// typegen/paths.ts
|
|
616
|
+
var Path2 = __toESM(require("pathe"));
|
|
617
|
+
var Pathe = __toESM(require("pathe/utils"));
|
|
618
|
+
function getTypesDir(ctx) {
|
|
619
|
+
return Path2.join(ctx.rootDirectory, ".react-router/types");
|
|
620
|
+
}
|
|
621
|
+
function getTypesPath(ctx, route) {
|
|
622
|
+
return Path2.join(
|
|
623
|
+
getTypesDir(ctx),
|
|
624
|
+
Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
|
|
625
|
+
Path2.dirname(route.file),
|
|
626
|
+
"+types/" + Pathe.filename(route.file) + ".ts"
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// typegen/generate.ts
|
|
631
|
+
function generate(ctx, route) {
|
|
632
|
+
const lineage = getRouteLineage(ctx.config.routes, route);
|
|
633
|
+
const urlpath = lineage.map((route2) => route2.path).join("/");
|
|
634
|
+
const typesPath = getTypesPath(ctx, route);
|
|
635
|
+
const parents = lineage.slice(0, -1);
|
|
636
|
+
const parentTypeImports = parents.map((parent, i) => {
|
|
637
|
+
const rel = Path3.relative(
|
|
638
|
+
Path3.dirname(typesPath),
|
|
639
|
+
getTypesPath(ctx, parent)
|
|
640
|
+
);
|
|
641
|
+
const indent = i === 0 ? "" : " ".repeat(2);
|
|
642
|
+
let source = noExtension(rel);
|
|
643
|
+
if (!source.startsWith("../")) source = "./" + source;
|
|
644
|
+
return `${indent}import type { Info as Parent${i} } from "${source}"`;
|
|
645
|
+
}).join("\n");
|
|
646
|
+
return import_dedent.default`
|
|
647
|
+
// React Router generated types for route:
|
|
648
|
+
// ${route.file}
|
|
649
|
+
|
|
650
|
+
import type * as T from "react-router/route-module"
|
|
651
|
+
|
|
652
|
+
${parentTypeImports}
|
|
653
|
+
|
|
654
|
+
type Module = typeof import("../${Pathe2.filename(route.file)}")
|
|
655
|
+
|
|
656
|
+
export type Info = {
|
|
657
|
+
parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
|
|
658
|
+
id: "${route.id}"
|
|
659
|
+
file: "${route.file}"
|
|
660
|
+
path: "${route.path}"
|
|
661
|
+
params: {${formatParamProperties(urlpath)}}
|
|
662
|
+
module: Module
|
|
663
|
+
loaderData: T.CreateLoaderData<Module>
|
|
664
|
+
actionData: T.CreateActionData<Module>
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export namespace Route {
|
|
668
|
+
export type LinkDescriptors = T.LinkDescriptors
|
|
669
|
+
export type LinksFunction = () => LinkDescriptors
|
|
670
|
+
|
|
671
|
+
export type MetaArgs = T.CreateMetaArgs<Info>
|
|
672
|
+
export type MetaDescriptors = T.MetaDescriptors
|
|
673
|
+
export type MetaFunction = (args: MetaArgs) => MetaDescriptors
|
|
674
|
+
|
|
675
|
+
export type LoaderArgs = T.CreateServerLoaderArgs<Info>
|
|
676
|
+
export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
|
|
677
|
+
export type ActionArgs = T.CreateServerActionArgs<Info>
|
|
678
|
+
export type ClientActionArgs = T.CreateClientActionArgs<Info>
|
|
679
|
+
|
|
680
|
+
export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
|
|
681
|
+
export type ComponentProps = T.CreateComponentProps<Info>
|
|
682
|
+
export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
|
|
683
|
+
}
|
|
684
|
+
`;
|
|
685
|
+
}
|
|
686
|
+
var noExtension = (path5) => Path3.join(Path3.dirname(path5), Pathe2.filename(path5));
|
|
687
|
+
function getRouteLineage(routes, route) {
|
|
688
|
+
const result = [];
|
|
689
|
+
while (route) {
|
|
690
|
+
result.push(route);
|
|
691
|
+
if (!route.parentId) break;
|
|
692
|
+
route = routes[route.parentId];
|
|
693
|
+
}
|
|
694
|
+
result.reverse();
|
|
695
|
+
return result;
|
|
696
|
+
}
|
|
697
|
+
function formatParamProperties(urlpath) {
|
|
698
|
+
const params = parseParams(urlpath);
|
|
699
|
+
const properties = Object.entries(params).map(([name, values]) => {
|
|
700
|
+
if (values.length === 1) {
|
|
701
|
+
const isOptional = values[0];
|
|
702
|
+
return isOptional ? `"${name}"?: string` : `"${name}": string`;
|
|
703
|
+
}
|
|
704
|
+
const items = values.map(
|
|
705
|
+
(isOptional) => isOptional ? "string | undefined" : "string"
|
|
706
|
+
);
|
|
707
|
+
return `"${name}": [${items.join(", ")}]`;
|
|
708
|
+
});
|
|
709
|
+
return properties.join("; ");
|
|
710
|
+
}
|
|
711
|
+
function parseParams(urlpath) {
|
|
712
|
+
const result = {};
|
|
713
|
+
let segments = urlpath.split("/");
|
|
714
|
+
segments.forEach((segment) => {
|
|
715
|
+
const match = segment.match(/^:([\w-]+)(\?)?/);
|
|
716
|
+
if (!match) return;
|
|
717
|
+
const param = match[1];
|
|
718
|
+
const isOptional = match[2] !== void 0;
|
|
719
|
+
result[param] ??= [];
|
|
720
|
+
result[param].push(isOptional);
|
|
721
|
+
return;
|
|
722
|
+
});
|
|
723
|
+
const hasSplat = segments.at(-1) === "*";
|
|
724
|
+
if (hasSplat) result["*"] = [false];
|
|
725
|
+
return result;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// typegen/index.ts
|
|
729
|
+
async function watch(rootDirectory, { logger } = {}) {
|
|
730
|
+
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
731
|
+
await writeAll(ctx);
|
|
732
|
+
logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
|
|
733
|
+
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
734
|
+
if (!result.ok) {
|
|
735
|
+
logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
ctx.config = result.value;
|
|
739
|
+
if (routeConfigChanged) {
|
|
740
|
+
await writeAll(ctx);
|
|
741
|
+
logger?.info(import_picocolors2.default.green("regenerated types"), {
|
|
742
|
+
timestamp: true,
|
|
743
|
+
clear: true
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
async function createContext2({
|
|
749
|
+
rootDirectory,
|
|
750
|
+
watch: watch2
|
|
751
|
+
}) {
|
|
752
|
+
const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
|
|
753
|
+
const configResult = await configLoader.getConfig();
|
|
754
|
+
if (!configResult.ok) {
|
|
755
|
+
throw new Error(configResult.error);
|
|
756
|
+
}
|
|
757
|
+
const config = configResult.value;
|
|
758
|
+
return {
|
|
759
|
+
configLoader,
|
|
760
|
+
rootDirectory,
|
|
761
|
+
config
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
async function writeAll(ctx) {
|
|
765
|
+
const typegenDir = getTypesDir(ctx);
|
|
766
|
+
import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
|
|
767
|
+
Object.values(ctx.config.routes).forEach((route) => {
|
|
768
|
+
const typesPath = getTypesPath(ctx, route);
|
|
769
|
+
const content = generate(ctx, route);
|
|
770
|
+
import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
|
|
771
|
+
import_node_fs2.default.writeFileSync(typesPath, content);
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// vite/babel.ts
|
|
776
|
+
var import_parser = require("@babel/parser");
|
|
777
|
+
var t = __toESM(require("@babel/types"));
|
|
778
|
+
var traverse = require("@babel/traverse").default;
|
|
779
|
+
var generate2 = require("@babel/generator").default;
|
|
780
|
+
|
|
781
|
+
// vite/node-adapter.ts
|
|
782
|
+
var import_node_events = require("events");
|
|
783
|
+
var import_node_stream = require("stream");
|
|
784
|
+
var import_set_cookie_parser = require("set-cookie-parser");
|
|
785
|
+
var import_node = require("@react-router/node");
|
|
786
|
+
function fromNodeHeaders(nodeHeaders) {
|
|
787
|
+
let headers = new Headers();
|
|
788
|
+
for (let [key, values] of Object.entries(nodeHeaders)) {
|
|
789
|
+
if (values) {
|
|
790
|
+
if (Array.isArray(values)) {
|
|
791
|
+
for (let value of values) {
|
|
792
|
+
headers.append(key, value);
|
|
793
|
+
}
|
|
794
|
+
} else {
|
|
795
|
+
headers.set(key, values);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return headers;
|
|
800
|
+
}
|
|
801
|
+
function fromNodeRequest(nodeReq, nodeRes) {
|
|
802
|
+
let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `http://${nodeReq.headers.host}`;
|
|
803
|
+
invariant(
|
|
804
|
+
nodeReq.originalUrl,
|
|
805
|
+
"Expected `nodeReq.originalUrl` to be defined"
|
|
806
|
+
);
|
|
807
|
+
let url3 = new URL(nodeReq.originalUrl, origin);
|
|
808
|
+
let controller = new AbortController();
|
|
809
|
+
let init = {
|
|
810
|
+
method: nodeReq.method,
|
|
811
|
+
headers: fromNodeHeaders(nodeReq.headers),
|
|
812
|
+
signal: controller.signal
|
|
813
|
+
};
|
|
814
|
+
nodeRes.on("finish", () => controller = null);
|
|
815
|
+
nodeRes.on("close", () => controller?.abort());
|
|
816
|
+
if (nodeReq.method !== "GET" && nodeReq.method !== "HEAD") {
|
|
817
|
+
init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
|
|
818
|
+
init.duplex = "half";
|
|
819
|
+
}
|
|
820
|
+
return new Request(url3.href, init);
|
|
821
|
+
}
|
|
822
|
+
async function toNodeRequest(res, nodeRes) {
|
|
823
|
+
nodeRes.statusCode = res.status;
|
|
824
|
+
nodeRes.statusMessage = res.statusText;
|
|
825
|
+
let cookiesStrings = [];
|
|
826
|
+
for (let [name, value] of res.headers) {
|
|
827
|
+
if (name === "set-cookie") {
|
|
828
|
+
cookiesStrings.push(...(0, import_set_cookie_parser.splitCookiesString)(value));
|
|
829
|
+
} else nodeRes.setHeader(name, value);
|
|
830
|
+
}
|
|
831
|
+
if (cookiesStrings.length) {
|
|
832
|
+
nodeRes.setHeader("set-cookie", cookiesStrings);
|
|
833
|
+
}
|
|
834
|
+
if (res.body) {
|
|
835
|
+
let responseBody = res.body;
|
|
836
|
+
let readable = import_node_stream.Readable.from(responseBody);
|
|
837
|
+
readable.pipe(nodeRes);
|
|
838
|
+
await (0, import_node_events.once)(readable, "end");
|
|
839
|
+
} else {
|
|
840
|
+
nodeRes.end();
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// vite/styles.ts
|
|
845
|
+
var path3 = __toESM(require("path"));
|
|
846
|
+
var import_react_router = require("react-router");
|
|
847
|
+
|
|
848
|
+
// vite/resolve-file-url.ts
|
|
849
|
+
var path2 = __toESM(require("path"));
|
|
850
|
+
var resolveFileUrl = ({ rootDirectory }, filePath) => {
|
|
851
|
+
let vite2 = importViteEsmSync();
|
|
852
|
+
let relativePath = path2.relative(rootDirectory, filePath);
|
|
853
|
+
let isWithinRoot = !relativePath.startsWith("..") && !path2.isAbsolute(relativePath);
|
|
854
|
+
if (!isWithinRoot) {
|
|
855
|
+
return path2.posix.join("/@fs", vite2.normalizePath(filePath));
|
|
856
|
+
}
|
|
857
|
+
return "/" + vite2.normalizePath(relativePath);
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
// vite/styles.ts
|
|
861
|
+
var cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
862
|
+
var cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
863
|
+
var isCssFile = (file) => cssFileRegExp.test(file);
|
|
864
|
+
var isCssModulesFile = (file) => cssModulesRegExp.test(file);
|
|
865
|
+
var cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
|
|
866
|
+
var isCssUrlWithoutSideEffects = (url3) => {
|
|
867
|
+
let queryString = url3.split("?")[1];
|
|
868
|
+
if (!queryString) {
|
|
869
|
+
return false;
|
|
870
|
+
}
|
|
871
|
+
let params = new URLSearchParams(queryString);
|
|
872
|
+
for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
|
|
873
|
+
if (
|
|
874
|
+
// Parameter is blank and not explicitly set, i.e. "?url", not "?url="
|
|
875
|
+
params.get(paramWithoutSideEffects) === "" && !url3.includes(`?${paramWithoutSideEffects}=`) && !url3.includes(`&${paramWithoutSideEffects}=`)
|
|
876
|
+
) {
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return false;
|
|
881
|
+
};
|
|
882
|
+
var getStylesForFiles = async ({
|
|
883
|
+
viteDevServer,
|
|
884
|
+
rootDirectory,
|
|
885
|
+
cssModulesManifest,
|
|
886
|
+
files
|
|
887
|
+
}) => {
|
|
888
|
+
let styles = {};
|
|
889
|
+
let deps = /* @__PURE__ */ new Set();
|
|
890
|
+
try {
|
|
891
|
+
for (let file of files) {
|
|
892
|
+
let normalizedPath = path3.resolve(rootDirectory, file).replace(/\\/g, "/");
|
|
893
|
+
let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
894
|
+
if (!node) {
|
|
895
|
+
try {
|
|
896
|
+
await viteDevServer.transformRequest(
|
|
897
|
+
resolveFileUrl({ rootDirectory }, normalizedPath)
|
|
898
|
+
);
|
|
899
|
+
} catch (err2) {
|
|
900
|
+
console.error(err2);
|
|
901
|
+
}
|
|
902
|
+
node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
|
|
903
|
+
}
|
|
904
|
+
if (!node) {
|
|
905
|
+
console.log(`Could not resolve module for file: ${file}`);
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
await findDeps(viteDevServer, node, deps);
|
|
909
|
+
}
|
|
910
|
+
} catch (err2) {
|
|
911
|
+
console.error(err2);
|
|
912
|
+
}
|
|
913
|
+
for (let dep of deps) {
|
|
914
|
+
if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url)) {
|
|
915
|
+
try {
|
|
916
|
+
let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(dep.url)).default;
|
|
917
|
+
if (css === void 0) {
|
|
918
|
+
throw new Error();
|
|
919
|
+
}
|
|
920
|
+
styles[dep.url] = css;
|
|
921
|
+
} catch {
|
|
922
|
+
console.warn(`Could not load ${dep.file}`);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return Object.entries(styles).map(([fileName, css], i) => [
|
|
927
|
+
`
|
|
928
|
+
/* ${fileName.replace(/\/\*/g, "/\\*").replace(/\*\//g, "*\\/")} */`,
|
|
929
|
+
css
|
|
930
|
+
]).flat().join("\n") || void 0;
|
|
931
|
+
};
|
|
932
|
+
var findDeps = async (vite2, node, deps) => {
|
|
933
|
+
let branches = [];
|
|
934
|
+
async function addFromNode(node2) {
|
|
935
|
+
if (!deps.has(node2)) {
|
|
936
|
+
deps.add(node2);
|
|
937
|
+
await findDeps(vite2, node2, deps);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
async function addFromUrl(url3) {
|
|
941
|
+
let node2 = await vite2.moduleGraph.getModuleByUrl(url3);
|
|
942
|
+
if (node2) {
|
|
943
|
+
await addFromNode(node2);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
if (node.ssrTransformResult) {
|
|
947
|
+
if (node.ssrTransformResult.deps) {
|
|
948
|
+
node.ssrTransformResult.deps.forEach(
|
|
949
|
+
(url3) => branches.push(addFromUrl(url3))
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
} else {
|
|
953
|
+
node.importedModules.forEach((node2) => branches.push(addFromNode(node2)));
|
|
954
|
+
}
|
|
955
|
+
await Promise.all(branches);
|
|
956
|
+
};
|
|
957
|
+
var groupRoutesByParentId = (manifest) => {
|
|
958
|
+
let routes = {};
|
|
959
|
+
Object.values(manifest).forEach((route) => {
|
|
960
|
+
if (route) {
|
|
961
|
+
let parentId = route.parentId || "";
|
|
962
|
+
if (!routes[parentId]) {
|
|
963
|
+
routes[parentId] = [];
|
|
964
|
+
}
|
|
965
|
+
routes[parentId].push(route);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
return routes;
|
|
969
|
+
};
|
|
970
|
+
var createRoutes = (manifest, parentId = "", routesByParentId = groupRoutesByParentId(manifest)) => {
|
|
971
|
+
return (routesByParentId[parentId] || []).map((route) => ({
|
|
972
|
+
...route,
|
|
973
|
+
children: createRoutes(manifest, route.id, routesByParentId)
|
|
974
|
+
}));
|
|
975
|
+
};
|
|
976
|
+
var getStylesForUrl = async ({
|
|
977
|
+
viteDevServer,
|
|
978
|
+
rootDirectory,
|
|
979
|
+
reactRouterConfig,
|
|
980
|
+
entryClientFilePath,
|
|
981
|
+
cssModulesManifest,
|
|
982
|
+
build,
|
|
983
|
+
url: url3
|
|
984
|
+
}) => {
|
|
985
|
+
if (url3 === void 0 || url3.includes("?_data=")) {
|
|
986
|
+
return void 0;
|
|
987
|
+
}
|
|
988
|
+
let routes = createRoutes(build.routes);
|
|
989
|
+
let appPath = path3.relative(process.cwd(), reactRouterConfig.appDirectory);
|
|
990
|
+
let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url3, build.basename)?.map(
|
|
991
|
+
(match) => path3.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
|
|
992
|
+
) ?? [];
|
|
993
|
+
let styles = await getStylesForFiles({
|
|
994
|
+
viteDevServer,
|
|
995
|
+
rootDirectory,
|
|
996
|
+
cssModulesManifest,
|
|
997
|
+
files: [
|
|
998
|
+
// Always include the client entry file when crawling the module graph for CSS
|
|
999
|
+
path3.relative(rootDirectory, entryClientFilePath),
|
|
1000
|
+
// Then include any styles from the matched routes
|
|
1001
|
+
...documentRouteFiles
|
|
1002
|
+
]
|
|
1003
|
+
});
|
|
1004
|
+
return styles;
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
// vite/vmod.ts
|
|
1008
|
+
var id = (name) => `virtual:react-router/${name}`;
|
|
1009
|
+
var resolve3 = (id2) => `\0${id2}`;
|
|
1010
|
+
var url = (id2) => `/@id/__x00__${id2}`;
|
|
1011
|
+
|
|
1012
|
+
// vite/combine-urls.ts
|
|
1013
|
+
function combineURLs(baseURL, relativeURL) {
|
|
1014
|
+
return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// vite/remove-exports.ts
|
|
1018
|
+
var import_babel_dead_code_elimination = require("babel-dead-code-elimination");
|
|
1019
|
+
var removeExports = (ast, exportsToRemove) => {
|
|
1020
|
+
let previouslyReferencedIdentifiers = (0, import_babel_dead_code_elimination.findReferencedIdentifiers)(ast);
|
|
1021
|
+
let exportsFiltered = false;
|
|
1022
|
+
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1023
|
+
traverse(ast, {
|
|
1024
|
+
ExportDeclaration(path5) {
|
|
1025
|
+
if (path5.node.type === "ExportNamedDeclaration") {
|
|
1026
|
+
if (path5.node.specifiers.length) {
|
|
1027
|
+
path5.node.specifiers = path5.node.specifiers.filter((specifier) => {
|
|
1028
|
+
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1029
|
+
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1030
|
+
exportsFiltered = true;
|
|
1031
|
+
return false;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
return true;
|
|
1035
|
+
});
|
|
1036
|
+
if (path5.node.specifiers.length === 0) {
|
|
1037
|
+
markedForRemoval.add(path5);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (path5.node.declaration?.type === "VariableDeclaration") {
|
|
1041
|
+
let declaration = path5.node.declaration;
|
|
1042
|
+
declaration.declarations = declaration.declarations.filter(
|
|
1043
|
+
(declaration2) => {
|
|
1044
|
+
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
1045
|
+
exportsFiltered = true;
|
|
1046
|
+
return false;
|
|
1047
|
+
}
|
|
1048
|
+
if (declaration2.id.type === "ArrayPattern" || declaration2.id.type === "ObjectPattern") {
|
|
1049
|
+
validateDestructuredExports(declaration2.id, exportsToRemove);
|
|
1050
|
+
}
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
1054
|
+
if (declaration.declarations.length === 0) {
|
|
1055
|
+
markedForRemoval.add(path5);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
if (path5.node.declaration?.type === "FunctionDeclaration") {
|
|
1059
|
+
let id2 = path5.node.declaration.id;
|
|
1060
|
+
if (id2 && exportsToRemove.includes(id2.name)) {
|
|
1061
|
+
markedForRemoval.add(path5);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
if (path5.node.declaration?.type === "ClassDeclaration") {
|
|
1065
|
+
let id2 = path5.node.declaration.id;
|
|
1066
|
+
if (id2 && exportsToRemove.includes(id2.name)) {
|
|
1067
|
+
markedForRemoval.add(path5);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (path5.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
1072
|
+
markedForRemoval.add(path5);
|
|
734
1073
|
}
|
|
735
|
-
);
|
|
736
|
-
if (isFirstLoad) {
|
|
737
|
-
process.exit(1);
|
|
738
1074
|
}
|
|
739
|
-
routes = lastValidRoutes;
|
|
740
|
-
}
|
|
741
|
-
let future = {};
|
|
742
|
-
let reactRouterConfig = deepFreeze({
|
|
743
|
-
appDirectory,
|
|
744
|
-
basename: basename2,
|
|
745
|
-
buildDirectory,
|
|
746
|
-
buildEnd,
|
|
747
|
-
future,
|
|
748
|
-
prerender,
|
|
749
|
-
routes,
|
|
750
|
-
serverBuildFile,
|
|
751
|
-
serverBundles,
|
|
752
|
-
serverModuleFormat,
|
|
753
|
-
ssr
|
|
754
1075
|
});
|
|
755
|
-
|
|
756
|
-
|
|
1076
|
+
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1077
|
+
for (let path5 of markedForRemoval) {
|
|
1078
|
+
path5.remove();
|
|
1079
|
+
}
|
|
1080
|
+
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
757
1081
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
let entryServerFile;
|
|
775
|
-
let entryClientFile = userEntryClientFile || "entry.client.tsx";
|
|
776
|
-
let pkgJson = await import_package_json.default.load(rootDirectory);
|
|
777
|
-
let deps = pkgJson.content.dependencies ?? {};
|
|
778
|
-
if (userEntryServerFile) {
|
|
779
|
-
entryServerFile = userEntryServerFile;
|
|
780
|
-
} else {
|
|
781
|
-
if (!deps["@react-router/node"]) {
|
|
782
|
-
throw new Error(
|
|
783
|
-
`Could not determine server runtime. Please install @react-router/node, or provide a custom entry.server.tsx/jsx file in your app directory.`
|
|
784
|
-
);
|
|
1082
|
+
};
|
|
1083
|
+
function validateDestructuredExports(id2, exportsToRemove) {
|
|
1084
|
+
if (id2.type === "ArrayPattern") {
|
|
1085
|
+
for (let element of id2.elements) {
|
|
1086
|
+
if (!element) {
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
if (element.type === "Identifier" && exportsToRemove.includes(element.name)) {
|
|
1090
|
+
throw invalidDestructureError(element.name);
|
|
1091
|
+
}
|
|
1092
|
+
if (element.type === "RestElement" && element.argument.type === "Identifier" && exportsToRemove.includes(element.argument.name)) {
|
|
1093
|
+
throw invalidDestructureError(element.argument.name);
|
|
1094
|
+
}
|
|
1095
|
+
if (element.type === "ArrayPattern" || element.type === "ObjectPattern") {
|
|
1096
|
+
validateDestructuredExports(element, exportsToRemove);
|
|
1097
|
+
}
|
|
785
1098
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
)
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
1099
|
+
}
|
|
1100
|
+
if (id2.type === "ObjectPattern") {
|
|
1101
|
+
for (let property of id2.properties) {
|
|
1102
|
+
if (!property) {
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
if (property.type === "ObjectProperty" && property.key.type === "Identifier") {
|
|
1106
|
+
if (property.value.type === "Identifier" && exportsToRemove.includes(property.value.name)) {
|
|
1107
|
+
throw invalidDestructureError(property.value.name);
|
|
794
1108
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
1109
|
+
if (property.value.type === "ArrayPattern" || property.value.type === "ObjectPattern") {
|
|
1110
|
+
validateDestructuredExports(property.value, exportsToRemove);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (property.type === "RestElement" && property.argument.type === "Identifier" && exportsToRemove.includes(property.argument.name)) {
|
|
1114
|
+
throw invalidDestructureError(property.argument.name);
|
|
1115
|
+
}
|
|
802
1116
|
}
|
|
803
|
-
entryServerFile = `entry.server.node.tsx`;
|
|
804
1117
|
}
|
|
805
|
-
let entryClientFilePath = userEntryClientFile ? import_node_path2.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_node_path2.default.resolve(defaultsDirectory, entryClientFile);
|
|
806
|
-
let entryServerFilePath = userEntryServerFile ? import_node_path2.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_node_path2.default.resolve(defaultsDirectory, entryServerFile);
|
|
807
|
-
return { entryClientFilePath, entryServerFilePath };
|
|
808
1118
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
for (let ext of entryExts) {
|
|
812
|
-
let file = import_node_path2.default.resolve(dir, basename2 + ext);
|
|
813
|
-
if (import_fs_extra.default.existsSync(file)) return import_node_path2.default.relative(dir, file);
|
|
814
|
-
}
|
|
815
|
-
return void 0;
|
|
1119
|
+
function invalidDestructureError(name) {
|
|
1120
|
+
return new Error(`Cannot remove destructured export "${name}"`);
|
|
816
1121
|
}
|
|
817
1122
|
|
|
818
1123
|
// vite/with-props.ts
|
|
819
|
-
var
|
|
1124
|
+
var import_dedent2 = __toESM(require("dedent"));
|
|
820
1125
|
var vmodId = id("with-props");
|
|
821
1126
|
var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
822
1127
|
var plugin = {
|
|
823
1128
|
name: "react-router-with-props",
|
|
824
1129
|
enforce: "pre",
|
|
825
1130
|
resolveId(id2) {
|
|
826
|
-
if (id2 === vmodId) return
|
|
1131
|
+
if (id2 === vmodId) return resolve3(vmodId);
|
|
827
1132
|
},
|
|
828
1133
|
async load(id2) {
|
|
829
|
-
if (id2 !==
|
|
830
|
-
return
|
|
1134
|
+
if (id2 !== resolve3(vmodId)) return;
|
|
1135
|
+
return import_dedent2.default`
|
|
831
1136
|
import { createElement as h } from "react";
|
|
832
|
-
import { useActionData, useLoaderData, useParams } from "react-router";
|
|
1137
|
+
import { useActionData, useLoaderData, useMatches, useParams } from "react-router";
|
|
833
1138
|
|
|
834
1139
|
export function withComponentProps(Component) {
|
|
835
1140
|
return function Wrapped() {
|
|
@@ -837,6 +1142,7 @@ var plugin = {
|
|
|
837
1142
|
params: useParams(),
|
|
838
1143
|
loaderData: useLoaderData(),
|
|
839
1144
|
actionData: useActionData(),
|
|
1145
|
+
matches: useMatches(),
|
|
840
1146
|
};
|
|
841
1147
|
return h(Component, props);
|
|
842
1148
|
};
|
|
@@ -937,48 +1243,6 @@ function toFunctionExpression(decl) {
|
|
|
937
1243
|
);
|
|
938
1244
|
}
|
|
939
1245
|
|
|
940
|
-
// vite/vite-node.ts
|
|
941
|
-
var import_server = require("vite-node/server");
|
|
942
|
-
var import_client = require("vite-node/client");
|
|
943
|
-
var import_source_map = require("vite-node/source-map");
|
|
944
|
-
async function createContext(viteConfig = {}) {
|
|
945
|
-
await preloadViteEsm();
|
|
946
|
-
const vite2 = importViteEsmSync();
|
|
947
|
-
const devServer = await vite2.createServer(
|
|
948
|
-
vite2.mergeConfig(
|
|
949
|
-
{
|
|
950
|
-
server: {
|
|
951
|
-
preTransformRequests: false,
|
|
952
|
-
hmr: false
|
|
953
|
-
},
|
|
954
|
-
optimizeDeps: {
|
|
955
|
-
noDiscovery: true
|
|
956
|
-
},
|
|
957
|
-
configFile: false,
|
|
958
|
-
envFile: false,
|
|
959
|
-
plugins: []
|
|
960
|
-
},
|
|
961
|
-
viteConfig
|
|
962
|
-
)
|
|
963
|
-
);
|
|
964
|
-
await devServer.pluginContainer.buildStart({});
|
|
965
|
-
const server = new import_server.ViteNodeServer(devServer);
|
|
966
|
-
(0, import_source_map.installSourcemapsSupport)({
|
|
967
|
-
getSourceMap: (source) => server.getSourceMap(source)
|
|
968
|
-
});
|
|
969
|
-
const runner = new import_client.ViteNodeRunner({
|
|
970
|
-
root: devServer.config.root,
|
|
971
|
-
base: devServer.config.base,
|
|
972
|
-
fetchModule(id2) {
|
|
973
|
-
return server.fetchModule(id2);
|
|
974
|
-
},
|
|
975
|
-
resolveId(id2, importer) {
|
|
976
|
-
return server.resolveId(id2, importer);
|
|
977
|
-
}
|
|
978
|
-
});
|
|
979
|
-
return { devServer, server, runner };
|
|
980
|
-
}
|
|
981
|
-
|
|
982
1246
|
// vite/plugin.ts
|
|
983
1247
|
var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "headers"];
|
|
984
1248
|
var CLIENT_ROUTE_EXPORTS = [
|
|
@@ -1012,7 +1276,7 @@ var vmods = [serverBuildId, serverManifestId, browserManifestId];
|
|
|
1012
1276
|
var invalidateVirtualModules = (viteDevServer) => {
|
|
1013
1277
|
vmods.forEach((vmod) => {
|
|
1014
1278
|
let mod = viteDevServer.moduleGraph.getModuleById(
|
|
1015
|
-
|
|
1279
|
+
resolve3(vmod)
|
|
1016
1280
|
);
|
|
1017
1281
|
if (mod) {
|
|
1018
1282
|
viteDevServer.moduleGraph.invalidateModule(mod);
|
|
@@ -1078,8 +1342,8 @@ function dedupe(array2) {
|
|
|
1078
1342
|
return [...new Set(array2)];
|
|
1079
1343
|
}
|
|
1080
1344
|
var writeFileSafe = async (file, contents) => {
|
|
1081
|
-
await
|
|
1082
|
-
await
|
|
1345
|
+
await fse.ensureDir(path4.dirname(file));
|
|
1346
|
+
await fse.writeFile(file, contents);
|
|
1083
1347
|
};
|
|
1084
1348
|
var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
|
|
1085
1349
|
let entries = await Promise.all(
|
|
@@ -1109,7 +1373,7 @@ var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteF
|
|
|
1109
1373
|
};
|
|
1110
1374
|
let [id2, code] = await Promise.all([
|
|
1111
1375
|
resolveId(),
|
|
1112
|
-
readRouteFile?.() ??
|
|
1376
|
+
readRouteFile?.() ?? fse.readFile(routePath, "utf-8"),
|
|
1113
1377
|
// pluginContainer.transform(...) fails if we don't do this first:
|
|
1114
1378
|
moduleGraph.ensureEntryFromUrl(url3, ssr)
|
|
1115
1379
|
]);
|
|
@@ -1136,68 +1400,53 @@ var defaultEntriesDir = path4.resolve(
|
|
|
1136
1400
|
"config",
|
|
1137
1401
|
"defaults"
|
|
1138
1402
|
);
|
|
1139
|
-
var defaultEntries =
|
|
1403
|
+
var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path4.join(defaultEntriesDir, filename3));
|
|
1140
1404
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
1141
1405
|
var reactRouterDevLoadContext = () => ({});
|
|
1142
|
-
var
|
|
1143
|
-
|
|
1144
|
-
let oIsFunction = typeof o === "function";
|
|
1145
|
-
let hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1146
|
-
Object.getOwnPropertyNames(o).forEach(function(prop) {
|
|
1147
|
-
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])) {
|
|
1148
|
-
deepFreeze2(o[prop]);
|
|
1149
|
-
}
|
|
1150
|
-
});
|
|
1151
|
-
return o;
|
|
1152
|
-
};
|
|
1153
|
-
var reactRouterVitePlugin = (_config) => {
|
|
1154
|
-
let reactRouterUserConfig = _config ?? {};
|
|
1155
|
-
reactRouterUserConfig = deepFreeze2(reactRouterUserConfig);
|
|
1406
|
+
var reactRouterVitePlugin = () => {
|
|
1407
|
+
let rootDirectory;
|
|
1156
1408
|
let viteCommand;
|
|
1157
1409
|
let viteUserConfig;
|
|
1158
1410
|
let viteConfigEnv;
|
|
1159
1411
|
let viteConfig;
|
|
1160
1412
|
let cssModulesManifest = {};
|
|
1161
1413
|
let viteChildCompiler = null;
|
|
1162
|
-
let
|
|
1163
|
-
let
|
|
1164
|
-
|
|
1165
|
-
// are linked to a directory outside of node_modules so Vite
|
|
1166
|
-
// treats them as internal code by default.
|
|
1167
|
-
"react-router",
|
|
1168
|
-
"react-router-dom",
|
|
1169
|
-
"@react-router/architect",
|
|
1170
|
-
"@react-router/cloudflare",
|
|
1171
|
-
"@react-router/dev",
|
|
1172
|
-
"@react-router/express",
|
|
1173
|
-
"@react-router/node",
|
|
1174
|
-
"@react-router/serve"
|
|
1175
|
-
] : void 0;
|
|
1414
|
+
let reactRouterConfigLoader;
|
|
1415
|
+
let logger;
|
|
1416
|
+
let firstLoad = true;
|
|
1176
1417
|
let ctx;
|
|
1177
|
-
let updatePluginContext = async ({
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
});
|
|
1418
|
+
let updatePluginContext = async () => {
|
|
1419
|
+
let reactRouterConfig;
|
|
1420
|
+
let reactRouterConfigResult = await reactRouterConfigLoader.getConfig();
|
|
1421
|
+
if (reactRouterConfigResult.ok) {
|
|
1422
|
+
reactRouterConfig = reactRouterConfigResult.value;
|
|
1423
|
+
} else {
|
|
1424
|
+
logger.error(reactRouterConfigResult.error);
|
|
1425
|
+
if (firstLoad) {
|
|
1426
|
+
process.exit(1);
|
|
1427
|
+
}
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1190
1430
|
let { entryClientFilePath, entryServerFilePath } = await resolveEntryFiles({
|
|
1191
1431
|
rootDirectory,
|
|
1192
1432
|
reactRouterConfig
|
|
1193
1433
|
});
|
|
1194
|
-
let publicPath =
|
|
1434
|
+
let publicPath = viteUserConfig.base ?? "/";
|
|
1435
|
+
if (reactRouterConfig.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !reactRouterConfig.basename.startsWith(publicPath)) {
|
|
1436
|
+
logger.error(
|
|
1437
|
+
import_picocolors3.default.red(
|
|
1438
|
+
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
1439
|
+
)
|
|
1440
|
+
);
|
|
1441
|
+
process.exit(1);
|
|
1442
|
+
}
|
|
1195
1443
|
let viteManifestEnabled = viteUserConfig.build?.manifest === true;
|
|
1196
1444
|
let ssrBuildCtx = viteConfigEnv.isSsrBuild && viteCommand === "build" ? {
|
|
1197
1445
|
isSsrBuild: true,
|
|
1198
1446
|
getReactRouterServerManifest: async () => (await generateReactRouterManifestsForBuild()).reactRouterServerManifest,
|
|
1199
1447
|
serverBundleBuildConfig: getServerBundleBuildConfig(viteUserConfig)
|
|
1200
1448
|
} : { isSsrBuild: false };
|
|
1449
|
+
firstLoad = false;
|
|
1201
1450
|
ctx = {
|
|
1202
1451
|
reactRouterConfig,
|
|
1203
1452
|
rootDirectory,
|
|
@@ -1262,7 +1511,7 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1262
1511
|
};`;
|
|
1263
1512
|
};
|
|
1264
1513
|
let loadViteManifest = async (directory) => {
|
|
1265
|
-
let manifestContents = await
|
|
1514
|
+
let manifestContents = await fse.readFile(
|
|
1266
1515
|
path4.resolve(directory, ".vite", "manifest.json"),
|
|
1267
1516
|
"utf-8"
|
|
1268
1517
|
);
|
|
@@ -1271,7 +1520,7 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1271
1520
|
let hasDependency = (name) => {
|
|
1272
1521
|
try {
|
|
1273
1522
|
return Boolean(require.resolve(name, { paths: [ctx.rootDirectory] }));
|
|
1274
|
-
} catch (
|
|
1523
|
+
} catch (err2) {
|
|
1275
1524
|
return false;
|
|
1276
1525
|
}
|
|
1277
1526
|
};
|
|
@@ -1416,15 +1665,19 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1416
1665
|
viteUserConfig = _viteUserConfig;
|
|
1417
1666
|
viteConfigEnv = _viteConfigEnv;
|
|
1418
1667
|
viteCommand = viteConfigEnv.command;
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1668
|
+
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
1669
|
+
prefix: "[react-router]"
|
|
1670
|
+
});
|
|
1671
|
+
rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
1672
|
+
if (viteCommand === "serve") {
|
|
1673
|
+
watch(rootDirectory, {
|
|
1674
|
+
// ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
|
|
1675
|
+
logger: vite2.createLogger("warn", { prefix: "[react-router]" })
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
reactRouterConfigLoader = await createConfigLoader({
|
|
1679
|
+
rootDirectory,
|
|
1680
|
+
watch: viteCommand === "serve"
|
|
1428
1681
|
});
|
|
1429
1682
|
await updatePluginContext();
|
|
1430
1683
|
Object.assign(
|
|
@@ -1459,9 +1712,19 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1459
1712
|
__reactRouterPluginContext: ctx,
|
|
1460
1713
|
appType: viteCommand === "serve" && viteConfigEnv.mode === "production" && ctx.reactRouterConfig.ssr === false ? "spa" : "custom",
|
|
1461
1714
|
ssr: {
|
|
1462
|
-
external: ssrExternals
|
|
1715
|
+
external: ssrExternals,
|
|
1716
|
+
resolve: {
|
|
1717
|
+
conditions: viteCommand === "build" ? [] : ["development"],
|
|
1718
|
+
externalConditions: viteCommand === "build" ? [] : ["development"]
|
|
1719
|
+
}
|
|
1463
1720
|
},
|
|
1464
1721
|
optimizeDeps: {
|
|
1722
|
+
entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
|
|
1723
|
+
ctx.entryClientFilePath,
|
|
1724
|
+
...Object.values(ctx.reactRouterConfig.routes).map(
|
|
1725
|
+
(route) => path4.join(ctx.reactRouterConfig.appDirectory, route.file)
|
|
1726
|
+
)
|
|
1727
|
+
] : [],
|
|
1465
1728
|
include: [
|
|
1466
1729
|
// Pre-bundle React dependencies to avoid React duplicates,
|
|
1467
1730
|
// even if React dependencies are not direct dependencies.
|
|
@@ -1492,7 +1755,8 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1492
1755
|
"react-router",
|
|
1493
1756
|
"react-router/dom",
|
|
1494
1757
|
"react-router-dom"
|
|
1495
|
-
]
|
|
1758
|
+
],
|
|
1759
|
+
conditions: viteCommand === "build" ? [] : ["development"]
|
|
1496
1760
|
},
|
|
1497
1761
|
base: viteUserConfig.base,
|
|
1498
1762
|
// When consumer provides an allow list for files that can be read by
|
|
@@ -1614,8 +1878,8 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1614
1878
|
invariant(viteConfig);
|
|
1615
1879
|
if (viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && viteConfig.build.sourcemap) {
|
|
1616
1880
|
viteConfig.logger.warn(
|
|
1617
|
-
|
|
1618
|
-
"\n" +
|
|
1881
|
+
import_picocolors3.default.yellow(
|
|
1882
|
+
"\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
|
|
1619
1883
|
"This makes your server code publicly",
|
|
1620
1884
|
"visible in the browser. This is highly",
|
|
1621
1885
|
"discouraged! If you insist, ensure that",
|
|
@@ -1650,31 +1914,38 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1650
1914
|
}
|
|
1651
1915
|
}
|
|
1652
1916
|
});
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
if (
|
|
1917
|
+
reactRouterConfigLoader.onChange(
|
|
1918
|
+
async ({
|
|
1919
|
+
result,
|
|
1920
|
+
configCodeUpdated,
|
|
1921
|
+
configChanged,
|
|
1922
|
+
routeConfigChanged
|
|
1923
|
+
}) => {
|
|
1924
|
+
if (!result.ok) {
|
|
1925
|
+
invalidateVirtualModules(viteDevServer);
|
|
1926
|
+
logger.error(result.error, {
|
|
1927
|
+
clear: true,
|
|
1928
|
+
timestamp: true
|
|
1929
|
+
});
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
if (routeConfigChanged) {
|
|
1933
|
+
logger.info(import_picocolors3.default.green("Route config changed."), {
|
|
1934
|
+
clear: true,
|
|
1935
|
+
timestamp: true
|
|
1936
|
+
});
|
|
1937
|
+
} else if (configCodeUpdated) {
|
|
1938
|
+
logger.info(import_picocolors3.default.green("Config updated."), {
|
|
1939
|
+
clear: true,
|
|
1940
|
+
timestamp: true
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
await updatePluginContext();
|
|
1944
|
+
if (configChanged) {
|
|
1674
1945
|
invalidateVirtualModules(viteDevServer);
|
|
1675
1946
|
}
|
|
1676
1947
|
}
|
|
1677
|
-
|
|
1948
|
+
);
|
|
1678
1949
|
return () => {
|
|
1679
1950
|
if (!viteDevServer.config.server.middlewareMode) {
|
|
1680
1951
|
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
@@ -1717,11 +1988,11 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1717
1988
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
1718
1989
|
let src = path4.join(serverBuildDirectory, ssrAssetPath);
|
|
1719
1990
|
let dest = path4.join(clientBuildDirectory, ssrAssetPath);
|
|
1720
|
-
if (!
|
|
1721
|
-
await
|
|
1991
|
+
if (!fse.existsSync(dest)) {
|
|
1992
|
+
await fse.move(src, dest);
|
|
1722
1993
|
movedAssetPaths.push(dest);
|
|
1723
1994
|
} else {
|
|
1724
|
-
await
|
|
1995
|
+
await fse.remove(src);
|
|
1725
1996
|
}
|
|
1726
1997
|
}
|
|
1727
1998
|
let ssrCssPaths = Object.values(ssrViteManifest).flatMap(
|
|
@@ -1729,16 +2000,16 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1729
2000
|
);
|
|
1730
2001
|
await Promise.all(
|
|
1731
2002
|
ssrCssPaths.map(
|
|
1732
|
-
(cssPath) =>
|
|
2003
|
+
(cssPath) => fse.remove(path4.join(serverBuildDirectory, cssPath))
|
|
1733
2004
|
)
|
|
1734
2005
|
);
|
|
1735
2006
|
if (movedAssetPaths.length) {
|
|
1736
2007
|
viteConfig.logger.info(
|
|
1737
2008
|
[
|
|
1738
2009
|
"",
|
|
1739
|
-
`${
|
|
2010
|
+
`${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
|
|
1740
2011
|
...movedAssetPaths.map(
|
|
1741
|
-
(movedAssetPath) =>
|
|
2012
|
+
(movedAssetPath) => import_picocolors3.default.dim(path4.relative(ctx.rootDirectory, movedAssetPath))
|
|
1742
2013
|
),
|
|
1743
2014
|
""
|
|
1744
2015
|
].join("\n")
|
|
@@ -1751,7 +2022,8 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1751
2022
|
serverBuildDirectory,
|
|
1752
2023
|
clientBuildDirectory
|
|
1753
2024
|
);
|
|
1754
|
-
}
|
|
2025
|
+
}
|
|
2026
|
+
if (!ctx.reactRouterConfig.ssr) {
|
|
1755
2027
|
await handleSpaMode(
|
|
1756
2028
|
viteConfig,
|
|
1757
2029
|
ctx.reactRouterConfig,
|
|
@@ -1763,17 +2035,17 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1763
2035
|
viteConfig.logger.info(
|
|
1764
2036
|
[
|
|
1765
2037
|
"Removing the server build in",
|
|
1766
|
-
|
|
2038
|
+
import_picocolors3.default.green(serverBuildDirectory),
|
|
1767
2039
|
"due to ssr:false"
|
|
1768
2040
|
].join(" ")
|
|
1769
2041
|
);
|
|
1770
|
-
|
|
2042
|
+
fse.removeSync(serverBuildDirectory);
|
|
1771
2043
|
}
|
|
1772
2044
|
}
|
|
1773
2045
|
},
|
|
1774
2046
|
async buildEnd() {
|
|
1775
2047
|
await viteChildCompiler?.close();
|
|
1776
|
-
await
|
|
2048
|
+
await reactRouterConfigLoader.close();
|
|
1777
2049
|
}
|
|
1778
2050
|
},
|
|
1779
2051
|
{
|
|
@@ -1798,20 +2070,20 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1798
2070
|
name: "react-router-virtual-modules",
|
|
1799
2071
|
enforce: "pre",
|
|
1800
2072
|
resolveId(id2) {
|
|
1801
|
-
if (vmods.includes(id2)) return
|
|
2073
|
+
if (vmods.includes(id2)) return resolve3(id2);
|
|
1802
2074
|
},
|
|
1803
2075
|
async load(id2) {
|
|
1804
2076
|
switch (id2) {
|
|
1805
|
-
case
|
|
2077
|
+
case resolve3(serverBuildId): {
|
|
1806
2078
|
return await getServerEntry();
|
|
1807
2079
|
}
|
|
1808
|
-
case
|
|
2080
|
+
case resolve3(serverManifestId): {
|
|
1809
2081
|
let reactRouterManifest = ctx.isSsrBuild ? await ctx.getReactRouterServerManifest() : await getReactRouterManifestForDev();
|
|
1810
2082
|
return `export default ${(0, import_jsesc.default)(reactRouterManifest, {
|
|
1811
2083
|
es6: true
|
|
1812
2084
|
})};`;
|
|
1813
2085
|
}
|
|
1814
|
-
case
|
|
2086
|
+
case resolve3(browserManifestId): {
|
|
1815
2087
|
if (viteCommand === "build") {
|
|
1816
2088
|
throw new Error("This module only exists in development");
|
|
1817
2089
|
}
|
|
@@ -1854,7 +2126,7 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1854
2126
|
).join(", ");
|
|
1855
2127
|
throw Error(
|
|
1856
2128
|
[
|
|
1857
|
-
|
|
2129
|
+
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
1858
2130
|
"",
|
|
1859
2131
|
` '${id2}' imported by route '${importerShort}'`,
|
|
1860
2132
|
"",
|
|
@@ -1870,7 +2142,7 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1870
2142
|
}
|
|
1871
2143
|
throw Error(
|
|
1872
2144
|
[
|
|
1873
|
-
|
|
2145
|
+
import_picocolors3.default.red(`Server-only module referenced by client`),
|
|
1874
2146
|
"",
|
|
1875
2147
|
` '${id2}' imported by '${importerShort}'`,
|
|
1876
2148
|
"",
|
|
@@ -1924,7 +2196,7 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1924
2196
|
removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
|
|
1925
2197
|
}
|
|
1926
2198
|
transform(ast);
|
|
1927
|
-
return
|
|
2199
|
+
return generate2(ast, {
|
|
1928
2200
|
sourceMaps: true,
|
|
1929
2201
|
filename: id2,
|
|
1930
2202
|
sourceFileName: filepath
|
|
@@ -1936,10 +2208,10 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1936
2208
|
enforce: "pre",
|
|
1937
2209
|
resolveId(id2) {
|
|
1938
2210
|
if (id2 === injectHmrRuntimeId)
|
|
1939
|
-
return
|
|
2211
|
+
return resolve3(injectHmrRuntimeId);
|
|
1940
2212
|
},
|
|
1941
2213
|
async load(id2) {
|
|
1942
|
-
if (id2 !==
|
|
2214
|
+
if (id2 !== resolve3(injectHmrRuntimeId)) return;
|
|
1943
2215
|
return [
|
|
1944
2216
|
`import RefreshRuntime from "${hmrRuntimeId}"`,
|
|
1945
2217
|
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
@@ -1953,10 +2225,10 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1953
2225
|
name: "react-router-hmr-runtime",
|
|
1954
2226
|
enforce: "pre",
|
|
1955
2227
|
resolveId(id2) {
|
|
1956
|
-
if (id2 === hmrRuntimeId) return
|
|
2228
|
+
if (id2 === hmrRuntimeId) return resolve3(hmrRuntimeId);
|
|
1957
2229
|
},
|
|
1958
2230
|
async load(id2) {
|
|
1959
|
-
if (id2 !==
|
|
2231
|
+
if (id2 !== resolve3(hmrRuntimeId)) return;
|
|
1960
2232
|
let reactRefreshDir = path4.dirname(
|
|
1961
2233
|
require.resolve("react-refresh/package.json")
|
|
1962
2234
|
);
|
|
@@ -1966,8 +2238,8 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
1966
2238
|
);
|
|
1967
2239
|
return [
|
|
1968
2240
|
"const exports = {}",
|
|
1969
|
-
await
|
|
1970
|
-
await
|
|
2241
|
+
await fse.readFile(reactRefreshRuntimePath, "utf8"),
|
|
2242
|
+
await fse.readFile(
|
|
1971
2243
|
require.resolve("./static/refresh-utils.cjs"),
|
|
1972
2244
|
"utf8"
|
|
1973
2245
|
),
|
|
@@ -2047,18 +2319,6 @@ var reactRouterVitePlugin = (_config) => {
|
|
|
2047
2319
|
}
|
|
2048
2320
|
];
|
|
2049
2321
|
};
|
|
2050
|
-
function isInReactRouterMonorepo() {
|
|
2051
|
-
let serverRuntimePath = path4.dirname(
|
|
2052
|
-
require.resolve("@react-router/node/package.json")
|
|
2053
|
-
);
|
|
2054
|
-
let serverRuntimeParentDir = path4.basename(
|
|
2055
|
-
path4.resolve(serverRuntimePath, "..")
|
|
2056
|
-
);
|
|
2057
|
-
return serverRuntimeParentDir === "packages";
|
|
2058
|
-
}
|
|
2059
|
-
function isEqualJson(v1, v2) {
|
|
2060
|
-
return JSON.stringify(v1) === JSON.stringify(v2);
|
|
2061
|
-
}
|
|
2062
2322
|
function addRefreshWrapper(reactRouterConfig, code, id2) {
|
|
2063
2323
|
let route = getRoute(reactRouterConfig, id2);
|
|
2064
2324
|
let acceptExports = route || isRouteEntry(id2) ? [
|
|
@@ -2191,9 +2451,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
2191
2451
|
let html = await response.text();
|
|
2192
2452
|
validatePrerenderedResponse(response, html, "SPA Mode", "/");
|
|
2193
2453
|
validatePrerenderedHtml(html, "SPA Mode");
|
|
2194
|
-
await
|
|
2454
|
+
await fse.writeFile(path4.join(clientBuildDirectory, "index.html"), html);
|
|
2195
2455
|
viteConfig.logger.info(
|
|
2196
|
-
"SPA Mode: index.html has been written to your " +
|
|
2456
|
+
"SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path4.relative(process.cwd(), clientBuildDirectory)) + " directory"
|
|
2197
2457
|
);
|
|
2198
2458
|
}
|
|
2199
2459
|
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
|
|
@@ -2256,7 +2516,12 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
2256
2516
|
clientBuildDirectory,
|
|
2257
2517
|
reactRouterConfig,
|
|
2258
2518
|
viteConfig,
|
|
2259
|
-
data ? {
|
|
2519
|
+
data ? {
|
|
2520
|
+
headers: {
|
|
2521
|
+
...headers,
|
|
2522
|
+
"X-React-Router-Prerender-Data": encodeURI(data)
|
|
2523
|
+
}
|
|
2524
|
+
} : { headers }
|
|
2260
2525
|
);
|
|
2261
2526
|
}
|
|
2262
2527
|
}
|
|
@@ -2306,9 +2571,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
|
|
|
2306
2571
|
validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
|
|
2307
2572
|
let outdir = path4.relative(process.cwd(), clientBuildDirectory);
|
|
2308
2573
|
let outfile = path4.join(outdir, ...normalizedPath.split("/"));
|
|
2309
|
-
await
|
|
2310
|
-
await
|
|
2311
|
-
viteConfig.logger.info(`Prerender: Generated ${
|
|
2574
|
+
await fse.ensureDir(path4.dirname(outfile));
|
|
2575
|
+
await fse.outputFile(outfile, data);
|
|
2576
|
+
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2312
2577
|
return data;
|
|
2313
2578
|
}
|
|
2314
2579
|
async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reactRouterConfig, viteConfig, requestInit) {
|
|
@@ -2325,9 +2590,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
2325
2590
|
}
|
|
2326
2591
|
let outdir = path4.relative(process.cwd(), clientBuildDirectory);
|
|
2327
2592
|
let outfile = path4.join(outdir, ...normalizedPath.split("/"), "index.html");
|
|
2328
|
-
await
|
|
2329
|
-
await
|
|
2330
|
-
viteConfig.logger.info(`Prerender: Generated ${
|
|
2593
|
+
await fse.ensureDir(path4.dirname(outfile));
|
|
2594
|
+
await fse.outputFile(outfile, html);
|
|
2595
|
+
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2331
2596
|
}
|
|
2332
2597
|
async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirectory, reactRouterConfig, viteConfig, requestInit) {
|
|
2333
2598
|
let normalizedPath = `${reactRouterConfig.basename}${prerenderPath}/`.replace(/\/\/+/g, "/").replace(/\/$/g, "");
|
|
@@ -2337,9 +2602,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
2337
2602
|
validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
|
|
2338
2603
|
let outdir = path4.relative(process.cwd(), clientBuildDirectory);
|
|
2339
2604
|
let outfile = path4.join(outdir, ...normalizedPath.split("/"));
|
|
2340
|
-
await
|
|
2341
|
-
await
|
|
2342
|
-
viteConfig.logger.info(`Prerender: Generated ${
|
|
2605
|
+
await fse.ensureDir(path4.dirname(outfile));
|
|
2606
|
+
await fse.outputFile(outfile, text);
|
|
2607
|
+
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2343
2608
|
}
|
|
2344
2609
|
async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig, viteConfig) {
|
|
2345
2610
|
let normalizedPath = `${reactRouterConfig.basename}/__manifest`.replace(
|
|
@@ -2348,10 +2613,10 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
|
|
|
2348
2613
|
);
|
|
2349
2614
|
let outdir = path4.relative(process.cwd(), clientBuildDirectory);
|
|
2350
2615
|
let outfile = path4.join(outdir, ...normalizedPath.split("/"));
|
|
2351
|
-
await
|
|
2616
|
+
await fse.ensureDir(path4.dirname(outfile));
|
|
2352
2617
|
let manifestData = JSON.stringify(build.assets.routes);
|
|
2353
|
-
await
|
|
2354
|
-
viteConfig.logger.info(`Prerender: Generated ${
|
|
2618
|
+
await fse.outputFile(outfile, manifestData);
|
|
2619
|
+
viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
|
|
2355
2620
|
}
|
|
2356
2621
|
function validatePrerenderedResponse(response, html, prefix, path5) {
|
|
2357
2622
|
if (response.status !== 200) {
|