diff --git a/src/index.ts b/src/index.ts index 3f90cfc..0497335 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,9 +27,10 @@ const PLUGIN_NAME = 'vite:istanbul'; const MODULE_PREFIX = '/@modules/'; const NULL_STRING = '\0'; -function sanitizeSourceMap(sourceMap: ExistingRawSourceMap): ExistingRawSourceMap { - // delete sourcesContent since it is optional and if it contains process.env.NODE_ENV vite will try and replace it and break - delete sourceMap.sourcesContent; +function sanitizeSourceMap(rawSourceMap: ExistingRawSourceMap): ExistingRawSourceMap { + // Delete sourcesContent since it is optional and if it contains process.env.NODE_ENV vite will break when trying to replace it + const { sourcesContent, ...sourceMap } = rawSourceMap; + // JSON parse/stringify trick required for istanbul to accept the SourceMap return JSON.parse(JSON.stringify(sourceMap)); } diff --git a/src/types.d.ts b/src/types.d.ts index 76566d8..e5c47fb 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,7 +1,8 @@ declare module 'istanbul-lib-instrument' { import { ExistingRawSourceMap } from 'rollup'; + interface Instrumenter { - instrumentSync(code: string, filename: string, inputSourceMap?: ExistingRawSourceMap | undefined): string; + instrumentSync(code: string, filename: string, inputSourceMap?: ExistingRawSourceMap): string; lastSourceMap(): ExistingRawSourceMap; } @@ -27,5 +28,6 @@ declare module 'test-exclude' { shouldInstrument(filePath:string):boolean } + export = TestExclude }