vite 5.0.3 → 5.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.
@@ -12955,6 +12955,15 @@ function getPackageManagerCommand(type = 'install') {
12955
12955
  function isDevServer(server) {
12956
12956
  return 'pluginContainer' in server;
12957
12957
  }
12958
+ function promiseWithResolvers() {
12959
+ let resolve;
12960
+ let reject;
12961
+ const promise = new Promise((_resolve, _reject) => {
12962
+ resolve = _resolve;
12963
+ reject = _reject;
12964
+ });
12965
+ return { promise, resolve, reject };
12966
+ }
12958
12967
 
12959
12968
  /* eslint no-console: 0 */
12960
12969
  const LogLevels = {
@@ -17141,11 +17150,6 @@ async function injectSourcesContent(map, file, logger) {
17141
17150
  debug$g?.(`Missing sources:\n ` + missingSources.join(`\n `));
17142
17151
  }
17143
17152
  }
17144
- async function getOriginalContent(filepath) {
17145
- if (virtualSourceRE.test(filepath))
17146
- return undefined;
17147
- return await fsp.readFile(filepath, 'utf-8').catch(() => undefined);
17148
- }
17149
17153
  function genSourceMapUrl(map) {
17150
17154
  if (typeof map !== 'string') {
17151
17155
  map = JSON.stringify(map);
@@ -28986,49 +28990,18 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
28986
28990
  if (data.exports) {
28987
28991
  entryPoint = resolveExportsOrImports(data, '.', options, targetWeb, 'exports');
28988
28992
  }
28989
- // handle edge case with browser and module field semantics
28990
- if (!entryPoint && targetWeb && options.mainFields.includes('browser')) {
28991
- // check browser field
28992
- // https://github.com/defunctzombie/package-browser-field-spec
28993
- const browserEntry = typeof data.browser === 'string'
28994
- ? data.browser
28995
- : isObject$1(data.browser) && data.browser['.'];
28996
- if (browserEntry) {
28997
- // check if the package also has a "module" field.
28998
- if (!options.isRequire &&
28999
- options.mainFields.includes('module') &&
29000
- typeof data.module === 'string' &&
29001
- data.module !== browserEntry) {
29002
- // if both are present, we may have a problem: some package points both
29003
- // to ESM, with "module" targeting Node.js, while some packages points
29004
- // "module" to browser ESM and "browser" to UMD/IIFE.
29005
- // the heuristics here is to actually read the browser entry when
29006
- // possible and check for hints of ESM. If it is not ESM, prefer "module"
29007
- // instead; Otherwise, assume it's ESM and use it.
29008
- const resolvedBrowserEntry = tryFsResolve(path$o.join(dir, browserEntry), options);
29009
- if (resolvedBrowserEntry) {
29010
- const content = fs$l.readFileSync(resolvedBrowserEntry, 'utf-8');
29011
- if (hasESMSyntax(content)) {
29012
- // likely ESM, prefer browser
29013
- entryPoint = browserEntry;
29014
- }
29015
- else {
29016
- // non-ESM, UMD or IIFE or CJS(!!! e.g. firebase 7.x), prefer module
29017
- entryPoint = data.module;
29018
- }
29019
- }
29020
- }
29021
- else {
29022
- entryPoint = browserEntry;
29023
- }
29024
- }
29025
- }
29026
28993
  // fallback to mainFields if still not resolved
29027
28994
  if (!entryPoint) {
29028
28995
  for (const field of options.mainFields) {
29029
- if (field === 'browser')
29030
- continue; // already checked above
29031
- if (typeof data[field] === 'string') {
28996
+ if (field === 'browser') {
28997
+ if (targetWeb) {
28998
+ entryPoint = tryResolveBrowserEntry(dir, data, options);
28999
+ if (entryPoint) {
29000
+ break;
29001
+ }
29002
+ }
29003
+ }
29004
+ else if (typeof data[field] === 'string') {
29032
29005
  entryPoint = data[field];
29033
29006
  break;
29034
29007
  }
@@ -29187,6 +29160,43 @@ function tryResolveBrowserMapping(id, importer, options, isFilePath, externalize
29187
29160
  }
29188
29161
  }
29189
29162
  }
29163
+ function tryResolveBrowserEntry(dir, data, options) {
29164
+ // handle edge case with browser and module field semantics
29165
+ // check browser field
29166
+ // https://github.com/defunctzombie/package-browser-field-spec
29167
+ const browserEntry = typeof data.browser === 'string'
29168
+ ? data.browser
29169
+ : isObject$1(data.browser) && data.browser['.'];
29170
+ if (browserEntry) {
29171
+ // check if the package also has a "module" field.
29172
+ if (!options.isRequire &&
29173
+ options.mainFields.includes('module') &&
29174
+ typeof data.module === 'string' &&
29175
+ data.module !== browserEntry) {
29176
+ // if both are present, we may have a problem: some package points both
29177
+ // to ESM, with "module" targeting Node.js, while some packages points
29178
+ // "module" to browser ESM and "browser" to UMD/IIFE.
29179
+ // the heuristics here is to actually read the browser entry when
29180
+ // possible and check for hints of ESM. If it is not ESM, prefer "module"
29181
+ // instead; Otherwise, assume it's ESM and use it.
29182
+ const resolvedBrowserEntry = tryFsResolve(path$o.join(dir, browserEntry), options);
29183
+ if (resolvedBrowserEntry) {
29184
+ const content = fs$l.readFileSync(resolvedBrowserEntry, 'utf-8');
29185
+ if (hasESMSyntax(content)) {
29186
+ // likely ESM, prefer browser
29187
+ return browserEntry;
29188
+ }
29189
+ else {
29190
+ // non-ESM, UMD or IIFE or CJS(!!! e.g. firebase 7.x), prefer module
29191
+ return data.module;
29192
+ }
29193
+ }
29194
+ }
29195
+ else {
29196
+ return browserEntry;
29197
+ }
29198
+ }
29199
+ }
29190
29200
  /**
29191
29201
  * given a relative path in pkg dir,
29192
29202
  * return a relative path in pkg dir,
@@ -39653,8 +39663,8 @@ function createCachedImport(imp) {
39653
39663
  return cached;
39654
39664
  };
39655
39665
  }
39656
- const importPostcssImport = createCachedImport(() => import('./dep-_rppyaaB.js').then(function (n) { return n.i; }));
39657
- const importPostcssModules = createCachedImport(() => import('./dep-m-h4L35S.js').then(function (n) { return n.i; }));
39666
+ const importPostcssImport = createCachedImport(() => import('./dep-nbvvoiwS.js').then(function (n) { return n.i; }));
39667
+ const importPostcssModules = createCachedImport(() => import('./dep-GiiHpyM6.js').then(function (n) { return n.i; }));
39658
39668
  const importPostcss = createCachedImport(() => import('postcss'));
39659
39669
  /**
39660
39670
  * @experimental
@@ -58388,9 +58398,7 @@ function send(req, res, content, type, options) {
58388
58398
  }
58389
58399
  // inject fallback sourcemap for js for improved debugging
58390
58400
  // https://github.com/vitejs/vite/pull/13514#issuecomment-1592431496
58391
- // for { mappings: "" }, we don't inject fallback sourcemap
58392
- // because it indicates generating a sourcemap is meaningless
58393
- else if (type === 'js' && map == null) {
58401
+ else if (type === 'js' && (!map || map.mappings !== '')) {
58394
58402
  const code = content.toString();
58395
58403
  // if the code has existing inline sourcemap, assume it's correct and skip
58396
58404
  if (convertSourceMap.mapFileCommentRegex.test(code)) {
@@ -58399,15 +58407,11 @@ function send(req, res, content, type, options) {
58399
58407
  else {
58400
58408
  const urlWithoutTimestamp = removeTimestampQuery(req.url);
58401
58409
  const ms = new MagicString(code);
58402
- const map = ms.generateMap({
58410
+ content = getCodeWithSourcemap(type, code, ms.generateMap({
58403
58411
  source: path$o.basename(urlWithoutTimestamp),
58404
58412
  hires: 'boundary',
58405
- includeContent: !options.originalContent,
58406
- });
58407
- if (options.originalContent != null) {
58408
- map.sourcesContent = [options.originalContent];
58409
- }
58410
- content = getCodeWithSourcemap(type, code, map);
58413
+ includeContent: true,
58414
+ }));
58411
58415
  }
58412
58416
  }
58413
58417
  res.statusCode = 200;
@@ -58543,19 +58547,12 @@ function transformMiddleware(server) {
58543
58547
  const depsOptimizer = getDepsOptimizer(server.config, false); // non-ssr
58544
58548
  const type = isDirectCSSRequest(url) ? 'css' : 'js';
58545
58549
  const isDep = DEP_VERSION_RE.test(url) || depsOptimizer?.isOptimizedDepUrl(url);
58546
- let originalContent;
58547
- if (type === 'js' && result.map == null) {
58548
- const filepath = (await server.moduleGraph.getModuleByUrl(url, false))?.file;
58549
- originalContent =
58550
- filepath != null ? await getOriginalContent(filepath) : undefined;
58551
- }
58552
58550
  return send(req, res, result.code, type, {
58553
58551
  etag: result.etag,
58554
58552
  // allow browser to cache npm deps!
58555
58553
  cacheControl: isDep ? 'max-age=31536000,immutable' : 'no-cache',
58556
58554
  headers: server.config.server.headers,
58557
58555
  map: result.map,
58558
- originalContent,
58559
58556
  });
58560
58557
  }
58561
58558
  }
@@ -59944,25 +59941,37 @@ async function restartServer(server) {
59944
59941
  },
59945
59942
  });
59946
59943
  }
59947
- let newServer = null;
59948
- try {
59949
- // delay ws server listen
59950
- newServer = await _createServer(inlineConfig, { ws: false });
59951
- }
59952
- catch (err) {
59953
- server.config.logger.error(err.message, {
59954
- timestamp: true,
59955
- });
59956
- server.config.logger.error('server restart failed', { timestamp: true });
59957
- return;
59944
+ // Reinit the server by creating a new instance using the same inlineConfig
59945
+ // This will triger a reload of the config file and re-create the plugins and
59946
+ // middlewares. We then assign all properties of the new server to the existing
59947
+ // server instance and set the user instance to be used in the new server.
59948
+ // This allows us to keep the same server instance for the user.
59949
+ {
59950
+ let newServer = null;
59951
+ try {
59952
+ // delay ws server listen
59953
+ newServer = await _createServer(inlineConfig, { ws: false });
59954
+ }
59955
+ catch (err) {
59956
+ server.config.logger.error(err.message, {
59957
+ timestamp: true,
59958
+ });
59959
+ server.config.logger.error('server restart failed', { timestamp: true });
59960
+ return;
59961
+ }
59962
+ await server.close();
59963
+ // Assign new server props to existing server instance
59964
+ const middlewares = server.middlewares;
59965
+ newServer._configServerPort = server._configServerPort;
59966
+ newServer._currentServerPort = server._currentServerPort;
59967
+ Object.assign(server, newServer);
59968
+ // Keep the same connect instance so app.use(vite.middlewares) works
59969
+ // after a restart in middlewareMode (.route is always '/')
59970
+ middlewares.stack = newServer.middlewares.stack;
59971
+ server.middlewares = middlewares;
59972
+ // Rebind internal server variable so functions reference the user server
59973
+ newServer._setInternalServer(server);
59958
59974
  }
59959
- await server.close();
59960
- // Assign new server props to existing server instance
59961
- newServer._configServerPort = server._configServerPort;
59962
- newServer._currentServerPort = server._currentServerPort;
59963
- Object.assign(server, newServer);
59964
- // Rebind internal server variable so functions reference the user server
59965
- newServer._setInternalServer(server);
59966
59975
  const { logger, server: { port, middlewareMode }, } = server.config;
59967
59976
  if (!middlewareMode) {
59968
59977
  await server.listen(port, true);
@@ -59973,7 +59982,7 @@ async function restartServer(server) {
59973
59982
  logger.info('server restarted.', { timestamp: true });
59974
59983
  if (shortcutsOptions) {
59975
59984
  shortcutsOptions.print = false;
59976
- bindCLIShortcuts(newServer, shortcutsOptions);
59985
+ bindCLIShortcuts(server, shortcutsOptions);
59977
59986
  }
59978
59987
  }
59979
59988
  /**
@@ -60474,15 +60483,12 @@ function definePlugin(config) {
60474
60483
  const isBuildLib = isBuild && config.build.lib;
60475
60484
  // ignore replace process.env in lib build
60476
60485
  const processEnv = {};
60477
- const processNodeEnv = {};
60478
60486
  if (!isBuildLib) {
60479
60487
  const nodeEnv = process.env.NODE_ENV || config.mode;
60480
60488
  Object.assign(processEnv, {
60481
60489
  'process.env': `{}`,
60482
60490
  'global.process.env': `{}`,
60483
60491
  'globalThis.process.env': `{}`,
60484
- });
60485
- Object.assign(processNodeEnv, {
60486
60492
  'process.env.NODE_ENV': JSON.stringify(nodeEnv),
60487
60493
  'global.process.env.NODE_ENV': JSON.stringify(nodeEnv),
60488
60494
  'globalThis.process.env.NODE_ENV': JSON.stringify(nodeEnv),
@@ -60515,11 +60521,10 @@ function definePlugin(config) {
60515
60521
  function generatePattern(ssr) {
60516
60522
  const replaceProcessEnv = !ssr || config.ssr?.target === 'webworker';
60517
60523
  const define = {
60518
- ...(replaceProcessEnv ? processNodeEnv : {}),
60524
+ ...(replaceProcessEnv ? processEnv : {}),
60519
60525
  ...importMetaKeys,
60520
60526
  ...userDefine,
60521
60527
  ...importMetaFallbackKeys,
60522
- ...(replaceProcessEnv ? processEnv : {}),
60523
60528
  };
60524
60529
  // Additional define fixes based on `ssr` value
60525
60530
  if ('import.meta.env.SSR' in define) {
@@ -63952,7 +63957,7 @@ async function createDepsOptimizer(config, server) {
63952
63957
  newDepsToLog = [];
63953
63958
  }
63954
63959
  };
63955
- let depOptimizationProcessing = newDepOptimizationProcessing();
63960
+ let depOptimizationProcessing = promiseWithResolvers();
63956
63961
  let depOptimizationProcessingQueue = [];
63957
63962
  const resolveEnqueuedProcessingPromises = () => {
63958
63963
  // Resolve all the processings (including the ones which were delayed)
@@ -64047,7 +64052,7 @@ async function createDepsOptimizer(config, server) {
64047
64052
  depOptimizationProcessingQueue.push(depOptimizationProcessing);
64048
64053
  // Create a new promise for the next rerun, discovered missing
64049
64054
  // dependencies will be assigned this promise from this point
64050
- depOptimizationProcessing = newDepOptimizationProcessing();
64055
+ depOptimizationProcessing = promiseWithResolvers();
64051
64056
  }
64052
64057
  function prepareKnownDeps() {
64053
64058
  const knownDeps = {};
@@ -64954,13 +64959,6 @@ async function addManuallyIncludedOptimizeDeps(deps, config, ssr, extra = [], fi
64954
64959
  }
64955
64960
  }
64956
64961
  }
64957
- function newDepOptimizationProcessing() {
64958
- let resolve;
64959
- const promise = new Promise((_resolve) => {
64960
- resolve = _resolve;
64961
- });
64962
- return { promise, resolve: resolve };
64963
- }
64964
64962
  // Convert to { id: src }
64965
64963
  function depsFromOptimizedDepInfo(depsInfo) {
64966
64964
  const obj = {};
@@ -65327,7 +65325,6 @@ var index = {
65327
65325
  initDepsOptimizerMetadata: initDepsOptimizerMetadata,
65328
65326
  initDevSsrDepsOptimizer: initDevSsrDepsOptimizer,
65329
65327
  loadCachedDepOptimizationMetadata: loadCachedDepOptimizationMetadata,
65330
- newDepOptimizationProcessing: newDepOptimizationProcessing,
65331
65328
  optimizeDeps: optimizeDeps,
65332
65329
  optimizeServerSsrDeps: optimizeServerSsrDeps,
65333
65330
  optimizedDepInfoFromFile: optimizedDepInfoFromFile,
@@ -1,4 +1,4 @@
1
- import { z as commonjsGlobal, y as getDefaultExportFromCjs } from './dep-vyqc0_aB.js';
1
+ import { z as commonjsGlobal, y as getDefaultExportFromCjs } from './dep-4RECYSE1.js';
2
2
  import require$$0__default from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -1,4 +1,4 @@
1
- import { y as getDefaultExportFromCjs } from './dep-vyqc0_aB.js';
1
+ import { y as getDefaultExportFromCjs } from './dep-4RECYSE1.js';
2
2
  import require$$0 from 'path';
3
3
  import require$$0__default from 'fs';
4
4
  import { l as lib } from './dep-8a-6Quh6.js';
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 { x as colors, k as createLogger, r as resolveConfig } from './chunks/dep-vyqc0_aB.js';
5
+ import { x as colors, k as createLogger, r as resolveConfig } from './chunks/dep-4RECYSE1.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-vyqc0_aB.js').then(function (n) { return n.A; });
762
+ const { createServer } = await import('./chunks/dep-4RECYSE1.js').then(function (n) { return n.A; });
763
763
  try {
764
764
  const server = await createServer({
765
765
  root,
@@ -839,7 +839,7 @@ cli
839
839
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
840
840
  .action(async (root, options) => {
841
841
  filterDuplicateOptions(options);
842
- const { build } = await import('./chunks/dep-vyqc0_aB.js').then(function (n) { return n.C; });
842
+ const { build } = await import('./chunks/dep-4RECYSE1.js').then(function (n) { return n.C; });
843
843
  const buildOptions = cleanOptions(options);
844
844
  try {
845
845
  await build({
@@ -867,7 +867,7 @@ cli
867
867
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
868
868
  .action(async (root, options) => {
869
869
  filterDuplicateOptions(options);
870
- const { optimizeDeps } = await import('./chunks/dep-vyqc0_aB.js').then(function (n) { return n.B; });
870
+ const { optimizeDeps } = await import('./chunks/dep-4RECYSE1.js').then(function (n) { return n.B; });
871
871
  try {
872
872
  const config = await resolveConfig({
873
873
  root,
@@ -893,7 +893,7 @@ cli
893
893
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
894
894
  .action(async (root, options) => {
895
895
  filterDuplicateOptions(options);
896
- const { preview } = await import('./chunks/dep-vyqc0_aB.js').then(function (n) { return n.D; });
896
+ const { preview } = await import('./chunks/dep-4RECYSE1.js').then(function (n) { return n.D; });
897
897
  try {
898
898
  const server = await preview({
899
899
  root,
@@ -3285,8 +3285,6 @@ interface SendOptions {
3285
3285
  map?: SourceMap | {
3286
3286
  mappings: '';
3287
3287
  } | null;
3288
- /** only used when type === 'js' && map == null (when the fallback sourcemap is used) */
3289
- originalContent?: string;
3290
3288
  }
3291
3289
  declare function send(req: IncomingMessage, res: ServerResponse, content: string | Buffer, type: string, options: SendOptions): void;
3292
3290
 
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules } from './chunks/dep-vyqc0_aB.js';
3
- export { b as build, e as buildErrorMessage, h as createFilter, k as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, u as isFileServingAllowed, l as loadConfigFromFile, v as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, r as resolveConfig, w as resolveEnvPrefix, q as searchForWorkspaceRoot, j as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-vyqc0_aB.js';
2
+ import { i as isInNodeModules } from './chunks/dep-4RECYSE1.js';
3
+ export { b as build, e as buildErrorMessage, h as createFilter, k as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, u as isFileServingAllowed, l as loadConfigFromFile, v as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, r as resolveConfig, w as resolveEnvPrefix, q as searchForWorkspaceRoot, j as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-4RECYSE1.js';
4
4
  export { VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  export { VERSION as rollupVersion } from 'rollup';
@@ -5329,9 +5329,7 @@ function send(req, res, content, type, options) {
5329
5329
  }
5330
5330
  // inject fallback sourcemap for js for improved debugging
5331
5331
  // https://github.com/vitejs/vite/pull/13514#issuecomment-1592431496
5332
- // for { mappings: "" }, we don't inject fallback sourcemap
5333
- // because it indicates generating a sourcemap is meaningless
5334
- else if (type === 'js' && map == null) {
5332
+ else if (type === 'js' && (!map || map.mappings !== '')) {
5335
5333
  const code = content.toString();
5336
5334
  // if the code has existing inline sourcemap, assume it's correct and skip
5337
5335
  if (convertSourceMap.mapFileCommentRegex.test(code)) {
@@ -5340,15 +5338,11 @@ function send(req, res, content, type, options) {
5340
5338
  else {
5341
5339
  const urlWithoutTimestamp = removeTimestampQuery(req.url);
5342
5340
  const ms = new MagicString(code);
5343
- const map = ms.generateMap({
5341
+ content = getCodeWithSourcemap(type, code, ms.generateMap({
5344
5342
  source: path$3.basename(urlWithoutTimestamp),
5345
5343
  hires: 'boundary',
5346
- includeContent: !options.originalContent,
5347
- });
5348
- if (options.originalContent != null) {
5349
- map.sourcesContent = [options.originalContent];
5350
- }
5351
- content = getCodeWithSourcemap(type, code, map);
5344
+ includeContent: true,
5345
+ }));
5352
5346
  }
5353
5347
  }
5354
5348
  res.statusCode = 200;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",