Skip to content

Commit

Permalink
Use file URL for source map paths (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaperStrike authored Jun 1, 2022
1 parent 04f4c28 commit 599f28b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 599f28b

Please sign in to comment.