UNPKG

15.5 kBTypeScriptView Raw
1import * as ESTree from 'estree';
2import { EventEmitter } from 'events';
3
4export const VERSION: string;
5
6export interface RollupError extends RollupLogProps {
7 parserError?: Error;
8 stack?: string;
9 watchFiles?: string[];
10}
11
12export interface RollupWarning extends RollupLogProps {
13 exporter?: string;
14 exportName?: string;
15 guess?: string;
16 importer?: string;
17 missing?: string;
18 modules?: string[];
19 names?: string[];
20 reexporter?: string;
21 source?: string;
22 sources?: string[];
23}
24
25export interface RollupLogProps {
26 code?: string;
27 frame?: string;
28 hook?: string;
29 id?: string;
30 loc?: {
31 column: number;
32 file?: string;
33 line: number;
34 };
35 message: string;
36 name?: string;
37 plugin?: string;
38 pluginCode?: string;
39 pos?: number;
40 url?: string;
41}
42
43export type SourceMapSegment =
44 | [number]
45 | [number, number, number, number]
46 | [number, number, number, number, number];
47
48export interface ExistingDecodedSourceMap {
49 file?: string;
50 mappings: SourceMapSegment[][];
51 names: string[];
52 sourceRoot?: string;
53 sources: string[];
54 sourcesContent?: string[];
55 version: number;
56}
57
58export interface ExistingRawSourceMap {
59 file?: string;
60 mappings: string;
61 names: string[];
62 sourceRoot?: string;
63 sources: string[];
64 sourcesContent?: string[];
65 version: number;
66}
67
68export type DecodedSourceMapOrMissing =
69 | {
70 mappings?: never;
71 missing: true;
72 plugin: string;
73 }
74 | ExistingDecodedSourceMap;
75
76export interface SourceMap {
77 file: string;
78 mappings: string;
79 names: string[];
80 sources: string[];
81 sourcesContent: string[];
82 version: number;
83 toString(): string;
84 toUrl(): string;
85}
86
87export type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' };
88
89export interface SourceDescription {
90 ast?: ESTree.Program;
91 code: string;
92 map?: SourceMapInput;
93 moduleSideEffects?: boolean | null;
94}
95
96export interface TransformSourceDescription extends SourceDescription {
97 dependencies?: string[];
98}
99
100export interface TransformModuleJSON {
101 ast: ESTree.Program;
102 code: string;
103 // note if plugins use new this.cache to opt-out auto transform cache
104 customTransformCache: boolean;
105 moduleSideEffects: boolean | null;
106 originalCode: string;
107 originalSourcemap: ExistingDecodedSourceMap | null;
108 resolvedIds?: ResolvedIdMap;
109 sourcemapChain: DecodedSourceMapOrMissing[];
110 transformDependencies: string[];
111}
112
113export interface ModuleJSON extends TransformModuleJSON {
114 dependencies: string[];
115 id: string;
116 transformFiles: EmittedFile[] | undefined;
117}
118
119export interface PluginCache {
120 delete(id: string): boolean;
121 get<T = any>(id: string): T;
122 has(id: string): boolean;
123 set<T = any>(id: string, value: T): void;
124}
125
126export interface MinimalPluginContext {
127 meta: PluginContextMeta;
128}
129
130export interface EmittedAsset {
131 fileName?: string;
132 name?: string;
133 source?: string | Buffer;
134 type: 'asset';
135}
136
137export interface EmittedChunk {
138 fileName?: string;
139 id: string;
140 name?: string;
141 type: 'chunk';
142}
143
144export type EmittedFile = EmittedAsset | EmittedChunk;
145
146export type EmitAsset = (name: string, source?: string | Buffer) => string;
147
148export type EmitChunk = (id: string, options?: { name?: string }) => string;
149
150export type EmitFile = (emittedFile: EmittedFile) => string;
151
152export interface PluginContext extends MinimalPluginContext {
153 addWatchFile: (id: string) => void;
154 cache: PluginCache;
155 /** @deprecated Use `this.emitFile` instead */
156 emitAsset: EmitAsset;
157 /** @deprecated Use `this.emitFile` instead */
158 emitChunk: EmitChunk;
159 emitFile: EmitFile;
160 error: (err: RollupError | string, pos?: number | { column: number; line: number }) => never;
161 /** @deprecated Use `this.getFileName` instead */
162 getAssetFileName: (assetReferenceId: string) => string;
163 /** @deprecated Use `this.getFileName` instead */
164 getChunkFileName: (chunkReferenceId: string) => string;
165 getFileName: (fileReferenceId: string) => string;
166 getModuleInfo: (
167 moduleId: string
168 ) => {
169 hasModuleSideEffects: boolean;
170 id: string;
171 importedIds: string[];
172 isEntry: boolean;
173 isExternal: boolean;
174 };
175 /** @deprecated Use `this.resolve` instead */
176 isExternal: IsExternal;
177 moduleIds: IterableIterator<string>;
178 parse: (input: string, options: any) => ESTree.Program;
179 resolve: (
180 source: string,
181 importer: string,
182 options?: { skipSelf: boolean }
183 ) => Promise<ResolvedId | null>;
184 /** @deprecated Use `this.resolve` instead */
185 resolveId: (source: string, importer: string) => Promise<string | null>;
186 setAssetSource: (assetReferenceId: string, source: string | Buffer) => void;
187 warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void;
188 /** @deprecated Use `this.addWatchFile` and the `watchChange` hook instead */
189 watcher: EventEmitter;
190}
191
192export interface PluginContextMeta {
193 rollupVersion: string;
194}
195
196export interface ResolvedId {
197 external: boolean;
198 id: string;
199 moduleSideEffects: boolean;
200}
201
202export interface ResolvedIdMap {
203 [key: string]: ResolvedId;
204}
205
206interface PartialResolvedId {
207 external?: boolean;
208 id: string;
209 moduleSideEffects?: boolean | null;
210}
211
212export type ResolveIdResult = string | false | null | undefined | PartialResolvedId;
213
214export type ResolveIdHook = (
215 this: PluginContext,
216 source: string,
217 importer: string | undefined
218) => Promise<ResolveIdResult> | ResolveIdResult;
219
220export type IsExternal = (
221 source: string,
222 importer: string,
223 isResolved: boolean
224) => boolean | null | undefined;
225
226export type IsPureModule = (id: string) => boolean | null | undefined;
227
228export type HasModuleSideEffects = (id: string, external: boolean) => boolean;
229
230export type LoadHook = (
231 this: PluginContext,
232 id: string
233) => Promise<SourceDescription | string | null> | SourceDescription | string | null;
234
235export type TransformResult = string | null | undefined | TransformSourceDescription;
236
237export type TransformHook = (
238 this: PluginContext,
239 code: string,
240 id: string
241) => Promise<TransformResult> | TransformResult;
242
243export type TransformChunkHook = (
244 this: PluginContext,
245 code: string,
246 options: OutputOptions
247) =>
248 | Promise<{ code: string; map?: SourceMapInput } | null | undefined>
249 | { code: string; map?: SourceMapInput }
250 | null
251 | undefined;
252
253export type RenderChunkHook = (
254 this: PluginContext,
255 code: string,
256 chunk: RenderedChunk,
257 options: OutputOptions
258) =>
259 | Promise<{ code: string; map?: SourceMapInput } | null>
260 | { code: string; map?: SourceMapInput }
261 | string
262 | null;
263
264export type ResolveDynamicImportHook = (
265 this: PluginContext,
266 specifier: string | ESTree.Node,
267 importer: string
268) => Promise<ResolveIdResult> | ResolveIdResult;
269
270export type ResolveImportMetaHook = (
271 this: PluginContext,
272 prop: string | null,
273 options: { chunkId: string; format: string; moduleId: string }
274) => string | null | undefined;
275
276export type ResolveAssetUrlHook = (
277 this: PluginContext,
278 options: {
279 assetFileName: string;
280 chunkId: string;
281 format: string;
282 moduleId: string;
283 relativeAssetPath: string;
284 }
285) => string | null | undefined;
286
287export type ResolveFileUrlHook = (
288 this: PluginContext,
289 options: {
290 assetReferenceId: string | null;
291 chunkId: string;
292 chunkReferenceId: string | null;
293 fileName: string;
294 format: string;
295 moduleId: string;
296 referenceId: string;
297 relativePath: string;
298 }
299) => string | null | undefined;
300
301export type AddonHook = string | ((this: PluginContext) => string | Promise<string>);
302
303/**
304 * use this type for plugin annotation
305 * @example
306 * ```ts
307 * interface Options {
308 * ...
309 * }
310 * const myPlugin: PluginImpl<Options> = (options = {}) => { ... }
311 * ```
312 */
313export type PluginImpl<O extends object = object> = (options?: O) => Plugin;
314
315export interface OutputBundle {
316 [fileName: string]: OutputAsset | OutputChunk;
317}
318
319export interface FilePlaceholder {
320 type: 'placeholder';
321}
322
323export interface OutputBundleWithPlaceholders {
324 [fileName: string]: OutputAsset | OutputChunk | FilePlaceholder;
325}
326
327interface OnGenerateOptions extends OutputOptions {
328 bundle: OutputChunk;
329}
330
331interface OnWriteOptions extends OutputOptions {
332 bundle: RollupBuild;
333}
334
335export interface PluginHooks {
336 augmentChunkHash: (this: PluginContext, chunk: PreRenderedChunk) => string | void;
337 buildEnd: (this: PluginContext, err?: Error) => Promise<void> | void;
338 buildStart: (this: PluginContext, options: InputOptions) => Promise<void> | void;
339 generateBundle: (
340 this: PluginContext,
341 options: OutputOptions,
342 bundle: OutputBundle,
343 isWrite: boolean
344 ) => void | Promise<void>;
345 load: LoadHook;
346 /** @deprecated Use `generateBundle` instead */
347 ongenerate: (
348 this: PluginContext,
349 options: OnGenerateOptions,
350 chunk: OutputChunk
351 ) => void | Promise<void>;
352 /** @deprecated Use `writeBundle` instead */
353 onwrite: (
354 this: PluginContext,
355 options: OnWriteOptions,
356 chunk: OutputChunk
357 ) => void | Promise<void>;
358 options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | null | undefined;
359 outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | null | undefined;
360 renderChunk: RenderChunkHook;
361 renderError: (this: PluginContext, err?: Error) => Promise<void> | void;
362 renderStart: (this: PluginContext) => Promise<void> | void;
363 /** @deprecated Use `resolveFileUrl` instead */
364 resolveAssetUrl: ResolveAssetUrlHook;
365 resolveDynamicImport: ResolveDynamicImportHook;
366 resolveFileUrl: ResolveFileUrlHook;
367 resolveId: ResolveIdHook;
368 resolveImportMeta: ResolveImportMetaHook;
369 transform: TransformHook;
370 /** @deprecated Use `renderChunk` instead */
371 transformBundle: TransformChunkHook;
372 /** @deprecated Use `renderChunk` instead */
373 transformChunk: TransformChunkHook;
374 watchChange: (id: string) => void;
375 writeBundle: (this: PluginContext, bundle: OutputBundle) => void | Promise<void>;
376}
377
378export interface Plugin extends Partial<PluginHooks> {
379 banner?: AddonHook;
380 cacheKey?: string;
381 footer?: AddonHook;
382 intro?: AddonHook;
383 name: string;
384 outro?: AddonHook;
385}
386
387export interface TreeshakingOptions {
388 annotations?: boolean;
389 moduleSideEffects?: ModuleSideEffectsOption;
390 propertyReadSideEffects?: boolean;
391 /** @deprecated Use `moduleSideEffects` instead */
392 pureExternalModules?: PureModulesOption;
393 tryCatchDeoptimization?: boolean;
394 unknownGlobalSideEffects?: boolean;
395}
396
397export type GetManualChunk = (id: string) => string | null | undefined;
398
399export type ExternalOption = string[] | IsExternal;
400export type PureModulesOption = boolean | string[] | IsPureModule;
401export type GlobalsOption = { [name: string]: string } | ((name: string) => string);
402export type InputOption = string | string[] | { [entryAlias: string]: string };
403export type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk;
404export type ModuleSideEffectsOption = boolean | 'no-external' | string[] | HasModuleSideEffects;
405
406export interface InputOptions {
407 acorn?: any;
408 acornInjectPlugins?: Function[];
409 cache?: false | RollupCache;
410 chunkGroupingSize?: number;
411 context?: string;
412 experimentalCacheExpiry?: number;
413 experimentalOptimizeChunks?: boolean;
414 experimentalTopLevelAwait?: boolean;
415 external?: ExternalOption;
416 inlineDynamicImports?: boolean;
417 input?: InputOption;
418 manualChunks?: ManualChunksOption;
419 moduleContext?: ((id: string) => string) | { [id: string]: string };
420 onwarn?: WarningHandlerWithDefault;
421 perf?: boolean;
422 plugins?: Plugin[];
423 preserveModules?: boolean;
424 preserveSymlinks?: boolean;
425 shimMissingExports?: boolean;
426 strictDeprecations?: boolean;
427 treeshake?: boolean | TreeshakingOptions;
428 watch?: WatcherOptions;
429}
430
431export type ModuleFormat =
432 | 'amd'
433 | 'cjs'
434 | 'commonjs'
435 | 'es'
436 | 'esm'
437 | 'iife'
438 | 'module'
439 | 'system'
440 | 'umd';
441
442export type OptionsPaths = Record<string, string> | ((id: string) => string);
443
444export interface OutputOptions {
445 amd?: {
446 define?: string;
447 id?: string;
448 };
449 assetFileNames?: string;
450 banner?: string | (() => string | Promise<string>);
451 chunkFileNames?: string;
452 compact?: boolean;
453 // only required for bundle.write
454 dir?: string;
455 dynamicImportFunction?: string;
456 entryFileNames?: string;
457 esModule?: boolean;
458 exports?: 'default' | 'named' | 'none' | 'auto';
459 extend?: boolean;
460 externalLiveBindings?: boolean;
461 // only required for bundle.write
462 file?: string;
463 footer?: string | (() => string | Promise<string>);
464 // this is optional at the base-level of RollupWatchOptions,
465 // which extends from this interface through config merge
466 format?: ModuleFormat;
467 freeze?: boolean;
468 globals?: GlobalsOption;
469 importMetaUrl?: (chunkId: string, moduleId: string) => string;
470 indent?: boolean;
471 interop?: boolean;
472 intro?: string | (() => string | Promise<string>);
473 name?: string;
474 namespaceToStringTag?: boolean;
475 noConflict?: boolean;
476 outro?: string | (() => string | Promise<string>);
477 paths?: OptionsPaths;
478 preferConst?: boolean;
479 sourcemap?: boolean | 'inline' | 'hidden';
480 sourcemapExcludeSources?: boolean;
481 sourcemapFile?: string;
482 sourcemapPathTransform?: (sourcePath: string) => string;
483 strict?: boolean;
484}
485
486export type WarningHandlerWithDefault = (
487 warning: string | RollupWarning,
488 defaultHandler: WarningHandler
489) => void;
490export type WarningHandler = (warning: string | RollupWarning) => void;
491
492export interface SerializedTimings {
493 [label: string]: [number, number, number];
494}
495
496export interface OutputAsset {
497 fileName: string;
498 /** @deprecated Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead */
499 isAsset: true;
500 source: string | Buffer;
501 type: 'asset';
502}
503
504export interface RenderedModule {
505 originalLength: number;
506 removedExports: string[];
507 renderedExports: string[];
508 renderedLength: number;
509}
510
511export interface PreRenderedChunk {
512 dynamicImports: string[];
513 exports: string[];
514 facadeModuleId: string | null;
515 imports: string[];
516 isDynamicEntry: boolean;
517 isEntry: boolean;
518 modules: {
519 [id: string]: RenderedModule;
520 };
521 name: string;
522}
523
524export interface RenderedChunk extends PreRenderedChunk {
525 fileName: string;
526}
527
528export interface OutputChunk extends RenderedChunk {
529 code: string;
530 map?: SourceMap;
531 type: 'chunk';
532}
533
534export interface SerializablePluginCache {
535 [key: string]: [number, any];
536}
537
538export interface RollupCache {
539 modules: ModuleJSON[];
540 plugins?: Record<string, SerializablePluginCache>;
541}
542
543export interface RollupOutput {
544 output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
545}
546
547export interface RollupBuild {
548 cache: RollupCache;
549 generate: (outputOptions: OutputOptions) => Promise<RollupOutput>;
550 getTimings?: () => SerializedTimings;
551 watchFiles: string[];
552 write: (options: OutputOptions) => Promise<RollupOutput>;
553}
554
555export interface RollupOptions extends InputOptions {
556 output?: OutputOptions | OutputOptions[];
557}
558
559export function rollup(options: RollupOptions): Promise<RollupBuild>;
560// chokidar watch options
561export interface WatchOptions {
562 alwaysStat?: boolean;
563 atomic?: boolean | number;
564 awaitWriteFinish?:
565 | {
566 pollInterval?: number;
567 stabilityThreshold?: number;
568 }
569 | boolean;
570 binaryInterval?: number;
571 cwd?: string;
572 depth?: number;
573 disableGlobbing?: boolean;
574 followSymlinks?: boolean;
575 ignored?: any;
576 ignoreInitial?: boolean;
577 ignorePermissionErrors?: boolean;
578 interval?: number;
579 persistent?: boolean;
580 useFsEvents?: boolean;
581 usePolling?: boolean;
582}
583
584export interface WatcherOptions {
585 chokidar?: boolean | WatchOptions;
586 clearScreen?: boolean;
587 exclude?: string[];
588 include?: string[];
589}
590
591export interface RollupWatchOptions extends InputOptions {
592 output?: OutputOptions | OutputOptions[];
593 watch?: WatcherOptions;
594}
595
596export interface RollupWatcher extends EventEmitter {
597 close(): void;
598}
599
600export function watch(configs: RollupWatchOptions[]): RollupWatcher;
601
\No newline at end of file