mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Rollup: transform/transformBundle can return a promise (#22684)
This commit is contained in:
parent
3423a601fb
commit
4acf2baba6
6
types/rollup/index.d.ts
vendored
6
types/rollup/index.d.ts
vendored
@ -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>
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user