UNPKG

27.9 kBTypeScriptView Raw
1import type { Node as EstreeNode, Program } from 'estree';
2
3export const VERSION: string;
4
5// utils
6type NullValue = null | undefined | void;
7type MaybeArray<T> = T | T[];
8type MaybePromise<T> = T | Promise<T>;
9
10type PartialNull<T> = {
11 [P in keyof T]: T[P] | null;
12};
13
14export interface RollupError extends RollupLog {
15 name?: string;
16 stack?: string;
17 watchFiles?: string[];
18}
19
20export interface RollupLog {
21 binding?: string;
22 cause?: unknown;
23 code?: string;
24 exporter?: string;
25 frame?: string;
26 hook?: string;
27 id?: string;
28 ids?: string[];
29 loc?: {
30 column: number;
31 file?: string;
32 line: number;
33 };
34 message: string;
35 meta?: any;
36 names?: string[];
37 plugin?: string;
38 pluginCode?: unknown;
39 pos?: number;
40 reexporter?: string;
41 stack?: string;
42 url?: string;
43}
44
45export type LogLevel = 'warn' | 'info' | 'debug';
46export type LogLevelOption = LogLevel | 'silent';
47
48export type SourceMapSegment =
49 | [number]
50 | [number, number, number, number]
51 | [number, number, number, number, number];
52
53export interface ExistingDecodedSourceMap {
54 file?: string;
55 readonly mappings: SourceMapSegment[][];
56 names: string[];
57 sourceRoot?: string;
58 sources: string[];
59 sourcesContent?: string[];
60 version: number;
61 x_google_ignoreList?: number[];
62}
63
64export interface ExistingRawSourceMap {
65 file?: string;
66 mappings: string;
67 names: string[];
68 sourceRoot?: string;
69 sources: string[];
70 sourcesContent?: string[];
71 version: number;
72 x_google_ignoreList?: number[];
73}
74
75export type DecodedSourceMapOrMissing =
76 | {
77 missing: true;
78 plugin: string;
79 }
80 | (ExistingDecodedSourceMap & { missing?: false });
81
82export interface SourceMap {
83 file: string;
84 mappings: string;
85 names: string[];
86 sources: string[];
87 sourcesContent?: string[];
88 version: number;
89 toString(): string;
90 toUrl(): string;
91}
92
93export type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' };
94
95interface ModuleOptions {
96 attributes: Record<string, string>;
97 meta: CustomPluginOptions;
98 moduleSideEffects: boolean | 'no-treeshake';
99 syntheticNamedExports: boolean | string;
100}
101
102export interface SourceDescription extends Partial<PartialNull<ModuleOptions>> {
103 ast?: ProgramNode;
104 code: string;
105 map?: SourceMapInput;
106}
107
108export interface TransformModuleJSON {
109 ast?: ProgramNode;
110 code: string;
111 // note if plugins use new this.cache to opt-out auto transform cache
112 customTransformCache: boolean;
113 originalCode: string;
114 originalSourcemap: ExistingDecodedSourceMap | null;
115 sourcemapChain: DecodedSourceMapOrMissing[];
116 transformDependencies: string[];
117}
118
119export interface ModuleJSON extends TransformModuleJSON, ModuleOptions {
120 ast: ProgramNode;
121 dependencies: string[];
122 id: string;
123 resolvedIds: ResolvedIdMap;
124 transformFiles: EmittedFile[] | undefined;
125}
126
127export interface PluginCache {
128 delete(id: string): boolean;
129 get<T = any>(id: string): T;
130 has(id: string): boolean;
131 set<T = any>(id: string, value: T): void;
132}
133
134export type LoggingFunction = (log: RollupLog | string | (() => RollupLog | string)) => void;
135
136export interface MinimalPluginContext {
137 debug: LoggingFunction;
138 error: (error: RollupError | string) => never;
139 info: LoggingFunction;
140 meta: PluginContextMeta;
141 warn: LoggingFunction;
142}
143
144export interface EmittedAsset {
145 fileName?: string;
146 name?: string;
147 needsCodeReference?: boolean;
148 source?: string | Uint8Array;
149 type: 'asset';
150}
151
152export interface EmittedChunk {
153 fileName?: string;
154 id: string;
155 implicitlyLoadedAfterOneOf?: string[];
156 importer?: string;
157 name?: string;
158 preserveSignature?: PreserveEntrySignaturesOption;
159 type: 'chunk';
160}
161
162export interface EmittedPrebuiltChunk {
163 code: string;
164 exports?: string[];
165 fileName: string;
166 map?: SourceMap;
167 sourcemapFileName?: string;
168 type: 'prebuilt-chunk';
169}
170
171export type EmittedFile = EmittedAsset | EmittedChunk | EmittedPrebuiltChunk;
172
173export type EmitFile = (emittedFile: EmittedFile) => string;
174
175interface ModuleInfo extends ModuleOptions {
176 ast: ProgramNode | null;
177 code: string | null;
178 dynamicImporters: readonly string[];
179 dynamicallyImportedIdResolutions: readonly ResolvedId[];
180 dynamicallyImportedIds: readonly string[];
181 exportedBindings: Record<string, string[]> | null;
182 exports: string[] | null;
183 hasDefaultExport: boolean | null;
184 id: string;
185 implicitlyLoadedAfterOneOf: readonly string[];
186 implicitlyLoadedBefore: readonly string[];
187 importedIdResolutions: readonly ResolvedId[];
188 importedIds: readonly string[];
189 importers: readonly string[];
190 isEntry: boolean;
191 isExternal: boolean;
192 isIncluded: boolean | null;
193}
194
195export type GetModuleInfo = (moduleId: string) => ModuleInfo | null;
196
197export interface CustomPluginOptions {
198 [plugin: string]: any;
199}
200
201type LoggingFunctionWithPosition = (
202 log: RollupLog | string | (() => RollupLog | string),
203 pos?: number | { column: number; line: number }
204) => void;
205
206export type ParseAst = (
207 input: string,
208 options?: { allowReturnOutsideFunction?: boolean }
209) => ProgramNode;
210
211// declare AbortSignal here for environments without DOM lib or @types/node
212declare global {
213 interface AbortSignal {}
214}
215
216export type ParseAstAsync = (
217 input: string,
218 options?: { allowReturnOutsideFunction?: boolean; signal?: AbortSignal }
219) => Promise<ProgramNode>;
220
221export interface PluginContext extends MinimalPluginContext {
222 addWatchFile: (id: string) => void;
223 cache: PluginCache;
224 debug: LoggingFunction;
225 emitFile: EmitFile;
226 error: (error: RollupError | string) => never;
227 getFileName: (fileReferenceId: string) => string;
228 getModuleIds: () => IterableIterator<string>;
229 getModuleInfo: GetModuleInfo;
230 getWatchFiles: () => string[];
231 info: LoggingFunction;
232 load: (
233 options: { id: string; resolveDependencies?: boolean } & Partial<PartialNull<ModuleOptions>>
234 ) => Promise<ModuleInfo>;
235 parse: ParseAst;
236 resolve: (
237 source: string,
238 importer?: string,
239 options?: {
240 attributes?: Record<string, string>;
241 custom?: CustomPluginOptions;
242 isEntry?: boolean;
243 skipSelf?: boolean;
244 }
245 ) => Promise<ResolvedId | null>;
246 setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void;
247 warn: LoggingFunction;
248}
249
250export interface PluginContextMeta {
251 rollupVersion: string;
252 watchMode: boolean;
253}
254
255export interface ResolvedId extends ModuleOptions {
256 external: boolean | 'absolute';
257 id: string;
258 resolvedBy: string;
259}
260
261export interface ResolvedIdMap {
262 [key: string]: ResolvedId;
263}
264
265interface PartialResolvedId extends Partial<PartialNull<ModuleOptions>> {
266 external?: boolean | 'absolute' | 'relative';
267 id: string;
268 resolvedBy?: string;
269}
270
271export type ResolveIdResult = string | NullValue | false | PartialResolvedId;
272
273export type ResolveIdResultWithoutNullValue = string | false | PartialResolvedId;
274
275export type ResolveIdHook = (
276 this: PluginContext,
277 source: string,
278 importer: string | undefined,
279 options: { attributes: Record<string, string>; custom?: CustomPluginOptions; isEntry: boolean }
280) => ResolveIdResult;
281
282export type ShouldTransformCachedModuleHook = (
283 this: PluginContext,
284 options: {
285 ast: ProgramNode;
286 code: string;
287 id: string;
288 meta: CustomPluginOptions;
289 moduleSideEffects: boolean | 'no-treeshake';
290 resolvedSources: ResolvedIdMap;
291 syntheticNamedExports: boolean | string;
292 }
293) => boolean | NullValue;
294
295export type IsExternal = (
296 source: string,
297 importer: string | undefined,
298 isResolved: boolean
299) => boolean;
300
301export type HasModuleSideEffects = (id: string, external: boolean) => boolean;
302
303export type LoadResult = SourceDescription | string | NullValue;
304
305export type LoadHook = (this: PluginContext, id: string) => LoadResult;
306
307export interface TransformPluginContext extends PluginContext {
308 debug: LoggingFunctionWithPosition;
309 error: (error: RollupError | string, pos?: number | { column: number; line: number }) => never;
310 getCombinedSourcemap: () => SourceMap;
311 info: LoggingFunctionWithPosition;
312 warn: LoggingFunctionWithPosition;
313}
314
315export type TransformResult = string | NullValue | Partial<SourceDescription>;
316
317export type TransformHook = (
318 this: TransformPluginContext,
319 code: string,
320 id: string
321) => TransformResult;
322
323export type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => void;
324
325export type RenderChunkHook = (
326 this: PluginContext,
327 code: string,
328 chunk: RenderedChunk,
329 options: NormalizedOutputOptions,
330 meta: { chunks: Record<string, RenderedChunk> }
331) => { code: string; map?: SourceMapInput } | string | NullValue;
332
333export type ResolveDynamicImportHook = (
334 this: PluginContext,
335 specifier: string | AstNode,
336 importer: string,
337 options: { attributes: Record<string, string> }
338) => ResolveIdResult;
339
340export type ResolveImportMetaHook = (
341 this: PluginContext,
342 property: string | null,
343 options: { chunkId: string; format: InternalModuleFormat; moduleId: string }
344) => string | NullValue;
345
346export type ResolveFileUrlHook = (
347 this: PluginContext,
348 options: {
349 chunkId: string;
350 fileName: string;
351 format: InternalModuleFormat;
352 moduleId: string;
353 referenceId: string;
354 relativePath: string;
355 }
356) => string | NullValue;
357
358export type AddonHookFunction = (
359 this: PluginContext,
360 chunk: RenderedChunk
361) => string | Promise<string>;
362export type AddonHook = string | AddonHookFunction;
363
364export type ChangeEvent = 'create' | 'update' | 'delete';
365export type WatchChangeHook = (
366 this: PluginContext,
367 id: string,
368 change: { event: ChangeEvent }
369) => void;
370
371/**
372 * use this type for plugin annotation
373 * @example
374 * ```ts
375 * interface Options {
376 * ...
377 * }
378 * const myPlugin: PluginImpl<Options> = (options = {}) => { ... }
379 * ```
380 */
381// eslint-disable-next-line @typescript-eslint/ban-types
382export type PluginImpl<O extends object = object, A = any> = (options?: O) => Plugin<A>;
383
384export interface OutputBundle {
385 [fileName: string]: OutputAsset | OutputChunk;
386}
387
388export interface FunctionPluginHooks {
389 augmentChunkHash: (this: PluginContext, chunk: RenderedChunk) => string | void;
390 buildEnd: (this: PluginContext, error?: Error) => void;
391 buildStart: (this: PluginContext, options: NormalizedInputOptions) => void;
392 closeBundle: (this: PluginContext) => void;
393 closeWatcher: (this: PluginContext) => void;
394 generateBundle: (
395 this: PluginContext,
396 options: NormalizedOutputOptions,
397 bundle: OutputBundle,
398 isWrite: boolean
399 ) => void;
400 load: LoadHook;
401 moduleParsed: ModuleParsedHook;
402 onLog: (this: MinimalPluginContext, level: LogLevel, log: RollupLog) => boolean | NullValue;
403 options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | NullValue;
404 outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | NullValue;
405 renderChunk: RenderChunkHook;
406 renderDynamicImport: (
407 this: PluginContext,
408 options: {
409 customResolution: string | null;
410 format: InternalModuleFormat;
411 moduleId: string;
412 targetModuleId: string | null;
413 }
414 ) => { left: string; right: string } | NullValue;
415 renderError: (this: PluginContext, error?: Error) => void;
416 renderStart: (
417 this: PluginContext,
418 outputOptions: NormalizedOutputOptions,
419 inputOptions: NormalizedInputOptions
420 ) => void;
421 resolveDynamicImport: ResolveDynamicImportHook;
422 resolveFileUrl: ResolveFileUrlHook;
423 resolveId: ResolveIdHook;
424 resolveImportMeta: ResolveImportMetaHook;
425 shouldTransformCachedModule: ShouldTransformCachedModuleHook;
426 transform: TransformHook;
427 watchChange: WatchChangeHook;
428 writeBundle: (
429 this: PluginContext,
430 options: NormalizedOutputOptions,
431 bundle: OutputBundle
432 ) => void;
433}
434
435export type OutputPluginHooks =
436 | 'augmentChunkHash'
437 | 'generateBundle'
438 | 'outputOptions'
439 | 'renderChunk'
440 | 'renderDynamicImport'
441 | 'renderError'
442 | 'renderStart'
443 | 'resolveFileUrl'
444 | 'resolveImportMeta'
445 | 'writeBundle';
446
447export type InputPluginHooks = Exclude<keyof FunctionPluginHooks, OutputPluginHooks>;
448
449export type SyncPluginHooks =
450 | 'augmentChunkHash'
451 | 'onLog'
452 | 'outputOptions'
453 | 'renderDynamicImport'
454 | 'resolveFileUrl'
455 | 'resolveImportMeta';
456
457export type AsyncPluginHooks = Exclude<keyof FunctionPluginHooks, SyncPluginHooks>;
458
459export type FirstPluginHooks =
460 | 'load'
461 | 'renderDynamicImport'
462 | 'resolveDynamicImport'
463 | 'resolveFileUrl'
464 | 'resolveId'
465 | 'resolveImportMeta'
466 | 'shouldTransformCachedModule';
467
468export type SequentialPluginHooks =
469 | 'augmentChunkHash'
470 | 'generateBundle'
471 | 'onLog'
472 | 'options'
473 | 'outputOptions'
474 | 'renderChunk'
475 | 'transform';
476
477export type ParallelPluginHooks = Exclude<
478 keyof FunctionPluginHooks | AddonHooks,
479 FirstPluginHooks | SequentialPluginHooks
480>;
481
482export type AddonHooks = 'banner' | 'footer' | 'intro' | 'outro';
483
484type MakeAsync<Function_> = Function_ extends (
485 this: infer This,
486 ...parameters: infer Arguments
487) => infer Return
488 ? (this: This, ...parameters: Arguments) => Return | Promise<Return>
489 : never;
490
491// eslint-disable-next-line @typescript-eslint/ban-types
492type ObjectHook<T, O = {}> = T | ({ handler: T; order?: 'pre' | 'post' | null } & O);
493
494export type PluginHooks = {
495 [K in keyof FunctionPluginHooks]: ObjectHook<
496 K extends AsyncPluginHooks ? MakeAsync<FunctionPluginHooks[K]> : FunctionPluginHooks[K],
497 // eslint-disable-next-line @typescript-eslint/ban-types
498 K extends ParallelPluginHooks ? { sequential?: boolean } : {}
499 >;
500};
501
502export interface OutputPlugin
503 extends Partial<{ [K in OutputPluginHooks]: PluginHooks[K] }>,
504 Partial<{ [K in AddonHooks]: ObjectHook<AddonHook> }> {
505 cacheKey?: string;
506 name: string;
507 version?: string;
508}
509
510export interface Plugin<A = any> extends OutputPlugin, Partial<PluginHooks> {
511 // for inter-plugin communication
512 api?: A;
513}
514
515export type TreeshakingPreset = 'smallest' | 'safest' | 'recommended';
516
517export interface NormalizedTreeshakingOptions {
518 annotations: boolean;
519 correctVarValueBeforeDeclaration: boolean;
520 manualPureFunctions: readonly string[];
521 moduleSideEffects: HasModuleSideEffects;
522 propertyReadSideEffects: boolean | 'always';
523 tryCatchDeoptimization: boolean;
524 unknownGlobalSideEffects: boolean;
525}
526
527export interface TreeshakingOptions
528 extends Partial<Omit<NormalizedTreeshakingOptions, 'moduleSideEffects'>> {
529 moduleSideEffects?: ModuleSideEffectsOption;
530 preset?: TreeshakingPreset;
531}
532
533interface ManualChunkMeta {
534 getModuleIds: () => IterableIterator<string>;
535 getModuleInfo: GetModuleInfo;
536}
537export type GetManualChunk = (id: string, meta: ManualChunkMeta) => string | NullValue;
538
539export type ExternalOption =
540 | (string | RegExp)[]
541 | string
542 | RegExp
543 | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | NullValue);
544
545export type GlobalsOption = { [name: string]: string } | ((name: string) => string);
546
547export type InputOption = string | string[] | { [entryAlias: string]: string };
548
549export type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk;
550
551export type LogHandlerWithDefault = (
552 level: LogLevel,
553 log: RollupLog,
554 defaultHandler: LogOrStringHandler
555) => void;
556
557export type LogOrStringHandler = (level: LogLevel | 'error', log: RollupLog | string) => void;
558
559export type LogHandler = (level: LogLevel, log: RollupLog) => void;
560
561export type ModuleSideEffectsOption = boolean | 'no-external' | string[] | HasModuleSideEffects;
562
563export type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only';
564
565export type SourcemapPathTransformOption = (
566 relativeSourcePath: string,
567 sourcemapPath: string
568) => string;
569
570export type SourcemapIgnoreListOption = (
571 relativeSourcePath: string,
572 sourcemapPath: string
573) => boolean;
574
575export type InputPluginOption = MaybePromise<Plugin | NullValue | false | InputPluginOption[]>;
576
577export interface InputOptions {
578 cache?: boolean | RollupCache;
579 context?: string;
580 experimentalCacheExpiry?: number;
581 experimentalLogSideEffects?: boolean;
582 external?: ExternalOption;
583 input?: InputOption;
584 logLevel?: LogLevelOption;
585 makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource';
586 maxParallelFileOps?: number;
587 moduleContext?: ((id: string) => string | NullValue) | { [id: string]: string };
588 onLog?: LogHandlerWithDefault;
589 onwarn?: WarningHandlerWithDefault;
590 perf?: boolean;
591 plugins?: InputPluginOption;
592 preserveEntrySignatures?: PreserveEntrySignaturesOption;
593 preserveSymlinks?: boolean;
594 shimMissingExports?: boolean;
595 strictDeprecations?: boolean;
596 treeshake?: boolean | TreeshakingPreset | TreeshakingOptions;
597 watch?: WatcherOptions | false;
598}
599
600export interface InputOptionsWithPlugins extends InputOptions {
601 plugins: Plugin[];
602}
603
604export interface NormalizedInputOptions {
605 cache: false | undefined | RollupCache;
606 context: string;
607 experimentalCacheExpiry: number;
608 experimentalLogSideEffects: boolean;
609 external: IsExternal;
610 input: string[] | { [entryAlias: string]: string };
611 logLevel: LogLevelOption;
612 makeAbsoluteExternalsRelative: boolean | 'ifRelativeSource';
613 maxParallelFileOps: number;
614 moduleContext: (id: string) => string;
615 onLog: LogHandler;
616 perf: boolean;
617 plugins: Plugin[];
618 preserveEntrySignatures: PreserveEntrySignaturesOption;
619 preserveSymlinks: boolean;
620 shimMissingExports: boolean;
621 strictDeprecations: boolean;
622 treeshake: false | NormalizedTreeshakingOptions;
623}
624
625export type InternalModuleFormat = 'amd' | 'cjs' | 'es' | 'iife' | 'system' | 'umd';
626export type ImportAttributesKey = 'with' | 'assert';
627
628export type ModuleFormat = InternalModuleFormat | 'commonjs' | 'esm' | 'module' | 'systemjs';
629
630type GeneratedCodePreset = 'es5' | 'es2015';
631
632interface NormalizedGeneratedCodeOptions {
633 arrowFunctions: boolean;
634 constBindings: boolean;
635 objectShorthand: boolean;
636 reservedNamesAsProps: boolean;
637 symbols: boolean;
638}
639
640interface GeneratedCodeOptions extends Partial<NormalizedGeneratedCodeOptions> {
641 preset?: GeneratedCodePreset;
642}
643
644export type OptionsPaths = Record<string, string> | ((id: string) => string);
645
646export type InteropType = 'compat' | 'auto' | 'esModule' | 'default' | 'defaultOnly';
647
648export type GetInterop = (id: string | null) => InteropType;
649
650export type AmdOptions = (
651 | {
652 autoId?: false;
653 id: string;
654 }
655 | {
656 autoId: true;
657 basePath?: string;
658 id?: undefined;
659 }
660 | {
661 autoId?: false;
662 id?: undefined;
663 }
664) & {
665 define?: string;
666 forceJsExtensionForImports?: boolean;
667};
668
669export type NormalizedAmdOptions = (
670 | {
671 autoId: false;
672 id?: string;
673 }
674 | {
675 autoId: true;
676 basePath: string;
677 }
678) & {
679 define: string;
680 forceJsExtensionForImports: boolean;
681};
682
683type AddonFunction = (chunk: RenderedChunk) => string | Promise<string>;
684
685type OutputPluginOption = MaybePromise<OutputPlugin | NullValue | false | OutputPluginOption[]>;
686
687type HashCharacters = 'base64' | 'base36' | 'hex';
688
689export interface OutputOptions {
690 amd?: AmdOptions;
691 assetFileNames?: string | ((chunkInfo: PreRenderedAsset) => string);
692 banner?: string | AddonFunction;
693 chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
694 compact?: boolean;
695 // only required for bundle.write
696 dir?: string;
697 dynamicImportInCjs?: boolean;
698 entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
699 esModule?: boolean | 'if-default-prop';
700 experimentalMinChunkSize?: number;
701 exports?: 'default' | 'named' | 'none' | 'auto';
702 extend?: boolean;
703 /** @deprecated Use "externalImportAttributes" instead. */
704 externalImportAssertions?: boolean;
705 externalImportAttributes?: boolean;
706 externalLiveBindings?: boolean;
707 // only required for bundle.write
708 file?: string;
709 footer?: string | AddonFunction;
710 format?: ModuleFormat;
711 freeze?: boolean;
712 generatedCode?: GeneratedCodePreset | GeneratedCodeOptions;
713 globals?: GlobalsOption;
714 hashCharacters?: HashCharacters;
715 hoistTransitiveImports?: boolean;
716 importAttributesKey?: ImportAttributesKey;
717 indent?: string | boolean;
718 inlineDynamicImports?: boolean;
719 interop?: InteropType | GetInterop;
720 intro?: string | AddonFunction;
721 manualChunks?: ManualChunksOption;
722 minifyInternalExports?: boolean;
723 name?: string;
724 noConflict?: boolean;
725 outro?: string | AddonFunction;
726 paths?: OptionsPaths;
727 plugins?: OutputPluginOption;
728 preserveModules?: boolean;
729 preserveModulesRoot?: string;
730 reexportProtoFromExternal?: boolean;
731 sanitizeFileName?: boolean | ((fileName: string) => string);
732 sourcemap?: boolean | 'inline' | 'hidden';
733 sourcemapBaseUrl?: string;
734 sourcemapExcludeSources?: boolean;
735 sourcemapFile?: string;
736 sourcemapFileNames?: string | ((chunkInfo: PreRenderedChunk) => string);
737 sourcemapIgnoreList?: boolean | SourcemapIgnoreListOption;
738 sourcemapPathTransform?: SourcemapPathTransformOption;
739 strict?: boolean;
740 systemNullSetters?: boolean;
741 validate?: boolean;
742}
743
744export interface NormalizedOutputOptions {
745 amd: NormalizedAmdOptions;
746 assetFileNames: string | ((chunkInfo: PreRenderedAsset) => string);
747 banner: AddonFunction;
748 chunkFileNames: string | ((chunkInfo: PreRenderedChunk) => string);
749 compact: boolean;
750 dir: string | undefined;
751 dynamicImportInCjs: boolean;
752 entryFileNames: string | ((chunkInfo: PreRenderedChunk) => string);
753 esModule: boolean | 'if-default-prop';
754 experimentalMinChunkSize: number;
755 exports: 'default' | 'named' | 'none' | 'auto';
756 extend: boolean;
757 /** @deprecated Use "externalImportAttributes" instead. */
758 externalImportAssertions: boolean;
759 externalImportAttributes: boolean;
760 externalLiveBindings: boolean;
761 file: string | undefined;
762 footer: AddonFunction;
763 format: InternalModuleFormat;
764 freeze: boolean;
765 generatedCode: NormalizedGeneratedCodeOptions;
766 globals: GlobalsOption;
767 hashCharacters: HashCharacters;
768 hoistTransitiveImports: boolean;
769 importAttributesKey: ImportAttributesKey;
770 indent: true | string;
771 inlineDynamicImports: boolean;
772 interop: GetInterop;
773 intro: AddonFunction;
774 manualChunks: ManualChunksOption;
775 minifyInternalExports: boolean;
776 name: string | undefined;
777 noConflict: boolean;
778 outro: AddonFunction;
779 paths: OptionsPaths;
780 plugins: OutputPlugin[];
781 preserveModules: boolean;
782 preserveModulesRoot: string | undefined;
783 reexportProtoFromExternal: boolean;
784 sanitizeFileName: (fileName: string) => string;
785 sourcemap: boolean | 'inline' | 'hidden';
786 sourcemapBaseUrl: string | undefined;
787 sourcemapExcludeSources: boolean;
788 sourcemapFile: string | undefined;
789 sourcemapFileNames: string | ((chunkInfo: PreRenderedChunk) => string) | undefined;
790 sourcemapIgnoreList: SourcemapIgnoreListOption;
791 sourcemapPathTransform: SourcemapPathTransformOption | undefined;
792 strict: boolean;
793 systemNullSetters: boolean;
794 validate: boolean;
795}
796
797export type WarningHandlerWithDefault = (
798 warning: RollupLog,
799 defaultHandler: LoggingFunction
800) => void;
801
802export interface SerializedTimings {
803 [label: string]: [number, number, number];
804}
805
806export interface PreRenderedAsset {
807 name: string | undefined;
808 source: string | Uint8Array;
809 type: 'asset';
810}
811
812export interface OutputAsset extends PreRenderedAsset {
813 fileName: string;
814 needsCodeReference: boolean;
815}
816
817export interface RenderedModule {
818 readonly code: string | null;
819 originalLength: number;
820 removedExports: string[];
821 renderedExports: string[];
822 renderedLength: number;
823}
824
825export interface PreRenderedChunk {
826 exports: string[];
827 facadeModuleId: string | null;
828 isDynamicEntry: boolean;
829 isEntry: boolean;
830 isImplicitEntry: boolean;
831 moduleIds: string[];
832 name: string;
833 type: 'chunk';
834}
835
836export interface RenderedChunk extends PreRenderedChunk {
837 dynamicImports: string[];
838 fileName: string;
839 implicitlyLoadedBefore: string[];
840 importedBindings: {
841 [imported: string]: string[];
842 };
843 imports: string[];
844 modules: {
845 [id: string]: RenderedModule;
846 };
847 referencedFiles: string[];
848}
849
850export interface OutputChunk extends RenderedChunk {
851 code: string;
852 map: SourceMap | null;
853 sourcemapFileName: string | null;
854 preliminaryFileName: string;
855}
856
857export interface SerializablePluginCache {
858 [key: string]: [number, any];
859}
860
861export interface RollupCache {
862 modules: ModuleJSON[];
863 plugins?: Record<string, SerializablePluginCache>;
864}
865
866export interface RollupOutput {
867 output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
868}
869
870export interface RollupBuild {
871 cache: RollupCache | undefined;
872 close: () => Promise<void>;
873 closed: boolean;
874 generate: (outputOptions: OutputOptions) => Promise<RollupOutput>;
875 getTimings?: () => SerializedTimings;
876 watchFiles: string[];
877 write: (options: OutputOptions) => Promise<RollupOutput>;
878}
879
880export interface RollupOptions extends InputOptions {
881 // This is included for compatibility with config files but ignored by rollup.rollup
882 output?: OutputOptions | OutputOptions[];
883}
884
885export interface MergedRollupOptions extends InputOptionsWithPlugins {
886 output: OutputOptions[];
887}
888
889export function rollup(options: RollupOptions): Promise<RollupBuild>;
890
891export interface ChokidarOptions {
892 alwaysStat?: boolean;
893 atomic?: boolean | number;
894 awaitWriteFinish?:
895 | {
896 pollInterval?: number;
897 stabilityThreshold?: number;
898 }
899 | boolean;
900 binaryInterval?: number;
901 cwd?: string;
902 depth?: number;
903 disableGlobbing?: boolean;
904 followSymlinks?: boolean;
905 ignoreInitial?: boolean;
906 ignorePermissionErrors?: boolean;
907 ignored?: any;
908 interval?: number;
909 persistent?: boolean;
910 useFsEvents?: boolean;
911 usePolling?: boolean;
912}
913
914export type RollupWatchHooks = 'onError' | 'onStart' | 'onBundleStart' | 'onBundleEnd' | 'onEnd';
915
916export interface WatcherOptions {
917 buildDelay?: number;
918 chokidar?: ChokidarOptions;
919 clearScreen?: boolean;
920 exclude?: string | RegExp | (string | RegExp)[];
921 include?: string | RegExp | (string | RegExp)[];
922 skipWrite?: boolean;
923}
924
925export interface RollupWatchOptions extends InputOptions {
926 output?: OutputOptions | OutputOptions[];
927 watch?: WatcherOptions | false;
928}
929
930export type AwaitedEventListener<
931 T extends { [event: string]: (...parameters: any) => any },
932 K extends keyof T
933> = (...parameters: Parameters<T[K]>) => void | Promise<void>;
934
935export interface AwaitingEventEmitter<T extends { [event: string]: (...parameters: any) => any }> {
936 close(): Promise<void>;
937 emit<K extends keyof T>(event: K, ...parameters: Parameters<T[K]>): Promise<unknown>;
938 /**
939 * Removes an event listener.
940 */
941 off<K extends keyof T>(event: K, listener: AwaitedEventListener<T, K>): this;
942 /**
943 * Registers an event listener that will be awaited before Rollup continues.
944 * All listeners will be awaited in parallel while rejections are tracked via
945 * Promise.all.
946 */
947 on<K extends keyof T>(event: K, listener: AwaitedEventListener<T, K>): this;
948 /**
949 * Registers an event listener that will be awaited before Rollup continues.
950 * All listeners will be awaited in parallel while rejections are tracked via
951 * Promise.all.
952 * Listeners are removed automatically when removeListenersForCurrentRun is
953 * called, which happens automatically after each run.
954 */
955 onCurrentRun<K extends keyof T>(
956 event: K,
957 listener: (...parameters: Parameters<T[K]>) => Promise<ReturnType<T[K]>>
958 ): this;
959 removeAllListeners(): this;
960 removeListenersForCurrentRun(): this;
961}
962
963export type RollupWatcherEvent =
964 | { code: 'START' }
965 | { code: 'BUNDLE_START'; input?: InputOption; output: readonly string[] }
966 | {
967 code: 'BUNDLE_END';
968 duration: number;
969 input?: InputOption;
970 output: readonly string[];
971 result: RollupBuild;
972 }
973 | { code: 'END' }
974 | { code: 'ERROR'; error: RollupError; result: RollupBuild | null };
975
976export type RollupWatcher = AwaitingEventEmitter<{
977 change: (id: string, change: { event: ChangeEvent }) => void;
978 close: () => void;
979 event: (event: RollupWatcherEvent) => void;
980 restart: () => void;
981}>;
982
983export function watch(config: RollupWatchOptions | RollupWatchOptions[]): RollupWatcher;
984
985interface AstNodeLocation {
986 end: number;
987 start: number;
988}
989
990type OmittedEstreeKeys =
991 | 'loc'
992 | 'range'
993 | 'leadingComments'
994 | 'trailingComments'
995 | 'innerComments'
996 | 'comments';
997type RollupAstNode<T> = Omit<T, OmittedEstreeKeys> & AstNodeLocation;
998
999type ProgramNode = RollupAstNode<Program>;
1000export type AstNode = RollupAstNode<EstreeNode>;
1001
1002export function defineConfig(options: RollupOptions): RollupOptions;
1003export function defineConfig(options: RollupOptions[]): RollupOptions[];
1004export function defineConfig(optionsFunction: RollupOptionsFunction): RollupOptionsFunction;
1005
1006export type RollupOptionsFunction = (
1007 commandLineArguments: Record<string, any>
1008) => MaybePromise<RollupOptions | RollupOptions[]>;