rollup.d.ts 34 KB

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