feat: improve rules_js parity

This commit is contained in:
eric
2026-03-14 23:50:26 +01:00
parent d7a6d6b0ba
commit c446f23a35
36 changed files with 1683 additions and 639 deletions

View File

@@ -0,0 +1,41 @@
load("//js:defs.bzl", "js_binary", "js_run_devserver", "js_test", "ts_library")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
ts_library(
name = "helper_lib",
srcs = ["helper.ts"],
data = ["payload.txt"],
)
js_binary(
name = "compat_bin",
entry_point = "main.ts",
deps = [":helper_lib"],
args = ["compat-mode"],
)
sh_test(
name = "js_binary_compat_test",
srcs = ["run_binary.sh"],
args = ["$(location :compat_bin)"],
data = [":compat_bin"],
)
js_test(
name = "compat_suite",
entry_point = "app.test.ts",
deps = [":helper_lib"],
)
js_run_devserver(
name = "compat_devserver",
tool = ":compat_bin",
args = ["devserver-mode"],
)
sh_test(
name = "js_run_devserver_compat_test",
srcs = ["run_devserver.sh"],
args = ["$(location :compat_devserver)"],
data = [":compat_devserver"],
)

View File

@@ -0,0 +1,7 @@
import { expect, test } from "bun:test";
import { helperMessage } from "./helper.ts";
test("js_test compatibility layer propagates deps and data", () => {
expect(helperMessage()).toBe("helper:payload-from-lib");
});

View File

@@ -0,0 +1,6 @@
import { readFileSync } from "node:fs";
export function helperMessage(): string {
const payload = readFileSync(new URL("./payload.txt", import.meta.url), "utf8").trim();
return `helper:${payload}`;
}

View File

@@ -0,0 +1,3 @@
import { helperMessage } from "./helper.ts";
console.log(`${helperMessage()} ${Bun.argv.slice(2).join(" ")}`.trim());

View File

@@ -0,0 +1 @@
payload-from-lib

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
binary="$1"
output="$("${binary}")"
if [[ ${output} != "helper:payload-from-lib compat-mode" ]]; then
echo "unexpected output: ${output}" >&2
exit 1
fi

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
binary="$1"
output="$("${binary}")"
if [[ ${output} != "helper:payload-from-lib compat-mode devserver-mode" ]]; then
echo "unexpected output: ${output}" >&2
exit 1
fi