vite 4.0.3 → 4.0.4

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.

@@ -1,6 +1,6 @@
1
1
  import require$$0__default from 'fs';
2
2
  import require$$0 from 'postcss';
3
- import { C as commonjsGlobal } from './dep-0bae2027.js';
3
+ import { C as commonjsGlobal } from './dep-5e7f419b.js';
4
4
  import require$$0$1 from 'path';
5
5
  import require$$5 from 'crypto';
6
6
  import require$$0$2 from 'util';
@@ -11968,7 +11968,12 @@ function copyDir(srcDir, destDir) {
11968
11968
  const removeDir = isWindows$4
11969
11969
  ? promisify$4(gracefulRemoveDir)
11970
11970
  : function removeDirSync(dir) {
11971
- fs$l.rmSync(dir, { recursive: true, force: true });
11971
+ // when removing `.vite/deps`, if it doesn't exist, nodejs may also remove
11972
+ // other directories within `.vite/`, including `.vite/deps_temp` (bug).
11973
+ // workaround by checking for directory existence before removing for now.
11974
+ if (fs$l.existsSync(dir)) {
11975
+ fs$l.rmSync(dir, { recursive: true, force: true });
11976
+ }
11972
11977
  };
11973
11978
  const renameDir = isWindows$4 ? promisify$4(gracefulRename) : fs$l.renameSync;
11974
11979
  function ensureWatchedFile(watcher, file, root) {
@@ -12152,8 +12157,8 @@ async function resolveServerUrls(server, options, config) {
12152
12157
  const base = config.rawBase === './' || config.rawBase === '' ? '/' : config.rawBase;
12153
12158
  if (hostname.host && loopbackHosts.has(hostname.host)) {
12154
12159
  let hostnameName = hostname.name;
12155
- if (hostnameName === '::1' ||
12156
- hostnameName === '0000:0000:0000:0000:0000:0000:0000:0001') {
12160
+ // ipv6 host
12161
+ if (hostnameName.includes(':')) {
12157
12162
  hostnameName = `[${hostnameName}]`;
12158
12163
  }
12159
12164
  local.push(`${protocol}://${hostnameName}:${port}${base}`);
@@ -12167,7 +12172,11 @@ async function resolveServerUrls(server, options, config) {
12167
12172
  // @ts-expect-error Node 18.0 - 18.3 returns number
12168
12173
  (typeof detail.family === 'number' && detail.family === 4)))
12169
12174
  .forEach((detail) => {
12170
- const host = detail.address.replace('127.0.0.1', hostname.name);
12175
+ let host = detail.address.replace('127.0.0.1', hostname.name);
12176
+ // ipv6 host
12177
+ if (host.includes(':')) {
12178
+ host = `[${host}]`;
12179
+ }
12171
12180
  const url = `${protocol}://${host}:${port}${base}`;
12172
12181
  if (detail.address.includes('127.0.0.1')) {
12173
12182
  local.push(url);
@@ -14282,6 +14291,7 @@ function lookup(extn) {
14282
14291
  const assetUrlRE = /__VITE_ASSET__([a-z\d]+)__(?:\$_(.*?)__)?/g;
14283
14292
  const rawRE = /(?:\?|&)raw(?:&|$)/;
14284
14293
  const urlRE = /(\?|&)url(?:&|$)/;
14294
+ const jsSourceMapRE = /\.[cm]?js\.map$/;
14285
14295
  const assetCache = new WeakMap();
14286
14296
  const generatedAssets = new WeakMap();
14287
14297
  // add own dictionary entry by directly assigning mrmime
@@ -14390,7 +14400,8 @@ function assetPlugin(config) {
14390
14400
  if (config.command === 'build' && config.build.ssr) {
14391
14401
  for (const file in bundle) {
14392
14402
  if (bundle[file].type === 'asset' &&
14393
- !file.includes('ssr-manifest.json')) {
14403
+ !file.endsWith('ssr-manifest.json') &&
14404
+ !jsSourceMapRE.test(file)) {
14394
14405
  delete bundle[file];
14395
14406
  }
14396
14407
  }
@@ -14405,6 +14416,10 @@ function checkPublicFile(url, { publicDir }) {
14405
14416
  return;
14406
14417
  }
14407
14418
  const publicFile = path$o.join(publicDir, cleanUrl(url));
14419
+ if (!publicFile.startsWith(publicDir)) {
14420
+ // can happen if URL starts with '../'
14421
+ return;
14422
+ }
14408
14423
  if (fs$l.existsSync(publicFile)) {
14409
14424
  return publicFile;
14410
14425
  }
@@ -35157,6 +35172,8 @@ const inlineImportRE = /(?<!(?<!\.\.)\.)\bimport\s*\(("(?:[^"]|(?<=\\)")*"|'(?:[
35157
35172
  const htmlLangRE = /\.(?:html|htm)$/;
35158
35173
  const importMapRE = /[ \t]*<script[^>]*type\s*=\s*(?:"importmap"|'importmap'|importmap)[^>]*>.*?<\/script>/is;
35159
35174
  const moduleScriptRE = /[ \t]*<script[^>]*type\s*=\s*(?:"module"|'module'|module)[^>]*>/i;
35175
+ const modulePreloadLinkRE = /[ \t]*<link[^>]*rel\s*=\s*(?:"modulepreload"|'modulepreload'|modulepreload)[\s\S]*?\/>/i;
35176
+ const importMapAppendRE = new RegExp([moduleScriptRE, modulePreloadLinkRE].map((r) => r.source).join('|'), 'i');
35160
35177
  const isHTMLProxy = (id) => htmlProxyRE$1.test(id);
35161
35178
  const isHTMLRequest = (request) => htmlLangRE.test(request);
35162
35179
  // HTML Proxy Caches are stored by config -> filePath -> index
@@ -35719,21 +35736,21 @@ function preImportMapHook(config) {
35719
35736
  const importMapIndex = html.match(importMapRE)?.index;
35720
35737
  if (importMapIndex === undefined)
35721
35738
  return;
35722
- const moduleScriptIndex = html.match(moduleScriptRE)?.index;
35723
- if (moduleScriptIndex === undefined)
35739
+ const importMapAppendIndex = html.match(importMapAppendRE)?.index;
35740
+ if (importMapAppendIndex === undefined)
35724
35741
  return;
35725
- if (moduleScriptIndex < importMapIndex) {
35742
+ if (importMapAppendIndex < importMapIndex) {
35726
35743
  const relativeHtml = normalizePath$3(path$o.relative(config.root, ctx.filename));
35727
- config.logger.warnOnce(picocolorsExports.yellow(picocolorsExports.bold(`(!) <script type="importmap"> should come before <script type="module"> in /${relativeHtml}`)));
35744
+ config.logger.warnOnce(picocolorsExports.yellow(picocolorsExports.bold(`(!) <script type="importmap"> should come before <script type="module"> and <link rel="modulepreload"> in /${relativeHtml}`)));
35728
35745
  }
35729
35746
  };
35730
35747
  }
35731
35748
  /**
35732
- * Move importmap before the first module script
35749
+ * Move importmap before the first module script and modulepreload link
35733
35750
  */
35734
35751
  function postImportMapHook() {
35735
35752
  return (html) => {
35736
- if (!moduleScriptRE.test(html))
35753
+ if (!importMapAppendRE.test(html))
35737
35754
  return;
35738
35755
  let importMap;
35739
35756
  html = html.replace(importMapRE, (match) => {
@@ -35741,7 +35758,7 @@ function postImportMapHook() {
35741
35758
  return '';
35742
35759
  });
35743
35760
  if (importMap) {
35744
- html = html.replace(moduleScriptRE, (match) => `${importMap}\n${match}`);
35761
+ html = html.replace(importMapAppendRE, (match) => `${importMap}\n${match}`);
35745
35762
  }
35746
35763
  return html;
35747
35764
  };
@@ -36297,6 +36314,15 @@ function cssPostPlugin(config) {
36297
36314
  }
36298
36315
  return null;
36299
36316
  },
36317
+ augmentChunkHash(chunk) {
36318
+ if (chunk.viteMetadata?.importedCss.size) {
36319
+ let hash = '';
36320
+ for (const id of chunk.viteMetadata.importedCss) {
36321
+ hash += id;
36322
+ }
36323
+ return hash;
36324
+ }
36325
+ },
36300
36326
  async generateBundle(opts, bundle) {
36301
36327
  // @ts-expect-error asset emits are skipped in legacy bundle
36302
36328
  if (opts.__vite_skip_asset_emit__) {
@@ -36500,7 +36526,7 @@ async function compileCSS(id, code, config, urlReplacer) {
36500
36526
  }));
36501
36527
  }
36502
36528
  if (isModule) {
36503
- postcssPlugins.unshift((await import('./dep-80491704.js').then(function (n) { return n.i; })).default({
36529
+ postcssPlugins.unshift((await import('./dep-3049ac5d.js').then(function (n) { return n.i; })).default({
36504
36530
  ...modulesOptions,
36505
36531
  localsConvention: modulesOptions?.localsConvention,
36506
36532
  getJSON(cssFileName, _modules, outputFileName) {
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { A as picocolorsExports, B as bindShortcuts, w as createLogger, h as resolveConfig } from './chunks/dep-0bae2027.js';
5
+ import { A as picocolorsExports, B as bindShortcuts, w as createLogger, h as resolveConfig } from './chunks/dep-5e7f419b.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:url';
8
8
  import 'node:module';
@@ -724,7 +724,7 @@ cli
724
724
  filterDuplicateOptions(options);
725
725
  // output structure is preserved even after bundling so require()
726
726
  // is ok here
727
- const { createServer } = await import('./chunks/dep-0bae2027.js').then(function (n) { return n.F; });
727
+ const { createServer } = await import('./chunks/dep-5e7f419b.js').then(function (n) { return n.F; });
728
728
  try {
729
729
  const server = await createServer({
730
730
  root,
@@ -802,7 +802,7 @@ cli
802
802
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
803
803
  .action(async (root, options) => {
804
804
  filterDuplicateOptions(options);
805
- const { build } = await import('./chunks/dep-0bae2027.js').then(function (n) { return n.E; });
805
+ const { build } = await import('./chunks/dep-5e7f419b.js').then(function (n) { return n.E; });
806
806
  const buildOptions = cleanOptions(options);
807
807
  try {
808
808
  await build({
@@ -830,7 +830,7 @@ cli
830
830
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
831
831
  .action(async (root, options) => {
832
832
  filterDuplicateOptions(options);
833
- const { optimizeDeps } = await import('./chunks/dep-0bae2027.js').then(function (n) { return n.D; });
833
+ const { optimizeDeps } = await import('./chunks/dep-5e7f419b.js').then(function (n) { return n.D; });
834
834
  try {
835
835
  const config = await resolveConfig({
836
836
  root,
@@ -855,7 +855,7 @@ cli
855
855
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
856
856
  .action(async (root, options) => {
857
857
  filterDuplicateOptions(options);
858
- const { preview } = await import('./chunks/dep-0bae2027.js').then(function (n) { return n.G; });
858
+ const { preview } = await import('./chunks/dep-5e7f419b.js').then(function (n) { return n.G; });
859
859
  try {
860
860
  const server = await preview({
861
861
  root,
@@ -1,4 +1,4 @@
1
- export { b as build, e as buildErrorMessage, u as createFilter, w as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, j as getDepOptimizationConfig, k as isDepsOptimizerEnabled, l as loadConfigFromFile, y as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, i as resolveBaseUrl, h as resolveConfig, z as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, x as searchForWorkspaceRoot, v as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-0bae2027.js';
1
+ export { b as build, e as buildErrorMessage, u as createFilter, w as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, j as getDepOptimizationConfig, k as isDepsOptimizerEnabled, l as loadConfigFromFile, y as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, i as resolveBaseUrl, h as resolveConfig, z as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, x as searchForWorkspaceRoot, v as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-5e7f419b.js';
2
2
  export { VERSION as version } from './constants.js';
3
3
  export { version as esbuildVersion } from 'esbuild';
4
4
  export { VERSION as rollupVersion } from 'rollup';
@@ -3478,7 +3478,12 @@ function isFileReadable(filename) {
3478
3478
  isWindows
3479
3479
  ? node_util.promisify(gracefulRemoveDir)
3480
3480
  : function removeDirSync(dir) {
3481
- fs$1.rmSync(dir, { recursive: true, force: true });
3481
+ // when removing `.vite/deps`, if it doesn't exist, nodejs may also remove
3482
+ // other directories within `.vite/`, including `.vite/deps_temp` (bug).
3483
+ // workaround by checking for directory existence before removing for now.
3484
+ if (fs$1.existsSync(dir)) {
3485
+ fs$1.rmSync(dir, { recursive: true, force: true });
3486
+ }
3482
3487
  };
3483
3488
  isWindows ? node_util.promisify(gracefulRename) : fs$1.renameSync;
3484
3489
  function arraify(target) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -75,7 +75,7 @@
75
75
  "@rollup/plugin-alias": "^4.0.2",
76
76
  "@rollup/plugin-commonjs": "^24.0.0",
77
77
  "@rollup/plugin-dynamic-import-vars": "^2.0.1",
78
- "@rollup/plugin-json": "^5.0.2",
78
+ "@rollup/plugin-json": "^6.0.0",
79
79
  "@rollup/plugin-node-resolve": "15.0.1",
80
80
  "@rollup/plugin-typescript": "^10.0.1",
81
81
  "@rollup/pluginutils": "^5.0.2",