Skip to content

Commit c980632

Browse files
committedNov 29, 2024
feat!: drop meta.build for esbuild
Use `this.getNativeBuildContext` instead
1 parent b35b88b commit c980632

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed
 

‎src/esbuild/index.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export interface EsbuildPluginBuild extends PluginBuild {
4141
onTransform: (options: OnTransformOptions, callback: OnTransformCallback) => void
4242
}
4343

44+
interface Loader {
45+
options?: OnLoadOptions
46+
onLoadCb?: Parameters<PluginBuild['onLoad']>[1]
47+
onTransformCb?: OnTransformCallback
48+
}
49+
4450
export function getEsbuildPlugin<UserOptions = Record<string, never>>(
4551
factory: UnpluginFactory<UserOptions>,
4652
): UnpluginInstance<UserOptions>['esbuild'] {
@@ -51,12 +57,7 @@ export function getEsbuildPlugin<UserOptions = Record<string, never>>(
5157
const plugins = toArray(factory(userOptions!, meta))
5258

5359
const setupPlugins: EsbuildPlugin['setup'] = async (build) => {
54-
const setup = buildSetup(meta)
55-
interface Loader {
56-
options?: OnLoadOptions
57-
onLoadCb?: Parameters<PluginBuild['onLoad']>[1]
58-
onTransformCb?: OnTransformCallback
59-
}
60+
const setup = buildSetup()
6061
const loaders: Loader[] = []
6162

6263
for (const plugin of plugins) {
@@ -139,20 +140,18 @@ export function getEsbuildPlugin<UserOptions = Record<string, never>>(
139140
}
140141
}
141142

142-
function buildSetup(meta: UnpluginContextMeta & { framework: 'esbuild' }) {
143+
function buildSetup() {
143144
return (plugin: UnpluginOptions): EsbuildPlugin['setup'] => {
144145
return (_build) => {
145-
const build = meta.build = _build as EsbuildPluginBuild
146+
const build = _build as EsbuildPluginBuild
146147
const context = createBuildContext(build)
147148
const { onStart, onEnd, onResolve, onLoad, onTransform, initialOptions } = build
148149

149150
const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/
150151
const onLoadFilter = plugin.esbuild?.onLoadFilter ?? /.*/
151-
152152
const loader = plugin.esbuild?.loader ?? guessLoader
153153

154-
if (plugin.esbuild?.config)
155-
plugin.esbuild.config.call(context, initialOptions)
154+
plugin.esbuild?.config?.call(context, initialOptions)
156155

157156
if (plugin.buildStart)
158157
onStart(() => plugin.buildStart!.call(context))
@@ -306,7 +305,7 @@ function buildSetup(meta: UnpluginContextMeta & { framework: 'esbuild' }) {
306305
}
307306

308307
if (plugin.esbuild?.setup)
309-
return plugin.esbuild.setup(meta.build)
308+
return plugin.esbuild.setup(build)
310309
}
311310
}
312311
}

‎src/types.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export interface UnpluginOptions {
9696
// using regexp in esbuild improves performance
9797
onResolveFilter?: RegExp
9898
onLoadFilter?: RegExp
99-
setup?: (build: EsbuildPluginBuild) => void | Promise<void>
10099
loader?: Loader | ((code: string, id: string) => Loader)
100+
setup?: (build: EsbuildPluginBuild) => void | Promise<void>
101101
config?: (options: BuildOptions) => void
102102
}
103103
farm?: Partial<FarmPlugin>
@@ -136,8 +136,6 @@ export type UnpluginContextMeta = Partial<RollupContextMeta> & ({
136136
webpack: { compiler: WebpackCompiler }
137137
} | {
138138
framework: 'esbuild'
139-
/** @deprecated {getNativeBuildContext} */
140-
build?: EsbuildPluginBuild
141139
/** Set the host plugin name of esbuild when returning multiple plugins */
142140
esbuildHostName?: string
143141
} | {

0 commit comments

Comments
 (0)
Please sign in to comment.