rollup.d.ts 29 KB

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