UNPKG

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