rollup.d.ts 29 KB

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