rollup.d.ts 27 KB

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