vite 2.7.0-beta.9 → 2.7.3

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.

Files changed (76) hide show
  1. package/CHANGELOG.md +99 -29
  2. package/dist/node/build.d.ts +200 -0
  3. package/dist/node/chunks/{dep-9aea22f6.js → dep-5496817b.js} +280 -110
  4. package/dist/node/chunks/dep-5496817b.js.map +1 -0
  5. package/dist/node/chunks/{dep-ff5fc8ed.js → dep-66abeb03.js} +2 -2
  6. package/dist/node/chunks/{dep-ff5fc8ed.js.map → dep-66abeb03.js.map} +1 -1
  7. package/dist/node/chunks/{dep-f90ad7ac.js → dep-cf2decec.js} +2 -2
  8. package/dist/node/chunks/{dep-f90ad7ac.js.map → dep-cf2decec.js.map} +1 -1
  9. package/dist/node/chunks/{dep-a2051654.js → dep-df937e9b.js} +2 -2
  10. package/dist/node/chunks/{dep-a2051654.js.map → dep-df937e9b.js.map} +1 -1
  11. package/dist/node/cli.d.ts +1 -0
  12. package/dist/node/cli.js +4 -4
  13. package/dist/node/cli.js.map +1 -1
  14. package/dist/node/config.d.ts +202 -0
  15. package/dist/node/constants.d.ts +33 -0
  16. package/dist/node/http.d.ts +84 -0
  17. package/dist/node/importGlob.d.ts +9 -0
  18. package/dist/node/index.d.ts +280 -280
  19. package/dist/node/index.js +1 -1
  20. package/dist/node/logger.d.ts +35 -0
  21. package/dist/node/optimizer/esbuildDepPlugin.d.ts +4 -0
  22. package/dist/node/optimizer/index.d.ts +66 -0
  23. package/dist/node/optimizer/registerMissing.d.ts +2 -0
  24. package/dist/node/optimizer/scan.d.ts +9 -0
  25. package/dist/node/packages.d.ts +25 -0
  26. package/dist/node/plugin.d.ts +115 -0
  27. package/dist/node/plugins/asset.d.ts +40 -0
  28. package/dist/node/plugins/assetImportMetaUrl.d.ts +13 -0
  29. package/dist/node/plugins/clientInjections.d.ts +7 -0
  30. package/dist/node/plugins/css.d.ts +72 -0
  31. package/dist/node/plugins/dataUri.d.ts +5 -0
  32. package/dist/node/plugins/define.d.ts +3 -0
  33. package/dist/node/plugins/esbuild.d.ts +15 -0
  34. package/dist/node/plugins/html.d.ts +102 -0
  35. package/dist/node/plugins/importAnalysis.d.ts +46 -0
  36. package/dist/node/plugins/importAnalysisBuild.d.ts +15 -0
  37. package/dist/node/plugins/index.d.ts +3 -0
  38. package/dist/node/plugins/json.d.ts +22 -0
  39. package/dist/node/plugins/loadFallback.d.ts +5 -0
  40. package/dist/node/plugins/manifest.d.ts +14 -0
  41. package/dist/node/plugins/modulePreloadPolyfill.d.ts +4 -0
  42. package/dist/node/plugins/preAlias.d.ts +5 -0
  43. package/dist/node/plugins/reporter.d.ts +3 -0
  44. package/dist/node/plugins/resolve.d.ts +38 -0
  45. package/dist/node/plugins/ssrRequireHook.d.ts +12 -0
  46. package/dist/node/plugins/terser.d.ts +3 -0
  47. package/dist/node/plugins/wasm.d.ts +3 -0
  48. package/dist/node/plugins/worker.d.ts +3 -0
  49. package/dist/node/preview.d.ts +31 -0
  50. package/dist/node/server/hmr.d.ts +37 -0
  51. package/dist/node/server/index.d.ts +214 -0
  52. package/dist/node/server/middlewares/base.d.ts +3 -0
  53. package/dist/node/server/middlewares/error.d.ts +8 -0
  54. package/dist/node/server/middlewares/indexHtml.d.ts +4 -0
  55. package/dist/node/server/middlewares/proxy.d.ts +20 -0
  56. package/dist/node/server/middlewares/spaFallback.d.ts +2 -0
  57. package/dist/node/server/middlewares/static.d.ts +6 -0
  58. package/dist/node/server/middlewares/time.d.ts +2 -0
  59. package/dist/node/server/middlewares/transform.d.ts +3 -0
  60. package/dist/node/server/moduleGraph.d.ts +53 -0
  61. package/dist/node/server/openBrowser.d.ts +15 -0
  62. package/dist/node/server/pluginContainer.d.ts +37 -0
  63. package/dist/node/server/searchRoot.d.ts +8 -0
  64. package/dist/node/server/send.d.ts +4 -0
  65. package/dist/node/server/sourcemap.d.ts +8 -0
  66. package/dist/node/server/transformRequest.d.ts +14 -0
  67. package/dist/node/server/ws.d.ts +14 -0
  68. package/dist/node/ssr/ssrExternal.d.ts +7 -0
  69. package/dist/node/ssr/ssrManifestPlugin.d.ts +3 -0
  70. package/dist/node/ssr/ssrModuleLoader.d.ts +7 -0
  71. package/dist/node/ssr/ssrStacktrace.d.ts +3 -0
  72. package/dist/node/ssr/ssrTransform.d.ts +8 -0
  73. package/dist/node/utils.d.ts +114 -0
  74. package/package.json +5 -5
  75. package/types/ws.d.ts +277 -281
  76. package/dist/node/chunks/dep-9aea22f6.js.map +0 -1
@@ -4316,8 +4316,8 @@ function arraify(target) {
4316
4316
  function toUpperCaseDriveLetter(pathName) {
4317
4317
  return pathName.replace(/^\w:/, (letter) => letter.toUpperCase());
4318
4318
  }
4319
- const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
4320
- const singlelineCommentsRE = /\/\/.*/g;
4319
+ const multilineCommentsRE$1 = /\/\*(.|[\r\n])*?\*\//gm;
4320
+ const singlelineCommentsRE$1 = /\/\/.*/g;
4321
4321
  const usingDynamicImport = typeof jest === 'undefined';
4322
4322
  /**
4323
4323
  * Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
@@ -5981,7 +5981,7 @@ function assetFileNamesToFileName(assetFileNames, file, contentHash, content) {
5981
5981
  // placeholders for `assetFileNames`
5982
5982
  // `hash` is slightly different from the rollup's one
5983
5983
  const extname = path__default.extname(basename);
5984
- const ext = extname.substr(1);
5984
+ const ext = extname.substring(1);
5985
5985
  const name = basename.slice(0, -extname.length);
5986
5986
  const hash = contentHash;
5987
5987
  if (typeof assetFileNames === 'function') {
@@ -20396,7 +20396,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20396
20396
  replacer: urlReplacer
20397
20397
  }));
20398
20398
  if (isModule) {
20399
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-f90ad7ac.js'); }).then(function (n) { return n.index; })).default({
20399
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-cf2decec.js'); }).then(function (n) { return n.index; })).default({
20400
20400
  ...modulesOptions,
20401
20401
  getJSON(cssFileName, _modules, outputFileName) {
20402
20402
  modules = _modules;
@@ -20976,7 +20976,34 @@ function lexGlobPattern(code, pos) {
20976
20976
  throw new Error('unknown import.meta.glob lexer state');
20977
20977
  }
20978
20978
  }
20979
- return [pattern, code.indexOf(`)`, i) + 1];
20979
+ const endIndex = getEndIndex(code, i);
20980
+ return [pattern, endIndex + 1];
20981
+ }
20982
+ // reg without the 'g' option, only matches the first match
20983
+ const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//m;
20984
+ const singlelineCommentsRE = /\/\/.*/;
20985
+ function getEndIndex(code, i) {
20986
+ var _a;
20987
+ const findStart = i;
20988
+ const endIndex = code.indexOf(`)`, findStart);
20989
+ const subCode = code.substring(findStart);
20990
+ const matched = (_a = subCode.match(singlelineCommentsRE)) !== null && _a !== void 0 ? _a : subCode.match(multilineCommentsRE);
20991
+ if (!matched) {
20992
+ return endIndex;
20993
+ }
20994
+ const str = matched[0];
20995
+ const index = matched.index;
20996
+ if (!index) {
20997
+ return endIndex;
20998
+ }
20999
+ const commentStart = findStart + index;
21000
+ const commentEnd = commentStart + str.length;
21001
+ if (endIndex > commentStart && endIndex < commentEnd) {
21002
+ return getEndIndex(code, commentEnd);
21003
+ }
21004
+ else {
21005
+ return endIndex;
21006
+ }
20980
21007
  }
20981
21008
  function error$3(pos) {
20982
21009
  const err = new Error(`import.meta.glob() can only accept string literals.`);
@@ -21342,7 +21369,7 @@ function htmlInlineScriptProxyPlugin(config) {
21342
21369
  const file = cleanUrl(id);
21343
21370
  const url = file.replace(normalizePath$4(config.root), '');
21344
21371
  const result = htmlProxyMap.get(config).get(url)[index];
21345
- if (result) {
21372
+ if (typeof result === 'string') {
21346
21373
  return result;
21347
21374
  }
21348
21375
  else {
@@ -21374,7 +21401,7 @@ const assetAttrsConfig = {
21374
21401
  const isAsyncScriptMap = new WeakMap();
21375
21402
  async function traverseHtml(html, filePath, visitor) {
21376
21403
  // lazy load compiler
21377
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-ff5fc8ed.js'); }).then(function (n) { return n.compilerDom_cjs; });
21404
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-66abeb03.js'); }).then(function (n) { return n.compilerDom_cjs; });
21378
21405
  // @vue/compiler-core doesn't like lowercase doctypes
21379
21406
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21380
21407
  try {
@@ -21440,6 +21467,7 @@ function buildHtmlPlugin(config) {
21440
21467
  isAsyncScriptMap.set(config, new Map());
21441
21468
  },
21442
21469
  async transform(html, id) {
21470
+ var _a, _b;
21443
21471
  if (id.endsWith('.html')) {
21444
21472
  const publicPath = `/${slash$3(path__default.relative(config.root, id))}`;
21445
21473
  // pre-transform
@@ -21530,20 +21558,26 @@ function buildHtmlPlugin(config) {
21530
21558
  config.logger.warn(`\nMixed async and defer script modules in ${id}, output script will fallback to defer. Every script, including inline ones, need to be marked as async for your output script to be async.`);
21531
21559
  }
21532
21560
  // for each encountered asset url, rewrite original html so that it
21533
- // references the post-build location.
21561
+ // references the post-build location, ignoring empty attributes and
21562
+ // attributes that directly reference named output.
21563
+ const namedOutput = Object.keys(((_b = (_a = config === null || config === void 0 ? void 0 : config.build) === null || _a === void 0 ? void 0 : _a.rollupOptions) === null || _b === void 0 ? void 0 : _b.input) || {});
21534
21564
  for (const attr of assetUrls) {
21535
21565
  const value = attr.value;
21536
- try {
21537
- const url = attr.name === 'srcset'
21538
- ? await processSrcSet(value.content, ({ url }) => urlToBuiltUrl(url, id, config, this))
21539
- : await urlToBuiltUrl(value.content, id, config, this);
21540
- s.overwrite(value.loc.start.offset, value.loc.end.offset, `"${url}"`);
21541
- }
21542
- catch (e) {
21543
- // #1885 preload may be pointing to urls that do not exist
21544
- // locally on disk
21545
- if (e.code !== 'ENOENT') {
21546
- throw e;
21566
+ const content = value.content;
21567
+ if (content !== '' && // Empty attribute
21568
+ !namedOutput.includes(content) && // Direct reference to named output
21569
+ !namedOutput.includes(content.replace(/^\//, '')) // Allow for absolute references as named output can't be an absolute path
21570
+ ) {
21571
+ try {
21572
+ const url = attr.name === 'srcset'
21573
+ ? await processSrcSet(content, ({ url }) => urlToBuiltUrl(url, id, config, this))
21574
+ : await urlToBuiltUrl(content, id, config, this);
21575
+ s.overwrite(value.loc.start.offset, value.loc.end.offset, `"${url}"`);
21576
+ }
21577
+ catch (e) {
21578
+ if (e.code !== 'ENOENT') {
21579
+ throw e;
21580
+ }
21547
21581
  }
21548
21582
  }
21549
21583
  }
@@ -30126,8 +30160,8 @@ function resolvePlugin(baseOptions) {
30126
30160
  // this is passed by @rollup/plugin-commonjs
30127
30161
  const isRequire = (_c = (_b = (_a = resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.custom) === null || _a === void 0 ? void 0 : _a['node-resolve']) === null || _b === void 0 ? void 0 : _b.isRequire) !== null && _c !== void 0 ? _c : false;
30128
30162
  const options = {
30129
- ...baseOptions,
30130
30163
  isRequire,
30164
+ ...baseOptions,
30131
30165
  isFromTsImporter: isTsRequest(importer !== null && importer !== void 0 ? importer : '')
30132
30166
  };
30133
30167
  let res;
@@ -30712,7 +30746,7 @@ function resolveSSRExternal(config, knownImports) {
30712
30746
  ssrExternals.add(id);
30713
30747
  seen.add(id);
30714
30748
  });
30715
- collectExternals(config.root, config.resolve.preserveSymlinks, ssrExternals, seen);
30749
+ collectExternals(config.root, config.resolve.preserveSymlinks, ssrExternals, seen, config.logger);
30716
30750
  const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined);
30717
30751
  for (const dep of importedDeps) {
30718
30752
  // Assume external if not yet seen
@@ -30731,17 +30765,18 @@ function resolveSSRExternal(config, knownImports) {
30731
30765
  }
30732
30766
  return externals;
30733
30767
  }
30768
+ const CJS_CONTENT_RE = /\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(|\bObject\.(defineProperty|defineProperties|assign)\s*\(\s*exports\b/;
30734
30769
  // do we need to do this ahead of time or could we do it lazily?
30735
- function collectExternals(root, preserveSymlinks, ssrExternals, seen) {
30770
+ function collectExternals(root, preserveSymlinks, ssrExternals, seen, logger) {
30736
30771
  var _a;
30737
- const pkgContent = lookupFile(root, ['package.json']);
30738
- if (!pkgContent) {
30772
+ const rootPkgContent = lookupFile(root, ['package.json']);
30773
+ if (!rootPkgContent) {
30739
30774
  return;
30740
30775
  }
30741
- const pkg = JSON.parse(pkgContent);
30776
+ const rootPkg = JSON.parse(rootPkgContent);
30742
30777
  const deps = {
30743
- ...pkg.devDependencies,
30744
- ...pkg.dependencies
30778
+ ...rootPkg.devDependencies,
30779
+ ...rootPkg.dependencies
30745
30780
  };
30746
30781
  const resolveOptions = {
30747
30782
  root,
@@ -30797,19 +30832,27 @@ function collectExternals(root, preserveSymlinks, ssrExternals, seen) {
30797
30832
  // or are there others like SystemJS / AMD that we'd need to handle?
30798
30833
  // for now, we'll just leave this as is
30799
30834
  else if (/\.m?js$/.test(esmEntry)) {
30835
+ const pkgPath = resolveFrom$3(`${id}/package.json`, root);
30836
+ const pkgContent = fs__default.readFileSync(pkgPath, 'utf-8');
30837
+ if (!pkgContent) {
30838
+ continue;
30839
+ }
30840
+ const pkg = JSON.parse(pkgContent);
30800
30841
  if (pkg.type === 'module' || esmEntry.endsWith('.mjs')) {
30801
30842
  ssrExternals.add(id);
30802
30843
  continue;
30803
30844
  }
30804
30845
  // check if the entry is cjs
30805
30846
  const content = fs__default.readFileSync(esmEntry, 'utf-8');
30806
- if (/\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(/.test(content)) {
30847
+ if (CJS_CONTENT_RE.test(content)) {
30807
30848
  ssrExternals.add(id);
30849
+ continue;
30808
30850
  }
30851
+ logger.warn(`${id} doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.`);
30809
30852
  }
30810
30853
  }
30811
30854
  for (const depRoot of depsToTrace) {
30812
- collectExternals(depRoot, preserveSymlinks, ssrExternals, seen);
30855
+ collectExternals(depRoot, preserveSymlinks, ssrExternals, seen, logger);
30813
30856
  }
30814
30857
  }
30815
30858
  function shouldExternalizeForSSR(id, externals) {
@@ -43018,11 +43061,15 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
43018
43061
  const contextMatch = openTag.match(contextRE);
43019
43062
  const context = contextMatch &&
43020
43063
  (contextMatch[1] || contextMatch[2] || contextMatch[3]);
43021
- if ((path.endsWith('.vue') && setupRE.test(raw)) ||
43064
+ if ((path.endsWith('.vue') && setupRE.test(openTag)) ||
43022
43065
  (path.endsWith('.svelte') && context !== 'module')) {
43066
+ // append imports in TS to prevent esbuild from removing them
43067
+ // since they may be used in the template
43068
+ const localContent = content +
43069
+ (loader.startsWith('ts') ? extractImportPaths(content) : '');
43023
43070
  localScripts[path] = {
43024
43071
  loader,
43025
- contents: content
43072
+ contents: localContent
43026
43073
  };
43027
43074
  js += `import '${virtualModulePrefix}${path}';\n`;
43028
43075
  }
@@ -43031,26 +43078,10 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
43031
43078
  }
43032
43079
  }
43033
43080
  }
43034
- // empty singleline & multiline comments to avoid matching comments
43035
- const code = js
43036
- .replace(multilineCommentsRE, '/* */')
43037
- .replace(singlelineCommentsRE, '');
43038
- if (loader.startsWith('ts') &&
43039
- (path.endsWith('.svelte') ||
43040
- (path.endsWith('.vue') && setupRE.test(raw)))) {
43041
- // when using TS + (Vue + <script setup>) or Svelte, imports may seem
43042
- // unused to esbuild and dropped in the build output, which prevents
43043
- // esbuild from crawling further.
43044
- // the solution is to add `import 'x'` for every source to force
43045
- // esbuild to keep crawling due to potential side effects.
43046
- let m;
43047
- while ((m = importsRE.exec(code)) != null) {
43048
- // This is necessary to avoid infinite loops with zero-width matches
43049
- if (m.index === importsRE.lastIndex) {
43050
- importsRE.lastIndex++;
43051
- }
43052
- js += `\nimport ${m[1]}`;
43053
- }
43081
+ // `<script>` in Svelte has imports that can be used in the template
43082
+ // so we handle them here too
43083
+ if (loader.startsWith('ts') && path.endsWith('.svelte')) {
43084
+ js += extractImportPaths(js);
43054
43085
  }
43055
43086
  // This will trigger incorrectly if `export default` is contained
43056
43087
  // anywhere in a string. Svelte and Astro files can't have
@@ -43192,6 +43223,29 @@ async function transformGlob(source, importer, root, loader) {
43192
43223
  }
43193
43224
  return s.toString();
43194
43225
  }
43226
+ /**
43227
+ * when using TS + (Vue + `<script setup>`) or Svelte, imports may seem
43228
+ * unused to esbuild and dropped in the build output, which prevents
43229
+ * esbuild from crawling further.
43230
+ * the solution is to add `import 'x'` for every source to force
43231
+ * esbuild to keep crawling due to potential side effects.
43232
+ */
43233
+ function extractImportPaths(code) {
43234
+ // empty singleline & multiline comments to avoid matching comments
43235
+ code = code
43236
+ .replace(multilineCommentsRE$1, '/* */')
43237
+ .replace(singlelineCommentsRE$1, '');
43238
+ let js = '';
43239
+ let m;
43240
+ while ((m = importsRE.exec(code)) != null) {
43241
+ // This is necessary to avoid infinite loops with zero-width matches
43242
+ if (m.index === importsRE.lastIndex) {
43243
+ importsRE.lastIndex++;
43244
+ }
43245
+ js += `\nimport ${m[1]}`;
43246
+ }
43247
+ return js;
43248
+ }
43195
43249
  function shouldExternalizeDep(resolvedId, rawId) {
43196
43250
  // not a valid file path
43197
43251
  if (!path__default.isAbsolute(resolvedId)) {
@@ -43225,8 +43279,8 @@ function assetImportMetaUrlPlugin(config) {
43225
43279
  if (code.includes('new URL') && code.includes(`import.meta.url`)) {
43226
43280
  const importMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\)/g;
43227
43281
  const noCommentsCode = code
43228
- .replace(multilineCommentsRE, (m) => ' '.repeat(m.length))
43229
- .replace(singlelineCommentsRE, (m) => ' '.repeat(m.length));
43282
+ .replace(multilineCommentsRE$1, (m) => ' '.repeat(m.length))
43283
+ .replace(singlelineCommentsRE$1, (m) => ' '.repeat(m.length));
43230
43284
  let s = null;
43231
43285
  let match;
43232
43286
  while ((match = importMetaUrlRE.exec(noCommentsCode))) {
@@ -43303,7 +43357,7 @@ function loadFallbackPlugin() {
43303
43357
  };
43304
43358
  }
43305
43359
 
43306
- function resolveBuildOptions(root, raw) {
43360
+ function resolveBuildOptions(root, raw, isBuild) {
43307
43361
  var _a;
43308
43362
  const resolved = {
43309
43363
  target: 'modules',
@@ -43352,18 +43406,22 @@ function resolveBuildOptions(root, raw) {
43352
43406
  ]))
43353
43407
  : resolve(raw.rollupOptions.input);
43354
43408
  }
43355
- else {
43356
- input = resolve((raw === null || raw === void 0 ? void 0 : raw.lib)
43357
- ? raw.lib.entry
43358
- : typeof (raw === null || raw === void 0 ? void 0 : raw.ssr) === 'string'
43359
- ? raw.ssr
43360
- : 'index.html');
43409
+ else if ((raw === null || raw === void 0 ? void 0 : raw.lib) && isBuild) {
43410
+ input = resolve(raw.lib.entry);
43411
+ }
43412
+ else if (typeof (raw === null || raw === void 0 ? void 0 : raw.ssr) === 'string') {
43413
+ input = resolve(raw.ssr);
43414
+ }
43415
+ else if (isBuild) {
43416
+ input = resolve('index.html');
43361
43417
  }
43362
43418
  if (!!(raw === null || raw === void 0 ? void 0 : raw.ssr) && typeof input === 'string' && input.endsWith('.html')) {
43363
43419
  throw new Error(`rollupOptions.input should not be an html file when building for SSR. ` +
43364
43420
  `Please specify a dedicated SSR entry.`);
43365
43421
  }
43366
- resolved.rollupOptions.input = input;
43422
+ if (input) {
43423
+ resolved.rollupOptions.input = input;
43424
+ }
43367
43425
  // handle special build targets
43368
43426
  if (resolved.target === 'modules') {
43369
43427
  // Support browserslist
@@ -43403,7 +43461,7 @@ function resolveBuildPlugins(config) {
43403
43461
  dynamicImportVariables(options.dynamicImportVarsOptions),
43404
43462
  assetImportMetaUrlPlugin(config),
43405
43463
  ...(options.rollupOptions.plugins
43406
- ? options.rollupOptions.plugins.filter((p) => !!p)
43464
+ ? options.rollupOptions.plugins.filter(Boolean)
43407
43465
  : [])
43408
43466
  ],
43409
43467
  post: [
@@ -43500,6 +43558,12 @@ async function doBuild(inlineConfig = {}) {
43500
43558
  };
43501
43559
  try {
43502
43560
  const buildOutputOptions = (output = {}) => {
43561
+ // @ts-ignore
43562
+ if (output.output) {
43563
+ config.logger.warn(`You've set "rollupOptions.output.output" in your config. ` +
43564
+ `This is deprecated and will override all Vite.js default output options. ` +
43565
+ `Please use "rollupOptions.output" instead.`);
43566
+ }
43503
43567
  return {
43504
43568
  dir: outDir,
43505
43569
  format: ssr ? 'cjs' : 'es',
@@ -49508,7 +49572,7 @@ function readFileIfExists(value) {
49508
49572
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49509
49573
  */
49510
49574
  async function createCertificate() {
49511
- const { generate } = await Promise.resolve().then(function () { return require('./dep-a2051654.js'); }).then(function (n) { return n.index; });
49575
+ const { generate } = await Promise.resolve().then(function () { return require('./dep-df937e9b.js'); }).then(function (n) { return n.index; });
49512
49576
  const pems = generate(null, {
49513
49577
  algorithm: 'sha256',
49514
49578
  days: 30,
@@ -51132,8 +51196,8 @@ class Sender$1 {
51132
51196
  if (payloadLength === 126) {
51133
51197
  target.writeUInt16BE(data.length, 2);
51134
51198
  } else if (payloadLength === 127) {
51135
- target.writeUInt32BE(0, 2);
51136
- target.writeUInt32BE(data.length, 6);
51199
+ target[2] = target[3] = 0;
51200
+ target.writeUIntBE(data.length, 4, 6);
51137
51201
  }
51138
51202
 
51139
51203
  if (!options.mask) return [target, data];
@@ -52002,6 +52066,7 @@ class WebSocket$1 extends EventEmitter$1 {
52002
52066
  this._closeMessage = EMPTY_BUFFER;
52003
52067
  this._closeTimer = null;
52004
52068
  this._extensions = {};
52069
+ this._paused = false;
52005
52070
  this._protocol = '';
52006
52071
  this._readyState = WebSocket$1.CONNECTING;
52007
52072
  this._receiver = null;
@@ -52068,6 +52133,13 @@ class WebSocket$1 extends EventEmitter$1 {
52068
52133
  return Object.keys(this._extensions).join();
52069
52134
  }
52070
52135
 
52136
+ /**
52137
+ * @type {Boolean}
52138
+ */
52139
+ get isPaused() {
52140
+ return this._paused;
52141
+ }
52142
+
52071
52143
  /**
52072
52144
  * @type {Function}
52073
52145
  */
@@ -52256,6 +52328,23 @@ class WebSocket$1 extends EventEmitter$1 {
52256
52328
  );
52257
52329
  }
52258
52330
 
52331
+ /**
52332
+ * Pause the socket.
52333
+ *
52334
+ * @public
52335
+ */
52336
+ pause() {
52337
+ if (
52338
+ this.readyState === WebSocket$1.CONNECTING ||
52339
+ this.readyState === WebSocket$1.CLOSED
52340
+ ) {
52341
+ return;
52342
+ }
52343
+
52344
+ this._paused = true;
52345
+ this._socket.pause();
52346
+ }
52347
+
52259
52348
  /**
52260
52349
  * Send a ping.
52261
52350
  *
@@ -52320,6 +52409,23 @@ class WebSocket$1 extends EventEmitter$1 {
52320
52409
  this._sender.pong(data || EMPTY_BUFFER, mask, cb);
52321
52410
  }
52322
52411
 
52412
+ /**
52413
+ * Resume the socket.
52414
+ *
52415
+ * @public
52416
+ */
52417
+ resume() {
52418
+ if (
52419
+ this.readyState === WebSocket$1.CONNECTING ||
52420
+ this.readyState === WebSocket$1.CLOSED
52421
+ ) {
52422
+ return;
52423
+ }
52424
+
52425
+ this._paused = false;
52426
+ if (!this._receiver._writableState.needDrain) this._socket.resume();
52427
+ }
52428
+
52323
52429
  /**
52324
52430
  * Send a data message.
52325
52431
  *
@@ -52462,6 +52568,7 @@ Object.defineProperty(WebSocket$1.prototype, 'CLOSED', {
52462
52568
  'binaryType',
52463
52569
  'bufferedAmount',
52464
52570
  'extensions',
52571
+ 'isPaused',
52465
52572
  'protocol',
52466
52573
  'readyState',
52467
52574
  'url'
@@ -52574,19 +52681,26 @@ function initAsClient(websocket, address, protocols, options) {
52574
52681
 
52575
52682
  const isSecure = parsedUrl.protocol === 'wss:';
52576
52683
  const isUnixSocket = parsedUrl.protocol === 'ws+unix:';
52684
+ let invalidURLMessage;
52577
52685
 
52578
52686
  if (parsedUrl.protocol !== 'ws:' && !isSecure && !isUnixSocket) {
52579
- throw new SyntaxError(
52580
- 'The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"'
52581
- );
52687
+ invalidURLMessage =
52688
+ 'The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"';
52689
+ } else if (isUnixSocket && !parsedUrl.pathname) {
52690
+ invalidURLMessage = "The URL's pathname is empty";
52691
+ } else if (parsedUrl.hash) {
52692
+ invalidURLMessage = 'The URL contains a fragment identifier';
52582
52693
  }
52583
52694
 
52584
- if (isUnixSocket && !parsedUrl.pathname) {
52585
- throw new SyntaxError("The URL's pathname is empty");
52586
- }
52695
+ if (invalidURLMessage) {
52696
+ const err = new SyntaxError(invalidURLMessage);
52587
52697
 
52588
- if (parsedUrl.hash) {
52589
- throw new SyntaxError('The URL contains a fragment identifier');
52698
+ if (websocket._redirects === 0) {
52699
+ throw err;
52700
+ } else {
52701
+ emitErrorAndClose(websocket, err);
52702
+ return;
52703
+ }
52590
52704
  }
52591
52705
 
52592
52706
  const defaultPort = isSecure ? 443 : 80;
@@ -52668,9 +52782,7 @@ function initAsClient(websocket, address, protocols, options) {
52668
52782
  if (req === null || req.aborted) return;
52669
52783
 
52670
52784
  req = websocket._req = null;
52671
- websocket._readyState = WebSocket$1.CLOSING;
52672
- websocket.emit('error', err);
52673
- websocket.emitClose();
52785
+ emitErrorAndClose(websocket, err);
52674
52786
  });
52675
52787
 
52676
52788
  req.on('response', (res) => {
@@ -52690,7 +52802,15 @@ function initAsClient(websocket, address, protocols, options) {
52690
52802
 
52691
52803
  req.abort();
52692
52804
 
52693
- const addr = new URL$2(location, address);
52805
+ let addr;
52806
+
52807
+ try {
52808
+ addr = new URL$2(location, address);
52809
+ } catch (e) {
52810
+ const err = new SyntaxError(`Invalid URL: ${location}`);
52811
+ emitErrorAndClose(websocket, err);
52812
+ return;
52813
+ }
52694
52814
 
52695
52815
  initAsClient(websocket, addr, protocols, options);
52696
52816
  } else if (!websocket.emit('unexpected-response', req, res)) {
@@ -52793,6 +52913,19 @@ function initAsClient(websocket, address, protocols, options) {
52793
52913
  });
52794
52914
  }
52795
52915
 
52916
+ /**
52917
+ * Emit the `'error'` and `'close'` event.
52918
+ *
52919
+ * @param {WebSocket} websocket The WebSocket instance
52920
+ * @param {Error} The error to emit
52921
+ * @private
52922
+ */
52923
+ function emitErrorAndClose(websocket, err) {
52924
+ websocket._readyState = WebSocket$1.CLOSING;
52925
+ websocket.emit('error', err);
52926
+ websocket.emitClose();
52927
+ }
52928
+
52796
52929
  /**
52797
52930
  * Create a `net.Socket` and initiate a connection.
52798
52931
  *
@@ -52919,7 +53052,9 @@ function receiverOnConclude(code, reason) {
52919
53052
  * @private
52920
53053
  */
52921
53054
  function receiverOnDrain() {
52922
- this[kWebSocket$1]._socket.resume();
53055
+ const websocket = this[kWebSocket$1];
53056
+
53057
+ if (!websocket.isPaused) websocket._socket.resume();
52923
53058
  }
52924
53059
 
52925
53060
  /**
@@ -53712,6 +53847,9 @@ function createWebSocketServer(server, config, httpsOptions) {
53712
53847
  },
53713
53848
  close() {
53714
53849
  return new Promise((resolve, reject) => {
53850
+ wss.clients.forEach((client) => {
53851
+ client.terminate();
53852
+ });
53715
53853
  wss.close((err) => {
53716
53854
  if (err) {
53717
53855
  reject(err);
@@ -56723,7 +56861,7 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
56723
56861
  });
56724
56862
  }
56725
56863
  else if (node.id.type === 'ArrayPattern') {
56726
- node.id.elements.forEach((element) => {
56864
+ node.id.elements.filter(Boolean).forEach((element) => {
56727
56865
  setScope(parentFunction, element.name);
56728
56866
  });
56729
56867
  }
@@ -57518,21 +57656,26 @@ function transformMiddleware(server) {
57518
57656
  // always allow vite client requests so that it can trigger page reload
57519
57657
  !((_a = req.url) === null || _a === void 0 ? void 0 : _a.startsWith(CLIENT_PUBLIC_PATH)) &&
57520
57658
  !((_b = req.url) === null || _b === void 0 ? void 0 : _b.includes('vite/dist/client'))) {
57521
- // missing dep pending reload, hold request until reload happens
57522
- server._pendingReload.then(() =>
57523
- // If the refresh has not happened after timeout, Vite considers
57524
- // something unexpected has happened. In this case, Vite
57525
- // returns an empty response that will error.
57526
- setTimeout(() => {
57659
+ try {
57660
+ // missing dep pending reload, hold request until reload happens
57661
+ await Promise.race([
57662
+ server._pendingReload,
57663
+ // If the refresh has not happened after timeout, Vite considers
57664
+ // something unexpected has happened. In this case, Vite
57665
+ // returns an empty response that will error.
57666
+ new Promise((_, reject) => setTimeout(reject, NEW_DEPENDENCY_BUILD_TIMEOUT))
57667
+ ]);
57668
+ }
57669
+ catch {
57527
57670
  // Don't do anything if response has already been sent
57528
- if (res.writableEnded)
57529
- return;
57530
- // status code request timeout
57531
- res.statusCode = 408;
57532
- res.end(`<h1>[vite] Something unexpected happened while optimizing "${req.url}"<h1>` +
57533
- `<p>The current page should have reloaded by now</p>`);
57534
- }, NEW_DEPENDENCY_BUILD_TIMEOUT));
57535
- return;
57671
+ if (!res.writableEnded) {
57672
+ // status code request timeout
57673
+ res.statusCode = 408;
57674
+ res.end(`<h1>[vite] Something unexpected happened while optimizing "${req.url}"<h1>` +
57675
+ `<p>The current page should have reloaded by now</p>`);
57676
+ }
57677
+ return;
57678
+ }
57536
57679
  }
57537
57680
  let url = decodeURI(removeTimestampQuery(req.url)).replace(NULL_BYTE_PLACEHOLDER, '\0');
57538
57681
  const withoutQuery = cleanUrl(url);
@@ -57677,7 +57820,13 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
57677
57820
  // add HTML Proxy to Map
57678
57821
  addToHTMLProxyCache(config, url, scriptModuleIndex, contents);
57679
57822
  // inline js module. convert to src="proxy"
57680
- s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${config.base + url.slice(1)}?html-proxy&index=${scriptModuleIndex}.js"></script>`);
57823
+ const modulePath = `${config.base + htmlPath.slice(1)}?html-proxy&index=${scriptModuleIndex}.js`;
57824
+ // invalidate the module so the newly cached contents will be served
57825
+ const module = server === null || server === void 0 ? void 0 : server.moduleGraph.getModuleById(modulePath);
57826
+ if (module) {
57827
+ server === null || server === void 0 ? void 0 : server.moduleGraph.invalidateModule(module);
57828
+ }
57829
+ s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${modulePath}"></script>`);
57681
57830
  }
57682
57831
  }
57683
57832
  // elements with [href/src] attrs
@@ -57926,7 +58075,12 @@ async function handleHMRUpdate(file, server) {
57926
58075
  // auto restart server
57927
58076
  debugHmr(`[config change] ${source.dim(shortFile)}`);
57928
58077
  config.logger.info(source.green(`${path__default.relative(process.cwd(), file)} changed, restarting server...`), { clear: true, timestamp: true });
57929
- await server.restart();
58078
+ try {
58079
+ await server.restart();
58080
+ }
58081
+ catch (e) {
58082
+ config.logger.error(source.red(e));
58083
+ }
57930
58084
  return;
57931
58085
  }
57932
58086
  debugHmr(`[file change] ${source.dim(shortFile)}`);
@@ -63712,7 +63866,7 @@ ssr) {
63712
63866
  data.browserHash = require$$1$1.createHash('sha256')
63713
63867
  .update(data.hash + JSON.stringify(deps))
63714
63868
  .digest('hex')
63715
- .substr(0, 8);
63869
+ .substring(0, 8);
63716
63870
  const missingIds = Object.keys(missing);
63717
63871
  if (missingIds.length) {
63718
63872
  throw new Error(`The following dependencies are imported but could not be resolved:\n\n ${missingIds
@@ -63900,7 +64054,7 @@ function getDepHash(root, config) {
63900
64054
  }
63901
64055
  return value;
63902
64056
  });
63903
- return require$$1$1.createHash('sha256').update(content).digest('hex').substr(0, 8);
64057
+ return require$$1$1.createHash('sha256').update(content).digest('hex').substring(0, 8);
63904
64058
  }
63905
64059
 
63906
64060
  var index$1 = {
@@ -67125,9 +67279,10 @@ function rebindErrorStacktrace(e, stacktrace) {
67125
67279
  * in development.
67126
67280
  */
67127
67281
  function ssrRequireHookPlugin(config) {
67128
- var _a;
67282
+ var _a, _b;
67129
67283
  if (config.command !== 'build' ||
67130
67284
  !((_a = config.resolve.dedupe) === null || _a === void 0 ? void 0 : _a.length) ||
67285
+ ((_b = config.ssr) === null || _b === void 0 ? void 0 : _b.noExternal) === true ||
67131
67286
  isBuildOutputEsm(config)) {
67132
67287
  return null;
67133
67288
  }
@@ -67350,19 +67505,24 @@ async function nodeImport(id, importer, resolveOptions) {
67350
67505
  }
67351
67506
  try {
67352
67507
  const mod = await dynamicImport(url);
67353
- return proxyESM(id, mod);
67508
+ return proxyESM(mod);
67354
67509
  }
67355
67510
  finally {
67356
67511
  unhookNodeResolve();
67357
67512
  }
67358
67513
  }
67359
67514
  // rollup-style default import interop for cjs
67360
- function proxyESM(id, mod) {
67361
- const defaultExport = mod.__esModule
67362
- ? mod.default
67363
- : mod.default
67364
- ? mod.default
67365
- : mod;
67515
+ function proxyESM(mod) {
67516
+ // This is the only sensible option when the exports object is a primitve
67517
+ if (isPrimitive(mod))
67518
+ return { default: mod };
67519
+ let defaultExport = 'default' in mod ? mod.default : mod;
67520
+ if (!isPrimitive(defaultExport) && '__esModule' in defaultExport) {
67521
+ mod = defaultExport;
67522
+ if ('default' in defaultExport) {
67523
+ defaultExport = defaultExport.default;
67524
+ }
67525
+ }
67366
67526
  return new Proxy(mod, {
67367
67527
  get(mod, prop) {
67368
67528
  var _a;
@@ -67372,6 +67532,9 @@ function proxyESM(id, mod) {
67372
67532
  }
67373
67533
  });
67374
67534
  }
67535
+ function isPrimitive(value) {
67536
+ return !value || (typeof value !== 'object' && typeof value !== 'function');
67537
+ }
67375
67538
 
67376
67539
  /**
67377
67540
  * The amount to wait for requests to register newly found dependencies before triggering
@@ -67540,6 +67703,7 @@ async function createServer(inlineConfig = {}) {
67540
67703
  pluginContainer: container,
67541
67704
  ws,
67542
67705
  moduleGraph,
67706
+ ssrTransform,
67543
67707
  transformWithEsbuild,
67544
67708
  transformRequest(url, options) {
67545
67709
  return transformRequest(url, server, options);
@@ -67852,7 +68016,7 @@ function resolveServerOptions(root, raw) {
67852
68016
  async function restartServer(server) {
67853
68017
  // @ts-ignore
67854
68018
  global.__vite_start_time = perf_hooks.performance.now();
67855
- const { port } = server.config.server;
68019
+ const { port: prevPort, host: prevHost } = server.config.server;
67856
68020
  await server.close();
67857
68021
  let newServer = null;
67858
68022
  try {
@@ -67870,11 +68034,17 @@ async function restartServer(server) {
67870
68034
  server[key] = newServer[key];
67871
68035
  }
67872
68036
  }
67873
- if (!server.config.server.middlewareMode) {
68037
+ const { logger, server: { port, host, middlewareMode } } = server.config;
68038
+ if (!middlewareMode) {
67874
68039
  await server.listen(port, true);
68040
+ logger.info('server restarted.', { timestamp: true });
68041
+ if (port !== prevPort || host !== prevHost) {
68042
+ logger.info('\n');
68043
+ server.printUrls();
68044
+ }
67875
68045
  }
67876
68046
  else {
67877
- server.config.logger.info('server restarted.', { timestamp: true });
68047
+ logger.info('server restarted.', { timestamp: true });
67878
68048
  }
67879
68049
  }
67880
68050
 
@@ -81891,7 +82061,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
81891
82061
  }
81892
82062
  // resolve public base url
81893
82063
  const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger);
81894
- const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build);
82064
+ const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build, command === 'build');
81895
82065
  // resolve cache directory
81896
82066
  const pkgPath = lookupFile(resolvedRoot, [`package.json`], true /* pathOnly */);
81897
82067
  const cacheDir = config.cacheDir
@@ -82416,4 +82586,4 @@ exports.send = send$1;
82416
82586
  exports.sortUserPlugins = sortUserPlugins;
82417
82587
  exports.source = source;
82418
82588
  exports.transformWithEsbuild = transformWithEsbuild;
82419
- //# sourceMappingURL=dep-9aea22f6.js.map
82589
+ //# sourceMappingURL=dep-5496817b.js.map