rollup.d.ts 24 KB

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