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