Rollup: transform/transformBundle can return a promise (#22684)

This commit is contained in:
Anton Galtsev 2018-01-07 11:22:25 +03:00 committed by Mohamed Hegazy
parent 3423a601fb
commit 4acf2baba6
2 changed files with 10 additions and 3 deletions

View File

@ -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<TransformResult>
/** 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<TransformResult>
/** 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<Bundle>

View File

@ -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
}
}