Skip to content

Commit

Permalink
feat: add support for source-file-name and source-root
Browse files Browse the repository at this point in the history
Fixes #166
  • Loading branch information
realtimetodie authored and alexeagle committed Feb 28, 2023
1 parent bfb08cf commit 0d82178
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
6 changes: 4 additions & 2 deletions examples/filegroup/check_outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ cd "$TEST_SRCDIR/$TEST_WORKSPACE/$(dirname $TEST_TARGET)"

grep "export var a" filegroup/a.js
grep "sourceMappingURL=a.js.map" filegroup/a.js
grep --fixed-strings '"sources":["examples/filegroup/a.ts"]' filegroup/a.js.map
grep --fixed-strings '"sourceRoot":"examples/filegroup"' filegroup/a.js.map
grep --fixed-strings '"sources":["a.ts"]' filegroup/a.js.map

grep "export var b" filegroup/b.js
grep "sourceMappingURL=b.js.map" filegroup/b.js
grep --fixed-strings '"sources":["examples/filegroup/b.ts"]' filegroup/b.js.map
grep --fixed-strings '"sourceRoot":"examples/filegroup"' filegroup/b.js.map
grep --fixed-strings '"sources":["b.ts"]' filegroup/b.js.map
26 changes: 9 additions & 17 deletions swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def _impl(ctx):

# Add user specified arguments *before* rule supplied arguments
args.add_all(ctx.attr.args)
args.add_all(["--source-maps", ctx.attr.source_maps])

args.add("--source-maps", ctx.attr.source_maps)

plugin_cache = []
plugin_args = []
Expand Down Expand Up @@ -222,17 +223,11 @@ def _impl(ctx):

output_sources = [output_dir]

args.add_all([
"--out-dir",
output_dir.path,
])
args.add("--out-dir", output_dir.path)

src_args = ctx.actions.args()
if ctx.attr.swcrc:
src_args.add_all([
"--config-file",
ctx.file.swcrc.path,
])
src_args.add("--config-file", ctx.file.swcrc.path)
inputs.append(ctx.file.swcrc)

_swc_action(
Expand All @@ -251,6 +246,9 @@ def _impl(ctx):

for src in ctx.files.srcs:
src_args = ctx.actions.args()
src_args.add("--source-file-name", src.basename)
src_args.add("--source-root", src.dirname)

src_path = _relative_to_package(src.path, ctx)

js_out_path = _calculate_js_out(src_path, ctx.attr.out_dir, ctx.attr.root_dir, [_relative_to_package(f.path, ctx) for f in ctx.outputs.js_outs])
Expand All @@ -271,16 +269,10 @@ def _impl(ctx):
inputs.extend(plugin_cache)

if ctx.attr.swcrc:
src_args.add_all([
"--config-file",
ctx.file.swcrc.path,
])
src_args.add("--config-file", ctx.file.swcrc.path)
inputs.append(ctx.file.swcrc)

src_args.add_all([
"--out-file",
js_out.path,
])
src_args.add("--out-file", js_out.path)

output_sources.extend(outputs)

Expand Down

0 comments on commit 0d82178

Please sign in to comment.