From b08c171a9342e0f746b17994c4cc5db3745446d0 Mon Sep 17 00:00:00 2001 From: Rares Andrei Date: Thu, 24 Oct 2024 18:40:00 +0300 Subject: [PATCH] fix: Consider root dir for source maps paths --- examples/root_dir/expected/a.js.map.golden | 2 +- examples/root_dir/expected/b.js.map.golden | 2 +- examples/root_dir/expected/sub/c.js.map.golden | 2 +- examples/source_root/expected_subdir.js.map.golden | 2 +- swc/private/swc.bzl | 5 ++++- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/root_dir/expected/a.js.map.golden b/examples/root_dir/expected/a.js.map.golden index 4cd080b..f2533ba 100644 --- a/examples/root_dir/expected/a.js.map.golden +++ b/examples/root_dir/expected/a.js.map.golden @@ -1,5 +1,5 @@ { "sources": [ - "../../src/a.ts" + "../src/a.ts" ] } \ No newline at end of file diff --git a/examples/root_dir/expected/b.js.map.golden b/examples/root_dir/expected/b.js.map.golden index f21f8a5..33da7c1 100644 --- a/examples/root_dir/expected/b.js.map.golden +++ b/examples/root_dir/expected/b.js.map.golden @@ -1,5 +1,5 @@ { "sources": [ - "../../src/b.ts" + "../src/b.ts" ] } \ No newline at end of file diff --git a/examples/root_dir/expected/sub/c.js.map.golden b/examples/root_dir/expected/sub/c.js.map.golden index fff83c0..c112944 100644 --- a/examples/root_dir/expected/sub/c.js.map.golden +++ b/examples/root_dir/expected/sub/c.js.map.golden @@ -1,5 +1,5 @@ { "sources": [ - "../../../src/sub/c.ts" + "../../src/sub/c.ts" ] } \ No newline at end of file diff --git a/examples/source_root/expected_subdir.js.map.golden b/examples/source_root/expected_subdir.js.map.golden index d165041..7b28ba1 100644 --- a/examples/source_root/expected_subdir.js.map.golden +++ b/examples/source_root/expected_subdir.js.map.golden @@ -1,6 +1,6 @@ { "sources": [ - "../src/subdir.ts" + "src/subdir.ts" ], "sourceRoot": "../../../debug/source" } \ No newline at end of file diff --git a/swc/private/swc.bzl b/swc/private/swc.bzl index 3331bdd..353d723 100644 --- a/swc/private/swc.bzl +++ b/swc/private/swc.bzl @@ -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: