rollup.d.ts 27 KB

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