vite 5.0.0-beta.3 → 5.0.0-beta.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.
@@ -12291,9 +12291,9 @@ function windowsSafeRealPathSync(path) {
12291
12291
  return fs$l.realpathSync(path);
12292
12292
  }
12293
12293
  function optimizeSafeRealPathSync() {
12294
- // Skip if using Node <16.18 due to MAX_PATH issue: https://github.com/vitejs/vite/issues/12931
12294
+ // Skip if using Node <18.10 due to MAX_PATH issue: https://github.com/vitejs/vite/issues/12931
12295
12295
  const nodeVersion = process.versions.node.split('.').map(Number);
12296
- if (nodeVersion[0] < 16 || (nodeVersion[0] === 16 && nodeVersion[1] < 18)) {
12296
+ if (nodeVersion[0] < 18 || (nodeVersion[0] === 18 && nodeVersion[1] < 10)) {
12297
12297
  safeRealpathSync = fs$l.realpathSync;
12298
12298
  return;
12299
12299
  }
@@ -14721,11 +14721,14 @@ const loadTerserPath = (root) => {
14721
14721
  return terserPath;
14722
14722
  };
14723
14723
  function terserPlugin(config) {
14724
+ const { maxWorkers, ...terserOptions } = config.build.terserOptions;
14724
14725
  const makeWorker = () => new Worker_1(async (terserPath, code, options) => {
14725
14726
  // test fails when using `import`. maybe related: https://github.com/nodejs/node/issues/43205
14726
14727
  // eslint-disable-next-line no-restricted-globals -- this function runs inside cjs
14727
14728
  const terser = require(terserPath);
14728
14729
  return terser.minify(code, options);
14730
+ }, {
14731
+ max: maxWorkers,
14729
14732
  });
14730
14733
  let worker;
14731
14734
  return {
@@ -14749,7 +14752,7 @@ function terserPlugin(config) {
14749
14752
  const terserPath = loadTerserPath(config.root);
14750
14753
  const res = await worker.run(terserPath, code, {
14751
14754
  safari10: true,
14752
- ...config.build.terserOptions,
14755
+ ...terserOptions,
14753
14756
  sourceMap: !!outputOptions.sourcemap,
14754
14757
  module: outputOptions.format.startsWith('es'),
14755
14758
  toplevel: outputOptions.format === 'cjs',
@@ -28821,8 +28824,10 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr = f
28821
28824
  bareImportRE.test(id)) {
28822
28825
  const mainPkg = findNearestMainPackageData(basedir, packageCache)?.data;
28823
28826
  if (mainPkg) {
28824
- if (mainPkg.peerDependencies?.[id] &&
28825
- mainPkg.peerDependenciesMeta?.[id]?.optional) {
28827
+ const pkgName = getNpmPackageName(id);
28828
+ if (pkgName != null &&
28829
+ mainPkg.peerDependencies?.[pkgName] &&
28830
+ mainPkg.peerDependenciesMeta?.[pkgName]?.optional) {
28826
28831
  return {
28827
28832
  id: `${optionalPeerDepId}:${id}:${mainPkg.name}`,
28828
28833
  };
@@ -37111,7 +37116,7 @@ function _stripLiteralAcorn(code, options) {
37111
37116
 
37112
37117
  const multilineCommentsRE = /\/\*([^*\/])*?\*\//gms;
37113
37118
  const singlelineCommentsRE = /(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/gm;
37114
- const templateLiteralRE = /\$\{(\s*(?:|{.*}|(?!\$\{).|\n|\r)*?\s*)\}/g;
37119
+ const templateLiteralRE$1 = /\$\{(\s*(?:|{.*}|(?!\$\{).|\n|\r)*?\s*)\}/g;
37115
37120
  const quotesRE = [
37116
37121
  /(["'`])((?:\\\1|(?!\1)|.|\r)*?)\1/gm,
37117
37122
  /([`])((?:\\\1|(?!\1)|.|\n|\r)*?)\1/gm
@@ -37125,7 +37130,7 @@ function stripLiteralRegex(code, options) {
37125
37130
  let expanded = code;
37126
37131
  for (let i = 0; i < 16; i++) {
37127
37132
  const before = expanded;
37128
- expanded = expanded.replace(templateLiteralRE, "` $1`");
37133
+ expanded = expanded.replace(templateLiteralRE$1, "` $1`");
37129
37134
  if (expanded === before)
37130
37135
  break;
37131
37136
  }
@@ -37635,6 +37640,14 @@ function expand (config) {
37635
37640
 
37636
37641
  var expand_1 = expand;
37637
37642
 
37643
+ function getEnvFilesForMode(mode) {
37644
+ return [
37645
+ /** default file */ `.env`,
37646
+ /** local file */ `.env.local`,
37647
+ /** mode file */ `.env.${mode}`,
37648
+ /** mode local file */ `.env.${mode}.local`,
37649
+ ];
37650
+ }
37638
37651
  function loadEnv(mode, envDir, prefixes = 'VITE_') {
37639
37652
  if (mode === 'local') {
37640
37653
  throw new Error(`"local" cannot be used as a mode name because it conflicts with ` +
@@ -37642,12 +37655,7 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
37642
37655
  }
37643
37656
  prefixes = arraify(prefixes);
37644
37657
  const env = {};
37645
- const envFiles = [
37646
- /** default file */ `.env`,
37647
- /** local file */ `.env.local`,
37648
- /** mode file */ `.env.${mode}`,
37649
- /** mode local file */ `.env.${mode}.local`,
37650
- ];
37658
+ const envFiles = getEnvFilesForMode(mode);
37651
37659
  const parsed = Object.fromEntries(envFiles.flatMap((file) => {
37652
37660
  const filePath = path$o.join(envDir, file);
37653
37661
  if (!tryStatSync(filePath)?.isFile())
@@ -39399,8 +39407,8 @@ function createCachedImport(imp) {
39399
39407
  return cached;
39400
39408
  };
39401
39409
  }
39402
- const importPostcssImport = createCachedImport(() => import('./dep-68c42983.js').then(function (n) { return n.i; }));
39403
- const importPostcssModules = createCachedImport(() => import('./dep-9586b1f1.js').then(function (n) { return n.i; }));
39410
+ const importPostcssImport = createCachedImport(() => import('./dep-a86a117b.js').then(function (n) { return n.i; }));
39411
+ const importPostcssModules = createCachedImport(() => import('./dep-ae1dfb84.js').then(function (n) { return n.i; }));
39404
39412
  const importPostcss = createCachedImport(() => import('postcss'));
39405
39413
  /**
39406
39414
  * @experimental
@@ -41716,7 +41724,7 @@ async function handleHMRUpdate(file, server, configOnly) {
41716
41724
  const isConfig = file === config.configFile;
41717
41725
  const isConfigDependency = config.configFileDependencies.some((name) => file === name);
41718
41726
  const isEnv = config.inlineConfig.envFile !== false &&
41719
- (fileName === '.env' || fileName.startsWith('.env.'));
41727
+ getEnvFilesForMode(config.mode).includes(fileName);
41720
41728
  if (isConfig || isConfigDependency || isEnv) {
41721
41729
  // auto restart server
41722
41730
  debugHmr?.(`[config change] ${colors$1.dim(shortFile)}`);
@@ -42098,6 +42106,7 @@ const hasImportInQueryParamsRE = /[?&]import=?\b/;
42098
42106
  const hasViteIgnoreRE = /\/\*\s*@vite-ignore\s*\*\//;
42099
42107
  const cleanUpRawUrlRE = /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm;
42100
42108
  const urlIsStringRE = /^(?:'.*'|".*"|`.*`)$/;
42109
+ const templateLiteralRE = /^\s*`(.*)`\s*$/;
42101
42110
  function isExplicitImportRequired(url) {
42102
42111
  return !isJSRequest(cleanUrl(url)) && !isCSSRequest(url);
42103
42112
  }
@@ -42255,7 +42264,6 @@ function importAnalysisPlugin(config) {
42255
42264
  let needQueryInjectHelper = false;
42256
42265
  let s;
42257
42266
  const str = () => s || (s = new MagicString(source));
42258
- const importedUrls = new Set();
42259
42267
  let isPartiallySelfAccepting = false;
42260
42268
  const importedBindings = enablePartialAccept
42261
42269
  ? new Map()
@@ -42356,13 +42364,14 @@ function importAnalysisPlugin(config) {
42356
42364
  }
42357
42365
  return [url, resolved.id];
42358
42366
  };
42367
+ const orderedImportedUrls = new Array(imports.length);
42359
42368
  const orderedAcceptedUrls = new Array(imports.length);
42360
42369
  const orderedAcceptedExports = new Array(imports.length);
42361
42370
  await Promise.all(imports.map(async (importSpecifier, index) => {
42362
- const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex,
42371
+ const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex, a: assertIndex, } = importSpecifier;
42363
42372
  // #2083 User may use escape path,
42364
42373
  // so use imports[index].n to get the unescaped string
42365
- n: specifier, a: assertIndex, } = importSpecifier;
42374
+ let specifier = importSpecifier.n;
42366
42375
  const rawUrl = source.slice(start, end);
42367
42376
  // check import.meta usage
42368
42377
  if (rawUrl === 'import.meta') {
@@ -42392,6 +42401,15 @@ function importAnalysisPlugin(config) {
42392
42401
  }
42393
42402
  return;
42394
42403
  }
42404
+ else if (templateLiteralRE.test(rawUrl)) {
42405
+ // If the import has backticks but isn't transformed as a glob import
42406
+ // (as there's nothing to glob), check if it's simply a plain string.
42407
+ // If so, we can replace the specifier as a plain string to prevent
42408
+ // an incorrect "cannot be analyzed" warning.
42409
+ if (!(rawUrl.includes('${') && rawUrl.includes('}'))) {
42410
+ specifier = rawUrl.replace(templateLiteralRE, '$1');
42411
+ }
42412
+ }
42395
42413
  const isDynamicImport = dynamicIndex > -1;
42396
42414
  // strip import assertions as we can process them ourselves
42397
42415
  if (!isDynamicImport && assertIndex > -1) {
@@ -42479,7 +42497,7 @@ function importAnalysisPlugin(config) {
42479
42497
  const hmrUrl = unwrapId(stripBase(url, base));
42480
42498
  const isLocalImport = !isExternalUrl(hmrUrl) && !isDataUrl(hmrUrl);
42481
42499
  if (isLocalImport) {
42482
- importedUrls.add(hmrUrl);
42500
+ orderedImportedUrls[index] = hmrUrl;
42483
42501
  }
42484
42502
  if (enablePartialAccept && importedBindings) {
42485
42503
  extractImportedBindings(resolvedId, source, importSpecifier, importedBindings);
@@ -42530,6 +42548,7 @@ function importAnalysisPlugin(config) {
42530
42548
  }
42531
42549
  }
42532
42550
  }));
42551
+ const importedUrls = new Set(orderedImportedUrls.filter(Boolean));
42533
42552
  const acceptedUrls = mergeAcceptedUrls(orderedAcceptedUrls);
42534
42553
  const acceptedExports = mergeAcceptedUrls(orderedAcceptedExports);
42535
42554
  if (hasEnv) {
@@ -64885,11 +64904,16 @@ function htmlFallbackMiddleware(root, spaFallback) {
64885
64904
  return spaFallback ? `/index.html` : request.url;
64886
64905
  },
64887
64906
  },
64888
- // don't rewrite paths ending with .html
64889
64907
  {
64890
64908
  from: /\.html$/,
64891
- to({ request }) {
64892
- return request.url;
64909
+ to({ parsedUrl, request }) {
64910
+ // .html files are not handled by serveStaticMiddleware
64911
+ // so we need to check if the file exists
64912
+ const pathname = decodeURIComponent(parsedUrl.pathname);
64913
+ if (fs$l.existsSync(path$o.join(root, pathname))) {
64914
+ return request.url;
64915
+ }
64916
+ return spaFallback ? `/index.html` : request.url;
64893
64917
  },
64894
64918
  },
64895
64919
  ],
@@ -66273,6 +66297,7 @@ async function preview(inlineConfig = {}) {
66273
66297
  etag: true,
66274
66298
  dev: true,
66275
66299
  single: config.appType === 'spa',
66300
+ ignores: false,
66276
66301
  setHeaders(res) {
66277
66302
  if (headers) {
66278
66303
  for (const name in headers) {
@@ -66403,6 +66428,10 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
66403
66428
  allowClearScreen: config.clearScreen,
66404
66429
  customLogger: config.customLogger,
66405
66430
  });
66431
+ let foundDiscouragedVariableName;
66432
+ if ((foundDiscouragedVariableName = Object.keys(config.define ?? {}).find((k) => ['process', 'global'].includes(k)))) {
66433
+ logger.warn(colors$1.yellow(`Replacing ${colors$1.bold(foundDiscouragedVariableName)} using the define option is discouraged. See https://vitejs.dev/config/shared-options.html#define for more details.`));
66434
+ }
66406
66435
  // resolve root
66407
66436
  const resolvedRoot = normalizePath$3(config.root ? path$o.resolve(config.root) : process.cwd());
66408
66437
  if (resolvedRoot.includes('#')) {
@@ -1,4 +1,4 @@
1
- import { D as getDefaultExportFromCjs } from './dep-dc9999ab.js';
1
+ import { D as getDefaultExportFromCjs } from './dep-69dc786c.js';
2
2
  import require$$0 from 'path';
3
3
  import require$$0__default from 'fs';
4
4
  import { l as lib } from './dep-c423598f.js';
@@ -1,4 +1,4 @@
1
- import { E as commonjsGlobal, D as getDefaultExportFromCjs } from './dep-dc9999ab.js';
1
+ import { E as commonjsGlobal, D as getDefaultExportFromCjs } from './dep-69dc786c.js';
2
2
  import require$$0__default from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
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 { C as colors, x as createLogger, h as resolveConfig } from './chunks/dep-dc9999ab.js';
5
+ import { C as colors, x as createLogger, h as resolveConfig } from './chunks/dep-69dc786c.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -759,7 +759,7 @@ cli
759
759
  filterDuplicateOptions(options);
760
760
  // output structure is preserved even after bundling so require()
761
761
  // is ok here
762
- const { createServer } = await import('./chunks/dep-dc9999ab.js').then(function (n) { return n.H; });
762
+ const { createServer } = await import('./chunks/dep-69dc786c.js').then(function (n) { return n.H; });
763
763
  try {
764
764
  const server = await createServer({
765
765
  root,
@@ -840,7 +840,7 @@ cli
840
840
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
841
841
  .action(async (root, options) => {
842
842
  filterDuplicateOptions(options);
843
- const { build } = await import('./chunks/dep-dc9999ab.js').then(function (n) { return n.G; });
843
+ const { build } = await import('./chunks/dep-69dc786c.js').then(function (n) { return n.G; });
844
844
  const buildOptions = cleanOptions(options);
845
845
  try {
846
846
  await build({
@@ -868,7 +868,7 @@ cli
868
868
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
869
869
  .action(async (root, options) => {
870
870
  filterDuplicateOptions(options);
871
- const { optimizeDeps } = await import('./chunks/dep-dc9999ab.js').then(function (n) { return n.F; });
871
+ const { optimizeDeps } = await import('./chunks/dep-69dc786c.js').then(function (n) { return n.F; });
872
872
  try {
873
873
  const config = await resolveConfig({
874
874
  root,
@@ -895,7 +895,7 @@ cli
895
895
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
896
896
  .action(async (root, options) => {
897
897
  filterDuplicateOptions(options);
898
- const { preview } = await import('./chunks/dep-dc9999ab.js').then(function (n) { return n.I; });
898
+ const { preview } = await import('./chunks/dep-69dc786c.js').then(function (n) { return n.I; });
899
899
  try {
900
900
  const server = await preview({
901
901
  root,
@@ -225,8 +225,11 @@ export declare interface BuildOptions {
225
225
  /**
226
226
  * Options for terser
227
227
  * https://terser.org/docs/api-reference#minify-options
228
+ *
229
+ * In addition, you can also pass a `maxWorkers: number` option to specify the
230
+ * max number of workers to spawn. Defaults to the number of CPUs minus 1.
228
231
  */
229
- terserOptions?: Terser.MinifyOptions;
232
+ terserOptions?: TerserOptions;
230
233
  /**
231
234
  * Will be merged with internal rollup options.
232
235
  * https://rollupjs.org/configuration-options/
@@ -2465,6 +2468,16 @@ export declare namespace Terser {
2465
2468
  }
2466
2469
  }
2467
2470
 
2471
+ export declare interface TerserOptions extends Terser.MinifyOptions {
2472
+ /**
2473
+ * Vite-specific option to specify the max number of workers to spawn
2474
+ * when minifying files with terser.
2475
+ *
2476
+ * @default number of CPUs minus 1
2477
+ */
2478
+ maxWorkers?: number;
2479
+ }
2480
+
2468
2481
  export declare interface TransformOptions {
2469
2482
  ssr?: boolean;
2470
2483
  html?: boolean;
@@ -1,5 +1,5 @@
1
- import { i as isInNodeModules } from './chunks/dep-dc9999ab.js';
2
- export { b as build, e as buildErrorMessage, v as createFilter, x as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, k as getDepOptimizationConfig, m as isDepsOptimizerEnabled, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, u as mergeAlias, q as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, j as resolveBaseUrl, h as resolveConfig, B as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-dc9999ab.js';
1
+ import { i as isInNodeModules } from './chunks/dep-69dc786c.js';
2
+ export { b as build, e as buildErrorMessage, v as createFilter, x as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, k as getDepOptimizationConfig, m as isDepsOptimizerEnabled, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, u as mergeAlias, q as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, j as resolveBaseUrl, h as resolveConfig, B as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-69dc786c.js';
3
3
  export { VERSION as version } from './constants.js';
4
4
  export { version as esbuildVersion } from 'esbuild';
5
5
  export { VERSION as rollupVersion } from 'rollup';
@@ -5987,6 +5987,14 @@ function expand (config) {
5987
5987
 
5988
5988
  var expand_1 = expand;
5989
5989
 
5990
+ function getEnvFilesForMode(mode) {
5991
+ return [
5992
+ /** default file */ `.env`,
5993
+ /** local file */ `.env.local`,
5994
+ /** mode file */ `.env.${mode}`,
5995
+ /** mode local file */ `.env.${mode}.local`,
5996
+ ];
5997
+ }
5990
5998
  function loadEnv(mode, envDir, prefixes = 'VITE_') {
5991
5999
  if (mode === 'local') {
5992
6000
  throw new Error(`"local" cannot be used as a mode name because it conflicts with ` +
@@ -5994,12 +6002,7 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
5994
6002
  }
5995
6003
  prefixes = arraify(prefixes);
5996
6004
  const env = {};
5997
- const envFiles = [
5998
- /** default file */ `.env`,
5999
- /** local file */ `.env.local`,
6000
- /** mode file */ `.env.${mode}`,
6001
- /** mode local file */ `.env.${mode}.local`,
6002
- ];
6005
+ const envFiles = getEnvFilesForMode(mode);
6003
6006
  const parsed = Object.fromEntries(envFiles.flatMap((file) => {
6004
6007
  const filePath = path$3.join(envDir, file);
6005
6008
  if (!tryStatSync(filePath)?.isFile())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",