Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: break circular dependencies to fix test-unit #18237

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -70,6 +70,7 @@ import { getHookHandler } from './plugins'
import { BaseEnvironment } from './baseEnvironment'
import type { MinimalPluginContext, Plugin, PluginContext } from './plugin'
import type { RollupPluginHooks } from './typeUtils'
import { getDefaultResolvedEnvironmentOptions } from './server/environment'

export interface BuildEnvironmentOptions {
/**
Expand Down
13 changes: 0 additions & 13 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <K extends keyof Plugin>(
hookName: K,
Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
13 changes: 6 additions & 7 deletions packages/vite/src/node/plugins/optimizedDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 14 additions & 2 deletions packages/vite/src/node/server/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ 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 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'
Expand All @@ -18,6 +16,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'
Expand All @@ -32,6 +31,19 @@ import {
import type { RemoteEnvironmentTransport } from './environmentTransport'
import { isWebSocketServer } from './ws'

export function getDefaultResolvedEnvironmentOptions(
config: ResolvedConfig,
): ResolvedEnvironmentOptions {
return {
define: config.define,
resolve: config.resolve,
consumer: 'server',
webCompatible: false,
dev: config.dev,
build: config.build,
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to move this one level up to /node/baseEnvironment so we don't need to include /server/ from build.ts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, done 👍

export interface DevEnvironmentContext {
hot: false | HotChannel
options?: EnvironmentOptions
Expand Down
7 changes: 5 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 7 additions & 6 deletions packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down