lib/condenser/processors/node_modules/rollup/dist/rollup.d.ts in condenser-0.2 vs lib/condenser/processors/node_modules/rollup/dist/rollup.d.ts in condenser-0.3

- old
+ new

@@ -1,8 +1,5 @@ -import * as ESTree from 'estree'; -import { EventEmitter } from 'events'; - export const VERSION: string; export interface RollupError extends RollupLogProps { parserError?: Error; stack?: string; @@ -87,23 +84,19 @@ } export type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' }; export interface SourceDescription { - ast?: ESTree.Program; + ast?: AcornNode; code: string; map?: SourceMapInput; moduleSideEffects?: boolean | null; syntheticNamedExports?: boolean; } -export interface TransformSourceDescription extends SourceDescription { - dependencies?: string[]; -} - export interface TransformModuleJSON { - ast: ESTree.Program; + ast?: AcornNode; code: string; // note if plugins use new this.cache to opt-out auto transform cache customTransformCache: boolean; moduleSideEffects: boolean | null; originalCode: string; @@ -113,10 +106,12 @@ syntheticNamedExports: boolean | null; transformDependencies: string[]; } export interface ModuleJSON extends TransformModuleJSON { + alwaysRemovedCode: [number, number][]; + ast: AcornNode; dependencies: string[]; id: string; transformFiles: EmittedFile[] | undefined; } @@ -132,24 +127,25 @@ } export interface EmittedAsset { fileName?: string; name?: string; - source?: string | Buffer; + source?: string | Uint8Array; type: 'asset'; } export interface EmittedChunk { fileName?: string; id: string; + importer?: string; name?: string; type: 'chunk'; } export type EmittedFile = EmittedAsset | EmittedChunk; -export type EmitAsset = (name: string, source?: string | Buffer) => string; +export type EmitAsset = (name: string, source?: string | Uint8Array) => string; export type EmitChunk = (id: string, options?: { name?: string }) => string; export type EmitFile = (emittedFile: EmittedFile) => string; @@ -168,31 +164,30 @@ getChunkFileName: (chunkReferenceId: string) => string; getFileName: (fileReferenceId: string) => string; getModuleInfo: ( moduleId: string ) => { + dynamicallyImportedIds: string[]; hasModuleSideEffects: boolean; id: string; importedIds: string[]; isEntry: boolean; isExternal: boolean; }; /** @deprecated Use `this.resolve` instead */ isExternal: IsExternal; moduleIds: IterableIterator<string>; - parse: (input: string, options: any) => ESTree.Program; + parse: (input: string, options: any) => AcornNode; resolve: ( source: string, - importer: string, + importer?: string, options?: { skipSelf: boolean } ) => Promise<ResolvedId | null>; /** @deprecated Use `this.resolve` instead */ - resolveId: (source: string, importer: string) => Promise<string | null>; - setAssetSource: (assetReferenceId: string, source: string | Buffer) => void; + resolveId: (source: string, importer?: string) => Promise<string | null>; + setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void; warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void; - /** @deprecated Use `this.addWatchFile` and the `watchChange` hook instead */ - watcher: EventEmitter; } export interface PluginContextMeta { rollupVersion: string; } @@ -223,11 +218,11 @@ importer: string | undefined ) => Promise<ResolveIdResult> | ResolveIdResult; export type IsExternal = ( source: string, - importer: string, + importer: string | undefined, isResolved: boolean ) => boolean | null | undefined; export type IsPureModule = (id: string) => boolean | null | undefined; @@ -235,28 +230,22 @@ type LoadResult = SourceDescription | string | null | undefined; export type LoadHook = (this: PluginContext, id: string) => Promise<LoadResult> | LoadResult; -export type TransformResult = string | null | undefined | TransformSourceDescription; +export interface TransformPluginContext extends PluginContext { + getCombinedSourcemap: () => SourceMap; +} +export type TransformResult = string | null | undefined | SourceDescription; + export type TransformHook = ( - this: PluginContext, + this: TransformPluginContext, code: string, id: string ) => Promise<TransformResult> | TransformResult; -export type TransformChunkHook = ( - this: PluginContext, - code: string, - options: OutputOptions -) => - | Promise<{ code: string; map?: SourceMapInput } | null | undefined> - | { code: string; map?: SourceMapInput } - | null - | undefined; - export type RenderChunkHook = ( this: PluginContext, code: string, chunk: RenderedChunk, options: OutputOptions @@ -266,26 +255,26 @@ | string | null; export type ResolveDynamicImportHook = ( this: PluginContext, - specifier: string | ESTree.Node, + specifier: string | AcornNode, importer: string ) => Promise<ResolveIdResult> | ResolveIdResult; export type ResolveImportMetaHook = ( this: PluginContext, prop: string | null, - options: { chunkId: string; format: string; moduleId: string } + options: { chunkId: string; format: InternalModuleFormat; moduleId: string } ) => string | null | undefined; export type ResolveAssetUrlHook = ( this: PluginContext, options: { assetFileName: string; chunkId: string; - format: string; + format: InternalModuleFormat; moduleId: string; relativeAssetPath: string; } ) => string | null | undefined; @@ -294,18 +283,19 @@ options: { assetReferenceId: string | null; chunkId: string; chunkReferenceId: string | null; fileName: string; - format: string; + format: InternalModuleFormat; moduleId: string; referenceId: string; relativePath: string; } ) => string | null | undefined; -export type AddonHook = string | ((this: PluginContext) => string | Promise<string>); +export type AddonHookFunction = (this: PluginContext) => string | Promise<string>; +export type AddonHook = string | AddonHookFunction; /** * use this type for plugin annotation * @example * ```ts @@ -327,68 +317,103 @@ export interface OutputBundleWithPlaceholders { [fileName: string]: OutputAsset | OutputChunk | FilePlaceholder; } -interface OnGenerateOptions extends OutputOptions { - bundle: OutputChunk; +export interface PluginHooks extends OutputPluginHooks { + buildEnd: (this: PluginContext, err?: Error) => Promise<void> | void; + buildStart: (this: PluginContext, options: InputOptions) => Promise<void> | void; + load: LoadHook; + options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | null | undefined; + resolveDynamicImport: ResolveDynamicImportHook; + resolveId: ResolveIdHook; + transform: TransformHook; + watchChange: (id: string) => void; } -interface OnWriteOptions extends OutputOptions { - bundle: RollupBuild; -} - interface OutputPluginHooks { augmentChunkHash: (this: PluginContext, chunk: PreRenderedChunk) => string | void; generateBundle: ( this: PluginContext, options: OutputOptions, bundle: OutputBundle, isWrite: boolean ) => void | Promise<void>; - /** @deprecated Use `generateBundle` instead */ - ongenerate: ( - this: PluginContext, - options: OnGenerateOptions, - chunk: OutputChunk - ) => void | Promise<void>; - /** @deprecated Use `writeBundle` instead */ - onwrite: ( - this: PluginContext, - options: OnWriteOptions, - chunk: OutputChunk - ) => void | Promise<void>; outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | null | undefined; renderChunk: RenderChunkHook; + renderDynamicImport: ( + this: PluginContext, + options: { + customResolution: string | null; + format: InternalModuleFormat; + moduleId: string; + targetModuleId: string | null; + } + ) => { left: string; right: string } | null | undefined; renderError: (this: PluginContext, err?: Error) => Promise<void> | void; renderStart: ( this: PluginContext, outputOptions: OutputOptions, inputOptions: InputOptions ) => Promise<void> | void; /** @deprecated Use `resolveFileUrl` instead */ resolveAssetUrl: ResolveAssetUrlHook; - resolveDynamicImport: ResolveDynamicImportHook; resolveFileUrl: ResolveFileUrlHook; - /** @deprecated Use `renderChunk` instead */ - transformBundle: TransformChunkHook; - /** @deprecated Use `renderChunk` instead */ - transformChunk: TransformChunkHook; - writeBundle: (this: PluginContext, bundle: OutputBundle) => void | Promise<void>; -} - -export interface PluginHooks extends OutputPluginHooks { - buildEnd: (this: PluginContext, err?: Error) => Promise<void> | void; - buildStart: (this: PluginContext, options: InputOptions) => Promise<void> | void; - load: LoadHook; - options: (this: MinimalPluginContext, options: InputOptions) => InputOptions | null | undefined; - resolveId: ResolveIdHook; resolveImportMeta: ResolveImportMetaHook; - transform: TransformHook; - watchChange: (id: string) => void; + writeBundle: ( + this: PluginContext, + options: OutputOptions, + bundle: OutputBundle + ) => void | Promise<void>; } +export type AsyncPluginHooks = + | 'buildEnd' + | 'buildStart' + | 'generateBundle' + | 'load' + | 'renderChunk' + | 'renderError' + | 'renderStart' + | 'resolveDynamicImport' + | 'resolveId' + | 'transform' + | 'writeBundle'; + +export type PluginValueHooks = 'banner' | 'footer' | 'intro' | 'outro'; + +export type SyncPluginHooks = Exclude<keyof PluginHooks, AsyncPluginHooks>; + +export type FirstPluginHooks = + | 'load' + | 'renderDynamicImport' + | 'resolveAssetUrl' + | 'resolveDynamicImport' + | 'resolveFileUrl' + | 'resolveId' + | 'resolveImportMeta'; + +export type SequentialPluginHooks = + | 'augmentChunkHash' + | 'generateBundle' + | 'options' + | 'outputOptions' + | 'renderChunk' + | 'transform' + | 'watchChange'; + +export type ParallelPluginHooks = + | 'banner' + | 'buildEnd' + | 'buildStart' + | 'footer' + | 'intro' + | 'outro' + | 'renderError' + | 'renderStart' + | 'writeBundle'; + interface OutputPluginValueHooks { banner: AddonHook; cacheKey: string; footer: AddonHook; intro: AddonHook; @@ -413,26 +438,23 @@ unknownGlobalSideEffects?: boolean; } export type GetManualChunk = (id: string) => string | null | undefined; -export type ExternalOption = string[] | IsExternal; +export type ExternalOption = (string | RegExp)[] | string | RegExp | IsExternal; export type PureModulesOption = boolean | string[] | IsPureModule; export type GlobalsOption = { [name: string]: string } | ((name: string) => string); export type InputOption = string | string[] | { [entryAlias: string]: string }; export type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk; export type ModuleSideEffectsOption = boolean | 'no-external' | string[] | HasModuleSideEffects; export interface InputOptions { acorn?: any; - acornInjectPlugins?: Function[]; + acornInjectPlugins?: Function | Function[]; cache?: false | RollupCache; - chunkGroupingSize?: number; context?: string; experimentalCacheExpiry?: number; - experimentalOptimizeChunks?: boolean; - experimentalTopLevelAwait?: boolean; external?: ExternalOption; inlineDynamicImports?: boolean; input?: InputOption; manualChunks?: ManualChunksOption; moduleContext?: ((id: string) => string) | { [id: string]: string }; @@ -445,21 +467,14 @@ strictDeprecations?: boolean; treeshake?: boolean | TreeshakingOptions; watch?: WatcherOptions; } -export type ModuleFormat = - | 'amd' - | 'cjs' - | 'commonjs' - | 'es' - | 'esm' - | 'iife' - | 'module' - | 'system' - | 'umd'; +export type InternalModuleFormat = 'amd' | 'cjs' | 'es' | 'iife' | 'system' | 'umd'; +export type ModuleFormat = InternalModuleFormat | 'commonjs' | 'esm' | 'module' | 'systemjs'; + export type OptionsPaths = Record<string, string> | ((id: string) => string); export interface OutputOptions { amd?: { define?: string; @@ -469,25 +484,24 @@ banner?: string | (() => string | Promise<string>); chunkFileNames?: string; compact?: boolean; // only required for bundle.write dir?: string; + /** @deprecated Use the "renderDynamicImport" plugin hook instead. */ dynamicImportFunction?: string; entryFileNames?: string; esModule?: boolean; exports?: 'default' | 'named' | 'none' | 'auto'; extend?: boolean; externalLiveBindings?: boolean; // only required for bundle.write file?: string; footer?: string | (() => string | Promise<string>); - // this is optional at the base-level of RollupWatchOptions, - // which extends from this interface through config merge format?: ModuleFormat; freeze?: boolean; globals?: GlobalsOption; - importMetaUrl?: (chunkId: string, moduleId: string) => string; + hoistTransitiveImports?: boolean; indent?: boolean; interop?: boolean; intro?: string | (() => string | Promise<string>); name?: string; namespaceToStringTag?: boolean; @@ -515,11 +529,11 @@ export interface OutputAsset { fileName: string; /** @deprecated Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead */ isAsset: true; - source: string | Buffer; + source: string | Uint8Array; type: 'asset'; } export interface RenderedModule { originalLength: number; @@ -575,13 +589,17 @@ export interface RollupOptions extends InputOptions { // This is included for compatibility with config files but ignored by rollup.rollup output?: OutputOptions | OutputOptions[]; } +export interface MergedRollupOptions extends InputOptions { + output: OutputOptions[]; +} + export function rollup(options: RollupOptions): Promise<RollupBuild>; -// chokidar watch options -export interface WatchOptions { + +export interface ChokidarOptions { alwaysStat?: boolean; atomic?: boolean | number; awaitWriteFinish?: | { pollInterval?: number; @@ -601,21 +619,64 @@ useFsEvents?: boolean; usePolling?: boolean; } export interface WatcherOptions { - chokidar?: boolean | WatchOptions; + chokidar?: ChokidarOptions; clearScreen?: boolean; exclude?: string[]; include?: string[]; + skipWrite?: boolean; } export interface RollupWatchOptions extends InputOptions { output?: OutputOptions | OutputOptions[]; watch?: WatcherOptions; } -export interface RollupWatcher extends EventEmitter { +interface TypedEventEmitter<T> { + addListener<K extends keyof T>(event: K, listener: T[K]): this; + emit<K extends keyof T>(event: K, ...args: any[]): boolean; + eventNames(): Array<keyof T>; + getMaxListeners(): number; + listenerCount(type: keyof T): number; + listeners<K extends keyof T>(event: K): Array<T[K]>; + off<K extends keyof T>(event: K, listener: T[K]): this; + on<K extends keyof T>(event: K, listener: T[K]): this; + once<K extends keyof T>(event: K, listener: T[K]): this; + prependListener<K extends keyof T>(event: K, listener: T[K]): this; + prependOnceListener<K extends keyof T>(event: K, listener: T[K]): this; + rawListeners<K extends keyof T>(event: K): Array<T[K]>; + removeAllListeners<K extends keyof T>(event?: K): this; + removeListener<K extends keyof T>(event: K, listener: T[K]): this; + setMaxListeners(n: number): this; +} + +export type RollupWatcherEvent = + | { code: 'START' } + | { code: 'BUNDLE_START'; input: InputOption; output: readonly string[] } + | { + code: 'BUNDLE_END'; + duration: number; + input: InputOption; + output: readonly string[]; + result: RollupBuild; + } + | { code: 'END' } + | { code: 'ERROR'; error: RollupError }; + +export interface RollupWatcher + extends TypedEventEmitter<{ + change: (id: string) => void; + event: (event: RollupWatcherEvent) => void; + restart: () => void; + }> { close(): void; } -export function watch(configs: RollupWatchOptions[]): RollupWatcher; +export function watch(config: RollupWatchOptions | RollupWatchOptions[]): RollupWatcher; + +interface AcornNode { + end: number; + start: number; + type: string; +}