Skip to content

Commit

Permalink
fix: consider root dir for source maps paths (#277)
Browse files Browse the repository at this point in the history
Co-authored-by: Rares Andrei <[email protected]>
  • Loading branch information
randrei-adobe and Rares Andrei authored Oct 28, 2024
1 parent 9498a51 commit d781cdd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/root_dir/expected/a.js.map.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sources": [
"../../src/a.ts"
"../src/a.ts"
]
}
2 changes: 1 addition & 1 deletion examples/root_dir/expected/b.js.map.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sources": [
"../../src/b.ts"
"../src/b.ts"
]
}
2 changes: 1 addition & 1 deletion examples/root_dir/expected/sub/c.js.map.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sources": [
"../../../src/sub/c.ts"
"../../src/sub/c.ts"
]
}
2 changes: 1 addition & 1 deletion examples/source_root/expected_subdir.js.map.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sources": [
"../src/subdir.ts"
"src/subdir.ts"
],
"sourceRoot": "../../../debug/source"
}
5 changes: 4 additions & 1 deletion swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ def _calculate_source_file(ctx, src):

# out of src subdir
if src_pkg:
s = paths.join(s, "/".join([".." for _ in src_pkg.split("/")]))
src_pkg_depth = len(src_pkg.split("/"))
root_dir_depth = len(ctx.attr.root_dir.split("/")) if ctx.attr.root_dir else 0
effective_depth = max(0, src_pkg_depth - root_dir_depth)
s = paths.join(s, "/".join([".." for _ in range(effective_depth)]))

# out of the out dir
if ctx.attr.out_dir:
Expand Down

0 comments on commit d781cdd

Please sign in to comment.