Skip to content

Commit

Permalink
Merge pull request #309 from kczulko/master
Browse files Browse the repository at this point in the history
Add example for nodejs toolchain with npm_install repository rule
  • Loading branch information
mergify[bot] authored Feb 8, 2023
2 parents 726e2b7 + ba39abb commit 6563f78
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/**/bazel-*

/**/node_modules
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

[Unreleased]: https://github.com/tweag/rules_nixpkgs/compare/v0.8.0...HEAD
[Unreleased]: https://github.com/tweag/rules_nixpkgs/compare/v0.9.0...HEAD

### Added
- nixpkgs_nodejs_configure_platforms for platform transparent npm_install
See [#309]

## [0.9.0] - 2022-07-19

[0.9.0]: https://github.com/tweag/rules_nixpkgs/compare/v0.9.0...v0.9.0
[0.9.0]: https://github.com/tweag/rules_nixpkgs/compare/v0.8.0...v0.9.0

### Added

Expand Down
1 change: 1 addition & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ generate_documentation(
"nixpkgs_rust_configure",
"nixpkgs_sh_posix_configure",
"nixpkgs_nodejs_configure",
"nixpkgs_nodejs_configure_platforms",
],
deps = [
"@io_tweag_rules_nixpkgs//nixpkgs",
Expand Down
1 change: 1 addition & 0 deletions examples/toolchains/nodejs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
nodejs_binary(
name = "hello",
entry_point = ":hello.js",
data = [ "@npm//ololog", ]
)
26 changes: 13 additions & 13 deletions examples/toolchains/nodejs/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ local_repository(

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_nodejs",
sha256 = "5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz"],
)

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "f10a3a12894fc3c9bf578ee5a5691769f6805c4be84359681a785a0c12e8d2b6",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-5.5.3.tar.gz"],
sha256 = "dcc55f810142b6cf46a44d0180a5a7fb923c04a5061e2e8d8eb05ccccc60864b",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.0/rules_nodejs-5.8.0.tar.gz"],
)

load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
Expand All @@ -34,12 +28,18 @@ nixpkgs_git_repository(
sha256 = "0f8c25433a6611fa5664797cd049c80faefec91575718794c701f3b033f2db01",
)

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_nodejs_configure")

nixpkgs_nodejs_configure(
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_nodejs_configure_platforms")
nixpkgs_nodejs_configure_platforms(
name = "nixpkgs-nodejs",
repository = "@nixpkgs",
)

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
npm_install(
name = "npm",
exports_directories_only = True,
node_repository = "nixpkgs-nodejs",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
)

node_repositories()
5 changes: 4 additions & 1 deletion examples/toolchains/nodejs/hello.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
console.log("Hello world!")
const log = require ('ololog')

log("Hello world!")

179 changes: 179 additions & 0 deletions examples/toolchains/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/toolchains/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"ololog": "^1.1.175"
}
}
2 changes: 1 addition & 1 deletion examples/toolchains/nodejs/shell.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{ pkgs ? import ./nixpkgs.nix { } }:

pkgs.mkShellNoCC { nativeBuildInputs = [ pkgs.bazel_6 ]; }
pkgs.mkShellNoCC { nativeBuildInputs = with pkgs; [ bazel_6 ]; }
2 changes: 2 additions & 0 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ load(
load(
"@rules_nixpkgs_nodejs//:nodejs.bzl",
_nixpkgs_nodejs_configure = "nixpkgs_nodejs_configure",
_nixpkgs_nodejs_configure_platforms = "nixpkgs_nodejs_configure_platforms",
)

# aliases for backwards compatibility prior to `bzlmod`
Expand All @@ -162,6 +163,7 @@ nixpkgs_cc_configure = _nixpkgs_cc_configure
nixpkgs_rust_configure = _nixpkgs_rust_configure
nixpkgs_sh_posix_configure = _nixpkgs_sh_posix_configure
nixpkgs_nodejs_configure = _nixpkgs_nodejs_configure
nixpkgs_nodejs_configure_platforms = _nixpkgs_nodejs_configure_platforms

def nixpkgs_cc_autoconf_impl(repository_ctx):
cpu_value = get_cpu_value(repository_ctx)
Expand Down
6 changes: 6 additions & 0 deletions nixpkgs/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def rules_nixpkgs_dependencies(rules_nixpkgs_name = "io_tweag_rules_nixpkgs", to
strip_prefix = "rules_java-5.0.0",
url = "https://github.com/bazelbuild/rules_java/archive/refs/tags/5.0.0.tar.gz",
)
maybe(
http_archive,
"rules_nodejs",
sha256 = "08337d4fffc78f7fe648a93be12ea2fc4e8eb9795a4e6aa48595b66b34555626",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.0/rules_nodejs-core-5.8.0.tar.gz"],
)

# the following complication is due to migrating to `bzlmod`.
# fetch extracted submodules as external repositories from an existing source tree, based on the import type.
Expand Down
1 change: 1 addition & 0 deletions toolchains/nodejs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ bzl_library(
srcs = ["//:nodejs.bzl"],
deps = [
"@rules_nixpkgs_core//:nixpkgs",
"@rules_nodejs//nodejs:bzl",
],
)
Loading

0 comments on commit 6563f78

Please sign in to comment.