Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
add workaround for relative sourcemap source paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kherock committed Feb 19, 2021
1 parent 1131a8d commit 7386945
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/swc/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as swc from "@swc/core";
import convertSourceMap from 'convert-source-map';
import fs from "fs";
import glob from "glob";
import uniq from "lodash/uniq";
Expand Down Expand Up @@ -89,9 +90,23 @@ export async function compile(
};

try {
return sync
const result = sync
? swc.transformFileSync(filename, opts)
: await swc.transformFile(filename, opts);

if (result.map) {
const map = convertSourceMap.fromJSON(result.map);
// TODO: fix this in core
// https://github.com/swc-project/swc/issues/1388
if (opts.sourceFileName) {
map.getProperty('sources')[0] = opts.sourceFileName;
}
if (opts.sourceRoot) {
map.setProperty('sourceRoot', opts.sourceRoot);
}
result.map = map.toJSON();
}
return result;
} catch (err) {
if (!err.message.includes("ignored by .swcrc")) {
throw err;
Expand Down

0 comments on commit 7386945

Please sign in to comment.