Skip to content

Commit d2a2493

Browse files
authoredNov 29, 2023
fix: revert "fix: js fallback sourcemap content should be using original content (#15135)" (#15178)
1 parent 4a111aa commit d2a2493

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed
 

‎packages/vite/src/node/server/middlewares/transform.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from '../../utils'
2121
import { send } from '../send'
2222
import { ERR_LOAD_URL, transformRequest } from '../transformRequest'
23-
import { applySourcemapIgnoreList, getOriginalContent } from '../sourcemap'
23+
import { applySourcemapIgnoreList } from '../sourcemap'
2424
import { isHTMLProxy } from '../../plugins/html'
2525
import {
2626
DEP_VERSION_RE,
@@ -205,21 +205,12 @@ export function transformMiddleware(
205205
const type = isDirectCSSRequest(url) ? 'css' : 'js'
206206
const isDep =
207207
DEP_VERSION_RE.test(url) || depsOptimizer?.isOptimizedDepUrl(url)
208-
let originalContent: string | undefined
209-
if (type === 'js' && result.map == null) {
210-
const filepath = (
211-
await server.moduleGraph.getModuleByUrl(url, false)
212-
)?.file
213-
originalContent =
214-
filepath != null ? await getOriginalContent(filepath) : undefined
215-
}
216208
return send(req, res, result.code, type, {
217209
etag: result.etag,
218210
// allow browser to cache npm deps!
219211
cacheControl: isDep ? 'max-age=31536000,immutable' : 'no-cache',
220212
headers: server.config.server.headers,
221213
map: result.map,
222-
originalContent,
223214
})
224215
}
225216
}

‎packages/vite/src/node/server/send.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export interface SendOptions {
2727
cacheControl?: string
2828
headers?: OutgoingHttpHeaders
2929
map?: SourceMap | { mappings: '' } | null
30-
/** only used when type === 'js' && map == null (when the fallback sourcemap is used) */
31-
originalContent?: string
3230
}
3331

3432
export function send(
@@ -73,25 +71,23 @@ export function send(
7371
}
7472
// inject fallback sourcemap for js for improved debugging
7573
// https://github.com/vitejs/vite/pull/13514#issuecomment-1592431496
76-
// for { mappings: "" }, we don't inject fallback sourcemap
77-
// because it indicates generating a sourcemap is meaningless
78-
else if (type === 'js' && map == null) {
74+
else if (type === 'js' && (!map || map.mappings !== '')) {
7975
const code = content.toString()
8076
// if the code has existing inline sourcemap, assume it's correct and skip
8177
if (convertSourceMap.mapFileCommentRegex.test(code)) {
8278
debug?.(`Skipped injecting fallback sourcemap for ${req.url}`)
8379
} else {
8480
const urlWithoutTimestamp = removeTimestampQuery(req.url!)
8581
const ms = new MagicString(code)
86-
const map = ms.generateMap({
87-
source: path.basename(urlWithoutTimestamp),
88-
hires: 'boundary',
89-
includeContent: !options.originalContent,
90-
})
91-
if (options.originalContent != null) {
92-
map.sourcesContent = [options.originalContent]
93-
}
94-
content = getCodeWithSourcemap(type, code, map)
82+
content = getCodeWithSourcemap(
83+
type,
84+
code,
85+
ms.generateMap({
86+
source: path.basename(urlWithoutTimestamp),
87+
hires: 'boundary',
88+
includeContent: true,
89+
}),
90+
)
9591
}
9692
}
9793

‎packages/vite/src/node/server/sourcemap.ts

-7
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ export async function injectSourcesContent(
6565
}
6666
}
6767

68-
export async function getOriginalContent(
69-
filepath: string,
70-
): Promise<string | undefined> {
71-
if (virtualSourceRE.test(filepath)) return undefined
72-
return await fsp.readFile(filepath, 'utf-8').catch(() => undefined)
73-
}
74-
7568
export function genSourceMapUrl(map: SourceMap | string): string {
7669
if (typeof map !== 'string') {
7770
map = JSON.stringify(map)

0 commit comments

Comments
 (0)
Please sign in to comment.