Skip to content

Commit

Permalink
fix: expose the raw swc rule
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexeagle committed Dec 21, 2021
1 parent f539478 commit ccaa332
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
29 changes: 29 additions & 0 deletions docs/swc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

swc rule

<a id="#swc_rule"></a>

## swc_rule

<pre>
swc_rule(<a href="#swc_rule-name">name</a>, <a href="#swc_rule-args">args</a>, <a href="#swc_rule-data">data</a>, <a href="#swc_rule-js_outs">js_outs</a>, <a href="#swc_rule-map_outs">map_outs</a>, <a href="#swc_rule-output_dir">output_dir</a>, <a href="#swc_rule-srcs">srcs</a>, <a href="#swc_rule-swc_cli">swc_cli</a>, <a href="#swc_rule-swcrc">swcrc</a>)
</pre>

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 |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="swc_rule-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="swc_rule-args"></a>args | additional arguments to pass to swc cli, see https://swc.rs/docs/usage/cli | List of strings | optional | [] |
| <a id="swc_rule-data"></a>data | runtime dependencies propagated to binaries that depend on this | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="swc_rule-js_outs"></a>js_outs | - | List of labels | optional | |
| <a id="swc_rule-map_outs"></a>map_outs | - | List of labels | optional | |
| <a id="swc_rule-output_dir"></a>output_dir | whether to produce a directory output rather than individual files | Boolean | optional | False |
| <a id="swc_rule-srcs"></a>srcs | source files, typically .ts files in the source tree | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | required | |
| <a id="swc_rule-swc_cli"></a>swc_cli | binary that executes the swc CLI | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | @aspect_rules_swc//swc:cli |
| <a id="swc_rule-swcrc"></a>swcrc | label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


<a id="#swc"></a>

## swc
Expand Down
12 changes: 6 additions & 6 deletions swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions swc/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ccaa332

Please sign in to comment.