Skip to content

Commit

Permalink
fix(ssrTransform): sourcemaps with multiple sources
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jul 14, 2024
1 parent 07bc489 commit 386a52d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect, test } from 'vitest'
import { readFileSync } from 'node:fs'
import { assert, expect, test } from 'vitest'
import type { SourceMap } from 'rollup'
import { transformWithEsbuild } from '../../plugins/esbuild'
import { ssrTransform } from '../ssrTransform'

Expand Down Expand Up @@ -411,11 +413,33 @@ test('sourcemap source', async () => {
'input.js',
'export const a = 1 /* */',
)
)?.map
)?.map as SourceMap

expect(map?.sources).toStrictEqual(['input.js'])
expect(map?.sourcesContent).toStrictEqual(['export const a = 1 /* */'])
})

test('sourcemap with multiple sources', async () => {
const code = readFixture('bundle.js')
const map = readFixture('bundle.js.map')

const result = await ssrTransform(code, JSON.parse(map), '', code)
assert(result?.map)

const { sources } = result.map as SourceMap
expect(sources).toContain('./first.ts')
expect(sources).toContain('./second.ts')

function readFixture(filename: string) {
const url = new URL(
`./fixtures/bundled-with-sourcemaps/${filename}`,
import.meta.url,
)

return readFileSync(url.pathname, 'utf8')

Check failure on line 439 in packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-20, windows-latest

packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts > sourcemap with multiple sources

Error: ENOENT: no such file or directory, open 'D:\D:\a\vite\vite\packages\vite\src\node\ssr\__tests__\fixtures\bundled-with-sourcemaps\bundle.js' ❯ Proxy.readFileSync node:fs:448:20 ❯ readFixture packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts:439:12 ❯ packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts:423:16 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { errno: -4058, code: 'ENOENT', syscall: 'open', path: 'D:\D:\a\vite\vite\packages\vite\src\node\ssr\__tests__\fixtures\bundled-with-sourcemaps\bundle.js' }
}
})

test('overwrite bindings', async () => {
expect(
await ssrTransformSimpleCode(
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,6 @@ export function combineSourcemaps(
}
return newSourcemaps
})
const escapedFilename = escapeToLinuxLikePath(filename)

// We don't declare type here so we can convert/fake/map as RawSourceMap
let map //: SourceMap
Expand All @@ -863,7 +862,7 @@ export function combineSourcemaps(
map = remapping(sourcemapList, () => null)
} else {
map = remapping(sourcemapList[0], function loader(sourcefile) {
if (sourcefile === escapedFilename && sourcemapList[mapIndex]) {
if (sourcemapList[mapIndex]) {
return sourcemapList[mapIndex++]
} else {
return null
Expand Down

0 comments on commit 386a52d

Please sign in to comment.