rollup.d.ts 35 KB

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