Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions examples/root_dir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ swc(
source_maps = True,
)

# Test case for root_dir="." (should have depth 0)
swc(
name = "compile_dot",
srcs = [
"src/a.ts",
"src/b.ts",
"src/sub/c.ts",
],
out_dir = "out_dot",
root_dir = ".",
source_maps = True,
)

# Test case for nested root_dir
swc(
name = "compile_nested",
srcs = [
"src/sub/c.ts",
],
out_dir = "out_nested",
root_dir = "src/sub",
source_maps = True,
)

# Assert that the output of "compile" rule matches the expected file.
write_source_files(
name = "test",
Expand All @@ -23,6 +47,24 @@ write_source_files(
},
)

# Assert outputs for dot root_dir test
write_source_files(
name = "test_dot",
files = {
"expected_dot/src/a.js": ":out_dot/src/a.js",
"expected_dot/src/b.js": ":out_dot/src/b.js",
"expected_dot/src/sub/c.js": ":out_dot/src/sub/c.js",
},
)

# Assert outputs for nested root_dir test
write_source_files(
name = "test_nested",
files = {
"expected_nested/c.js": ":out_nested/c.js",
},
)

[
assert_json_matches(
name = "test_%s" % f.replace("/", "-"),
Expand All @@ -37,3 +79,26 @@ write_source_files(
"sub/c",
]
]

[
assert_json_matches(
name = "test_dot_%s" % f.replace("/", "-"),
file1 = ":out_dot/%s.js.map" % f,
file2 = "expected_dot/%s.js.map.golden" % f,
filter1 = ".sourceRoot,.sources",
filter2 = ".sourceRoot,.sources",
)
for f in [
"src/a",
"src/b",
"src/sub/c",
]
]

assert_json_matches(
name = "test_nested_c",
file1 = ":out_nested/c.js.map",
file2 = "expected_nested/c.js.map.golden",
filter1 = ".sourceRoot,.sources",
filter2 = ".sourceRoot,.sources",
)
3 changes: 3 additions & 0 deletions examples/root_dir/expected_dot/src/a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/root_dir/expected_dot/src/a.js.map.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sources": [
"../../src/a.ts"
]
}
3 changes: 3 additions & 0 deletions examples/root_dir/expected_dot/src/b.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/root_dir/expected_dot/src/b.js.map.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sources": [
"../../src/b.ts"
]
}
3 changes: 3 additions & 0 deletions examples/root_dir/expected_dot/src/sub/c.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/root_dir/expected_dot/src/sub/c.js.map.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sources": [
"../../../src/sub/c.ts"
]
}
3 changes: 3 additions & 0 deletions examples/root_dir/expected_nested/c.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/root_dir/expected_nested/c.js.map.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sources": [
"../src/sub/c.ts"
]
}
2 changes: 1 addition & 1 deletion swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _calculate_source_file(ctx, src):
# out of src subdir
if src_pkg:
src_pkg_depth = len(src_pkg.split("/"))
root_dir_depth = len(ctx.attr.root_dir.split("/")) if ctx.attr.root_dir else 0
root_dir_depth = len(ctx.attr.root_dir.split("/")) if ctx.attr.root_dir and 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)]))

Expand Down