vite 8.3.0-beta.1 → 8.3.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/dist/node/chunks/node.js +77 -54
- package/package.json +1 -1
package/dist/node/chunks/node.js
CHANGED
|
@@ -628,7 +628,7 @@ var BaseEnvironment = class extends PartialEnvironment {
|
|
|
628
628
|
};
|
|
629
629
|
//#endregion
|
|
630
630
|
//#region package.json
|
|
631
|
-
var version = "8.3.0
|
|
631
|
+
var version = "8.3.0";
|
|
632
632
|
//#endregion
|
|
633
633
|
//#region src/node/constants.ts
|
|
634
634
|
const ROLLUP_HOOKS = [
|
|
@@ -2057,8 +2057,9 @@ function isNodeBuiltin(id) {
|
|
|
2057
2057
|
if (id.startsWith(NODE_BUILTIN_NAMESPACE)) return true;
|
|
2058
2058
|
return nodeBuiltins.includes(id);
|
|
2059
2059
|
}
|
|
2060
|
+
const inNodeModulesRE = /(?:^|[\\/])node_modules(?:[\\/]|$)/;
|
|
2060
2061
|
function isInNodeModules(id) {
|
|
2061
|
-
return
|
|
2062
|
+
return inNodeModulesRE.test(id);
|
|
2062
2063
|
}
|
|
2063
2064
|
function moduleListContains(moduleList, id) {
|
|
2064
2065
|
return moduleList?.some((m) => m === id || id.startsWith(withTrailingSlash(m)));
|
|
@@ -2253,6 +2254,13 @@ function isFilePathFormatExplicit(filePath, packageCache) {
|
|
|
2253
2254
|
}
|
|
2254
2255
|
const splitRE = /\r?\n/g;
|
|
2255
2256
|
const range = 2;
|
|
2257
|
+
/**
|
|
2258
|
+
* `splitRE` treats both LF and CRLF as a line terminator, so the terminator
|
|
2259
|
+
* following a line is 2 characters long when the source uses CRLF.
|
|
2260
|
+
*/
|
|
2261
|
+
function lineTerminatorLengthAt(source, index) {
|
|
2262
|
+
return source[index] === "\r" ? 2 : 1;
|
|
2263
|
+
}
|
|
2256
2264
|
function pad(source, n = 2) {
|
|
2257
2265
|
return source.split(splitRE).map((l) => ` `.repeat(n) + l).join(`\n`);
|
|
2258
2266
|
}
|
|
@@ -2261,7 +2269,10 @@ function posToNumber(source, pos) {
|
|
|
2261
2269
|
const lines = source.split(splitRE);
|
|
2262
2270
|
const { line, column } = pos;
|
|
2263
2271
|
let start = 0;
|
|
2264
|
-
for (let i = 0; i < line - 1 && i < lines.length; i++)
|
|
2272
|
+
for (let i = 0; i < line - 1 && i < lines.length; i++) {
|
|
2273
|
+
start += lines[i].length;
|
|
2274
|
+
start += lineTerminatorLengthAt(source, start);
|
|
2275
|
+
}
|
|
2265
2276
|
return start + column;
|
|
2266
2277
|
}
|
|
2267
2278
|
function numberToPos(source, offset) {
|
|
@@ -2319,12 +2330,12 @@ function generateCodeFrame(source, start = 0, end) {
|
|
|
2319
2330
|
const underline = "^".repeat(Math.min(length, MAX_DISPLAY_LEN));
|
|
2320
2331
|
res.push(`${" ".repeat(lineNumberWidth)}| ` + underline);
|
|
2321
2332
|
}
|
|
2322
|
-
count +=
|
|
2333
|
+
count += lineTerminatorLengthAt(source, count) + lineLength;
|
|
2323
2334
|
}
|
|
2324
2335
|
}
|
|
2325
2336
|
break;
|
|
2326
2337
|
}
|
|
2327
|
-
count
|
|
2338
|
+
count += lineTerminatorLengthAt(source, count);
|
|
2328
2339
|
}
|
|
2329
2340
|
return res.join("\n");
|
|
2330
2341
|
}
|
|
@@ -19349,6 +19360,13 @@ const rewriteOriginHeader = (proxyReq, options, config) => {
|
|
|
19349
19360
|
}
|
|
19350
19361
|
}
|
|
19351
19362
|
};
|
|
19363
|
+
function createProxyContextMatcher(context) {
|
|
19364
|
+
if (context[0] === "^") {
|
|
19365
|
+
const regex = new RegExp(context);
|
|
19366
|
+
return (url) => regex.test(url);
|
|
19367
|
+
}
|
|
19368
|
+
return (url) => url.startsWith(context);
|
|
19369
|
+
}
|
|
19352
19370
|
function proxyMiddleware(httpServer, options, config) {
|
|
19353
19371
|
const proxies = {};
|
|
19354
19372
|
Object.keys(options).forEach((context) => {
|
|
@@ -19384,72 +19402,77 @@ function proxyMiddleware(httpServer, options, config) {
|
|
|
19384
19402
|
});
|
|
19385
19403
|
});
|
|
19386
19404
|
});
|
|
19387
|
-
proxies[context] =
|
|
19405
|
+
proxies[context] = {
|
|
19406
|
+
proxy,
|
|
19407
|
+
options: { ...opts },
|
|
19408
|
+
match: createProxyContextMatcher(context)
|
|
19409
|
+
};
|
|
19388
19410
|
});
|
|
19389
19411
|
if (httpServer) httpServer.on("upgrade", async (req, socket, head) => {
|
|
19390
19412
|
const url = req.url;
|
|
19391
|
-
for (const context in proxies)
|
|
19392
|
-
const
|
|
19393
|
-
if (
|
|
19394
|
-
if (opts.
|
|
19395
|
-
|
|
19396
|
-
|
|
19397
|
-
|
|
19398
|
-
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
|
|
19402
|
-
|
|
19403
|
-
|
|
19413
|
+
for (const context in proxies) {
|
|
19414
|
+
const { proxy, options: opts, match } = proxies[context];
|
|
19415
|
+
if (match(url)) {
|
|
19416
|
+
if (opts.ws || opts.target?.toString().startsWith("ws:") || opts.target?.toString().startsWith("wss:")) {
|
|
19417
|
+
if (opts.bypass) try {
|
|
19418
|
+
const bypassResult = await opts.bypass(req, void 0, opts);
|
|
19419
|
+
if (typeof bypassResult === "string") {
|
|
19420
|
+
debug$8?.(`bypass: ${req.url} -> ${bypassResult}`);
|
|
19421
|
+
req.url = bypassResult;
|
|
19422
|
+
return;
|
|
19423
|
+
}
|
|
19424
|
+
if (bypassResult === false) {
|
|
19425
|
+
debug$8?.(`bypass: ${req.url} -> 404`);
|
|
19426
|
+
socket.end("HTTP/1.1 404 Not Found\r\n\r\n", "");
|
|
19427
|
+
return;
|
|
19428
|
+
}
|
|
19429
|
+
} catch (err) {
|
|
19430
|
+
config.logger.error(`${import_picocolors.default.red(`ws proxy bypass error:`)}\n${err.stack}`, {
|
|
19431
|
+
timestamp: true,
|
|
19432
|
+
error: err
|
|
19433
|
+
});
|
|
19404
19434
|
return;
|
|
19405
19435
|
}
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
error: err
|
|
19410
|
-
});
|
|
19436
|
+
if (opts.rewrite) req.url = opts.rewrite(url);
|
|
19437
|
+
debug$8?.(`${req.url} -> ws ${opts.target}`);
|
|
19438
|
+
proxy.ws(req, socket, head);
|
|
19411
19439
|
return;
|
|
19412
19440
|
}
|
|
19413
|
-
if (opts.rewrite) req.url = opts.rewrite(url);
|
|
19414
|
-
debug$8?.(`${req.url} -> ws ${opts.target}`);
|
|
19415
|
-
proxy.ws(req, socket, head);
|
|
19416
|
-
return;
|
|
19417
19441
|
}
|
|
19418
19442
|
}
|
|
19419
19443
|
});
|
|
19420
19444
|
return async function viteProxyMiddleware(req, res, next) {
|
|
19421
19445
|
const url = req.url;
|
|
19422
|
-
for (const context in proxies)
|
|
19423
|
-
const
|
|
19424
|
-
|
|
19425
|
-
|
|
19426
|
-
|
|
19427
|
-
|
|
19428
|
-
|
|
19429
|
-
|
|
19430
|
-
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
|
|
19435
|
-
|
|
19436
|
-
|
|
19446
|
+
for (const context in proxies) {
|
|
19447
|
+
const { proxy, options: opts, match } = proxies[context];
|
|
19448
|
+
if (match(url)) {
|
|
19449
|
+
const options = {};
|
|
19450
|
+
if (opts.bypass) try {
|
|
19451
|
+
const bypassResult = await opts.bypass(req, res, opts);
|
|
19452
|
+
if (typeof bypassResult === "string") {
|
|
19453
|
+
debug$8?.(`bypass: ${req.url} -> ${bypassResult}`);
|
|
19454
|
+
req.url = bypassResult;
|
|
19455
|
+
if (res.writableEnded) return;
|
|
19456
|
+
return next();
|
|
19457
|
+
}
|
|
19458
|
+
if (bypassResult === false) {
|
|
19459
|
+
debug$8?.(`bypass: ${req.url} -> 404`);
|
|
19460
|
+
res.statusCode = 404;
|
|
19461
|
+
return res.end();
|
|
19462
|
+
}
|
|
19463
|
+
} catch (e) {
|
|
19464
|
+
debug$8?.(`bypass: ${req.url} -> ${e}`);
|
|
19465
|
+
return next(e);
|
|
19437
19466
|
}
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
19467
|
+
debug$8?.(`${req.url} -> ${opts.target || opts.forward}`);
|
|
19468
|
+
if (opts.rewrite) req.url = opts.rewrite(req.url);
|
|
19469
|
+
proxy.web(req, res, options);
|
|
19470
|
+
return;
|
|
19441
19471
|
}
|
|
19442
|
-
debug$8?.(`${req.url} -> ${opts.target || opts.forward}`);
|
|
19443
|
-
if (opts.rewrite) req.url = opts.rewrite(req.url);
|
|
19444
|
-
proxy.web(req, res, options);
|
|
19445
|
-
return;
|
|
19446
19472
|
}
|
|
19447
19473
|
next();
|
|
19448
19474
|
};
|
|
19449
19475
|
}
|
|
19450
|
-
function doesProxyContextMatchUrl(context, url) {
|
|
19451
|
-
return context[0] === "^" && new RegExp(context).test(url) || url.startsWith(context);
|
|
19452
|
-
}
|
|
19453
19476
|
//#endregion
|
|
19454
19477
|
//#region src/node/server/middlewares/rejectInvalidRequest.ts
|
|
19455
19478
|
/**
|
|
@@ -26412,7 +26435,7 @@ function preload(baseModule, deps, importerUrl) {
|
|
|
26412
26435
|
link.addEventListener("load", res);
|
|
26413
26436
|
link.addEventListener("error", () => rej(/* @__PURE__ */ new Error(`Unable to preload CSS for ${dep}`)));
|
|
26414
26437
|
});
|
|
26415
|
-
}));
|
|
26438
|
+
}).filter((p) => p !== void 0));
|
|
26416
26439
|
}
|
|
26417
26440
|
function handlePreloadError(err) {
|
|
26418
26441
|
const e = new Event("vite:preloadError", { cancelable: true });
|