Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vite-node): don't remove sourcemap string in source code (#2918) #3379

Merged
merged 7 commits into from May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/basic/test/sourcemap.test.ts
@@ -0,0 +1,7 @@
import { expect, it } from 'vitest'

it('should have sourcemaps', () => {
expect('\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,').toBeTruthy()
expect('\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,').toBeTruthy()
expect('\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,').toBeTruthy()
})
3 changes: 2 additions & 1 deletion packages/vite-node/src/source-map.ts
Expand Up @@ -41,7 +41,8 @@ export function withInlineSourcemap(result: TransformResult, options: {
})

// to reduce the payload size, we only inline vite node source map, because it's also the only one we use
const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,(.+)`, 'g')
// const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,(.+)`, 'g')
const OTHER_SOURCE_MAP_REGEXP = /(?<!['"`])\/\/# ${SOURCEMAPPING_URL}=data:application\/json[^,]+base64,(.+?)(?!\w)/g
while (OTHER_SOURCE_MAP_REGEXP.test(code))
code = code.replace(OTHER_SOURCE_MAP_REGEXP, '')

Expand Down