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