|
1 | 1 | import type { AstNode, EmittedAsset, PluginContextMeta as RollupContextMeta, Plugin as RollupPlugin, SourceMapInput } from 'rollup' |
2 | | -import type { Compiler as WebpackCompiler, WebpackPluginInstance } from 'webpack' |
| 2 | +import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, LoaderContext as WebpackLoaderContext, WebpackPluginInstance } from 'webpack' |
3 | 3 | import type { Plugin as VitePlugin } from 'vite' |
4 | 4 | import type { Plugin as RolldownPlugin } from 'rolldown' |
5 | 5 | import type { BuildOptions, Plugin as EsbuildPlugin, Loader } from 'esbuild' |
6 | | -import type { Compiler as RspackCompiler, RspackPluginInstance } from '@rspack/core' |
| 6 | +import type { Compilation as RspackCompilation, Compiler as RspackCompiler, LoaderContext as RspackLoaderContext, RspackPluginInstance } from '@rspack/core' |
7 | 7 | import type VirtualModulesPlugin from 'webpack-virtual-modules' |
8 | | -import type { JsPlugin as FarmPlugin } from '@farmfe/core' |
| 8 | +import type { CompilationContext as FarmCompilationContext, JsPlugin as FarmPlugin } from '@farmfe/core' |
9 | 9 | import type { EsbuildPluginBuild } from './esbuild' |
10 | 10 |
|
11 | 11 | export { |
@@ -40,11 +40,18 @@ export type TransformResult = string | { code: string, map?: SourceMapInput | So |
40 | 40 |
|
41 | 41 | export interface ExternalIdResult { id: string, external?: boolean } |
42 | 42 |
|
| 43 | +export type NativeBuildContext = |
| 44 | + { framework: 'webpack', compiler: WebpackCompiler, compilation?: WebpackCompilation, loaderContext?: WebpackLoaderContext<{ unpluginName: string }> } | |
| 45 | + { framework: 'esbuild', build: EsbuildPluginBuild } | |
| 46 | + { framework: 'rspack', compiler: RspackCompiler, compilation: RspackCompilation, loaderContext?: RspackLoaderContext } | |
| 47 | + { framework: 'farm', context: FarmCompilationContext } |
| 48 | + |
43 | 49 | export interface UnpluginBuildContext { |
44 | 50 | addWatchFile: (id: string) => void |
45 | 51 | emitFile: (emittedFile: EmittedAsset) => void |
46 | 52 | getWatchFiles: () => string[] |
47 | 53 | parse: (input: string, options?: any) => AstNode |
| 54 | + getNativeBuildContext?: () => NativeBuildContext |
48 | 55 | } |
49 | 56 |
|
50 | 57 | export interface UnpluginOptions { |
@@ -117,24 +124,19 @@ export interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> |
117 | 124 | } |
118 | 125 |
|
119 | 126 | export type UnpluginContextMeta = Partial<RollupContextMeta> & ({ |
120 | | - framework: 'rollup' | 'vite' | 'rolldown' |
| 127 | + framework: 'rollup' | 'vite' | 'rolldown' | 'farm' |
121 | 128 | } | { |
122 | 129 | framework: 'webpack' |
123 | | - webpack: { |
124 | | - compiler: WebpackCompiler |
125 | | - } |
| 130 | + webpack: { compiler: WebpackCompiler } |
126 | 131 | } | { |
127 | 132 | framework: 'esbuild' |
| 133 | + /** @deprecated {getNativeBuildContext} */ |
128 | 134 | build?: EsbuildPluginBuild |
129 | 135 | /** Set the host plugin name of esbuild when returning multiple plugins */ |
130 | 136 | esbuildHostName?: string |
131 | 137 | } | { |
132 | 138 | framework: 'rspack' |
133 | | - rspack: { |
134 | | - compiler: RspackCompiler |
135 | | - } |
136 | | -} | { |
137 | | - framework: 'farm' |
| 139 | + rspack: { compiler: RspackCompiler } |
138 | 140 | }) |
139 | 141 |
|
140 | 142 | export interface UnpluginMessage { |
|
0 commit comments