diff --git a/packages/vite/src/node/baseEnvironment.ts b/packages/vite/src/node/baseEnvironment.ts index 3408db1e1ddc70..e02b1a39e0c374 100644 --- a/packages/vite/src/node/baseEnvironment.ts +++ b/packages/vite/src/node/baseEnvironment.ts @@ -10,6 +10,19 @@ const environmentColors = [ colors.gray, ] +export function getDefaultResolvedEnvironmentOptions( + config: ResolvedConfig, +): ResolvedEnvironmentOptions { + return { + define: config.define, + resolve: config.resolve, + consumer: 'server', + webCompatible: false, + dev: config.dev, + build: config.build, + } +} + export class PartialEnvironment { name: string getTopLevelConfig(): ResolvedConfig { diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 65a0cb4286e267..7f1813ec4113d6 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -33,7 +33,7 @@ import type { ResolvedConfig, ResolvedEnvironmentOptions, } from './config' -import { getDefaultResolvedEnvironmentOptions, resolveConfig } from './config' +import { resolveConfig } from './config' import type { PartialEnvironment } from './baseEnvironment' import { buildReporterPlugin } from './plugins/reporter' import { buildEsbuildPlugin } from './plugins/esbuild' @@ -67,7 +67,10 @@ import { completeSystemWrapPlugin } from './plugins/completeSystemWrap' import { mergeConfig } from './publicUtils' import { webWorkerPostPlugin } from './plugins/worker' import { getHookHandler } from './plugins' -import { BaseEnvironment } from './baseEnvironment' +import { + BaseEnvironment, + getDefaultResolvedEnvironmentOptions, +} from './baseEnvironment' import type { MinimalPluginContext, Plugin, PluginContext } from './plugin' import type { RollupPluginHooks } from './typeUtils' diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index ae5d1bca82fb89..6f7efc1a4b5bc2 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -670,19 +670,6 @@ export function getDefaultEnvironmentOptions( } } -export function getDefaultResolvedEnvironmentOptions( - config: ResolvedConfig, -): ResolvedEnvironmentOptions { - return { - define: config.define, - resolve: config.resolve, - consumer: 'server', - webCompatible: false, - dev: config.dev, - build: config.build, - } -} - export interface PluginHookUtils { getSortedPlugins: ( hookName: K, diff --git a/packages/vite/src/node/constants.ts b/packages/vite/src/node/constants.ts index 088b4cb64dbc68..3acc2f759037e5 100644 --- a/packages/vite/src/node/constants.ts +++ b/packages/vite/src/node/constants.ts @@ -173,3 +173,9 @@ export const DEFAULT_PREVIEW_PORT = 4173 export const DEFAULT_ASSETS_INLINE_LIMIT = 4096 export const METADATA_FILENAME = '_metadata.json' + +export const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = + 'ERR_OPTIMIZE_DEPS_PROCESSING_ERROR' +export const ERR_OUTDATED_OPTIMIZED_DEP = 'ERR_OUTDATED_OPTIMIZED_DEP' +export const ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR = + 'ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR' diff --git a/packages/vite/src/node/plugins/optimizedDeps.ts b/packages/vite/src/node/plugins/optimizedDeps.ts index e1c4dcc049426a..9b67dfdbe444ec 100644 --- a/packages/vite/src/node/plugins/optimizedDeps.ts +++ b/packages/vite/src/node/plugins/optimizedDeps.ts @@ -2,17 +2,16 @@ import fsp from 'node:fs/promises' import colors from 'picocolors' import type { DevEnvironment } from '..' import type { Plugin } from '../plugin' -import { DEP_VERSION_RE } from '../constants' +import { + DEP_VERSION_RE, + ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, + ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, + ERR_OUTDATED_OPTIMIZED_DEP, +} from '../constants' import { createDebugger } from '../utils' import { optimizedDepInfoFromFile } from '../optimizer' import { cleanUrl } from '../../shared/utils' -export const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = - 'ERR_OPTIMIZE_DEPS_PROCESSING_ERROR' -export const ERR_OUTDATED_OPTIMIZED_DEP = 'ERR_OUTDATED_OPTIMIZED_DEP' -export const ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR = - 'ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR' - const debug = createDebugger('vite:optimize-deps') export function optimizedDepsPlugin(): Plugin { diff --git a/packages/vite/src/node/server/environment.ts b/packages/vite/src/node/server/environment.ts index 9bbeb1f8b3f5b5..1b6864fe09a1c8 100644 --- a/packages/vite/src/node/server/environment.ts +++ b/packages/vite/src/node/server/environment.ts @@ -1,14 +1,15 @@ import type { FetchFunctionOptions, FetchResult } from 'vite/module-runner' import type { FSWatcher } from 'dep-types/chokidar' import colors from 'picocolors' -import { BaseEnvironment } from '../baseEnvironment' -import { ERR_OUTDATED_OPTIMIZED_DEP } from '../plugins/optimizedDeps' +import { + BaseEnvironment, + getDefaultResolvedEnvironmentOptions, +} from '../baseEnvironment' import type { EnvironmentOptions, ResolvedConfig, ResolvedEnvironmentOptions, } from '../config' -import { getDefaultResolvedEnvironmentOptions } from '../config' import { mergeConfig, promiseWithResolvers } from '../utils' import { fetchModule } from '../ssr/fetchModule' import type { DepsOptimizer } from '../optimizer' @@ -18,6 +19,7 @@ import { createExplicitDepsOptimizer, } from '../optimizer/optimizer' import { resolveEnvironmentPlugins } from '../plugin' +import { ERR_OUTDATED_OPTIMIZED_DEP } from '../constants' import { EnvironmentModuleGraph } from './moduleGraph' import type { EnvironmentModuleNode } from './moduleGraph' import type { HotChannel } from './hmr' diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 26340de8c0197b..533d0797528b45 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -40,10 +40,13 @@ import { getFsUtils } from '../fsUtils' import { ssrLoadModule } from '../ssr/ssrModuleLoader' import { ssrFixStacktrace, ssrRewriteStacktrace } from '../ssr/ssrStacktrace' import { ssrTransform } from '../ssr/ssrTransform' -import { ERR_OUTDATED_OPTIMIZED_DEP } from '../plugins/optimizedDeps' import { bindCLIShortcuts } from '../shortcuts' import type { BindCLIShortcutsOptions } from '../shortcuts' -import { CLIENT_DIR, DEFAULT_DEV_PORT } from '../constants' +import { + CLIENT_DIR, + DEFAULT_DEV_PORT, + ERR_OUTDATED_OPTIMIZED_DEP, +} from '../constants' import type { Logger } from '../logger' import { printServerUrls } from '../logger' import { warnFutureDeprecation } from '../deprecations' diff --git a/packages/vite/src/node/server/middlewares/transform.ts b/packages/vite/src/node/server/middlewares/transform.ts index 72e9e3e9bdbdf0..d2cb48ef80acd0 100644 --- a/packages/vite/src/node/server/middlewares/transform.ts +++ b/packages/vite/src/node/server/middlewares/transform.ts @@ -21,17 +21,18 @@ import { send } from '../send' import { ERR_LOAD_URL, transformRequest } from '../transformRequest' import { applySourcemapIgnoreList } from '../sourcemap' import { isHTMLProxy } from '../../plugins/html' -import { DEP_VERSION_RE, FS_PREFIX } from '../../constants' +import { + DEP_VERSION_RE, + ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, + ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, + ERR_OUTDATED_OPTIMIZED_DEP, + FS_PREFIX, +} from '../../constants' import { isCSSRequest, isDirectCSSRequest, isDirectRequest, } from '../../plugins/css' -import { - ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, - ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, - ERR_OUTDATED_OPTIMIZED_DEP, -} from '../../plugins/optimizedDeps' import { ERR_CLOSED_SERVER } from '../pluginContainer' import { cleanUrl, unwrapId, withTrailingSlash } from '../../../shared/utils' import { NULL_BYTE_PLACEHOLDER } from '../../../shared/constants'