vite 5.4.13 → 5.4.14

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.
@@ -10,7 +10,7 @@ import crypto$2, { createHash as createHash$2 } from 'node:crypto';
10
10
  import require$$0$3 from 'tty';
11
11
  import require$$0$4, { win32, posix, isAbsolute, resolve as resolve$3, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, sep as sep$1, normalize as normalize$1 } from 'path';
12
12
  import esbuild, { transform as transform$1, formatMessages, build as build$3 } from 'esbuild';
13
- import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, CSS_LANGS_RE, ESBUILD_MODULES_TARGET, SPECIAL_QUERY_RE, ENV_ENTRY, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS, KNOWN_ASSET_TYPES, JS_TYPES_RE, METADATA_FILENAME, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
13
+ import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, CSS_LANGS_RE, ESBUILD_MODULES_TARGET, SPECIAL_QUERY_RE, ENV_ENTRY, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS, KNOWN_ASSET_TYPES, JS_TYPES_RE, METADATA_FILENAME, VITE_PACKAGE_DIR, defaultAllowedOrigins, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
14
14
  import * as require$$0$2 from 'fs';
15
15
  import require$$0__default, { lstatSync, readdir as readdir$4, readdirSync, readlinkSync, realpathSync as realpathSync$1, existsSync, readFileSync, statSync as statSync$1 } from 'fs';
16
16
  import { EventEmitter as EventEmitter$4 } from 'node:events';
@@ -36991,8 +36991,8 @@ function createCachedImport(imp) {
36991
36991
  return cached;
36992
36992
  };
36993
36993
  }
36994
- const importPostcssImport = createCachedImport(() => import('./dep-CT-NxJFJ.js').then(function (n) { return n.i; }));
36995
- const importPostcssModules = createCachedImport(() => import('./dep-Dzr4bp1s.js').then(function (n) { return n.i; }));
36994
+ const importPostcssImport = createCachedImport(() => import('./dep-D0tGukau.js').then(function (n) { return n.i; }));
36995
+ const importPostcssModules = createCachedImport(() => import('./dep-DIiRB4RW.js').then(function (n) { return n.i; }));
36996
36996
  const importPostcss = createCachedImport(() => import('postcss'));
36997
36997
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
36998
36998
  let alwaysFakeWorkerWorkerControllerCache;
@@ -59177,7 +59177,8 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
59177
59177
 
59178
59178
  var WebSocketServerRaw_ = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
59179
59179
 
59180
- const allowedHostsCache = /* @__PURE__ */ new WeakMap();
59180
+ const allowedHostsServerCache = /* @__PURE__ */ new WeakMap();
59181
+ const allowedHostsPreviewCache = /* @__PURE__ */ new WeakMap();
59181
59182
  const isFileOrExtensionProtocolRE = /^(?:file|.+-extension):/i;
59182
59183
  function getAdditionalAllowedHosts(resolvedServerOptions, resolvedPreviewOptions) {
59183
59184
  const list = [];
@@ -59234,39 +59235,42 @@ function isHostAllowedWithoutCache(allowedHosts, additionalAllowedHosts, host) {
59234
59235
  }
59235
59236
  return false;
59236
59237
  }
59237
- function isHostAllowed(config, host) {
59238
- if (config.server.allowedHosts === true) {
59238
+ function isHostAllowed(config, isPreview, host) {
59239
+ const allowedHosts = isPreview ? config.preview.allowedHosts : config.server.allowedHosts;
59240
+ if (allowedHosts === true) {
59239
59241
  return true;
59240
59242
  }
59241
- if (!allowedHostsCache.has(config)) {
59242
- allowedHostsCache.set(config, /* @__PURE__ */ new Set());
59243
+ const cache = isPreview ? allowedHostsPreviewCache : allowedHostsServerCache;
59244
+ if (!cache.has(config)) {
59245
+ cache.set(config, /* @__PURE__ */ new Set());
59243
59246
  }
59244
- const allowedHosts = allowedHostsCache.get(config);
59245
- if (allowedHosts.has(host)) {
59247
+ const cachedAllowedHosts = cache.get(config);
59248
+ if (cachedAllowedHosts.has(host)) {
59246
59249
  return true;
59247
59250
  }
59248
59251
  const result = isHostAllowedWithoutCache(
59249
- config.server.allowedHosts ?? [],
59252
+ allowedHosts ?? [],
59250
59253
  config.additionalAllowedHosts,
59251
59254
  host
59252
59255
  );
59253
59256
  if (result) {
59254
- allowedHosts.add(host);
59257
+ cachedAllowedHosts.add(host);
59255
59258
  }
59256
59259
  return result;
59257
59260
  }
59258
- function hostCheckMiddleware(config) {
59261
+ function hostCheckMiddleware(config, isPreview) {
59259
59262
  return function viteHostCheckMiddleware(req, res, next) {
59260
59263
  const hostHeader = req.headers.host;
59261
- if (!hostHeader || !isHostAllowed(config, hostHeader)) {
59264
+ if (!hostHeader || !isHostAllowed(config, isPreview, hostHeader)) {
59262
59265
  const hostname = hostHeader?.replace(/:\d+$/, "");
59263
59266
  const hostnameWithQuotes = JSON.stringify(hostname);
59267
+ const optionName = `${isPreview ? "preview" : "server"}.allowedHosts`;
59264
59268
  res.writeHead(403, {
59265
59269
  "Content-Type": "text/plain"
59266
59270
  });
59267
59271
  res.end(
59268
59272
  `Blocked request. This host (${hostnameWithQuotes}) is not allowed.
59269
- To allow this host, add ${hostnameWithQuotes} to \`server.allowedHosts\` in vite.config.js.`
59273
+ To allow this host, add ${hostnameWithQuotes} to \`${optionName}\` in vite.config.js.`
59270
59274
  );
59271
59275
  return;
59272
59276
  }
@@ -59329,7 +59333,7 @@ function createWebSocketServer(server, config, httpsOptions) {
59329
59333
  const host = hmr && hmr.host || void 0;
59330
59334
  const shouldHandle = (req) => {
59331
59335
  const hostHeader = req.headers.host;
59332
- if (!hostHeader || !isHostAllowed(config, hostHeader)) {
59336
+ if (!hostHeader || !isHostAllowed(config, false, hostHeader)) {
59333
59337
  return false;
59334
59338
  }
59335
59339
  if (config.legacy?.skipWebSocketTokenCheck) {
@@ -63229,12 +63233,16 @@ async function _createServer(inlineConfig = {}, options) {
63229
63233
  middlewares.use(timeMiddleware(root));
63230
63234
  }
63231
63235
  const { cors } = serverConfig;
63232
- if (cors !== void 0 && cors !== false) {
63233
- middlewares.use(corsMiddleware(typeof cors === "boolean" ? {} : cors));
63236
+ if (cors !== false) {
63237
+ middlewares.use(
63238
+ corsMiddleware(
63239
+ typeof cors === "boolean" ? {} : cors ?? { origin: defaultAllowedOrigins }
63240
+ )
63241
+ );
63234
63242
  }
63235
63243
  const { allowedHosts } = serverConfig;
63236
63244
  if (allowedHosts !== true && !serverConfig.https) {
63237
- middlewares.use(hostCheckMiddleware(config));
63245
+ middlewares.use(hostCheckMiddleware(config, false));
63238
63246
  }
63239
63247
  middlewares.use(cachedTransformMiddleware(server));
63240
63248
  const { proxy } = serverConfig;
@@ -66161,12 +66169,16 @@ async function preview(inlineConfig = {}) {
66161
66169
  postHooks.push(await hook(server));
66162
66170
  }
66163
66171
  const { cors } = config.preview;
66164
- if (cors !== void 0 && cors !== false) {
66165
- app.use(corsMiddleware(typeof cors === "boolean" ? {} : cors));
66172
+ if (cors !== false) {
66173
+ app.use(
66174
+ corsMiddleware(
66175
+ typeof cors === "boolean" ? {} : cors ?? { origin: defaultAllowedOrigins }
66176
+ )
66177
+ );
66166
66178
  }
66167
66179
  const { allowedHosts } = config.preview;
66168
66180
  if (allowedHosts !== true && !config.preview.https) {
66169
- app.use(hostCheckMiddleware(config));
66181
+ app.use(hostCheckMiddleware(config, true));
66170
66182
  }
66171
66183
  const { proxy } = config.preview;
66172
66184
  if (proxy) {
@@ -1,4 +1,4 @@
1
- import { B as getDefaultExportFromCjs } from './dep-Cjmyj91f.js';
1
+ import { B as getDefaultExportFromCjs } from './dep-CHZK6zbr.js';
2
2
  import require$$0 from 'path';
3
3
  import require$$0__default from 'fs';
4
4
  import { l as lib } from './dep-IQS-Za7F.js';
@@ -1,4 +1,4 @@
1
- import { C as commonjsGlobal, B as getDefaultExportFromCjs } from './dep-Cjmyj91f.js';
1
+ import { C as commonjsGlobal, B as getDefaultExportFromCjs } from './dep-CHZK6zbr.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__default from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { A as colors, v as createLogger, r as resolveConfig } from './chunks/dep-Cjmyj91f.js';
5
+ import { A as colors, v as createLogger, r as resolveConfig } from './chunks/dep-CHZK6zbr.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -731,7 +731,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
731
731
  `[boolean] force the optimizer to ignore the cache and re-bundle`
732
732
  ).action(async (root, options) => {
733
733
  filterDuplicateOptions(options);
734
- const { createServer } = await import('./chunks/dep-Cjmyj91f.js').then(function (n) { return n.E; });
734
+ const { createServer } = await import('./chunks/dep-CHZK6zbr.js').then(function (n) { return n.E; });
735
735
  try {
736
736
  const server = await createServer({
737
737
  root,
@@ -823,7 +823,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
823
823
  `[boolean] force empty outDir when it's outside of root`
824
824
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).action(async (root, options) => {
825
825
  filterDuplicateOptions(options);
826
- const { build } = await import('./chunks/dep-Cjmyj91f.js').then(function (n) { return n.F; });
826
+ const { build } = await import('./chunks/dep-CHZK6zbr.js').then(function (n) { return n.F; });
827
827
  const buildOptions = cleanOptions(options);
828
828
  try {
829
829
  await build({
@@ -852,7 +852,7 @@ cli.command("optimize [root]", "pre-bundle dependencies").option(
852
852
  ).action(
853
853
  async (root, options) => {
854
854
  filterDuplicateOptions(options);
855
- const { optimizeDeps } = await import('./chunks/dep-Cjmyj91f.js').then(function (n) { return n.D; });
855
+ const { optimizeDeps } = await import('./chunks/dep-CHZK6zbr.js').then(function (n) { return n.D; });
856
856
  try {
857
857
  const config = await resolveConfig(
858
858
  {
@@ -878,7 +878,7 @@ ${e.stack}`),
878
878
  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(
879
879
  async (root, options) => {
880
880
  filterDuplicateOptions(options);
881
- const { preview } = await import('./chunks/dep-Cjmyj91f.js').then(function (n) { return n.G; });
881
+ const { preview } = await import('./chunks/dep-CHZK6zbr.js').then(function (n) { return n.G; });
882
882
  try {
883
883
  const server = await preview({
884
884
  root,
@@ -107,6 +107,7 @@ const wildcardHosts = /* @__PURE__ */ new Set([
107
107
  const DEFAULT_DEV_PORT = 5173;
108
108
  const DEFAULT_PREVIEW_PORT = 4173;
109
109
  const DEFAULT_ASSETS_INLINE_LIMIT = 4096;
110
+ const defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
110
111
  const METADATA_FILENAME = "_metadata.json";
111
112
 
112
- export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, CSS_LANGS_RE, DEFAULT_ASSETS_INLINE_LIMIT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_DEV_PORT, DEFAULT_EXTENSIONS, DEFAULT_MAIN_FIELDS, DEFAULT_PREVIEW_PORT, DEP_VERSION_RE, ENV_ENTRY, ENV_PUBLIC_PATH, ESBUILD_MODULES_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, METADATA_FILENAME, OPTIMIZABLE_ENTRY_RE, SPECIAL_QUERY_RE, VERSION, VITE_PACKAGE_DIR, loopbackHosts, wildcardHosts };
113
+ export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, CSS_LANGS_RE, DEFAULT_ASSETS_INLINE_LIMIT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_DEV_PORT, DEFAULT_EXTENSIONS, DEFAULT_MAIN_FIELDS, DEFAULT_PREVIEW_PORT, DEP_VERSION_RE, ENV_ENTRY, ENV_PUBLIC_PATH, ESBUILD_MODULES_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, METADATA_FILENAME, OPTIMIZABLE_ENTRY_RE, SPECIAL_QUERY_RE, VERSION, VITE_PACKAGE_DIR, defaultAllowedOrigins, loopbackHosts, wildcardHosts };
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-Cjmyj91f.js';
3
- export { b as build, g as buildErrorMessage, k as createFilter, v as createLogger, c as createServer, d as defineConfig, h as fetchModule, f as formatPostcssSourceMap, x as isFileServingAllowed, l as loadConfigFromFile, y as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, e as preprocessCSS, p as preview, r as resolveConfig, z as resolveEnvPrefix, q as rollupVersion, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Cjmyj91f.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-CHZK6zbr.js';
3
+ export { b as build, g as buildErrorMessage, k as createFilter, v as createLogger, c as createServer, d as defineConfig, h as fetchModule, f as formatPostcssSourceMap, x as isFileServingAllowed, l as loadConfigFromFile, y as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, e as preprocessCSS, p as preview, r as resolveConfig, z as resolveEnvPrefix, q as rollupVersion, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-CHZK6zbr.js';
4
4
  export { VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import { existsSync, readFileSync } from 'node:fs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "5.4.13",
3
+ "version": "5.4.14",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",