vite 4.2.0-beta.2 → 4.2.1

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.

@@ -11565,7 +11565,8 @@ function unwrapId(id) {
11565
11565
  const flattenId = (id) => id
11566
11566
  .replace(/[/:]/g, '_')
11567
11567
  .replace(/\./g, '__')
11568
- .replace(/(\s*>\s*)/g, '___');
11568
+ .replace(/(\s*>\s*)/g, '___')
11569
+ .replace(/#/g, '____');
11569
11570
  const normalizeId = (id) => id.replace(/(\s*>\s*)/g, ' > ');
11570
11571
  //TODO: revisit later to see if the edge case that "compiling using node v12 code to be run in node v16 in the server" is what we intend to support.
11571
11572
  const builtins = new Set([
@@ -11617,11 +11618,11 @@ function resolveFrom(id, basedir, preserveSymlinks = false, ssr = false) {
11617
11618
  * like `resolveFrom` but supports resolving `>` path in `id`,
11618
11619
  * for example: `foo > bar > baz`
11619
11620
  */
11620
- function nestedResolveFrom(id, basedir, preserveSymlinks = false) {
11621
+ function nestedResolveFrom(id, basedir, preserveSymlinks = false, ssr = false) {
11621
11622
  const pkgs = id.split('>').map((pkg) => pkg.trim());
11622
11623
  try {
11623
11624
  for (const pkg of pkgs) {
11624
- basedir = resolveFrom(pkg, basedir, preserveSymlinks);
11625
+ basedir = resolveFrom(pkg, basedir, preserveSymlinks, ssr);
11625
11626
  }
11626
11627
  }
11627
11628
  catch { }
@@ -16023,7 +16024,7 @@ const debug$e = createDebugger('vite:sourcemap', {
16023
16024
  // Virtual modules should be prefixed with a null byte to avoid a
16024
16025
  // false positive "missing source" warning. We also check for certain
16025
16026
  // prefixes used for special handling in esbuildDepPlugin.
16026
- const virtualSourceRE = /^(?:\0|dep:|browser-external:)/;
16027
+ const virtualSourceRE = /^(?:dep:|browser-external:|virtual:)|\0/;
16027
16028
  async function injectSourcesContent(map, file, logger) {
16028
16029
  let sourceRoot;
16029
16030
  try {
@@ -22465,18 +22466,31 @@ function webWorkerPlugin(config) {
22465
22466
  getDepsOptimizer(config, ssr)?.registerWorkersSource(id);
22466
22467
  if (query.inline != null) {
22467
22468
  const chunk = await bundleWorkerEntry(config, id, query);
22468
- // inline as blob data url
22469
+ const encodedJs = `const encodedJs = "${Buffer.from(chunk.code).toString('base64')}";`;
22470
+ const code =
22471
+ // Using blob URL for SharedWorker results in multiple instances of a same worker
22472
+ workerConstructor === 'Worker'
22473
+ ? `${encodedJs}
22474
+ const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
22475
+ export default function WorkerWrapper() {
22476
+ let objURL;
22477
+ try {
22478
+ objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
22479
+ if (!objURL) throw ''
22480
+ return new ${workerConstructor}(objURL)
22481
+ } catch(e) {
22482
+ return new ${workerConstructor}("data:application/javascript;base64," + encodedJs${workerOptions});
22483
+ } finally {
22484
+ objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
22485
+ }
22486
+ }`
22487
+ : `${encodedJs}
22488
+ export default function WorkerWrapper() {
22489
+ return new ${workerConstructor}("data:application/javascript;base64," + encodedJs${workerOptions});
22490
+ }
22491
+ `;
22469
22492
  return {
22470
- code: `const encodedJs = "${Buffer.from(chunk.code).toString('base64')}";
22471
- const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
22472
- export default function WorkerWrapper() {
22473
- const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
22474
- try {
22475
- return objURL ? new ${workerConstructor}(objURL) : new ${workerConstructor}("data:application/javascript;base64," + encodedJs${workerOptions});
22476
- } finally {
22477
- objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
22478
- }
22479
- }`,
22493
+ code,
22480
22494
  // Empty sourcemap to suppress Rollup warning
22481
22495
  map: { mappings: '' },
22482
22496
  };
@@ -22589,7 +22603,14 @@ function resolvePlugin(resolveOptions) {
22589
22603
  if (!pkgJsonPath)
22590
22604
  return;
22591
22605
  const pkgData = loadPackageData(pkgJsonPath, options.preserveSymlinks);
22592
- return resolveExportsOrImports(pkgData.data, id, options, targetWeb, 'imports');
22606
+ let importsPath = resolveExportsOrImports(pkgData.data, id, options, targetWeb, 'imports');
22607
+ if (importsPath?.startsWith('.')) {
22608
+ importsPath = path$o.relative(basedir, path$o.join(path$o.dirname(pkgJsonPath), importsPath));
22609
+ if (!importsPath.startsWith('.')) {
22610
+ importsPath = `./${importsPath}`;
22611
+ }
22612
+ }
22613
+ return importsPath;
22593
22614
  };
22594
22615
  const resolvedImports = resolveSubpathImports(id, importer);
22595
22616
  if (resolvedImports) {
@@ -22892,22 +22913,15 @@ function tryResolveFile(file, postfix, options, tryIndex, targetWeb, tryPrefix,
22892
22913
  }
22893
22914
  }
22894
22915
  const idToPkgMap = new Map();
22895
- function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, externalize, allowLinkedExternal = true) {
22916
+ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr = false, externalize, allowLinkedExternal = true) {
22896
22917
  const { root, dedupe, isBuild, preserveSymlinks, packageCache } = options;
22897
- ssr ?? (ssr = false);
22898
- // split id by last '>' for nested selected packages, for example:
22899
- // 'foo > bar > baz' => 'foo > bar' & 'baz'
22900
- // 'foo' => '' & 'foo'
22901
- const lastArrowIndex = id.lastIndexOf('>');
22902
- const nestedRoot = id.substring(0, lastArrowIndex).trim();
22903
- const nestedPath = id.substring(lastArrowIndex + 1).trim();
22904
22918
  const possiblePkgIds = [];
22905
22919
  for (let prevSlashIndex = -1;;) {
22906
- let slashIndex = nestedPath.indexOf('/', prevSlashIndex + 1);
22920
+ let slashIndex = id.indexOf('/', prevSlashIndex + 1);
22907
22921
  if (slashIndex < 0) {
22908
- slashIndex = nestedPath.length;
22922
+ slashIndex = id.length;
22909
22923
  }
22910
- const part = nestedPath.slice(prevSlashIndex + 1, (prevSlashIndex = slashIndex));
22924
+ const part = id.slice(prevSlashIndex + 1, (prevSlashIndex = slashIndex));
22911
22925
  if (!part) {
22912
22926
  break;
22913
22927
  }
@@ -22918,7 +22932,7 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
22918
22932
  if (possiblePkgIds.length ? path$o.extname(part) : part[0] === '@') {
22919
22933
  continue;
22920
22934
  }
22921
- const possiblePkgId = nestedPath.slice(0, slashIndex);
22935
+ const possiblePkgId = id.slice(0, slashIndex);
22922
22936
  possiblePkgIds.push(possiblePkgId);
22923
22937
  }
22924
22938
  let basedir;
@@ -22933,10 +22947,6 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
22933
22947
  else {
22934
22948
  basedir = root;
22935
22949
  }
22936
- // nested node module, step-by-step resolve to the basedir of the nestedPath
22937
- if (nestedRoot) {
22938
- basedir = nestedResolveFrom(nestedRoot, basedir, preserveSymlinks);
22939
- }
22940
22950
  let pkg;
22941
22951
  let pkgId;
22942
22952
  // nearest package.json
@@ -22959,19 +22969,19 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
22959
22969
  // if import can't be found, check if it's an optional peer dep.
22960
22970
  // if so, we can resolve to a special id that errors only when imported.
22961
22971
  if (basedir !== root && // root has no peer dep
22962
- !isBuiltin(nestedPath) &&
22963
- !nestedPath.includes('\0') &&
22964
- bareImportRE.test(nestedPath)) {
22972
+ !isBuiltin(id) &&
22973
+ !id.includes('\0') &&
22974
+ bareImportRE.test(id)) {
22965
22975
  // find package.json with `name` as main
22966
22976
  const mainPackageJson = lookupFile(basedir, ['package.json'], {
22967
22977
  predicate: (content) => !!JSON.parse(content).name,
22968
22978
  });
22969
22979
  if (mainPackageJson) {
22970
22980
  const mainPkg = JSON.parse(mainPackageJson);
22971
- if (mainPkg.peerDependencies?.[nestedPath] &&
22972
- mainPkg.peerDependenciesMeta?.[nestedPath]?.optional) {
22981
+ if (mainPkg.peerDependencies?.[id] &&
22982
+ mainPkg.peerDependenciesMeta?.[id]?.optional) {
22973
22983
  return {
22974
- id: `${optionalPeerDepId}:${nestedPath}:${mainPkg.name}`,
22984
+ id: `${optionalPeerDepId}:${id}:${mainPkg.name}`,
22975
22985
  };
22976
22986
  }
22977
22987
  }
@@ -22980,10 +22990,10 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
22980
22990
  }
22981
22991
  let resolveId = resolvePackageEntry;
22982
22992
  let unresolvedId = pkgId;
22983
- const isDeepImport = unresolvedId !== nestedPath;
22993
+ const isDeepImport = unresolvedId !== id;
22984
22994
  if (isDeepImport) {
22985
22995
  resolveId = resolveDeepImport;
22986
- unresolvedId = '.' + nestedPath.slice(pkgId.length);
22996
+ unresolvedId = '.' + id.slice(pkgId.length);
22987
22997
  }
22988
22998
  let resolved;
22989
22999
  try {
@@ -23064,16 +23074,14 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
23064
23074
  const skipOptimization = !isJsType ||
23065
23075
  importer?.includes('node_modules') ||
23066
23076
  exclude?.includes(pkgId) ||
23067
- exclude?.includes(nestedPath) ||
23077
+ exclude?.includes(id) ||
23068
23078
  SPECIAL_QUERY_RE.test(resolved) ||
23069
23079
  // During dev SSR, we don't have a way to reload the module graph if
23070
23080
  // a non-optimized dep is found. So we need to skip optimization here.
23071
23081
  // The only optimized deps are the ones explicitly listed in the config.
23072
23082
  (!options.ssrOptimizeCheck && !isBuild && ssr) ||
23073
23083
  // Only optimize non-external CJS deps during SSR by default
23074
- (ssr &&
23075
- !isCJS &&
23076
- !(include?.includes(pkgId) || include?.includes(nestedPath)));
23084
+ (ssr && !isCJS && !(include?.includes(pkgId) || include?.includes(id)));
23077
23085
  if (options.ssrOptimizeCheck) {
23078
23086
  return {
23079
23087
  id: skipOptimization
@@ -37079,7 +37087,7 @@ function handleParseError(parserError, html, filePath) {
37079
37087
  function buildHtmlPlugin(config) {
37080
37088
  const [preHooks, normalHooks, postHooks] = resolveHtmlTransforms(config.plugins);
37081
37089
  preHooks.unshift(preImportMapHook(config));
37082
- normalHooks.unshift(htmlEnvHook(config));
37090
+ preHooks.push(htmlEnvHook(config));
37083
37091
  postHooks.push(postImportMapHook());
37084
37092
  const processedHtml = new Map();
37085
37093
  const isExcludedUrl = (url) => url.startsWith('#') ||
@@ -37904,7 +37912,9 @@ function cssPostPlugin(config) {
37904
37912
  const getContentWithSourcemap = async (content) => {
37905
37913
  if (config.css?.devSourcemap) {
37906
37914
  const sourcemap = this.getCombinedSourcemap();
37907
- await injectSourcesContent(sourcemap, cleanUrl(id), config.logger);
37915
+ if (sourcemap.mappings && !sourcemap.sourcesContent) {
37916
+ await injectSourcesContent(sourcemap, cleanUrl(id), config.logger);
37917
+ }
37908
37918
  return getCodeWithSourcemap('css', content, sourcemap);
37909
37919
  }
37910
37920
  return content;
@@ -38311,7 +38321,7 @@ async function compileCSS(id, code, config, urlReplacer) {
38311
38321
  }));
38312
38322
  }
38313
38323
  if (isModule) {
38314
- postcssPlugins.unshift((await import('./dep-80b98891.js').then(function (n) { return n.i; })).default({
38324
+ postcssPlugins.unshift((await import('./dep-f63b56ae.js').then(function (n) { return n.i; })).default({
38315
38325
  ...modulesOptions,
38316
38326
  localsConvention: modulesOptions?.localsConvention,
38317
38327
  getJSON(cssFileName, _modules, outputFileName) {
@@ -44877,18 +44887,13 @@ async function addManuallyIncludedOptimizeDeps(deps, config, ssr, extra = [], fi
44877
44887
  logger.warn(`${msg}: ${picocolorsExports.cyan(id)}, present in '${ssr ? 'ssr.' : ''}optimizeDeps.include'`);
44878
44888
  }
44879
44889
  };
44880
- const resolve = config.createResolver({
44881
- asSrc: false,
44882
- scan: true,
44883
- ssrOptimizeCheck: ssr,
44884
- ssrConfig: config.ssr,
44885
- });
44890
+ const resolve = createOptimizeDepsIncludeResolver(config, ssr);
44886
44891
  for (const id of [...optimizeDepsInclude, ...extra]) {
44887
44892
  // normalize 'foo >bar` as 'foo > bar' to prevent same id being added
44888
44893
  // and for pretty printing
44889
44894
  const normalizedId = normalizeId(id);
44890
44895
  if (!deps[normalizedId] && filter?.(normalizedId) !== false) {
44891
- const entry = await resolve(id, undefined, undefined, ssr);
44896
+ const entry = await resolve(id);
44892
44897
  if (entry) {
44893
44898
  if (isOptimizable(entry, optimizeDeps)) {
44894
44899
  if (!entry.endsWith('?__vite_skip_optimization')) {
@@ -44906,6 +44911,26 @@ async function addManuallyIncludedOptimizeDeps(deps, config, ssr, extra = [], fi
44906
44911
  }
44907
44912
  }
44908
44913
  }
44914
+ function createOptimizeDepsIncludeResolver(config, ssr) {
44915
+ const resolve = config.createResolver({
44916
+ asSrc: false,
44917
+ scan: true,
44918
+ ssrOptimizeCheck: ssr,
44919
+ ssrConfig: config.ssr,
44920
+ });
44921
+ return async (id) => {
44922
+ const lastArrowIndex = id.lastIndexOf('>');
44923
+ if (lastArrowIndex === -1) {
44924
+ return await resolve(id, undefined, undefined, ssr);
44925
+ }
44926
+ // split nested selected id by last '>', for example:
44927
+ // 'foo > bar > baz' => 'foo > bar' & 'baz'
44928
+ const nestedRoot = id.substring(0, lastArrowIndex).trim();
44929
+ const nestedPath = id.substring(lastArrowIndex + 1).trim();
44930
+ const basedir = nestedResolveFrom(nestedRoot, config.root, config.resolve.preserveSymlinks, ssr);
44931
+ return await resolve(nestedPath, basedir, undefined, ssr);
44932
+ };
44933
+ }
44909
44934
  function newDepOptimizationProcessing() {
44910
44935
  let resolve;
44911
44936
  const promise = new Promise((_resolve) => {
@@ -45212,8 +45237,9 @@ async function cleanupDepsCacheStaleDirs(config) {
45212
45237
  for (const dirent of dirents) {
45213
45238
  if (dirent.isDirectory() && dirent.name.includes('_temp_')) {
45214
45239
  const tempDirPath = path$o.resolve(config.cacheDir, dirent.name);
45215
- const { mtime } = await fsp.stat(tempDirPath);
45216
- if (Date.now() - mtime.getTime() > MAX_TEMP_DIR_AGE_MS) {
45240
+ const stats = await fsp.stat(tempDirPath).catch((_) => null);
45241
+ if (stats?.mtime &&
45242
+ Date.now() - stats.mtime.getTime() > MAX_TEMP_DIR_AGE_MS) {
45217
45243
  await removeDir(tempDirPath);
45218
45244
  }
45219
45245
  }
@@ -61136,6 +61162,7 @@ function transformMiddleware(server) {
61136
61162
  // Skip if response has already been sent
61137
61163
  if (!res.writableEnded) {
61138
61164
  res.statusCode = 504; // status code request timeout
61165
+ res.statusMessage = 'Optimize Deps Processing Error';
61139
61166
  res.end();
61140
61167
  }
61141
61168
  // This timeout is unexpected
@@ -61146,6 +61173,7 @@ function transformMiddleware(server) {
61146
61173
  // Skip if response has already been sent
61147
61174
  if (!res.writableEnded) {
61148
61175
  res.statusCode = 504; // status code request timeout
61176
+ res.statusMessage = 'Outdated Optimize Dep';
61149
61177
  res.end();
61150
61178
  }
61151
61179
  // We don't need to log an error in this case, the request
@@ -63100,7 +63128,6 @@ async function restartServer(server) {
63100
63128
  const { port: prevPort, host: prevHost } = server.config.server;
63101
63129
  const shortcutsOptions = server._shortcutsOptions;
63102
63130
  const oldUrls = server.resolvedUrls;
63103
- await server.close();
63104
63131
  let inlineConfig = server.config.inlineConfig;
63105
63132
  if (server._forceOptimizeOnRestart) {
63106
63133
  inlineConfig = mergeConfig(inlineConfig, {
@@ -63117,8 +63144,10 @@ async function restartServer(server) {
63117
63144
  server.config.logger.error(err.message, {
63118
63145
  timestamp: true,
63119
63146
  });
63147
+ server.config.logger.error('server restart failed', { timestamp: true });
63120
63148
  return;
63121
63149
  }
63150
+ await server.close();
63122
63151
  // prevent new server `restart` function from calling
63123
63152
  newServer._restartPromise = server._restartPromise;
63124
63153
  Object.assign(server, newServer);
@@ -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-84d7cc5e.js';
3
+ import { C as commonjsGlobal } from './dep-79892de8.js';
4
4
  import require$$0$1 from 'path';
5
5
  import require$$5 from 'crypto';
6
6
  import require$$0$2 from 'util';
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-84d7cc5e.js';
5
+ import { A as picocolorsExports, B as bindShortcuts, w as createLogger, h as resolveConfig } from './chunks/dep-79892de8.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:url';
8
8
  import 'node:module';
@@ -729,7 +729,7 @@ cli
729
729
  filterDuplicateOptions(options);
730
730
  // output structure is preserved even after bundling so require()
731
731
  // is ok here
732
- const { createServer } = await import('./chunks/dep-84d7cc5e.js').then(function (n) { return n.F; });
732
+ const { createServer } = await import('./chunks/dep-79892de8.js').then(function (n) { return n.F; });
733
733
  try {
734
734
  const server = await createServer({
735
735
  root,
@@ -807,7 +807,7 @@ cli
807
807
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
808
808
  .action(async (root, options) => {
809
809
  filterDuplicateOptions(options);
810
- const { build } = await import('./chunks/dep-84d7cc5e.js').then(function (n) { return n.E; });
810
+ const { build } = await import('./chunks/dep-79892de8.js').then(function (n) { return n.E; });
811
811
  const buildOptions = cleanOptions(options);
812
812
  try {
813
813
  await build({
@@ -835,7 +835,7 @@ cli
835
835
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
836
836
  .action(async (root, options) => {
837
837
  filterDuplicateOptions(options);
838
- const { optimizeDeps } = await import('./chunks/dep-84d7cc5e.js').then(function (n) { return n.D; });
838
+ const { optimizeDeps } = await import('./chunks/dep-79892de8.js').then(function (n) { return n.D; });
839
839
  try {
840
840
  const config = await resolveConfig({
841
841
  root,
@@ -860,7 +860,7 @@ cli
860
860
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
861
861
  .action(async (root, options) => {
862
862
  filterDuplicateOptions(options);
863
- const { preview } = await import('./chunks/dep-84d7cc5e.js').then(function (n) { return n.G; });
863
+ const { preview } = await import('./chunks/dep-79892de8.js').then(function (n) { return n.G; });
864
864
  try {
865
865
  const server = await preview({
866
866
  root,
@@ -2502,7 +2502,7 @@ export declare interface UserConfig {
2502
2502
  clearScreen?: boolean;
2503
2503
  /**
2504
2504
  * Environment files directory. Can be an absolute path, or a path relative from
2505
- * the location of the config file itself.
2505
+ * root.
2506
2506
  * @default root
2507
2507
  */
2508
2508
  envDir?: string;
@@ -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-84d7cc5e.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-79892de8.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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "4.2.0-beta.2",
3
+ "version": "4.2.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",