vite 4.0.0 → 4.0.2

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -7295,7 +7295,7 @@ function isReference(node, parent) {
7295
7295
  return false;
7296
7296
  }
7297
7297
 
7298
- var version$3 = "23.0.3";
7298
+ var version$3 = "23.0.4";
7299
7299
  var peerDependencies = {
7300
7300
  rollup: "^2.68.0||^3.0.0"
7301
7301
  };
@@ -12175,10 +12175,8 @@ async function resolveServerUrls(server, options, config) {
12175
12175
  .flatMap((nInterface) => nInterface ?? [])
12176
12176
  .filter((detail) => detail &&
12177
12177
  detail.address &&
12178
- // Node < v18
12179
12178
  ((typeof detail.family === 'string' && detail.family === 'IPv4') ||
12180
- // Node >= v18
12181
- // @ts-expect-error
12179
+ // @ts-expect-error Node 18.0 - 18.3 returns number
12182
12180
  (typeof detail.family === 'number' && detail.family === 4)))
12183
12181
  .forEach((detail) => {
12184
12182
  const host = detail.address.replace('127.0.0.1', hostname.name);
@@ -12203,7 +12201,7 @@ function toUpperCaseDriveLetter(pathName) {
12203
12201
  const multilineCommentsRE$1 = /\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g;
12204
12202
  const singlelineCommentsRE$1 = /\/\/.*/g;
12205
12203
  const requestQuerySplitRE = /\?(?!.*[/|}])/;
12206
- // @ts-expect-error
12204
+ // @ts-expect-error jest only exists when running Jest
12207
12205
  const usingDynamicImport = typeof jest === 'undefined';
12208
12206
  /**
12209
12207
  * Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
@@ -12421,23 +12419,11 @@ const isNonDriveRelativeAbsolutePath = (p) => {
12421
12419
  * Determine if a file is being requested with the correct case, to ensure
12422
12420
  * consistent behaviour between dev and prod and across operating systems.
12423
12421
  */
12424
- function shouldServe(url, assetsDir) {
12425
- try {
12426
- // viteTestUrl is set to something like http://localhost:4173/ and then many tests make calls
12427
- // like `await page.goto(viteTestUrl + '/example')` giving us URLs beginning with a double slash
12428
- const pathname = decodeURI(new URL$3(url.startsWith('//') ? url.substring(1) : url, 'http://example.com').pathname);
12429
- const file = path$o.join(assetsDir, pathname);
12430
- if (!fs$l.existsSync(file) ||
12431
- (isCaseInsensitiveFS && // can skip case check on Linux
12432
- !fs$l.statSync(file).isDirectory() &&
12433
- !hasCorrectCase(file, assetsDir))) {
12434
- return false;
12435
- }
12422
+ function shouldServeFile(filePath, root) {
12423
+ // can skip case check on Linux
12424
+ if (!isCaseInsensitiveFS)
12436
12425
  return true;
12437
- }
12438
- catch (err) {
12439
- return false;
12440
- }
12426
+ return hasCorrectCase(filePath, root);
12441
12427
  }
12442
12428
  /**
12443
12429
  * Note that we can't use realpath here, because we don't want to follow
@@ -13378,7 +13364,7 @@ async function transformWithEsbuild(code, filename, options, inMap) {
13378
13364
  const loadedCompilerOptions = loadedTsconfig.compilerOptions ?? {};
13379
13365
  for (const field of meaningfulFields) {
13380
13366
  if (field in loadedCompilerOptions) {
13381
- // @ts-ignore TypeScript can't tell they are of the same type
13367
+ // @ts-expect-error TypeScript can't tell they are of the same type
13382
13368
  compilerOptionsForFile[field] = loadedCompilerOptions[field];
13383
13369
  }
13384
13370
  }
@@ -13390,6 +13376,23 @@ async function transformWithEsbuild(code, filename, options, inMap) {
13390
13376
  ...tsconfigRaw?.compilerOptions,
13391
13377
  },
13392
13378
  };
13379
+ const { compilerOptions } = tsconfigRaw;
13380
+ if (compilerOptions) {
13381
+ // esbuild derives `useDefineForClassFields` from `target` instead of `tsconfig.compilerOptions.target`
13382
+ // https://github.com/evanw/esbuild/issues/2584
13383
+ // but we want `useDefineForClassFields` to be derived from `tsconfig.compilerOptions.target`
13384
+ if (compilerOptions.useDefineForClassFields === undefined) {
13385
+ const lowercaseTarget = compilerOptions.target?.toLowerCase() ?? 'es3';
13386
+ if (lowercaseTarget.startsWith('es')) {
13387
+ const esVersion = lowercaseTarget.slice(2);
13388
+ compilerOptions.useDefineForClassFields =
13389
+ esVersion === 'next' || +esVersion >= 2022;
13390
+ }
13391
+ else {
13392
+ compilerOptions.useDefineForClassFields = false;
13393
+ }
13394
+ }
13395
+ }
13393
13396
  }
13394
13397
  const resolvedOptions = {
13395
13398
  sourcemap: true,
@@ -13529,7 +13532,7 @@ const buildEsbuildPlugin = (config) => {
13529
13532
  await initTSConfck(config);
13530
13533
  },
13531
13534
  async renderChunk(code, chunk, opts) {
13532
- // @ts-ignore injected by @vitejs/plugin-legacy
13535
+ // @ts-expect-error injected by @vitejs/plugin-legacy
13533
13536
  if (opts.__vite_skip_esbuild__) {
13534
13537
  return null;
13535
13538
  }
@@ -13843,7 +13846,7 @@ function terserPlugin(config) {
13843
13846
  // so that normal chunks can use the preferred minifier, and legacy chunks
13844
13847
  // can use terser.
13845
13848
  if (config.build.minify !== 'terser' &&
13846
- // @ts-ignore injected by @vitejs/plugin-legacy
13849
+ // @ts-expect-error injected by @vitejs/plugin-legacy
13847
13850
  !outputOptions.__vite_force_terser__) {
13848
13851
  return null;
13849
13852
  }
@@ -21609,6 +21612,43 @@ var acorn = {
21609
21612
  version: version$2
21610
21613
  };
21611
21614
 
21615
+ const HASH_RE = /#/g;
21616
+ const AMPERSAND_RE = /&/g;
21617
+ const EQUAL_RE = /=/g;
21618
+ const PLUS_RE = /\+/g;
21619
+ const ENC_BRACKET_OPEN_RE = /%5b/gi;
21620
+ const ENC_BRACKET_CLOSE_RE = /%5d/gi;
21621
+ const ENC_CARET_RE = /%5e/gi;
21622
+ const ENC_BACKTICK_RE = /%60/gi;
21623
+ const ENC_CURLY_OPEN_RE = /%7b/gi;
21624
+ const ENC_PIPE_RE = /%7c/gi;
21625
+ const ENC_CURLY_CLOSE_RE = /%7d/gi;
21626
+ const ENC_SPACE_RE = /%20/gi;
21627
+ function encode(text) {
21628
+ return encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
21629
+ }
21630
+ function encodeQueryValue(text) {
21631
+ return encode(text).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
21632
+ }
21633
+ function encodeQueryKey(text) {
21634
+ return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
21635
+ }
21636
+ function encodeQueryItem(key, value) {
21637
+ if (typeof value === "number" || typeof value === "boolean") {
21638
+ value = String(value);
21639
+ }
21640
+ if (!value) {
21641
+ return encodeQueryKey(key);
21642
+ }
21643
+ if (Array.isArray(value)) {
21644
+ return value.map((_value) => `${encodeQueryKey(key)}=${encodeQueryValue(_value)}`).join("&");
21645
+ }
21646
+ return `${encodeQueryKey(key)}=${encodeQueryValue(value)}`;
21647
+ }
21648
+ function stringifyQuery(query) {
21649
+ return Object.keys(query).filter((k) => query[k] !== void 0).map((k) => encodeQueryItem(k, query[k])).join("&");
21650
+ }
21651
+
21612
21652
  function matchAll(regex, string, addition) {
21613
21653
  const matches = [];
21614
21654
  for (const match of string.matchAll(regex)) {
@@ -22241,7 +22281,7 @@ function webWorkerPlugin(config) {
22241
22281
  return result();
22242
22282
  },
22243
22283
  generateBundle(opts) {
22244
- // @ts-ignore asset emits are skipped in legacy bundle
22284
+ // @ts-expect-error asset emits are skipped in legacy bundle
22245
22285
  if (opts.__vite_skip_asset_emit__ || isWorker) {
22246
22286
  return;
22247
22287
  }
@@ -36388,12 +36428,12 @@ function formatParseError(parserError, id, html) {
36388
36428
  const formattedError = {
36389
36429
  code: parserError.code,
36390
36430
  message: `parse5 error code ${parserError.code}`,
36391
- };
36392
- formattedError.frame = generateCodeFrame(html, parserError.startOffset);
36393
- formattedError.loc = {
36394
- file: id,
36395
- line: parserError.startLine,
36396
- column: parserError.startCol,
36431
+ frame: generateCodeFrame(html, parserError.startOffset),
36432
+ loc: {
36433
+ file: id,
36434
+ line: parserError.startLine,
36435
+ column: parserError.startCol,
36436
+ },
36397
36437
  };
36398
36438
  return formattedError;
36399
36439
  }
@@ -36413,12 +36453,10 @@ function handleParseError(parserError, html, filePath) {
36413
36453
  // Allow self closing on non-void elements #10439
36414
36454
  return;
36415
36455
  }
36416
- const parseError = {
36417
- loc: filePath,
36418
- frame: '',
36419
- ...formatParseError(parserError, filePath, html),
36420
- };
36421
- throw new Error(`Unable to parse HTML; ${parseError.message}\n at ${JSON.stringify(parseError.loc)}\n${parseError.frame}`);
36456
+ const parseError = formatParseError(parserError, filePath, html);
36457
+ throw new Error(`Unable to parse HTML; ${parseError.message}\n` +
36458
+ ` at ${parseError.loc.file}:${parseError.loc.line}:${parseError.loc.column}\n` +
36459
+ `${parseError.frame}`);
36422
36460
  }
36423
36461
  /**
36424
36462
  * Compiles index.html into an entry js module
@@ -37407,7 +37445,7 @@ function cssPostPlugin(config) {
37407
37445
  return null;
37408
37446
  },
37409
37447
  async generateBundle(opts, bundle) {
37410
- // @ts-ignore asset emits are skipped in legacy bundle
37448
+ // @ts-expect-error asset emits are skipped in legacy bundle
37411
37449
  if (opts.__vite_skip_asset_emit__) {
37412
37450
  return;
37413
37451
  }
@@ -37585,7 +37623,7 @@ async function compileCSS(id, code, config, urlReplacer) {
37585
37623
  }
37586
37624
  const postcssPlugins = postcssConfig && postcssConfig.plugins ? postcssConfig.plugins.slice() : [];
37587
37625
  if (needInlineImport) {
37588
- postcssPlugins.unshift((await import('./dep-1e0f5bc1.js').then(function (n) { return n.i; })).default({
37626
+ postcssPlugins.unshift((await import('./dep-a1fa0d33.js').then(function (n) { return n.i; })).default({
37589
37627
  async resolve(id, basedir) {
37590
37628
  const publicFile = checkPublicFile(id, config);
37591
37629
  if (publicFile) {
@@ -37609,7 +37647,7 @@ async function compileCSS(id, code, config, urlReplacer) {
37609
37647
  }));
37610
37648
  }
37611
37649
  if (isModule) {
37612
- postcssPlugins.unshift((await import('./dep-8f344fbd.js').then(function (n) { return n.i; })).default({
37650
+ postcssPlugins.unshift((await import('./dep-e4585742.js').then(function (n) { return n.i; })).default({
37613
37651
  ...modulesOptions,
37614
37652
  localsConvention: modulesOptions?.localsConvention,
37615
37653
  getJSON(cssFileName, _modules, outputFileName) {
@@ -37784,7 +37822,6 @@ async function resolvePostcssConfig(config, dialect = 'css') {
37784
37822
  else {
37785
37823
  const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root;
37786
37824
  try {
37787
- // @ts-ignore
37788
37825
  result = await src$1({}, searchPath);
37789
37826
  }
37790
37827
  catch (e) {
@@ -38034,11 +38071,9 @@ function fixScssBugImportValue(data) {
38034
38071
  typeof window !== 'undefined' &&
38035
38072
  typeof location !== 'undefined' &&
38036
38073
  data &&
38037
- // @ts-expect-error
38038
- data.file &&
38039
- // @ts-expect-error
38040
- data.contents == null) {
38041
- // @ts-expect-error
38074
+ 'file' in data &&
38075
+ (!('contents' in data) || data.contents == null)) {
38076
+ // @ts-expect-error we need to preserve file property for HMR
38042
38077
  data.contents = fs$l.readFileSync(data.file, 'utf-8');
38043
38078
  }
38044
38079
  return data;
@@ -38644,43 +38679,6 @@ base.MethodDefinition = base.PropertyDefinition = base.Property = function (node
38644
38679
  if (node.value) { c(node.value, st, "Expression"); }
38645
38680
  };
38646
38681
 
38647
- const HASH_RE = /#/g;
38648
- const AMPERSAND_RE = /&/g;
38649
- const EQUAL_RE = /=/g;
38650
- const PLUS_RE = /\+/g;
38651
- const ENC_BRACKET_OPEN_RE = /%5B/gi;
38652
- const ENC_BRACKET_CLOSE_RE = /%5D/gi;
38653
- const ENC_CARET_RE = /%5E/gi;
38654
- const ENC_BACKTICK_RE = /%60/gi;
38655
- const ENC_CURLY_OPEN_RE = /%7B/gi;
38656
- const ENC_PIPE_RE = /%7C/gi;
38657
- const ENC_CURLY_CLOSE_RE = /%7D/gi;
38658
- const ENC_SPACE_RE = /%20/gi;
38659
- function encode(text) {
38660
- return encodeURI("" + text).replace(ENC_PIPE_RE, "|").replace(ENC_BRACKET_OPEN_RE, "[").replace(ENC_BRACKET_CLOSE_RE, "]");
38661
- }
38662
- function encodeQueryValue(text) {
38663
- return encode(text).replace(PLUS_RE, "%2B").replace(ENC_SPACE_RE, "+").replace(HASH_RE, "%23").replace(AMPERSAND_RE, "%26").replace(ENC_BACKTICK_RE, "`").replace(ENC_CURLY_OPEN_RE, "{").replace(ENC_CURLY_CLOSE_RE, "}").replace(ENC_CARET_RE, "^");
38664
- }
38665
- function encodeQueryKey(text) {
38666
- return encodeQueryValue(text).replace(EQUAL_RE, "%3D");
38667
- }
38668
- function encodeQueryItem(key, val) {
38669
- if (typeof val === "number" || typeof val === "boolean") {
38670
- val = String(val);
38671
- }
38672
- if (!val) {
38673
- return encodeQueryKey(key);
38674
- }
38675
- if (Array.isArray(val)) {
38676
- return val.map((_val) => `${encodeQueryKey(key)}=${encodeQueryValue(_val)}`).join("&");
38677
- }
38678
- return `${encodeQueryKey(key)}=${encodeQueryValue(val)}`;
38679
- }
38680
- function stringifyQuery(query) {
38681
- return Object.keys(query).map((k) => encodeQueryItem(k, query[k])).join("&");
38682
- }
38683
-
38684
38682
  const { isMatch: isMatch$1, scan } = micromatch_1;
38685
38683
  function getAffectedGlobModules(file, server) {
38686
38684
  const modules = [];
@@ -39634,19 +39632,19 @@ function stattag (stat) {
39634
39632
  var convertSourceMap = {};
39635
39633
 
39636
39634
  (function (exports) {
39637
- var fs = require$$0__default;
39638
- var path = require$$0$4;
39639
39635
 
39640
39636
  Object.defineProperty(exports, 'commentRegex', {
39641
39637
  get: function getCommentRegex () {
39642
- return /^\s*\/(?:\/|\*)[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/mg;
39638
+ // Groups: 1: media type, 2: MIME type, 3: charset, 4: encoding, 5: data.
39639
+ return /^\s*?\/[\/\*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/mg;
39643
39640
  }
39644
39641
  });
39645
39642
 
39643
+
39646
39644
  Object.defineProperty(exports, 'mapFileCommentRegex', {
39647
39645
  get: function getMapFileCommentRegex () {
39648
39646
  // Matches sourceMappingURL in either // or /* comment styles.
39649
- return /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"`]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/){1}[ \t]*$)/mg;
39647
+ return /(?:\/\/[@#][ \t]+?sourceMappingURL=([^\s'"`]+?)[ \t]*?$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*?(?:\*\/){1}[ \t]*?$)/mg;
39650
39648
  }
39651
39649
  });
39652
39650
 
@@ -39680,29 +39678,43 @@ var convertSourceMap = {};
39680
39678
  return sm.split(',').pop();
39681
39679
  }
39682
39680
 
39683
- function readFromFileMap(sm, dir) {
39684
- // NOTE: this will only work on the server since it attempts to read the map file
39685
-
39681
+ function readFromFileMap(sm, read) {
39686
39682
  var r = exports.mapFileCommentRegex.exec(sm);
39687
-
39688
39683
  // for some odd reason //# .. captures in 1 and /* .. */ in 2
39689
39684
  var filename = r[1] || r[2];
39690
- var filepath = path.resolve(dir, filename);
39691
39685
 
39692
39686
  try {
39693
- return fs.readFileSync(filepath, 'utf8');
39687
+ var sm = read(filename);
39688
+ if (sm != null && typeof sm.catch === 'function') {
39689
+ return sm.catch(throwError);
39690
+ } else {
39691
+ return sm;
39692
+ }
39694
39693
  } catch (e) {
39695
- throw new Error('An error occurred while trying to read the map file at ' + filepath + '\n' + e);
39694
+ throwError(e);
39695
+ }
39696
+
39697
+ function throwError(e) {
39698
+ throw new Error('An error occurred while trying to read the map file at ' + filename + '\n' + e.stack);
39696
39699
  }
39697
39700
  }
39698
39701
 
39699
39702
  function Converter (sm, opts) {
39700
39703
  opts = opts || {};
39701
39704
 
39702
- if (opts.isFileComment) sm = readFromFileMap(sm, opts.commentFileDir);
39703
- if (opts.hasComment) sm = stripComment(sm);
39704
- if (opts.isEncoded) sm = decodeBase64(sm);
39705
- if (opts.isJSON || opts.isEncoded) sm = JSON.parse(sm);
39705
+ if (opts.hasComment) {
39706
+ sm = stripComment(sm);
39707
+ }
39708
+
39709
+ if (opts.encoding === 'base64') {
39710
+ sm = decodeBase64(sm);
39711
+ } else if (opts.encoding === 'uri') {
39712
+ sm = decodeURIComponent(sm);
39713
+ }
39714
+
39715
+ if (opts.isJSON || opts.encoding) {
39716
+ sm = JSON.parse(sm);
39717
+ }
39706
39718
 
39707
39719
  this.sourcemap = sm;
39708
39720
  }
@@ -39739,10 +39751,22 @@ var convertSourceMap = {};
39739
39751
  return btoa(unescape(encodeURIComponent(json)));
39740
39752
  }
39741
39753
 
39754
+ Converter.prototype.toURI = function () {
39755
+ var json = this.toJSON();
39756
+ return encodeURIComponent(json);
39757
+ };
39758
+
39742
39759
  Converter.prototype.toComment = function (options) {
39743
- var base64 = this.toBase64();
39744
- var data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64;
39745
- return options && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
39760
+ var encoding, content, data;
39761
+ if (options != null && options.encoding === 'uri') {
39762
+ encoding = '';
39763
+ content = this.toURI();
39764
+ } else {
39765
+ encoding = ';base64';
39766
+ content = this.toBase64();
39767
+ }
39768
+ data = 'sourceMappingURL=data:application/json;charset=utf-8' + encoding + ',' + content;
39769
+ return options != null && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
39746
39770
  };
39747
39771
 
39748
39772
  // returns copy instead of original
@@ -39772,20 +39796,42 @@ var convertSourceMap = {};
39772
39796
  return new Converter(json, { isJSON: true });
39773
39797
  };
39774
39798
 
39799
+ exports.fromURI = function (uri) {
39800
+ return new Converter(uri, { encoding: 'uri' });
39801
+ };
39802
+
39775
39803
  exports.fromBase64 = function (base64) {
39776
- return new Converter(base64, { isEncoded: true });
39804
+ return new Converter(base64, { encoding: 'base64' });
39777
39805
  };
39778
39806
 
39779
39807
  exports.fromComment = function (comment) {
39808
+ var m, encoding;
39780
39809
  comment = comment
39781
39810
  .replace(/^\/\*/g, '//')
39782
39811
  .replace(/\*\/$/g, '');
39783
-
39784
- return new Converter(comment, { isEncoded: true, hasComment: true });
39812
+ m = exports.commentRegex.exec(comment);
39813
+ encoding = m && m[4] || 'uri';
39814
+ return new Converter(comment, { encoding: encoding, hasComment: true });
39785
39815
  };
39786
39816
 
39787
- exports.fromMapFileComment = function (comment, dir) {
39788
- return new Converter(comment, { commentFileDir: dir, isFileComment: true, isJSON: true });
39817
+ function makeConverter(sm) {
39818
+ return new Converter(sm, { isJSON: true });
39819
+ }
39820
+
39821
+ exports.fromMapFileComment = function (comment, read) {
39822
+ if (typeof read === 'string') {
39823
+ throw new Error(
39824
+ 'String directory paths are no longer supported with `fromMapFileComment`\n' +
39825
+ 'Please review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading'
39826
+ )
39827
+ }
39828
+
39829
+ var sm = readFromFileMap(comment, read);
39830
+ if (sm != null && typeof sm.then === 'function') {
39831
+ return sm.then(makeConverter);
39832
+ } else {
39833
+ return makeConverter(sm);
39834
+ }
39789
39835
  };
39790
39836
 
39791
39837
  // Finds last sourcemap comment in file or returns null if none was found
@@ -39795,9 +39841,15 @@ var convertSourceMap = {};
39795
39841
  };
39796
39842
 
39797
39843
  // Finds last sourcemap comment in file or returns null if none was found
39798
- exports.fromMapFileSource = function (content, dir) {
39844
+ exports.fromMapFileSource = function (content, read) {
39845
+ if (typeof read === 'string') {
39846
+ throw new Error(
39847
+ 'String directory paths are no longer supported with `fromMapFileSource`\n' +
39848
+ 'Please review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading'
39849
+ )
39850
+ }
39799
39851
  var m = content.match(exports.mapFileCommentRegex);
39800
- return m ? exports.fromMapFileComment(m.pop(), dir) : null;
39852
+ return m ? exports.fromMapFileComment(m.pop(), read) : null;
39801
39853
  };
39802
39854
 
39803
39855
  exports.removeComments = function (src) {
@@ -39897,7 +39949,7 @@ function viaCache(cache, uri, extns) {
39897
39949
  }
39898
39950
  }
39899
39951
 
39900
- function viaLocal(dir, isEtag, uri, extns) {
39952
+ function viaLocal(dir, isEtag, uri, extns, shouldServe) {
39901
39953
  let i=0, arr=toAssume(uri, extns);
39902
39954
  let abs, stats, name, headers;
39903
39955
  for (; i < arr.length; i++) {
@@ -39905,6 +39957,7 @@ function viaLocal(dir, isEtag, uri, extns) {
39905
39957
  if (abs.startsWith(dir) && require$$0$2.existsSync(abs)) {
39906
39958
  stats = require$$0$2.statSync(abs);
39907
39959
  if (stats.isDirectory()) continue;
39960
+ if (shouldServe && !shouldServe(abs)) continue;
39908
39961
  headers = toHeaders(name, stats, isEtag);
39909
39962
  headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
39910
39963
  return { abs, stats, headers };
@@ -40034,7 +40087,7 @@ function sirv (dir, opts={}) {
40034
40087
  catch (err) { /* malform uri */ }
40035
40088
  }
40036
40089
 
40037
- let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
40090
+ let data = lookup(pathname, extns, opts.shouldServe) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns, opts.shouldServe);
40038
40091
  if (!data) return next ? next() : isNotFound(req, res);
40039
40092
 
40040
40093
  if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
@@ -40051,7 +40104,7 @@ function sirv (dir, opts={}) {
40051
40104
  };
40052
40105
  }
40053
40106
 
40054
- const sirvOptions = (headers) => {
40107
+ const sirvOptions = ({ headers, shouldServe, }) => {
40055
40108
  return {
40056
40109
  dev: true,
40057
40110
  etag: true,
@@ -40071,24 +40124,27 @@ const sirvOptions = (headers) => {
40071
40124
  }
40072
40125
  }
40073
40126
  },
40127
+ shouldServe,
40074
40128
  };
40075
40129
  };
40076
40130
  function servePublicMiddleware(dir, headers) {
40077
- const serve = sirv(dir, sirvOptions(headers));
40131
+ const serve = sirv(dir, sirvOptions({
40132
+ headers,
40133
+ shouldServe: (filePath) => shouldServeFile(filePath, dir),
40134
+ }));
40078
40135
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
40079
40136
  return function viteServePublicMiddleware(req, res, next) {
40080
40137
  // skip import request and internal requests `/@fs/ /@vite-client` etc...
40081
40138
  if (isImportRequest(req.url) || isInternalRequest(req.url)) {
40082
40139
  return next();
40083
40140
  }
40084
- if (shouldServe(req.url, dir)) {
40085
- return serve(req, res, next);
40086
- }
40087
- next();
40141
+ serve(req, res, next);
40088
40142
  };
40089
40143
  }
40090
40144
  function serveStaticMiddleware(dir, server) {
40091
- const serve = sirv(dir, sirvOptions(server.config.server.headers));
40145
+ const serve = sirv(dir, sirvOptions({
40146
+ headers: server.config.server.headers,
40147
+ }));
40092
40148
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
40093
40149
  return function viteServeStaticMiddleware(req, res, next) {
40094
40150
  // only serve the file if it's not an html request or ends with `/`
@@ -40136,7 +40192,7 @@ function serveStaticMiddleware(dir, server) {
40136
40192
  };
40137
40193
  }
40138
40194
  function serveRawFsMiddleware(server) {
40139
- const serveFromRoot = sirv('/', sirvOptions(server.config.server.headers));
40195
+ const serveFromRoot = sirv('/', sirvOptions({ headers: server.config.server.headers }));
40140
40196
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
40141
40197
  return function viteServeRawFsMiddleware(req, res, next) {
40142
40198
  const url = new URL(req.url, 'http://example.com');
@@ -40339,7 +40395,7 @@ async function loadAndTransform(id, url, server, options, timestamp) {
40339
40395
  if (code) {
40340
40396
  try {
40341
40397
  map = (convertSourceMap.fromSource(code) ||
40342
- convertSourceMap.fromMapFileSource(code, path$o.dirname(file)))?.toObject();
40398
+ (await convertSourceMap.fromMapFileSource(code, createConvertSourceMapReadMap(file))))?.toObject();
40343
40399
  code = code.replace(convertSourceMap.mapFileCommentRegex, blankReplacer);
40344
40400
  }
40345
40401
  catch (e) {
@@ -40414,6 +40470,11 @@ async function loadAndTransform(id, url, server, options, timestamp) {
40414
40470
  }
40415
40471
  return result;
40416
40472
  }
40473
+ function createConvertSourceMapReadMap(originalFileName) {
40474
+ return (filename) => {
40475
+ return promises$2.readFile(path$o.resolve(path$o.dirname(originalFileName), filename), 'utf-8');
40476
+ };
40477
+ }
40417
40478
 
40418
40479
  const isDebug$1 = !!process.env.DEBUG;
40419
40480
  const debug$9 = createDebugger('vite:import-analysis');
@@ -40695,26 +40756,6 @@ function importAnalysisPlugin(config) {
40695
40756
  if (!isDynamicImport && assertIndex > -1) {
40696
40757
  str().remove(end + 1, expEnd);
40697
40758
  }
40698
- if (!isDynamicImport &&
40699
- specifier &&
40700
- !specifier.includes('?') && // ignore custom queries
40701
- isCSSRequest(specifier) &&
40702
- !isModuleCSSRequest(specifier)) {
40703
- const sourceExp = source.slice(expStart, start);
40704
- if (sourceExp.includes('from') && // check default and named imports
40705
- !sourceExp.includes('__vite_glob_') // glob handles deprecation message itself
40706
- ) {
40707
- const newImport = sourceExp + specifier + `?inline` + source.slice(end, expEnd);
40708
- this.warn(`\n` +
40709
- picocolors.exports.cyan(importerModule.file) +
40710
- `\n` +
40711
- picocolors.exports.reset(generateCodeFrame(source, start)) +
40712
- `\n` +
40713
- picocolors.exports.yellow(`Default and named imports from CSS files are deprecated. ` +
40714
- `Use the ?inline query instead. ` +
40715
- `For example: ${newImport}`));
40716
- }
40717
- }
40718
40759
  // static import or valid string in dynamic import
40719
40760
  // If resolvable, let's resolve it
40720
40761
  if (specifier) {
@@ -40751,6 +40792,26 @@ function importAnalysisPlugin(config) {
40751
40792
  }
40752
40793
  // normalize
40753
40794
  const [url, resolvedId] = await normalizeUrl(specifier, start);
40795
+ if (!isDynamicImport &&
40796
+ specifier &&
40797
+ !specifier.includes('?') && // ignore custom queries
40798
+ isCSSRequest(resolvedId) &&
40799
+ !isModuleCSSRequest(resolvedId)) {
40800
+ const sourceExp = source.slice(expStart, start);
40801
+ if (sourceExp.includes('from') && // check default and named imports
40802
+ !sourceExp.includes('__vite_glob_') // glob handles deprecation message itself
40803
+ ) {
40804
+ const newImport = sourceExp + specifier + `?inline` + source.slice(end, expEnd);
40805
+ this.warn(`\n` +
40806
+ picocolors.exports.cyan(importerModule.file) +
40807
+ `\n` +
40808
+ picocolors.exports.reset(generateCodeFrame(source, start)) +
40809
+ `\n` +
40810
+ picocolors.exports.yellow(`Default and named imports from CSS files are deprecated. ` +
40811
+ `Use the ?inline query instead. ` +
40812
+ `For example: ${newImport}`));
40813
+ }
40814
+ }
40754
40815
  // record as safe modules
40755
40816
  server?.moduleGraph.safeModulesPath.add(fsPathFromUrl(url));
40756
40817
  if (url !== specifier) {
@@ -41072,7 +41133,7 @@ function clientInjectionsPlugin(config) {
41072
41133
  }
41073
41134
  return code
41074
41135
  .replace(`__MODE__`, JSON.stringify(config.mode))
41075
- .replace(`__BASE__`, JSON.stringify(devBase))
41136
+ .replace(/__BASE__/g, JSON.stringify(devBase))
41076
41137
  .replace(`__DEFINES__`, serializeDefine(config.define || {}))
41077
41138
  .replace(`__SERVER_HOST__`, JSON.stringify(serverHost))
41078
41139
  .replace(`__HMR_PROTOCOL__`, JSON.stringify(protocol))
@@ -41112,7 +41173,6 @@ const wasmHelper = async (opts = {}, url) => {
41112
41173
  bytes = Buffer.from(urlContent, 'base64');
41113
41174
  }
41114
41175
  else if (typeof atob === 'function') {
41115
- // @ts-ignore
41116
41176
  const binaryString = atob(urlContent);
41117
41177
  bytes = new Uint8Array(binaryString.length);
41118
41178
  for (let i = 0; i < binaryString.length; i++) {
@@ -41122,7 +41182,6 @@ const wasmHelper = async (opts = {}, url) => {
41122
41182
  else {
41123
41183
  throw new Error('Failed to decode base64-encoded data URL, Buffer and atob are not supported');
41124
41184
  }
41125
- // @ts-ignore
41126
41185
  result = await WebAssembly.instantiate(bytes, opts);
41127
41186
  }
41128
41187
  else {
@@ -41131,19 +41190,14 @@ const wasmHelper = async (opts = {}, url) => {
41131
41190
  // correct MIME type for .wasm files, which unfortunately doesn't work for
41132
41191
  // a lot of static file servers, so we just work around it by getting the
41133
41192
  // raw buffer.
41134
- // @ts-ignore
41135
41193
  const response = await fetch(url);
41136
41194
  const contentType = response.headers.get('Content-Type') || '';
41137
- if (
41138
- // @ts-ignore
41139
- 'instantiateStreaming' in WebAssembly &&
41195
+ if ('instantiateStreaming' in WebAssembly &&
41140
41196
  contentType.startsWith('application/wasm')) {
41141
- // @ts-ignore
41142
41197
  result = await WebAssembly.instantiateStreaming(response, opts);
41143
41198
  }
41144
41199
  else {
41145
41200
  const buffer = await response.arrayBuffer();
41146
- // @ts-ignore
41147
41201
  result = await WebAssembly.instantiate(buffer, opts);
41148
41202
  }
41149
41203
  }
@@ -42173,7 +42227,7 @@ async function createPluginContainer(config, moduleGraph, watcher) {
42173
42227
  const hook = plugin[hookName];
42174
42228
  if (!hook)
42175
42229
  continue;
42176
- // @ts-expect-error
42230
+ // @ts-expect-error hook is not a primitive
42177
42231
  const handler = 'handler' in hook ? hook.handler : hook;
42178
42232
  if (hook.sequential) {
42179
42233
  await Promise.all(parallelPromises);
@@ -43348,7 +43402,7 @@ async function createDepsOptimizer(config, server) {
43348
43402
  metadata.discovered = {};
43349
43403
  }
43350
43404
  currentlyProcessing = false;
43351
- // @ts-ignore
43405
+ // @ts-expect-error `enqueuedRerun` could exist because `debouncedProcessing` may run while awaited
43352
43406
  enqueuedRerun?.();
43353
43407
  }
43354
43408
  function fullReload() {
@@ -44321,26 +44375,22 @@ function toRelativePath(filename, importer) {
44321
44375
  * the async chunk itself.
44322
44376
  */
44323
44377
  function detectScriptRel() {
44324
- // @ts-ignore
44325
44378
  const relList = document.createElement('link').relList;
44326
- // @ts-ignore
44327
44379
  return relList && relList.supports && relList.supports('modulepreload')
44328
44380
  ? 'modulepreload'
44329
44381
  : 'preload';
44330
44382
  }
44331
44383
  function preload(baseModule, deps, importerUrl) {
44332
- // @ts-ignore
44384
+ // @ts-expect-error __VITE_IS_MODERN__ will be replaced with boolean later
44333
44385
  if (!__VITE_IS_MODERN__ || !deps || deps.length === 0) {
44334
44386
  return baseModule();
44335
44387
  }
44336
44388
  const links = document.getElementsByTagName('link');
44337
44389
  return Promise.all(deps.map((dep) => {
44338
- // @ts-ignore
44390
+ // @ts-expect-error assetsURL is declared before preload.toString()
44339
44391
  dep = assetsURL(dep, importerUrl);
44340
- // @ts-ignore
44341
44392
  if (dep in seen)
44342
44393
  return;
44343
- // @ts-ignore
44344
44394
  seen[dep] = true;
44345
44395
  const isCss = dep.endsWith('.css');
44346
44396
  const cssSelector = isCss ? '[rel="stylesheet"]' : '';
@@ -44361,16 +44411,13 @@ function preload(baseModule, deps, importerUrl) {
44361
44411
  else if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
44362
44412
  return;
44363
44413
  }
44364
- // @ts-ignore
44365
44414
  const link = document.createElement('link');
44366
- // @ts-ignore
44367
44415
  link.rel = isCss ? 'stylesheet' : scriptRel;
44368
44416
  if (!isCss) {
44369
44417
  link.as = 'script';
44370
44418
  link.crossOrigin = '';
44371
44419
  }
44372
44420
  link.href = dep;
44373
- // @ts-ignore
44374
44421
  document.head.appendChild(link);
44375
44422
  if (isCss) {
44376
44423
  return new Promise((res, rej) => {
@@ -45246,6 +45293,10 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
45246
45293
  return [];
45247
45294
  return Object.entries(parse_1$1(fs$l.readFileSync(path)));
45248
45295
  }));
45296
+ // test NODE_ENV override before expand as otherwise process.env.NODE_ENV would override this
45297
+ if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === undefined) {
45298
+ process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV;
45299
+ }
45249
45300
  try {
45250
45301
  // let environment variables use each other
45251
45302
  expand_1({ parsed });
@@ -45263,11 +45314,6 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
45263
45314
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
45264
45315
  env[key] = value;
45265
45316
  }
45266
- else if (key === 'NODE_ENV' &&
45267
- process.env.VITE_USER_NODE_ENV === undefined) {
45268
- // NODE_ENV override in .env file
45269
- process.env.VITE_USER_NODE_ENV = value;
45270
- }
45271
45317
  }
45272
45318
  // check if there are actual env variables starting with VITE_*
45273
45319
  // these are typically provided inline and should be prioritized
@@ -45489,8 +45535,7 @@ async function doBuild(inlineConfig = {}) {
45489
45535
  };
45490
45536
  try {
45491
45537
  const buildOutputOptions = (output = {}) => {
45492
- // See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
45493
- // @ts-ignore
45538
+ // @ts-expect-error See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
45494
45539
  if (output.output) {
45495
45540
  config.logger.warn(`You've set "rollupOptions.output.output" in your config. ` +
45496
45541
  `This is deprecated and will override all Vite.js default output options. ` +
@@ -45906,7 +45951,7 @@ function toOutputFilePathWithoutRuntime(filename, type, hostId, hostType, config
45906
45951
  });
45907
45952
  if (typeof result === 'object') {
45908
45953
  if (result.runtime) {
45909
- throw new Error(`{ runtime: "${result.runtime} }" is not supported for assets in ${hostType} files: ${filename}`);
45954
+ throw new Error(`{ runtime: "${result.runtime}" } is not supported for assets in ${hostType} files: ${filename}`);
45910
45955
  }
45911
45956
  if (typeof result.relative === 'boolean') {
45912
45957
  relative = result.relative;
@@ -53269,7 +53314,7 @@ async function nodeImport(id, importer, resolveOptions) {
53269
53314
  const resolved = tryNodeResolve(id, importer,
53270
53315
  // Non-external modules can import ESM-only modules, but only outside
53271
53316
  // of test runs, because we use Node `require` in Jest to avoid segfault.
53272
- // @ts-expect-error
53317
+ // @ts-expect-error jest only exists when running Jest
53273
53318
  typeof jest === 'undefined'
53274
53319
  ? { ...resolveOptions, tryEsmOnly: true }
53275
53320
  : resolveOptions, false);
@@ -54401,12 +54446,14 @@ function startBrowserProcess(browser, url) {
54401
54446
  const openedBrowser = preferredOSXBrowser && ps.includes(preferredOSXBrowser)
54402
54447
  ? preferredOSXBrowser
54403
54448
  : supportedChromiumBrowsers.find((b) => ps.includes(b));
54404
- // Try our best to reuse existing tab with AppleScript
54405
- execSync(`osascript openChrome.applescript "${encodeURI(url)}" "${openedBrowser}"`, {
54406
- cwd: join$2(VITE_PACKAGE_DIR, 'bin'),
54407
- stdio: 'ignore',
54408
- });
54409
- return true;
54449
+ if (openedBrowser) {
54450
+ // Try our best to reuse existing tab with AppleScript
54451
+ execSync(`osascript openChrome.applescript "${encodeURI(url)}" "${openedBrowser}"`, {
54452
+ cwd: join$2(VITE_PACKAGE_DIR, 'bin'),
54453
+ stdio: 'ignore',
54454
+ });
54455
+ return true;
54456
+ }
54410
54457
  }
54411
54458
  catch (err) {
54412
54459
  // Ignore errors
@@ -54484,6 +54531,14 @@ const BASE_SHORTCUTS = [
54484
54531
  await server.restart();
54485
54532
  },
54486
54533
  },
54534
+ {
54535
+ key: 'u',
54536
+ description: 'show server url',
54537
+ action(server) {
54538
+ server.config.logger.info('');
54539
+ server.printUrls();
54540
+ },
54541
+ },
54487
54542
  {
54488
54543
  key: 'o',
54489
54544
  description: 'open in browser',
@@ -61591,7 +61646,7 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
61591
61646
  }
61592
61647
  s.update(node.sourceCodeLocation.startOffset, node.sourceCodeLocation.endOffset, `<script type="module" src="${modulePath}"></script>`);
61593
61648
  };
61594
- await traverseHtml(html, htmlPath, (node) => {
61649
+ await traverseHtml(html, filename, (node) => {
61595
61650
  if (!nodeIsElement(node)) {
61596
61651
  return;
61597
61652
  }
@@ -61682,7 +61737,6 @@ function timeMiddleware(root) {
61682
61737
  const end = res.end;
61683
61738
  res.end = (...args) => {
61684
61739
  logTime(`${timeFrom(start)} ${prettifyUrl(req.url, root)}`);
61685
- // @ts-ignore
61686
61740
  return end.call(res, ...args);
61687
61741
  };
61688
61742
  next();
@@ -62167,7 +62221,7 @@ async function startServer(server, inlinePort, isRestart = false) {
62167
62221
  const path = typeof options.open === 'string' ? options.open : server.config.base;
62168
62222
  openBrowser(path.startsWith('http')
62169
62223
  ? path
62170
- : `${protocol}://${hostname.name}:${serverPort}${path}`, true, server.config.logger);
62224
+ : new URL(path, `${protocol}://${hostname.name}:${serverPort}`).href, true, server.config.logger);
62171
62225
  }
62172
62226
  }
62173
62227
  function createServerCloseFn(server) {
@@ -62234,7 +62288,6 @@ function resolveServerOptions(root, raw, logger) {
62234
62288
  return server;
62235
62289
  }
62236
62290
  async function restartServer(server) {
62237
- // @ts-ignore
62238
62291
  global.__vite_start_time = performance.now();
62239
62292
  const { port: prevPort, host: prevHost } = server.config.server;
62240
62293
  const shortcutsOptions = server._shortcutsOptions;
@@ -62257,17 +62310,9 @@ async function restartServer(server) {
62257
62310
  });
62258
62311
  return;
62259
62312
  }
62260
- for (const key in newServer) {
62261
- if (key === '_restartPromise') {
62262
- // prevent new server `restart` function from calling
62263
- // @ts-ignore
62264
- newServer[key] = server[key];
62265
- }
62266
- else {
62267
- // @ts-ignore
62268
- server[key] = newServer[key];
62269
- }
62270
- }
62313
+ // prevent new server `restart` function from calling
62314
+ newServer._restartPromise = server._restartPromise;
62315
+ Object.assign(server, newServer);
62271
62316
  const { logger, server: { port, host, middlewareMode }, } = server.config;
62272
62317
  if (!middlewareMode) {
62273
62318
  await server.listen(port, true);
@@ -62315,7 +62360,7 @@ var index = {
62315
62360
  searchForWorkspaceRoot: searchForWorkspaceRoot
62316
62361
  };
62317
62362
 
62318
- //@ts-nocheck
62363
+ /* eslint-disable */
62319
62364
  /* global Buffer */
62320
62365
  const noop = () => { };
62321
62366
  const mimes = /text|javascript|\/json|xml/i;
@@ -62346,7 +62391,6 @@ function compression() {
62346
62391
  let size = 0;
62347
62392
  function start() {
62348
62393
  started = true;
62349
- // @ts-ignore
62350
62394
  size = res.getHeader('Content-Length') | 0 || size;
62351
62395
  const compressible = mimes.test(String(res.getHeader('Content-Type') || 'text/plain'));
62352
62396
  const cleartext = !res.getHeader('Content-Encoding');
@@ -62473,13 +62517,11 @@ async function preview(inlineConfig = {}) {
62473
62517
  }
62474
62518
  }
62475
62519
  },
62520
+ shouldServe(filePath) {
62521
+ return shouldServeFile(filePath, distDir);
62522
+ },
62476
62523
  });
62477
- app.use(previewBase, async (req, res, next) => {
62478
- if (shouldServe(req.url, distDir)) {
62479
- return assetServer(req, res, next);
62480
- }
62481
- next();
62482
- });
62524
+ app.use(previewBase, assetServer);
62483
62525
  // apply post server hooks from plugins
62484
62526
  postHooks.forEach((fn) => fn && fn());
62485
62527
  const options = config.preview;
@@ -62498,7 +62540,7 @@ async function preview(inlineConfig = {}) {
62498
62540
  const path = typeof options.open === 'string' ? options.open : previewBase;
62499
62541
  openBrowser(path.startsWith('http')
62500
62542
  ? path
62501
- : `${protocol}://${hostname.name}:${serverPort}${path}`, true, logger);
62543
+ : new URL(path, `${protocol}://${hostname.name}:${serverPort}`).href, true, logger);
62502
62544
  }
62503
62545
  return {
62504
62546
  config,
@@ -62622,14 +62664,11 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
62622
62664
  // resolve root
62623
62665
  const resolvedRoot = normalizePath$3(config.root ? path$o.resolve(config.root) : process.cwd());
62624
62666
  const clientAlias = [
62625
- { find: /^\/?@vite\/env/, replacement: () => ENV_ENTRY },
62626
- { find: /^\/?@vite\/client/, replacement: () => CLIENT_ENTRY },
62667
+ { find: /^\/?@vite\/env/, replacement: ENV_ENTRY },
62668
+ { find: /^\/?@vite\/client/, replacement: CLIENT_ENTRY },
62627
62669
  ];
62628
62670
  // resolve alias with internal client alias
62629
- const resolvedAlias = normalizeAlias(mergeAlias(
62630
- // @ts-ignore because @rollup/plugin-alias' type doesn't allow function
62631
- // replacement, but its implementation does work with function values.
62632
- clientAlias, config.resolve?.alias || []));
62671
+ const resolvedAlias = normalizeAlias(mergeAlias(clientAlias, config.resolve?.alias || []));
62633
62672
  const resolveOptions = {
62634
62673
  mainFields: config.resolve?.mainFields ?? DEFAULT_MAIN_FIELDS,
62635
62674
  browserField: config.resolve?.browserField ?? true,