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

200
flake.nix
View File

@@ -3,143 +3,50 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.0.1";
devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
repo-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/v3.0.0";
repo-lib.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
devshell-lib,
repo-lib,
...
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
bazelVersion = "9.0.0";
in
{
devShells = forAllSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
bazel9 = pkgs.writeShellScriptBin "bazel" ''
export USE_BAZEL_VERSION="''${USE_BAZEL_VERSION:-9.0.0}"
exec ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
env = devshell-lib.lib.mkDevShell {
inherit system;
repo-lib.lib.mkRepo {
inherit self nixpkgs;
src = ./.;
extraPackages = with pkgs; [
go
gopls
gotools
bun
bazel9
bazel-buildtools
self.packages.${system}.release
];
config = {
shell.extraShellText = ''
export USE_BAZEL_VERSION="''${USE_BAZEL_VERSION:-${bazelVersion}}"
export BUN_INSTALL="''${BUN_INSTALL:-$HOME/.bun}"
export PATH="$BUN_INSTALL/bin:$PATH"
'';
features = {
oxfmt = false;
};
formatting = {
programs.shfmt.enable = true;
settings.shfmt.options = [
"-i"
"2"
"-s"
"-w"
];
};
formatters = {
shfmt.enable = true;
};
formatterSettings = {
shfmt.options = [
"-i"
"2"
"-s"
"-w"
];
};
additionalHooks = {
tests = {
enable = true;
entry = ''
bazel test //tests/...
'';
pass_filenames = false;
stages = [ "pre-push" ];
};
};
tools = [
{
name = "Bun";
bin = "${pkgs.bun}/bin/bun";
versionCmd = "--version";
color = "YELLOW";
}
{
name = "Go";
bin = "${pkgs.go}/bin/go";
versionCmd = "version";
color = "CYAN";
}
{
name = "Bazel";
bin = "${bazel9}/bin/bazel";
versionCmd = "--version";
color = "GREEN";
}
];
extraShellHook = ''
export USE_BAZEL_VERSION="''${USE_BAZEL_VERSION:-9.0.0}"
export BUN_INSTALL="''${BUN_INSTALL:-$HOME/.bun}"
export PATH="$BUN_INSTALL/bin:$PATH"
'';
};
in
{
default = env.shell;
}
);
checks = forAllSystems (
system:
let
env = devshell-lib.lib.mkDevShell { inherit system; };
in
{
inherit (env) pre-commit-check;
}
);
formatter = forAllSystems (system: (devshell-lib.lib.mkDevShell { inherit system; }).formatter);
# Optional: release command (`release`)
#
# The release script always updates VERSION first, then:
# 1) runs release steps in order (file writes and scripts)
# 2) runs postVersion hook
# 3) formats, stages, commits, tags, and pushes
#
# Runtime env vars available in release.run/postVersion:
# BASE_VERSION, CHANNEL, PRERELEASE_NUM, FULL_VERSION, FULL_TAG
#
packages = forAllSystems (system: {
release = devshell-lib.lib.mkRelease {
inherit system;
release = [
release = {
steps = [
{
run = ''
run.script = ''
sed -E -i 's#^([[:space:]]*version[[:space:]]*=[[:space:]]*")[^"]*(",)$#\1'"$FULL_VERSION"'\2#' "$ROOT_DIR/MODULE.bazel"
'';
}
{
run = ''
run.script = ''
README="$ROOT_DIR/README.md"
TMP="$README.tmp"
@@ -174,8 +81,59 @@
echo "Released $FULL_TAG"
'';
};
});
};
perSystem =
{
pkgs,
system,
...
}:
let
bazel9 = pkgs.writeShellScriptBin "bazel" ''
export USE_BAZEL_VERSION="''${USE_BAZEL_VERSION:-${bazelVersion}}"
exec ${pkgs.bazelisk}/bin/bazelisk "$@"
'';
in
{
tools = [
(repo-lib.lib.tools.fromPackage {
name = "Bun";
package = pkgs.bun;
version.args = [ "--version" ];
banner.color = "YELLOW";
})
(repo-lib.lib.tools.fromPackage {
name = "Go";
package = pkgs.go;
version.args = [ "version" ];
banner.color = "CYAN";
})
(repo-lib.lib.tools.fromPackage {
name = "Bazel";
package = bazel9;
version.args = [ "--version" ];
banner.color = "GREEN";
})
];
shell.packages = [
pkgs.gopls
pkgs.gotools
pkgs.bazel-buildtools
self.packages.${system}.release
];
checks.tests = {
command = "bazel test //tests/...";
stage = "pre-push";
passFilenames = false;
runtimeInputs = [
bazel9
pkgs.bun
pkgs.go
];
};
};
};
}