rollup.d.ts 34 KB

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