Skip to content

Commit

Permalink
fix: append inline sourcemap to executed modules, close #342
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 29, 2021
1 parent 3611bdf commit 274203b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/vitest/src/node/transform.ts
Expand Up @@ -32,8 +32,26 @@ async function _transformRequest(ctx: Vitest, id: string) {
result = await ctx.server.ssrTransform(result.code, result.map, id)
}

if (result)
withInlineSourcemap(result)

if (result?.map && process.env.NODE_V8_COVERAGE)
ctx.visitedFilesMap.set(toFilePath(id, ctx.config.root), result.map as any)

// TODO: cache this result based on Vite's module graph
return result
}

let SOURCEMAPPING_URL = 'sourceMa'
SOURCEMAPPING_URL += 'ppingURL'

export async function withInlineSourcemap(result: TransformResult) {
const { code, map } = result

if (code.includes(`${SOURCEMAPPING_URL}=`))
return result
if (map)
result.code = `${code}\n\n//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), 'utf-8').toString('base64')}`

return result
}

0 comments on commit 274203b

Please sign in to comment.