vite 5.0.0-beta.14 → 5.0.0-beta.15

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.
@@ -1,4 +1,4 @@
1
- import { y as getDefaultExportFromCjs } from './dep-QFst3FNH.js';
1
+ import { y as getDefaultExportFromCjs } from './dep-Kf16Z54K.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';
@@ -32,7 +32,7 @@ import assert$1 from 'node:assert';
32
32
  import process$1 from 'node:process';
33
33
  import v8 from 'node:v8';
34
34
  import { VERSION } from 'rollup';
35
- import { parseAst } from 'rollup/parseAst';
35
+ import { parseAstAsync, parseAst } from 'rollup/parseAst';
36
36
  import * as qs from 'querystring';
37
37
  import readline from 'node:readline';
38
38
  import { EventEmitter as EventEmitter$4 } from 'node:events';
@@ -38479,8 +38479,8 @@ function createCachedImport(imp) {
38479
38479
  return cached;
38480
38480
  };
38481
38481
  }
38482
- const importPostcssImport = createCachedImport(() => import('./dep-L-2yzs6m.js').then(function (n) { return n.i; }));
38483
- const importPostcssModules = createCachedImport(() => import('./dep-OMqKnqdS.js').then(function (n) { return n.i; }));
38482
+ const importPostcssImport = createCachedImport(() => import('./dep-01ZZG1lv.js').then(function (n) { return n.i; }));
38483
+ const importPostcssModules = createCachedImport(() => import('./dep-dhvB1mwU.js').then(function (n) { return n.i; }));
38484
38484
  const importPostcss = createCachedImport(() => import('postcss'));
38485
38485
  /**
38486
38486
  * @experimental
@@ -47650,7 +47650,7 @@ async function doTransform(url, server, options, timestamp) {
47650
47650
  // tries to handle soft invalidation of the module if available,
47651
47651
  // returns a boolean true is successful, or false if no handling is needed
47652
47652
  const softInvalidatedTransformResult = module &&
47653
- (await handleModuleSoftInvalidation(module, ssr, timestamp, server.config.base));
47653
+ (await handleModuleSoftInvalidation(module, ssr, timestamp, server));
47654
47654
  if (softInvalidatedTransformResult) {
47655
47655
  debugCache$1?.(`[memory-hmr] ${prettyUrl}`);
47656
47656
  return softInvalidatedTransformResult;
@@ -47827,7 +47827,7 @@ function createConvertSourceMapReadMap(originalFileName) {
47827
47827
  * - Client: We need to transform the import specifiers with new timestamps
47828
47828
  * - SSR: We don't need to change anything as `ssrLoadModule` controls it
47829
47829
  */
47830
- async function handleModuleSoftInvalidation(mod, ssr, timestamp, base) {
47830
+ async function handleModuleSoftInvalidation(mod, ssr, timestamp, server) {
47831
47831
  const transformResult = ssr ? mod.ssrInvalidationState : mod.invalidationState;
47832
47832
  // Reset invalidation state
47833
47833
  if (ssr)
@@ -47838,7 +47838,7 @@ async function handleModuleSoftInvalidation(mod, ssr, timestamp, base) {
47838
47838
  if (!transformResult || transformResult === 'HARD_INVALIDATED')
47839
47839
  return;
47840
47840
  if (ssr ? mod.ssrTransformResult : mod.transformResult) {
47841
- throw new Error(`Internal server error: Soft-invalidated module "${mod.url}" should not have existing tranform result`);
47841
+ throw new Error(`Internal server error: Soft-invalidated module "${mod.url}" should not have existing transform result`);
47842
47842
  }
47843
47843
  let result;
47844
47844
  // For SSR soft-invalidation, no transformation is needed
@@ -47861,7 +47861,7 @@ async function handleModuleSoftInvalidation(mod, ssr, timestamp, base) {
47861
47861
  }
47862
47862
  const urlWithoutTimestamp = removeTimestampQuery(rawUrl);
47863
47863
  // hmrUrl must be derived the same way as importAnalysis
47864
- const hmrUrl = unwrapId(stripBase(removeImportQuery(urlWithoutTimestamp), base));
47864
+ const hmrUrl = unwrapId(stripBase(removeImportQuery(urlWithoutTimestamp), server.config.base));
47865
47865
  for (const importedMod of mod.clientImportedModules) {
47866
47866
  if (importedMod.url !== hmrUrl)
47867
47867
  continue;
@@ -47871,6 +47871,10 @@ async function handleModuleSoftInvalidation(mod, ssr, timestamp, base) {
47871
47871
  const end = hasQuotes ? imp.e - 1 : imp.e;
47872
47872
  s.overwrite(start, end, replacedUrl);
47873
47873
  }
47874
+ if (imp.d === -1 && server.config.server.preTransformRequests) {
47875
+ // pre-transform known direct imports
47876
+ server.warmupRequest(hmrUrl, { ssr });
47877
+ }
47874
47878
  break;
47875
47879
  }
47876
47880
  }
@@ -48207,7 +48211,7 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
48207
48211
  const s = new MagicString(code);
48208
48212
  let ast;
48209
48213
  try {
48210
- ast = parseAst(code);
48214
+ ast = await parseAstAsync(code);
48211
48215
  }
48212
48216
  catch (err) {
48213
48217
  if (!err.loc || !err.loc.line)
@@ -57682,20 +57686,9 @@ function indexHtmlMiddleware(root, server) {
57682
57686
  function preTransformRequest(server, url, base) {
57683
57687
  if (!server.config.server.preTransformRequests)
57684
57688
  return;
57685
- url = unwrapId(stripBase(url, base));
57686
57689
  // transform all url as non-ssr as html includes client-side assets only
57687
- server.transformRequest(url).catch((e) => {
57688
- if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP ||
57689
- e?.code === ERR_CLOSED_SERVER) {
57690
- // these are expected errors
57691
- return;
57692
- }
57693
- // Unexpected error, log the issue but avoid an unhandled exception
57694
- server.config.logger.error(`Pre-transform error: ${e.message}`, {
57695
- error: e,
57696
- timestamp: true,
57697
- });
57698
- });
57690
+ url = unwrapId(stripBase(url, base));
57691
+ server.warmupRequest(url);
57699
57692
  }
57700
57693
 
57701
57694
  const logTime = createDebugger('vite:time');
@@ -58258,26 +58251,29 @@ function warmupFiles(server) {
58258
58251
  }
58259
58252
  }
58260
58253
  async function warmupFile(server, file, ssr) {
58261
- try {
58262
- // transform html with the `transformIndexHtml` hook as Vite internals would
58263
- // pre-transform the imported JS modules linked. this may cause `transformIndexHtml`
58264
- // plugins to be executed twice, but that's probably fine.
58265
- if (file.endsWith('.html')) {
58266
- const url = htmlFileToUrl(file, server.config.root);
58267
- if (url) {
58254
+ // transform html with the `transformIndexHtml` hook as Vite internals would
58255
+ // pre-transform the imported JS modules linked. this may cause `transformIndexHtml`
58256
+ // plugins to be executed twice, but that's probably fine.
58257
+ if (file.endsWith('.html')) {
58258
+ const url = htmlFileToUrl(file, server.config.root);
58259
+ if (url) {
58260
+ try {
58268
58261
  const html = await fsp.readFile(file, 'utf-8');
58269
58262
  await server.transformIndexHtml(url, html);
58270
58263
  }
58271
- }
58272
- // for other files, pass it through `transformRequest`. this is what Vite uses
58273
- // for it's `server.preTransformRequests` option.
58274
- else {
58275
- const url = fileToUrl(file, server.config.root);
58276
- await server.transformRequest(url, { ssr });
58264
+ catch (e) {
58265
+ // Unexpected error, log the issue but avoid an unhandled exception
58266
+ server.config.logger.error(`Pre-transform error (${colors$1.cyan(file)}): ${e.message}`, {
58267
+ error: e,
58268
+ timestamp: true,
58269
+ });
58270
+ }
58277
58271
  }
58278
58272
  }
58279
- catch (e) {
58280
- server.config.logger.error(colors$1.red(`Failed to warm up ${colors$1.cyan(file)}:\n`) + e.message);
58273
+ // for other files, pass it through `transformRequest` with warmup
58274
+ else {
58275
+ const url = fileToUrl(file, server.config.root);
58276
+ await server.warmupRequest(url, { ssr });
58281
58277
  }
58282
58278
  }
58283
58279
  function htmlFileToUrl(file, root) {
@@ -58350,6 +58346,20 @@ async function _createServer(inlineConfig = {}, options) {
58350
58346
  transformRequest(url, options) {
58351
58347
  return transformRequest(url, server, options);
58352
58348
  },
58349
+ async warmupRequest(url, options) {
58350
+ await transformRequest(url, server, options).catch((e) => {
58351
+ if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP ||
58352
+ e?.code === ERR_CLOSED_SERVER) {
58353
+ // these are expected errors
58354
+ return;
58355
+ }
58356
+ // Unexpected error, log the issue but avoid an unhandled exception
58357
+ server.config.logger.error(`Pre-transform error: ${e.message}`, {
58358
+ error: e,
58359
+ timestamp: true,
58360
+ });
58361
+ });
58362
+ },
58353
58363
  transformIndexHtml: null,
58354
58364
  async ssrLoadModule(url, opts) {
58355
58365
  if (isDepsOptimizerEnabled(config, true)) {
@@ -58500,11 +58510,13 @@ async function _createServer(inlineConfig = {}, options) {
58500
58510
  };
58501
58511
  const onFileAddUnlink = async (file, isUnlink) => {
58502
58512
  file = normalizePath$3(file);
58513
+ await container.watchChange(file, { event: isUnlink ? 'delete' : 'create' });
58503
58514
  await handleFileAddUnlink(file, server, isUnlink);
58504
58515
  await onHMRUpdate(file, true);
58505
58516
  };
58506
58517
  watcher.on('change', async (file) => {
58507
58518
  file = normalizePath$3(file);
58519
+ await container.watchChange(file, { event: 'update' });
58508
58520
  // invalidate module graph cache on file change
58509
58521
  moduleGraph.onFileChange(file);
58510
58522
  await onHMRUpdate(file, false);
@@ -59197,7 +59209,6 @@ function definePlugin(config) {
59197
59209
  'process.env.NODE_ENV': JSON.stringify(nodeEnv),
59198
59210
  'global.process.env.NODE_ENV': JSON.stringify(nodeEnv),
59199
59211
  'globalThis.process.env.NODE_ENV': JSON.stringify(nodeEnv),
59200
- __vite_process_env_NODE_ENV: JSON.stringify(nodeEnv),
59201
59212
  });
59202
59213
  }
59203
59214
  // during dev, import.meta properties are handled by importAnalysis plugin.
@@ -59234,9 +59245,6 @@ function definePlugin(config) {
59234
59245
  ...(replaceProcessEnv ? processEnv : {}),
59235
59246
  };
59236
59247
  // Additional define fixes based on `ssr` value
59237
- if (isBuild && !replaceProcessEnv) {
59238
- define['__vite_process_env_NODE_ENV'] = 'process.env.NODE_ENV';
59239
- }
59240
59248
  if ('import.meta.env.SSR' in define) {
59241
59249
  define['import.meta.env.SSR'] = ssr + '';
59242
59250
  }
@@ -59247,16 +59255,16 @@ function definePlugin(config) {
59247
59255
  ...userDefineEnv,
59248
59256
  });
59249
59257
  }
59250
- const defineKeys = Object.keys(define);
59251
- const pattern = defineKeys.length
59252
- ? new RegExp(
59253
- // Mustn't be preceded by a char that can be part of an identifier
59254
- // or a '.' that isn't part of a spread operator
59255
- '(?<![\\p{L}\\p{N}_$]|(?<!\\.\\.)\\.)(' +
59256
- defineKeys.map(escapeRegex).join('|') +
59257
- // Mustn't be followed by a char that can be part of an identifier
59258
- // or an assignment (but allow equality operators)
59259
- ')(?:(?<=\\.)|(?![\\p{L}\\p{N}_$]|\\s*?=[^=]))', 'gu')
59258
+ // Create regex pattern as a fast check before running esbuild
59259
+ const patternKeys = Object.keys(userDefine);
59260
+ if (replaceProcessEnv && Object.keys(processEnv).length) {
59261
+ patternKeys.push('process.env');
59262
+ }
59263
+ if (Object.keys(importMetaKeys).length) {
59264
+ patternKeys.push('import.meta.env', 'import.meta.hot');
59265
+ }
59266
+ const pattern = patternKeys.length
59267
+ ? new RegExp(patternKeys.map(escapeRegex).join('|'))
59260
59268
  : null;
59261
59269
  return [define, pattern];
59262
59270
  }
@@ -59766,18 +59774,7 @@ function importAnalysisPlugin(config) {
59766
59774
  // These requests will also be registered in transformRequest to be awaited
59767
59775
  // by the deps optimizer
59768
59776
  const url = removeImportQuery(hmrUrl);
59769
- server.transformRequest(url, { ssr }).catch((e) => {
59770
- if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP ||
59771
- e?.code === ERR_CLOSED_SERVER) {
59772
- // these are expected errors
59773
- return;
59774
- }
59775
- // Unexpected error, log the issue but avoid an unhandled exception
59776
- config.logger.error(`Pre-transform error: ${e.message}`, {
59777
- error: e,
59778
- timestamp: true,
59779
- });
59780
- });
59777
+ server.warmupRequest(url, { ssr });
59781
59778
  }
59782
59779
  }
59783
59780
  else if (!importer.startsWith(withTrailingSlash(clientDir))) {
@@ -61893,6 +61890,10 @@ async function createPluginContainer(config, moduleGraph, watcher) {
61893
61890
  map: ctx._getCombinedSourcemap(),
61894
61891
  };
61895
61892
  },
61893
+ async watchChange(id, change) {
61894
+ const ctx = new Context();
61895
+ await hookParallel('watchChange', () => ctx, () => [id, change]);
61896
+ },
61896
61897
  async close() {
61897
61898
  if (closed)
61898
61899
  return;
@@ -63525,12 +63526,10 @@ async function prepareEsbuildOptimizerRun(resolvedConfig, depsInfo, ssr, process
63525
63526
  if (optimizerContext.cancelled)
63526
63527
  return { context: undefined, idToExports };
63527
63528
  // esbuild automatically replaces process.env.NODE_ENV for platform 'browser'
63528
- // In lib mode, we need to keep process.env.NODE_ENV untouched, so to at build
63529
- // time we replace it by __vite_process_env_NODE_ENV. This placeholder will be
63530
- // later replaced by the define plugin
63529
+ // But in lib mode, we need to keep process.env.NODE_ENV untouched
63531
63530
  const define = {
63532
- 'process.env.NODE_ENV': isBuild
63533
- ? '__vite_process_env_NODE_ENV'
63531
+ 'process.env.NODE_ENV': isBuild && config.build.lib
63532
+ ? 'process.env.NODE_ENV'
63534
63533
  : JSON.stringify(process.env.NODE_ENV || config.mode),
63535
63534
  };
63536
63535
  const platform = ssr && config.ssr?.target !== 'webworker' ? 'node' : 'browser';
@@ -65630,10 +65629,6 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
65630
65629
  allowClearScreen: config.clearScreen,
65631
65630
  customLogger: config.customLogger,
65632
65631
  });
65633
- let foundDiscouragedVariableName;
65634
- if ((foundDiscouragedVariableName = Object.keys(config.define ?? {}).find((k) => ['process', 'global'].includes(k)))) {
65635
- 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.`));
65636
- }
65637
65632
  // resolve root
65638
65633
  const resolvedRoot = normalizePath$3(config.root ? path$o.resolve(config.root) : process.cwd());
65639
65634
  if (resolvedRoot.includes('#')) {
@@ -1,4 +1,4 @@
1
- import { z as commonjsGlobal, y as getDefaultExportFromCjs } from './dep-QFst3FNH.js';
1
+ import { z as commonjsGlobal, y as getDefaultExportFromCjs } from './dep-Kf16Z54K.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 { x as colors, k as createLogger, r as resolveConfig } from './chunks/dep-QFst3FNH.js';
5
+ import { x as colors, k as createLogger, r as resolveConfig } from './chunks/dep-Kf16Z54K.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-QFst3FNH.js').then(function (n) { return n.A; });
762
+ const { createServer } = await import('./chunks/dep-Kf16Z54K.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-QFst3FNH.js').then(function (n) { return n.C; });
842
+ const { build } = await import('./chunks/dep-Kf16Z54K.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-QFst3FNH.js').then(function (n) { return n.B; });
870
+ const { optimizeDeps } = await import('./chunks/dep-Kf16Z54K.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-QFst3FNH.js').then(function (n) { return n.D; });
896
+ const { preview } = await import('./chunks/dep-Kf16Z54K.js').then(function (n) { return n.D; });
897
897
  try {
898
898
  const server = await preview({
899
899
  root,
@@ -3,6 +3,7 @@ import { PluginHooks, RollupError, SourceMap, ModuleInfo, PartialResolvedId, Inp
3
3
  import * as rollup from 'rollup';
4
4
  export { rollup as Rollup };
5
5
  export { VERSION as rollupVersion } from 'rollup';
6
+ export { parseAst, parseAstAsync } from 'rollup/parseAst';
6
7
  import * as http from 'node:http';
7
8
  import { OutgoingHttpHeaders, ClientRequestArgs, IncomingMessage, ClientRequest, Agent, Server, ServerResponse } from 'node:http';
8
9
  import * as fs from 'node:fs';
@@ -859,6 +860,9 @@ interface PluginContainer {
859
860
  load(id: string, options?: {
860
861
  ssr?: boolean;
861
862
  }): Promise<LoadResult | null>;
863
+ watchChange(id: string, change: {
864
+ event: 'create' | 'update' | 'delete';
865
+ }): Promise<void>;
862
866
  close(): Promise<void>;
863
867
  }
864
868
 
@@ -1595,6 +1599,12 @@ interface ViteDevServer {
1595
1599
  * without going through the http request pipeline.
1596
1600
  */
1597
1601
  transformRequest(url: string, options?: TransformOptions): Promise<TransformResult | null>;
1602
+ /**
1603
+ * Same as `transformRequest` but only warm up the URLs so the next request
1604
+ * will already be cached. The function will never throw as it handles and
1605
+ * reports errors internally.
1606
+ */
1607
+ warmupRequest(url: string, options?: TransformOptions): Promise<void>;
1598
1608
  /**
1599
1609
  * Apply vite built-in HTML transforms and any plugin HTML transforms.
1600
1610
  */
@@ -3097,7 +3107,7 @@ interface UserConfig {
3097
3107
  */
3098
3108
  format?: 'es' | 'iife';
3099
3109
  /**
3100
- * Vite plugins that apply to worker bundle. The plugins retured by this function
3110
+ * Vite plugins that apply to worker bundle. The plugins returned by this function
3101
3111
  * should be new instances every time it is called, because they are used for each
3102
3112
  * rollup worker bundling process.
3103
3113
  */
@@ -1,5 +1,6 @@
1
- import { i as isInNodeModules } from './chunks/dep-QFst3FNH.js';
2
- 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-QFst3FNH.js';
1
+ export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
+ import { i as isInNodeModules } from './chunks/dep-Kf16Z54K.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-Kf16Z54K.js';
3
4
  export { VERSION as version } from './constants.js';
4
5
  export { version as esbuildVersion } from 'esbuild';
5
6
  export { VERSION as rollupVersion } from 'rollup';
@@ -33,7 +34,6 @@ import 'module';
33
34
  import 'node:assert';
34
35
  import 'node:process';
35
36
  import 'node:v8';
36
- import 'rollup/parseAst';
37
37
  import 'querystring';
38
38
  import 'node:readline';
39
39
  import 'node:events';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "5.0.0-beta.14",
3
+ "version": "5.0.0-beta.15",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -63,7 +63,7 @@
63
63
  "dependencies": {
64
64
  "esbuild": "^0.19.3",
65
65
  "postcss": "^8.4.31",
66
- "rollup": "^4.1.4"
66
+ "rollup": "^4.2.0"
67
67
  },
68
68
  "optionalDependencies": {
69
69
  "fsevents": "~2.3.3"