import { ParserOptions } from '@babel/parser'; import { Program, Node } from '@babel/types'; import { FilterPattern } from '@rollup/pluginutils'; // utils type NullValue = null | undefined | void; type MaybePromise = T | Promise; type PartialNull = { [P in keyof T]: T[P] | null; }; interface RollupError extends RollupLog { name?: string; stack?: string; watchFiles?: string[]; } type RollupWarning = RollupLog; interface RollupLog { binding?: string; cause?: unknown; code?: string; exporter?: string; frame?: string; hook?: string; id?: string; ids?: string[]; loc?: { column: number; file?: string; line: number; }; message: string; names?: string[]; plugin?: string; pluginCode?: string; pos?: number; reexporter?: string; stack?: string; url?: string; } type SourceMapSegment = | [number] | [number, number, number, number] | [number, number, number, number, number]; interface ExistingDecodedSourceMap { file?: string; mappings: SourceMapSegment[][]; names: string[]; sourceRoot?: string; sources: string[]; sourcesContent?: (string | null)[]; version: number; x_google_ignoreList?: number[]; } interface ExistingRawSourceMap { file?: string; mappings: string; names: string[]; sourceRoot?: string; sources: string[]; sourcesContent?: (string | null)[]; version: number; x_google_ignoreList?: number[]; } type DecodedSourceMapOrMissing = | { mappings?: never; missing: true; plugin: string; } | ExistingDecodedSourceMap; interface SourceMap { file: string; mappings: string; names: string[]; sources: string[]; sourcesContent: (string | null)[]; version: number; toString(): string; toUrl(): string; } type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' }; interface ModuleOptions { assertions: Record; meta: CustomPluginOptions; moduleSideEffects: boolean | 'no-treeshake'; syntheticNamedExports: boolean | string; } interface SourceDescription extends Partial> { ast?: AcornNode; code: string; map?: SourceMapInput; } interface TransformModuleJSON { ast?: AcornNode; code: string; // note if plugins use new this.cache to opt-out auto transform cache customTransformCache: boolean; originalCode: string; originalSourcemap: ExistingDecodedSourceMap | null; sourcemapChain: DecodedSourceMapOrMissing[]; transformDependencies: string[]; } interface ModuleJSON extends TransformModuleJSON, ModuleOptions { ast: AcornNode; dependencies: string[]; id: string; resolvedIds: ResolvedIdMap; transformFiles: EmittedFile[] | undefined; } interface PluginCache { delete(id: string): boolean; get(id: string): T; has(id: string): boolean; set(id: string, value: T): void; } interface MinimalPluginContext { meta: PluginContextMeta; } interface EmittedAsset { fileName?: string; name?: string; needsCodeReference?: boolean; source?: string | Uint8Array; type: 'asset'; } interface EmittedChunk { fileName?: string; id: string; implicitlyLoadedAfterOneOf?: string[]; importer?: string; name?: string; preserveSignature?: PreserveEntrySignaturesOption; type: 'chunk'; } interface EmittedPrebuiltChunk { code: string; exports?: string[]; fileName: string; map?: SourceMap; type: 'prebuilt-chunk'; } type EmittedFile = EmittedAsset | EmittedChunk | EmittedPrebuiltChunk; type EmitFile = (emittedFile: EmittedFile) => string; interface ModuleInfo extends ModuleOptions { ast: AcornNode | null; code: string | null; dynamicImporters: readonly string[]; dynamicallyImportedIdResolutions: readonly ResolvedId[]; dynamicallyImportedIds: readonly string[]; exportedBindings: Record | null; exports: string[] | null; hasDefaultExport: boolean | null; /** @deprecated Use `moduleSideEffects` instead */ hasModuleSideEffects: boolean | 'no-treeshake'; id: string; implicitlyLoadedAfterOneOf: readonly string[]; implicitlyLoadedBefore: readonly string[]; importedIdResolutions: readonly ResolvedId[]; importedIds: readonly string[]; importers: readonly string[]; isEntry: boolean; isExternal: boolean; isIncluded: boolean | null; } type GetModuleInfo = (moduleId: string) => ModuleInfo | null; interface CustomPluginOptions { [plugin: string]: any; } interface PluginContext extends MinimalPluginContext { addWatchFile: (id: string) => void; cache: PluginCache; emitFile: EmitFile; error: (error: RollupError | string, pos?: number | { column: number; line: number }) => never; getFileName: (fileReferenceId: string) => string; getModuleIds: () => IterableIterator; getModuleInfo: GetModuleInfo; getWatchFiles: () => string[]; load: ( options: { id: string; resolveDependencies?: boolean } & Partial> ) => Promise; /** @deprecated Use `this.getModuleIds` instead */ moduleIds: IterableIterator; parse: (input: string, options?: any) => AcornNode; resolve: ( source: string, importer?: string, options?: { assertions?: Record; custom?: CustomPluginOptions; isEntry?: boolean; skipSelf?: boolean; } ) => Promise; setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void; warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void; } interface PluginContextMeta { rollupVersion: string; watchMode: boolean; } interface ResolvedId extends ModuleOptions { external: boolean | 'absolute'; id: string; resolvedBy: string; } interface ResolvedIdMap { [key: string]: ResolvedId; } interface PartialResolvedId extends Partial> { external?: boolean | 'absolute' | 'relative'; id: string; resolvedBy?: string; } type ResolveIdResult = string | NullValue | false | PartialResolvedId; type ResolveIdHook = ( this: PluginContext, source: string, importer: string | undefined, options: { assertions: Record; custom?: CustomPluginOptions; isEntry: boolean } ) => ResolveIdResult; type ShouldTransformCachedModuleHook = ( this: PluginContext, options: { ast: AcornNode; code: string; id: string; meta: CustomPluginOptions; moduleSideEffects: boolean | 'no-treeshake'; resolvedSources: ResolvedIdMap; syntheticNamedExports: boolean | string; } ) => boolean | NullValue; type IsExternal = ( source: string, importer: string | undefined, isResolved: boolean ) => boolean; type HasModuleSideEffects = (id: string, external: boolean) => boolean; type LoadResult = SourceDescription | string | NullValue; type LoadHook = (this: PluginContext, id: string) => LoadResult; interface TransformPluginContext extends PluginContext { getCombinedSourcemap: () => SourceMap; } type TransformResult = string | NullValue | Partial; type TransformHook = ( this: TransformPluginContext, code: string, id: string ) => TransformResult; type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => void; type RenderChunkHook = ( this: PluginContext, code: string, chunk: RenderedChunk, options: NormalizedOutputOptions, meta: { chunks: Record } ) => { code: string; map?: SourceMapInput } | string | NullValue; type ResolveDynamicImportHook = ( this: PluginContext, specifier: string | AcornNode, importer: string, options: { assertions: Record } ) => ResolveIdResult; type ResolveImportMetaHook = ( this: PluginContext, property: string | null, options: { chunkId: string; format: InternalModuleFormat; moduleId: string } ) => string | NullValue; type ResolveFileUrlHook = ( this: PluginContext, options: { chunkId: string; fileName: string; format: InternalModuleFormat; moduleId: string; referenceId: string; relativePath: string; } ) => string | NullValue; type AddonHookFunction = ( this: PluginContext, chunk: RenderedChunk ) => string | Promise; type AddonHook = string | AddonHookFunction; type ChangeEvent = 'create' | 'update' | 'delete'; type WatchChangeHook = ( this: PluginContext, id: string, change: { event: ChangeEvent } ) => void; interface OutputBundle { [fileName: string]: OutputAsset | OutputChunk; } interface FunctionPluginHooks { augmentChunkHash: (this: PluginContext, chunk: RenderedChunk) => string | void; buildEnd: (this: PluginContext, error?: Error) => void; buildStart: (this: PluginContext, options: NormalizedInputOptions) => void; closeBundle: (this: PluginContext) => void; closeWatcher: (this: PluginContext) => void; generateBundle: ( this: PluginContext, options: NormalizedOutputOptions, bundle: OutputBundle, isWrite: boolean ) => void; load: LoadHook; moduleParsed: ModuleParsedHook; options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | NullValue; outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | NullValue; renderChunk: RenderChunkHook; renderDynamicImport: ( this: PluginContext, options: { customResolution: string | null; format: InternalModuleFormat; moduleId: string; targetModuleId: string | null; } ) => { left: string; right: string } | NullValue; renderError: (this: PluginContext, error?: Error) => void; renderStart: ( this: PluginContext, outputOptions: NormalizedOutputOptions, inputOptions: NormalizedInputOptions ) => void; resolveDynamicImport: ResolveDynamicImportHook; resolveFileUrl: ResolveFileUrlHook; resolveId: ResolveIdHook; resolveImportMeta: ResolveImportMetaHook; shouldTransformCachedModule: ShouldTransformCachedModuleHook; transform: TransformHook; watchChange: WatchChangeHook; writeBundle: ( this: PluginContext, options: NormalizedOutputOptions, bundle: OutputBundle ) => void; } type OutputPluginHooks = | 'augmentChunkHash' | 'generateBundle' | 'outputOptions' | 'renderChunk' | 'renderDynamicImport' | 'renderError' | 'renderStart' | 'resolveFileUrl' | 'resolveImportMeta' | 'writeBundle'; type SyncPluginHooks = | 'augmentChunkHash' | 'outputOptions' | 'renderDynamicImport' | 'resolveFileUrl' | 'resolveImportMeta'; type AsyncPluginHooks = Exclude; type FirstPluginHooks = | 'load' | 'renderDynamicImport' | 'resolveDynamicImport' | 'resolveFileUrl' | 'resolveId' | 'resolveImportMeta' | 'shouldTransformCachedModule'; type SequentialPluginHooks = | 'augmentChunkHash' | 'generateBundle' | 'options' | 'outputOptions' | 'renderChunk' | 'transform'; type ParallelPluginHooks = Exclude< keyof FunctionPluginHooks | AddonHooks, FirstPluginHooks | SequentialPluginHooks >; type AddonHooks = 'banner' | 'footer' | 'intro' | 'outro'; type MakeAsync = Function_ extends ( this: infer This, ...parameters: infer Arguments ) => infer Return ? (this: This, ...parameters: Arguments) => Return | Promise : never; // eslint-disable-next-line @typescript-eslint/ban-types type ObjectHook = T | ({ handler: T; order?: 'pre' | 'post' | null } & O); type PluginHooks = { [K in keyof FunctionPluginHooks]: ObjectHook< K extends AsyncPluginHooks ? MakeAsync : FunctionPluginHooks[K], // eslint-disable-next-line @typescript-eslint/ban-types K extends ParallelPluginHooks ? { sequential?: boolean } : {} >; }; interface OutputPlugin extends Partial<{ [K in OutputPluginHooks]: PluginHooks[K] }>, Partial<{ [K in AddonHooks]: ObjectHook }> { cacheKey?: string; name: string; version?: string; } interface Plugin extends OutputPlugin, Partial { // for inter-plugin communication api?: any; } type TreeshakingPreset = 'smallest' | 'safest' | 'recommended'; interface NormalizedTreeshakingOptions { annotations: boolean; correctVarValueBeforeDeclaration: boolean; manualPureFunctions: readonly string[]; moduleSideEffects: HasModuleSideEffects; propertyReadSideEffects: boolean | 'always'; tryCatchDeoptimization: boolean; unknownGlobalSideEffects: boolean; } interface TreeshakingOptions extends Partial> { moduleSideEffects?: ModuleSideEffectsOption; preset?: TreeshakingPreset; } interface ManualChunkMeta { getModuleIds: () => IterableIterator; getModuleInfo: GetModuleInfo; } type GetManualChunk = (id: string, meta: ManualChunkMeta) => string | NullValue; type ExternalOption = | (string | RegExp)[] | string | RegExp | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | NullValue); type GlobalsOption = { [name: string]: string } | ((name: string) => string); type InputOption = string | string[] | { [entryAlias: string]: string }; type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk; type ModuleSideEffectsOption = boolean | 'no-external' | string[] | HasModuleSideEffects; type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only'; type SourcemapPathTransformOption = ( relativeSourcePath: string, sourcemapPath: string ) => string; type SourcemapIgnoreListOption = ( relativeSourcePath: string, sourcemapPath: string ) => boolean; type InputPluginOption = MaybePromise; interface InputOptions { acorn?: Record; acornInjectPlugins?: ((...arguments_: any[]) => unknown)[] | ((...arguments_: any[]) => unknown); cache?: boolean | RollupCache; context?: string; experimentalCacheExpiry?: number; experimentalLogSideEffects?: boolean; external?: ExternalOption; /** @deprecated Use the "inlineDynamicImports" output option instead. */ inlineDynamicImports?: boolean; input?: InputOption; makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource'; /** @deprecated Use the "manualChunks" output option instead. */ manualChunks?: ManualChunksOption; maxParallelFileOps?: number; /** @deprecated Use the "maxParallelFileOps" option instead. */ maxParallelFileReads?: number; moduleContext?: ((id: string) => string | NullValue) | { [id: string]: string }; onwarn?: WarningHandlerWithDefault; perf?: boolean; plugins?: InputPluginOption; preserveEntrySignatures?: PreserveEntrySignaturesOption; /** @deprecated Use the "preserveModules" output option instead. */ preserveModules?: boolean; preserveSymlinks?: boolean; shimMissingExports?: boolean; strictDeprecations?: boolean; treeshake?: boolean | TreeshakingPreset | TreeshakingOptions; watch?: WatcherOptions | false; } interface NormalizedInputOptions { acorn: Record; acornInjectPlugins: (() => unknown)[]; cache: false | undefined | RollupCache; context: string; experimentalCacheExpiry: number; experimentalLogSideEffects: boolean; external: IsExternal; /** @deprecated Use the "inlineDynamicImports" output option instead. */ inlineDynamicImports: boolean | undefined; input: string[] | { [entryAlias: string]: string }; makeAbsoluteExternalsRelative: boolean | 'ifRelativeSource'; /** @deprecated Use the "manualChunks" output option instead. */ manualChunks: ManualChunksOption | undefined; maxParallelFileOps: number; /** @deprecated Use the "maxParallelFileOps" option instead. */ maxParallelFileReads: number; moduleContext: (id: string) => string; onwarn: WarningHandler; perf: boolean; plugins: Plugin[]; preserveEntrySignatures: PreserveEntrySignaturesOption; /** @deprecated Use the "preserveModules" output option instead. */ preserveModules: boolean | undefined; preserveSymlinks: boolean; shimMissingExports: boolean; strictDeprecations: boolean; treeshake: false | NormalizedTreeshakingOptions; } type InternalModuleFormat = 'amd' | 'cjs' | 'es' | 'iife' | 'system' | 'umd'; type ModuleFormat = InternalModuleFormat | 'commonjs' | 'esm' | 'module' | 'systemjs'; type GeneratedCodePreset = 'es5' | 'es2015'; interface NormalizedGeneratedCodeOptions { arrowFunctions: boolean; constBindings: boolean; objectShorthand: boolean; reservedNamesAsProps: boolean; symbols: boolean; } interface GeneratedCodeOptions extends Partial { preset?: GeneratedCodePreset; } type OptionsPaths = Record | ((id: string) => string); type InteropType = 'compat' | 'auto' | 'esModule' | 'default' | 'defaultOnly'; type GetInterop = (id: string | null) => InteropType; type AmdOptions = ( | { autoId?: false; id: string; } | { autoId: true; basePath?: string; id?: undefined; } | { autoId?: false; id?: undefined; } ) & { define?: string; forceJsExtensionForImports?: boolean; }; type NormalizedAmdOptions = ( | { autoId: false; id?: string; } | { autoId: true; basePath: string; } ) & { define: string; forceJsExtensionForImports: boolean; }; type AddonFunction = (chunk: RenderedChunk) => string | Promise; type OutputPluginOption = MaybePromise; interface OutputOptions { amd?: AmdOptions; assetFileNames?: string | ((chunkInfo: PreRenderedAsset) => string); banner?: string | AddonFunction; chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); compact?: boolean; // only required for bundle.write dir?: string; /** @deprecated Use the "renderDynamicImport" plugin hook instead. */ dynamicImportFunction?: string; dynamicImportInCjs?: boolean; entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); esModule?: boolean | 'if-default-prop'; /** @deprecated This option is no longer needed and ignored. */ experimentalDeepDynamicChunkOptimization?: boolean; experimentalMinChunkSize?: number; exports?: 'default' | 'named' | 'none' | 'auto'; extend?: boolean; externalImportAssertions?: boolean; externalLiveBindings?: boolean; // only required for bundle.write file?: string; footer?: string | AddonFunction; format?: ModuleFormat; freeze?: boolean; generatedCode?: GeneratedCodePreset | GeneratedCodeOptions; globals?: GlobalsOption; hoistTransitiveImports?: boolean; indent?: string | boolean; inlineDynamicImports?: boolean; interop?: InteropType | GetInterop; intro?: string | AddonFunction; manualChunks?: ManualChunksOption; minifyInternalExports?: boolean; name?: string; /** @deprecated Use "generatedCode.symbols" instead. */ namespaceToStringTag?: boolean; noConflict?: boolean; outro?: string | AddonFunction; paths?: OptionsPaths; plugins?: OutputPluginOption; /** @deprecated Use "generatedCode.constBindings" instead. */ preferConst?: boolean; preserveModules?: boolean; preserveModulesRoot?: string; sanitizeFileName?: boolean | ((fileName: string) => string); sourcemap?: boolean | 'inline' | 'hidden'; sourcemapBaseUrl?: string; sourcemapExcludeSources?: boolean; sourcemapFile?: string; sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption; sourcemapPathTransform?: SourcemapPathTransformOption; strict?: boolean; systemNullSetters?: boolean; validate?: boolean; } interface NormalizedOutputOptions { amd: NormalizedAmdOptions; assetFileNames: string | ((chunkInfo: PreRenderedAsset) => string); banner: AddonFunction; chunkFileNames: string | ((chunkInfo: PreRenderedChunk) => string); compact: boolean; dir: string | undefined; /** @deprecated Use the "renderDynamicImport" plugin hook instead. */ dynamicImportFunction: string | undefined; dynamicImportInCjs: boolean; entryFileNames: string | ((chunkInfo: PreRenderedChunk) => string); esModule: boolean | 'if-default-prop'; /** @deprecated This option is no longer needed and ignored. */ experimentalDeepDynamicChunkOptimization: boolean; experimentalMinChunkSize: number; exports: 'default' | 'named' | 'none' | 'auto'; extend: boolean; externalImportAssertions: boolean; externalLiveBindings: boolean; file: string | undefined; footer: AddonFunction; format: InternalModuleFormat; freeze: boolean; generatedCode: NormalizedGeneratedCodeOptions; globals: GlobalsOption; hoistTransitiveImports: boolean; indent: true | string; inlineDynamicImports: boolean; interop: GetInterop; intro: AddonFunction; manualChunks: ManualChunksOption; minifyInternalExports: boolean; name: string | undefined; /** @deprecated Use "generatedCode.symbols" instead. */ namespaceToStringTag: boolean; noConflict: boolean; outro: AddonFunction; paths: OptionsPaths; plugins: OutputPlugin[]; /** @deprecated Use "generatedCode.constBindings" instead. */ preferConst: boolean; preserveModules: boolean; preserveModulesRoot: string | undefined; sanitizeFileName: (fileName: string) => string; sourcemap: boolean | 'inline' | 'hidden'; sourcemapBaseUrl: string | undefined; sourcemapExcludeSources: boolean; sourcemapFile: string | undefined; sourcemapIgnoreList: SourcemapIgnoreListOption; sourcemapPathTransform: SourcemapPathTransformOption | undefined; strict: boolean; systemNullSetters: boolean; validate: boolean; } type WarningHandlerWithDefault = ( warning: RollupWarning, defaultHandler: WarningHandler ) => void; type WarningHandler = (warning: RollupWarning) => void; interface PreRenderedAsset { name: string | undefined; source: string | Uint8Array; type: 'asset'; } interface OutputAsset extends PreRenderedAsset { fileName: string; needsCodeReference: boolean; } interface RenderedModule { code: string | null; originalLength: number; removedExports: string[]; renderedExports: string[]; renderedLength: number; } interface PreRenderedChunk { exports: string[]; facadeModuleId: string | null; isDynamicEntry: boolean; isEntry: boolean; isImplicitEntry: boolean; moduleIds: string[]; name: string; type: 'chunk'; } interface RenderedChunk extends PreRenderedChunk { dynamicImports: string[]; fileName: string; implicitlyLoadedBefore: string[]; importedBindings: { [imported: string]: string[]; }; imports: string[]; modules: { [id: string]: RenderedModule; }; referencedFiles: string[]; } interface OutputChunk extends RenderedChunk { code: string; map: SourceMap | null; } interface SerializablePluginCache { [key: string]: [number, any]; } interface RollupCache { modules: ModuleJSON[]; plugins?: Record; } interface ChokidarOptions { alwaysStat?: boolean; atomic?: boolean | number; awaitWriteFinish?: | { pollInterval?: number; stabilityThreshold?: number; } | boolean; binaryInterval?: number; cwd?: string; depth?: number; disableGlobbing?: boolean; followSymlinks?: boolean; ignoreInitial?: boolean; ignorePermissionErrors?: boolean; ignored?: any; interval?: number; persistent?: boolean; useFsEvents?: boolean; usePolling?: boolean; } interface WatcherOptions { buildDelay?: number; chokidar?: ChokidarOptions; clearScreen?: boolean; exclude?: string | RegExp | (string | RegExp)[]; include?: string | RegExp | (string | RegExp)[]; skipWrite?: boolean; } interface AcornNode { end: number; start: number; type: string; } interface ScriptTagMeta { start: number; end: number; contentStart: number; contentEnd: number; content: string; attrs: Record; found: boolean; ast: Program; } interface ParsedSFC { id?: string; template: { /** foo-bar -> FooBar */ components: Set; /** v-foo-bar -> fooBar */ directives: Set; identifiers: Set; }; scriptSetup: ScriptTagMeta; script: ScriptTagMeta; parserOptions: ParserOptions; extraDeclarations: Node[]; } interface ScriptSetupTransformOptions { astTransforms?: { script?: (ast: Program) => Program; scriptSetup?: (ast: Program) => Program; post?: (ast: Program, sfc: ParsedSFC) => Program; }; reactivityTransform?: boolean; importHelpersFrom?: string; sourceMap?: boolean; } interface PluginOptions extends ScriptSetupTransformOptions { include?: FilterPattern; exclude?: FilterPattern; } declare const _default: (options: PluginOptions) => Plugin | Plugin[]; export { _default as default };