vite 6.0.9 → 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-BdTvomPN.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-BdTvomPN.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 = [];
@@ -37684,8 +37685,11 @@ function getAdditionalAllowedHosts(resolvedServerOptions, resolvedPreviewOptions
37684
37685
  list.push(resolvedPreviewOptions.host);
37685
37686
  }
37686
37687
  if (resolvedServerOptions.origin) {
37687
- const serverOriginUrl = new URL(resolvedServerOptions.origin);
37688
- list.push(serverOriginUrl.hostname);
37688
+ try {
37689
+ const serverOriginUrl = new URL(resolvedServerOptions.origin);
37690
+ list.push(serverOriginUrl.hostname);
37691
+ } catch {
37692
+ }
37689
37693
  }
37690
37694
  return list;
37691
37695
  }
@@ -37724,39 +37728,42 @@ function isHostAllowedWithoutCache(allowedHosts, additionalAllowedHosts, host) {
37724
37728
  }
37725
37729
  return false;
37726
37730
  }
37727
- function isHostAllowed(config, host) {
37728
- 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) {
37729
37734
  return true;
37730
37735
  }
37731
- if (!allowedHostsCache.has(config)) {
37732
- allowedHostsCache.set(config, /* @__PURE__ */ new Set());
37736
+ const cache = isPreview ? allowedHostsPreviewCache : allowedHostsServerCache;
37737
+ if (!cache.has(config)) {
37738
+ cache.set(config, /* @__PURE__ */ new Set());
37733
37739
  }
37734
- const allowedHosts = allowedHostsCache.get(config);
37735
- if (allowedHosts.has(host)) {
37740
+ const cachedAllowedHosts = cache.get(config);
37741
+ if (cachedAllowedHosts.has(host)) {
37736
37742
  return true;
37737
37743
  }
37738
37744
  const result = isHostAllowedWithoutCache(
37739
- config.server.allowedHosts,
37745
+ allowedHosts,
37740
37746
  config.additionalAllowedHosts,
37741
37747
  host
37742
37748
  );
37743
37749
  if (result) {
37744
- allowedHosts.add(host);
37750
+ cachedAllowedHosts.add(host);
37745
37751
  }
37746
37752
  return result;
37747
37753
  }
37748
- function hostCheckMiddleware(config) {
37754
+ function hostCheckMiddleware(config, isPreview) {
37749
37755
  return function viteHostCheckMiddleware(req, res, next) {
37750
37756
  const hostHeader = req.headers.host;
37751
- if (!hostHeader || !isHostAllowed(config, hostHeader)) {
37757
+ if (!hostHeader || !isHostAllowed(config, isPreview, hostHeader)) {
37752
37758
  const hostname = hostHeader?.replace(/:\d+$/, "");
37753
37759
  const hostnameWithQuotes = JSON.stringify(hostname);
37760
+ const optionName = `${isPreview ? "preview" : "server"}.allowedHosts`;
37754
37761
  res.writeHead(403, {
37755
37762
  "Content-Type": "text/plain"
37756
37763
  });
37757
37764
  res.end(
37758
37765
  `Blocked request. This host (${hostnameWithQuotes}) is not allowed.
37759
- 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.`
37760
37767
  );
37761
37768
  return;
37762
37769
  }
@@ -37830,7 +37837,7 @@ function createWebSocketServer(server, config, httpsOptions) {
37830
37837
  const protocol = req.headers["sec-websocket-protocol"];
37831
37838
  if (protocol === "vite-ping") return true;
37832
37839
  const hostHeader = req.headers.host;
37833
- if (!hostHeader || !isHostAllowed(config, hostHeader)) {
37840
+ if (!hostHeader || !isHostAllowed(config, false, hostHeader)) {
37834
37841
  return false;
37835
37842
  }
37836
37843
  if (config.legacy?.skipWebSocketTokenCheck) {
@@ -44030,7 +44037,7 @@ async function _createServer(inlineConfig = {}, options) {
44030
44037
  }
44031
44038
  const { allowedHosts } = serverConfig;
44032
44039
  if (allowedHosts !== true && !serverConfig.https) {
44033
- middlewares.use(hostCheckMiddleware(config));
44040
+ middlewares.use(hostCheckMiddleware(config, false));
44034
44041
  }
44035
44042
  middlewares.use(cachedTransformMiddleware(server));
44036
44043
  const { proxy } = serverConfig;
@@ -44156,7 +44163,7 @@ const serverConfigDefaults = Object.freeze({
44156
44163
  https: undefined,
44157
44164
  open: false,
44158
44165
  proxy: undefined,
44159
- cors: false,
44166
+ cors: { origin: defaultAllowedOrigins },
44160
44167
  headers: {},
44161
44168
  // hmr
44162
44169
  // ws
@@ -48872,8 +48879,8 @@ function createCachedImport(imp) {
48872
48879
  return cached;
48873
48880
  };
48874
48881
  }
48875
- const importPostcssImport = createCachedImport(() => import('./dep-CgjxNdwk.js').then(function (n) { return n.i; }));
48876
- const importPostcssModules = createCachedImport(() => import('./dep-BurZv_3i.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; }));
48877
48884
  const importPostcss = createCachedImport(() => import('postcss'));
48878
48885
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
48879
48886
  let alwaysFakeWorkerWorkerControllerCache;
@@ -53099,7 +53106,7 @@ async function preview(inlineConfig = {}) {
53099
53106
  }
53100
53107
  const { allowedHosts } = config.preview;
53101
53108
  if (allowedHosts !== true && !config.preview.https) {
53102
- app.use(hostCheckMiddleware(config));
53109
+ app.use(hostCheckMiddleware(config, true));
53103
53110
  }
53104
53111
  const { proxy } = config.preview;
53105
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-BdTvomPN.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-BdTvomPN.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-BdTvomPN.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-BdTvomPN.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-BdTvomPN.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-BdTvomPN.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-BdTvomPN.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.9",
3
+ "version": "6.0.11",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",