diff --git a/types/rollup/index.d.ts b/types/rollup/index.d.ts index 567dd148ae..fcd5f799c3 100644 --- a/types/rollup/index.d.ts +++ b/types/rollup/index.d.ts @@ -138,9 +138,9 @@ export interface Plugin { */ resolveId?(importee: string, importer: string | undefined): string | null | undefined | false | 0 | '' /** A module transformer function */ - transform?(this: TransformContext, source: string, id: string): string | null | undefined | { code: string, map: SourceMap } + transform?(this: TransformContext, source: string, id: string): TransformResult | Promise /** A bundle transformer function */ - transformBundle?(source: string, options: { format: Format }): string | null | undefined | { code: string, map: SourceMap } + transformBundle?(source: string, options: { format: Format }): TransformResult | Promise /** Function hook called when bundle.generate() is being executed. */ ongenerate?(options: GenerateOptions, bundle: Bundle): void /** Function hook called when bundle.write() is being executed, after the file has been written to disk. */ @@ -163,6 +163,8 @@ export interface TransformContext { error(message: string | { message: string }, pos?: number | { line: number, column: number }): void } +export type TransformResult = string | null | undefined | { code: string, map: SourceMap } + /** Returns a Promise that resolves with a bundle */ export function rollup(options: Options): Promise diff --git a/types/rollup/rollup-tests.ts b/types/rollup/rollup-tests.ts index b9a9eac5d7..e2b18d6109 100644 --- a/types/rollup/rollup-tests.ts +++ b/types/rollup/rollup-tests.ts @@ -21,6 +21,9 @@ const plugin: Plugin = { this.warn(`Prefer ' over " for strings`, indexOfQuote) return undefined } + if (id === 'foo') { + return Promise.resolve(source) + } return source }, transformBundle(source, options) { @@ -29,7 +32,9 @@ const plugin: Plugin = { } else if (options.format === 'cjs') { return null } - + if (options.format !== 'es') { + return Promise.resolve(source) + } return undefined } }