You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1104 lines
30 KiB

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