@reckona/mreact-router 0.0.132 → 0.0.135
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/README.md +1 -1
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/cloudflare.js.map +1 -1
- package/dist/adapters/static.js +5 -1
- package/dist/adapters/static.js.map +1 -1
- package/dist/build.d.ts +1 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +136 -41
- package/dist/build.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +167 -8
- package/dist/client.js.map +1 -1
- package/dist/http.d.ts +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +7 -1
- package/dist/http.js.map +1 -1
- package/dist/module-runner.d.ts +4 -1
- package/dist/module-runner.d.ts.map +1 -1
- package/dist/module-runner.js +3 -2
- package/dist/module-runner.js.map +1 -1
- package/dist/render.d.ts +6 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +84 -46
- package/dist/render.js.map +1 -1
- package/dist/routes.js +1 -1
- package/dist/routes.js.map +1 -1
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +110 -17
- package/dist/serve.js.map +1 -1
- package/dist/vite-plugin-cache-key.d.ts +2 -1
- package/dist/vite-plugin-cache-key.d.ts.map +1 -1
- package/dist/vite-plugin-cache-key.js +9 -0
- package/dist/vite-plugin-cache-key.js.map +1 -1
- package/dist/vite.d.ts +2 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +2 -0
- package/dist/vite.js.map +1 -1
- package/package.json +11 -11
- package/src/adapters/cloudflare.ts +1 -1
- package/src/adapters/static.ts +7 -1
- package/src/build.ts +201 -53
- package/src/client.ts +288 -17
- package/src/http.ts +9 -1
- package/src/module-runner.ts +8 -2
- package/src/render.ts +117 -21
- package/src/routes.ts +1 -1
- package/src/serve.ts +167 -18
- package/src/vite-plugin-cache-key.ts +12 -1
- package/src/vite.ts +4 -0
package/src/client.ts
CHANGED
|
@@ -920,10 +920,16 @@ async function inferClientRouteModuleSource(options: {
|
|
|
920
920
|
if (exported.clientBoundaryModule) {
|
|
921
921
|
clientProxy = true;
|
|
922
922
|
} else if (exported.clientBoundaryExportNames.length > 0) {
|
|
923
|
-
|
|
924
|
-
|
|
923
|
+
if (reference.exportAll) {
|
|
924
|
+
for (const exportName of exported.clientBoundaryExportNames) {
|
|
925
925
|
clientBoundaryExportNames.add(exportName);
|
|
926
926
|
}
|
|
927
|
+
} else {
|
|
928
|
+
for (const specifier of reference.specifiers) {
|
|
929
|
+
if (exported.clientBoundaryExportNames.includes(specifier.localName)) {
|
|
930
|
+
clientBoundaryExportNames.add(specifier.exportedName);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
927
933
|
}
|
|
928
934
|
} else if (exported.client) {
|
|
929
935
|
nestedClient = true;
|
|
@@ -1110,10 +1116,15 @@ function isStyleModuleSpecifier(source: string): boolean {
|
|
|
1110
1116
|
const styleModuleExtensions = new Set([".css", ".less", ".sass", ".scss", ".styl", ".stylus"]);
|
|
1111
1117
|
|
|
1112
1118
|
function isClientBoundaryFallbackEligibleSource(source: string): boolean {
|
|
1119
|
+
if (hasClientBoundaryFallbackUnsafeBrowserGlobal(source)) {
|
|
1120
|
+
return false;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1113
1123
|
const destructuredCallbackPropNames = destructuredPropsCallbackNames(source);
|
|
1114
1124
|
const callbackPropNames = new Set([
|
|
1115
1125
|
...destructuredCallbackPropNames,
|
|
1116
1126
|
...propsCallbackAliasNames(source),
|
|
1127
|
+
...memberCallbackNames(source),
|
|
1117
1128
|
]);
|
|
1118
1129
|
const sourceWithoutComponentCallbackProps = source.replaceAll(
|
|
1119
1130
|
/<[A-Z][A-Za-z0-9_$.]*(?:\s[\s\S]*?)?>/gu,
|
|
@@ -1130,36 +1141,97 @@ function isClientBoundaryFallbackEligibleSource(source: string): boolean {
|
|
|
1130
1141
|
);
|
|
1131
1142
|
|
|
1132
1143
|
for (const callbackName of callbackPropNames) {
|
|
1144
|
+
const escapedCallbackName = escapeRegExp(callbackName);
|
|
1145
|
+
const callbackHandlerAttributePattern = new RegExp(
|
|
1146
|
+
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*[^{}]*\b${escapedCallbackName}\b[^{}]*\}`,
|
|
1147
|
+
"gu",
|
|
1148
|
+
);
|
|
1133
1149
|
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1134
1150
|
new RegExp(
|
|
1135
|
-
String.raw`\b(?:const|let|var)\s+${
|
|
1136
|
-
callbackName,
|
|
1137
|
-
)}\s*=\s*props\.[A-Za-z_$][\w$]*\s*;?`,
|
|
1151
|
+
String.raw`\b(?:const|let|var)\s+${escapedCallbackName}\s*=\s*props\.[A-Za-z_$][\w$]*\s*;?`,
|
|
1138
1152
|
"gu",
|
|
1139
1153
|
),
|
|
1140
1154
|
"",
|
|
1141
1155
|
);
|
|
1142
1156
|
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1143
1157
|
new RegExp(
|
|
1144
|
-
String.raw`\
|
|
1145
|
-
|
|
1146
|
-
|
|
1158
|
+
String.raw`\b(?:const|let|var)\s+${escapedCallbackName}\s*=\s*[^;\n]+\.${escapedCallbackName}\s*;?`,
|
|
1159
|
+
"gu",
|
|
1160
|
+
),
|
|
1161
|
+
"",
|
|
1162
|
+
);
|
|
1163
|
+
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1164
|
+
new RegExp(
|
|
1165
|
+
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*\?\s*[^{}]*:\s*undefined\s*\}`,
|
|
1166
|
+
"gu",
|
|
1167
|
+
),
|
|
1168
|
+
"",
|
|
1169
|
+
);
|
|
1170
|
+
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1171
|
+
new RegExp(
|
|
1172
|
+
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*(?:===|==)\s*(?:undefined|null)\s*\?\s*undefined\s*:\s*[^{}]*\}`,
|
|
1173
|
+
"gu",
|
|
1174
|
+
),
|
|
1175
|
+
"",
|
|
1176
|
+
);
|
|
1177
|
+
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1178
|
+
new RegExp(
|
|
1179
|
+
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*(?:undefined|null)\s*(?:===|==)\s*${escapedCallbackName}\s*\?\s*undefined\s*:\s*[^{}]*\}`,
|
|
1180
|
+
"gu",
|
|
1181
|
+
),
|
|
1182
|
+
"",
|
|
1183
|
+
);
|
|
1184
|
+
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1185
|
+
new RegExp(
|
|
1186
|
+
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*(?:!==|!=)\s*(?:undefined|null)\s*\?\s*[^{}]*:\s*undefined\s*\}`,
|
|
1187
|
+
"gu",
|
|
1188
|
+
),
|
|
1189
|
+
"",
|
|
1190
|
+
);
|
|
1191
|
+
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1192
|
+
new RegExp(
|
|
1193
|
+
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*typeof\s+${escapedCallbackName}\s*===\s*["']function["']\s*\?\s*[^{}]*:\s*undefined\s*\}`,
|
|
1194
|
+
"gu",
|
|
1195
|
+
),
|
|
1196
|
+
"",
|
|
1197
|
+
);
|
|
1198
|
+
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1199
|
+
new RegExp(
|
|
1200
|
+
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*\?\?\s*undefined\s*\}`,
|
|
1147
1201
|
"gu",
|
|
1148
1202
|
),
|
|
1149
1203
|
"",
|
|
1150
1204
|
);
|
|
1151
1205
|
|
|
1152
|
-
if (
|
|
1206
|
+
if (
|
|
1207
|
+
hasCallbackAbsenceGuard(
|
|
1208
|
+
sourceWithoutComponentCallbackProps.replaceAll(callbackHandlerAttributePattern, ""),
|
|
1209
|
+
callbackName,
|
|
1210
|
+
)
|
|
1211
|
+
) {
|
|
1153
1212
|
sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
|
|
1154
|
-
|
|
1155
|
-
String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*[^{}]*\b${escapeRegExp(
|
|
1156
|
-
callbackName,
|
|
1157
|
-
)}\b[^{}]*\}`,
|
|
1158
|
-
"gu",
|
|
1159
|
-
),
|
|
1213
|
+
callbackHandlerAttributePattern,
|
|
1160
1214
|
"",
|
|
1161
1215
|
);
|
|
1162
1216
|
}
|
|
1217
|
+
sourceWithoutGuardedUndefinedCallbacks = removeSafeCallbackHandlerAttributes(
|
|
1218
|
+
sourceWithoutGuardedUndefinedCallbacks,
|
|
1219
|
+
callbackName,
|
|
1220
|
+
{
|
|
1221
|
+
externalAbsenceGuard: hasCallbackAbsenceGuard(
|
|
1222
|
+
sourceWithoutComponentCallbackProps.replaceAll(callbackHandlerAttributePattern, ""),
|
|
1223
|
+
callbackName,
|
|
1224
|
+
),
|
|
1225
|
+
},
|
|
1226
|
+
);
|
|
1227
|
+
|
|
1228
|
+
if (
|
|
1229
|
+
new RegExp(String.raw`\b${escapedCallbackName}\s*\(`, "u").test(
|
|
1230
|
+
sourceWithoutGuardedUndefinedCallbacks,
|
|
1231
|
+
)
|
|
1232
|
+
) {
|
|
1233
|
+
return false;
|
|
1234
|
+
}
|
|
1163
1235
|
}
|
|
1164
1236
|
|
|
1165
1237
|
return (
|
|
@@ -1168,6 +1240,14 @@ function isClientBoundaryFallbackEligibleSource(source: string): boolean {
|
|
|
1168
1240
|
);
|
|
1169
1241
|
}
|
|
1170
1242
|
|
|
1243
|
+
function hasClientBoundaryFallbackUnsafeBrowserGlobal(source: string): boolean {
|
|
1244
|
+
const sourceWithoutTypeofGuards = source.replaceAll(
|
|
1245
|
+
/\btypeof\s+(?:window|document|localStorage)\s*(?:(?:={2,3}|!={1,2})\s*["']undefined["'])?/gu,
|
|
1246
|
+
"",
|
|
1247
|
+
);
|
|
1248
|
+
return /\b(?:window|document|localStorage)\b/u.test(sourceWithoutTypeofGuards);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1171
1251
|
function propsCallbackAliasNames(source: string): Set<string> {
|
|
1172
1252
|
const names = new Set<string>();
|
|
1173
1253
|
|
|
@@ -1185,6 +1265,65 @@ function propsCallbackAliasNames(source: string): Set<string> {
|
|
|
1185
1265
|
}
|
|
1186
1266
|
}
|
|
1187
1267
|
|
|
1268
|
+
for (const match of source.matchAll(
|
|
1269
|
+
/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*\(\s*props\s+as\s+[^)]+\)\.([A-Za-z_$][\w$]*)\b/gu,
|
|
1270
|
+
)) {
|
|
1271
|
+
const localName = match[1];
|
|
1272
|
+
const propName = match[2];
|
|
1273
|
+
|
|
1274
|
+
if (
|
|
1275
|
+
localName !== undefined &&
|
|
1276
|
+
(isCallbackPropName(propName) || isCallbackPropName(localName))
|
|
1277
|
+
) {
|
|
1278
|
+
names.add(localName);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
for (const match of source.matchAll(
|
|
1283
|
+
/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*\(\s*props\s*\)\.([A-Za-z_$][\w$]*)\b/gu,
|
|
1284
|
+
)) {
|
|
1285
|
+
const localName = match[1];
|
|
1286
|
+
const propName = match[2];
|
|
1287
|
+
|
|
1288
|
+
if (
|
|
1289
|
+
localName !== undefined &&
|
|
1290
|
+
(isCallbackPropName(propName) || isCallbackPropName(localName))
|
|
1291
|
+
) {
|
|
1292
|
+
names.add(localName);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
for (const match of source.matchAll(
|
|
1297
|
+
/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*[^;\n]+\.([A-Za-z_$][\w$]*)\s*;?/gu,
|
|
1298
|
+
)) {
|
|
1299
|
+
const localName = match[1];
|
|
1300
|
+
const propName = match[2];
|
|
1301
|
+
|
|
1302
|
+
if (
|
|
1303
|
+
localName !== undefined &&
|
|
1304
|
+
(isCallbackPropName(propName) || isCallbackPropName(localName))
|
|
1305
|
+
) {
|
|
1306
|
+
names.add(localName);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
let added = true;
|
|
1311
|
+
while (added) {
|
|
1312
|
+
added = false;
|
|
1313
|
+
for (const match of source.matchAll(
|
|
1314
|
+
/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([A-Za-z_$][\w$]*)\b/gu,
|
|
1315
|
+
)) {
|
|
1316
|
+
const localName = match[1];
|
|
1317
|
+
const sourceName = match[2];
|
|
1318
|
+
|
|
1319
|
+
if (localName !== undefined && sourceName !== undefined && names.has(sourceName)) {
|
|
1320
|
+
const previousSize = names.size;
|
|
1321
|
+
names.add(localName);
|
|
1322
|
+
added ||= names.size !== previousSize;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1188
1327
|
return names;
|
|
1189
1328
|
}
|
|
1190
1329
|
|
|
@@ -1197,6 +1336,109 @@ function hasCallbackAbsenceGuard(source: string, name: string): boolean {
|
|
|
1197
1336
|
).test(source);
|
|
1198
1337
|
}
|
|
1199
1338
|
|
|
1339
|
+
function memberCallbackNames(source: string): Set<string> {
|
|
1340
|
+
const names = new Set<string>();
|
|
1341
|
+
|
|
1342
|
+
for (const match of source.matchAll(/\.([A-Za-z_$][\w$]*)\b/gu)) {
|
|
1343
|
+
const memberName = match[1];
|
|
1344
|
+
|
|
1345
|
+
if (memberName !== undefined && isCallbackPropName(memberName)) {
|
|
1346
|
+
names.add(memberName);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
return names;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
function removeSafeCallbackHandlerAttributes(
|
|
1354
|
+
source: string,
|
|
1355
|
+
callbackName: string,
|
|
1356
|
+
options: { externalAbsenceGuard: boolean },
|
|
1357
|
+
): string {
|
|
1358
|
+
const attributePattern = /\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{/gu;
|
|
1359
|
+
let result = "";
|
|
1360
|
+
let cursor = 0;
|
|
1361
|
+
|
|
1362
|
+
for (const match of source.matchAll(attributePattern)) {
|
|
1363
|
+
const start = match.index;
|
|
1364
|
+
const expressionStart = start + match[0].length;
|
|
1365
|
+
const end = matchingBraceEnd(source, expressionStart - 1);
|
|
1366
|
+
|
|
1367
|
+
if (end === undefined) {
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
const expression = source.slice(expressionStart, end);
|
|
1372
|
+
if (isSafeCallbackHandlerExpression(expression, callbackName, options)) {
|
|
1373
|
+
result += source.slice(cursor, start);
|
|
1374
|
+
cursor = end + 1;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
return cursor === 0 ? source : result + source.slice(cursor);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
function matchingBraceEnd(source: string, openBraceIndex: number): number | undefined {
|
|
1382
|
+
let depth = 0;
|
|
1383
|
+
let quote: "\"" | "'" | "`" | undefined;
|
|
1384
|
+
let escaped = false;
|
|
1385
|
+
|
|
1386
|
+
for (let index = openBraceIndex; index < source.length; index += 1) {
|
|
1387
|
+
const char = source[index];
|
|
1388
|
+
|
|
1389
|
+
if (quote !== undefined) {
|
|
1390
|
+
if (escaped) {
|
|
1391
|
+
escaped = false;
|
|
1392
|
+
} else if (char === "\\") {
|
|
1393
|
+
escaped = true;
|
|
1394
|
+
} else if (char === quote) {
|
|
1395
|
+
quote = undefined;
|
|
1396
|
+
}
|
|
1397
|
+
continue;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
if (char === "\"" || char === "'" || char === "`") {
|
|
1401
|
+
quote = char;
|
|
1402
|
+
continue;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
if (char === "{") {
|
|
1406
|
+
depth += 1;
|
|
1407
|
+
continue;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
if (char === "}") {
|
|
1411
|
+
depth -= 1;
|
|
1412
|
+
if (depth === 0) {
|
|
1413
|
+
return index;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
return undefined;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
function isSafeCallbackHandlerExpression(
|
|
1422
|
+
expression: string,
|
|
1423
|
+
callbackName: string,
|
|
1424
|
+
options: { externalAbsenceGuard: boolean },
|
|
1425
|
+
): boolean {
|
|
1426
|
+
const escapedName = escapeRegExp(callbackName);
|
|
1427
|
+
if (!new RegExp(String.raw`\b${escapedName}\b`, "u").test(expression)) {
|
|
1428
|
+
return false;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
if (new RegExp(String.raw`\b${escapedName}\s*\(`, "u").test(expression)) {
|
|
1432
|
+
return false;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
return (
|
|
1436
|
+
new RegExp(String.raw`\b${escapedName}\s*\?\.\s*\(`, "u").test(expression) ||
|
|
1437
|
+
new RegExp(String.raw`^\s*${escapedName}\s*\?\?\s*undefined\s*$`, "u").test(expression) ||
|
|
1438
|
+
options.externalAbsenceGuard
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1200
1442
|
function destructuredPropsCallbackNames(source: string): Set<string> {
|
|
1201
1443
|
const names = new Set<string>();
|
|
1202
1444
|
|
|
@@ -1205,7 +1447,31 @@ function destructuredPropsCallbackNames(source: string): Set<string> {
|
|
|
1205
1447
|
}
|
|
1206
1448
|
|
|
1207
1449
|
for (const match of source.matchAll(
|
|
1208
|
-
/\
|
|
1450
|
+
/\{[^{}]*:\s*\{([^{}]+)\}\s*(?:=\s*\{\})?[^{}]*\}/gu,
|
|
1451
|
+
)) {
|
|
1452
|
+
addDestructuredCallbackNames(names, match[1] ?? "");
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
for (const match of source.matchAll(
|
|
1456
|
+
/\bfunction(?:\s+[A-Za-z_$][\w$]*(?:<[^>()]+>)?)?\s*\(\s*\{([^}]+)\}/gu,
|
|
1457
|
+
)) {
|
|
1458
|
+
addDestructuredCallbackNames(names, match[1] ?? "");
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
for (const match of source.matchAll(
|
|
1462
|
+
/\b(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*(?:async\s*)?\(?\s*\{([^}]+)\}\s*(?::\s*[^)=]+)?\)?\s*=>/gu,
|
|
1463
|
+
)) {
|
|
1464
|
+
addDestructuredCallbackNames(names, match[1] ?? "");
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
for (const match of source.matchAll(
|
|
1468
|
+
/\bexport\s+default\s+(?:async\s*)?\(?\s*\{([^}]+)\}\s*(?::\s*[^)=]+)?\)?\s*=>/gu,
|
|
1469
|
+
)) {
|
|
1470
|
+
addDestructuredCallbackNames(names, match[1] ?? "");
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
for (const match of source.matchAll(
|
|
1474
|
+
/\b(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*function(?:\s+[A-Za-z_$][\w$]*)?\s*\(\s*\{([^}]+)\}/gu,
|
|
1209
1475
|
)) {
|
|
1210
1476
|
addDestructuredCallbackNames(names, match[1] ?? "");
|
|
1211
1477
|
}
|
|
@@ -4315,5 +4581,10 @@ function errorMessage(error: unknown): string {
|
|
|
4315
4581
|
}
|
|
4316
4582
|
|
|
4317
4583
|
function escapeScriptJson(value: string): string {
|
|
4318
|
-
return value
|
|
4584
|
+
return value
|
|
4585
|
+
.replaceAll("&", "\\u0026")
|
|
4586
|
+
.replaceAll("<", "\\u003c")
|
|
4587
|
+
.replaceAll(">", "\\u003e")
|
|
4588
|
+
.replaceAll("\u2028", "\\u2028")
|
|
4589
|
+
.replaceAll("\u2029", "\\u2029");
|
|
4319
4590
|
}
|
package/src/http.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { ServerResponse } from "node:http";
|
|
|
2
2
|
import type { IncomingMessage } from "node:http";
|
|
3
3
|
import { Readable } from "node:stream";
|
|
4
4
|
|
|
5
|
+
const rawUrlByRequest = new WeakMap<Request, string>();
|
|
6
|
+
|
|
5
7
|
export function nodeRequestToWebRequest(
|
|
6
8
|
incoming: IncomingMessage,
|
|
7
9
|
origin: string,
|
|
@@ -32,7 +34,13 @@ export function nodeRequestToWebRequest(
|
|
|
32
34
|
init.duplex = "half";
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
const request = new Request(new URL(incoming.url ?? "/", origin), init);
|
|
38
|
+
rawUrlByRequest.set(request, incoming.url ?? "/");
|
|
39
|
+
return request;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function rawNodeRequestUrl(request: Request): string | undefined {
|
|
43
|
+
return rawUrlByRequest.get(request);
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
/**
|
package/src/module-runner.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type InlineConfig,
|
|
14
14
|
type PluginOption,
|
|
15
15
|
type RunnableDevEnvironment,
|
|
16
|
+
type UserConfig,
|
|
16
17
|
} from "vite";
|
|
17
18
|
import { resolveWorkspacePackageFile } from "./workspace-packages.js";
|
|
18
19
|
import {
|
|
@@ -36,7 +37,7 @@ import {
|
|
|
36
37
|
inferClientRouteModule,
|
|
37
38
|
type ClientRouteInferenceCache,
|
|
38
39
|
} from "./client-route-inference.js";
|
|
39
|
-
import { vitePluginsCacheKey } from "./vite-plugin-cache-key.js";
|
|
40
|
+
import { viteDefineCacheKey, vitePluginsCacheKey } from "./vite-plugin-cache-key.js";
|
|
40
41
|
|
|
41
42
|
const runnerConfig = {
|
|
42
43
|
configFile: false,
|
|
@@ -81,6 +82,7 @@ export function routerModuleRunnerRuntimeCacheStats(): RouterRuntimeCacheStat[]
|
|
|
81
82
|
export async function importAppRouterSourceModule<T>(options: {
|
|
82
83
|
cacheKey?: string | undefined;
|
|
83
84
|
code: string;
|
|
85
|
+
define?: UserConfig["define"] | undefined;
|
|
84
86
|
externalizeAppSourceModuleDirs?: readonly string[] | undefined;
|
|
85
87
|
label: string;
|
|
86
88
|
plugins?: readonly RouterCompatPlugin[] | undefined;
|
|
@@ -122,6 +124,7 @@ export async function importAppRouterSourceModule<T>(options: {
|
|
|
122
124
|
|
|
123
125
|
async function importAppRouterSourceModuleWithoutCache<T>(options: {
|
|
124
126
|
code: string;
|
|
127
|
+
define?: UserConfig["define"] | undefined;
|
|
125
128
|
externalizeAppSourceModuleDirs?: readonly string[] | undefined;
|
|
126
129
|
label: string;
|
|
127
130
|
plugins?: readonly RouterCompatPlugin[] | undefined;
|
|
@@ -273,6 +276,7 @@ export async function importAppRouterBuiltFileModule<T>(options: {
|
|
|
273
276
|
|
|
274
277
|
export async function bundleAppRouterSourceModule(options: {
|
|
275
278
|
code: string;
|
|
279
|
+
define?: UserConfig["define"] | undefined;
|
|
276
280
|
externalizeAppSourceModuleDirs?: readonly string[] | undefined;
|
|
277
281
|
label: string;
|
|
278
282
|
plugins?: readonly RouterCompatPlugin[] | undefined;
|
|
@@ -284,6 +288,7 @@ export async function bundleAppRouterSourceModule(options: {
|
|
|
284
288
|
}): Promise<string> {
|
|
285
289
|
const output = await bundleRouterModule({
|
|
286
290
|
code: options.code,
|
|
291
|
+
define: options.define,
|
|
287
292
|
externalizeAppSourceModuleDirs: options.externalizeAppSourceModuleDirs,
|
|
288
293
|
filename: options.sourcefile ?? join(options.resolveDir ?? process.cwd(), "module.js"),
|
|
289
294
|
platform: "node",
|
|
@@ -334,6 +339,7 @@ export function fileImportMetaUrlPlugin(): RouterCompatPlugin {
|
|
|
334
339
|
|
|
335
340
|
interface ServerSourceTransformOptions {
|
|
336
341
|
clientRouteInferenceCache?: ClientRouteInferenceCache | undefined;
|
|
342
|
+
define?: UserConfig["define"] | undefined;
|
|
337
343
|
dev: boolean;
|
|
338
344
|
serverModules?: ReadonlyMap<string, BuiltServerModuleArtifact> | undefined;
|
|
339
345
|
serverOutput: ServerOutputMode;
|
|
@@ -411,7 +417,7 @@ async function transformServerSourceFile(
|
|
|
411
417
|
console.warn(formatClientRouteInferenceDiagnostic(diagnostic));
|
|
412
418
|
}
|
|
413
419
|
|
|
414
|
-
const cacheKey = `${options.serverOutput}\0${options.dev ? "dev" : "prod"}\0${options.filename}\0${transformedSourceHash}\0${clientInference.clientBoundaryImports.join("\0")}\0${clientInference.clientBoundaryFallbackImports.join("\0")}\0${vitePluginsCacheKey(options.vitePlugins)}`;
|
|
420
|
+
const cacheKey = `${options.serverOutput}\0${options.dev ? "dev" : "prod"}\0${options.filename}\0${transformedSourceHash}\0${clientInference.clientBoundaryImports.join("\0")}\0${clientInference.clientBoundaryFallbackImports.join("\0")}\0${viteDefineCacheKey(options.define)}\0${vitePluginsCacheKey(options.vitePlugins)}`;
|
|
415
421
|
const cached = readRouterRuntimeCacheEntry(
|
|
416
422
|
serverSourceTransformCache,
|
|
417
423
|
cacheKey,
|