Skip to content

Commit 4c85c0a

Browse files
authoredNov 29, 2022
fix(esbuild): handle inline sourcemap option (#11120)
1 parent e92d025 commit 4c85c0a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed
 

‎packages/vite/src/node/__tests__/plugins/esbuild.spec.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, expect, test } from 'vitest'
22
import type { ResolvedConfig, UserConfig } from '../../config'
3-
import { resolveEsbuildTranspileOptions } from '../../plugins/esbuild'
3+
import {
4+
ESBuildTransformResult,
5+
resolveEsbuildTranspileOptions,
6+
transformWithEsbuild
7+
} from '../../plugins/esbuild'
48

59
describe('resolveEsbuildTranspileOptions', () => {
610
test('resolve default', () => {
@@ -237,6 +241,16 @@ describe('resolveEsbuildTranspileOptions', () => {
237241
})
238242
})
239243

244+
describe('transformWithEsbuild', () => {
245+
test('not throw on inline sourcemap', async () => {
246+
const result = await transformWithEsbuild(`const foo = 'bar'`, '', {
247+
sourcemap: 'inline'
248+
})
249+
expect(result?.code).toBeTruthy()
250+
expect(result?.map).toBeTruthy()
251+
})
252+
})
253+
240254
/**
241255
* Helper for `resolveEsbuildTranspileOptions` to created resolved config with types.
242256
* Note: The function only uses `build.target`, `build.minify` and `esbuild` options.

‎packages/vite/src/node/plugins/esbuild.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ export async function transformWithEsbuild(
145145
inMap as RawSourceMap
146146
]) as SourceMap
147147
} else {
148-
map = resolvedOptions.sourcemap
149-
? JSON.parse(result.map)
150-
: { mappings: '' }
148+
map =
149+
resolvedOptions.sourcemap && resolvedOptions.sourcemap !== 'inline'
150+
? JSON.parse(result.map)
151+
: { mappings: '' }
151152
}
152153
if (Array.isArray(map.sources)) {
153154
map.sources = map.sources.map((it) => toUpperCaseDriveLetter(it))

0 commit comments

Comments
 (0)
Please sign in to comment.