diff --git a/.bcr/README.md b/.bcr/README.md new file mode 100644 index 0000000000..44ae7fe555 --- /dev/null +++ b/.bcr/README.md @@ -0,0 +1,9 @@ +# Bazel Central Registry + +When the ruleset is released, we want it to be published to the +Bazel Central Registry automatically: + + +This folder contains configuration files to automate the publish step. +See +for authoritative documentation about these files. diff --git a/.bcr/config.yml b/.bcr/config.yml new file mode 100644 index 0000000000..c78ab7eec3 --- /dev/null +++ b/.bcr/config.yml @@ -0,0 +1,5 @@ +# See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation + +fixedReleaser: + login: alexeagle + email: alex@aspect.dev diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json new file mode 100644 index 0000000000..b34f48ce25 --- /dev/null +++ b/.bcr/metadata.template.json @@ -0,0 +1,7 @@ +{ + "homepage": "https://github.com/bazelbuild/rules_nodejs", + "maintainers": [], + "repository": ["github:bazelbuild/rules_nodejs"], + "versions": [], + "yanked_versions": {} +} diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml new file mode 100644 index 0000000000..e76a8bb7b0 --- /dev/null +++ b/.bcr/presubmit.yml @@ -0,0 +1,10 @@ +bcr_test_module: + module_path: 'e2e/smoke' + matrix: + platform: ['debian10', 'macos', 'ubuntu2004', 'windows'] + tasks: + run_tests: + name: 'Run test module' + platform: ${{ platform }} + test_targets: + - '//...' diff --git a/.bcr/source.template.json b/.bcr/source.template.json new file mode 100644 index 0000000000..1c50eb2033 --- /dev/null +++ b/.bcr/source.template.json @@ -0,0 +1,5 @@ +{ + "integrity": "**leave this alone**", + "strip_prefix": "{REPO}-{VERSION}", + "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_nodejs-{TAG}.tar.gz" +} diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000000..41eb74156e --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,19 @@ +"bzlmod declaration for bazelbuild/rules_nodejs" + +module( + name = "rules_nodejs", + compatibility_level = 1, + version = "0.0.0", +) + +bazel_dep(name = "bazel_skylib", version = "1.1.1") +bazel_dep(name = "platforms", version = "0.0.5") + +node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node") + +# Note, this gets the default version of Node.js from +# https://github.com/bazelbuild/rules_nodejs/blob/5.8.0/nodejs/repositories.bzl#L11 +node.toolchain(name = "nodejs") + +use_repo(node, "nodejs_toolchains") +register_toolchains("@nodejs_toolchains//:all") diff --git a/examples/toolchain/BUILD.bazel b/e2e/smoke/BUILD.bazel similarity index 96% rename from examples/toolchain/BUILD.bazel rename to e2e/smoke/BUILD.bazel index cdae503ce3..4800250aec 100644 --- a/examples/toolchain/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -198,11 +198,13 @@ my_nodejs( ) # this tests to make sure that the first version imported in the workspace is used as default -diff_test( - name = "node_version_default_toolchain_test", - file1 = "write_node_version_16", - file2 = "thing_no_toolchain", -) +# FIXME: under bzlmod, the first toolchain registered is in the rules_nodejs/MODULE.bazel +# which is the "latest version" of node, not the one in our local MODULE.bazel file. +# diff_test( +# name = "node_version_default_toolchain_test", +# file1 = "write_node_version_16", +# file2 = "thing_no_toolchain", +# ) # Output contains the version number of node that is used. # This is used in tests later to verify the toolchain specified is resolved correctly diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel new file mode 100644 index 0000000000..12968458b3 --- /dev/null +++ b/e2e/smoke/MODULE.bazel @@ -0,0 +1,41 @@ +"bzlmod dependencies" +module( + name = "rules_nodejs_smoke_test", + compatibility_level = 1, + version = "0.0.0", +) + +bazel_dep(name = "rules_nodejs", dev_dependency = True, version = "0.0.0") +bazel_dep(name = "bazel_skylib", dev_dependency = True, version = "1.3.0") +bazel_dep(name = "aspect_bazel_lib", dev_dependency = True, version = "1.30.2") + +local_path_override( + module_name = "rules_nodejs", + path = "../..", +) + +node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node") + +# Note, this gets the default version of Node.js from +# https://github.com/bazelbuild/rules_nodejs/blob/5.8.0/nodejs/repositories.bzl#L11 +node.toolchain( + name = "node16", + node_version = "16.5.0", +) + +node.toolchain( + name = "node15", + node_version = "15.14.0", +) + +# FIXME(6.0): a repo rule with name=foo should create a repo named @foo, not @foo_toolchains +use_repo( + node, + "node16_toolchains", + "node15_linux_amd64", + "node15_darwin_amd64", + "node15_windows_amd64", + "node16_linux_amd64", + "node16_darwin_amd64", + "node16_windows_amd64", +) diff --git a/e2e/smoke/README.md b/e2e/smoke/README.md new file mode 100644 index 0000000000..aa11c363ce --- /dev/null +++ b/e2e/smoke/README.md @@ -0,0 +1,5 @@ +# smoke test + +This e2e exercises the repo from an end-users perpective. +It catches mistakes in our install instructions, or usages that fail when called from an "external" repository to rules_nodejs. +It is also used by the presubmit check for the Bazel Central Registry. diff --git a/examples/toolchain/WORKSPACE b/e2e/smoke/WORKSPACE.bazel similarity index 52% rename from examples/toolchain/WORKSPACE rename to e2e/smoke/WORKSPACE.bazel index c3b2b245f0..a754bd4235 100644 --- a/examples/toolchain/WORKSPACE +++ b/e2e/smoke/WORKSPACE.bazel @@ -8,14 +8,26 @@ http_archive( urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"], ) -# Note: skylib 1.1.1 has some bug on Windows with diff_test, which we use in this example http_archive( name = "bazel_skylib", - sha256 = "afbe4d9d033c007940acd24bb9becf1580a0280ae0b2ebbb5a7cb12912d2c115", - strip_prefix = "bazel-skylib-ffad33e9bfc60bdfa98292ca655a4e7035792046", - urls = ["https://github.com/bazelbuild/bazel-skylib/archive/ffad33e9bfc60bdfa98292ca655a4e7035792046.tar.gz"], + sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz", + ], ) +http_archive( + name = "aspect_bazel_lib", + sha256 = "97fa63d95cc9af006c4c7b2123ddd2a91fb8d273012f17648e6423bae2c69470", + strip_prefix = "bazel-lib-1.30.2", + url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.30.2/bazel-lib-v1.30.2.tar.gz", +) + +load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") + +aspect_bazel_lib_dependencies() + load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains") # The order matters because Bazel will provide the first registered toolchain when a rule asks Bazel to select it @@ -32,21 +44,7 @@ nodejs_register_toolchains( http_archive( name = "npm_acorn-8.5.0", - build_file_content = """ -load("@rules_nodejs//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") - -# Turn a source directory into a TreeArtifact for RBE-compat -copy_file( - name = "npm_acorn-8.5.0", - src = "package", - # This attribute comes from rules_nodejs patch of - # https://github.com/bazelbuild/bazel-skylib/pull/323 - is_directory = True, - # We must give this as the directory in order for it to appear on NODE_PATH - out = "acorn", - visibility = ["//visibility:public"], -) -""", + build_file = "acorn.BUILD", sha256 = "d8f9d40c4656537a60bf0c6daae6f0553f54df5ff2518f86464b7c785f20376b", urls = ["https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz"], ) diff --git a/e2e/smoke/WORKSPACE.bzlmod b/e2e/smoke/WORKSPACE.bzlmod new file mode 100644 index 0000000000..aede9808b5 --- /dev/null +++ b/e2e/smoke/WORKSPACE.bzlmod @@ -0,0 +1,10 @@ +# Replaces WORKSPACE.bazel under --enable_bzlmod + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "npm_acorn-8.5.0", + build_file = "acorn.BUILD", + sha256 = "d8f9d40c4656537a60bf0c6daae6f0553f54df5ff2518f86464b7c785f20376b", + urls = ["https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz"], +) diff --git a/examples/toolchain/defs.bzl b/e2e/smoke/defs.bzl similarity index 100% rename from examples/toolchain/defs.bzl rename to e2e/smoke/defs.bzl diff --git a/e2e/smoke/external/acorn.BUILD b/e2e/smoke/external/acorn.BUILD new file mode 100644 index 0000000000..caac6be637 --- /dev/null +++ b/e2e/smoke/external/acorn.BUILD @@ -0,0 +1,10 @@ +load("@aspect_bazel_lib//lib:copy_directory.bzl", "copy_directory") + +# Turn a source directory into a TreeArtifact for RBE-compat +copy_directory( + name = "npm_acorn-8.5.0", + src = "package", + # We must give this as the directory in order for it to appear on NODE_PATH + out = "acorn", + visibility = ["//visibility:public"], +)