From 0d82178e1db354951bde52449df1ba420d6fe9be Mon Sep 17 00:00:00 2001 From: shooj4aegohbaivo Date: Mon, 27 Feb 2023 11:09:48 +0100 Subject: [PATCH] feat: add support for source-file-name and source-root Fixes https://github.com/aspect-build/rules_swc/issues/166 --- examples/filegroup/check_outputs.sh | 6 ++++-- swc/private/swc.bzl | 26 +++++++++----------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/examples/filegroup/check_outputs.sh b/examples/filegroup/check_outputs.sh index de96ec7..b1b36ab 100755 --- a/examples/filegroup/check_outputs.sh +++ b/examples/filegroup/check_outputs.sh @@ -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 \ No newline at end of file +grep --fixed-strings '"sourceRoot":"examples/filegroup"' filegroup/b.js.map +grep --fixed-strings '"sources":["b.ts"]' filegroup/b.js.map \ No newline at end of file diff --git a/swc/private/swc.bzl b/swc/private/swc.bzl index db10bb0..e8ae7bb 100644 --- a/swc/private/swc.bzl +++ b/swc/private/swc.bzl @@ -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 = [] @@ -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( @@ -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]) @@ -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)