From 599f28bbed574003aea08cffab098a3348475649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=8E?= Date: Thu, 2 Jun 2022 06:07:22 +0800 Subject: [PATCH] Use file URL for source map paths (#1771) --- 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); }