vite 8.2.0 → 8.2.1

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.
@@ -71,7 +71,7 @@ var __copyProps = (to, from, except, desc) => {
71
71
  }
72
72
  return to;
73
73
  };
74
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
74
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
75
75
  value: mod,
76
76
  enumerable: true
77
77
  }) : target, mod));
@@ -635,6 +635,8 @@ const ENV_PUBLIC_PATH = `/@vite/env`;
635
635
  const VITE_PACKAGE_DIR = resolve(fileURLToPath(new URL("../../../src/node/constants.ts", import.meta.url)), "../../..");
636
636
  const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
637
637
  const BUNDLED_DEV_CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/bundledDevClient.mjs");
638
+ /** URL filename the bundled-dev server serves the vite client under */
639
+ const BUNDLED_DEV_CLIENT_FILENAME = "bundledDevClient.mjs";
638
640
  const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
639
641
  const CLIENT_DIR = path.dirname(CLIENT_ENTRY);
640
642
  const KNOWN_ASSET_TYPES = [
@@ -732,7 +734,7 @@ function hasMoreVlq$1(reader, max) {
732
734
  if (reader.pos >= max) return false;
733
735
  return reader.peek() !== comma$1;
734
736
  }
735
- var bufLength = 1024 * 16;
737
+ var bufLength = 16384;
736
738
  var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
737
739
  return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
738
740
  } } : { decode(buf) {
@@ -1746,7 +1748,8 @@ function getMatcherString$1(id, resolutionBase) {
1746
1748
  const createFilter$2 = function createFilter(include, exclude, options) {
1747
1749
  const resolutionBase = options && options.resolve;
1748
1750
  const getMatcher = (id) => id instanceof RegExp ? id : { test: (what) => {
1749
- return pm(getMatcherString$1(id, resolutionBase), { dot: true })(what);
1751
+ const pattern = getMatcherString$1(id, resolutionBase);
1752
+ return pm(pattern, { dot: true })(what);
1750
1753
  } };
1751
1754
  const includeMatchers = ensureArray(include).map(getMatcher);
1752
1755
  const excludeMatchers = ensureArray(exclude).map(getMatcher);
@@ -1948,10 +1951,13 @@ function loadPackageData(pkgPath) {
1948
1951
  let hasSideEffects;
1949
1952
  if (typeof sideEffects === "boolean") hasSideEffects = () => sideEffects;
1950
1953
  else if (Array.isArray(sideEffects)) if (sideEffects.length <= 0) hasSideEffects = () => false;
1951
- else hasSideEffects = createFilter$1(sideEffects.map((sideEffect) => {
1952
- if (sideEffect.includes("/")) return sideEffect;
1953
- return `**/${sideEffect}`;
1954
- }), null, { resolve: pkgDir });
1954
+ else {
1955
+ const finalPackageSideEffects = sideEffects.map((sideEffect) => {
1956
+ if (sideEffect.includes("/")) return sideEffect;
1957
+ return `**/${sideEffect}`;
1958
+ });
1959
+ hasSideEffects = createFilter$1(finalPackageSideEffects, null, { resolve: pkgDir });
1960
+ }
1955
1961
  else hasSideEffects = () => null;
1956
1962
  const resolvedCache = {};
1957
1963
  return {
@@ -3163,7 +3169,8 @@ function formatAndTruncateFileList(files) {
3163
3169
  truncated
3164
3170
  };
3165
3171
  }
3166
- const hashbangRE = /^#!.*\n/;
3172
+ const lineTerminatorRE = /[\r\n\u2028\u2029]$/;
3173
+ const hashbangRE = /^#![^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029])?/;
3167
3174
  function getFileStartIndex(code) {
3168
3175
  return hashbangRE.exec(code)?.[0].length ?? 0;
3169
3176
  }
@@ -3293,7 +3300,7 @@ function printServerUrls(urls, optionsHost, info) {
3293
3300
  const interfaceName = urls.networkInterfaceNames?.[index];
3294
3301
  let suffix = "";
3295
3302
  if (interfaceName) {
3296
- const label = interfaceName.length > maxNetworkInterfaceNameLength ? `${interfaceName.slice(0, maxNetworkInterfaceNameLength - 1)}…` : interfaceName;
3303
+ const label = interfaceName.length > maxNetworkInterfaceNameLength ? `${interfaceName.slice(0, 19)}…` : interfaceName;
3297
3304
  suffix = " ".repeat(networkUrlMaxLength - url.length + 2) + import_picocolors.default.dim(label);
3298
3305
  }
3299
3306
  info(` ${import_picocolors.default.green("➜")} ${import_picocolors.default.bold("Network")}: ${colorUrl(url)}${suffix}`);
@@ -3570,7 +3577,7 @@ var Worker$1 = class {
3570
3577
  _queue;
3571
3578
  constructor(fn, options = {}) {
3572
3579
  this._isModule = options.type === "module";
3573
- this._code = genWorkerCode(fn, this._isModule, 5 * 1e3, options.parentFunctions ?? {});
3580
+ this._code = genWorkerCode(fn, this._isModule, 5e3, options.parentFunctions ?? {});
3574
3581
  this._parentFunctions = options.parentFunctions ?? {};
3575
3582
  const defaultMax = Math.max(1, (os.availableParallelism?.() ?? os.cpus().length) - 1);
3576
3583
  this._max = options.max || defaultMax;
@@ -4189,8 +4196,6 @@ function convertEsbuildConfigToOxcConfig(esbuildConfig, logger) {
4189
4196
  jsxOptions.runtime = "classic";
4190
4197
  if (esbuildTransformOptions.jsxFactory) jsxOptions.pragma = esbuildTransformOptions.jsxFactory;
4191
4198
  if (esbuildTransformOptions.jsxFragment) jsxOptions.pragmaFrag = esbuildTransformOptions.jsxFragment;
4192
- break;
4193
- default: break;
4194
4199
  }
4195
4200
  if (esbuildTransformOptions.jsxDev !== void 0) jsxOptions.development = esbuildTransformOptions.jsxDev;
4196
4201
  if (esbuildTransformOptions.jsxSideEffects !== void 0) jsxOptions.pure = !esbuildTransformOptions.jsxSideEffects;
@@ -5891,9 +5896,10 @@ function loadEnv(mode, envDir, prefixes = "VITE_") {
5891
5896
  if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0) process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV;
5892
5897
  if (parsed.BROWSER && process.env.BROWSER === void 0) process.env.BROWSER = parsed.BROWSER;
5893
5898
  if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0) process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
5899
+ const processEnv = { ...process.env };
5894
5900
  (0, import_main.expand)({
5895
5901
  parsed,
5896
- processEnv: { ...process.env }
5902
+ processEnv
5897
5903
  });
5898
5904
  for (const [key, value] of Object.entries(parsed)) if (prefixes.some((prefix) => key.startsWith(prefix))) env[key] = value;
5899
5905
  for (const prefix of prefixes) Object.assign(env, getEnvs({ prefix }));
@@ -7236,9 +7242,7 @@ var require_vary = /* @__PURE__ */ __commonJSMin(((exports, module) => {
7236
7242
  list.push(header.substring(start, end));
7237
7243
  start = end = i + 1;
7238
7244
  break;
7239
- default:
7240
- end = i + 1;
7241
- break;
7245
+ default: end = i + 1;
7242
7246
  }
7243
7247
  list.push(header.substring(start, end));
7244
7248
  return list;
@@ -11576,6 +11580,22 @@ async function readFileIfExists(value) {
11576
11580
  if (typeof value === "string") return fsp.readFile(path.resolve(value)).catch(() => value);
11577
11581
  return value;
11578
11582
  }
11583
+ async function getAvailableEphemeralPort(specifiedHost) {
11584
+ for (let attempt = 0; attempt < 3; attempt++) {
11585
+ let port = 0;
11586
+ let available = true;
11587
+ for (const host of [...wildcardHosts, specifiedHost]) {
11588
+ const availablePort = await tryListen(port, host).catch(() => port);
11589
+ if (availablePort == null) {
11590
+ available = false;
11591
+ break;
11592
+ }
11593
+ port = availablePort;
11594
+ }
11595
+ if (available) return port;
11596
+ }
11597
+ return null;
11598
+ }
11579
11599
  async function isPortAvailable(port) {
11580
11600
  for (const host of wildcardHosts) if (!await tryListen(port, host).catch(() => true)) return false;
11581
11601
  return true;
@@ -11584,10 +11604,11 @@ function tryListen(port, host) {
11584
11604
  return new Promise((resolve) => {
11585
11605
  const server = net.createServer();
11586
11606
  server.once("error", (e) => {
11587
- server.close(() => resolve(e.code !== "EADDRINUSE"));
11607
+ server.close(() => resolve(e.code === "EADDRINUSE" ? null : port));
11588
11608
  });
11589
11609
  server.once("listening", () => {
11590
- server.close(() => resolve(true));
11610
+ const address = server.address();
11611
+ server.close(() => resolve(typeof address === "object" && address ? address.port : port));
11591
11612
  });
11592
11613
  server.listen(port, host);
11593
11614
  });
@@ -11615,6 +11636,14 @@ async function tryBindServer(httpServer, port, host) {
11615
11636
  const MAX_PORT = 65535;
11616
11637
  async function httpServerStart(httpServer, serverOptions) {
11617
11638
  const { port: startPort, strictPort, host, logger } = serverOptions;
11639
+ if (startPort === 0) {
11640
+ const port = await getAvailableEphemeralPort(host);
11641
+ if (port == null) throw new Error("No available ephemeral port found");
11642
+ const result = await tryBindServer(httpServer, port, host);
11643
+ if (result.success) return port;
11644
+ if (result.error.code !== "EADDRINUSE") throw result.error;
11645
+ throw new Error(`Port ${port} is already in use`);
11646
+ }
11618
11647
  for (let port = startPort; port <= MAX_PORT; port++) {
11619
11648
  const portAvailableOnWildcard = await isPortAvailable(port);
11620
11649
  if (strictPort) {
@@ -11649,9 +11678,7 @@ function setClientErrorHandler(server, logger) {
11649
11678
  case "ERR_HTTP_REQUEST_TIMEOUT":
11650
11679
  msg = "408 Request Timeout";
11651
11680
  break;
11652
- default:
11653
- msg = "400 Bad Request";
11654
- break;
11681
+ default: msg = "400 Bad Request";
11655
11682
  }
11656
11683
  if (err.code === "ECONNRESET" || !socket.writable) return;
11657
11684
  socket.end(`HTTP/1.1 ${msg}\r\nConnection: close\r\n\r\n`);
@@ -12033,7 +12060,6 @@ function analyze(expression) {
12033
12060
  if (node.param) {
12034
12061
  for (const name of extract_names(node.param)) if (node.param) current_scope.declarations.set(name, node.param);
12035
12062
  }
12036
- break;
12037
12063
  }
12038
12064
  context.next();
12039
12065
  if (map.has(node) && current_scope !== null && current_scope.parent) current_scope = current_scope.parent;
@@ -12133,9 +12159,7 @@ function extract_identifiers(param, nodes = []) {
12133
12159
  case "RestElement":
12134
12160
  extract_identifiers(param.argument, nodes);
12135
12161
  break;
12136
- case "AssignmentPattern":
12137
- extract_identifiers(param.left, nodes);
12138
- break;
12162
+ case "AssignmentPattern": extract_identifiers(param.left, nodes);
12139
12163
  }
12140
12164
  return nodes;
12141
12165
  }
@@ -13214,7 +13238,8 @@ var require_which = /* @__PURE__ */ __commonJSMin(((exports, module) => {
13214
13238
  const getNotFoundError = (cmd) => Object.assign(/* @__PURE__ */ new Error(`not found: ${cmd}`), { code: "ENOENT" });
13215
13239
  const getPathInfo = (cmd, opt) => {
13216
13240
  const colon = opt.colon || COLON;
13217
- const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [...isWindows ? [process.cwd()] : [], ...(opt.path || process.env.PATH || "").split(colon)];
13241
+ const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [...isWindows ? [process.cwd()] : [], ...(opt.path || process.env.PATH ||
13242
+ /* istanbul ignore next: very unusual */ "").split(colon)];
13218
13243
  const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
13219
13244
  const pathExt = isWindows ? pathExtExe.split(colon) : [""];
13220
13245
  if (isWindows) {
@@ -14957,7 +14982,7 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
14957
14982
  const { mask: applyMask, toBuffer } = require_buffer_util();
14958
14983
  const kByteLength = Symbol("kByteLength");
14959
14984
  const maskBuffer = Buffer.alloc(4);
14960
- const RANDOM_POOL_SIZE = 8 * 1024;
14985
+ const RANDOM_POOL_SIZE = 8192;
14961
14986
  let randomPool;
14962
14987
  let randomPoolPointer = RANDOM_POOL_SIZE;
14963
14988
  const DEFAULT = 0;
@@ -16343,9 +16368,9 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
16343
16368
  autoPong: true,
16344
16369
  closeTimeout: CLOSE_TIMEOUT,
16345
16370
  protocolVersion: protocolVersions[1],
16346
- maxBufferedChunks: 256 * 1024,
16347
- maxFragments: 16 * 1024,
16348
- maxPayload: 100 * 1024 * 1024,
16371
+ maxBufferedChunks: 262144,
16372
+ maxFragments: 16384,
16373
+ maxPayload: 104857600,
16349
16374
  skipUTF8Validation: false,
16350
16375
  perMessageDeflate: true,
16351
16376
  followRedirects: false,
@@ -17022,9 +17047,9 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
17022
17047
  options = {
17023
17048
  allowSynchronousEvents: true,
17024
17049
  autoPong: true,
17025
- maxBufferedChunks: 256 * 1024,
17026
- maxFragments: 16 * 1024,
17027
- maxPayload: 100 * 1024 * 1024,
17050
+ maxBufferedChunks: 262144,
17051
+ maxFragments: 16384,
17052
+ maxPayload: 104857600,
17028
17053
  skipUTF8Validation: false,
17029
17054
  perMessageDeflate: false,
17030
17055
  handleProtocols: null,
@@ -17995,7 +18020,7 @@ var require_follow_redirects = /* @__PURE__ */ __commonJSMin(((exports, module)
17995
18020
  function wrap(protocols) {
17996
18021
  var exports$1 = {
17997
18022
  maxRedirects: 21,
17998
- maxBodyLength: 10 * 1024 * 1024
18023
+ maxBodyLength: 10485760
17999
18024
  };
18000
18025
  var nativeProtocols = {};
18001
18026
  Object.keys(protocols).forEach(function(scheme) {
@@ -20703,402 +20728,404 @@ function getModuleTypeFromId(id) {
20703
20728
  }
20704
20729
  }
20705
20730
  //#endregion
20706
- //#region ../../node_modules/.pnpm/strip-literal@3.1.0/node_modules/strip-literal/dist/index.mjs
20707
- var import_js_tokens = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
20708
- var HashbangComment;
20709
- var Identifier;
20710
- var JSXIdentifier;
20711
- var JSXPunctuator;
20712
- var JSXString;
20713
- var JSXText;
20714
- var KeywordsWithExpressionAfter;
20715
- var KeywordsWithNoLineTerminatorAfter;
20716
- var LineTerminatorSequence;
20717
- var MultiLineComment;
20718
- var Newline;
20719
- var NumericLiteral;
20720
- var Punctuator;
20721
- var RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:[^\]\\\n\r\u2028\u2029]+|\\.)*\]?|[^\/[\\\n\r\u2028\u2029]+|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/uy;
20722
- var SingleLineComment;
20723
- var StringLiteral;
20724
- var Template;
20725
- var TokensNotPrecedingObjectLiteral;
20726
- var TokensPrecedingExpression;
20727
- var WhiteSpace;
20728
- Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
20729
- Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]+|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/uy;
20730
- StringLiteral = /(['"])(?:[^'"\\\n\r]+|(?!\1)['"]|\\(?:\r\n|[^]))*(\1)?/y;
20731
- NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
20732
- Template = /[`}](?:[^`\\$]+|\\[^]|\$(?!\{))*(`|\$\{)?/y;
20733
- WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/uy;
20734
- LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
20735
- MultiLineComment = /\/\*(?:[^*]+|\*(?!\/))*(\*\/)?/y;
20736
- SingleLineComment = /\/\/.*/y;
20737
- HashbangComment = /^#!.*/;
20738
- JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
20739
- JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/uy;
20740
- JSXString = /(['"])(?:[^'"]+|(?!\1)['"])*(\1)?/y;
20741
- JSXText = /[^<>{}]+/y;
20742
- TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
20743
- TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
20744
- KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
20745
- KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
20746
- Newline = RegExp(LineTerminatorSequence.source);
20747
- module.exports = function* (input, { jsx = false } = {}) {
20748
- var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
20749
- ({length} = input);
20750
- lastIndex = 0;
20751
- lastSignificantToken = "";
20752
- stack = [{ tag: "JS" }];
20753
- braces = [];
20754
- parenNesting = 0;
20755
- postfixIncDec = false;
20756
- if (match = HashbangComment.exec(input)) {
20757
- yield {
20758
- type: "HashbangComment",
20759
- value: match[0]
20760
- };
20761
- lastIndex = match[0].length;
20762
- }
20763
- while (lastIndex < length) {
20764
- mode = stack[stack.length - 1];
20765
- switch (mode.tag) {
20766
- case "JS":
20767
- case "JSNonExpressionParen":
20768
- case "InterpolationInTemplate":
20769
- case "InterpolationInJSX":
20770
- if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
20771
- RegularExpressionLiteral.lastIndex = lastIndex;
20772
- if (match = RegularExpressionLiteral.exec(input)) {
20773
- lastIndex = RegularExpressionLiteral.lastIndex;
20774
- lastSignificantToken = match[0];
20775
- postfixIncDec = true;
20776
- yield {
20777
- type: "RegularExpressionLiteral",
20778
- value: match[0],
20779
- closed: match[1] !== void 0 && match[1] !== "\\"
20780
- };
20781
- continue;
20782
- }
20731
+ //#region ../../node_modules/.pnpm/js-tokens@10.0.0/node_modules/js-tokens/index.js
20732
+ var HashbangComment;
20733
+ var Identifier;
20734
+ var JSXIdentifier;
20735
+ var JSXPunctuator;
20736
+ var JSXString;
20737
+ var JSXText;
20738
+ var KeywordsWithExpressionAfter;
20739
+ var KeywordsWithNoLineTerminatorAfter;
20740
+ var LineTerminatorSequence;
20741
+ var MultiLineComment;
20742
+ var Newline;
20743
+ var NumericLiteral;
20744
+ var Punctuator;
20745
+ var RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:[^\]\\\n\r\u2028\u2029]+|\\.)*\]?|[^\/[\\\n\r\u2028\u2029]+|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/uy;
20746
+ var SingleLineComment;
20747
+ var StringLiteral;
20748
+ var Template;
20749
+ var TokensNotPrecedingObjectLiteral;
20750
+ var TokensPrecedingExpression;
20751
+ var WhiteSpace;
20752
+ var jsTokens;
20753
+ Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
20754
+ Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]+|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/uy;
20755
+ StringLiteral = /(['"])(?:[^'"\\\n\r]+|(?!\1)['"]|\\(?:\r\n|[^]))*(\1)?/y;
20756
+ NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
20757
+ Template = /[`}](?:[^`\\$]+|\\[^]|\$(?!\{))*(`|\$\{)?/y;
20758
+ WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/uy;
20759
+ LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
20760
+ MultiLineComment = /\/\*(?:[^*]+|\*(?!\/))*(\*\/)?/y;
20761
+ SingleLineComment = /\/\/.*/y;
20762
+ HashbangComment = /^#!.*/;
20763
+ JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
20764
+ JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/uy;
20765
+ JSXString = /(['"])(?:[^'"]+|(?!\1)['"])*(\1)?/y;
20766
+ JSXText = /[^<>{}]+/y;
20767
+ TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
20768
+ TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
20769
+ KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
20770
+ KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
20771
+ Newline = RegExp(LineTerminatorSequence.source);
20772
+ jsTokens = function* (input, { jsx = false } = {}) {
20773
+ var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
20774
+ ({length} = input);
20775
+ lastIndex = 0;
20776
+ lastSignificantToken = "";
20777
+ stack = [{ tag: "JS" }];
20778
+ braces = [];
20779
+ parenNesting = 0;
20780
+ postfixIncDec = false;
20781
+ if (match = HashbangComment.exec(input)) {
20782
+ yield {
20783
+ type: "HashbangComment",
20784
+ value: match[0]
20785
+ };
20786
+ lastIndex = match[0].length;
20787
+ }
20788
+ while (lastIndex < length) {
20789
+ mode = stack[stack.length - 1];
20790
+ switch (mode.tag) {
20791
+ case "JS":
20792
+ case "JSNonExpressionParen":
20793
+ case "InterpolationInTemplate":
20794
+ case "InterpolationInJSX":
20795
+ if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
20796
+ RegularExpressionLiteral.lastIndex = lastIndex;
20797
+ if (match = RegularExpressionLiteral.exec(input)) {
20798
+ lastIndex = RegularExpressionLiteral.lastIndex;
20799
+ lastSignificantToken = match[0];
20800
+ postfixIncDec = true;
20801
+ yield {
20802
+ type: "RegularExpressionLiteral",
20803
+ value: match[0],
20804
+ closed: match[1] !== void 0 && match[1] !== "\\"
20805
+ };
20806
+ continue;
20783
20807
  }
20784
- Punctuator.lastIndex = lastIndex;
20785
- if (match = Punctuator.exec(input)) {
20786
- punctuator = match[0];
20787
- nextLastIndex = Punctuator.lastIndex;
20788
- nextLastSignificantToken = punctuator;
20789
- switch (punctuator) {
20790
- case "(":
20791
- if (lastSignificantToken === "?NonExpressionParenKeyword") stack.push({
20792
- tag: "JSNonExpressionParen",
20793
- nesting: parenNesting
20794
- });
20795
- parenNesting++;
20796
- postfixIncDec = false;
20797
- break;
20798
- case ")":
20799
- parenNesting--;
20800
- postfixIncDec = true;
20801
- if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
20802
- stack.pop();
20803
- nextLastSignificantToken = "?NonExpressionParenEnd";
20804
- postfixIncDec = false;
20805
- }
20806
- break;
20807
- case "{":
20808
- Punctuator.lastIndex = 0;
20809
- isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
20810
- braces.push(isExpression);
20808
+ }
20809
+ Punctuator.lastIndex = lastIndex;
20810
+ if (match = Punctuator.exec(input)) {
20811
+ punctuator = match[0];
20812
+ nextLastIndex = Punctuator.lastIndex;
20813
+ nextLastSignificantToken = punctuator;
20814
+ switch (punctuator) {
20815
+ case "(":
20816
+ if (lastSignificantToken === "?NonExpressionParenKeyword") stack.push({
20817
+ tag: "JSNonExpressionParen",
20818
+ nesting: parenNesting
20819
+ });
20820
+ parenNesting++;
20821
+ postfixIncDec = false;
20822
+ break;
20823
+ case ")":
20824
+ parenNesting--;
20825
+ postfixIncDec = true;
20826
+ if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
20827
+ stack.pop();
20828
+ nextLastSignificantToken = "?NonExpressionParenEnd";
20811
20829
  postfixIncDec = false;
20812
- break;
20813
- case "}":
20814
- switch (mode.tag) {
20815
- case "InterpolationInTemplate":
20816
- if (braces.length === mode.nesting) {
20817
- Template.lastIndex = lastIndex;
20818
- match = Template.exec(input);
20819
- lastIndex = Template.lastIndex;
20820
- lastSignificantToken = match[0];
20821
- if (match[1] === "${") {
20822
- lastSignificantToken = "?InterpolationInTemplate";
20823
- postfixIncDec = false;
20824
- yield {
20825
- type: "TemplateMiddle",
20826
- value: match[0]
20827
- };
20828
- } else {
20829
- stack.pop();
20830
- postfixIncDec = true;
20831
- yield {
20832
- type: "TemplateTail",
20833
- value: match[0],
20834
- closed: match[1] === "`"
20835
- };
20836
- }
20837
- continue;
20830
+ }
20831
+ break;
20832
+ case "{":
20833
+ Punctuator.lastIndex = 0;
20834
+ isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
20835
+ braces.push(isExpression);
20836
+ postfixIncDec = false;
20837
+ break;
20838
+ case "}":
20839
+ switch (mode.tag) {
20840
+ case "InterpolationInTemplate":
20841
+ if (braces.length === mode.nesting) {
20842
+ Template.lastIndex = lastIndex;
20843
+ match = Template.exec(input);
20844
+ lastIndex = Template.lastIndex;
20845
+ lastSignificantToken = match[0];
20846
+ if (match[1] === "${") {
20847
+ lastSignificantToken = "?InterpolationInTemplate";
20848
+ postfixIncDec = false;
20849
+ yield {
20850
+ type: "TemplateMiddle",
20851
+ value: match[0]
20852
+ };
20853
+ } else {
20854
+ stack.pop();
20855
+ postfixIncDec = true;
20856
+ yield {
20857
+ type: "TemplateTail",
20858
+ value: match[0],
20859
+ closed: match[1] === "`"
20860
+ };
20838
20861
  }
20839
- break;
20840
- case "InterpolationInJSX": if (braces.length === mode.nesting) {
20841
- stack.pop();
20842
- lastIndex += 1;
20843
- lastSignificantToken = "}";
20844
- yield {
20845
- type: "JSXPunctuator",
20846
- value: "}"
20847
- };
20848
20862
  continue;
20849
20863
  }
20850
- }
20851
- postfixIncDec = braces.pop();
20852
- nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
20853
- break;
20854
- case "]":
20855
- postfixIncDec = true;
20856
- break;
20857
- case "++":
20858
- case "--":
20859
- nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
20860
- break;
20861
- case "<":
20862
- if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
20863
- stack.push({ tag: "JSXTag" });
20864
+ break;
20865
+ case "InterpolationInJSX": if (braces.length === mode.nesting) {
20866
+ stack.pop();
20864
20867
  lastIndex += 1;
20865
- lastSignificantToken = "<";
20868
+ lastSignificantToken = "}";
20866
20869
  yield {
20867
20870
  type: "JSXPunctuator",
20868
- value: punctuator
20871
+ value: "}"
20869
20872
  };
20870
20873
  continue;
20871
20874
  }
20872
- postfixIncDec = false;
20873
- break;
20874
- default: postfixIncDec = false;
20875
- }
20876
- lastIndex = nextLastIndex;
20877
- lastSignificantToken = nextLastSignificantToken;
20878
- yield {
20879
- type: "Punctuator",
20880
- value: punctuator
20881
- };
20882
- continue;
20875
+ }
20876
+ postfixIncDec = braces.pop();
20877
+ nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
20878
+ break;
20879
+ case "]":
20880
+ postfixIncDec = true;
20881
+ break;
20882
+ case "++":
20883
+ case "--":
20884
+ nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
20885
+ break;
20886
+ case "<":
20887
+ if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
20888
+ stack.push({ tag: "JSXTag" });
20889
+ lastIndex += 1;
20890
+ lastSignificantToken = "<";
20891
+ yield {
20892
+ type: "JSXPunctuator",
20893
+ value: punctuator
20894
+ };
20895
+ continue;
20896
+ }
20897
+ postfixIncDec = false;
20898
+ break;
20899
+ default: postfixIncDec = false;
20883
20900
  }
20884
- Identifier.lastIndex = lastIndex;
20885
- if (match = Identifier.exec(input)) {
20886
- lastIndex = Identifier.lastIndex;
20887
- nextLastSignificantToken = match[0];
20888
- switch (match[0]) {
20889
- case "for":
20890
- case "if":
20891
- case "while":
20892
- case "with": if (lastSignificantToken !== "." && lastSignificantToken !== "?.") nextLastSignificantToken = "?NonExpressionParenKeyword";
20893
- }
20894
- lastSignificantToken = nextLastSignificantToken;
20895
- postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
20901
+ lastIndex = nextLastIndex;
20902
+ lastSignificantToken = nextLastSignificantToken;
20903
+ yield {
20904
+ type: "Punctuator",
20905
+ value: punctuator
20906
+ };
20907
+ continue;
20908
+ }
20909
+ Identifier.lastIndex = lastIndex;
20910
+ if (match = Identifier.exec(input)) {
20911
+ lastIndex = Identifier.lastIndex;
20912
+ nextLastSignificantToken = match[0];
20913
+ switch (match[0]) {
20914
+ case "for":
20915
+ case "if":
20916
+ case "while":
20917
+ case "with": if (lastSignificantToken !== "." && lastSignificantToken !== "?.") nextLastSignificantToken = "?NonExpressionParenKeyword";
20918
+ }
20919
+ lastSignificantToken = nextLastSignificantToken;
20920
+ postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
20921
+ yield {
20922
+ type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
20923
+ value: match[0]
20924
+ };
20925
+ continue;
20926
+ }
20927
+ StringLiteral.lastIndex = lastIndex;
20928
+ if (match = StringLiteral.exec(input)) {
20929
+ lastIndex = StringLiteral.lastIndex;
20930
+ lastSignificantToken = match[0];
20931
+ postfixIncDec = true;
20932
+ yield {
20933
+ type: "StringLiteral",
20934
+ value: match[0],
20935
+ closed: match[2] !== void 0
20936
+ };
20937
+ continue;
20938
+ }
20939
+ NumericLiteral.lastIndex = lastIndex;
20940
+ if (match = NumericLiteral.exec(input)) {
20941
+ lastIndex = NumericLiteral.lastIndex;
20942
+ lastSignificantToken = match[0];
20943
+ postfixIncDec = true;
20944
+ yield {
20945
+ type: "NumericLiteral",
20946
+ value: match[0]
20947
+ };
20948
+ continue;
20949
+ }
20950
+ Template.lastIndex = lastIndex;
20951
+ if (match = Template.exec(input)) {
20952
+ lastIndex = Template.lastIndex;
20953
+ lastSignificantToken = match[0];
20954
+ if (match[1] === "${") {
20955
+ lastSignificantToken = "?InterpolationInTemplate";
20956
+ stack.push({
20957
+ tag: "InterpolationInTemplate",
20958
+ nesting: braces.length
20959
+ });
20960
+ postfixIncDec = false;
20896
20961
  yield {
20897
- type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
20962
+ type: "TemplateHead",
20898
20963
  value: match[0]
20899
20964
  };
20900
- continue;
20901
- }
20902
- StringLiteral.lastIndex = lastIndex;
20903
- if (match = StringLiteral.exec(input)) {
20904
- lastIndex = StringLiteral.lastIndex;
20905
- lastSignificantToken = match[0];
20965
+ } else {
20906
20966
  postfixIncDec = true;
20907
20967
  yield {
20908
- type: "StringLiteral",
20968
+ type: "NoSubstitutionTemplate",
20909
20969
  value: match[0],
20910
- closed: match[2] !== void 0
20970
+ closed: match[1] === "`"
20911
20971
  };
20912
- continue;
20913
- }
20914
- NumericLiteral.lastIndex = lastIndex;
20915
- if (match = NumericLiteral.exec(input)) {
20916
- lastIndex = NumericLiteral.lastIndex;
20917
- lastSignificantToken = match[0];
20918
- postfixIncDec = true;
20919
- yield {
20920
- type: "NumericLiteral",
20921
- value: match[0]
20922
- };
20923
- continue;
20924
20972
  }
20925
- Template.lastIndex = lastIndex;
20926
- if (match = Template.exec(input)) {
20927
- lastIndex = Template.lastIndex;
20928
- lastSignificantToken = match[0];
20929
- if (match[1] === "${") {
20930
- lastSignificantToken = "?InterpolationInTemplate";
20973
+ continue;
20974
+ }
20975
+ break;
20976
+ case "JSXTag":
20977
+ case "JSXTagEnd":
20978
+ JSXPunctuator.lastIndex = lastIndex;
20979
+ if (match = JSXPunctuator.exec(input)) {
20980
+ lastIndex = JSXPunctuator.lastIndex;
20981
+ nextLastSignificantToken = match[0];
20982
+ switch (match[0]) {
20983
+ case "<":
20984
+ stack.push({ tag: "JSXTag" });
20985
+ break;
20986
+ case ">":
20987
+ stack.pop();
20988
+ if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
20989
+ nextLastSignificantToken = "?JSX";
20990
+ postfixIncDec = true;
20991
+ } else stack.push({ tag: "JSXChildren" });
20992
+ break;
20993
+ case "{":
20931
20994
  stack.push({
20932
- tag: "InterpolationInTemplate",
20995
+ tag: "InterpolationInJSX",
20933
20996
  nesting: braces.length
20934
20997
  });
20998
+ nextLastSignificantToken = "?InterpolationInJSX";
20935
20999
  postfixIncDec = false;
20936
- yield {
20937
- type: "TemplateHead",
20938
- value: match[0]
20939
- };
20940
- } else {
20941
- postfixIncDec = true;
20942
- yield {
20943
- type: "NoSubstitutionTemplate",
20944
- value: match[0],
20945
- closed: match[1] === "`"
20946
- };
21000
+ break;
21001
+ case "/": if (lastSignificantToken === "<") {
21002
+ stack.pop();
21003
+ if (stack[stack.length - 1].tag === "JSXChildren") stack.pop();
21004
+ stack.push({ tag: "JSXTagEnd" });
20947
21005
  }
20948
- continue;
20949
21006
  }
20950
- break;
20951
- case "JSXTag":
20952
- case "JSXTagEnd":
20953
- JSXPunctuator.lastIndex = lastIndex;
20954
- if (match = JSXPunctuator.exec(input)) {
20955
- lastIndex = JSXPunctuator.lastIndex;
20956
- nextLastSignificantToken = match[0];
20957
- switch (match[0]) {
20958
- case "<":
20959
- stack.push({ tag: "JSXTag" });
20960
- break;
20961
- case ">":
20962
- stack.pop();
20963
- if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
20964
- nextLastSignificantToken = "?JSX";
20965
- postfixIncDec = true;
20966
- } else stack.push({ tag: "JSXChildren" });
20967
- break;
20968
- case "{":
20969
- stack.push({
20970
- tag: "InterpolationInJSX",
20971
- nesting: braces.length
20972
- });
20973
- nextLastSignificantToken = "?InterpolationInJSX";
20974
- postfixIncDec = false;
20975
- break;
20976
- case "/": if (lastSignificantToken === "<") {
20977
- stack.pop();
20978
- if (stack[stack.length - 1].tag === "JSXChildren") stack.pop();
20979
- stack.push({ tag: "JSXTagEnd" });
20980
- }
20981
- }
20982
- lastSignificantToken = nextLastSignificantToken;
21007
+ lastSignificantToken = nextLastSignificantToken;
21008
+ yield {
21009
+ type: "JSXPunctuator",
21010
+ value: match[0]
21011
+ };
21012
+ continue;
21013
+ }
21014
+ JSXIdentifier.lastIndex = lastIndex;
21015
+ if (match = JSXIdentifier.exec(input)) {
21016
+ lastIndex = JSXIdentifier.lastIndex;
21017
+ lastSignificantToken = match[0];
21018
+ yield {
21019
+ type: "JSXIdentifier",
21020
+ value: match[0]
21021
+ };
21022
+ continue;
21023
+ }
21024
+ JSXString.lastIndex = lastIndex;
21025
+ if (match = JSXString.exec(input)) {
21026
+ lastIndex = JSXString.lastIndex;
21027
+ lastSignificantToken = match[0];
21028
+ yield {
21029
+ type: "JSXString",
21030
+ value: match[0],
21031
+ closed: match[2] !== void 0
21032
+ };
21033
+ continue;
21034
+ }
21035
+ break;
21036
+ case "JSXChildren":
21037
+ JSXText.lastIndex = lastIndex;
21038
+ if (match = JSXText.exec(input)) {
21039
+ lastIndex = JSXText.lastIndex;
21040
+ lastSignificantToken = match[0];
21041
+ yield {
21042
+ type: "JSXText",
21043
+ value: match[0]
21044
+ };
21045
+ continue;
21046
+ }
21047
+ switch (input[lastIndex]) {
21048
+ case "<":
21049
+ stack.push({ tag: "JSXTag" });
21050
+ lastIndex++;
21051
+ lastSignificantToken = "<";
20983
21052
  yield {
20984
21053
  type: "JSXPunctuator",
20985
- value: match[0]
20986
- };
20987
- continue;
20988
- }
20989
- JSXIdentifier.lastIndex = lastIndex;
20990
- if (match = JSXIdentifier.exec(input)) {
20991
- lastIndex = JSXIdentifier.lastIndex;
20992
- lastSignificantToken = match[0];
20993
- yield {
20994
- type: "JSXIdentifier",
20995
- value: match[0]
21054
+ value: "<"
20996
21055
  };
20997
21056
  continue;
20998
- }
20999
- JSXString.lastIndex = lastIndex;
21000
- if (match = JSXString.exec(input)) {
21001
- lastIndex = JSXString.lastIndex;
21002
- lastSignificantToken = match[0];
21003
- yield {
21004
- type: "JSXString",
21005
- value: match[0],
21006
- closed: match[2] !== void 0
21007
- };
21008
- continue;
21009
- }
21010
- break;
21011
- case "JSXChildren":
21012
- JSXText.lastIndex = lastIndex;
21013
- if (match = JSXText.exec(input)) {
21014
- lastIndex = JSXText.lastIndex;
21015
- lastSignificantToken = match[0];
21057
+ case "{":
21058
+ stack.push({
21059
+ tag: "InterpolationInJSX",
21060
+ nesting: braces.length
21061
+ });
21062
+ lastIndex++;
21063
+ lastSignificantToken = "?InterpolationInJSX";
21064
+ postfixIncDec = false;
21016
21065
  yield {
21017
- type: "JSXText",
21018
- value: match[0]
21066
+ type: "JSXPunctuator",
21067
+ value: "{"
21019
21068
  };
21020
21069
  continue;
21021
- }
21022
- switch (input[lastIndex]) {
21023
- case "<":
21024
- stack.push({ tag: "JSXTag" });
21025
- lastIndex++;
21026
- lastSignificantToken = "<";
21027
- yield {
21028
- type: "JSXPunctuator",
21029
- value: "<"
21030
- };
21031
- continue;
21032
- case "{":
21033
- stack.push({
21034
- tag: "InterpolationInJSX",
21035
- nesting: braces.length
21036
- });
21037
- lastIndex++;
21038
- lastSignificantToken = "?InterpolationInJSX";
21039
- postfixIncDec = false;
21040
- yield {
21041
- type: "JSXPunctuator",
21042
- value: "{"
21043
- };
21044
- continue;
21045
- }
21046
- }
21047
- WhiteSpace.lastIndex = lastIndex;
21048
- if (match = WhiteSpace.exec(input)) {
21049
- lastIndex = WhiteSpace.lastIndex;
21050
- yield {
21051
- type: "WhiteSpace",
21052
- value: match[0]
21053
- };
21054
- continue;
21055
- }
21056
- LineTerminatorSequence.lastIndex = lastIndex;
21057
- if (match = LineTerminatorSequence.exec(input)) {
21058
- lastIndex = LineTerminatorSequence.lastIndex;
21070
+ }
21071
+ }
21072
+ WhiteSpace.lastIndex = lastIndex;
21073
+ if (match = WhiteSpace.exec(input)) {
21074
+ lastIndex = WhiteSpace.lastIndex;
21075
+ yield {
21076
+ type: "WhiteSpace",
21077
+ value: match[0]
21078
+ };
21079
+ continue;
21080
+ }
21081
+ LineTerminatorSequence.lastIndex = lastIndex;
21082
+ if (match = LineTerminatorSequence.exec(input)) {
21083
+ lastIndex = LineTerminatorSequence.lastIndex;
21084
+ postfixIncDec = false;
21085
+ if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) lastSignificantToken = "?NoLineTerminatorHere";
21086
+ yield {
21087
+ type: "LineTerminatorSequence",
21088
+ value: match[0]
21089
+ };
21090
+ continue;
21091
+ }
21092
+ MultiLineComment.lastIndex = lastIndex;
21093
+ if (match = MultiLineComment.exec(input)) {
21094
+ lastIndex = MultiLineComment.lastIndex;
21095
+ if (Newline.test(match[0])) {
21059
21096
  postfixIncDec = false;
21060
21097
  if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) lastSignificantToken = "?NoLineTerminatorHere";
21061
- yield {
21062
- type: "LineTerminatorSequence",
21063
- value: match[0]
21064
- };
21065
- continue;
21066
- }
21067
- MultiLineComment.lastIndex = lastIndex;
21068
- if (match = MultiLineComment.exec(input)) {
21069
- lastIndex = MultiLineComment.lastIndex;
21070
- if (Newline.test(match[0])) {
21071
- postfixIncDec = false;
21072
- if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) lastSignificantToken = "?NoLineTerminatorHere";
21073
- }
21074
- yield {
21075
- type: "MultiLineComment",
21076
- value: match[0],
21077
- closed: match[1] !== void 0
21078
- };
21079
- continue;
21080
21098
  }
21081
- SingleLineComment.lastIndex = lastIndex;
21082
- if (match = SingleLineComment.exec(input)) {
21083
- lastIndex = SingleLineComment.lastIndex;
21084
- postfixIncDec = false;
21085
- yield {
21086
- type: "SingleLineComment",
21087
- value: match[0]
21088
- };
21089
- continue;
21090
- }
21091
- firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
21092
- lastIndex += firstCodePoint.length;
21093
- lastSignificantToken = firstCodePoint;
21099
+ yield {
21100
+ type: "MultiLineComment",
21101
+ value: match[0],
21102
+ closed: match[1] !== void 0
21103
+ };
21104
+ continue;
21105
+ }
21106
+ SingleLineComment.lastIndex = lastIndex;
21107
+ if (match = SingleLineComment.exec(input)) {
21108
+ lastIndex = SingleLineComment.lastIndex;
21094
21109
  postfixIncDec = false;
21095
21110
  yield {
21096
- type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
21097
- value: firstCodePoint
21111
+ type: "SingleLineComment",
21112
+ value: match[0]
21098
21113
  };
21114
+ continue;
21099
21115
  }
21100
- };
21101
- })))(), 1);
21116
+ firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
21117
+ lastIndex += firstCodePoint.length;
21118
+ lastSignificantToken = firstCodePoint;
21119
+ postfixIncDec = false;
21120
+ yield {
21121
+ type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
21122
+ value: firstCodePoint
21123
+ };
21124
+ }
21125
+ };
21126
+ var js_tokens_default = jsTokens;
21127
+ //#endregion
21128
+ //#region ../../node_modules/.pnpm/strip-literal@4.0.0/node_modules/strip-literal/dist/index.mjs
21102
21129
  const FILL_COMMENT = " ";
21103
21130
  function stripLiteralFromToken(token, fillChar, filter) {
21104
21131
  if (token.type === "SingleLineComment") return FILL_COMMENT.repeat(token.value.length);
@@ -21136,10 +21163,13 @@ function optionsWithDefaults(options) {
21136
21163
  filter: options?.filter ?? (() => true)
21137
21164
  };
21138
21165
  }
21166
+ /**
21167
+ * Strip literal from code.
21168
+ */
21139
21169
  function stripLiteral(code, options) {
21140
21170
  let result = "";
21141
21171
  const _options = optionsWithDefaults(options);
21142
- for (const token of (0, import_js_tokens.default)(code, { jsx: false })) result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
21172
+ for (const token of js_tokens_default(code, { jsx: false })) result += stripLiteralFromToken(token, _options.fillChar, _options.filter);
21143
21173
  return result;
21144
21174
  }
21145
21175
  //#endregion
@@ -21381,7 +21411,8 @@ function assetPlugin(config) {
21381
21411
  }
21382
21412
  }
21383
21413
  if (config.command === "build" && !this.environment.config.build.emitAssets) {
21384
- for (const file in bundle) if (bundle[file].type === "asset" && !file.endsWith("ssr-manifest.json") && !jsSourceMapRE.test(file)) delete bundle[file];
21414
+ const chunkImportMapEnabled = this.environment.config.build.chunkImportMap;
21415
+ for (const file in bundle) if (bundle[file].type === "asset" && !file.endsWith("ssr-manifest.json") && !jsSourceMapRE.test(file) && !(chunkImportMapEnabled && file === getImportMapFilename(this.environment.config))) delete bundle[file];
21385
21416
  }
21386
21417
  },
21387
21418
  watchChange(id) {
@@ -21858,7 +21889,7 @@ var require_src$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21858
21889
  };
21859
21890
  }));
21860
21891
  //#endregion
21861
- //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/req.js
21892
+ //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.25_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/req.js
21862
21893
  var require_req = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21863
21894
  const { createRequire: createRequire$1 } = __require("node:module");
21864
21895
  const { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1 } = __require("node:url");
@@ -21900,7 +21931,7 @@ var require_req = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21900
21931
  module.exports = req;
21901
21932
  }));
21902
21933
  //#endregion
21903
- //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/options.js
21934
+ //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.25_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/options.js
21904
21935
  var require_options = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21905
21936
  const req = require_req();
21906
21937
  /**
@@ -21934,7 +21965,7 @@ var require_options = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21934
21965
  module.exports = options;
21935
21966
  }));
21936
21967
  //#endregion
21937
- //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/plugins.js
21968
+ //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.25_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/plugins.js
21938
21969
  var require_plugins = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21939
21970
  const req = require_req();
21940
21971
  /**
@@ -21988,7 +22019,7 @@ var require_plugins = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21988
22019
  module.exports = plugins;
21989
22020
  }));
21990
22021
  //#endregion
21991
- //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/index.js
22022
+ //#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.25_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/index.js
21992
22023
  var require_src = /* @__PURE__ */ __commonJSMin(((exports, module) => {
21993
22024
  const { resolve: resolve$3 } = __require("node:path");
21994
22025
  const config = require_src$1();
@@ -22811,8 +22842,8 @@ function cssPostPlugin(config) {
22811
22842
  });
22812
22843
  }
22813
22844
  }
22814
- if (config.build.chunkImportMap && chunkCssReferences.size) {
22815
- const importMap = getImportMap(bundle, config);
22845
+ if (this.environment.config.build.chunkImportMap && chunkCssReferences.size) {
22846
+ const importMap = getImportMap(bundle, this.environment.config);
22816
22847
  const importMapReverseMapping = Object.fromEntries(Object.entries(importMap.mapping).map(([k, v]) => [v, k]));
22817
22848
  const chunksByPreliminaryFileName = new Map(Object.values(bundle).filter((output) => output.type === "chunk").map((chunk) => [chunk.preliminaryFileName, chunk]));
22818
22849
  for (const [chunkFileName, referenceId] of chunkCssReferences) {
@@ -22828,9 +22859,10 @@ function cssPostPlugin(config) {
22828
22859
  if (pureCssChunks.size) {
22829
22860
  const prelimaryNameToChunkMap = Object.fromEntries(Object.values(bundle).filter((chunk) => chunk.type === "chunk").map((chunk) => [chunk.preliminaryFileName, chunk.fileName]));
22830
22861
  const pureCssChunkNames = [...pureCssChunks].map((pureCssChunk) => prelimaryNameToChunkMap[pureCssChunk.fileName]).filter(Boolean);
22862
+ const pureCssChunkNameSet = new Set(pureCssChunkNames);
22831
22863
  let importMapReverseMapping;
22832
- if (config.build.chunkImportMap) {
22833
- const importMap = getImportMap(bundle, config);
22864
+ if (this.environment.config.build.chunkImportMap) {
22865
+ const importMap = getImportMap(bundle, this.environment.config);
22834
22866
  importMapReverseMapping = Object.fromEntries(Object.entries(importMap.mapping).map(([k, v]) => [v, k]));
22835
22867
  }
22836
22868
  const replaceEmptyChunk = getEmptyChunkReplacer(importMapReverseMapping ? pureCssChunkNames.map((name) => importMapReverseMapping[name] ?? name) : pureCssChunkNames, opts.format);
@@ -22839,7 +22871,7 @@ function cssPostPlugin(config) {
22839
22871
  if (chunk.type === "chunk") {
22840
22872
  let chunkImportsPureCssChunk = false;
22841
22873
  chunk.imports = chunk.imports.filter((file) => {
22842
- if (pureCssChunkNames.includes(file)) {
22874
+ if (pureCssChunkNameSet.has(file)) {
22843
22875
  const { importedCss, importedAssets } = bundle[file].viteMetadata;
22844
22876
  importedCss.forEach((file) => chunk.viteMetadata.importedCss.add(file));
22845
22877
  importedAssets.forEach((file) => chunk.viteMetadata.importedAssets.add(file));
@@ -22880,12 +22912,13 @@ function injectInlinedCSS(s, ctx, code, format, injectCode) {
22880
22912
  if (!m) ctx.error("Injection point for inlined CSS not found");
22881
22913
  injectionPoint = m.index + m[0].length;
22882
22914
  } else if (format === "es") if (code.startsWith("#!")) {
22883
- const newlinePos = code.indexOf("\n");
22884
- if (newlinePos === -1) {
22915
+ const fileStartIndex = getFileStartIndex(code);
22916
+ const hashbang = code.slice(0, fileStartIndex);
22917
+ if (!lineTerminatorRE.test(hashbang)) {
22885
22918
  s.append(`\n${injectCode}`);
22886
22919
  return;
22887
22920
  }
22888
- injectionPoint = newlinePos + 1;
22921
+ injectionPoint = fileStartIndex;
22889
22922
  } else injectionPoint = 0;
22890
22923
  else ctx.error("Non supported format");
22891
22924
  s.appendRight(injectionPoint, injectCode);
@@ -23248,7 +23281,8 @@ async function resolvePostcssConfig(config) {
23248
23281
  };
23249
23282
  } else {
23250
23283
  const searchPath = typeof inlineOptions === "string" ? inlineOptions : config.root;
23251
- result = (0, import_src.default)({}, searchPath, { stopDir: searchForWorkspaceRoot(config.root) }).catch((e) => {
23284
+ const stopDir = searchForWorkspaceRoot(config.root);
23285
+ result = (0, import_src.default)({}, searchPath, { stopDir }).catch((e) => {
23252
23286
  if (!e.message.includes("No PostCSS Config found")) if (e instanceof Error) {
23253
23287
  const { name, message, stack } = e;
23254
23288
  e.name = "Failed to load PostCSS config";
@@ -23389,10 +23423,12 @@ async function minifyCSS(css, config, inlined, filename = defaultCssBundleName)
23389
23423
  const { code, warnings } = (await importLightningCSS()).transform({
23390
23424
  ...config.css.lightningcss,
23391
23425
  targets: convertTargets(config.build.cssTarget),
23392
- cssModules: void 0,
23393
23426
  filename,
23394
23427
  code: Buffer.from(css),
23395
- minify: true
23428
+ minify: true,
23429
+ cssModules: void 0,
23430
+ visitor: void 0,
23431
+ customAtRules: void 0
23396
23432
  });
23397
23433
  for (const warning of warnings) {
23398
23434
  let msg = `[lightningcss minify] ${warning.message}`;
@@ -23491,7 +23527,8 @@ function loadSassPackage(root, skipEmbedded = false) {
23491
23527
  let cachedSss;
23492
23528
  async function loadSss(root) {
23493
23529
  if (!cachedSss) cachedSss = (async () => {
23494
- return cachedSss = (await import(pathToFileURL(loadPreprocessorPath("sugarss", root)).href)).default;
23530
+ const sssPath = loadPreprocessorPath("sugarss", root);
23531
+ return cachedSss = (await import(pathToFileURL(sssPath).href)).default;
23495
23532
  })();
23496
23533
  return cachedSss;
23497
23534
  }
@@ -24627,6 +24664,13 @@ function buildHtmlPlugin(config) {
24627
24664
  assetTags.push(...getCssTagsForChunk(chunk, toOutputAssetFilePath));
24628
24665
  result = injectToHead(result, assetTags);
24629
24666
  }
24667
+ if (config.command === "serve" && this.environment.config.consumer === "client" && this.environment.config.isBundled) result = injectToHead(result, [{
24668
+ tag: "script",
24669
+ attrs: {
24670
+ type: "module",
24671
+ src: path.posix.join(config.base, BUNDLED_DEV_CLIENT_FILENAME)
24672
+ }
24673
+ }], true);
24630
24674
  if (!this.environment.config.build.cssCodeSplit) {
24631
24675
  const cssBundleName = cssBundleNameCache.get(config);
24632
24676
  const cssChunk = cssBundleName && Object.values(bundle).find((chunk) => chunk.type === "asset" && chunk.names.includes(cssBundleName));
@@ -24724,7 +24768,7 @@ function preImportMapHook(config) {
24724
24768
  function postImportMapHook(config) {
24725
24769
  const decoder = new TextDecoder();
24726
24770
  return function(html, { bundle }) {
24727
- const chunkImportMapEnabled = config.command === "build" && config.build.chunkImportMap;
24771
+ const chunkImportMapEnabled = config.command === "build" && config.environments.client.build.chunkImportMap;
24728
24772
  if (importMapAppendRE.test(html)) {
24729
24773
  let importMap;
24730
24774
  html = html.replace(importMapRE, (match) => {
@@ -24738,7 +24782,7 @@ function postImportMapHook(config) {
24738
24782
  }
24739
24783
  if (chunkImportMapEnabled) {
24740
24784
  const nonce = config.html?.cspNonce;
24741
- const importMap = bundle[getImportMapFilename(config)];
24785
+ const importMap = bundle[getImportMapFilename(config.environments.client)];
24742
24786
  const importMapHtml = serializeTag({
24743
24787
  tag: "script",
24744
24788
  attrs: {
@@ -24962,23 +25006,29 @@ function serializeAttrs(attrs) {
24962
25006
  function incrementIndent(indent = "") {
24963
25007
  return `${indent}${indent[0] === " " ? " " : " "}`;
24964
25008
  }
24965
- function getImportMapFilename(config) {
24966
- const chunkImportMap = config.build.rolldownOptions.experimental?.chunkImportMap;
25009
+ function getImportMapFilename(options) {
25010
+ const chunkImportMap = options.build.rolldownOptions.experimental?.chunkImportMap;
24967
25011
  if (typeof chunkImportMap === "object" && chunkImportMap.fileName) return chunkImportMap.fileName;
24968
25012
  return "importmap.json";
24969
25013
  }
25014
+ function getImportMapBaseUrl(options) {
25015
+ const chunkImportMap = options.build.rolldownOptions.experimental?.chunkImportMap;
25016
+ if (typeof chunkImportMap === "object" && chunkImportMap.baseUrl) return chunkImportMap.baseUrl;
25017
+ return "/";
25018
+ }
24970
25019
  /**
24971
25020
  * Read and parse the chunk import map asset from the bundle.
24972
25021
  * Returns `undefined` when the import map is not present in the bundle.
24973
25022
  */
24974
- function getImportMap(bundle, config) {
24975
- const asset = bundle[getImportMapFilename(config)];
25023
+ function getImportMap(bundle, options) {
25024
+ const asset = bundle[getImportMapFilename(options)];
24976
25025
  if (!asset) return void 0;
24977
25026
  const content = JSON.parse(typeof asset.source === "string" ? asset.source : new TextDecoder().decode(asset.source));
25027
+ const baseUrl = getImportMapBaseUrl(options);
24978
25028
  return {
24979
25029
  asset,
24980
25030
  content,
24981
- mapping: Object.fromEntries(Object.entries(content.imports).map(([k, v]) => [k.slice(config.base.length), v.slice(config.base.length)]))
25031
+ mapping: Object.fromEntries(Object.entries(content.imports).map(([k, v]) => [k.slice(baseUrl.length), v.slice(baseUrl.length)]))
24982
25032
  };
24983
25033
  }
24984
25034
  //#endregion
@@ -25587,7 +25637,7 @@ function indexHtmlMiddleware(root, server) {
25587
25637
  }
25588
25638
  const filePath = pathname.slice(1);
25589
25639
  let file = fullBundle.memoryFiles.get(filePath);
25590
- if (!file && fullBundle.memoryFiles.size !== 0) return next();
25640
+ if (!file && fullBundle.hasBuildOutput) return next();
25591
25641
  if ([
25592
25642
  "document",
25593
25643
  "iframe",
@@ -26570,7 +26620,7 @@ async function startServer(server, hostname, inlinePort) {
26570
26620
  if (!httpServer) throw new Error("Cannot call server.listen in middleware mode.");
26571
26621
  const options = server.config.server;
26572
26622
  const configPort = inlinePort ?? options.port;
26573
- const port = (!configPort || configPort === server._configServerPort ? server._currentServerPort : configPort) ?? 5173;
26623
+ const port = configPort === server._configServerPort ? server._currentServerPort ?? configPort : configPort;
26574
26624
  server._configServerPort = configPort;
26575
26625
  server._currentServerPort = await httpServerStart(httpServer, {
26576
26626
  port,
@@ -26657,7 +26707,8 @@ async function resolveServerOptions(root, raw, logger) {
26657
26707
  let allowDirs = server.fs.allow;
26658
26708
  const cwd = searchForPackageRoot(root);
26659
26709
  if (process.versions.pnp) try {
26660
- const yarnCacheDir = execSync(`yarn config get ${execSync("yarn config get enableGlobalCache", { cwd }).toString().trim() === "true" ? "globalFolder" : "cacheFolder"}`, { cwd }).toString().trim();
26710
+ const enableGlobalCache = execSync("yarn config get enableGlobalCache", { cwd }).toString().trim() === "true";
26711
+ const yarnCacheDir = execSync(`yarn config get ${enableGlobalCache ? "globalFolder" : "cacheFolder"}`, { cwd }).toString().trim();
26661
26712
  allowDirs.push(yarnCacheDir);
26662
26713
  } catch (e) {
26663
26714
  logger.warn(`Get yarn cache dir error: ${e.message}`, { timestamp: true });
@@ -28871,8 +28922,8 @@ function buildImportAnalysisPlugin(config) {
28871
28922
  const { modulePreload } = this.environment.config.build;
28872
28923
  let importMapMapping;
28873
28924
  let importMapReverseMapping;
28874
- if (config.build.chunkImportMap) {
28875
- const importMap = getImportMap(bundle, config);
28925
+ if (this.environment.config.build.chunkImportMap) {
28926
+ const importMap = getImportMap(bundle, this.environment.config);
28876
28927
  importMapMapping = importMap.mapping;
28877
28928
  importMapReverseMapping = Object.fromEntries(Object.entries(importMapMapping).map(([k, v]) => [v, k]));
28878
28929
  if (config.isOutputOptionsForLegacyChunks?.(opts)) {
@@ -28881,7 +28932,7 @@ function buildImportAnalysisPlugin(config) {
28881
28932
  fileName: "importmap.legacy.json",
28882
28933
  source: importMap.asset.source
28883
28934
  });
28884
- delete bundle[getImportMapFilename(config)];
28935
+ delete bundle[getImportMapFilename(this.environment.config)];
28885
28936
  }
28886
28937
  }
28887
28938
  for (const file in bundle) {
@@ -28990,7 +29041,7 @@ function buildImportAnalysisPlugin(config) {
28990
29041
  }
28991
29042
  if (fileDeps.length > 0) {
28992
29043
  const mapDepsCode = `const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=${`[${fileDeps.map((fileDep) => fileDep.runtime ? fileDep.url : JSON.stringify(fileDep.url)).join(",")}]`})))=>i.map(i=>d[i]);\n`;
28993
- if (code.startsWith("#!")) s.prependLeft(code.indexOf("\n") + 1, mapDepsCode);
29044
+ if (code.startsWith("#!")) s.prependLeft(getFileStartIndex(code), mapDepsCode);
28994
29045
  else s.prepend(mapDepsCode);
28995
29046
  }
28996
29047
  let markerStartPos = findPreloadMarker(code);
@@ -29025,8 +29076,9 @@ function buildImportAnalysisPlugin(config) {
29025
29076
  }
29026
29077
  }
29027
29078
  }, perEnvironmentPlugin("native:import-analysis-build", (environment) => {
29079
+ const preloadCode = getPreloadCode(environment, !!renderBuiltUrl, isRelativeBase);
29028
29080
  return viteBuildImportAnalysisPlugin({
29029
- preloadCode: getPreloadCode(environment, !!renderBuiltUrl, isRelativeBase),
29081
+ preloadCode,
29030
29082
  insertPreload: getInsertPreload(environment),
29031
29083
  optimizeModulePreloadRelativePaths: false,
29032
29084
  renderBuiltUrl: !!renderBuiltUrl,
@@ -29489,7 +29541,8 @@ async function parseImportGlob(code, importer, root, resolveId, logger) {
29489
29541
  };
29490
29542
  const end = findCorrespondingCloseParenthesisPosition(cleanCode, start + match[0].length) + 1;
29491
29543
  if (end <= 0) throw err("Close parenthesis not found");
29492
- const rootAst = (await parseAstAsync(code.slice(start, end))).body[0];
29544
+ const statementCode = code.slice(start, end);
29545
+ const rootAst = (await parseAstAsync(statementCode)).body[0];
29493
29546
  if (rootAst.type !== "ExpressionStatement") throw err(`Expect CallExpression, got ${rootAst.type}`);
29494
29547
  const ast = rootAst.expression;
29495
29548
  if (ast.type !== "CallExpression") throw err(`Expect CallExpression, got ${ast.type}`);
@@ -29566,9 +29619,10 @@ async function transformGlobImport(code, id, root, resolveId, restoreQueryExtens
29566
29619
  const s = new MagicString(code);
29567
29620
  const staticImports = (await Promise.all(matches.map(async ({ globsResolved, isRelative, options, index, start, end, onlyKeys, onlyValues }) => {
29568
29621
  if (!dir && !options.base && isRelative) throw new Error("In virtual modules, all globs must start with '/'");
29622
+ const cwd = getCommonBase(globsResolved) ?? root;
29569
29623
  const files = (await glob(globsResolved, {
29570
29624
  absolute: true,
29571
- cwd: getCommonBase(globsResolved) ?? root,
29625
+ cwd,
29572
29626
  dot: !!options.exhaustive,
29573
29627
  expandDirectories: false,
29574
29628
  caseSensitiveMatch: options.caseSensitive ?? true,
@@ -29714,7 +29768,8 @@ function patternToIdFilter(pattern, cwd) {
29714
29768
  pattern.lastIndex = 0;
29715
29769
  return result;
29716
29770
  };
29717
- const matcher = pm(getMatcherString(pattern, cwd), { dot: true });
29771
+ const glob = getMatcherString(pattern, cwd);
29772
+ const matcher = pm(glob, { dot: true });
29718
29773
  return (id) => {
29719
29774
  const normalizedId = slash(id);
29720
29775
  return matcher(normalizedId);
@@ -32611,7 +32666,7 @@ async function optimizedDepNeedsInterop(environment, metadata, file) {
32611
32666
  }
32612
32667
  return depInfo?.needsInterop;
32613
32668
  }
32614
- const MAX_TEMP_DIR_AGE_MS = 1440 * 60 * 1e3;
32669
+ const MAX_TEMP_DIR_AGE_MS = 864e5;
32615
32670
  async function cleanupDepsCacheStaleDirs(config) {
32616
32671
  try {
32617
32672
  const cacheDir = path.resolve(config.cacheDir);
@@ -33479,7 +33534,10 @@ function resolveBuildEnvironmentOptions(raw, logger, consumer, isBundledDev, inp
33479
33534
  platform: consumer === "client" || isSsrTargetWebworkerEnvironment ? "browser" : "node",
33480
33535
  ...merged.rolldownOptions
33481
33536
  };
33482
- if (merged.lib && merged.lib.entry == null && input != null) merged.lib.entry = input;
33537
+ if (merged.lib && merged.lib.entry == null && input != null) merged.lib = {
33538
+ ...merged.lib,
33539
+ entry: input
33540
+ };
33483
33541
  if (merged.target === "baseline-widely-available") merged.target = ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET;
33484
33542
  if (Array.isArray(merged.target)) merged.target = unique(merged.target);
33485
33543
  if (merged.minify === "false") merged.minify = false;
@@ -33575,7 +33633,10 @@ function resolveRolldownOptions(environment, chunkMetadataMap) {
33575
33633
  experimental: {
33576
33634
  ...options.rolldownOptions.experimental,
33577
33635
  viteMode: true,
33578
- chunkImportMap: options.chunkImportMap ? { baseUrl: base } : options.rolldownOptions.experimental?.chunkImportMap
33636
+ chunkImportMap: options.chunkImportMap ? {
33637
+ ...typeof options.rolldownOptions.experimental?.chunkImportMap === "object" ? options.rolldownOptions.experimental?.chunkImportMap : {},
33638
+ baseUrl: base
33639
+ } : options.rolldownOptions.experimental?.chunkImportMap
33579
33640
  }
33580
33641
  };
33581
33642
  const isSsrTargetWebworkerEnvironment = environment.name === "ssr" && environment.getTopLevelConfig().ssr?.target === "webworker";
@@ -33853,9 +33914,7 @@ function injectEnvironmentToHooks(environment, chunkMetadataMap, plugin) {
33853
33914
  case "transform":
33854
33915
  clone[hook] = wrapEnvironmentTransform(environment, transform, plugin.name);
33855
33916
  break;
33856
- default:
33857
- if (ROLLUP_HOOKS.includes(hook)) clone[hook] = wrapEnvironmentHook(environment, chunkMetadataMap, plugin, hook);
33858
- break;
33917
+ default: if (ROLLUP_HOOKS.includes(hook)) clone[hook] = wrapEnvironmentHook(environment, chunkMetadataMap, plugin, hook);
33859
33918
  }
33860
33919
  return clone;
33861
33920
  }
@@ -34419,7 +34478,7 @@ function createDepsOptimizer(environment) {
34419
34478
  logOptimizeDepsIncludeSuggestion("speed up cold start");
34420
34479
  warnAboutMissedDependencies = false;
34421
34480
  }
34422
- }, 2 * debounceMs);
34481
+ }, 200);
34423
34482
  } else debug$2(import_picocolors.default.green(!isRerun ? `dependencies optimized` : `optimized dependencies unchanged`));
34424
34483
  } else if (newDepsDiscovered) {
34425
34484
  processingResult.cancel();
@@ -34958,6 +35017,7 @@ var MemoryFiles = class {
34958
35017
  var BundledDev = class {
34959
35018
  environment;
34960
35019
  _devEngine;
35020
+ viteRuntime;
34961
35021
  initialBuildCompleted = false;
34962
35022
  _closed = false;
34963
35023
  clients = new Clients();
@@ -34990,6 +35050,9 @@ var BundledDev = class {
34990
35050
  return this._devEngine;
34991
35051
  }
34992
35052
  pendingPayloadFilenames = /* @__PURE__ */ new Set();
35053
+ get hasBuildOutput() {
35054
+ return this.memoryFiles.size > 1 || this.memoryFiles.size === 1 && !this.memoryFiles.has("bundledDevClient.mjs");
35055
+ }
34993
35056
  async listen() {
34994
35057
  this._closed = false;
34995
35058
  debug$1?.("INITIAL: setup bundle options");
@@ -35079,6 +35142,8 @@ var BundledDev = class {
35079
35142
  }, (e) => {
35080
35143
  debug$1?.("INITIAL: run error", e);
35081
35144
  });
35145
+ this.viteRuntime = await getHmrImplementation(this.environment.getTopLevelConfig());
35146
+ this.storeOutputFiles([]);
35082
35147
  this.waitForInitialBuildFinish().then(() => {
35083
35148
  if (this._closed) return;
35084
35149
  debug$1?.("INITIAL: build done");
@@ -35095,7 +35160,7 @@ var BundledDev = class {
35095
35160
  await this.devEngine.ensureCurrentBuildFinish();
35096
35161
  if (this._closed) return;
35097
35162
  let state = await this.devEngine.getBundleState();
35098
- while (this.memoryFiles.size === 0 && !state.lastBuildErrored) {
35163
+ while (!this.hasBuildOutput && !state.lastBuildErrored) {
35099
35164
  await setTimeout$1(10);
35100
35165
  if (this._closed) return;
35101
35166
  await this.devEngine.ensureCurrentBuildFinish();
@@ -35149,6 +35214,10 @@ var BundledDev = class {
35149
35214
  this.initialBuildCompleted = false;
35150
35215
  }
35151
35216
  storeOutputFiles(output) {
35217
+ if (this.viteRuntime) this.memoryFiles.set(BUNDLED_DEV_CLIENT_FILENAME, {
35218
+ source: this.viteRuntime,
35219
+ etag: (0, import_etag.default)(Buffer.from(this.viteRuntime), { weak: true })
35220
+ });
35152
35221
  for (const outputFile of output) this.memoryFiles.set(outputFile.fileName, () => {
35153
35222
  const source = outputFile.type === "chunk" ? outputFile.code : outputFile.source;
35154
35223
  return {
@@ -35164,23 +35233,11 @@ var BundledDev = class {
35164
35233
  rolldownOptions.experimental.devMode = {
35165
35234
  lazy: true,
35166
35235
  ...typeof rolldownOptions.experimental.devMode === "object" ? rolldownOptions.experimental.devMode : {},
35167
- implement: await getHmrImplementation(this.environment.getTopLevelConfig())
35236
+ implement: "",
35237
+ skipCommonRuntimeInjection: true
35168
35238
  };
35169
35239
  rolldownOptions.optimization ??= {};
35170
35240
  rolldownOptions.optimization.inlineConst = false;
35171
- const plugins = await asyncFlatten([rolldownOptions.plugins]);
35172
- for (const plugin of plugins) {
35173
- const transform = plugin && "transform" in plugin ? plugin.transform : void 0;
35174
- if (!transform) continue;
35175
- const handler = typeof transform === "function" ? transform : transform.handler;
35176
- const wrappedHandler = function(code, id, opts) {
35177
- if (id.includes("?rolldown-lazy=")) return null;
35178
- return handler.call(this, code, id, opts);
35179
- };
35180
- if (typeof transform === "function") plugin.transform = wrappedHandler;
35181
- else transform.handler = wrappedHandler;
35182
- }
35183
- rolldownOptions.plugins = plugins;
35184
35241
  if (Array.isArray(rolldownOptions.output)) for (const output of rolldownOptions.output) {
35185
35242
  output.entryFileNames = "assets/[name].js";
35186
35243
  output.chunkFileNames = "assets/[name]-[hash].js";
@@ -35803,9 +35860,7 @@ function analyzeConfigModuleReferences(code, ast, file) {
35803
35860
  case "ExportAllDeclaration":
35804
35861
  if (node.source) addImportRef(node.source, hasTypeJson(node.attributes));
35805
35862
  break;
35806
- case "ImportExpression":
35807
- if (node.source.type === "Literal" && typeof node.source.value === "string") addImportRef(node.source, node.options != null);
35808
- break;
35863
+ case "ImportExpression": if (node.source.type === "Literal" && typeof node.source.value === "string") addImportRef(node.source, node.options != null);
35809
35864
  }
35810
35865
  } });
35811
35866
  const globals = [];
@@ -36946,9 +37001,9 @@ async function bundleConfigFile(fileName, isESM) {
36946
37001
  } else injectValues += `const ${importMetaResolveVarName} = (specifier, importer = ${importMetaUrlVarName}) => { throw new Error('import.meta.resolve is not supported in CJS config files') };`;
36947
37002
  let injectedContents;
36948
37003
  if (code.startsWith("#!")) {
36949
- let firstLineEndIndex = code.indexOf("\n");
36950
- if (firstLineEndIndex < 0) firstLineEndIndex = code.length;
36951
- injectedContents = code.slice(0, firstLineEndIndex + 1) + injectValues + code.slice(firstLineEndIndex + 1);
37004
+ const fileStartIndex = getFileStartIndex(code);
37005
+ const hashbang = code.slice(0, fileStartIndex);
37006
+ injectedContents = hashbang + (lineTerminatorRE.test(hashbang) ? "" : "\n") + injectValues + code.slice(fileStartIndex);
36952
37007
  } else injectedContents = injectValues + code;
36953
37008
  return {
36954
37009
  code: injectedContents,
@@ -37029,10 +37084,11 @@ async function loadConfigFromBundledFile(fileName, bundledCode, isESM) {
37029
37084
  }
37030
37085
  async function runConfigHook(config, plugins, configEnv) {
37031
37086
  let conf = config;
37032
- const context = new BasicMinimalPluginContext(basePluginContextMeta, createLogger(config.logLevel, {
37087
+ const tempLogger = createLogger(config.logLevel, {
37033
37088
  allowClearScreen: config.clearScreen,
37034
37089
  customLogger: config.customLogger
37035
- }));
37090
+ });
37091
+ const context = new BasicMinimalPluginContext(basePluginContextMeta, tempLogger);
37036
37092
  for (const p of getSortedPluginsByHook("config", plugins)) {
37037
37093
  const hook = p.config;
37038
37094
  const res = await getHookHandler(hook).call(context, conf, configEnv);