From 02c03ef730bd3b853f20dbb647682996140638b6 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Sat, 7 Mar 2020 21:26:51 +0300 Subject: [PATCH 1/2] Add missing type declaration for getCombinedSourcemap --- src/rollup/types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index e30d97159fc..e727e27eb6a 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -182,6 +182,7 @@ export interface PluginContext extends MinimalPluginContext { resolveId: (source: string, importer: string) => Promise; setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void; warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void; + getCombinedSourcemap: () => SourceMap; } export interface PluginContextMeta { From a2aa6eec9ee289b1c9d488312df5fc2c9c81162f Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 10 Mar 2020 06:15:39 +0100 Subject: [PATCH 2/2] Only add getCombinedSourcemap to transform hook --- docs/05-plugin-development.md | 2 +- src/rollup/types.d.ts | 7 +++++-- src/utils/transform.ts | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 465acd1475f..642412166e0 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -478,7 +478,7 @@ Structurally equivalent to `this.warn`, except that it will also abort the bundl #### `this.getCombinedSourcemap() => SourceMap` -Get the combined source maps of all previous plugins. This context function can only be used in [`transform`](guide/en/#transform) plugin hook. +Get the combined source maps of all previous plugins. This context function can only be used in the [`transform`](guide/en/#transform) plugin hook. #### `this.getFileName(referenceId: string) => string` diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index e727e27eb6a..352acf4cec4 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -182,7 +182,6 @@ export interface PluginContext extends MinimalPluginContext { resolveId: (source: string, importer: string) => Promise; setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void; warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void; - getCombinedSourcemap: () => SourceMap; } export interface PluginContextMeta { @@ -229,10 +228,14 @@ type LoadResult = SourceDescription | string | null | undefined; export type LoadHook = (this: PluginContext, id: string) => Promise | LoadResult; +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; diff --git a/src/utils/transform.ts b/src/utils/transform.ts index b536cadb968..5433bafd8d1 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -10,6 +10,7 @@ import { RollupWarning, SourceDescription, TransformModuleJSON, + TransformPluginContext, TransformResult } from '../rollup/types'; import { collapseSourcemap } from './collapseSourcemaps'; @@ -81,7 +82,7 @@ export default function transform( 'transform', [curSource, id], transformReducer, - (pluginContext, plugin) => { + (pluginContext, plugin): TransformPluginContext => { curPlugin = plugin; return { ...pluginContext,