Skip to content

Commit 77c95bf

Browse files
authored
fix(module-runner): handle non-ascii characters in base64 sourcemaps (#21985)
1 parent ddfe20d commit 77c95bf

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/vite/rolldown.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const moduleRunnerConfig = defineConfig({
147147
'@vitejs/devtools/cli-commands',
148148
...Object.keys(pkg.dependencies),
149149
],
150-
plugins: [bundleSizeLimit(54), enableSourceMapsInWatchModePlugin()],
150+
plugins: [bundleSizeLimit(55), enableSourceMapsInWatchModePlugin()],
151151
output: {
152152
...sharedNodeOptions.output,
153153
minify: {

packages/vite/src/module-runner/utils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import * as pathe from 'pathe'
22
import { isWindows } from '../shared/utils'
33

4-
export const decodeBase64: typeof atob =
5-
typeof atob !== 'undefined'
6-
? atob
7-
: (str: string) => Buffer.from(str, 'base64').toString('utf-8')
4+
const textDecoder = new TextDecoder()
5+
6+
export const decodeBase64: (base64: string) => string = (() => {
7+
if (typeof Buffer === 'function' && typeof Buffer.from === 'function') {
8+
return (base64: string) => Buffer.from(base64, 'base64').toString('utf-8')
9+
}
10+
11+
return (base64: string) =>
12+
textDecoder.decode(Uint8Array.from(atob(base64), (c) => c.charCodeAt(0)))
13+
})()
814

915
const CHAR_FORWARD_SLASH = 47
1016
const CHAR_BACKWARD_SLASH = 92

0 commit comments

Comments
 (0)