feat: add option for process cwd (.env support)
This commit is contained in:
@@ -17,10 +17,18 @@ runfiles_dir="${{RUNFILES_DIR:-$0.runfiles}}"
|
||||
bun_bin="${{runfiles_dir}}/_main/{bun_short_path}"
|
||||
entry_point="${{runfiles_dir}}/_main/{entry_short_path}"
|
||||
|
||||
exec "${{bun_bin}}" run "${{entry_point}}" "$@"
|
||||
working_dir="{working_dir}"
|
||||
if [[ "${{working_dir}}" == "entry_point" ]]; then
|
||||
cd "$(dirname "${{entry_point}}")"
|
||||
else
|
||||
cd "${{runfiles_dir}}/_main"
|
||||
fi
|
||||
|
||||
exec "${{bun_bin}}" --bun run "${{entry_point}}" "$@"
|
||||
""".format(
|
||||
bun_short_path = bun_bin.short_path,
|
||||
entry_short_path = entry_point.short_path,
|
||||
working_dir = ctx.attr.working_dir,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -50,6 +58,10 @@ bun_binary = rule(
|
||||
),
|
||||
"node_modules": attr.label(),
|
||||
"data": attr.label_list(allow_files = True),
|
||||
"working_dir": attr.string(
|
||||
default = "workspace",
|
||||
values = ["workspace", "entry_point"],
|
||||
),
|
||||
},
|
||||
executable = True,
|
||||
toolchains = ["//bun:toolchain_type"],
|
||||
|
||||
@@ -27,6 +27,7 @@ def _bun_bundle_impl(ctx):
|
||||
outputs.append(output)
|
||||
|
||||
args = ctx.actions.args()
|
||||
args.add("--bun")
|
||||
args.add("build")
|
||||
args.add(entry.path)
|
||||
args.add("--outfile")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"""Rule for running JS/TS scripts with Bun in watch mode for development."""
|
||||
|
||||
|
||||
def _bun_dev_impl(ctx):
|
||||
toolchain = ctx.toolchains["//bun:toolchain_type"]
|
||||
bun_bin = toolchain.bun.bun_bin
|
||||
@@ -18,7 +17,13 @@ set -euo pipefail
|
||||
runfiles_dir="${{RUNFILES_DIR:-$0.runfiles}}"
|
||||
bun_bin="${{runfiles_dir}}/_main/{bun_short_path}"
|
||||
entry_point="${{runfiles_dir}}/_main/{entry_short_path}"
|
||||
cd "${{runfiles_dir}}/_main"
|
||||
|
||||
working_dir="{working_dir}"
|
||||
if [[ "${{working_dir}}" == "entry_point" ]]; then
|
||||
cd "$(dirname "${{entry_point}}")"
|
||||
else
|
||||
cd "${{runfiles_dir}}/_main"
|
||||
fi
|
||||
|
||||
watch_mode="{watch_mode}"
|
||||
if [[ "${{watch_mode}}" == "hot" ]]; then
|
||||
@@ -28,7 +33,7 @@ else
|
||||
fi
|
||||
|
||||
run_dev() {{
|
||||
exec "${{bun_bin}}" "${{dev_flag}}" run "${{entry_point}}" "$@"
|
||||
exec "${{bun_bin}}" --bun "${{dev_flag}}" run "${{entry_point}}" "$@"
|
||||
}}
|
||||
|
||||
if [[ {restart_count} -eq 0 ]]; then
|
||||
@@ -50,8 +55,9 @@ file_mtime() {{
|
||||
|
||||
declare -A mtimes
|
||||
for rel in "${{restart_paths[@]}}"; do
|
||||
if [[ -e "${{rel}}" ]]; then
|
||||
mtimes["${{rel}}"]="$(file_mtime "${{rel}}")"
|
||||
path="${{runfiles_dir}}/_main/${{rel}}"
|
||||
if [[ -e "${{path}}" ]]; then
|
||||
mtimes["${{rel}}"]="$(file_mtime "${{path}}")"
|
||||
else
|
||||
mtimes["${{rel}}"]="missing"
|
||||
fi
|
||||
@@ -63,7 +69,7 @@ restart_child() {{
|
||||
kill "${{child_pid}}"
|
||||
wait "${{child_pid}}" || true
|
||||
fi
|
||||
"${{bun_bin}}" "${{dev_flag}}" run "${{entry_point}}" "$@" &
|
||||
"${{bun_bin}}" --bun "${{dev_flag}}" run "${{entry_point}}" "$@" &
|
||||
child_pid=$!
|
||||
}}
|
||||
|
||||
@@ -82,8 +88,9 @@ while true; do
|
||||
sleep 1
|
||||
changed=0
|
||||
for rel in "${{restart_paths[@]}}"; do
|
||||
if [[ -e "${{rel}}" ]]; then
|
||||
current="$(file_mtime "${{rel}}")"
|
||||
path="${{runfiles_dir}}/_main/${{rel}}"
|
||||
if [[ -e "${{path}}" ]]; then
|
||||
current="$(file_mtime "${{path}}")"
|
||||
else
|
||||
current="missing"
|
||||
fi
|
||||
@@ -100,6 +107,7 @@ done
|
||||
bun_short_path = bun_bin.short_path,
|
||||
entry_short_path = entry_point.short_path,
|
||||
watch_mode = ctx.attr.watch_mode,
|
||||
working_dir = ctx.attr.working_dir,
|
||||
restart_count = len(ctx.files.restart_on),
|
||||
restart_watch_paths = restart_watch_paths,
|
||||
),
|
||||
@@ -121,7 +129,6 @@ done
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
bun_dev = rule(
|
||||
implementation = _bun_dev_impl,
|
||||
attrs = {
|
||||
@@ -136,6 +143,10 @@ bun_dev = rule(
|
||||
"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"],
|
||||
),
|
||||
},
|
||||
executable = True,
|
||||
toolchains = ["//bun:toolchain_type"],
|
||||
|
||||
@@ -36,14 +36,14 @@ def _bun_install_repository_impl(repository_ctx):
|
||||
repository_ctx.symlink(bun_lockfile, "bun.lockb")
|
||||
|
||||
result = repository_ctx.execute(
|
||||
[str(bun_bin), "install", "--frozen-lockfile", "--no-progress"],
|
||||
[str(bun_bin), "--bun", "install", "--frozen-lockfile", "--no-progress"],
|
||||
timeout = 600,
|
||||
quiet = False,
|
||||
environment = {"HOME": str(repository_ctx.path("."))},
|
||||
)
|
||||
|
||||
if result.return_code:
|
||||
fail("""bun_install failed running `bun install --frozen-lockfile`.
|
||||
fail("""bun_install failed running `bun --bun install --frozen-lockfile`.
|
||||
stdout:
|
||||
{}
|
||||
stderr:
|
||||
|
||||
@@ -24,15 +24,15 @@ bun_bin="${{runfiles_dir}}/_main/{bun_short_path}"
|
||||
cd "${{runfiles_dir}}/_main"
|
||||
|
||||
if [[ -n "${{TESTBRIDGE_TEST_ONLY:-}}" && -n "${{COVERAGE_DIR:-}}" ]]; then
|
||||
exec "${{bun_bin}}" test {src_args} --test-name-pattern "${{TESTBRIDGE_TEST_ONLY}}" --coverage "$@"
|
||||
exec "${{bun_bin}}" --bun test {src_args} --test-name-pattern "${{TESTBRIDGE_TEST_ONLY}}" --coverage "$@"
|
||||
fi
|
||||
if [[ -n "${{TESTBRIDGE_TEST_ONLY:-}}" ]]; then
|
||||
exec "${{bun_bin}}" test {src_args} --test-name-pattern "${{TESTBRIDGE_TEST_ONLY}}" "$@"
|
||||
exec "${{bun_bin}}" --bun test {src_args} --test-name-pattern "${{TESTBRIDGE_TEST_ONLY}}" "$@"
|
||||
fi
|
||||
if [[ -n "${{COVERAGE_DIR:-}}" ]]; then
|
||||
exec "${{bun_bin}}" test {src_args} --coverage "$@"
|
||||
exec "${{bun_bin}}" --bun test {src_args} --coverage "$@"
|
||||
fi
|
||||
exec "${{bun_bin}}" test {src_args} "$@"
|
||||
exec "${{bun_bin}}" --bun test {src_args} "$@"
|
||||
""".format(
|
||||
bun_short_path = bun_bin.short_path,
|
||||
src_args = src_args,
|
||||
|
||||
Reference in New Issue
Block a user