Skip to content

Commit

Permalink
fix: sourcesContent not being escaped
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed May 5, 2022
1 parent 03772db commit 99ce9c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SourceMap } from 'rollup';
import type { ExistingRawSourceMap } from 'rollup';
import { Plugin, TransformResult, createLogger } from 'vite';
import { createInstrumenter } from 'istanbul-lib-instrument';
import TestExclude from 'test-exclude';
Expand Down Expand Up @@ -27,7 +27,9 @@ const PLUGIN_NAME = 'vite:istanbul';
const MODULE_PREFIX = '/@modules/';
const NULL_STRING = '\0';

function sanitizeSourceMap(sourceMap: SourceMap): SourceMap {
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;
// JSON parse/stringify trick required for istanbul to accept the SourceMap
return JSON.parse(JSON.stringify(sourceMap));
}
Expand Down
6 changes: 3 additions & 3 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
declare module 'istanbul-lib-instrument' {
import { SourceMap } from 'rollup';
import { ExistingRawSourceMap } from 'rollup';
interface Instrumenter {
instrumentSync(code: string, filename: string, inputSourceMap?: SourceMap | undefined): string;
lastSourceMap(): SourceMap;
instrumentSync(code: string, filename: string, inputSourceMap?: ExistingRawSourceMap | undefined): string;
lastSourceMap(): ExistingRawSourceMap;
}

export function createInstrumenter(opts: {
Expand Down

0 comments on commit 99ce9c0

Please sign in to comment.