Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Revert "fix: missing js sourcemaps with rewritten imports broke debugging (#7767) (#9476)" #11144

Merged
merged 1 commit into from Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 1 addition & 19 deletions packages/vite/src/node/server/transformRequest.ts
Expand Up @@ -5,7 +5,6 @@ import getEtag from 'etag'
import convertSourceMap from 'convert-source-map'
import type { SourceDescription, SourceMap } from 'rollup'
import colors from 'picocolors'
import MagicString from 'magic-string'
import type { ViteDevServer } from '..'
import {
blankReplacer,
Expand All @@ -19,8 +18,6 @@ import {
} from '../utils'
import { checkPublicFile } from '../plugins/asset'
import { getDepsOptimizer } from '../optimizer'
import { isCSSRequest } from '../plugins/css'
import { SPECIAL_QUERY_RE } from '../constants'
import { injectSourcesContent } from './sourcemap'
import { isFileServingAllowed } from './middlewares/static'

Expand Down Expand Up @@ -257,26 +254,11 @@ async function loadAndTransform(
isDebug && debugTransform(`${timeFrom(transformStart)} ${prettyUrl}`)
code = transformResult.code!
map = transformResult.map

// To enable IDE debugging, add a minimal sourcemap for modified JS files without one
if (
!map &&
mod.file &&
mod.type === 'js' &&
code !== originalCode &&
!(isCSSRequest(id) && !SPECIAL_QUERY_RE.test(id)) // skip CSS : #9914
) {
map = new MagicString(code).generateMap({ source: mod.file })
}
}

if (map && mod.file) {
map = (typeof map === 'string' ? JSON.parse(map) : map) as SourceMap
if (
map.mappings &&
(!map.sourcesContent ||
(map.sourcesContent as Array<string | null>).includes(null))
) {
if (map.mappings && !map.sourcesContent) {
await injectSourcesContent(map, mod.file, logger)
}
}
Expand Down
23 changes: 1 addition & 22 deletions playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Expand Up @@ -9,34 +9,13 @@ import {
} from '~utils'

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

test('js', async () => {
const res = await page.request.get(new URL('./qux.js', page.url()).href)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
{
"mappings": "AAAA;AACA;AACA;",
"sources": [
"/root/qux.js",
],
"sourcesContent": [
"import { foo } from './foo'
export const qux = 'qux'
",
],
"version": 3,
}
`)
})

test('ts', async () => {
const res = await page.request.get(new URL('./bar.ts', page.url()).href)
const js = await res.text()
Expand Down
3 changes: 0 additions & 3 deletions playground/js-sourcemap/qux.js

This file was deleted.