From 3be84fe1aa0228beb184c4c24ea67271e6d3ba76 Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Sat, 18 Nov 2017 02:54:58 +0100 Subject: [PATCH] transform/transformBundle can return null/undefined I did not find it explicitly in documentation, but here is the code: https://github.com/rollup/rollup/blob/master/src/utils/transform.js#L78 https://github.com/rollup/rollup/blob/master/src/utils/transformBundle.js#L12 --- types/rollup/index.d.ts | 4 ++-- types/rollup/rollup-tests.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/types/rollup/index.d.ts b/types/rollup/index.d.ts index b1a67c9fdc..05fb4e9319 100644 --- a/types/rollup/index.d.ts +++ b/types/rollup/index.d.ts @@ -137,9 +137,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 | { code: string, map: SourceMap } + transform?(this: TransformContext, source: string, id: string): string | null | undefined | { code: string, map: SourceMap } /** A bundle transformer function */ - transformBundle?(source: string, options: { format: Format }): string | { code: string, map: SourceMap } + transformBundle?(source: string, options: { format: Format }): string | null | undefined | { code: string, map: SourceMap } /** 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. */ diff --git a/types/rollup/rollup-tests.ts b/types/rollup/rollup-tests.ts index 078cdf5450..04908c52bb 100644 --- a/types/rollup/rollup-tests.ts +++ b/types/rollup/rollup-tests.ts @@ -14,12 +14,23 @@ const plugin: Plugin = { transform(source, id) { if (id === 'rxjs') { this.error(new Error(`Don't import this directly`)) + return null } const indexOfQuote = source.indexOf('"') if (indexOfQuote >= 0) { this.warn(`Prefer ' over " for strings`, indexOfQuote) + return undefined } return source + }, + transformBundle(source, options) { + if (options.format === 'iife') { + return `window.nonModule = true\n${source}` + } else if (options.format === 'cjs') { + return null + } + + return undefined } }