Skip to content

Commit b9ed818

Browse files
authored
Merge pull request #677 from tweag/nodejs_bzlmod
Convert the nodejs toolchain example to bzlmod
2 parents 3147ff7 + 4f01776 commit b9ed818

File tree

27 files changed

+946
-99
lines changed

27 files changed

+946
-99
lines changed

examples/cc-template/flake.lock

Lines changed: 25 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cc-template/flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
inputs = {
33
# Track a specific tag on the nixpkgs repo.
4-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
55

66
# The flake format itself is very minimal, so the use of this
77
# library is common.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# @generated
2+
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "@@//:pnpm-lock.yaml").
3+
# This file should be checked into version control along with the pnpm-lock.yaml file.
4+
package-lock.json=1929670025
5+
package.json=75205318
6+
pnpm-lock.yaml=138343633

examples/toolchains/nodejs/.bazeliskrc

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
USE_BAZEL_VERSION=7.x
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import %workspace%/../../../.bazelrc.remote-cache
22

3-
build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
3+
build:nix --host_platform=@rules_nixpkgs_core//platforms:host

examples/toolchains/nodejs/BUILD

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
2-
nodejs_binary(
1+
load("@npm//:defs.bzl", "npm_link_all_packages")
2+
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary", "js_test")
3+
4+
npm_link_all_packages(name = "node_modules")
5+
6+
js_binary(
37
name = "hello",
48
entry_point = ":hello.js",
5-
data = [ "@npm//ololog", ]
9+
data = [ ":node_modules/ololog", ]
610
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
module(
2+
name = "hello_world_nodejs",
3+
version = "0.0.0",
4+
)
5+
6+
bazel_dep(name = "rules_nixpkgs_core", version = "0.0.0")
7+
local_path_override(
8+
module_name = "rules_nixpkgs_core",
9+
path = "../../../core",
10+
)
11+
bazel_dep(name = "rules_nixpkgs_nodejs", version = "0.0.0")
12+
local_path_override(
13+
module_name = "rules_nixpkgs_nodejs",
14+
path = "../../../toolchains/nodejs",
15+
)
16+
17+
bazel_dep(name = "platforms", version = "1.0.0")
18+
bazel_dep(name = "rules_nodejs", version = "6.3.0")
19+
bazel_dep(name = "aspect_rules_js", version = "2.8.0")
20+
21+
#
22+
# Nixpkgs
23+
#
24+
25+
nix_repo = use_extension("@rules_nixpkgs_core//extensions:repository.bzl", "nix_repo")
26+
nix_repo.file(
27+
name = "nixpkgs",
28+
file = "//:nixpkgs.nix",
29+
file_deps = [
30+
"//:nixpkgs.json",
31+
],
32+
)
33+
use_repo(nix_repo, "nixpkgs")
34+
35+
nodejs_configure = use_extension("//:extension.bzl", "nodejs_configure")
36+
use_repo(nodejs_configure, "nixpkgs_nodejs")
37+
use_repo(nodejs_configure, "nixpkgs_nodejs_toolchain")
38+
39+
register_toolchains("@nixpkgs_nodejs_toolchain//:all")
40+
41+
#
42+
# NPM dependencies
43+
#
44+
45+
npm = use_extension(
46+
"@aspect_rules_js//npm:extensions.bzl",
47+
"npm",
48+
dev_dependency = True,
49+
)
50+
npm.npm_translate_lock(
51+
name = "npm",
52+
npm_package_lock = "//:package-lock.json",
53+
pnpm_lock = "//:pnpm-lock.yaml",
54+
data = [
55+
"//:package.json"
56+
],
57+
update_pnpm_lock = True,
58+
)
59+
use_repo(npm, "npm")

0 commit comments

Comments
 (0)