vite 2.7.0-beta.4 → 2.7.0-beta.8

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.

@@ -2961,7 +2961,7 @@ if (typeof process === 'undefined' || process.type === 'renderer' || process.bro
2961
2961
  src$2.exports = node$1.exports;
2962
2962
  }
2963
2963
 
2964
- var debug$f = src$2.exports;
2964
+ var debug$g = src$2.exports;
2965
2965
 
2966
2966
  const DEFAULT_MAIN_FIELDS = [
2967
2967
  'module',
@@ -2988,9 +2988,15 @@ const FS_PREFIX = `/@fs/`;
2988
2988
  */
2989
2989
  const VALID_ID_PREFIX = `/@id/`;
2990
2990
  /**
2991
- * Some Rollup plugins use ids that starts with the null byte \0 to avoid
2992
- * collisions, but it is not permitted in import URLs so we have to replace
2993
- * them.
2991
+ * Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
2992
+ * module ID with `\0`, a convention from the rollup ecosystem.
2993
+ * This prevents other plugins from trying to process the id (like node resolution),
2994
+ * and core features like sourcemaps can use this info to differentiate between
2995
+ * virtual modules and regular files.
2996
+ * `\0` is not a permitted char in import URLs so we have to replace them during
2997
+ * import analysis. The id will be decoded back before entering the plugins pipeline.
2998
+ * These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
2999
+ * modules in the browser end up encoded as `/@id/__x00__{id}`
2994
3000
  */
2995
3001
  const NULL_BYTE_PLACEHOLDER = `__x00__`;
2996
3002
  const CLIENT_PUBLIC_PATH = `/@vite/client`;
@@ -3924,7 +3930,7 @@ function nestedResolveFrom(id, basedir, preserveSymlinks = false) {
3924
3930
  const filter$1 = process.env.VITE_DEBUG_FILTER;
3925
3931
  const DEBUG$1 = process.env.DEBUG;
3926
3932
  function createDebugger(namespace, options = {}) {
3927
- const log = debug$f(namespace);
3933
+ const log = debug$g(namespace);
3928
3934
  const { onlyWhenFocused } = options;
3929
3935
  const focus = typeof onlyWhenFocused === 'string' ? onlyWhenFocused : namespace;
3930
3936
  return (msg, ...args) => {
@@ -3958,7 +3964,8 @@ const externalRE = /^(https?:)?\/\//;
3958
3964
  const isExternalUrl = (url) => externalRE.test(url);
3959
3965
  const dataUrlRE = /^\s*data:/i;
3960
3966
  const isDataUrl = (url) => dataUrlRE.test(url);
3961
- const virtualModuleRE = /virtual-module:.*/;
3967
+ const virtualModuleRE = /^virtual-module:.*/;
3968
+ const virtualModulePrefix = 'virtual-module:';
3962
3969
  const knownJsSrcRE = /\.((j|t)sx?|mjs|vue|marko|svelte|astro)($|\?)/;
3963
3970
  const isJSRequest = (url) => {
3964
3971
  url = cleanUrl(url);
@@ -3974,7 +3981,7 @@ const knownTsRE = /\.(ts|mts|cts|tsx)$/;
3974
3981
  const knownTsOutputRE = /\.(js|mjs|cjs|jsx)$/;
3975
3982
  const isTsRequest = (url) => knownTsRE.test(cleanUrl(url));
3976
3983
  const isPossibleTsOutput = (url) => knownTsOutputRE.test(cleanUrl(url));
3977
- const getTsSrcPath = (filename) => filename.replace(/\.([cm])?(js)(x?)$/, '.$1ts$3');
3984
+ const getTsSrcPath = (filename) => filename.replace(/\.([cm])?(js)(x?)(\?|$)/, '.$1ts$3');
3978
3985
  const importQueryRE = /(\?|&)import=?(?:&|$)/;
3979
3986
  const internalPrefixes = [
3980
3987
  FS_PREFIX,
@@ -20385,7 +20392,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20385
20392
  replacer: urlReplacer
20386
20393
  }));
20387
20394
  if (isModule) {
20388
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-9583e954.js'); }).then(function (n) { return n.index; })).default({
20395
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-b192ffe4.js'); }).then(function (n) { return n.index; })).default({
20389
20396
  ...modulesOptions,
20390
20397
  getJSON(cssFileName, _modules, outputFileName) {
20391
20398
  modules = _modules;
@@ -21090,7 +21097,7 @@ function buildImportAnalysisPlugin(config) {
21090
21097
  }
21091
21098
  // Differentiate CSS imports that use the default export from those that
21092
21099
  // do not by injecting a ?used query - this allows us to avoid including
21093
- // the CSS string when unnecessary (esbuild has trouble treeshaking
21100
+ // the CSS string when unnecessary (esbuild has trouble tree-shaking
21094
21101
  // them)
21095
21102
  if (specifier &&
21096
21103
  isCSSRequest(specifier) &&
@@ -21350,7 +21357,7 @@ const assetAttrsConfig = {
21350
21357
  const isAsyncScriptMap = new WeakMap();
21351
21358
  async function traverseHtml(html, filePath, visitor) {
21352
21359
  // lazy load compiler
21353
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-ef63fa34.js'); }).then(function (n) { return n.compilerDom_cjs; });
21360
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-8fdf8f48.js'); }).then(function (n) { return n.compilerDom_cjs; });
21354
21361
  // @vue/compiler-core doesn't like lowercase doctypes
21355
21362
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21356
21363
  try {
@@ -22299,7 +22306,7 @@ var TSConfckParseError = class extends Error {
22299
22306
  }
22300
22307
  };
22301
22308
 
22302
- const debug$e = createDebugger('vite:esbuild');
22309
+ const debug$f = createDebugger('vite:esbuild');
22303
22310
  let server;
22304
22311
  async function transformWithEsbuild(code, filename, options, inMap) {
22305
22312
  var _a, _b, _c;
@@ -22389,7 +22396,7 @@ async function transformWithEsbuild(code, filename, options, inMap) {
22389
22396
  };
22390
22397
  }
22391
22398
  catch (e) {
22392
- debug$e(`esbuild error with options used: `, resolvedOptions);
22399
+ debug$f(`esbuild error with options used: `, resolvedOptions);
22393
22400
  // patch error information
22394
22401
  if (e.errors) {
22395
22402
  e.frame = '';
@@ -22434,7 +22441,15 @@ function esbuildPlugin(options = {}) {
22434
22441
  const rollupToEsbuildFormatMap = {
22435
22442
  es: 'esm',
22436
22443
  cjs: 'cjs',
22437
- iife: 'iife'
22444
+ // passing `var Lib = (() => {})()` to esbuild with format = "iife"
22445
+ // will turn it to `(() => { var Lib = (() => {})() })()`,
22446
+ // so we remove the format config to tell esbuild not doing this
22447
+ //
22448
+ // although esbuild doesn't change format, there is still possibility
22449
+ // that `{ treeShaking: true }` removes a top-level no-side-effect variable
22450
+ // like: `var Lib = 1`, which becomes `` after esbuild transforming,
22451
+ // but thankfully rollup does not do this optimization now
22452
+ iife: undefined
22438
22453
  };
22439
22454
  const buildEsbuildPlugin = (config) => {
22440
22455
  return {
@@ -29940,6 +29955,126 @@ function resolve(pkg, entry='.', options={}) {
29940
29955
  }
29941
29956
  }
29942
29957
 
29958
+ const isDebug$6 = process.env.DEBUG;
29959
+ const debug$e = createDebugger('vite:resolve-details', {
29960
+ onlyWhenFocused: true
29961
+ });
29962
+ function invalidatePackageData(packageCache, pkgPath) {
29963
+ packageCache.delete(pkgPath);
29964
+ const pkgDir = path__default.dirname(pkgPath);
29965
+ packageCache.forEach((pkg, cacheKey) => {
29966
+ if (pkg.dir === pkgDir) {
29967
+ packageCache.delete(cacheKey);
29968
+ }
29969
+ });
29970
+ }
29971
+ function resolvePackageData(id, basedir, preserveSymlinks = false, packageCache) {
29972
+ let pkg;
29973
+ let cacheKey;
29974
+ if (packageCache) {
29975
+ cacheKey = `${id}&${basedir}&${preserveSymlinks}`;
29976
+ if ((pkg = packageCache.get(cacheKey))) {
29977
+ return pkg;
29978
+ }
29979
+ }
29980
+ let pkgPath;
29981
+ try {
29982
+ pkgPath = resolveFrom$3(`${id}/package.json`, basedir, preserveSymlinks);
29983
+ pkg = loadPackageData(pkgPath, true, packageCache);
29984
+ if (packageCache) {
29985
+ packageCache.set(cacheKey, pkg);
29986
+ }
29987
+ return pkg;
29988
+ }
29989
+ catch (e) {
29990
+ if (e instanceof SyntaxError) {
29991
+ isDebug$6 && debug$e(`Parsing failed: ${pkgPath}`);
29992
+ }
29993
+ // Ignore error for missing package.json
29994
+ else if (e.code !== 'MODULE_NOT_FOUND') {
29995
+ throw e;
29996
+ }
29997
+ }
29998
+ return null;
29999
+ }
30000
+ function loadPackageData(pkgPath, preserveSymlinks, packageCache) {
30001
+ if (!preserveSymlinks) {
30002
+ pkgPath = fs__default.realpathSync.native(pkgPath);
30003
+ }
30004
+ let cached;
30005
+ if ((cached = packageCache === null || packageCache === void 0 ? void 0 : packageCache.get(pkgPath))) {
30006
+ return cached;
30007
+ }
30008
+ const data = JSON.parse(fs__default.readFileSync(pkgPath, 'utf-8'));
30009
+ const pkgDir = path__default.dirname(pkgPath);
30010
+ const { sideEffects } = data;
30011
+ let hasSideEffects;
30012
+ if (typeof sideEffects === 'boolean') {
30013
+ hasSideEffects = () => sideEffects;
30014
+ }
30015
+ else if (Array.isArray(sideEffects)) {
30016
+ hasSideEffects = createFilter$1(sideEffects, null, { resolve: pkgDir });
30017
+ }
30018
+ else {
30019
+ hasSideEffects = () => true;
30020
+ }
30021
+ const pkg = {
30022
+ dir: pkgDir,
30023
+ data,
30024
+ hasSideEffects,
30025
+ webResolvedImports: {},
30026
+ nodeResolvedImports: {},
30027
+ setResolvedCache(key, entry, targetWeb) {
30028
+ if (targetWeb) {
30029
+ pkg.webResolvedImports[key] = entry;
30030
+ }
30031
+ else {
30032
+ pkg.nodeResolvedImports[key] = entry;
30033
+ }
30034
+ },
30035
+ getResolvedCache(key, targetWeb) {
30036
+ if (targetWeb) {
30037
+ return pkg.webResolvedImports[key];
30038
+ }
30039
+ else {
30040
+ return pkg.nodeResolvedImports[key];
30041
+ }
30042
+ }
30043
+ };
30044
+ packageCache === null || packageCache === void 0 ? void 0 : packageCache.set(pkgPath, pkg);
30045
+ return pkg;
30046
+ }
30047
+ function watchPackageDataPlugin(config) {
30048
+ const watchQueue = new Set();
30049
+ let watchFile = (id) => {
30050
+ watchQueue.add(id);
30051
+ };
30052
+ const { packageCache } = config;
30053
+ const setPackageData = packageCache.set.bind(packageCache);
30054
+ packageCache.set = (id, pkg) => {
30055
+ if (id.endsWith('.json')) {
30056
+ watchFile(id);
30057
+ }
30058
+ return setPackageData(id, pkg);
30059
+ };
30060
+ return {
30061
+ name: 'vite:watch-package-data',
30062
+ buildStart() {
30063
+ watchFile = this.addWatchFile;
30064
+ watchQueue.forEach(watchFile);
30065
+ watchQueue.clear();
30066
+ },
30067
+ buildEnd() {
30068
+ watchFile = (id) => watchQueue.add(id);
30069
+ },
30070
+ watchChange(id) {
30071
+ if (id.endsWith('/package.json')) {
30072
+ invalidatePackageData(packageCache, id);
30073
+ }
30074
+ }
30075
+ };
30076
+ }
30077
+
29943
30078
  // special id for paths marked with browser: false
29944
30079
  // https://github.com/defunctzombie/package-browser-field-spec#ignore-a-module
29945
30080
  const browserExternalId = '__vite-browser-external';
@@ -29974,12 +30109,11 @@ function resolvePlugin(baseOptions) {
29974
30109
  isRequire,
29975
30110
  isFromTsImporter: isTsRequest(importer !== null && importer !== void 0 ? importer : '')
29976
30111
  };
29977
- const preserveSymlinks = !!(server === null || server === void 0 ? void 0 : server.config.resolve.preserveSymlinks);
29978
30112
  let res;
29979
30113
  // explicit fs paths that starts with /@fs/*
29980
30114
  if (asSrc && id.startsWith(FS_PREFIX)) {
29981
30115
  const fsPath = fsPathFromId(id);
29982
- res = tryFsResolve(fsPath, options, preserveSymlinks);
30116
+ res = tryFsResolve(fsPath, options);
29983
30117
  isDebug$5 && debug$d(`[@fs] ${source.cyan(id)} -> ${source.dim(res)}`);
29984
30118
  // always return here even if res doesn't exist since /@fs/ is explicit
29985
30119
  // if the file doesn't exist it should be a 404
@@ -29989,7 +30123,7 @@ function resolvePlugin(baseOptions) {
29989
30123
  // /foo -> /fs-root/foo
29990
30124
  if (asSrc && id.startsWith('/')) {
29991
30125
  const fsPath = path__default.resolve(root, id.slice(1));
29992
- if ((res = tryFsResolve(fsPath, options, preserveSymlinks))) {
30126
+ if ((res = tryFsResolve(fsPath, options))) {
29993
30127
  isDebug$5 && debug$d(`[url] ${source.cyan(id)} -> ${source.dim(res)}`);
29994
30128
  return res;
29995
30129
  }
@@ -30011,10 +30145,10 @@ function resolvePlugin(baseOptions) {
30011
30145
  }
30012
30146
  }
30013
30147
  if (targetWeb &&
30014
- (res = tryResolveBrowserMapping(fsPath, importer, options, true, preserveSymlinks))) {
30148
+ (res = tryResolveBrowserMapping(fsPath, importer, options, true))) {
30015
30149
  return res;
30016
30150
  }
30017
- if ((res = tryFsResolve(fsPath, options, preserveSymlinks))) {
30151
+ if ((res = tryFsResolve(fsPath, options))) {
30018
30152
  isDebug$5 && debug$d(`[relative] ${source.cyan(id)} -> ${source.dim(res)}`);
30019
30153
  const pkg = importer != null && idToPkgMap.get(importer);
30020
30154
  if (pkg) {
@@ -30028,8 +30162,7 @@ function resolvePlugin(baseOptions) {
30028
30162
  }
30029
30163
  }
30030
30164
  // absolute fs paths
30031
- if (path__default.isAbsolute(id) &&
30032
- (res = tryFsResolve(id, options, preserveSymlinks))) {
30165
+ if (path__default.isAbsolute(id) && (res = tryFsResolve(id, options))) {
30033
30166
  isDebug$5 && debug$d(`[fs] ${source.cyan(id)} -> ${source.dim(res)}`);
30034
30167
  return res;
30035
30168
  }
@@ -30054,7 +30187,7 @@ function resolvePlugin(baseOptions) {
30054
30187
  return res;
30055
30188
  }
30056
30189
  if (targetWeb &&
30057
- (res = tryResolveBrowserMapping(id, importer, options, false, preserveSymlinks))) {
30190
+ (res = tryResolveBrowserMapping(id, importer, options, false))) {
30058
30191
  return res;
30059
30192
  }
30060
30193
  if ((res = tryNodeResolve(id, importer, options, targetWeb, server, ssr))) {
@@ -30103,7 +30236,7 @@ function resolvePlugin(baseOptions) {
30103
30236
  }
30104
30237
  };
30105
30238
  }
30106
- function tryFsResolve(fsPath, options, preserveSymlinks, tryIndex = true, targetWeb = true) {
30239
+ function tryFsResolve(fsPath, options, tryIndex = true, targetWeb = true) {
30107
30240
  let file = fsPath;
30108
30241
  let postfix = '';
30109
30242
  let postfixIndex = fsPath.indexOf('?');
@@ -30117,48 +30250,53 @@ function tryFsResolve(fsPath, options, preserveSymlinks, tryIndex = true, target
30117
30250
  let res;
30118
30251
  // if we fould postfix exist, we should first try resolving file with postfix. details see #4703.
30119
30252
  if (postfix &&
30120
- (res = tryResolveFile(fsPath, '', options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30253
+ (res = tryResolveFile(fsPath, '', options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
30121
30254
  return res;
30122
30255
  }
30123
- if ((res = tryResolveFile(file, postfix, options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30256
+ if ((res = tryResolveFile(file, postfix, options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
30124
30257
  return res;
30125
30258
  }
30126
30259
  for (const ext of options.extensions || DEFAULT_EXTENSIONS$1) {
30127
30260
  if (postfix &&
30128
- (res = tryResolveFile(fsPath + ext, '', options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30261
+ (res = tryResolveFile(fsPath + ext, '', options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
30129
30262
  return res;
30130
30263
  }
30131
- if ((res = tryResolveFile(file + ext, postfix, options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30264
+ if ((res = tryResolveFile(file + ext, postfix, options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
30132
30265
  return res;
30133
30266
  }
30134
30267
  }
30135
30268
  if (postfix &&
30136
- (res = tryResolveFile(fsPath, '', options, tryIndex, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30269
+ (res = tryResolveFile(fsPath, '', options, tryIndex, targetWeb, options.tryPrefix, options.skipPackageJson))) {
30137
30270
  return res;
30138
30271
  }
30139
- if ((res = tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30272
+ if ((res = tryResolveFile(file, postfix, options, tryIndex, targetWeb, options.tryPrefix, options.skipPackageJson))) {
30140
30273
  return res;
30141
30274
  }
30142
30275
  }
30143
- function tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSymlinks, tryPrefix, skipPackageJson) {
30276
+ function tryResolveFile(file, postfix, options, tryIndex, targetWeb, tryPrefix, skipPackageJson) {
30144
30277
  // #2051 if we don't have read permission on a directory, existsSync() still
30145
30278
  // works and will result in massively slow subsequent checks (which are
30146
30279
  // unnecessary in the first place)
30147
30280
  if (isFileReadable(file)) {
30148
30281
  if (!fs__default.statSync(file).isDirectory()) {
30149
- return getRealPath(file, preserveSymlinks) + postfix;
30282
+ return getRealPath(file, options.preserveSymlinks) + postfix;
30150
30283
  }
30151
30284
  else if (tryIndex) {
30152
30285
  if (!skipPackageJson) {
30153
30286
  const pkgPath = file + '/package.json';
30154
- if (fs__default.existsSync(pkgPath)) {
30287
+ try {
30155
30288
  // path points to a node package
30156
- const pkg = loadPackageData(pkgPath);
30157
- const resolved = resolvePackageEntry(file, pkg, options, targetWeb, preserveSymlinks);
30289
+ const pkg = loadPackageData(pkgPath, options.preserveSymlinks);
30290
+ const resolved = resolvePackageEntry(file, pkg, targetWeb, options);
30158
30291
  return resolved;
30159
30292
  }
30293
+ catch (e) {
30294
+ if (e.code !== 'ENOENT') {
30295
+ throw e;
30296
+ }
30297
+ }
30160
30298
  }
30161
- const index = tryFsResolve(file + '/index', options, preserveSymlinks);
30299
+ const index = tryFsResolve(file + '/index', options);
30162
30300
  if (index)
30163
30301
  return index + postfix;
30164
30302
  }
@@ -30166,28 +30304,45 @@ function tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSym
30166
30304
  const tryTsExtension = options.isFromTsImporter && isPossibleTsOutput(file);
30167
30305
  if (tryTsExtension) {
30168
30306
  const tsSrcPath = getTsSrcPath(file);
30169
- return tryResolveFile(tsSrcPath, postfix, options, tryIndex, targetWeb, preserveSymlinks, tryPrefix, skipPackageJson);
30307
+ return tryResolveFile(tsSrcPath, postfix, options, tryIndex, targetWeb, tryPrefix, skipPackageJson);
30170
30308
  }
30171
30309
  if (tryPrefix) {
30172
30310
  const prefixed = `${path__default.dirname(file)}/${tryPrefix}${path__default.basename(file)}`;
30173
- return tryResolveFile(prefixed, postfix, options, tryIndex, targetWeb, preserveSymlinks);
30311
+ return tryResolveFile(prefixed, postfix, options, tryIndex, targetWeb);
30174
30312
  }
30175
30313
  }
30176
30314
  const idToPkgMap = new Map();
30177
30315
  function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
30178
30316
  var _a, _b, _c;
30179
- const { root, dedupe, isBuild } = options;
30317
+ const { root, dedupe, isBuild, preserveSymlinks, packageCache } = options;
30180
30318
  // split id by last '>' for nested selected packages, for example:
30181
30319
  // 'foo > bar > baz' => 'foo > bar' & 'baz'
30182
30320
  // 'foo' => '' & 'foo'
30183
30321
  const lastArrowIndex = id.lastIndexOf('>');
30184
30322
  const nestedRoot = id.substring(0, lastArrowIndex).trim();
30185
30323
  const nestedPath = id.substring(lastArrowIndex + 1).trim();
30186
- // check for deep import, e.g. "my-lib/foo"
30187
- const deepMatch = nestedPath.match(deepImportRE);
30188
- const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : nestedPath;
30324
+ const possiblePkgIds = [];
30325
+ for (let prevSlashIndex = -1;;) {
30326
+ let slashIndex = nestedPath.indexOf('/', prevSlashIndex + 1);
30327
+ if (slashIndex < 0) {
30328
+ slashIndex = nestedPath.length;
30329
+ }
30330
+ const part = nestedPath.slice(prevSlashIndex + 1, (prevSlashIndex = slashIndex));
30331
+ if (!part) {
30332
+ break;
30333
+ }
30334
+ // Assume path parts with an extension are not package roots, except for the
30335
+ // first path part (since periods are sadly allowed in package names).
30336
+ // At the same time, skip the first path part if it begins with "@"
30337
+ // (since "@foo/bar" should be treated as the top-level path).
30338
+ if (possiblePkgIds.length ? path__default.extname(part) : part[0] === '@') {
30339
+ continue;
30340
+ }
30341
+ const possiblePkgId = nestedPath.slice(0, slashIndex);
30342
+ possiblePkgIds.push(possiblePkgId);
30343
+ }
30189
30344
  let basedir;
30190
- if (dedupe && dedupe.includes(pkgId)) {
30345
+ if (dedupe === null || dedupe === void 0 ? void 0 : dedupe.some((id) => possiblePkgIds.includes(id))) {
30191
30346
  basedir = root;
30192
30347
  }
30193
30348
  else if (importer &&
@@ -30200,15 +30355,39 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
30200
30355
  }
30201
30356
  // nested node module, step-by-step resolve to the basedir of the nestedPath
30202
30357
  if (nestedRoot) {
30203
- basedir = nestedResolveFrom(nestedRoot, basedir, options.preserveSymlinks);
30358
+ basedir = nestedResolveFrom(nestedRoot, basedir, preserveSymlinks);
30204
30359
  }
30205
- const pkg = resolvePackageData(pkgId, basedir, options.preserveSymlinks);
30360
+ let pkg;
30361
+ const pkgId = possiblePkgIds.reverse().find((pkgId) => {
30362
+ pkg = resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
30363
+ return pkg;
30364
+ });
30206
30365
  if (!pkg) {
30207
30366
  return;
30208
30367
  }
30209
- let resolved = deepMatch
30210
- ? resolveDeepImport('.' + id.slice(pkgId.length), pkg, options, targetWeb, options.preserveSymlinks)
30211
- : resolvePackageEntry(id, pkg, options, targetWeb, options.preserveSymlinks);
30368
+ let resolveId = resolvePackageEntry;
30369
+ let unresolvedId = pkgId;
30370
+ if (unresolvedId !== nestedPath) {
30371
+ resolveId = resolveDeepImport;
30372
+ unresolvedId = '.' + nestedPath.slice(pkgId.length);
30373
+ }
30374
+ let resolved;
30375
+ try {
30376
+ resolved = resolveId(unresolvedId, pkg, targetWeb, options);
30377
+ }
30378
+ catch (err) {
30379
+ if (!options.tryEsmOnly) {
30380
+ throw err;
30381
+ }
30382
+ }
30383
+ if (!resolved && options.tryEsmOnly) {
30384
+ resolved = resolveId(unresolvedId, pkg, targetWeb, {
30385
+ ...options,
30386
+ isRequire: false,
30387
+ mainFields: DEFAULT_MAIN_FIELDS,
30388
+ extensions: DEFAULT_EXTENSIONS$1
30389
+ });
30390
+ }
30212
30391
  if (!resolved) {
30213
30392
  return;
30214
30393
  }
@@ -30235,7 +30414,7 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
30235
30414
  if (!isJsType ||
30236
30415
  (importer === null || importer === void 0 ? void 0 : importer.includes('node_modules')) ||
30237
30416
  (exclude === null || exclude === void 0 ? void 0 : exclude.includes(pkgId)) ||
30238
- (exclude === null || exclude === void 0 ? void 0 : exclude.includes(id)) ||
30417
+ (exclude === null || exclude === void 0 ? void 0 : exclude.includes(nestedPath)) ||
30239
30418
  SPECIAL_QUERY_RE.test(resolved) ||
30240
30419
  ssr) {
30241
30420
  // excluded from optimization
@@ -30298,61 +30477,7 @@ function tryOptimizedResolve(id, server, importer) {
30298
30477
  }
30299
30478
  }
30300
30479
  }
30301
- const packageCache = new Map();
30302
- function resolvePackageData(id, basedir, preserveSymlinks = false) {
30303
- const cacheKey = id + basedir;
30304
- if (packageCache.has(cacheKey)) {
30305
- return packageCache.get(cacheKey);
30306
- }
30307
- try {
30308
- const pkgPath = resolveFrom$3(`${id}/package.json`, basedir, preserveSymlinks);
30309
- return loadPackageData(pkgPath, cacheKey);
30310
- }
30311
- catch (e) {
30312
- isDebug$5 && debug$d(`${source.red(`[failed loading package.json]`)} ${id}`);
30313
- }
30314
- }
30315
- function loadPackageData(pkgPath, cacheKey = pkgPath) {
30316
- const data = JSON.parse(fs__default.readFileSync(pkgPath, 'utf-8'));
30317
- const pkgDir = path__default.dirname(pkgPath);
30318
- const { sideEffects } = data;
30319
- let hasSideEffects;
30320
- if (typeof sideEffects === 'boolean') {
30321
- hasSideEffects = () => sideEffects;
30322
- }
30323
- else if (Array.isArray(sideEffects)) {
30324
- hasSideEffects = createFilter$1(sideEffects, null, { resolve: pkgDir });
30325
- }
30326
- else {
30327
- hasSideEffects = () => true;
30328
- }
30329
- const pkg = {
30330
- dir: pkgDir,
30331
- data,
30332
- hasSideEffects,
30333
- webResolvedImports: {},
30334
- nodeResolvedImports: {},
30335
- setResolvedCache(key, entry, targetWeb) {
30336
- if (targetWeb) {
30337
- pkg.webResolvedImports[key] = entry;
30338
- }
30339
- else {
30340
- pkg.nodeResolvedImports[key] = entry;
30341
- }
30342
- },
30343
- getResolvedCache(key, targetWeb) {
30344
- if (targetWeb) {
30345
- return pkg.webResolvedImports[key];
30346
- }
30347
- else {
30348
- return pkg.nodeResolvedImports[key];
30349
- }
30350
- }
30351
- };
30352
- packageCache.set(cacheKey, pkg);
30353
- return pkg;
30354
- }
30355
- function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache }, options, targetWeb, preserveSymlinks = false) {
30480
+ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache }, targetWeb, options) {
30356
30481
  var _a, _b;
30357
30482
  const cached = getResolvedCache('.', targetWeb);
30358
30483
  if (cached) {
@@ -30384,7 +30509,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
30384
30509
  // the heuristics here is to actually read the browser entry when
30385
30510
  // possible and check for hints of UMD. If it is UMD, prefer "module"
30386
30511
  // instead; Otherwise, assume it's ESM and use it.
30387
- const resolvedBrowserEntry = tryFsResolve(path__default.join(dir, browserEntry), options, preserveSymlinks);
30512
+ const resolvedBrowserEntry = tryFsResolve(path__default.join(dir, browserEntry), options);
30388
30513
  if (resolvedBrowserEntry) {
30389
30514
  const content = fs__default.readFileSync(resolvedBrowserEntry, 'utf-8');
30390
30515
  if ((/typeof exports\s*==/.test(content) &&
@@ -30421,7 +30546,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
30421
30546
  entryPoint = mapWithBrowserField(entryPoint, browserField) || entryPoint;
30422
30547
  }
30423
30548
  entryPoint = path__default.join(dir, entryPoint);
30424
- const resolvedEntryPoint = tryFsResolve(entryPoint, options, preserveSymlinks);
30549
+ const resolvedEntryPoint = tryFsResolve(entryPoint, options);
30425
30550
  if (resolvedEntryPoint) {
30426
30551
  isDebug$5 &&
30427
30552
  debug$d(`[package entry] ${source.cyan(id)} -> ${source.dim(resolvedEntryPoint)}`);
@@ -30455,7 +30580,7 @@ function resolveExports(pkg, key, options, targetWeb) {
30455
30580
  conditions
30456
30581
  });
30457
30582
  }
30458
- function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolvedCache, dir, data }, options, targetWeb, preserveSymlinks) {
30583
+ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolvedCache, dir, data }, targetWeb, options) {
30459
30584
  const cache = getResolvedCache(id, targetWeb);
30460
30585
  if (cache) {
30461
30586
  return cache;
@@ -30486,7 +30611,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
30486
30611
  }
30487
30612
  }
30488
30613
  if (relativeId) {
30489
- const resolved = tryFsResolve(path__default.join(dir, relativeId), options, preserveSymlinks, !exportsField, // try index only if no exports field
30614
+ const resolved = tryFsResolve(path__default.join(dir, relativeId), options, !exportsField, // try index only if no exports field
30490
30615
  targetWeb);
30491
30616
  if (resolved) {
30492
30617
  isDebug$5 &&
@@ -30496,7 +30621,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
30496
30621
  }
30497
30622
  }
30498
30623
  }
30499
- function tryResolveBrowserMapping(id, importer, options, isFilePath, preserveSymlinks) {
30624
+ function tryResolveBrowserMapping(id, importer, options, isFilePath) {
30500
30625
  let res;
30501
30626
  const pkg = importer && idToPkgMap.get(importer);
30502
30627
  if (pkg && isObject$3(pkg.data.browser)) {
@@ -30504,7 +30629,7 @@ function tryResolveBrowserMapping(id, importer, options, isFilePath, preserveSym
30504
30629
  const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser);
30505
30630
  if (browserMappedPath) {
30506
30631
  const fsPath = path__default.join(pkg.dir, browserMappedPath);
30507
- if ((res = tryFsResolve(fsPath, options, preserveSymlinks))) {
30632
+ if ((res = tryFsResolve(fsPath, options))) {
30508
30633
  isDebug$5 &&
30509
30634
  debug$d(`[browser mapped] ${source.cyan(id)} -> ${source.dim(res)}`);
30510
30635
  idToPkgMap.set(res, pkg);
@@ -42770,7 +42895,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42770
42895
  return {
42771
42896
  name: 'vite:dep-scan',
42772
42897
  setup(build) {
42773
- const moduleScripts = {};
42898
+ const localScripts = {};
42774
42899
  // external urls
42775
42900
  build.onResolve({ filter: externalRE }, ({ path }) => ({
42776
42901
  path,
@@ -42781,12 +42906,17 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42781
42906
  path,
42782
42907
  external: true
42783
42908
  }));
42784
- build.onResolve({ filter: virtualModuleRE }, async ({ path, importer }) => {
42909
+ // local scripts (`<script>` in Svelte and `<script setup>` in Vue)
42910
+ build.onResolve({ filter: virtualModuleRE }, ({ path }) => {
42785
42911
  return {
42786
- path,
42787
- namespace: 'html'
42912
+ // strip prefix to get valid filesystem path so esbuild can resolve imports in the file
42913
+ path: path.replace(virtualModulePrefix, ''),
42914
+ namespace: 'local-script'
42788
42915
  };
42789
42916
  });
42917
+ build.onLoad({ filter: /.*/, namespace: 'local-script' }, ({ path }) => {
42918
+ return localScripts[path];
42919
+ });
42790
42920
  // html types: extract script contents -----------------------------------
42791
42921
  build.onResolve({ filter: htmlTypesRE }, async ({ path, importer }) => {
42792
42922
  return {
@@ -42794,9 +42924,6 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42794
42924
  namespace: 'html'
42795
42925
  };
42796
42926
  });
42797
- build.onLoad({ filter: virtualModuleRE, namespace: 'html' }, async ({ path }) => {
42798
- return moduleScripts[path];
42799
- });
42800
42927
  // extract scripts inside HTML-like files and treat it as a js module
42801
42928
  build.onLoad({ filter: htmlTypesRE, namespace: 'html' }, async ({ path }) => {
42802
42929
  let raw = fs__default.readFileSync(path, 'utf-8');
@@ -42838,12 +42965,11 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42838
42965
  (contextMatch[1] || contextMatch[2] || contextMatch[3]);
42839
42966
  if ((path.endsWith('.vue') && setupRE.test(raw)) ||
42840
42967
  (path.endsWith('.svelte') && context !== 'module')) {
42841
- const id = `virtual-module:${path}`;
42842
- moduleScripts[id] = {
42968
+ localScripts[path] = {
42843
42969
  loader,
42844
42970
  contents: content
42845
42971
  };
42846
- js += `import '${id}';\n`;
42972
+ js += `import '${virtualModulePrefix}${path}';\n`;
42847
42973
  }
42848
42974
  else {
42849
42975
  js += content + '\n';
@@ -43163,11 +43289,12 @@ function resolveBuildOptions(root, raw) {
43163
43289
  let input;
43164
43290
  if ((_a = raw === null || raw === void 0 ? void 0 : raw.rollupOptions) === null || _a === void 0 ? void 0 : _a.input) {
43165
43291
  input = Array.isArray(raw.rollupOptions.input)
43166
- ? raw.rollupOptions.input.map(input => resolve(input))
43292
+ ? raw.rollupOptions.input.map((input) => resolve(input))
43167
43293
  : typeof raw.rollupOptions.input === 'object'
43168
- ? Object.assign(
43169
- // @ts-ignore
43170
- ...Object.keys(raw.rollupOptions.input).map(key => ({ [key]: resolve(raw.rollupOptions.input[key]) })))
43294
+ ? Object.fromEntries(Object.entries(raw.rollupOptions.input).map(([key, value]) => [
43295
+ key,
43296
+ resolve(value)
43297
+ ]))
43171
43298
  : resolve(raw.rollupOptions.input);
43172
43299
  }
43173
43300
  else {
@@ -43214,6 +43341,7 @@ function resolveBuildPlugins(config) {
43214
43341
  const options = config.build;
43215
43342
  return {
43216
43343
  pre: [
43344
+ watchPackageDataPlugin(config),
43217
43345
  buildHtmlPlugin(config),
43218
43346
  commonjs(options.commonjsOptions),
43219
43347
  dataURIPlugin(),
@@ -49325,7 +49453,7 @@ function readFileIfExists(value) {
49325
49453
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49326
49454
  */
49327
49455
  async function createCertificate() {
49328
- const { generate } = await Promise.resolve().then(function () { return require('./dep-90234190.js'); }).then(function (n) { return n.index; });
49456
+ const { generate } = await Promise.resolve().then(function () { return require('./dep-03d6dbab.js'); }).then(function (n) { return n.index; });
49329
49457
  const pems = generate(null, {
49330
49458
  algorithm: 'sha256',
49331
49459
  days: 30,
@@ -56506,16 +56634,20 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
56506
56634
  // so that we don't prefix them
56507
56635
  node.params.forEach((p) => walk$1(p.type === 'AssignmentPattern' ? p.left : p, {
56508
56636
  enter(child, parent) {
56509
- if (child.type === 'Identifier' &&
56510
- // do not record as scope variable if is a destructuring key
56511
- !isStaticPropertyKey(child, parent) &&
56512
- // do not record if this is a default value
56513
- // assignment of a destructuring variable
56514
- !(parent &&
56515
- parent.type === 'AssignmentPattern' &&
56516
- parent.right === child)) {
56517
- setScope(node, child.name);
56637
+ if (child.type !== 'Identifier')
56638
+ return;
56639
+ // do not record as scope variable if is a destructuring keyword
56640
+ if (isStaticPropertyKey(child, parent))
56641
+ return;
56642
+ // do not record if this is a default value
56643
+ // assignment of a destructuring variable
56644
+ if (((parent === null || parent === void 0 ? void 0 : parent.type) === 'AssignmentPattern' &&
56645
+ (parent === null || parent === void 0 ? void 0 : parent.right) === child) ||
56646
+ ((parent === null || parent === void 0 ? void 0 : parent.type) === 'TemplateLiteral' &&
56647
+ (parent === null || parent === void 0 ? void 0 : parent.expressions.includes(child)))) {
56648
+ return;
56518
56649
  }
56650
+ setScope(node, child.name);
56519
56651
  }
56520
56652
  }));
56521
56653
  }
@@ -56535,6 +56667,11 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
56535
56667
  }
56536
56668
  });
56537
56669
  }
56670
+ else if (node.id.type === 'ArrayPattern') {
56671
+ node.id.elements.forEach((element) => {
56672
+ setScope(parentFunction, element.name);
56673
+ });
56674
+ }
56538
56675
  else {
56539
56676
  setScope(parentFunction, node.id.name);
56540
56677
  }
@@ -57731,7 +57868,7 @@ async function handleHMRUpdate(file, server) {
57731
57868
  // auto restart server
57732
57869
  debugHmr(`[config change] ${source.dim(shortFile)}`);
57733
57870
  config.logger.info(source.green(`${path__default.relative(process.cwd(), file)} changed, restarting server...`), { clear: true, timestamp: true });
57734
- await restartServer(server);
57871
+ await server.restart();
57735
57872
  return;
57736
57873
  }
57737
57874
  debugHmr(`[file change] ${source.dim(shortFile)}`);
@@ -58074,34 +58211,6 @@ async function readModifiedFile(file) {
58074
58211
  return content;
58075
58212
  }
58076
58213
  }
58077
- async function restartServer(server) {
58078
- // @ts-ignore
58079
- global.__vite_start_time = perf_hooks.performance.now();
58080
- const { port } = server.config.server;
58081
- await server.close();
58082
- let newServer = null;
58083
- try {
58084
- newServer = await createServer(server.config.inlineConfig);
58085
- }
58086
- catch (err) {
58087
- server.config.logger.error(err.message, {
58088
- timestamp: true
58089
- });
58090
- return;
58091
- }
58092
- for (const key in newServer) {
58093
- if (key !== 'app') {
58094
- // @ts-ignore
58095
- server[key] = newServer[key];
58096
- }
58097
- }
58098
- if (!server.config.server.middlewareMode) {
58099
- await server.listen(port, true);
58100
- }
58101
- else {
58102
- server.config.logger.info('server restarted.', { timestamp: true });
58103
- }
58104
- }
58105
58214
 
58106
58215
  var isWsl$2 = {exports: {}};
58107
58216
 
@@ -66959,7 +67068,9 @@ function rebindErrorStacktrace(e, stacktrace) {
66959
67068
  */
66960
67069
  function ssrRequireHookPlugin(config) {
66961
67070
  var _a;
66962
- if (config.command !== 'build' || !((_a = config.resolve.dedupe) === null || _a === void 0 ? void 0 : _a.length)) {
67071
+ if (config.command !== 'build' ||
67072
+ !((_a = config.resolve.dedupe) === null || _a === void 0 ? void 0 : _a.length) ||
67073
+ isBuildOutputEsm(config)) {
66963
67074
  return null;
66964
67075
  }
66965
67076
  return {
@@ -67003,6 +67114,11 @@ function hookNodeResolve(getResolver) {
67003
67114
  Module._resolveFilename = prevResolver;
67004
67115
  };
67005
67116
  }
67117
+ function isBuildOutputEsm(config) {
67118
+ var _a;
67119
+ const outputs = arraify((_a = config.build.rollupOptions) === null || _a === void 0 ? void 0 : _a.output);
67120
+ return outputs.some((output) => (output === null || output === void 0 ? void 0 : output.format) === 'es' || (output === null || output === void 0 ? void 0 : output.format) === 'esm');
67121
+ }
67006
67122
 
67007
67123
  const pendingModules = new Map();
67008
67124
  const pendingImports = new Map();
@@ -67052,17 +67168,18 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
67052
67168
  };
67053
67169
  urlStack = urlStack.concat(url);
67054
67170
  const isCircular = (url) => urlStack.includes(url);
67055
- const { isProduction, resolve: { dedupe }, root } = server.config;
67171
+ const { isProduction, resolve: { dedupe, preserveSymlinks }, root } = server.config;
67172
+ // The `extensions` and `mainFields` options are used to ensure that
67173
+ // CommonJS modules are preferred. We want to avoid ESM->ESM imports
67174
+ // whenever possible, because `hookNodeResolve` can't intercept them.
67056
67175
  const resolveOptions = {
67057
- conditions: ['node'],
67058
67176
  dedupe,
67059
- // Prefer CommonJS modules.
67060
- extensions: ['.js', '.mjs', '.ts', '.jsx', '.tsx', '.json'],
67177
+ extensions: ['.js', '.cjs', '.json'],
67061
67178
  isBuild: true,
67062
67179
  isProduction,
67063
- // Disable "module" condition.
67064
67180
  isRequire: true,
67065
67181
  mainFields: ['main'],
67182
+ preserveSymlinks,
67066
67183
  root
67067
67184
  };
67068
67185
  // Since dynamic imports can happen in parallel, we need to
@@ -67134,8 +67251,8 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
67134
67251
  async function nodeImport(id, importer, resolveOptions) {
67135
67252
  // Node's module resolution is hi-jacked so Vite can ensure the
67136
67253
  // configured `resolve.dedupe` and `mode` options are respected.
67137
- const viteResolve = (id, importer) => {
67138
- const resolved = tryNodeResolve(id, importer, resolveOptions, false);
67254
+ const viteResolve = (id, importer, options = resolveOptions) => {
67255
+ const resolved = tryNodeResolve(id, importer, options, false);
67139
67256
  if (!resolved) {
67140
67257
  const err = new Error(`Cannot find module '${id}' imported from '${importer}'`);
67141
67258
  err.code = 'ERR_MODULE_NOT_FOUND';
@@ -67144,16 +67261,29 @@ async function nodeImport(id, importer, resolveOptions) {
67144
67261
  return resolved.id;
67145
67262
  };
67146
67263
  // When an ESM module imports an ESM dependency, this hook is *not* used.
67147
- const unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => id[0] === '.' || isBuiltin(id)
67148
- ? nodeResolve(id, parent, isMain, options)
67149
- : viteResolve(id, parent.id));
67264
+ const unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => {
67265
+ if (id[0] === '.' || isBuiltin(id)) {
67266
+ return nodeResolve(id, parent, isMain, options);
67267
+ }
67268
+ if (parent) {
67269
+ return viteResolve(id, parent.id);
67270
+ }
67271
+ // Importing a CJS module from an ESM module. In this case, the import
67272
+ // specifier is already an absolute path, so this is a no-op.
67273
+ // Options like `resolve.dedupe` and `mode` are not respected.
67274
+ return id;
67275
+ });
67150
67276
  let url;
67151
- // `resolve` doesn't handle `node:` builtins, so handle them directly
67152
67277
  if (id.startsWith('node:') || isBuiltin(id)) {
67153
67278
  url = id;
67154
67279
  }
67155
67280
  else {
67156
- url = viteResolve(id, importer);
67281
+ url = viteResolve(id, importer,
67282
+ // Non-external modules can import ESM-only modules, but only outside
67283
+ // of test runs, because we use Node `require` in Jest to avoid segfault.
67284
+ typeof jest === 'undefined'
67285
+ ? { ...resolveOptions, tryEsmOnly: true }
67286
+ : resolveOptions);
67157
67287
  if (usingDynamicImport) {
67158
67288
  url = require$$0$7.pathToFileURL(url).toString();
67159
67289
  }
@@ -67390,9 +67520,21 @@ async function createServer(inlineConfig = {}) {
67390
67520
  throw new Error('cannot print server URLs in middleware mode.');
67391
67521
  }
67392
67522
  },
67523
+ async restart(forceOptimize) {
67524
+ if (!server._restartPromise) {
67525
+ server._forceOptimizeOnRestart = !!forceOptimize;
67526
+ server._restartPromise = restartServer(server).finally(() => {
67527
+ server._restartPromise = null;
67528
+ server._forceOptimizeOnRestart = false;
67529
+ });
67530
+ }
67531
+ return server._restartPromise;
67532
+ },
67393
67533
  _optimizeDepsMetadata: null,
67394
67534
  _ssrExternals: null,
67395
67535
  _globImporters: Object.create(null),
67536
+ _restartPromise: null,
67537
+ _forceOptimizeOnRestart: false,
67396
67538
  _isRunningOptimizer: false,
67397
67539
  _registerMissingImport: null,
67398
67540
  _pendingReload: null,
@@ -67411,8 +67553,19 @@ async function createServer(inlineConfig = {}) {
67411
67553
  if (!middlewareMode && process.env.CI !== 'true') {
67412
67554
  process.stdin.on('end', exitProcess);
67413
67555
  }
67556
+ const { packageCache } = config;
67557
+ const setPackageData = packageCache.set.bind(packageCache);
67558
+ packageCache.set = (id, pkg) => {
67559
+ if (id.endsWith('.json')) {
67560
+ watcher.add(id);
67561
+ }
67562
+ return setPackageData(id, pkg);
67563
+ };
67414
67564
  watcher.on('change', async (file) => {
67415
67565
  file = normalizePath$4(file);
67566
+ if (file.endsWith('/package.json')) {
67567
+ return invalidatePackageData(packageCache, file);
67568
+ }
67416
67569
  // invalidate module graph cache on file change
67417
67570
  moduleGraph.onFileChange(file);
67418
67571
  if (serverConfig.hmr !== false) {
@@ -67507,7 +67660,7 @@ async function createServer(inlineConfig = {}) {
67507
67660
  if (config.cacheDir) {
67508
67661
  server._isRunningOptimizer = true;
67509
67662
  try {
67510
- server._optimizeDepsMetadata = await optimizeDeps(config);
67663
+ server._optimizeDepsMetadata = await optimizeDeps(config, config.server.force || server._forceOptimizeOnRestart);
67511
67664
  }
67512
67665
  finally {
67513
67666
  server._isRunningOptimizer = false;
@@ -67636,6 +67789,34 @@ function resolveServerOptions(root, raw) {
67636
67789
  };
67637
67790
  return server;
67638
67791
  }
67792
+ async function restartServer(server) {
67793
+ // @ts-ignore
67794
+ global.__vite_start_time = perf_hooks.performance.now();
67795
+ const { port } = server.config.server;
67796
+ await server.close();
67797
+ let newServer = null;
67798
+ try {
67799
+ newServer = await createServer(server.config.inlineConfig);
67800
+ }
67801
+ catch (err) {
67802
+ server.config.logger.error(err.message, {
67803
+ timestamp: true
67804
+ });
67805
+ return;
67806
+ }
67807
+ for (const key in newServer) {
67808
+ if (key !== 'app') {
67809
+ // @ts-ignore
67810
+ server[key] = newServer[key];
67811
+ }
67812
+ }
67813
+ if (!server.config.server.middlewareMode) {
67814
+ await server.listen(port, true);
67815
+ }
67816
+ else {
67817
+ server.config.logger.info('server restarted.', { timestamp: true });
67818
+ }
67819
+ }
67639
67820
 
67640
67821
  var index = {
67641
67822
  __proto__: null,
@@ -80871,6 +81052,12 @@ function importAnalysisPlugin(config) {
80871
81052
  if (pluginImports) {
80872
81053
  (await Promise.all([...pluginImports].map((id) => normalizeUrl(id, 0)))).forEach(([url]) => importedUrls.add(url));
80873
81054
  }
81055
+ // HMR transforms are no-ops in SSR, so an `accept` call will
81056
+ // never be injected. Avoid updating the `isSelfAccepting`
81057
+ // property for our module node in that case.
81058
+ if (ssr && importerModule.isSelfAccepting) {
81059
+ isSelfAccepting = true;
81060
+ }
80874
81061
  const prunedImports = await moduleGraph.updateModuleInfo(importerModule, importedUrls, normalizedAcceptedUrls, isSelfAccepting);
80875
81062
  if (hasHMR && prunedImports) {
80876
81063
  handlePrunedModules(prunedImports, server);
@@ -80931,11 +81118,14 @@ function transformCjsImport(importExp, url, rawUrl, importIndex) {
80931
81118
  ecmaVersion: 'latest',
80932
81119
  sourceType: 'module'
80933
81120
  }).body[0];
80934
- if (node.type === 'ImportDeclaration') {
81121
+ if (node.type === 'ImportDeclaration' ||
81122
+ node.type === 'ExportNamedDeclaration') {
80935
81123
  if (!node.specifiers.length) {
80936
81124
  return `import "${url}"`;
80937
81125
  }
80938
81126
  const importNames = [];
81127
+ const exportNames = [];
81128
+ let defaultExports = '';
80939
81129
  for (const spec of node.specifiers) {
80940
81130
  if (spec.type === 'ImportSpecifier' &&
80941
81131
  spec.imported.type === 'Identifier') {
@@ -80952,6 +81142,21 @@ function transformCjsImport(importExp, url, rawUrl, importIndex) {
80952
81142
  else if (spec.type === 'ImportNamespaceSpecifier') {
80953
81143
  importNames.push({ importedName: '*', localName: spec.local.name });
80954
81144
  }
81145
+ else if (spec.type === 'ExportSpecifier' &&
81146
+ spec.exported.type === 'Identifier') {
81147
+ // for ExportSpecifier, local name is same as imported name
81148
+ const importedName = spec.local.name;
81149
+ // we want to specify exported name as variable and re-export it
81150
+ const exportedName = spec.exported.name;
81151
+ if (exportedName === 'default') {
81152
+ defaultExports = makeLegalIdentifier$1(`__vite__cjsExportDefault_${importIndex}`);
81153
+ importNames.push({ importedName, localName: defaultExports });
81154
+ }
81155
+ else {
81156
+ importNames.push({ importedName, localName: exportedName });
81157
+ exportNames.push(exportedName);
81158
+ }
81159
+ }
80955
81160
  }
80956
81161
  // If there is multiple import for same id in one file,
80957
81162
  // importIndex will prevent the cjsModuleName to be duplicate
@@ -80968,6 +81173,12 @@ function transformCjsImport(importExp, url, rawUrl, importIndex) {
80968
81173
  lines.push(`const ${localName} = ${cjsModuleName}["${importedName}"]`);
80969
81174
  }
80970
81175
  });
81176
+ if (defaultExports) {
81177
+ lines.push(`export default ${defaultExports}`);
81178
+ }
81179
+ if (exportNames.length) {
81180
+ lines.push(`export { ${exportNames.join(', ')} }`);
81181
+ }
80971
81182
  return lines.join('; ');
80972
81183
  }
80973
81184
  }
@@ -81325,6 +81536,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
81325
81536
  root: config.root,
81326
81537
  isProduction: config.isProduction,
81327
81538
  isBuild,
81539
+ packageCache: config.packageCache,
81328
81540
  ssrConfig: config.ssr,
81329
81541
  asSrc: true
81330
81542
  }),
@@ -81701,6 +81913,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
81701
81913
  return DEFAULT_ASSETS_RE.test(file) || assetsFilter(file);
81702
81914
  },
81703
81915
  logger,
81916
+ packageCache: new Map(),
81704
81917
  createResolver,
81705
81918
  optimizeDeps: {
81706
81919
  ...config.optimizeDeps,
@@ -81996,8 +82209,7 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
81996
82209
  if (!userConfig) {
81997
82210
  // 2. if we reach here, the file is ts or using es import syntax, or
81998
82211
  // the user has type: "module" in their package.json (#917)
81999
- // transpile es import syntax to require syntax using rollup.
82000
- // lazy require rollup (it's actually in dependencies)
82212
+ // transpile es import syntax to require syntax using esbuild.
82001
82213
  const bundled = await bundleConfigFile(resolvedPath);
82002
82214
  dependencies = bundled.dependencies;
82003
82215
  userConfig = await loadConfigFromBundledFile(resolvedPath, bundled.code);
@@ -82168,4 +82380,4 @@ exports.send = send$1;
82168
82380
  exports.sortUserPlugins = sortUserPlugins;
82169
82381
  exports.source = source;
82170
82382
  exports.transformWithEsbuild = transformWithEsbuild;
82171
- //# sourceMappingURL=dep-6cab8e8a.js.map
82383
+ //# sourceMappingURL=dep-d87be5e9.js.map