feat: add docs
This commit is contained in:
@@ -1,10 +1,39 @@
|
||||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
exports_files([
|
||||
"bun_binary.bzl",
|
||||
"bun_bundle.bzl",
|
||||
"bun_dev.bzl",
|
||||
"bun_install.bzl",
|
||||
"bun_test.bzl",
|
||||
"js_library.bzl",
|
||||
"bun_binary.bzl",
|
||||
"bun_bundle.bzl",
|
||||
"bun_dev.bzl",
|
||||
"bun_install.bzl",
|
||||
"bun_test.bzl",
|
||||
"js_library.bzl",
|
||||
])
|
||||
|
||||
bzl_library(
|
||||
name = "bun_binary_bzl",
|
||||
srcs = ["bun_binary.bzl"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "bun_bundle_bzl",
|
||||
srcs = ["bun_bundle.bzl"],
|
||||
deps = [":js_library_bzl"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "bun_dev_bzl",
|
||||
srcs = ["bun_dev.bzl"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "bun_test_bzl",
|
||||
srcs = ["bun_test.bzl"],
|
||||
deps = [":js_library_bzl"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "js_library_bzl",
|
||||
srcs = ["js_library.bzl"],
|
||||
)
|
||||
|
||||
@@ -51,16 +51,27 @@ exec "${{bun_bin}}" --bun run "${{entry_point}}" "$@"
|
||||
|
||||
bun_binary = rule(
|
||||
implementation = _bun_binary_impl,
|
||||
doc = """Runs a JS/TS entry point with Bun as an executable target.
|
||||
|
||||
Use this rule for non-test scripts and CLIs that should run via `bazel run`.
|
||||
""",
|
||||
attrs = {
|
||||
"entry_point": attr.label(
|
||||
mandatory = True,
|
||||
allow_single_file = [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"],
|
||||
doc = "Path to the main JS/TS file to execute.",
|
||||
),
|
||||
"node_modules": attr.label(
|
||||
doc = "Optional label providing Bun/npm package files in runfiles.",
|
||||
),
|
||||
"data": attr.label_list(
|
||||
allow_files = True,
|
||||
doc = "Additional runtime files required by the program.",
|
||||
),
|
||||
"node_modules": attr.label(),
|
||||
"data": attr.label_list(allow_files = True),
|
||||
"working_dir": attr.string(
|
||||
default = "workspace",
|
||||
values = ["workspace", "entry_point"],
|
||||
doc = "Working directory at runtime: `workspace` root or `entry_point` directory.",
|
||||
),
|
||||
},
|
||||
executable = True,
|
||||
|
||||
@@ -61,25 +61,47 @@ def _bun_bundle_impl(ctx):
|
||||
|
||||
bun_bundle = rule(
|
||||
implementation = _bun_bundle_impl,
|
||||
doc = """Bundles one or more JS/TS entry points using Bun build.
|
||||
|
||||
Each entry point produces one output JavaScript artifact.
|
||||
""",
|
||||
attrs = {
|
||||
"entry_points": attr.label_list(
|
||||
mandatory = True,
|
||||
allow_files = [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"],
|
||||
doc = "Entry files to bundle.",
|
||||
),
|
||||
"node_modules": attr.label(
|
||||
doc = "Optional label providing Bun/npm package files for resolution.",
|
||||
),
|
||||
"deps": attr.label_list(
|
||||
doc = "Source/library dependencies that provide transitive inputs.",
|
||||
),
|
||||
"data": attr.label_list(
|
||||
allow_files = True,
|
||||
doc = "Additional non-source files needed during bundling.",
|
||||
),
|
||||
"node_modules": attr.label(),
|
||||
"deps": attr.label_list(),
|
||||
"data": attr.label_list(allow_files = True),
|
||||
"target": attr.string(
|
||||
default = "browser",
|
||||
values = ["browser", "node", "bun"],
|
||||
doc = "Bun build target environment.",
|
||||
),
|
||||
"format": attr.string(
|
||||
default = "esm",
|
||||
values = ["esm", "cjs", "iife"],
|
||||
doc = "Output module format.",
|
||||
),
|
||||
"minify": attr.bool(
|
||||
default = False,
|
||||
doc = "If true, minifies bundle output.",
|
||||
),
|
||||
"sourcemap": attr.bool(
|
||||
default = False,
|
||||
doc = "If true, emits source maps.",
|
||||
),
|
||||
"external": attr.string_list(
|
||||
doc = "Package names to treat as externals (not bundled).",
|
||||
),
|
||||
"minify": attr.bool(default = False),
|
||||
"sourcemap": attr.bool(default = False),
|
||||
"external": attr.string_list(),
|
||||
},
|
||||
toolchains = ["//bun:toolchain_type"],
|
||||
)
|
||||
|
||||
@@ -131,21 +131,37 @@ done
|
||||
|
||||
bun_dev = rule(
|
||||
implementation = _bun_dev_impl,
|
||||
doc = """Runs a JS/TS entry point in Bun development watch mode.
|
||||
|
||||
This rule is intended for local dev loops (`bazel run`) and supports Bun
|
||||
watch/HMR plus optional full restarts on selected file changes.
|
||||
""",
|
||||
attrs = {
|
||||
"entry_point": attr.label(
|
||||
mandatory = True,
|
||||
allow_single_file = [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"],
|
||||
doc = "Path to the main JS/TS file to execute in dev mode.",
|
||||
),
|
||||
"watch_mode": attr.string(
|
||||
default = "watch",
|
||||
values = ["watch", "hot"],
|
||||
doc = "Bun live-reload mode: `watch` (default) or `hot`.",
|
||||
),
|
||||
"restart_on": attr.label_list(
|
||||
allow_files = True,
|
||||
doc = "Files that trigger a full Bun process restart when they change.",
|
||||
),
|
||||
"node_modules": attr.label(
|
||||
doc = "Optional label providing Bun/npm package files in runfiles.",
|
||||
),
|
||||
"data": attr.label_list(
|
||||
allow_files = True,
|
||||
doc = "Additional runtime files required by the dev process.",
|
||||
),
|
||||
"restart_on": attr.label_list(allow_files = True),
|
||||
"node_modules": attr.label(),
|
||||
"data": attr.label_list(allow_files = True),
|
||||
"working_dir": attr.string(
|
||||
default = "workspace",
|
||||
values = ["workspace", "entry_point"],
|
||||
doc = "Working directory at runtime: `workspace` root or `entry_point` directory.",
|
||||
),
|
||||
},
|
||||
executable = True,
|
||||
|
||||
@@ -63,14 +63,26 @@ exec "${{bun_bin}}" --bun test {src_args} "$@"
|
||||
|
||||
bun_test = rule(
|
||||
implementation = _bun_test_impl,
|
||||
doc = """Runs Bun tests as a Bazel test target.
|
||||
|
||||
Supports Bazel test filtering (`--test_filter`) and coverage integration.
|
||||
""",
|
||||
attrs = {
|
||||
"srcs": attr.label_list(
|
||||
mandatory = True,
|
||||
allow_files = [".js", ".ts", ".jsx", ".tsx", ".mjs", ".cjs"],
|
||||
doc = "Test source files passed to `bun test`.",
|
||||
),
|
||||
"node_modules": attr.label(
|
||||
doc = "Optional label providing Bun/npm package files in runfiles.",
|
||||
),
|
||||
"deps": attr.label_list(
|
||||
doc = "Library dependencies required by test sources.",
|
||||
),
|
||||
"data": attr.label_list(
|
||||
allow_files = True,
|
||||
doc = "Additional runtime files needed by tests.",
|
||||
),
|
||||
"node_modules": attr.label(),
|
||||
"deps": attr.label_list(),
|
||||
"data": attr.label_list(allow_files = True),
|
||||
},
|
||||
test = True,
|
||||
toolchains = ["//bun:toolchain_type"],
|
||||
|
||||
@@ -21,20 +21,28 @@ def _bun_library_impl(ctx):
|
||||
|
||||
js_library = rule(
|
||||
implementation = _bun_library_impl,
|
||||
doc = "Aggregates JavaScript sources and transitive Bun source dependencies.",
|
||||
attrs = {
|
||||
"srcs": attr.label_list(
|
||||
allow_files = [".js", ".jsx", ".mjs", ".cjs"],
|
||||
doc = "JavaScript source files in this library.",
|
||||
),
|
||||
"deps": attr.label_list(
|
||||
doc = "Other Bun source libraries to include transitively.",
|
||||
),
|
||||
"deps": attr.label_list(),
|
||||
},
|
||||
)
|
||||
|
||||
ts_library = rule(
|
||||
implementation = _bun_library_impl,
|
||||
doc = "Aggregates TypeScript sources and transitive Bun source dependencies.",
|
||||
attrs = {
|
||||
"srcs": attr.label_list(
|
||||
allow_files = [".ts", ".tsx"],
|
||||
doc = "TypeScript source files in this library.",
|
||||
),
|
||||
"deps": attr.label_list(
|
||||
doc = "Other Bun source libraries to include transitively.",
|
||||
),
|
||||
"deps": attr.label_list(),
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user