vite 3.2.0-beta.0 → 3.2.0-beta.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.
@@ -1,5 +1,5 @@
1
1
  import require$$0$1 from 'postcss';
2
- import { z as commonjsGlobal } from './dep-92763d7a.js';
2
+ import { z as commonjsGlobal } from './dep-0856a44a.js';
3
3
  import require$$0 from 'path';
4
4
  import require$$5 from 'crypto';
5
5
  import require$$0__default from 'fs';
@@ -1,11 +1,11 @@
1
1
  import fs$l, { promises as promises$2 } from 'node:fs';
2
- import path$n, { posix as posix$2, isAbsolute as isAbsolute$3, resolve as resolve$6, join as join$2, relative as relative$2, dirname as dirname$2, basename as basename$2, extname as extname$1 } from 'node:path';
2
+ import path$n, { posix as posix$2, isAbsolute as isAbsolute$2, resolve as resolve$6, join as join$2, relative as relative$2, dirname as dirname$2, basename as basename$2, extname as extname$1 } from 'node:path';
3
3
  import { URL as URL$3, pathToFileURL, URLSearchParams, parse as parse$k } from 'node:url';
4
4
  import { performance } from 'node:perf_hooks';
5
5
  import { createRequire as createRequire$1, builtinModules } from 'node:module';
6
6
  import require$$0$3 from 'tty';
7
7
  import { transform as transform$2, build as build$3, formatMessages } from 'esbuild';
8
- import require$$0$4, { sep, resolve as resolve$4, posix as posix$1, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, win32 as win32$1, isAbsolute as isAbsolute$2, normalize } from 'path';
8
+ import require$$0$4, { sep, resolve as resolve$4, posix as posix$1, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, win32 as win32$1, isAbsolute as isAbsolute$1, normalize } from 'path';
9
9
  import * as require$$0$2 from 'fs';
10
10
  import require$$0__default, { existsSync, readFileSync, statSync as statSync$1, promises as promises$1, readdirSync } from 'fs';
11
11
  import require$$0$5 from 'events';
@@ -165,14 +165,21 @@ function getEntries({ entries, customResolver }) {
165
165
  return { find: key, replacement: value, resolverFunction: resolverFunctionFromOptions };
166
166
  });
167
167
  }
168
+ function getHookFunction(hook) {
169
+ if (typeof hook === 'function') {
170
+ return hook;
171
+ }
172
+ if (hook && 'handler' in hook && typeof hook.handler === 'function') {
173
+ return hook.handler;
174
+ }
175
+ return null;
176
+ }
168
177
  function resolveCustomResolver(customResolver) {
178
+ if (typeof customResolver === 'function') {
179
+ return customResolver;
180
+ }
169
181
  if (customResolver) {
170
- if (typeof customResolver === 'function') {
171
- return customResolver;
172
- }
173
- if (typeof customResolver.resolveId === 'function') {
174
- return customResolver.resolveId;
175
- }
182
+ return getHookFunction(customResolver.resolveId);
176
183
  }
177
184
  return null;
178
185
  }
@@ -187,10 +194,7 @@ function alias$1(options = {}) {
187
194
  return {
188
195
  name: 'alias',
189
196
  async buildStart(inputOptions) {
190
- await Promise.all([...(Array.isArray(options.entries) ? options.entries : []), options].map(({ customResolver }) => customResolver &&
191
- typeof customResolver === 'object' &&
192
- typeof customResolver.buildStart === 'function' &&
193
- customResolver.buildStart.call(this, inputOptions)));
197
+ await Promise.all([...(Array.isArray(options.entries) ? options.entries : []), options].map(({ customResolver }) => { var _a; return customResolver && ((_a = getHookFunction(customResolver.buildStart)) === null || _a === void 0 ? void 0 : _a.call(this, inputOptions)); }));
194
198
  },
195
199
  resolveId(importee, importer, resolveOptions) {
196
200
  if (!importer) {
@@ -4327,7 +4331,7 @@ function ownProp (obj, field) {
4327
4331
  var fs$i = require$$0__default;
4328
4332
  var path$i = require$$0$4;
4329
4333
  var minimatch = minimatch_1;
4330
- var isAbsolute$1 = pathIsAbsolute.exports;
4334
+ var isAbsolute = pathIsAbsolute.exports;
4331
4335
  var Minimatch = minimatch.Minimatch;
4332
4336
 
4333
4337
  function alphasort (a, b) {
@@ -4415,7 +4419,7 @@ function setopts (self, pattern, options) {
4415
4419
 
4416
4420
  // TODO: is an absolute `cwd` supposed to be resolved against `root`?
4417
4421
  // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
4418
- self.cwdAbs = isAbsolute$1(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
4422
+ self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
4419
4423
  if (process.platform === "win32")
4420
4424
  self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
4421
4425
  self.nomount = !!options.nomount;
@@ -4514,7 +4518,7 @@ function makeAbs (self, f) {
4514
4518
  var abs = f;
4515
4519
  if (f.charAt(0) === '/') {
4516
4520
  abs = path$i.join(self.root, f);
4517
- } else if (isAbsolute$1(f) || f === '') {
4521
+ } else if (isAbsolute(f) || f === '') {
4518
4522
  abs = f;
4519
4523
  } else if (self.changedCwd) {
4520
4524
  abs = path$i.resolve(self.cwd, f);
@@ -9645,16 +9649,30 @@ const schemeRegex = /^[\w+.-]+:\/\//;
9645
9649
  * 3. Host, guaranteed.
9646
9650
  * 4. Port, including ":", optional.
9647
9651
  * 5. Path, including "/", optional.
9652
+ * 6. Query, including "?", optional.
9653
+ * 7. Hash, including "#", optional.
9648
9654
  */
9649
- const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?/;
9655
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
9650
9656
  /**
9651
9657
  * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
9652
9658
  * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
9653
9659
  *
9654
9660
  * 1. Host, optional.
9655
- * 2. Path, which may inclue "/", guaranteed.
9656
- */
9657
- const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/]*)?)?(\/?.*)/i;
9661
+ * 2. Path, which may include "/", guaranteed.
9662
+ * 3. Query, including "?", optional.
9663
+ * 4. Hash, including "#", optional.
9664
+ */
9665
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
9666
+ var UrlType;
9667
+ (function (UrlType) {
9668
+ UrlType[UrlType["Empty"] = 1] = "Empty";
9669
+ UrlType[UrlType["Hash"] = 2] = "Hash";
9670
+ UrlType[UrlType["Query"] = 3] = "Query";
9671
+ UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
9672
+ UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
9673
+ UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
9674
+ UrlType[UrlType["Absolute"] = 7] = "Absolute";
9675
+ })(UrlType || (UrlType = {}));
9658
9676
  function isAbsoluteUrl(input) {
9659
9677
  return schemeRegex.test(input);
9660
9678
  }
@@ -9667,35 +9685,42 @@ function isAbsolutePath(input) {
9667
9685
  function isFileUrl(input) {
9668
9686
  return input.startsWith('file:');
9669
9687
  }
9688
+ function isRelative(input) {
9689
+ return /^[.?#]/.test(input);
9690
+ }
9670
9691
  function parseAbsoluteUrl(input) {
9671
9692
  const match = urlRegex.exec(input);
9672
- return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/');
9693
+ return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
9673
9694
  }
9674
9695
  function parseFileUrl(input) {
9675
9696
  const match = fileRegex.exec(input);
9676
9697
  const path = match[2];
9677
- return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path);
9698
+ return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
9678
9699
  }
9679
- function makeUrl(scheme, user, host, port, path) {
9700
+ function makeUrl(scheme, user, host, port, path, query, hash) {
9680
9701
  return {
9681
9702
  scheme,
9682
9703
  user,
9683
9704
  host,
9684
9705
  port,
9685
9706
  path,
9686
- relativePath: false,
9707
+ query,
9708
+ hash,
9709
+ type: UrlType.Absolute,
9687
9710
  };
9688
9711
  }
9689
9712
  function parseUrl$2(input) {
9690
9713
  if (isSchemeRelativeUrl(input)) {
9691
9714
  const url = parseAbsoluteUrl('http:' + input);
9692
9715
  url.scheme = '';
9716
+ url.type = UrlType.SchemeRelative;
9693
9717
  return url;
9694
9718
  }
9695
9719
  if (isAbsolutePath(input)) {
9696
9720
  const url = parseAbsoluteUrl('http://foo.com' + input);
9697
9721
  url.scheme = '';
9698
9722
  url.host = '';
9723
+ url.type = UrlType.AbsolutePath;
9699
9724
  return url;
9700
9725
  }
9701
9726
  if (isFileUrl(input))
@@ -9705,7 +9730,13 @@ function parseUrl$2(input) {
9705
9730
  const url = parseAbsoluteUrl('http://foo.com/' + input);
9706
9731
  url.scheme = '';
9707
9732
  url.host = '';
9708
- url.relativePath = true;
9733
+ url.type = input
9734
+ ? input.startsWith('?')
9735
+ ? UrlType.Query
9736
+ : input.startsWith('#')
9737
+ ? UrlType.Hash
9738
+ : UrlType.RelativePath
9739
+ : UrlType.Empty;
9709
9740
  return url;
9710
9741
  }
9711
9742
  function stripPathFilename(path) {
@@ -9717,10 +9748,7 @@ function stripPathFilename(path) {
9717
9748
  return path.slice(0, index + 1);
9718
9749
  }
9719
9750
  function mergePaths(url, base) {
9720
- // If we're not a relative path, then we're an absolute path, and it doesn't matter what base is.
9721
- if (!url.relativePath)
9722
- return;
9723
- normalizePath$5(base);
9751
+ normalizePath$5(base, base.type);
9724
9752
  // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
9725
9753
  // path).
9726
9754
  if (url.path === '/') {
@@ -9730,15 +9758,13 @@ function mergePaths(url, base) {
9730
9758
  // Resolution happens relative to the base path's directory, not the file.
9731
9759
  url.path = stripPathFilename(base.path) + url.path;
9732
9760
  }
9733
- // If the base path is absolute, then our path is now absolute too.
9734
- url.relativePath = base.relativePath;
9735
9761
  }
9736
9762
  /**
9737
9763
  * The path can have empty directories "//", unneeded parents "foo/..", or current directory
9738
9764
  * "foo/.". We need to normalize to a standard representation.
9739
9765
  */
9740
- function normalizePath$5(url) {
9741
- const { relativePath } = url;
9766
+ function normalizePath$5(url, type) {
9767
+ const rel = type <= UrlType.RelativePath;
9742
9768
  const pieces = url.path.split('/');
9743
9769
  // We need to preserve the first piece always, so that we output a leading slash. The item at
9744
9770
  // pieces[0] is an empty string.
@@ -9770,7 +9796,7 @@ function normalizePath$5(url) {
9770
9796
  positive--;
9771
9797
  pointer--;
9772
9798
  }
9773
- else if (relativePath) {
9799
+ else if (rel) {
9774
9800
  // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
9775
9801
  // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
9776
9802
  pieces[pointer++] = piece;
@@ -9798,37 +9824,60 @@ function resolve$3(input, base) {
9798
9824
  if (!input && !base)
9799
9825
  return '';
9800
9826
  const url = parseUrl$2(input);
9801
- // If we have a base, and the input isn't already an absolute URL, then we need to merge.
9802
- if (base && !url.scheme) {
9827
+ let inputType = url.type;
9828
+ if (base && inputType !== UrlType.Absolute) {
9803
9829
  const baseUrl = parseUrl$2(base);
9804
- url.scheme = baseUrl.scheme;
9805
- // If there's no host, then we were just a path.
9806
- if (!url.host) {
9807
- // The host, user, and port are joined, you can't copy one without the others.
9808
- url.user = baseUrl.user;
9809
- url.host = baseUrl.host;
9810
- url.port = baseUrl.port;
9811
- }
9812
- mergePaths(url, baseUrl);
9813
- }
9814
- normalizePath$5(url);
9815
- // If the input (and base, if there was one) are both relative, then we need to output a relative.
9816
- if (url.relativePath) {
9817
- // The first char is always a "/".
9818
- const path = url.path.slice(1);
9819
- if (!path)
9820
- return '.';
9821
- // If base started with a leading ".", or there is no base and input started with a ".", then we
9822
- // need to ensure that the relative path starts with a ".". We don't know if relative starts
9823
- // with a "..", though, so check before prepending.
9824
- const keepRelative = (base || input).startsWith('.');
9825
- return !keepRelative || path.startsWith('.') ? path : './' + path;
9830
+ const baseType = baseUrl.type;
9831
+ switch (inputType) {
9832
+ case UrlType.Empty:
9833
+ url.hash = baseUrl.hash;
9834
+ // fall through
9835
+ case UrlType.Hash:
9836
+ url.query = baseUrl.query;
9837
+ // fall through
9838
+ case UrlType.Query:
9839
+ case UrlType.RelativePath:
9840
+ mergePaths(url, baseUrl);
9841
+ // fall through
9842
+ case UrlType.AbsolutePath:
9843
+ // The host, user, and port are joined, you can't copy one without the others.
9844
+ url.user = baseUrl.user;
9845
+ url.host = baseUrl.host;
9846
+ url.port = baseUrl.port;
9847
+ // fall through
9848
+ case UrlType.SchemeRelative:
9849
+ // The input doesn't have a schema at least, so we need to copy at least that over.
9850
+ url.scheme = baseUrl.scheme;
9851
+ }
9852
+ if (baseType > inputType)
9853
+ inputType = baseType;
9854
+ }
9855
+ normalizePath$5(url, inputType);
9856
+ const queryHash = url.query + url.hash;
9857
+ switch (inputType) {
9858
+ // This is impossible, because of the empty checks at the start of the function.
9859
+ // case UrlType.Empty:
9860
+ case UrlType.Hash:
9861
+ case UrlType.Query:
9862
+ return queryHash;
9863
+ case UrlType.RelativePath: {
9864
+ // The first char is always a "/", and we need it to be relative.
9865
+ const path = url.path.slice(1);
9866
+ if (!path)
9867
+ return queryHash || '.';
9868
+ if (isRelative(base || input) && !isRelative(path)) {
9869
+ // If base started with a leading ".", or there is no base and input started with a ".",
9870
+ // then we need to ensure that the relative path starts with a ".". We don't know if
9871
+ // relative starts with a "..", though, so check before prepending.
9872
+ return './' + path + queryHash;
9873
+ }
9874
+ return path + queryHash;
9875
+ }
9876
+ case UrlType.AbsolutePath:
9877
+ return url.path + queryHash;
9878
+ default:
9879
+ return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
9826
9880
  }
9827
- // If there's no host (and no scheme/user/port), then we need to output an absolute path.
9828
- if (!url.scheme && !url.host)
9829
- return url.path;
9830
- // We're outputting either an absolute URL, or a protocol relative one.
9831
- return `${url.scheme}//${url.user}${url.host}${url.port}${url.path}`;
9832
9881
  }
9833
9882
 
9834
9883
  function resolve$2(input, base) {
@@ -10033,7 +10082,9 @@ class TraceMap {
10033
10082
  // mapping (like a "//# sourceMappingURL=") at the end of the child file.
10034
10083
  if (line >= decoded.length)
10035
10084
  return null;
10036
- return traceSegmentInternal(decoded[line], map._decodedMemo, line, column, GREATEST_LOWER_BOUND);
10085
+ const segments = decoded[line];
10086
+ const index = traceSegmentInternal(segments, map._decodedMemo, line, column, GREATEST_LOWER_BOUND);
10087
+ return index === -1 ? null : segments[index];
10037
10088
  };
10038
10089
  originalPositionFor$1 = (map, { line, column, bias }) => {
10039
10090
  line--;
@@ -10046,10 +10097,12 @@ class TraceMap {
10046
10097
  // mapping (like a "//# sourceMappingURL=") at the end of the child file.
10047
10098
  if (line >= decoded.length)
10048
10099
  return OMapping(null, null, null, null);
10049
- const segment = traceSegmentInternal(decoded[line], map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
10050
- if (segment == null)
10100
+ const segments = decoded[line];
10101
+ const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
10102
+ if (index === -1)
10051
10103
  return OMapping(null, null, null, null);
10052
- if (segment.length == 1)
10104
+ const segment = segments[index];
10105
+ if (segment.length === 1)
10053
10106
  return OMapping(null, null, null, null);
10054
10107
  const { names, resolvedSources } = map;
10055
10108
  return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
@@ -10066,8 +10119,8 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
10066
10119
  else if (bias === LEAST_UPPER_BOUND)
10067
10120
  index++;
10068
10121
  if (index === -1 || index === segments.length)
10069
- return null;
10070
- return segments[index];
10122
+ return -1;
10123
+ return index;
10071
10124
  }
10072
10125
 
10073
10126
  /**
@@ -11473,7 +11526,7 @@ const normalizePath$4 = function normalizePath(filename) {
11473
11526
  };
11474
11527
 
11475
11528
  function getMatcherString(id, resolutionBase) {
11476
- if (resolutionBase === false || isAbsolute$2(id) || id.startsWith('*')) {
11529
+ if (resolutionBase === false || isAbsolute$1(id) || id.startsWith('*')) {
11477
11530
  return normalizePath$4(id);
11478
11531
  }
11479
11532
  // resolve('') is valid and will default to process.cwd()
@@ -26803,6 +26856,11 @@ class MagicString {
26803
26856
  }
26804
26857
 
26805
26858
  overwrite(start, end, content, options) {
26859
+ options = options || {};
26860
+ return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
26861
+ }
26862
+
26863
+ update(start, end, content, options) {
26806
26864
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
26807
26865
 
26808
26866
  while (start < 0) start += this.original.length;
@@ -26828,7 +26886,7 @@ class MagicString {
26828
26886
  options = { storeName: true };
26829
26887
  }
26830
26888
  const storeName = options !== undefined ? options.storeName : false;
26831
- const contentOnly = options !== undefined ? options.contentOnly : false;
26889
+ const overwrite = options !== undefined ? options.overwrite : false;
26832
26890
 
26833
26891
  if (storeName) {
26834
26892
  const original = this.original.slice(start, end);
@@ -26852,7 +26910,7 @@ class MagicString {
26852
26910
  chunk.edit('', false);
26853
26911
  }
26854
26912
 
26855
- first.edit(content, storeName, contentOnly);
26913
+ first.edit(content, storeName, !overwrite);
26856
26914
  } else {
26857
26915
  // must be inserting at the end
26858
26916
  const newChunk = new Chunk(start, end, '').edit(content, storeName);
@@ -33438,9 +33496,7 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
33438
33496
  const replacementString = typeof replacement === 'string'
33439
33497
  ? JSON.stringify(replacement).slice(1, -1)
33440
33498
  : `"+${replacement.runtime}+"`;
33441
- s.overwrite(match.index, match.index + full.length, replacementString, {
33442
- contentOnly: true
33443
- });
33499
+ s.update(match.index, match.index + full.length, replacementString);
33444
33500
  }
33445
33501
  // Replace __VITE_PUBLIC_ASSET__5aa0ddc0__ with absolute paths
33446
33502
  const publicAssetUrlMap = publicAssetUrlCache.get(config);
@@ -33452,9 +33508,7 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
33452
33508
  const replacementString = typeof replacement === 'string'
33453
33509
  ? JSON.stringify(replacement).slice(1, -1)
33454
33510
  : `"+${replacement.runtime}+"`;
33455
- s.overwrite(match.index, match.index + full.length, replacementString, {
33456
- contentOnly: true
33457
- });
33511
+ s.update(match.index, match.index + full.length, replacementString);
33458
33512
  }
33459
33513
  return s;
33460
33514
  }
@@ -34530,9 +34584,7 @@ function webWorkerPlugin(config) {
34530
34584
  const replacementString = typeof replacement === 'string'
34531
34585
  ? JSON.stringify(replacement).slice(1, -1)
34532
34586
  : `"+${replacement.runtime}+"`;
34533
- s.overwrite(match.index, match.index + full.length, replacementString, {
34534
- contentOnly: true
34535
- });
34587
+ s.update(match.index, match.index + full.length, replacementString);
34536
34588
  }
34537
34589
  }
34538
34590
  return result();
@@ -34916,12 +34968,24 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
34916
34968
  if (nestedRoot) {
34917
34969
  basedir = nestedResolveFrom(nestedRoot, basedir, preserveSymlinks);
34918
34970
  }
34971
+ // nearest package.json
34972
+ let nearestPkg;
34973
+ // nearest package.json that may have the `exports` field
34919
34974
  let pkg;
34920
- const pkgId = possiblePkgIds.reverse().find((pkgId) => {
34921
- pkg = resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
34922
- return pkg;
34975
+ let pkgId = possiblePkgIds.reverse().find((pkgId) => {
34976
+ nearestPkg = resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
34977
+ return nearestPkg;
34923
34978
  });
34924
- if (!pkg) {
34979
+ const rootPkgId = possiblePkgIds[0];
34980
+ const rootPkg = resolvePackageData(rootPkgId, basedir, preserveSymlinks, packageCache);
34981
+ if (rootPkg?.data?.exports) {
34982
+ pkg = rootPkg;
34983
+ pkgId = rootPkgId;
34984
+ }
34985
+ else {
34986
+ pkg = nearestPkg;
34987
+ }
34988
+ if (!pkg || !nearestPkg) {
34925
34989
  // if import can't be found, check if it's an optional peer dep.
34926
34990
  // if so, we can resolve to a special id that errors only when imported.
34927
34991
  if (basedir !== root && // root has no peer dep
@@ -35008,7 +35072,7 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
35008
35072
  });
35009
35073
  }
35010
35074
  const ext = path$n.extname(resolved);
35011
- const isCJS = ext === '.cjs' || (ext === '.js' && pkg.data.type !== 'module');
35075
+ const isCJS = ext === '.cjs' || (ext === '.js' && nearestPkg.data.type !== 'module');
35012
35076
  if (!options.ssrOptimizeCheck &&
35013
35077
  (!resolved.includes('node_modules') || // linked
35014
35078
  !depsOptimizer || // resolving before listening to the server
@@ -35489,8 +35553,7 @@ function esbuildDepPlugin(qualified, exportsData, external, config, ssr) {
35489
35553
  const flatId = flattenId(id);
35490
35554
  if (flatId in qualified) {
35491
35555
  return {
35492
- path: flatId,
35493
- namespace: 'dep'
35556
+ path: qualified[flatId]
35494
35557
  };
35495
35558
  }
35496
35559
  }
@@ -35519,43 +35582,6 @@ function esbuildDepPlugin(qualified, exportsData, external, config, ssr) {
35519
35582
  return resolveResult(id, resolved);
35520
35583
  }
35521
35584
  });
35522
- // For entry files, we'll read it ourselves and construct a proxy module
35523
- // to retain the entry's raw id instead of file path so that esbuild
35524
- // outputs desired output file structure.
35525
- // It is necessary to do the re-exporting to separate the virtual proxy
35526
- // module from the actual module since the actual module may get
35527
- // referenced via relative imports - if we don't separate the proxy and
35528
- // the actual module, esbuild will create duplicated copies of the same
35529
- // module!
35530
- const root = path$n.resolve(config.root);
35531
- build.onLoad({ filter: /.*/, namespace: 'dep' }, ({ path: id }) => {
35532
- const entryFile = qualified[id];
35533
- let relativePath = normalizePath$3(path$n.relative(root, entryFile));
35534
- if (!relativePath.startsWith('./') &&
35535
- !relativePath.startsWith('../') &&
35536
- relativePath !== '.') {
35537
- relativePath = `./${relativePath}`;
35538
- }
35539
- let contents = '';
35540
- const { hasImports, exports, hasReExports } = exportsData[id];
35541
- if (!hasImports && !exports.length) {
35542
- // cjs
35543
- contents += `export default require("${relativePath}");`;
35544
- }
35545
- else {
35546
- if (exports.includes('default')) {
35547
- contents += `import d from "${relativePath}";export default d;`;
35548
- }
35549
- if (hasReExports || exports.length > 1 || exports[0] !== 'default') {
35550
- contents += `\nexport * from "${relativePath}"`;
35551
- }
35552
- }
35553
- return {
35554
- loader: 'js',
35555
- contents,
35556
- resolveDir: root
35557
- };
35558
- });
35559
35585
  build.onLoad({ filter: /.*/, namespace: 'browser-external' }, ({ path }) => {
35560
35586
  if (config.isProduction) {
35561
35587
  return {
@@ -36445,7 +36471,7 @@ async function toAbsoluteGlob(glob, root, importer, resolveId) {
36445
36471
  if (glob.startsWith('**'))
36446
36472
  return pre + glob;
36447
36473
  const resolved = normalizePath$3((await resolveId(glob, importer)) || glob);
36448
- if (isAbsolute$3(resolved)) {
36474
+ if (isAbsolute$2(resolved)) {
36449
36475
  return pre + globSafeResolvedPath(resolved, glob);
36450
36476
  }
36451
36477
  throw new Error(`Invalid glob: "${glob}" (resolved: "${resolved}"). It must start with '/' or './'`);
@@ -38765,7 +38791,7 @@ function definePlugin(config) {
38765
38791
  const start = match.index;
38766
38792
  const end = start + match[0].length;
38767
38793
  const replacement = '' + replacements[match[1]];
38768
- s.overwrite(start, end, replacement, { contentOnly: true });
38794
+ s.update(start, end, replacement);
38769
38795
  }
38770
38796
  if (!hasReplaced) {
38771
38797
  return null;
@@ -40333,7 +40359,7 @@ function workerImportMetaUrlPlugin(config) {
40333
40359
  builtUrl = injectQuery(builtUrl, WORKER_FILE_ID);
40334
40360
  builtUrl = injectQuery(builtUrl, `type=${workerType}`);
40335
40361
  }
40336
- s.overwrite(urlIndex, urlIndex + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`, { contentOnly: true });
40362
+ s.update(urlIndex, urlIndex + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`);
40337
40363
  }
40338
40364
  if (s) {
40339
40365
  return transformStableResult(s, id, config);
@@ -40385,7 +40411,7 @@ function assetImportMetaUrlPlugin(config) {
40385
40411
  // target so we use the global location here. It can be
40386
40412
  // window.location or self.location in case it is used in a Web Worker.
40387
40413
  // @see https://developer.mozilla.org/en-US/docs/Web/API/Window/self
40388
- s.overwrite(index, index + exp.length, `new URL((import.meta.glob(${pattern}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`, { contentOnly: true });
40414
+ s.update(index, index + exp.length, `new URL((import.meta.glob(${pattern}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`);
40389
40415
  continue;
40390
40416
  }
40391
40417
  }
@@ -40428,7 +40454,7 @@ function assetImportMetaUrlPlugin(config) {
40428
40454
  config.logger.warnOnce(`\n${rawExp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
40429
40455
  builtUrl = url;
40430
40456
  }
40431
- s.overwrite(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`, { contentOnly: true });
40457
+ s.update(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`);
40432
40458
  }
40433
40459
  if (s) {
40434
40460
  return transformStableResult(s, id, config);
@@ -43325,9 +43351,7 @@ function buildImportAnalysisPlugin(config) {
43325
43351
  let rewrittenUrl = JSON.stringify(file);
43326
43352
  if (!isDynamicImport)
43327
43353
  rewrittenUrl = rewrittenUrl.slice(1, -1);
43328
- str().overwrite(start, end, rewrittenUrl, {
43329
- contentOnly: true
43330
- });
43354
+ str().update(start, end, rewrittenUrl);
43331
43355
  }
43332
43356
  }
43333
43357
  }
@@ -43346,9 +43370,7 @@ function buildImportAnalysisPlugin(config) {
43346
43370
  // edge case for package names ending with .css (e.g normalize.css)
43347
43371
  !(bareImportRE.test(specifier) && !specifier.includes('/'))) {
43348
43372
  const url = specifier.replace(/\?|$/, (m) => `?used${m ? '&' : ''}`);
43349
- str().overwrite(start, end, isDynamicImport ? `'${url}'` : url, {
43350
- contentOnly: true
43351
- });
43373
+ str().update(start, end, isDynamicImport ? `'${url}'` : url);
43352
43374
  }
43353
43375
  }
43354
43376
  if (needPreloadHelper &&
@@ -43372,7 +43394,7 @@ function buildImportAnalysisPlugin(config) {
43372
43394
  const s = new MagicString(code);
43373
43395
  let match;
43374
43396
  while ((match = re.exec(code))) {
43375
- s.overwrite(match.index, match.index + isModernFlag.length, isModern, { contentOnly: true });
43397
+ s.update(match.index, match.index + isModernFlag.length, isModern);
43376
43398
  }
43377
43399
  return {
43378
43400
  code: s.toString(),
@@ -43452,9 +43474,7 @@ function buildImportAnalysisPlugin(config) {
43452
43474
  });
43453
43475
  hasRemovedPureCssChunk = true;
43454
43476
  }
43455
- s.overwrite(expStart, expEnd, 'Promise.resolve({})', {
43456
- contentOnly: true
43457
- });
43477
+ s.update(expStart, expEnd, 'Promise.resolve({})');
43458
43478
  }
43459
43479
  }
43460
43480
  };
@@ -43512,7 +43532,7 @@ function buildImportAnalysisPlugin(config) {
43512
43532
  ? toRelativePath(d, file)
43513
43533
  : d));
43514
43534
  }
43515
- s.overwrite(markerStartPos, markerStartPos + preloadMarkerWithQuote.length, `[${renderedDeps.join(',')}]`, { contentOnly: true });
43535
+ s.update(markerStartPos, markerStartPos + preloadMarkerWithQuote.length, `[${renderedDeps.join(',')}]`);
43516
43536
  rewroteMarkerStartPos.add(markerStartPos);
43517
43537
  }
43518
43538
  }
@@ -43522,7 +43542,7 @@ function buildImportAnalysisPlugin(config) {
43522
43542
  let markerStartPos = code.indexOf(preloadMarkerWithQuote);
43523
43543
  while (markerStartPos >= 0) {
43524
43544
  if (!rewroteMarkerStartPos.has(markerStartPos)) {
43525
- s.overwrite(markerStartPos, markerStartPos + preloadMarkerWithQuote.length, 'void 0', { contentOnly: true });
43545
+ s.update(markerStartPos, markerStartPos + preloadMarkerWithQuote.length, 'void 0');
43526
43546
  }
43527
43547
  markerStartPos = code.indexOf(preloadMarkerWithQuote, markerStartPos + preloadMarkerWithQuote.length);
43528
43548
  }
@@ -43707,6 +43727,8 @@ function getScriptInfo(node) {
43707
43727
  let isModule = false;
43708
43728
  let isAsync = false;
43709
43729
  for (const p of node.attrs) {
43730
+ if (p.prefix !== undefined)
43731
+ continue;
43710
43732
  if (p.name === 'src') {
43711
43733
  if (!src) {
43712
43734
  src = p;
@@ -43732,7 +43754,7 @@ function overwriteAttrValue(s, sourceCodeLocation, newValue) {
43732
43754
  }
43733
43755
  const wrapOffset = valueStart[1] === '"' || valueStart[1] === "'" ? 1 : 0;
43734
43756
  const valueOffset = valueStart.index + valueStart[0].length - 1;
43735
- s.overwrite(sourceCodeLocation.startOffset + valueOffset + wrapOffset, sourceCodeLocation.endOffset - wrapOffset, newValue, { contentOnly: true });
43757
+ s.update(sourceCodeLocation.startOffset + valueOffset + wrapOffset, sourceCodeLocation.endOffset - wrapOffset, newValue);
43736
43758
  return s;
43737
43759
  }
43738
43760
  /**
@@ -43873,15 +43895,17 @@ function buildHtmlPlugin(config) {
43873
43895
  const assetAttrs = assetAttrsConfig[node.nodeName];
43874
43896
  if (assetAttrs) {
43875
43897
  for (const p of node.attrs) {
43876
- if (p.value && assetAttrs.includes(p.name)) {
43877
- const attrSourceCodeLocation = node.sourceCodeLocation.attrs[p.name];
43898
+ const attrKey = getAttrKey(p);
43899
+ if (p.value && assetAttrs.includes(attrKey)) {
43900
+ const attrSourceCodeLocation = node.sourceCodeLocation.attrs[attrKey];
43878
43901
  // assetsUrl may be encodeURI
43879
43902
  const url = decodeURI(p.value);
43880
43903
  if (!isExcludedUrl(url)) {
43881
43904
  if (node.nodeName === 'link' &&
43882
43905
  isCSSRequest(url) &&
43883
43906
  // should not be converted if following attributes are present (#6748)
43884
- !node.attrs.some((p) => p.name === 'media' || p.name === 'disabled')) {
43907
+ !node.attrs.some((p) => p.prefix === undefined &&
43908
+ (p.name === 'media' || p.name === 'disabled'))) {
43885
43909
  // CSS references, convert to import
43886
43910
  const importExpression = `\nimport ${JSON.stringify(url)}`;
43887
43911
  styleUrls.push({
@@ -43906,7 +43930,9 @@ function buildHtmlPlugin(config) {
43906
43930
  }
43907
43931
  // <tag style="... url(...) ..."></tag>
43908
43932
  // extract inline styles as virtual css and add class attribute to tag for selecting
43909
- const inlineStyle = node.attrs.find((prop) => prop.name === 'style' && prop.value.includes('url(') // only url(...) in css need to emit file
43933
+ const inlineStyle = node.attrs.find((prop) => prop.prefix === undefined &&
43934
+ prop.name === 'style' &&
43935
+ prop.value.includes('url(') // only url(...) in css need to emit file
43910
43936
  );
43911
43937
  if (inlineStyle) {
43912
43938
  inlineModuleIndex++;
@@ -43933,7 +43959,7 @@ function buildHtmlPlugin(config) {
43933
43959
  js += `\nimport "${id}?html-proxy&inline-css&index=${inlineModuleIndex}.css"`;
43934
43960
  const hash = getHash(cleanUrl(id));
43935
43961
  // will transform in `applyHtmlTransforms`
43936
- s.overwrite(styleNode.sourceCodeLocation.startOffset, styleNode.sourceCodeLocation.endOffset, `__VITE_INLINE_CSS__${hash}_${inlineModuleIndex}__`, { contentOnly: true });
43962
+ s.update(styleNode.sourceCodeLocation.startOffset, styleNode.sourceCodeLocation.endOffset, `__VITE_INLINE_CSS__${hash}_${inlineModuleIndex}__`);
43937
43963
  }
43938
43964
  if (shouldRemove) {
43939
43965
  // remove the script tag from the html. we are going to inject new
@@ -43957,7 +43983,7 @@ function buildHtmlPlugin(config) {
43957
43983
  !namedOutput.includes(content.replace(/^\//, '')) // Allow for absolute references as named output can't be an absolute path
43958
43984
  ) {
43959
43985
  try {
43960
- const url = attr.name === 'srcset'
43986
+ const url = attr.prefix === undefined && attr.name === 'srcset'
43961
43987
  ? await processSrcSet(content, ({ url }) => urlToBuiltUrl(url, id, config, this))
43962
43988
  : await urlToBuiltUrl(content, id, config, this);
43963
43989
  overwriteAttrValue(s, sourceCodeLocation, url);
@@ -43972,12 +43998,10 @@ function buildHtmlPlugin(config) {
43972
43998
  // emit <script>import("./aaa")</script> asset
43973
43999
  for (const { start, end, url } of scriptUrls) {
43974
44000
  if (!isExcludedUrl(url)) {
43975
- s.overwrite(start, end, await urlToBuiltUrl(url, id, config, this), { contentOnly: true });
44001
+ s.update(start, end, await urlToBuiltUrl(url, id, config, this));
43976
44002
  }
43977
44003
  else if (checkPublicFile(url, config)) {
43978
- s.overwrite(start, end, toOutputPublicFilePath(url), {
43979
- contentOnly: true
43980
- });
44004
+ s.update(start, end, toOutputPublicFilePath(url));
43981
44005
  }
43982
44006
  }
43983
44007
  // ignore <link rel="stylesheet"> if its url can't be resolved
@@ -44139,7 +44163,7 @@ function buildHtmlPlugin(config) {
44139
44163
  s || (s = new MagicString(result));
44140
44164
  const { 0: full, 1: scopedName } = match;
44141
44165
  const cssTransformedCode = htmlProxyResult.get(scopedName);
44142
- s.overwrite(match.index, match.index + full.length, cssTransformedCode, { contentOnly: true });
44166
+ s.update(match.index, match.index + full.length, cssTransformedCode);
44143
44167
  }
44144
44168
  if (s) {
44145
44169
  result = s.toString();
@@ -44379,6 +44403,9 @@ function serializeAttrs(attrs) {
44379
44403
  function incrementIndent(indent = '') {
44380
44404
  return `${indent}${indent[0] === '\t' ? '\t' : ' '}`;
44381
44405
  }
44406
+ function getAttrKey(attr) {
44407
+ return attr.prefix === undefined ? attr.name : `${attr.prefix}:${attr.name}`;
44408
+ }
44382
44409
 
44383
44410
  const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)`;
44384
44411
  const cssLangRE = new RegExp(cssLangs);
@@ -44919,7 +44946,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
44919
44946
  logger: config.logger
44920
44947
  }));
44921
44948
  if (isModule) {
44922
- postcssPlugins.unshift((await import('./dep-553f6a62.js').then(function (n) { return n.i; })).default({
44949
+ postcssPlugins.unshift((await import('./dep-0726141c.js').then(function (n) { return n.i; })).default({
44923
44950
  ...modulesOptions,
44924
44951
  getJSON(cssFileName, _modules, outputFileName) {
44925
44952
  modules = _modules;
@@ -46258,10 +46285,11 @@ function resolveLibFilename(libOptions, format, entryName, root, extension) {
46258
46285
  }
46259
46286
  function resolveBuildOutputs(outputs, libOptions, logger) {
46260
46287
  if (libOptions) {
46261
- const formats = libOptions.formats || ['es', 'umd'];
46288
+ const hasMultipleEntries = typeof libOptions.entry !== 'string' &&
46289
+ Object.values(libOptions.entry).length > 1;
46290
+ const formats = libOptions.formats || (hasMultipleEntries ? ['es', 'cjs'] : ['es', 'umd']);
46262
46291
  if (formats.includes('umd') || formats.includes('iife')) {
46263
- if (typeof libOptions.entry !== 'string' &&
46264
- Object.values(libOptions.entry).length > 1) {
46292
+ if (hasMultipleEntries) {
46265
46293
  throw new Error(`Multiple entry points are not supported when output formats include "umd" or "iife".`);
46266
46294
  }
46267
46295
  if (!libOptions.name) {
@@ -46522,6 +46550,7 @@ var build$1 = {
46522
46550
  resolveBuildPlugins: resolveBuildPlugins,
46523
46551
  build: build,
46524
46552
  resolveLibFilename: resolveLibFilename,
46553
+ resolveBuildOutputs: resolveBuildOutputs,
46525
46554
  onRollupWarning: onRollupWarning,
46526
46555
  toOutputFilePathInJS: toOutputFilePathInJS,
46527
46556
  createToImportMetaURLBasedRelativeRuntime: createToImportMetaURLBasedRelativeRuntime,
@@ -53346,7 +53375,7 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
53346
53375
  }
53347
53376
  else {
53348
53377
  // anonymous default exports
53349
- s.overwrite(node.start, node.start + 14 /* 'export default'.length */, `${ssrModuleExportsKey}.default =`, { contentOnly: true });
53378
+ s.update(node.start, node.start + 14 /* 'export default'.length */, `${ssrModuleExportsKey}.default =`);
53350
53379
  }
53351
53380
  }
53352
53381
  // export * from './foo'
@@ -53389,16 +53418,14 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
53389
53418
  }
53390
53419
  }
53391
53420
  else {
53392
- s.overwrite(id.start, id.end, binding, { contentOnly: true });
53421
+ s.update(id.start, id.end, binding);
53393
53422
  }
53394
53423
  },
53395
53424
  onImportMeta(node) {
53396
- s.overwrite(node.start, node.end, ssrImportMetaKey, { contentOnly: true });
53425
+ s.update(node.start, node.end, ssrImportMetaKey);
53397
53426
  },
53398
53427
  onDynamicImport(node) {
53399
- s.overwrite(node.start, node.start + 6, ssrDynamicImportKey, {
53400
- contentOnly: true
53401
- });
53428
+ s.update(node.start, node.start + 6, ssrDynamicImportKey);
53402
53429
  if (node.type === 'ImportExpression' && node.source.type === 'Literal') {
53403
53430
  dynamicDeps.add(node.source.value);
53404
53431
  }
@@ -53437,6 +53464,7 @@ const isNodeInPattern = (node) => isNodeInPatternWeakSet.has(node);
53437
53464
  */
53438
53465
  function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
53439
53466
  const parentStack = [];
53467
+ const varKindStack = [];
53440
53468
  const scopeMap = new WeakMap();
53441
53469
  const identifiers = [];
53442
53470
  const setScope = (node, name) => {
@@ -53495,6 +53523,10 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
53495
53523
  !(parent.type === 'IfStatement' && node === parent.alternate)) {
53496
53524
  parentStack.unshift(parent);
53497
53525
  }
53526
+ // track variable declaration kind stack used by VariableDeclarator
53527
+ if (node.type === 'VariableDeclaration') {
53528
+ varKindStack.unshift(node.kind);
53529
+ }
53498
53530
  if (node.type === 'MetaProperty' && node.meta.name === 'import') {
53499
53531
  onImportMeta(node);
53500
53532
  }
@@ -53553,7 +53585,7 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
53553
53585
  setIsNodeInPattern(node);
53554
53586
  }
53555
53587
  else if (node.type === 'VariableDeclarator') {
53556
- const parentFunction = findParentScope(parentStack);
53588
+ const parentFunction = findParentScope(parentStack, varKindStack[0] === 'var');
53557
53589
  if (parentFunction) {
53558
53590
  handlePattern(node.id, parentFunction);
53559
53591
  }
@@ -53565,6 +53597,9 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
53565
53597
  !(parent.type === 'IfStatement' && node === parent.alternate)) {
53566
53598
  parentStack.shift();
53567
53599
  }
53600
+ if (node.type === 'VariableDeclaration') {
53601
+ varKindStack.shift();
53602
+ }
53568
53603
  }
53569
53604
  });
53570
53605
  // emit the identifier events in BFS so the hoisted declarations
@@ -53631,8 +53666,9 @@ function isFunction(node) {
53631
53666
  return functionNodeTypeRE.test(node.type);
53632
53667
  }
53633
53668
  const scopeNodeTypeRE = /(?:Function|Class)(?:Expression|Declaration)$|Method$|^IfStatement$/;
53634
- function findParentScope(parentStack) {
53635
- return parentStack.find((i) => scopeNodeTypeRE.test(i.type));
53669
+ function findParentScope(parentStack, isVar = false) {
53670
+ const regex = isVar ? functionNodeTypeRE : scopeNodeTypeRE;
53671
+ return parentStack.find((i) => regex.test(i.type));
53636
53672
  }
53637
53673
  function isInDestructuringAssignment(parent, parentStack) {
53638
53674
  if (parent &&
@@ -53763,7 +53799,7 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
53763
53799
  preserveSymlinks,
53764
53800
  isBuild: true,
53765
53801
  isProduction,
53766
- isRequire: true,
53802
+ isRequire: false,
53767
53803
  root
53768
53804
  };
53769
53805
  // Since dynamic imports can happen in parallel, we need to
@@ -53834,6 +53870,11 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
53834
53870
  }
53835
53871
  return Object.freeze(ssrModule);
53836
53872
  }
53873
+ // `nodeImport` may run in parallel on multiple `ssrLoadModule` calls.
53874
+ // We keep track of the current importing count so that the first import
53875
+ // would `hookNodeResolve`, and the last import would `unhookNodeResolve`.
53876
+ let importingCount = 0;
53877
+ let unhookNodeResolve;
53837
53878
  // In node@12+ we can use dynamic import to load CJS and ESM
53838
53879
  async function nodeImport(id, importer, resolveOptions) {
53839
53880
  // Node's module resolution is hi-jacked so Vite can ensure the
@@ -53847,30 +53888,32 @@ async function nodeImport(id, importer, resolveOptions) {
53847
53888
  }
53848
53889
  return resolved.id;
53849
53890
  };
53850
- // When an ESM module imports an ESM dependency, this hook is *not* used.
53851
- const unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => {
53852
- // Use the Vite resolver only for bare imports while skipping
53853
- // any absolute paths, built-in modules and binary modules.
53854
- if (!bareImportRE.test(id) ||
53855
- path$n.isAbsolute(id) ||
53856
- isBuiltin(id) ||
53857
- id.endsWith('.node')) {
53858
- return nodeResolve(id, parent, isMain, options);
53859
- }
53860
- if (parent) {
53861
- let resolved = viteResolve(id, parent.id);
53862
- if (resolved) {
53863
- // hookNodeResolve must use platform-specific path.normalize
53864
- // to be compatible with dynamicImport (#6080)
53865
- resolved = path$n.normalize(resolved);
53891
+ if (importingCount === 0) {
53892
+ // When an ESM module imports an ESM dependency, this hook is *not* used.
53893
+ unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => {
53894
+ // Use the Vite resolver only for bare imports while skipping
53895
+ // any absolute paths, built-in modules and binary modules.
53896
+ if (!bareImportRE.test(id) ||
53897
+ path$n.isAbsolute(id) ||
53898
+ isBuiltin(id) ||
53899
+ id.endsWith('.node')) {
53900
+ return nodeResolve(id, parent, isMain, options);
53901
+ }
53902
+ if (parent) {
53903
+ let resolved = viteResolve(id, parent.id);
53904
+ if (resolved) {
53905
+ // hookNodeResolve must use platform-specific path.normalize
53906
+ // to be compatible with dynamicImport (#6080)
53907
+ resolved = path$n.normalize(resolved);
53908
+ }
53909
+ return resolved;
53866
53910
  }
53867
- return resolved;
53868
- }
53869
- // Importing a CJS module from an ESM module. In this case, the import
53870
- // specifier is already an absolute path, so this is a no-op.
53871
- // Options like `resolve.dedupe` and `mode` are not respected.
53872
- return id;
53873
- });
53911
+ // Importing a CJS module from an ESM module. In this case, the import
53912
+ // specifier is already an absolute path, so this is a no-op.
53913
+ // Options like `resolve.dedupe` and `mode` are not respected.
53914
+ return id;
53915
+ });
53916
+ }
53874
53917
  let url;
53875
53918
  if (id.startsWith('node:') || isBuiltin(id)) {
53876
53919
  url = id;
@@ -53888,11 +53931,15 @@ async function nodeImport(id, importer, resolveOptions) {
53888
53931
  }
53889
53932
  }
53890
53933
  try {
53934
+ importingCount++;
53891
53935
  const mod = await dynamicImport(url);
53892
53936
  return proxyESM(mod);
53893
53937
  }
53894
53938
  finally {
53895
- unhookNodeResolve();
53939
+ importingCount--;
53940
+ if (importingCount === 0) {
53941
+ unhookNodeResolve?.();
53942
+ }
53896
53943
  }
53897
53944
  }
53898
53945
  // rollup-style default import interop for cjs
@@ -60963,7 +61010,7 @@ const processNodeUrl = (attr, sourceCodeLocation, s, config, htmlPath, originalU
60963
61010
  // path will add `/a/` prefix, it will caused 404.
60964
61011
  // rewrite before `./index.js` -> `localhost:5173/a/index.js`.
60965
61012
  // rewrite after `../index.js` -> `localhost:5173/index.js`.
60966
- const processedUrl = attr.name === 'srcset'
61013
+ const processedUrl = attr.name === 'srcset' && attr.prefix === undefined
60967
61014
  ? processSrcSetSync(url, ({ url }) => replacer(url))
60968
61015
  : replacer(url);
60969
61016
  overwriteAttrValue(s, sourceCodeLocation, processedUrl);
@@ -61014,7 +61061,7 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
61014
61061
  if (module) {
61015
61062
  server?.moduleGraph.invalidateModule(module);
61016
61063
  }
61017
- s.overwrite(node.sourceCodeLocation.startOffset, node.sourceCodeLocation.endOffset, `<script type="module" src="${modulePath}"></script>`, { contentOnly: true });
61064
+ s.update(node.sourceCodeLocation.startOffset, node.sourceCodeLocation.endOffset, `<script type="module" src="${modulePath}"></script>`);
61018
61065
  };
61019
61066
  await traverseHtml(html, htmlPath, (node) => {
61020
61067
  if (!nodeIsElement(node)) {
@@ -61042,8 +61089,9 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
61042
61089
  const assetAttrs = assetAttrsConfig[node.nodeName];
61043
61090
  if (assetAttrs) {
61044
61091
  for (const p of node.attrs) {
61045
- if (p.value && assetAttrs.includes(p.name)) {
61046
- processNodeUrl(p, node.sourceCodeLocation.attrs[p.name], s, config, htmlPath, originalUrl);
61092
+ const attrKey = getAttrKey(p);
61093
+ if (p.value && assetAttrs.includes(attrKey)) {
61094
+ processNodeUrl(p, node.sourceCodeLocation.attrs[attrKey], s, config, htmlPath, originalUrl);
61047
61095
  }
61048
61096
  }
61049
61097
  }
@@ -62519,6 +62567,11 @@ async function createServer(inlineConfig = {}) {
62519
62567
  ssrRewriteStacktrace(stack) {
62520
62568
  return ssrRewriteStacktrace(stack, moduleGraph);
62521
62569
  },
62570
+ async reloadModule(module) {
62571
+ if (serverConfig.hmr !== false && module.file) {
62572
+ updateModules(module.file, [module], Date.now(), server);
62573
+ }
62574
+ },
62522
62575
  async listen(port, isRestart) {
62523
62576
  await startServer(server, port, isRestart);
62524
62577
  if (httpServer) {
@@ -63850,7 +63903,7 @@ async function bundleConfigFile(fileName, isESM) {
63850
63903
  isRequire: !isESM,
63851
63904
  preferRelative: false,
63852
63905
  tryIndex: true,
63853
- mainFields: DEFAULT_MAIN_FIELDS,
63906
+ mainFields: [],
63854
63907
  browserField: false,
63855
63908
  conditions: [],
63856
63909
  dedupe: [],
@@ -63859,7 +63912,11 @@ async function bundleConfigFile(fileName, isESM) {
63859
63912
  };
63860
63913
  build.onResolve({ filter: /.*/ }, ({ path: id, importer, kind }) => {
63861
63914
  // externalize bare imports
63862
- if (id[0] !== '.' && !isAbsolute(id)) {
63915
+ if (id[0] !== '.' && !path$n.isAbsolute(id) && !isBuiltin(id)) {
63916
+ // partial deno support as `npm:` does not work in `tryNodeResolve`
63917
+ if (id.startsWith('npm:')) {
63918
+ return { external: true };
63919
+ }
63863
63920
  let idFsPath = tryNodeResolve(id, importer, options, false)?.id;
63864
63921
  if (idFsPath && (isESM || kind === 'dynamic-import')) {
63865
63922
  idFsPath = pathToFileURL(idFsPath).href;
@@ -63962,8 +64019,5 @@ function isDepsOptimizerEnabled(config, ssr) {
63962
64019
  (command === 'build' && disabled === 'build') ||
63963
64020
  (command === 'serve' && disabled === 'dev'));
63964
64021
  }
63965
- function isAbsolute(id) {
63966
- return path$n.isAbsolute(id) || path$n.posix.isAbsolute(id);
63967
- }
63968
64022
 
63969
64023
  export { index$1 as A, build$1 as B, index as C, preview$1 as D, resolvePackageData as a, build as b, createServer as c, defineConfig as d, resolveConfig as e, formatPostcssSourceMap as f, resolveBaseUrl as g, getDepOptimizationConfig as h, isDepsOptimizerEnabled as i, mergeAlias as j, createFilter as k, loadConfigFromFile as l, mergeConfig as m, normalizePath$3 as n, optimizeDeps as o, preview as p, send as q, resolvePackageEntry as r, sortUserPlugins as s, transformWithEsbuild as t, createLogger as u, searchForWorkspaceRoot as v, loadEnv as w, resolveEnvPrefix as x, picocolors as y, commonjsGlobal as z };
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { EventEmitter } from 'events';
3
- import { y as picocolors, u as createLogger, e as resolveConfig } from './chunks/dep-92763d7a.js';
3
+ import { y as picocolors, u as createLogger, e as resolveConfig } from './chunks/dep-0856a44a.js';
4
4
  import { VERSION } from './constants.js';
5
5
  import 'node:fs';
6
6
  import 'node:path';
@@ -695,7 +695,7 @@ cli
695
695
  .action(async (root, options) => {
696
696
  // output structure is preserved even after bundling so require()
697
697
  // is ok here
698
- const { createServer } = await import('./chunks/dep-92763d7a.js').then(function (n) { return n.C; });
698
+ const { createServer } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.C; });
699
699
  try {
700
700
  const server = await createServer({
701
701
  root,
@@ -742,7 +742,7 @@ cli
742
742
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
743
743
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
744
744
  .action(async (root, options) => {
745
- const { build } = await import('./chunks/dep-92763d7a.js').then(function (n) { return n.B; });
745
+ const { build } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.B; });
746
746
  const buildOptions = cleanOptions(options);
747
747
  try {
748
748
  await build({
@@ -766,7 +766,7 @@ cli
766
766
  .command('optimize [root]', 'pre-bundle dependencies')
767
767
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
768
768
  .action(async (root, options) => {
769
- const { optimizeDeps } = await import('./chunks/dep-92763d7a.js').then(function (n) { return n.A; });
769
+ const { optimizeDeps } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.A; });
770
770
  try {
771
771
  const config = await resolveConfig({
772
772
  root,
@@ -789,7 +789,7 @@ cli
789
789
  .option('--https', `[boolean] use TLS + HTTP/2`)
790
790
  .option('--open [path]', `[boolean | string] open browser on startup`)
791
791
  .action(async (root, options) => {
792
- const { preview } = await import('./chunks/dep-92763d7a.js').then(function (n) { return n.D; });
792
+ const { preview } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.D; });
793
793
  try {
794
794
  const server = await preview({
795
795
  root,
@@ -1,7 +1,7 @@
1
1
  import path, { resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
 
4
- var version = "3.2.0-beta.0";
4
+ var version = "3.2.0-beta.2";
5
5
 
6
6
  const VERSION = version;
7
7
  const DEFAULT_MAIN_FIELDS = [
@@ -1252,6 +1252,8 @@ export declare interface ManifestChunk {
1252
1252
  dynamicImports?: string[];
1253
1253
  }
1254
1254
 
1255
+ export declare type MapToFunction<T> = T extends Function ? T : never
1256
+
1255
1257
  export declare type Matcher = AnymatchPattern | AnymatchPattern[]
1256
1258
 
1257
1259
  export declare function mergeAlias(a?: AliasOptions, b?: AliasOptions): AliasOptions | undefined;
@@ -1685,7 +1687,7 @@ export declare function resolvePackageData(id: string, basedir: string, preserve
1685
1687
 
1686
1688
  export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, targetWeb: boolean, options: InternalResolveOptions): string | undefined;
1687
1689
 
1688
- export declare type ResolverFunction = PluginHooks['resolveId']
1690
+ export declare type ResolverFunction = MapToFunction<PluginHooks['resolveId']>
1689
1691
 
1690
1692
  export declare interface ResolverObject {
1691
1693
  buildStart?: PluginHooks['buildStart']
@@ -2519,6 +2521,11 @@ export declare interface ViteDevServer {
2519
2521
  * Mutates the given SSR error by rewriting the stacktrace
2520
2522
  */
2521
2523
  ssrFixStacktrace(e: Error): void;
2524
+ /**
2525
+ * Triggers HMR for a module in the module graph. You can use the `server.moduleGraph`
2526
+ * API to retrieve the module to be reloaded. If `hmr` is false, this is a no-op.
2527
+ */
2528
+ reloadModule(module: ModuleNode): Promise<void>;
2522
2529
  /**
2523
2530
  * Start the server.
2524
2531
  */
@@ -1,4 +1,4 @@
1
- export { b as build, k as createFilter, u as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, h as getDepOptimizationConfig, i as isDepsOptimizerEnabled, l as loadConfigFromFile, w as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, x as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, v as searchForWorkspaceRoot, q as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-92763d7a.js';
1
+ export { b as build, k as createFilter, u as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, h as getDepOptimizationConfig, i as isDepsOptimizerEnabled, l as loadConfigFromFile, w as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, x as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, v as searchForWorkspaceRoot, q as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-0856a44a.js';
2
2
  export { VERSION as version } from './constants.js';
3
3
  export { version as esbuildVersion } from 'esbuild';
4
4
  export { VERSION as rollupVersion } from 'rollup';
@@ -31,7 +31,7 @@ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
31
31
  var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
32
32
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
33
33
 
34
- var version = "3.2.0-beta.0";
34
+ var version = "3.2.0-beta.2";
35
35
 
36
36
  const VERSION = version;
37
37
  const VITE_PACKAGE_DIR = path$3.resolve(
@@ -155,6 +155,18 @@ for (let i = 0; i < chars.length; i++) {
155
155
  charToInt[c] = i;
156
156
  }
157
157
 
158
+ // Matches the scheme of a URL, eg "http://"
159
+ var UrlType;
160
+ (function (UrlType) {
161
+ UrlType[UrlType["Empty"] = 1] = "Empty";
162
+ UrlType[UrlType["Hash"] = 2] = "Hash";
163
+ UrlType[UrlType["Query"] = 3] = "Query";
164
+ UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
165
+ UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
166
+ UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
167
+ UrlType[UrlType["Absolute"] = 7] = "Absolute";
168
+ })(UrlType || (UrlType = {}));
169
+
158
170
  function getDefaultExportFromCjs (x) {
159
171
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
160
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "3.2.0-beta.0",
3
+ "version": "3.2.0-beta.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -71,8 +71,8 @@
71
71
  "@ampproject/remapping": "^2.2.0",
72
72
  "@babel/parser": "^7.19.3",
73
73
  "@babel/types": "^7.19.3",
74
- "@jridgewell/trace-mapping": "^0.3.15",
75
- "@rollup/plugin-alias": "^3.1.9",
74
+ "@jridgewell/trace-mapping": "^0.3.16",
75
+ "@rollup/plugin-alias": "^4.0.0",
76
76
  "@rollup/plugin-commonjs": "^22.0.2",
77
77
  "@rollup/plugin-dynamic-import-vars": "^1.4.4",
78
78
  "@rollup/plugin-json": "^4.1.0",
@@ -97,7 +97,7 @@
97
97
  "http-proxy": "^1.18.1",
98
98
  "json5": "^2.2.1",
99
99
  "launch-editor-middleware": "^2.6.0",
100
- "magic-string": "^0.26.5",
100
+ "magic-string": "^0.26.7",
101
101
  "micromatch": "^4.0.5",
102
102
  "mlly": "^0.5.16",
103
103
  "mrmime": "^1.0.1",
@@ -0,0 +1,3 @@
1
+ {
2
+ "//": "this file is here to make typescript happy when moduleResolution=node16+"
3
+ }