Skip to content

Commit

Permalink
refactor: Minor refactor to commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iFaxity committed May 5, 2022
1 parent 99ce9c0 commit d8ef700
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 3 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -27,5 +28,6 @@ declare module 'test-exclude' {

shouldInstrument(filePath:string):boolean
}

export = TestExclude
}

0 comments on commit d8ef700

Please sign in to comment.