rollup.d.ts 27 KB

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