Skip to content

Commit

Permalink
fix: avoid swallowing ENOENT errors for malformed source paths
Browse files Browse the repository at this point in the history
Also, when the `file` is a virtual module, assume source paths are already absolute.
  • Loading branch information
aleclarson committed Jun 25, 2021
1 parent 8e9cfe6 commit 7105a09
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/vite/src/node/server/sourcemap.ts
Expand Up @@ -10,21 +10,17 @@ export async function injectSourcesContent(
path.resolve(path.dirname(file), map.sourceRoot || '')
)
} catch (e) {
if (e.code == 'ENOENT') return
throw e
if (e.code !== 'ENOENT') throw e
var isVirtual = true
}
map.sourcesContent = []
await Promise.all(
map.sources.map(async (sourcePath, i) => {
try {
map.sourcesContent![i] = await fs.readFile(
path.resolve(sourceRoot, decodeURI(sourcePath)),
'utf-8'
)
} catch (e) {
if (e.code == 'ENOENT') return
throw e
sourcePath = decodeURI(sourcePath)
if (!isVirtual) {
sourcePath = path.resolve(sourceRoot, sourcePath)
}
map.sourcesContent![i] = await fs.readFile(sourcePath, 'utf-8')
})
)
}

0 comments on commit 7105a09

Please sign in to comment.