提交 c811f0d3 编写于 作者: fxy060608's avatar fxy060608 提交者: qiang

fix(h5): 修复 pendingRequests sourceMap 拦截

上级 3f2a4e39
......@@ -29,37 +29,43 @@ class PendingRequests extends Map<string, PendingRequest> {
_inputDir!: string
_server!: ViteDevServer
set(key: string, value: PendingRequest) {
value.request = value.request
.then(async (request) => {
const map = request?.map
if (map) {
const mod = await this._server.moduleGraph.ensureEntryFromUrl(key)
if (mod.file && isAbsolute(mod.file)) {
const dir = normalizePath(dirname(mod.file))
if (dir.startsWith(this._inputDir)) {
for (
let sourcesIndex = 0;
sourcesIndex < map.sources.length;
++sourcesIndex
) {
const sourcePath = map.sources[sourcesIndex]
if (sourcePath) {
// 将相对路径转换为绝对路径
if (!isAbsolute(sourcePath)) {
map.sources[sourcesIndex] = normalizePath(
join(dir, sourcePath)
)
const then = value.request.then
// @ts-expect-error
value.request.then = (onFulfilled, onRejected) => {
// @ts-expect-error
return then.call(
value.request,
(request) => {
const map = request?.map
if (map) {
// @ts-expect-error
const mod = this._server.moduleGraph._getUnresolvedUrlToModule(key)
if (mod && mod.file && isAbsolute(mod.file)) {
const dir = normalizePath(dirname(mod.file))
if (dir.startsWith(this._inputDir)) {
for (
let sourcesIndex = 0;
sourcesIndex < map.sources.length;
++sourcesIndex
) {
const sourcePath = map.sources[sourcesIndex]
if (sourcePath) {
// 将相对路径转换为绝对路径
if (!isAbsolute(sourcePath)) {
map.sources[sourcesIndex] = normalizePath(
join(dir, sourcePath)
)
}
}
}
}
}
}
}
return request
})
.catch(() => {
return null
})
return onFulfilled?.(request)
},
onRejected
)
}
return super.set(key, value)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册