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.
@@ -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-beta.1";
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 id.includes("node_modules");
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++) start += lines[i].length + 1;
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 += lineLength + 1;
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] = [proxy, { ...opts }];
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) if (doesProxyContextMatchUrl(context, url)) {
19392
- const [proxy, opts] = proxies[context];
19393
- if (opts.ws || opts.target?.toString().startsWith("ws:") || opts.target?.toString().startsWith("wss:")) {
19394
- if (opts.bypass) try {
19395
- const bypassResult = await opts.bypass(req, void 0, opts);
19396
- if (typeof bypassResult === "string") {
19397
- debug$8?.(`bypass: ${req.url} -> ${bypassResult}`);
19398
- req.url = bypassResult;
19399
- return;
19400
- }
19401
- if (bypassResult === false) {
19402
- debug$8?.(`bypass: ${req.url} -> 404`);
19403
- socket.end("HTTP/1.1 404 Not Found\r\n\r\n", "");
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
- } catch (err) {
19407
- config.logger.error(`${import_picocolors.default.red(`ws proxy bypass error:`)}\n${err.stack}`, {
19408
- timestamp: true,
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) if (doesProxyContextMatchUrl(context, url)) {
19423
- const [proxy, opts] = proxies[context];
19424
- const options = {};
19425
- if (opts.bypass) try {
19426
- const bypassResult = await opts.bypass(req, res, opts);
19427
- if (typeof bypassResult === "string") {
19428
- debug$8?.(`bypass: ${req.url} -> ${bypassResult}`);
19429
- req.url = bypassResult;
19430
- if (res.writableEnded) return;
19431
- return next();
19432
- }
19433
- if (bypassResult === false) {
19434
- debug$8?.(`bypass: ${req.url} -> 404`);
19435
- res.statusCode = 404;
19436
- return res.end();
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
- } catch (e) {
19439
- debug$8?.(`bypass: ${req.url} -> ${e}`);
19440
- return next(e);
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 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "8.3.0-beta.1",
3
+ "version": "8.3.0",
4
4
  "description": "Native-ESM powered web dev build tool",
5
5
  "keywords": [
6
6
  "build-tool",