rollup.d.ts 28 KB

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