From ccaa3325d03f131d07df8a5617e14b347160d46f Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 21 Dec 2021 12:40:48 -0800 Subject: [PATCH] fix: expose the raw swc rule This is needed when using it with the ts_project#transpiler attribute, as it wants to set js_outs rather than reuse the swc macro to do that. --- docs/swc.md | 29 +++++++++++++++++++++++++++++ swc/private/swc.bzl | 12 ++++++------ swc/swc.bzl | 8 ++++++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/docs/swc.md b/docs/swc.md index a5a2b01..2554f9d 100644 --- a/docs/swc.md +++ b/docs/swc.md @@ -2,6 +2,35 @@ swc rule + + +## swc_rule + +
+swc_rule(name, args, data, js_outs, map_outs, output_dir, srcs, swc_cli, swcrc)
+
+ +Underlying rule for the `swc` macro. + + Use this if you need more control over how the rule is called, + for example to set your own output labels for `js_outs`. + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| args | additional arguments to pass to swc cli, see https://swc.rs/docs/usage/cli | List of strings | optional | [] | +| data | runtime dependencies propagated to binaries that depend on this | List of labels | optional | [] | +| js_outs | - | List of labels | optional | | +| map_outs | - | List of labels | optional | | +| output_dir | whether to produce a directory output rather than individual files | Boolean | optional | False | +| srcs | source files, typically .ts files in the source tree | List of labels | required | | +| swc_cli | binary that executes the swc CLI | Label | optional | @aspect_rules_swc//swc:cli | +| swcrc | label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc | Label | optional | None | + + ## swc diff --git a/swc/private/swc.bzl b/swc/private/swc.bzl index 738f0f8..b11dc78 100644 --- a/swc/private/swc.bzl +++ b/swc/private/swc.bzl @@ -3,13 +3,13 @@ load("@bazel_skylib//lib:paths.bzl", "paths") _attrs = { - "srcs": attr.label_list(allow_files = True, mandatory = True), - "args": attr.string_list(), - "source_maps": attr.string(), - "output_dir": attr.bool(), - "data": attr.label_list(default = [], allow_files = True), - "swcrc": attr.label(allow_single_file = True), + "srcs": attr.label_list(allow_files = True, mandatory = True, doc = "source files, typically .ts files in the source tree"), + "args": attr.string_list(doc = "additional arguments to pass to swc cli, see https://swc.rs/docs/usage/cli"), + "output_dir": attr.bool(doc = "whether to produce a directory output rather than individual files"), + "data": attr.label_list(default = [], allow_files = True, doc = "runtime dependencies propagated to binaries that depend on this"), + "swcrc": attr.label(allow_single_file = True, doc = "label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc"), "swc_cli": attr.label( + doc = "binary that executes the swc CLI", default = "@aspect_rules_swc//swc:cli", executable = True, cfg = "exec", diff --git a/swc/swc.bzl b/swc/swc.bzl index 71a7137..31b05c8 100644 --- a/swc/swc.bzl +++ b/swc/swc.bzl @@ -3,7 +3,11 @@ load("//swc/private:swc.bzl", _swc_lib = "swc") load("@bazel_skylib//lib:paths.bzl", "paths") -_swc = rule( +swc_rule = rule( + doc = """Underlying rule for the `swc` macro. + + Use this if you need more control over how the rule is called, + for example to set your own output labels for `js_outs`.""", implementation = _swc_lib.implementation, attrs = _swc_lib.attrs, toolchains = _swc_lib.toolchains, @@ -64,7 +68,7 @@ def swc(name, srcs = None, args = [], data = [], output_dir = False, swcrc = Non if source_map_outputs: map_outs.append(paths.replace_extension(f, ".js.map")) - _swc( + swc_rule( name = name, srcs = srcs, js_outs = js_outs,