1 | import * as ESTree from 'estree';
|
2 | import { EventEmitter } from 'events';
|
3 |
|
4 | export const VERSION: string;
|
5 |
|
6 | export interface RollupError extends RollupLogProps {
|
7 | stack?: string;
|
8 | }
|
9 |
|
10 | export 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 |
|
23 | export 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 |
|
41 | export type SourceMapSegment =
|
42 | | [number]
|
43 | | [number, number, number, number]
|
44 | | [number, number, number, number, number];
|
45 |
|
46 | export 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 |
|
56 | export 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 |
|
66 | export type DecodedSourceMapOrMissing =
|
67 | | {
|
68 | mappings?: never;
|
69 | missing: true;
|
70 | plugin: string;
|
71 | }
|
72 | | ExistingDecodedSourceMap;
|
73 |
|
74 | export 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 |
|
85 | export type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' };
|
86 |
|
87 | export interface SourceDescription {
|
88 | ast?: ESTree.Program;
|
89 | code: string;
|
90 | map?: SourceMapInput;
|
91 | moduleSideEffects?: boolean | null;
|
92 | }
|
93 |
|
94 | export interface TransformSourceDescription extends SourceDescription {
|
95 | dependencies?: string[];
|
96 | }
|
97 |
|
98 | export interface TransformModuleJSON {
|
99 | ast: ESTree.Program;
|
100 | code: string;
|
101 |
|
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 |
|
111 | export interface ModuleJSON extends TransformModuleJSON {
|
112 | dependencies: string[];
|
113 | id: string;
|
114 | transformFiles: EmittedFile[] | undefined;
|
115 | }
|
116 |
|
117 | export 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 |
|
124 | export interface MinimalPluginContext {
|
125 | meta: PluginContextMeta;
|
126 | }
|
127 |
|
128 | export interface EmittedAsset {
|
129 | fileName?: string;
|
130 | name?: string;
|
131 | source?: string | Buffer;
|
132 | type: 'asset';
|
133 | }
|
134 |
|
135 | export interface EmittedChunk {
|
136 | fileName?: string;
|
137 | id: string;
|
138 | name?: string;
|
139 | type: 'chunk';
|
140 | }
|
141 |
|
142 | export type EmittedFile = EmittedAsset | EmittedChunk;
|
143 |
|
144 | export type EmitAsset = (name: string, source?: string | Buffer) => string;
|
145 |
|
146 | export type EmitChunk = (id: string, options?: { name?: string }) => string;
|
147 |
|
148 | export type EmitFile = (emittedFile: EmittedFile) => string;
|
149 |
|
150 | export interface PluginContext extends MinimalPluginContext {
|
151 | addWatchFile: (id: string) => void;
|
152 | cache: PluginCache;
|
153 |
|
154 | emitAsset: EmitAsset;
|
155 |
|
156 | emitChunk: EmitChunk;
|
157 | emitFile: EmitFile;
|
158 | error: (err: RollupError | string, pos?: number | { column: number; line: number }) => never;
|
159 |
|
160 | getAssetFileName: (assetReferenceId: string) => string;
|
161 |
|
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 |
|
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 |
|
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 |
|
187 | watcher: EventEmitter;
|
188 | }
|
189 |
|
190 | export interface PluginContextMeta {
|
191 | rollupVersion: string;
|
192 | }
|
193 |
|
194 | export interface ResolvedId {
|
195 | external: boolean;
|
196 | id: string;
|
197 | moduleSideEffects: boolean;
|
198 | }
|
199 |
|
200 | export interface ResolvedIdMap {
|
201 | [key: string]: ResolvedId;
|
202 | }
|
203 |
|
204 | interface PartialResolvedId {
|
205 | external?: boolean;
|
206 | id: string;
|
207 | moduleSideEffects?: boolean | null;
|
208 | }
|
209 |
|
210 | export type ResolveIdResult = string | false | null | undefined | PartialResolvedId;
|
211 |
|
212 | export type ResolveIdHook = (
|
213 | this: PluginContext,
|
214 | source: string,
|
215 | importer: string | undefined
|
216 | ) => Promise<ResolveIdResult> | ResolveIdResult;
|
217 |
|
218 | export type IsExternal = (
|
219 | source: string,
|
220 | importer: string,
|
221 | isResolved: boolean
|
222 | ) => boolean | null | undefined;
|
223 |
|
224 | export type IsPureModule = (id: string) => boolean | null | undefined;
|
225 |
|
226 | export type HasModuleSideEffects = (id: string, external: boolean) => boolean;
|
227 |
|
228 | export type LoadHook = (
|
229 | this: PluginContext,
|
230 | id: string
|
231 | ) => Promise<SourceDescription | string | null> | SourceDescription | string | null;
|
232 |
|
233 | export type TransformResult = string | null | undefined | TransformSourceDescription;
|
234 |
|
235 | export type TransformHook = (
|
236 | this: PluginContext,
|
237 | code: string,
|
238 | id: string
|
239 | ) => Promise<TransformResult> | TransformResult;
|
240 |
|
241 | export 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 |
|
251 | export 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 |
|
262 | export type ResolveDynamicImportHook = (
|
263 | this: PluginContext,
|
264 | specifier: string | ESTree.Node,
|
265 | importer: string
|
266 | ) => Promise<ResolveIdResult> | ResolveIdResult;
|
267 |
|
268 | export type ResolveImportMetaHook = (
|
269 | this: PluginContext,
|
270 | prop: string | null,
|
271 | options: { chunkId: string; format: string; moduleId: string }
|
272 | ) => string | null | undefined;
|
273 |
|
274 | export 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 |
|
285 | export 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 |
|
299 | export 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 | */
|
311 | export type PluginImpl<O extends object = object> = (options?: O) => Plugin;
|
312 |
|
313 | export interface OutputBundle {
|
314 | [fileName: string]: OutputAsset | OutputChunk;
|
315 | }
|
316 |
|
317 | export interface OutputBundleWithPlaceholders {
|
318 | [fileName: string]: OutputAsset | OutputChunk | {};
|
319 | }
|
320 |
|
321 | interface OnGenerateOptions extends OutputOptions {
|
322 | bundle: OutputChunk;
|
323 | }
|
324 |
|
325 | interface OnWriteOptions extends OutputOptions {
|
326 | bundle: RollupBuild;
|
327 | }
|
328 |
|
329 | export 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 |
|
371 | export 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 |
|
380 | export interface TreeshakingOptions {
|
381 | annotations?: boolean;
|
382 | moduleSideEffects?: ModuleSideEffectsOption;
|
383 | propertyReadSideEffects?: boolean;
|
384 | /** @deprecated Use `moduleSideEffects` instead */
|
385 | pureExternalModules?: PureModulesOption;
|
386 | tryCatchDeoptimization?: boolean;
|
387 | }
|
388 |
|
389 | export type GetManualChunk = (id: string) => string | null | undefined;
|
390 |
|
391 | export type ExternalOption = string[] | IsExternal;
|
392 | export type PureModulesOption = boolean | string[] | IsPureModule;
|
393 | export type GlobalsOption = { [name: string]: string } | ((name: string) => string);
|
394 | export type InputOption = string | string[] | { [entryAlias: string]: string };
|
395 | export type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk;
|
396 | export type ModuleSideEffectsOption = boolean | 'no-external' | string[] | HasModuleSideEffects;
|
397 |
|
398 | export 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 |
|
423 | export type ModuleFormat =
|
424 | | 'amd'
|
425 | | 'cjs'
|
426 | | 'commonjs'
|
427 | | 'es'
|
428 | | 'esm'
|
429 | | 'iife'
|
430 | | 'module'
|
431 | | 'system'
|
432 | | 'umd';
|
433 |
|
434 | export type OptionsPaths = Record<string, string> | ((id: string) => string);
|
435 |
|
436 | export 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 |
|
478 | export type WarningHandlerWithDefault = (
|
479 | warning: string | RollupWarning,
|
480 | defaultHandler: WarningHandler
|
481 | ) => void;
|
482 | export type WarningHandler = (warning: string | RollupWarning) => void;
|
483 |
|
484 | export interface SerializedTimings {
|
485 | [label: string]: [number, number, number];
|
486 | }
|
487 |
|
488 | export interface OutputAsset {
|
489 | code?: undefined;
|
490 | fileName: string;
|
491 | isAsset: true;
|
492 | source: string | Buffer;
|
493 | }
|
494 |
|
495 | export interface RenderedModule {
|
496 | originalLength: number;
|
497 | removedExports: string[];
|
498 | renderedExports: string[];
|
499 | renderedLength: number;
|
500 | }
|
501 |
|
502 | export 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 |
|
516 | export interface OutputChunk extends RenderedChunk {
|
517 | code: string;
|
518 | map?: SourceMap;
|
519 | }
|
520 |
|
521 | export interface SerializablePluginCache {
|
522 | [key: string]: [number, any];
|
523 | }
|
524 |
|
525 | export interface RollupCache {
|
526 | modules?: ModuleJSON[];
|
527 | plugins?: Record<string, SerializablePluginCache>;
|
528 | }
|
529 |
|
530 | export interface RollupOutput {
|
531 | output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
|
532 | }
|
533 |
|
534 | export 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 |
|
542 | export interface RollupOptions extends InputOptions {
|
543 | output?: OutputOptions;
|
544 | }
|
545 |
|
546 | export function rollup(options: RollupOptions): Promise<RollupBuild>;
|
547 | // chokidar watch options
|
548 | export 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 |
|
571 | export interface WatcherOptions {
|
572 | chokidar?: boolean | WatchOptions;
|
573 | clearScreen?: boolean;
|
574 | exclude?: string[];
|
575 | include?: string[];
|
576 | }
|
577 |
|
578 | export interface RollupWatchOptions extends InputOptions {
|
579 | output?: OutputOptions | OutputOptions[];
|
580 | watch?: WatcherOptions;
|
581 | }
|
582 |
|
583 | export interface RollupWatcher extends EventEmitter {
|
584 | close(): void;
|
585 | }
|
586 |
|
587 | export function watch(configs: RollupWatchOptions[]): RollupWatcher;
|
588 |
|
\ | No newline at end of file |