vite 6.0.10 → 6.0.11

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 { O as commonjsGlobal, N as getDefaultExportFromCjs } from './dep-DP_yvx5y.js';
1
+ import { O as commonjsGlobal, N as getDefaultExportFromCjs } from './dep-M1IYMR16.js';
2
2
  import require$$0$2 from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -1,4 +1,4 @@
1
- import { N as getDefaultExportFromCjs } from './dep-DP_yvx5y.js';
1
+ import { N as getDefaultExportFromCjs } from './dep-M1IYMR16.js';
2
2
  import require$$0 from 'path';
3
3
  import { l as lib } from './dep-3RmXg9uo.js';
4
4
 
@@ -8,7 +8,7 @@ import { performance } from 'node:perf_hooks';
8
8
  import require$$0$6, { createRequire as createRequire$1, builtinModules } from 'node:module';
9
9
  import crypto$2 from 'node:crypto';
10
10
  import esbuild, { transform as transform$1, formatMessages, build as build$b } from 'esbuild';
11
- import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, ENV_ENTRY, DEP_VERSION_RE, SPECIAL_QUERY_RE, DEV_PROD_CONDITION, JS_TYPES_RE, KNOWN_ASSET_TYPES, CSS_LANGS_RE, METADATA_FILENAME, ESBUILD_MODULES_TARGET, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, ROLLUP_HOOKS, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_SERVER_MAIN_FIELDS, DEFAULT_CLIENT_CONDITIONS, DEFAULT_SERVER_CONDITIONS } from '../constants.js';
11
+ import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, ENV_ENTRY, DEP_VERSION_RE, SPECIAL_QUERY_RE, DEV_PROD_CONDITION, JS_TYPES_RE, KNOWN_ASSET_TYPES, CSS_LANGS_RE, METADATA_FILENAME, ESBUILD_MODULES_TARGET, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, defaultAllowedOrigins, CLIENT_DIR, VERSION, ROLLUP_HOOKS, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_SERVER_MAIN_FIELDS, DEFAULT_CLIENT_CONDITIONS, DEFAULT_SERVER_CONDITIONS } from '../constants.js';
12
12
  import require$$0$2, { posix, win32, isAbsolute, resolve as resolve$3, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join, sep } from 'path';
13
13
  import require$$0$3, { existsSync, readFileSync, statSync, readdirSync } from 'fs';
14
14
  import childProcess$2, { exec, execFile, execSync } from 'node:child_process';
@@ -37670,7 +37670,8 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
37670
37670
 
37671
37671
  var WebSocketServerRaw_ = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
37672
37672
 
37673
- const allowedHostsCache = /* @__PURE__ */ new WeakMap();
37673
+ const allowedHostsServerCache = /* @__PURE__ */ new WeakMap();
37674
+ const allowedHostsPreviewCache = /* @__PURE__ */ new WeakMap();
37674
37675
  const isFileOrExtensionProtocolRE = /^(?:file|.+-extension):/i;
37675
37676
  function getAdditionalAllowedHosts(resolvedServerOptions, resolvedPreviewOptions) {
37676
37677
  const list = [];
@@ -37727,39 +37728,42 @@ function isHostAllowedWithoutCache(allowedHosts, additionalAllowedHosts, host) {
37727
37728
  }
37728
37729
  return false;
37729
37730
  }
37730
- function isHostAllowed(config, host) {
37731
- if (config.server.allowedHosts === true) {
37731
+ function isHostAllowed(config, isPreview, host) {
37732
+ const allowedHosts = isPreview ? config.preview.allowedHosts : config.server.allowedHosts;
37733
+ if (allowedHosts === true) {
37732
37734
  return true;
37733
37735
  }
37734
- if (!allowedHostsCache.has(config)) {
37735
- allowedHostsCache.set(config, /* @__PURE__ */ new Set());
37736
+ const cache = isPreview ? allowedHostsPreviewCache : allowedHostsServerCache;
37737
+ if (!cache.has(config)) {
37738
+ cache.set(config, /* @__PURE__ */ new Set());
37736
37739
  }
37737
- const allowedHosts = allowedHostsCache.get(config);
37738
- if (allowedHosts.has(host)) {
37740
+ const cachedAllowedHosts = cache.get(config);
37741
+ if (cachedAllowedHosts.has(host)) {
37739
37742
  return true;
37740
37743
  }
37741
37744
  const result = isHostAllowedWithoutCache(
37742
- config.server.allowedHosts,
37745
+ allowedHosts,
37743
37746
  config.additionalAllowedHosts,
37744
37747
  host
37745
37748
  );
37746
37749
  if (result) {
37747
- allowedHosts.add(host);
37750
+ cachedAllowedHosts.add(host);
37748
37751
  }
37749
37752
  return result;
37750
37753
  }
37751
- function hostCheckMiddleware(config) {
37754
+ function hostCheckMiddleware(config, isPreview) {
37752
37755
  return function viteHostCheckMiddleware(req, res, next) {
37753
37756
  const hostHeader = req.headers.host;
37754
- if (!hostHeader || !isHostAllowed(config, hostHeader)) {
37757
+ if (!hostHeader || !isHostAllowed(config, isPreview, hostHeader)) {
37755
37758
  const hostname = hostHeader?.replace(/:\d+$/, "");
37756
37759
  const hostnameWithQuotes = JSON.stringify(hostname);
37760
+ const optionName = `${isPreview ? "preview" : "server"}.allowedHosts`;
37757
37761
  res.writeHead(403, {
37758
37762
  "Content-Type": "text/plain"
37759
37763
  });
37760
37764
  res.end(
37761
37765
  `Blocked request. This host (${hostnameWithQuotes}) is not allowed.
37762
- To allow this host, add ${hostnameWithQuotes} to \`server.allowedHosts\` in vite.config.js.`
37766
+ To allow this host, add ${hostnameWithQuotes} to \`${optionName}\` in vite.config.js.`
37763
37767
  );
37764
37768
  return;
37765
37769
  }
@@ -37833,7 +37837,7 @@ function createWebSocketServer(server, config, httpsOptions) {
37833
37837
  const protocol = req.headers["sec-websocket-protocol"];
37834
37838
  if (protocol === "vite-ping") return true;
37835
37839
  const hostHeader = req.headers.host;
37836
- if (!hostHeader || !isHostAllowed(config, hostHeader)) {
37840
+ if (!hostHeader || !isHostAllowed(config, false, hostHeader)) {
37837
37841
  return false;
37838
37842
  }
37839
37843
  if (config.legacy?.skipWebSocketTokenCheck) {
@@ -44033,7 +44037,7 @@ async function _createServer(inlineConfig = {}, options) {
44033
44037
  }
44034
44038
  const { allowedHosts } = serverConfig;
44035
44039
  if (allowedHosts !== true && !serverConfig.https) {
44036
- middlewares.use(hostCheckMiddleware(config));
44040
+ middlewares.use(hostCheckMiddleware(config, false));
44037
44041
  }
44038
44042
  middlewares.use(cachedTransformMiddleware(server));
44039
44043
  const { proxy } = serverConfig;
@@ -44159,7 +44163,7 @@ const serverConfigDefaults = Object.freeze({
44159
44163
  https: undefined,
44160
44164
  open: false,
44161
44165
  proxy: undefined,
44162
- cors: false,
44166
+ cors: { origin: defaultAllowedOrigins },
44163
44167
  headers: {},
44164
44168
  // hmr
44165
44169
  // ws
@@ -48875,8 +48879,8 @@ function createCachedImport(imp) {
48875
48879
  return cached;
48876
48880
  };
48877
48881
  }
48878
- const importPostcssImport = createCachedImport(() => import('./dep-a6F3bn0a.js').then(function (n) { return n.i; }));
48879
- const importPostcssModules = createCachedImport(() => import('./dep-BgKqB7IO.js').then(function (n) { return n.i; }));
48882
+ const importPostcssImport = createCachedImport(() => import('./dep-DSNpxjPn.js').then(function (n) { return n.i; }));
48883
+ const importPostcssModules = createCachedImport(() => import('./dep-BSWb06ib.js').then(function (n) { return n.i; }));
48880
48884
  const importPostcss = createCachedImport(() => import('postcss'));
48881
48885
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
48882
48886
  let alwaysFakeWorkerWorkerControllerCache;
@@ -53102,7 +53106,7 @@ async function preview(inlineConfig = {}) {
53102
53106
  }
53103
53107
  const { allowedHosts } = config.preview;
53104
53108
  if (allowedHosts !== true && !config.preview.https) {
53105
- app.use(hostCheckMiddleware(config));
53109
+ app.use(hostCheckMiddleware(config, true));
53106
53110
  }
53107
53111
  const { proxy } = config.preview;
53108
53112
  if (proxy) {
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 { M as colors, G as createLogger, r as resolveConfig } from './chunks/dep-DP_yvx5y.js';
5
+ import { M as colors, G as createLogger, r as resolveConfig } from './chunks/dep-M1IYMR16.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -741,7 +741,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
741
741
  `[boolean] force the optimizer to ignore the cache and re-bundle`
742
742
  ).action(async (root, options) => {
743
743
  filterDuplicateOptions(options);
744
- const { createServer } = await import('./chunks/dep-DP_yvx5y.js').then(function (n) { return n.Q; });
744
+ const { createServer } = await import('./chunks/dep-M1IYMR16.js').then(function (n) { return n.Q; });
745
745
  try {
746
746
  const server = await createServer({
747
747
  root,
@@ -834,7 +834,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
834
834
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--app", `[boolean] same as \`builder: {}\``).action(
835
835
  async (root, options) => {
836
836
  filterDuplicateOptions(options);
837
- const { createBuilder } = await import('./chunks/dep-DP_yvx5y.js').then(function (n) { return n.R; });
837
+ const { createBuilder } = await import('./chunks/dep-M1IYMR16.js').then(function (n) { return n.R; });
838
838
  const buildOptions = cleanGlobalCLIOptions(
839
839
  cleanBuilderCLIOptions(options)
840
840
  );
@@ -869,7 +869,7 @@ cli.command("optimize [root]", "pre-bundle dependencies").option(
869
869
  ).action(
870
870
  async (root, options) => {
871
871
  filterDuplicateOptions(options);
872
- const { optimizeDeps } = await import('./chunks/dep-DP_yvx5y.js').then(function (n) { return n.P; });
872
+ const { optimizeDeps } = await import('./chunks/dep-M1IYMR16.js').then(function (n) { return n.P; });
873
873
  try {
874
874
  const config = await resolveConfig(
875
875
  {
@@ -895,7 +895,7 @@ ${e.stack}`),
895
895
  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(
896
896
  async (root, options) => {
897
897
  filterDuplicateOptions(options);
898
- const { preview } = await import('./chunks/dep-DP_yvx5y.js').then(function (n) { return n.S; });
898
+ const { preview } = await import('./chunks/dep-M1IYMR16.js').then(function (n) { return n.S; });
899
899
  try {
900
900
  const server = await preview({
901
901
  root,
@@ -140,8 +140,9 @@ const wildcardHosts = /* @__PURE__ */ new Set([
140
140
  const DEFAULT_DEV_PORT = 5173;
141
141
  const DEFAULT_PREVIEW_PORT = 4173;
142
142
  const DEFAULT_ASSETS_INLINE_LIMIT = 4096;
143
+ const defaultAllowedOrigins = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
143
144
  const METADATA_FILENAME = "_metadata.json";
144
145
  const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR";
145
146
  const ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR = "ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR";
146
147
 
147
- export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, CSS_LANGS_RE, DEFAULT_ASSETS_INLINE_LIMIT, DEFAULT_ASSETS_RE, DEFAULT_CLIENT_CONDITIONS, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_CONFIG_FILES, DEFAULT_DEV_PORT, DEFAULT_PREVIEW_PORT, DEFAULT_SERVER_CONDITIONS, DEFAULT_SERVER_MAIN_FIELDS, DEP_VERSION_RE, DEV_PROD_CONDITION, ENV_ENTRY, ENV_PUBLIC_PATH, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ESBUILD_MODULES_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, METADATA_FILENAME, OPTIMIZABLE_ENTRY_RE, ROLLUP_HOOKS, SPECIAL_QUERY_RE, VERSION, VITE_PACKAGE_DIR, loopbackHosts, wildcardHosts };
148
+ export { CLIENT_DIR, CLIENT_ENTRY, CLIENT_PUBLIC_PATH, CSS_LANGS_RE, DEFAULT_ASSETS_INLINE_LIMIT, DEFAULT_ASSETS_RE, DEFAULT_CLIENT_CONDITIONS, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_CONFIG_FILES, DEFAULT_DEV_PORT, DEFAULT_PREVIEW_PORT, DEFAULT_SERVER_CONDITIONS, DEFAULT_SERVER_MAIN_FIELDS, DEP_VERSION_RE, DEV_PROD_CONDITION, ENV_ENTRY, ENV_PUBLIC_PATH, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ESBUILD_MODULES_TARGET, FS_PREFIX, JS_TYPES_RE, KNOWN_ASSET_TYPES, METADATA_FILENAME, OPTIMIZABLE_ENTRY_RE, ROLLUP_HOOKS, 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-DP_yvx5y.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, C as createFilter, h as createIdResolver, G as createLogger, n as createRunnableDevEnvironment, c as createServer, w as createServerHotChannel, v as createServerModuleRunner, d as defineConfig, u as fetchModule, j as formatPostcssSourceMap, J as isFileLoadingAllowed, I as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, K as loadEnv, A as mergeAlias, z as mergeConfig, x as moduleRunnerTransform, y as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, L as resolveEnvPrefix, E as rollupVersion, H as searchForWorkspaceRoot, F as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-DP_yvx5y.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-M1IYMR16.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, C as createFilter, h as createIdResolver, G as createLogger, n as createRunnableDevEnvironment, c as createServer, w as createServerHotChannel, v as createServerModuleRunner, d as defineConfig, u as fetchModule, j as formatPostcssSourceMap, J as isFileLoadingAllowed, I as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, K as loadEnv, A as mergeAlias, z as mergeConfig, x as moduleRunnerTransform, y as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, L as resolveEnvPrefix, E as rollupVersion, H as searchForWorkspaceRoot, F as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-M1IYMR16.js';
4
4
  export { 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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.0.10",
3
+ "version": "6.0.11",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",