feat: add phase 6 js_library and ts_library bootstrap

This commit is contained in:
Eric
2026-03-04 07:31:19 +00:00
committed by copilot-swe-agent[bot]
parent e671447d13
commit 9868933b27
10 changed files with 127 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
"""Rule for bundling JS/TS sources with Bun."""
load("//internal:js_library.bzl", "BunSourcesInfo")
def _output_name(target_name, entry):
stem = entry.basename.rsplit(".", 1)[0]
@@ -13,6 +15,11 @@ def _bun_bundle_impl(ctx):
transitive_inputs = []
if ctx.attr.node_modules:
transitive_inputs.append(ctx.attr.node_modules[DefaultInfo].files)
for dep in ctx.attr.deps:
if BunSourcesInfo in dep:
transitive_inputs.append(dep[BunSourcesInfo].transitive_sources)
else:
transitive_inputs.append(dep[DefaultInfo].files)
outputs = []
for entry in ctx.files.entry_points:
@@ -59,6 +66,7 @@ bun_bundle = rule(
allow_files = [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"],
),
"node_modules": attr.label(),
"deps": attr.label_list(),
"data": attr.label_list(allow_files = True),
"target": attr.string(
default = "browser",

View File

@@ -1,5 +1,7 @@
"""Rule for running test suites with Bun."""
load("//internal:js_library.bzl", "BunSourcesInfo")
def _shell_quote(value):
return "'" + value.replace("'", "'\"'\"'") + "'"
@@ -34,6 +36,11 @@ exec "{bun_bin}" test {src_args} "${{extra_args[@]}}" "$@"
transitive_files = []
if ctx.attr.node_modules:
transitive_files.append(ctx.attr.node_modules[DefaultInfo].files)
for dep in ctx.attr.deps:
if BunSourcesInfo in dep:
transitive_files.append(dep[BunSourcesInfo].transitive_sources)
else:
transitive_files.append(dep[DefaultInfo].files)
runfiles = ctx.runfiles(
files = [bun_bin] + ctx.files.srcs + ctx.files.data,
@@ -56,6 +63,7 @@ bun_test = rule(
allow_files = [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"],
),
"node_modules": attr.label(),
"deps": attr.label_list(),
"data": attr.label_list(allow_files = True),
},
test = True,

40
internal/js_library.bzl Normal file
View File

@@ -0,0 +1,40 @@
"""Lightweight JS/TS source grouping rules."""
BunSourcesInfo = provider(fields = ["transitive_sources"])
def _bun_library_impl(ctx):
transitive_sources = [
dep[BunSourcesInfo].transitive_sources
for dep in ctx.attr.deps
if BunSourcesInfo in dep
]
all_sources = depset(
direct = ctx.files.srcs,
transitive = transitive_sources,
)
return [
BunSourcesInfo(transitive_sources = all_sources),
DefaultInfo(files = all_sources),
]
js_library = rule(
implementation = _bun_library_impl,
attrs = {
"srcs": attr.label_list(
allow_files = [".js", ".jsx", ".mjs", ".cjs"],
),
"deps": attr.label_list(),
},
)
ts_library = rule(
implementation = _bun_library_impl,
attrs = {
"srcs": attr.label_list(
allow_files = [".ts", ".tsx"],
),
"deps": attr.label_list(),
},
)