import VirtualModulesPlugin from "webpack-virtual-modules"; import { CompilationContext, JsPlugin } from "@farmfe/core"; import { RsbuildPlugin } from "@rsbuild/core"; import { Compilation, Compiler as RspackCompiler, LoaderContext, RspackPluginInstance } from "@rspack/core"; import { BunPlugin, Loader, PluginBuilder } from "bun"; import { BuildOptions, Loader as Loader$1, Plugin as EsbuildPlugin, PluginBuild } from "esbuild"; import { Plugin as RolldownPlugin } from "rolldown"; import { EmittedAsset, Plugin as RollupPlugin, PluginContextMeta, SourceMapInput } from "rollup"; import { Plugin as UnloaderPlugin } from "unloader"; import { Plugin as VitePlugin } from "vite"; import { Compilation as Compilation$1, Compiler as WebpackCompiler, LoaderContext as LoaderContext$1, WebpackPluginInstance } from "webpack"; //#region src/types.d.ts type Thenable = T | Promise; /** * Null or whatever */ type Nullable = T | null | undefined; /** * Array, or not yet */ type Arrayable = T | Array; interface SourceMapCompact { file?: string | undefined; mappings: string; names: string[]; sourceRoot?: string | undefined; sources: string[]; sourcesContent?: (string | null)[] | undefined; version: number; } type TransformResult = string | { code: string; map?: SourceMapInput | SourceMapCompact | null | undefined; } | null | undefined | void; interface ExternalIdResult { id: string; external?: boolean | undefined; } type NativeBuildContext = { framework: "webpack"; compiler: WebpackCompiler; compilation?: Compilation$1 | undefined; loaderContext?: LoaderContext$1<{ unpluginName: string; }> | undefined; inputSourceMap?: any; } | { framework: "esbuild"; build: PluginBuild; } | { framework: "rspack"; compiler: RspackCompiler; compilation: Compilation; loaderContext?: LoaderContext | undefined; inputSourceMap?: any; } | { framework: "farm"; context: CompilationContext; } | { framework: "bun"; build: PluginBuilder; }; interface UnpluginBuildContext { addWatchFile: (id: string) => void; emitFile: (emittedFile: EmittedAsset) => void; getWatchFiles: () => string[]; parse: (input: string, options?: any) => any; getNativeBuildContext?: (() => NativeBuildContext) | undefined; } type StringOrRegExp = string | RegExp; type FilterPattern = Arrayable; type StringFilter = FilterPattern | { include?: FilterPattern | undefined; exclude?: FilterPattern | undefined; }; interface HookFilter { id?: StringFilter | undefined; code?: StringFilter | undefined; } interface ObjectHook { filter?: Pick | undefined; handler: T; } type Hook = T | ObjectHook; interface HookFnMap { buildStart: (this: UnpluginBuildContext) => Thenable; buildEnd: (this: UnpluginBuildContext) => Thenable; transform: (this: UnpluginBuildContext & UnpluginContext, code: string, id: string) => Thenable; load: (this: UnpluginBuildContext & UnpluginContext, id: string) => Thenable; resolveId: (this: UnpluginBuildContext & UnpluginContext, id: string, importer: string | undefined, options: { isEntry: boolean; }) => Thenable; writeBundle: (this: void) => Thenable; } interface UnpluginOptions { name: string; enforce?: "post" | "pre" | undefined; buildStart?: HookFnMap["buildStart"] | undefined; buildEnd?: HookFnMap["buildEnd"] | undefined; transform?: Hook | undefined; load?: Hook | undefined; resolveId?: Hook | undefined; writeBundle?: HookFnMap["writeBundle"] | undefined; watchChange?: ((this: UnpluginBuildContext, id: string, change: { event: "create" | "update" | "delete"; }) => void) | undefined; /** * Custom predicate function to filter modules to be loaded. * When omitted, all modules will be included (might have potential perf impact on Webpack). * * @deprecated Use `load.filter` instead. */ loadInclude?: ((id: string) => boolean | null | undefined) | undefined; /** * Custom predicate function to filter modules to be transformed. * When omitted, all modules will be included (might have potential perf impact on Webpack). * * @deprecated Use `transform.filter` instead. */ transformInclude?: ((id: string) => boolean | null | undefined) | undefined; rollup?: Partial | undefined; webpack?: ((compiler: WebpackCompiler) => void) | undefined; rspack?: ((compiler: RspackCompiler) => void) | undefined; rsbuild?: Partial | undefined; vite?: Partial | undefined; unloader?: Partial | undefined; rolldown?: Partial | undefined; esbuild?: { onResolveFilter?: RegExp | undefined; onLoadFilter?: RegExp | undefined; loader?: Loader$1 | ((code: string, id: string) => Loader$1) | undefined; setup?: ((build: PluginBuild) => void | Promise) | undefined; config?: ((options: BuildOptions) => void) | undefined; } | undefined; farm?: Partial | undefined; bun?: { loader?: Loader | ((code: string, id: string) => Loader) | undefined; setup?: ((build: PluginBuilder) => void | Promise) | undefined; } | undefined; } interface ResolvedUnpluginOptions extends UnpluginOptions { __vfs?: VirtualModulesPlugin | undefined; __vfsModules?: Map> | Set | undefined; __virtualModulePrefix: string; } type UnpluginFactory = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array : UnpluginOptions; type UnpluginFactoryOutput = undefined extends UserOptions ? (options?: UserOptions | undefined) => Return : (options: UserOptions) => Return; interface UnpluginInstance { rollup: UnpluginFactoryOutput : RollupPlugin>; vite: UnpluginFactoryOutput : VitePlugin>; rolldown: UnpluginFactoryOutput : RolldownPlugin>; webpack: UnpluginFactoryOutput; rspack: UnpluginFactoryOutput; rsbuild: UnpluginFactoryOutput : RsbuildPlugin>; esbuild: UnpluginFactoryOutput; unloader: UnpluginFactoryOutput : UnloaderPlugin>; farm: UnpluginFactoryOutput; bun: UnpluginFactoryOutput; raw: UnpluginFactory; } type SupportedFramework = "rollup" | "vite" | "rolldown" | "farm" | "unloader" | "webpack" | "rspack" | "rsbuild" | "esbuild" | "bun"; type UnpluginContextMeta = Partial & { /** * Version information for frameworks. * Access the current framework version via: `meta.versions[meta.framework]` * * For Vite, includes both Vite's version and the underlying bundler (Rollup/Rolldown). * For Rollup-compatible frameworks (vite, rollup, rolldown, unloader), * versions are only available after the `buildStart` hook. * * The `unplugin` version is always available for all frameworks. */ versions: Partial>; } & ({ framework: "rollup" | "vite" | "rolldown" | "farm" | "unloader"; } | { framework: "webpack"; webpack: { compiler: WebpackCompiler; }; } | { framework: "esbuild"; /** Set the host plugin name of esbuild when returning multiple plugins */ esbuildHostName?: string | undefined; } | { framework: "bun"; /** Set the host plugin name of bun when returning multiple plugins */ bunHostName?: string | undefined; } | { framework: "rspack"; rspack: { compiler: RspackCompiler; }; } | { framework: "rsbuild"; }); interface UnpluginMessage { name?: string | undefined; id?: string | undefined; message: string; stack?: string | undefined; code?: string | undefined; plugin?: string | undefined; pluginCode?: unknown | undefined; loc?: { column: number; file?: string | undefined; line: number; } | undefined; meta?: any; } interface UnpluginContext { error: (message: string | UnpluginMessage) => void; warn: (message: string | UnpluginMessage) => void; } //#endregion //#region src/define.d.ts declare function createUnplugin(factory: UnpluginFactory): UnpluginInstance; declare function createEsbuildPlugin(factory: UnpluginFactory): UnpluginInstance["esbuild"]; declare function createRollupPlugin(factory: UnpluginFactory): UnpluginInstance["rollup"]; declare function createVitePlugin(factory: UnpluginFactory): UnpluginInstance["vite"]; declare function createRolldownPlugin(factory: UnpluginFactory): UnpluginInstance["rolldown"]; declare function createWebpackPlugin(factory: UnpluginFactory): UnpluginInstance["webpack"]; declare function createRspackPlugin(factory: UnpluginFactory): UnpluginInstance["rspack"]; declare function createRsbuildPlugin(factory: UnpluginFactory): UnpluginInstance["rsbuild"]; declare function createFarmPlugin(factory: UnpluginFactory): UnpluginInstance["farm"]; declare function createUnloaderPlugin(factory: UnpluginFactory): UnpluginInstance["unloader"]; declare function createBunPlugin(factory: UnpluginFactory): UnpluginInstance["bun"]; //#endregion //#region src/utils/parse.d.ts declare function setParseImpl(customParse: (code: string, opts?: any) => any): void; //#endregion //#region src/index.d.ts declare const version: string; //#endregion export { Arrayable, type BunPlugin, type EsbuildPlugin, ExternalIdResult, FilterPattern, Hook, HookFilter, HookFnMap, NativeBuildContext, Nullable, ObjectHook, ResolvedUnpluginOptions, type RolldownPlugin, type RollupPlugin, type RsbuildPlugin, type RspackCompiler, type RspackPluginInstance, SourceMapCompact, StringFilter, StringOrRegExp, SupportedFramework, Thenable, TransformResult, type UnloaderPlugin, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginMessage, UnpluginOptions, type VitePlugin, type WebpackCompiler, type WebpackPluginInstance, createBunPlugin, createEsbuildPlugin, createFarmPlugin, createRolldownPlugin, createRollupPlugin, createRsbuildPlugin, createRspackPlugin, createUnloaderPlugin, createUnplugin, createVitePlugin, createWebpackPlugin, setParseImpl, version };