Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support .js inputs without out_dir #244

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/allow_js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Simple use case for swc: transpiling .js using the `swc` rule, similar to tsc with 'allowJs'
"""

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

# Runs `swc in.js > ../../bazel-bin/examples/js_outs/in.js`
swc(
name = "compile",
srcs = ["in.js"],
)

# Assert that the output of "compile" rule matches the expected file.
write_source_files(
name = "test",
# There is no pre-declared output of the "compile" rule because the input is .js
# so the the target name is used instead of output file.
files = {"expected.js": ":compile"},
)
1 change: 1 addition & 0 deletions examples/allow_js/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var a = "simple";
1 change: 1 addition & 0 deletions examples/allow_js/in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a = "simple";
10 changes: 1 addition & 9 deletions swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,10 @@ def _calculate_js_out(src, out_dir, root_dir, js_outs = []):
return js_out

def _calculate_js_outs(srcs, out_dir, root_dir):
if out_dir == None:
js_srcs = []
for src in srcs:
if src.endswith(".js"):
js_srcs.append(src)
if len(js_srcs) > 0:
fail("Detected swc rule with srcs=[{}, ...] and out_dir=None. Please set out_dir when compiling .js files.".format(", ".join(js_srcs[:3])))

out = []
for f in srcs:
js_out = _calculate_js_out(f, out_dir, root_dir)
if js_out:
if js_out and js_out != f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: copy comment from rules_ts and/or link to that spot?

out.append(js_out)
return out

Expand Down
Loading