Skip to content

Commit 4305682

Browse files
committed
fix: Revert "fix: missing js sourcemaps with rewritten imports broke debugging (vitejs#7767) (vitejs#9476)"
1 parent c26679a commit 4305682

File tree

3 files changed

+2
-44
lines changed

3 files changed

+2
-44
lines changed

packages/vite/src/node/server/transformRequest.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import getEtag from 'etag'
55
import convertSourceMap from 'convert-source-map'
66
import type { SourceDescription, SourceMap } from 'rollup'
77
import colors from 'picocolors'
8-
import MagicString from 'magic-string'
98
import type { ViteDevServer } from '..'
109
import {
1110
blankReplacer,
@@ -19,8 +18,6 @@ import {
1918
} from '../utils'
2019
import { checkPublicFile } from '../plugins/asset'
2120
import { getDepsOptimizer } from '../optimizer'
22-
import { isCSSRequest } from '../plugins/css'
23-
import { SPECIAL_QUERY_RE } from '../constants'
2421
import { injectSourcesContent } from './sourcemap'
2522
import { isFileServingAllowed } from './middlewares/static'
2623

@@ -257,26 +254,11 @@ async function loadAndTransform(
257254
isDebug && debugTransform(`${timeFrom(transformStart)} ${prettyUrl}`)
258255
code = transformResult.code!
259256
map = transformResult.map
260-
261-
// To enable IDE debugging, add a minimal sourcemap for modified JS files without one
262-
if (
263-
!map &&
264-
mod.file &&
265-
mod.type === 'js' &&
266-
code !== originalCode &&
267-
!(isCSSRequest(id) && !SPECIAL_QUERY_RE.test(id)) // skip CSS : #9914
268-
) {
269-
map = new MagicString(code).generateMap({ source: mod.file })
270-
}
271257
}
272258

273259
if (map && mod.file) {
274260
map = (typeof map === 'string' ? JSON.parse(map) : map) as SourceMap
275-
if (
276-
map.mappings &&
277-
(!map.sourcesContent ||
278-
(map.sourcesContent as Array<string | null>).includes(null))
279-
) {
261+
if (map.mappings && !map.sourcesContent) {
280262
await injectSourcesContent(map, mod.file, logger)
281263
}
282264
}

playground/js-sourcemap/__tests__/js-sourcemap.spec.ts

+1-22
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,13 @@ import {
99
} from '~utils'
1010

1111
if (!isBuild) {
12-
test('js without import', async () => {
12+
test('js', async () => {
1313
const res = await page.request.get(new URL('./foo.js', page.url()).href)
1414
const js = await res.text()
1515
const lines = js.split('\n')
1616
expect(lines[lines.length - 1].includes('//')).toBe(false) // expect no sourcemap
1717
})
1818

19-
test('js', async () => {
20-
const res = await page.request.get(new URL('./qux.js', page.url()).href)
21-
const js = await res.text()
22-
const map = extractSourcemap(js)
23-
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
24-
{
25-
"mappings": "AAAA;AACA;AACA;",
26-
"sources": [
27-
"/root/qux.js",
28-
],
29-
"sourcesContent": [
30-
"import { foo } from './foo'
31-
32-
export const qux = 'qux'
33-
",
34-
],
35-
"version": 3,
36-
}
37-
`)
38-
})
39-
4019
test('ts', async () => {
4120
const res = await page.request.get(new URL('./bar.ts', page.url()).href)
4221
const js = await res.text()

playground/js-sourcemap/qux.js

-3
This file was deleted.

0 commit comments

Comments
 (0)