Skip to content

Commit

Permalink
Document that --config is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Jan 6, 2023
1 parent cfb3c92 commit fc4f36a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
34 changes: 30 additions & 4 deletions examples/custom_outs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
"""Demonstrate that js_outs can go to whatever file extensions you like."""

load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@aspect_rules_swc//swc:defs.bzl", "swc_compile")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

# Note, --config is documented on swcx CLI but isn't functional. See
# https://github.com/swc-project/swc/issues/4017#issuecomment-1374141572
# In the call to swc_compile below, we ought to be able to use
# `args = ["--config", "module.format=" + format]`
# As a workaround, write our config to an rc file. Can be changed back when swcx supports --config.
[
write_file(
name = "_write_swcrc_" + format,
out = "swcrc_" + format,
content = [json.encode({
"jsc": {
"parser": {
"syntax": "typescript",
},
},
"module": {
"type": format,
},
})],
)
for format in [
"commonjs",
"es6",
]
]

[
swc_compile(
name = "transpile_" + format,
srcs = ["a.ts"],
args = [
"--config",
"module.type=" + format,
],
# The extension of the outputs can be modified using js_outs
js_outs = [format + "/a." + ("cjs" if format == "commonjs" else "js")],
out_dir = format,
swcrc = "swcrc_" + format,
)
for format in [
"commonjs",
Expand Down
12 changes: 11 additions & 1 deletion examples/custom_outs/expected.cjs
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export var a = "a";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "a", {
enumerable: true,
get: function() {
return a;
}
});
var a = "a";

0 comments on commit fc4f36a

Please sign in to comment.