From 7105a09aa1b68f54d25b695d2580ecacce7322c4 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Fri, 25 Jun 2021 12:00:36 -0400 Subject: [PATCH] fix: avoid swallowing ENOENT errors for malformed source paths Also, when the `file` is a virtual module, assume source paths are already absolute. --- packages/vite/src/node/server/sourcemap.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index b668cb4c4c742f..65c57423206008 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -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') }) ) }