rollup.d.ts 27 KB

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