vite 6.3.0-beta.2 → 6.3.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.

@@ -56,13 +56,16 @@ class HMRContext {
56
56
  decline() {
57
57
  }
58
58
  invalidate(message) {
59
+ const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
59
60
  this.hmrClient.notifyListeners("vite:invalidate", {
60
61
  path: this.ownerPath,
61
- message
62
+ message,
63
+ firstInvalidatedBy
62
64
  });
63
65
  this.send("vite:invalidate", {
64
66
  path: this.ownerPath,
65
- message
67
+ message,
68
+ firstInvalidatedBy
66
69
  });
67
70
  this.hmrClient.logger.debug(
68
71
  `invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
@@ -184,7 +187,7 @@ class HMRClient {
184
187
  }
185
188
  }
186
189
  async fetchUpdate(update) {
187
- const { path, acceptedPath } = update;
190
+ const { path, acceptedPath, firstInvalidatedBy } = update;
188
191
  const mod = this.hotModulesMap.get(path);
189
192
  if (!mod) {
190
193
  return;
@@ -204,13 +207,20 @@ class HMRClient {
204
207
  }
205
208
  }
206
209
  return () => {
207
- for (const { deps, fn } of qualifiedCallbacks) {
208
- fn(
209
- deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
210
- );
210
+ try {
211
+ this.currentFirstInvalidatedBy = firstInvalidatedBy;
212
+ for (const { deps, fn } of qualifiedCallbacks) {
213
+ fn(
214
+ deps.map(
215
+ (dep) => dep === acceptedPath ? fetchedModule : void 0
216
+ )
217
+ );
218
+ }
219
+ const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
220
+ this.logger.debug(`hot updated: ${loggedPath}`);
221
+ } finally {
222
+ this.currentFirstInvalidatedBy = void 0;
211
223
  }
212
- const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
213
- this.logger.debug(`hot updated: ${loggedPath}`);
214
224
  };
215
225
  }
216
226
  }
@@ -7510,6 +7510,15 @@ const teardownSIGTERMListener = (callback) => {
7510
7510
  }
7511
7511
  }
7512
7512
  };
7513
+ function getServerUrlByHost(server, host) {
7514
+ if (typeof host !== "string") {
7515
+ return server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0];
7516
+ }
7517
+ return [
7518
+ ...server.resolvedUrls?.local ?? [],
7519
+ ...server.resolvedUrls?.network ?? []
7520
+ ].find((url) => url.includes(host));
7521
+ }
7513
7522
 
7514
7523
  const LogLevels = {
7515
7524
  silent: 0,
@@ -12094,7 +12103,7 @@ const jsonLangs = `\\.(?:json|json5)(?:$|\\?)`;
12094
12103
  const jsonLangRE = new RegExp(jsonLangs);
12095
12104
  const isJSONRequest = (request) => jsonLangRE.test(request);
12096
12105
  function jsonPlugin(options, isBuild) {
12097
- return {
12106
+ const plugin = {
12098
12107
  name: "vite:json",
12099
12108
  transform: {
12100
12109
  handler(json, id) {
@@ -12162,6 +12171,10 @@ Please use ?url&inline or ?url&no-inline to control JSON file inlining behavior.
12162
12171
  }
12163
12172
  }
12164
12173
  };
12174
+ const handler = plugin.transform.handler;
12175
+ plugin.transform = handler;
12176
+ plugin.transform.handler = handler;
12177
+ return plugin;
12165
12178
  }
12166
12179
  function serializeValue(value) {
12167
12180
  const valueAsString = JSON.stringify(value);
@@ -38416,15 +38429,7 @@ async function _createServer(inlineConfig = {}, options) {
38416
38429
  },
38417
38430
  openBrowser() {
38418
38431
  const options2 = server.config.server;
38419
- const host = options2.host;
38420
- let url;
38421
- if (typeof host === "string") {
38422
- url = [
38423
- ...server.resolvedUrls?.local ?? [],
38424
- ...server.resolvedUrls?.network ?? []
38425
- ].find((url2) => url2.includes(host));
38426
- }
38427
- url ??= server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0];
38432
+ const url = getServerUrlByHost(server, options2.host);
38428
38433
  if (url) {
38429
38434
  const path2 = typeof options2.open === "string" ? new URL(options2.open, url).href : url;
38430
38435
  if (server.config.server.preTransformRequests) {
@@ -39222,7 +39227,7 @@ async function handleHMRUpdate(type, file, server) {
39222
39227
  });
39223
39228
  await hotUpdateEnvironments(server, hmr);
39224
39229
  }
39225
- function updateModules(environment, file, modules, timestamp, afterInvalidation) {
39230
+ function updateModules(environment, file, modules, timestamp, firstInvalidatedBy) {
39226
39231
  const { hot } = environment;
39227
39232
  const updates = [];
39228
39233
  const invalidatedModules = /* @__PURE__ */ new Set();
@@ -39244,6 +39249,12 @@ function updateModules(environment, file, modules, timestamp, afterInvalidation)
39244
39249
  needFullReload = hasDeadEnd;
39245
39250
  continue;
39246
39251
  }
39252
+ if (firstInvalidatedBy && boundaries.some(
39253
+ ({ acceptedVia }) => normalizeHmrUrl(acceptedVia.url) === firstInvalidatedBy
39254
+ )) {
39255
+ needFullReload = "circular import invalidate";
39256
+ continue;
39257
+ }
39247
39258
  updates.push(
39248
39259
  ...boundaries.map(
39249
39260
  ({ boundary, acceptedVia, isWithinCircularImport }) => ({
@@ -39252,7 +39263,8 @@ function updateModules(environment, file, modules, timestamp, afterInvalidation)
39252
39263
  path: normalizeHmrUrl(boundary.url),
39253
39264
  acceptedPath: normalizeHmrUrl(acceptedVia.url),
39254
39265
  explicitImportRequired: boundary.type === "js" ? isExplicitImportRequired(acceptedVia.url) : false,
39255
- isWithinCircularImport
39266
+ isWithinCircularImport,
39267
+ firstInvalidatedBy
39256
39268
  })
39257
39269
  )
39258
39270
  );
@@ -39261,7 +39273,7 @@ function updateModules(environment, file, modules, timestamp, afterInvalidation)
39261
39273
  const reason = typeof needFullReload === "string" ? colors$1.dim(` (${needFullReload})`) : "";
39262
39274
  environment.logger.info(
39263
39275
  colors$1.green(`page reload `) + colors$1.dim(file) + reason,
39264
- { clear: !afterInvalidation, timestamp: true }
39276
+ { clear: !firstInvalidatedBy, timestamp: true }
39265
39277
  );
39266
39278
  hot.send({
39267
39279
  type: "full-reload",
@@ -39275,7 +39287,7 @@ function updateModules(environment, file, modules, timestamp, afterInvalidation)
39275
39287
  }
39276
39288
  environment.logger.info(
39277
39289
  colors$1.green(`hmr update `) + colors$1.dim([...new Set(updates.map((u) => u.path))].join(", ")),
39278
- { clear: !afterInvalidation, timestamp: true }
39290
+ { clear: !firstInvalidatedBy, timestamp: true }
39279
39291
  );
39280
39292
  hot.send({
39281
39293
  type: "update",
@@ -42937,7 +42949,7 @@ function cssPostPlugin(config) {
42937
42949
  cssBundleNameCache.set(config, cssBundleName);
42938
42950
  return cssBundleName;
42939
42951
  }
42940
- return {
42952
+ const plugin = {
42941
42953
  name: "vite:css-post",
42942
42954
  renderStart() {
42943
42955
  pureCssChunks = /* @__PURE__ */ new Set();
@@ -43351,6 +43363,10 @@ function cssPostPlugin(config) {
43351
43363
  }
43352
43364
  }
43353
43365
  };
43366
+ const handler = plugin.transform.handler;
43367
+ plugin.transform = handler;
43368
+ plugin.transform.handler = handler;
43369
+ return plugin;
43354
43370
  }
43355
43371
  function cssAnalysisPlugin(config) {
43356
43372
  return {
@@ -43818,8 +43834,8 @@ function createCachedImport(imp) {
43818
43834
  return cached;
43819
43835
  };
43820
43836
  }
43821
- const importPostcssImport = createCachedImport(() => import('./dep-BVYvZuv7.js').then(function (n) { return n.i; }));
43822
- const importPostcssModules = createCachedImport(() => import('./dep-B8BdvHtp.js').then(function (n) { return n.i; }));
43837
+ const importPostcssImport = createCachedImport(() => import('./dep-DYEId0Fh.js').then(function (n) { return n.i; }));
43838
+ const importPostcssModules = createCachedImport(() => import('./dep-yVbOhD1o.js').then(function (n) { return n.i; }));
43823
43839
  const importPostcss = createCachedImport(() => import('postcss'));
43824
43840
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
43825
43841
  let alwaysFakeWorkerWorkerControllerCache;
@@ -45162,12 +45178,22 @@ function detectScriptRel() {
45162
45178
  function preload(baseModule, deps, importerUrl) {
45163
45179
  let promise = Promise.resolve();
45164
45180
  if (__VITE_IS_MODERN__ && deps && deps.length > 0) {
45181
+ let allSettled2 = function(promises) {
45182
+ return Promise.all(
45183
+ promises.map(
45184
+ (p) => Promise.resolve(p).then(
45185
+ (value) => ({ status: "fulfilled", value }),
45186
+ (reason) => ({ status: "rejected", reason })
45187
+ )
45188
+ )
45189
+ );
45190
+ };
45165
45191
  const links = document.getElementsByTagName("link");
45166
45192
  const cspNonceMeta = document.querySelector(
45167
45193
  "meta[property=csp-nonce]"
45168
45194
  );
45169
45195
  const cspNonce = cspNonceMeta?.nonce || cspNonceMeta?.getAttribute("nonce");
45170
- promise = Promise.allSettled(
45196
+ promise = allSettled2(
45171
45197
  deps.map((dep) => {
45172
45198
  dep = assetsURL(dep, importerUrl);
45173
45199
  if (dep in seen) return;
@@ -47754,12 +47780,16 @@ class DevEnvironment extends BaseEnvironment {
47754
47780
  return this.fetchModule(id, importer, options2);
47755
47781
  }
47756
47782
  });
47757
- this.hot.on("vite:invalidate", async ({ path, message }) => {
47758
- invalidateModule(this, {
47759
- path,
47760
- message
47761
- });
47762
- });
47783
+ this.hot.on(
47784
+ "vite:invalidate",
47785
+ async ({ path, message, firstInvalidatedBy }) => {
47786
+ invalidateModule(this, {
47787
+ path,
47788
+ message,
47789
+ firstInvalidatedBy
47790
+ });
47791
+ }
47792
+ );
47763
47793
  const { optimizeDeps } = this.config;
47764
47794
  if (context.depsOptimizer) {
47765
47795
  this.depsOptimizer = context.depsOptimizer;
@@ -47873,7 +47903,7 @@ function invalidateModule(environment, m) {
47873
47903
  file,
47874
47904
  [...mod.importers],
47875
47905
  mod.lastHMRTimestamp,
47876
- true
47906
+ m.firstInvalidatedBy
47877
47907
  );
47878
47908
  }
47879
47909
  }
@@ -48214,7 +48244,7 @@ async function preview(inlineConfig = {}) {
48214
48244
  config
48215
48245
  );
48216
48246
  if (options.open) {
48217
- const url = server.resolvedUrls.local[0] ?? server.resolvedUrls.network[0];
48247
+ const url = getServerUrlByHost(server, options.host);
48218
48248
  if (url) {
48219
48249
  const path2 = typeof options.open === "string" ? new URL(options.open, url).href : url;
48220
48250
  openBrowser(path2, true, logger);
@@ -1,4 +1,4 @@
1
- import { P as getDefaultExportFromCjs } from './dep-jcjTW_IO.js';
1
+ import { P as getDefaultExportFromCjs } from './dep-Bxmd1Uxj.js';
2
2
  import require$$0 from 'path';
3
3
  import { l as lib } from './dep-3RmXg9uo.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-jcjTW_IO.js';
1
+ import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-Bxmd1Uxj.js';
2
2
  import require$$0$2 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__default from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-jcjTW_IO.js';
5
+ import { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-Bxmd1Uxj.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -748,7 +748,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
748
748
  `[boolean] force the optimizer to ignore the cache and re-bundle`
749
749
  ).action(async (root, options) => {
750
750
  filterDuplicateOptions(options);
751
- const { createServer } = await import('./chunks/dep-jcjTW_IO.js').then(function (n) { return n.S; });
751
+ const { createServer } = await import('./chunks/dep-Bxmd1Uxj.js').then(function (n) { return n.S; });
752
752
  try {
753
753
  const server = await createServer({
754
754
  root,
@@ -843,7 +843,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
843
843
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--app", `[boolean] same as \`builder: {}\``).action(
844
844
  async (root, options) => {
845
845
  filterDuplicateOptions(options);
846
- const { createBuilder } = await import('./chunks/dep-jcjTW_IO.js').then(function (n) { return n.T; });
846
+ const { createBuilder } = await import('./chunks/dep-Bxmd1Uxj.js').then(function (n) { return n.T; });
847
847
  const buildOptions = cleanGlobalCLIOptions(
848
848
  cleanBuilderCLIOptions(options)
849
849
  );
@@ -882,7 +882,7 @@ cli.command(
882
882
  ).action(
883
883
  async (root, options) => {
884
884
  filterDuplicateOptions(options);
885
- const { optimizeDeps } = await import('./chunks/dep-jcjTW_IO.js').then(function (n) { return n.R; });
885
+ const { optimizeDeps } = await import('./chunks/dep-Bxmd1Uxj.js').then(function (n) { return n.R; });
886
886
  try {
887
887
  const config = await resolveConfig(
888
888
  {
@@ -909,7 +909,7 @@ ${e.stack}`),
909
909
  cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(
910
910
  async (root, options) => {
911
911
  filterDuplicateOptions(options);
912
- const { preview } = await import('./chunks/dep-jcjTW_IO.js').then(function (n) { return n.U; });
912
+ const { preview } = await import('./chunks/dep-Bxmd1Uxj.js').then(function (n) { return n.U; });
913
913
  try {
914
914
  const server = await preview({
915
915
  root,
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { a as arraify, i as isInNodeModules, D as DevEnvironment } from './chunks/dep-jcjTW_IO.js';
3
- export { B as BuildEnvironment, f as build, m as buildErrorMessage, g as createBuilder, F as createFilter, h as createIdResolver, I as createLogger, n as createRunnableDevEnvironment, c as createServer, y as createServerHotChannel, w as createServerModuleRunner, x as createServerModuleRunnerTransport, d as defineConfig, v as fetchModule, j as formatPostcssSourceMap, L as isFileLoadingAllowed, K as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, M as loadEnv, E as mergeAlias, C as mergeConfig, z as moduleRunnerTransform, A as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, N as resolveEnvPrefix, G as rollupVersion, u as runnerImport, J as searchForWorkspaceRoot, H as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-jcjTW_IO.js';
2
+ import { a as arraify, i as isInNodeModules, D as DevEnvironment } from './chunks/dep-Bxmd1Uxj.js';
3
+ export { B as BuildEnvironment, f as build, m as buildErrorMessage, g as createBuilder, F as createFilter, h as createIdResolver, I as createLogger, n as createRunnableDevEnvironment, c as createServer, y as createServerHotChannel, w as createServerModuleRunner, x as createServerModuleRunnerTransport, d as defineConfig, v as fetchModule, j as formatPostcssSourceMap, L as isFileLoadingAllowed, K as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, M as loadEnv, E as mergeAlias, C as mergeConfig, z as moduleRunnerTransform, A as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, N as resolveEnvPrefix, G as rollupVersion, u as runnerImport, J as searchForWorkspaceRoot, H as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Bxmd1Uxj.js';
4
4
  export { defaultAllowedOrigins, DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import 'node:fs';
@@ -51,6 +51,7 @@ declare class HMRClient {
51
51
  dataMap: Map<string, any>;
52
52
  customListenersMap: CustomListenersMap;
53
53
  ctxToListenersMap: Map<string, CustomListenersMap>;
54
+ currentFirstInvalidatedBy: string | undefined;
54
55
  constructor(logger: HMRLogger, transport: NormalizedModuleRunnerTransport, importUpdatedModule: (update: Update) => Promise<ModuleNamespace>);
55
56
  notifyListeners<T extends string>(event: T, data: InferCustomEventPayload<T>): Promise<void>;
56
57
  send(payload: HotPayload): void;
@@ -383,12 +383,15 @@ class HMRContext {
383
383
  decline() {
384
384
  }
385
385
  invalidate(message) {
386
+ const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
386
387
  this.hmrClient.notifyListeners("vite:invalidate", {
387
388
  path: this.ownerPath,
388
- message
389
+ message,
390
+ firstInvalidatedBy
389
391
  }), this.send("vite:invalidate", {
390
392
  path: this.ownerPath,
391
- message
393
+ message,
394
+ firstInvalidatedBy
392
395
  }), this.hmrClient.logger.debug(
393
396
  `invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
394
397
  );
@@ -439,6 +442,7 @@ class HMRClient {
439
442
  dataMap = /* @__PURE__ */ new Map();
440
443
  customListenersMap = /* @__PURE__ */ new Map();
441
444
  ctxToListenersMap = /* @__PURE__ */ new Map();
445
+ currentFirstInvalidatedBy;
442
446
  async notifyListeners(event, data) {
443
447
  const cbs = this.customListenersMap.get(event);
444
448
  cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
@@ -485,7 +489,7 @@ class HMRClient {
485
489
  }
486
490
  }
487
491
  async fetchUpdate(update) {
488
- const { path, acceptedPath } = update, mod = this.hotModulesMap.get(path);
492
+ const { path, acceptedPath, firstInvalidatedBy } = update, mod = this.hotModulesMap.get(path);
489
493
  if (!mod)
490
494
  return;
491
495
  let fetchedModule;
@@ -502,12 +506,19 @@ class HMRClient {
502
506
  }
503
507
  }
504
508
  return () => {
505
- for (const { deps, fn } of qualifiedCallbacks)
506
- fn(
507
- deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
508
- );
509
- const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
510
- this.logger.debug(`hot updated: ${loggedPath}`);
509
+ try {
510
+ this.currentFirstInvalidatedBy = firstInvalidatedBy;
511
+ for (const { deps, fn } of qualifiedCallbacks)
512
+ fn(
513
+ deps.map(
514
+ (dep) => dep === acceptedPath ? fetchedModule : void 0
515
+ )
516
+ );
517
+ const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
518
+ this.logger.debug(`hot updated: ${loggedPath}`);
519
+ } finally {
520
+ this.currentFirstInvalidatedBy = void 0;
521
+ }
511
522
  };
512
523
  }
513
524
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.3.0-beta.2",
3
+ "version": "6.3.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -30,6 +30,7 @@ export interface WebSocketConnectionPayload {
30
30
  export interface InvalidatePayload {
31
31
  path: string
32
32
  message: string | undefined
33
+ firstInvalidatedBy: string
33
34
  }
34
35
 
35
36
  /**
@@ -32,6 +32,8 @@ export interface Update {
32
32
  /** @internal */
33
33
  isWithinCircularImport?: boolean
34
34
  /** @internal */
35
+ firstInvalidatedBy?: string
36
+ /** @internal */
35
37
  invalidates?: string[]
36
38
  }
37
39