vite 2.7.2 → 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.

package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## [2.7.3](https://github.com/vitejs/vite/compare/v2.7.2...v2.7.3) (2021-12-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * do not overwrite rollupOptions.input in dev ([#6025](https://github.com/vitejs/vite/issues/6025)) ([6cdf13a](https://github.com/vitejs/vite/commit/6cdf13ae808a99b7aca6d278bee2ebe6e51d0846))
7
+ * Improve post-build asset update check ([#6113](https://github.com/vitejs/vite/issues/6113)) ([611fa03](https://github.com/vitejs/vite/commit/611fa037a72a1179c27794353ffad6ed27e10d1a))
8
+ * improve warning message for malformed packages ([#6086](https://github.com/vitejs/vite/issues/6086)) ([717cb08](https://github.com/vitejs/vite/commit/717cb08f8611fd1a15cfd614d346185ffe8a61fd))
9
+ * pending reload never timeout ([#6120](https://github.com/vitejs/vite/issues/6120)) ([e002f4f](https://github.com/vitejs/vite/commit/e002f4f4a578ae63156e756abac0487f42b4cdcd))
10
+ * respect new port when change the config file ([#6075](https://github.com/vitejs/vite/issues/6075)) ([3ceffcc](https://github.com/vitejs/vite/commit/3ceffcca66311f9a7d71612a596b84888c3f843b))
11
+ * **ssr:** robust regexp to check cjs content ([#6053](https://github.com/vitejs/vite/issues/6053)) ([0373441](https://github.com/vitejs/vite/commit/03734417cde10807ab2dd0d71b08c26081aac0b7))
12
+ * terminate WebSocket connections before closing WebSocket server ([#6115](https://github.com/vitejs/vite/issues/6115)) ([b9871bb](https://github.com/vitejs/vite/commit/b9871bbed57c5964b3393e798b0ef2526471d692))
13
+
14
+
15
+
1
16
  ## [2.7.2](https://github.com/vitejs/vite/compare/v2.7.1...v2.7.2) (2021-12-13)
2
17
 
3
18
 
@@ -186,7 +186,7 @@ export interface LibraryOptions {
186
186
  }
187
187
  export declare type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife';
188
188
  export declare type ResolvedBuildOptions = Required<Omit<BuildOptions, 'base' | 'cleanCssOptions' | 'polyfillDynamicImport' | 'brotliSize'>>;
189
- export declare function resolveBuildOptions(root: string, raw?: BuildOptions): ResolvedBuildOptions;
189
+ export declare function resolveBuildOptions(root: string, raw?: BuildOptions, isBuild?: boolean): ResolvedBuildOptions;
190
190
  export declare function resolveBuildPlugins(config: ResolvedConfig): {
191
191
  pre: Plugin[];
192
192
  post: Plugin[];
@@ -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-fffc0487.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;
@@ -21401,7 +21401,7 @@ const assetAttrsConfig = {
21401
21401
  const isAsyncScriptMap = new WeakMap();
21402
21402
  async function traverseHtml(html, filePath, visitor) {
21403
21403
  // lazy load compiler
21404
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-93096c54.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; });
21405
21405
  // @vue/compiler-core doesn't like lowercase doctypes
21406
21406
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21407
21407
  try {
@@ -21467,6 +21467,7 @@ function buildHtmlPlugin(config) {
21467
21467
  isAsyncScriptMap.set(config, new Map());
21468
21468
  },
21469
21469
  async transform(html, id) {
21470
+ var _a, _b;
21470
21471
  if (id.endsWith('.html')) {
21471
21472
  const publicPath = `/${slash$3(path__default.relative(config.root, id))}`;
21472
21473
  // pre-transform
@@ -21557,20 +21558,26 @@ function buildHtmlPlugin(config) {
21557
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.`);
21558
21559
  }
21559
21560
  // for each encountered asset url, rewrite original html so that it
21560
- // 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) || {});
21561
21564
  for (const attr of assetUrls) {
21562
21565
  const value = attr.value;
21563
- try {
21564
- const url = attr.name === 'srcset'
21565
- ? await processSrcSet(value.content, ({ url }) => urlToBuiltUrl(url, id, config, this))
21566
- : await urlToBuiltUrl(value.content, id, config, this);
21567
- s.overwrite(value.loc.start.offset, value.loc.end.offset, `"${url}"`);
21568
- }
21569
- catch (e) {
21570
- // #1885 preload may be pointing to urls that do not exist
21571
- // locally on disk
21572
- if (e.code !== 'ENOENT') {
21573
- 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
+ }
21574
21581
  }
21575
21582
  }
21576
21583
  }
@@ -30758,6 +30765,7 @@ function resolveSSRExternal(config, knownImports) {
30758
30765
  }
30759
30766
  return externals;
30760
30767
  }
30768
+ const CJS_CONTENT_RE = /\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(|\bObject\.(defineProperty|defineProperties|assign)\s*\(\s*exports\b/;
30761
30769
  // do we need to do this ahead of time or could we do it lazily?
30762
30770
  function collectExternals(root, preserveSymlinks, ssrExternals, seen, logger) {
30763
30771
  var _a;
@@ -30836,11 +30844,11 @@ function collectExternals(root, preserveSymlinks, ssrExternals, seen, logger) {
30836
30844
  }
30837
30845
  // check if the entry is cjs
30838
30846
  const content = fs__default.readFileSync(esmEntry, 'utf-8');
30839
- if (/\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(/.test(content)) {
30847
+ if (CJS_CONTENT_RE.test(content)) {
30840
30848
  ssrExternals.add(id);
30841
30849
  continue;
30842
30850
  }
30843
- logger.warn(`${id} is incorrectly packaged. Please contact the package author to fix.`);
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.`);
30844
30852
  }
30845
30853
  }
30846
30854
  for (const depRoot of depsToTrace) {
@@ -43349,7 +43357,7 @@ function loadFallbackPlugin() {
43349
43357
  };
43350
43358
  }
43351
43359
 
43352
- function resolveBuildOptions(root, raw) {
43360
+ function resolveBuildOptions(root, raw, isBuild) {
43353
43361
  var _a;
43354
43362
  const resolved = {
43355
43363
  target: 'modules',
@@ -43398,18 +43406,22 @@ function resolveBuildOptions(root, raw) {
43398
43406
  ]))
43399
43407
  : resolve(raw.rollupOptions.input);
43400
43408
  }
43401
- else {
43402
- input = resolve((raw === null || raw === void 0 ? void 0 : raw.lib)
43403
- ? raw.lib.entry
43404
- : typeof (raw === null || raw === void 0 ? void 0 : raw.ssr) === 'string'
43405
- ? raw.ssr
43406
- : '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');
43407
43417
  }
43408
43418
  if (!!(raw === null || raw === void 0 ? void 0 : raw.ssr) && typeof input === 'string' && input.endsWith('.html')) {
43409
43419
  throw new Error(`rollupOptions.input should not be an html file when building for SSR. ` +
43410
43420
  `Please specify a dedicated SSR entry.`);
43411
43421
  }
43412
- resolved.rollupOptions.input = input;
43422
+ if (input) {
43423
+ resolved.rollupOptions.input = input;
43424
+ }
43413
43425
  // handle special build targets
43414
43426
  if (resolved.target === 'modules') {
43415
43427
  // Support browserslist
@@ -43449,7 +43461,7 @@ function resolveBuildPlugins(config) {
43449
43461
  dynamicImportVariables(options.dynamicImportVarsOptions),
43450
43462
  assetImportMetaUrlPlugin(config),
43451
43463
  ...(options.rollupOptions.plugins
43452
- ? options.rollupOptions.plugins.filter((p) => !!p)
43464
+ ? options.rollupOptions.plugins.filter(Boolean)
43453
43465
  : [])
43454
43466
  ],
43455
43467
  post: [
@@ -49560,7 +49572,7 @@ function readFileIfExists(value) {
49560
49572
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49561
49573
  */
49562
49574
  async function createCertificate() {
49563
- const { generate } = await Promise.resolve().then(function () { return require('./dep-453486e7.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; });
49564
49576
  const pems = generate(null, {
49565
49577
  algorithm: 'sha256',
49566
49578
  days: 30,
@@ -53835,6 +53847,9 @@ function createWebSocketServer(server, config, httpsOptions) {
53835
53847
  },
53836
53848
  close() {
53837
53849
  return new Promise((resolve, reject) => {
53850
+ wss.clients.forEach((client) => {
53851
+ client.terminate();
53852
+ });
53838
53853
  wss.close((err) => {
53839
53854
  if (err) {
53840
53855
  reject(err);
@@ -57641,21 +57656,26 @@ function transformMiddleware(server) {
57641
57656
  // always allow vite client requests so that it can trigger page reload
57642
57657
  !((_a = req.url) === null || _a === void 0 ? void 0 : _a.startsWith(CLIENT_PUBLIC_PATH)) &&
57643
57658
  !((_b = req.url) === null || _b === void 0 ? void 0 : _b.includes('vite/dist/client'))) {
57644
- // missing dep pending reload, hold request until reload happens
57645
- server._pendingReload.then(() =>
57646
- // If the refresh has not happened after timeout, Vite considers
57647
- // something unexpected has happened. In this case, Vite
57648
- // returns an empty response that will error.
57649
- 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 {
57650
57670
  // Don't do anything if response has already been sent
57651
- if (res.writableEnded)
57652
- return;
57653
- // status code request timeout
57654
- res.statusCode = 408;
57655
- res.end(`<h1>[vite] Something unexpected happened while optimizing "${req.url}"<h1>` +
57656
- `<p>The current page should have reloaded by now</p>`);
57657
- }, NEW_DEPENDENCY_BUILD_TIMEOUT));
57658
- 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
+ }
57659
57679
  }
57660
57680
  let url = decodeURI(removeTimestampQuery(req.url)).replace(NULL_BYTE_PLACEHOLDER, '\0');
57661
57681
  const withoutQuery = cleanUrl(url);
@@ -58055,7 +58075,12 @@ async function handleHMRUpdate(file, server) {
58055
58075
  // auto restart server
58056
58076
  debugHmr(`[config change] ${source.dim(shortFile)}`);
58057
58077
  config.logger.info(source.green(`${path__default.relative(process.cwd(), file)} changed, restarting server...`), { clear: true, timestamp: true });
58058
- await server.restart();
58078
+ try {
58079
+ await server.restart();
58080
+ }
58081
+ catch (e) {
58082
+ config.logger.error(source.red(e));
58083
+ }
58059
58084
  return;
58060
58085
  }
58061
58086
  debugHmr(`[file change] ${source.dim(shortFile)}`);
@@ -67991,7 +68016,7 @@ function resolveServerOptions(root, raw) {
67991
68016
  async function restartServer(server) {
67992
68017
  // @ts-ignore
67993
68018
  global.__vite_start_time = perf_hooks.performance.now();
67994
- const { port } = server.config.server;
68019
+ const { port: prevPort, host: prevHost } = server.config.server;
67995
68020
  await server.close();
67996
68021
  let newServer = null;
67997
68022
  try {
@@ -68009,11 +68034,17 @@ async function restartServer(server) {
68009
68034
  server[key] = newServer[key];
68010
68035
  }
68011
68036
  }
68012
- if (!server.config.server.middlewareMode) {
68037
+ const { logger, server: { port, host, middlewareMode } } = server.config;
68038
+ if (!middlewareMode) {
68013
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
+ }
68014
68045
  }
68015
68046
  else {
68016
- server.config.logger.info('server restarted.', { timestamp: true });
68047
+ logger.info('server restarted.', { timestamp: true });
68017
68048
  }
68018
68049
  }
68019
68050
 
@@ -82030,7 +82061,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
82030
82061
  }
82031
82062
  // resolve public base url
82032
82063
  const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger);
82033
- const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build);
82064
+ const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build, command === 'build');
82034
82065
  // resolve cache directory
82035
82066
  const pkgPath = lookupFile(resolvedRoot, [`package.json`], true /* pathOnly */);
82036
82067
  const cacheDir = config.cacheDir
@@ -82555,4 +82586,4 @@ exports.send = send$1;
82555
82586
  exports.sortUserPlugins = sortUserPlugins;
82556
82587
  exports.source = source;
82557
82588
  exports.transformWithEsbuild = transformWithEsbuild;
82558
- //# sourceMappingURL=dep-7817f5b4.js.map
82589
+ //# sourceMappingURL=dep-5496817b.js.map