Skip to content

Commit

Permalink
fix(esbuild): handle inline sourcemap option (#11120)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Nov 29, 2022
1 parent e92d025 commit 4c85c0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 15 additions & 1 deletion packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
@@ -1,6 +1,10 @@
import { describe, expect, test } from 'vitest'
import type { ResolvedConfig, UserConfig } from '../../config'
import { resolveEsbuildTranspileOptions } from '../../plugins/esbuild'
import {
ESBuildTransformResult,
resolveEsbuildTranspileOptions,
transformWithEsbuild
} from '../../plugins/esbuild'

describe('resolveEsbuildTranspileOptions', () => {
test('resolve default', () => {
Expand Down Expand Up @@ -237,6 +241,16 @@ describe('resolveEsbuildTranspileOptions', () => {
})
})

describe('transformWithEsbuild', () => {
test('not throw on inline sourcemap', async () => {
const result = await transformWithEsbuild(`const foo = 'bar'`, '', {
sourcemap: 'inline'
})
expect(result?.code).toBeTruthy()
expect(result?.map).toBeTruthy()
})
})

/**
* Helper for `resolveEsbuildTranspileOptions` to created resolved config with types.
* Note: The function only uses `build.target`, `build.minify` and `esbuild` options.
Expand Down
7 changes: 4 additions & 3 deletions packages/vite/src/node/plugins/esbuild.ts
Expand Up @@ -145,9 +145,10 @@ export async function transformWithEsbuild(
inMap as RawSourceMap
]) as SourceMap
} else {
map = resolvedOptions.sourcemap
? JSON.parse(result.map)
: { mappings: '' }
map =
resolvedOptions.sourcemap && resolvedOptions.sourcemap !== 'inline'
? JSON.parse(result.map)
: { mappings: '' }
}
if (Array.isArray(map.sources)) {
map.sources = map.sources.map((it) => toUpperCaseDriveLetter(it))
Expand Down

0 comments on commit 4c85c0a

Please sign in to comment.