rollup.d.ts 26 KB

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