Skip to content

Commit ab5b8f4

Browse files
jbedardgregmagolan
authored andcommitted
feat: add orion plugin to generate js_binary for main.{js,ts} (#368)
1 parent 682acb8 commit ab5b8f4

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
configure:
22
languages:
33
javascript: true
4+
plugins:
5+
- .aspect/cli/main.star
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# TODO: delete when all rules_js rules added to aspect-cli
2+
aspect.register_rule_kind("js_binary", {
3+
"From": "@aspect_rules_js//js:defs.bzl",
4+
"MergeableAttrs": ["data"],
5+
"ResolveAttrs": ["entry_point", "data"],
6+
})
7+
8+
def declare_main_js(ctx):
9+
if len(ctx.sources) == 0:
10+
ctx.targets.remove("main")
11+
return
12+
13+
entry_point = ctx.sources[0].path.replace(".ts", ".js")
14+
15+
ctx.targets.add(
16+
name = "main",
17+
kind = "js_binary",
18+
attrs = {
19+
# The entry point file
20+
"entry_point": entry_point,
21+
"data": [
22+
aspect.Label(
23+
pkg = ctx.rel,
24+
name = "tsc",
25+
),
26+
],
27+
},
28+
)
29+
30+
aspect.register_configure_extension(
31+
id = "main_js",
32+
prepare = lambda _: aspect.PrepareResult(
33+
sources = [
34+
aspect.SourceGlobs("**/main.ts"),
35+
aspect.SourceGlobs("**/main.js"),
36+
],
37+
),
38+
declare = declare_main_js,
39+
)

pnpm-workspaces/apps/alpha/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ js_library(
2626

2727
js_binary(
2828
name = "main",
29-
data = [":pkg"],
29+
data = [":tsc"],
3030
entry_point = "src/main.js",
3131
)

0 commit comments

Comments
 (0)