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

feat: support this.environment in options and onLog hook #18142

Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import { mergeConfig } from './publicUtils'
import { webWorkerPostPlugin } from './plugins/worker'
import { getHookHandler } from './plugins'
import { BaseEnvironment } from './baseEnvironment'
import type { Plugin, PluginContext } from './plugin'
import type { MinimalPluginContext, Plugin, PluginContext } from './plugin'
import type { RollupPluginHooks } from './typeUtils'

export interface BuildEnvironmentOptions {
Expand Down Expand Up @@ -1253,7 +1253,7 @@ function wrapEnvironmentHook<HookName extends keyof Plugin>(
}
}

function injectEnvironmentInContext<Context extends PluginContext>(
function injectEnvironmentInContext<Context extends MinimalPluginContext>(
context: Context,
environment: BuildEnvironment,
) {
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { version } = JSON.parse(
)

export const ROLLUP_HOOKS = [
'options',
'buildStart',
'buildEnd',
'renderStart',
Expand All @@ -33,6 +34,7 @@ export const ROLLUP_HOOKS = [
'resolveId',
'shouldTransformCachedModule',
'transform',
'onLog',
] satisfies RollupPluginHooks[]

export const VERSION = version as string
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
LoadResult,
ObjectHook,
ResolveIdResult,
MinimalPluginContext as RollupMinimalPluginContext,
Plugin as RollupPlugin,
PluginContext as RollupPluginContext,
TransformPluginContext as RollupTransformPluginContext,
Expand Down Expand Up @@ -61,6 +62,10 @@ export interface HotUpdatePluginContext {
environment: DevEnvironment
}

export interface MinimalPluginContext
extends RollupMinimalPluginContext,
PluginContextExtension {}

export interface PluginContext
extends RollupPluginContext,
PluginContextExtension {}
Expand All @@ -75,7 +80,7 @@ export interface TransformPluginContext

// Argument Rollup types to have the PluginContextExtension
declare module 'rollup' {
export interface PluginContext extends PluginContextExtension {}
export interface MinimalPluginContext extends PluginContextExtension {}
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class EnvironmentPluginContainer {
warn: noop,
// @ts-expect-error noop
error: noop,
environment,
}
const utils = createPluginHookUtils(plugins)
this.getSortedPlugins = utils.getSortedPlugins
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/typeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
ObjectHook,
MinimalPluginContext as RollupMinimalPluginContext,
Plugin as RollupPlugin,
PluginContext as RollupPluginContext,
} from 'rollup'

export type NonNeverKeys<T> = {
Expand All @@ -11,7 +11,7 @@ export type NonNeverKeys<T> = {
export type GetHookContextMap<Plugin> = {
[K in keyof Plugin]-?: Plugin[K] extends ObjectHook<infer T, unknown>
? T extends (this: infer This, ...args: any[]) => any
? This extends RollupPluginContext
? This extends RollupMinimalPluginContext
? This
: never
: never
Expand Down