UNPKG

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