From 134bef23b949ab1c0510a883afe9e99dddfe0c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E?= Date: Sun, 22 May 2022 20:44:16 +0800 Subject: [PATCH] Use file URL for source map paths --- src/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 607d5976d..799731f2a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ -import { relative, basename, extname, dirname, join } from 'path'; +import { relative, basename, extname, dirname, join, isAbsolute } from 'path'; import { Module } from 'module'; import * as util from 'util'; -import { fileURLToPath } from 'url'; +import { fileURLToPath, pathToFileURL } from 'url'; import type * as _sourceMapSupport from '@cspotcode/source-map-support'; import { BaseError } from 'make-error'; @@ -1667,8 +1667,11 @@ function updateOutput( */ function updateSourceMap(sourceMapText: string, fileName: string) { const sourceMap = JSON.parse(sourceMapText); - sourceMap.file = fileName; - sourceMap.sources = [fileName]; + const outputFileName = isAbsolute(fileName) + ? pathToFileURL(fileName).href + : fileName; + sourceMap.file = outputFileName; + sourceMap.sources = [outputFileName]; delete sourceMap.sourceRoot; return JSON.stringify(sourceMap); }