From cc2d7e9182a67bcfbe7b0934ea2affa97974a619 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 21 May 2024 17:55:19 -0700 Subject: [PATCH] feat: upgrade to rules_js 2.0 (#68) --- .aspect/bazelrc/javascript.bazelrc | 1 + MODULE.bazel | 9 ++++---- WORKSPACE.bazel | 19 ++--------------- cypress/defs.bzl | 6 +----- cypress/dependencies.bzl | 21 ++++++++++--------- cypress/private/cypress_test.bzl | 8 ++++--- e2e/workspace/MODULE.bazel | 4 ++-- e2e/workspace/WORKSPACE.bazel | 17 +++------------ .../server_example/cypress.config.js | 16 ++++++++++---- 9 files changed, 42 insertions(+), 59 deletions(-) diff --git a/.aspect/bazelrc/javascript.bazelrc b/.aspect/bazelrc/javascript.bazelrc index 474ec63..ace9d60 100644 --- a/.aspect/bazelrc/javascript.bazelrc +++ b/.aspect/bazelrc/javascript.bazelrc @@ -8,3 +8,4 @@ # details. # Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options run:debug -- --node_options=--inspect-brk +test:debug --test_env=NODE_OPTIONS=--inspect-brk diff --git a/MODULE.bazel b/MODULE.bazel index 75a2c02..5537449 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,11 +6,12 @@ module( compatibility_level = 1, ) -bazel_dep(name = "aspect_bazel_lib", version = "1.42.3") -bazel_dep(name = "aspect_rules_js", version = "1.41.2") -bazel_dep(name = "bazel_skylib", version = "1.4.1") +# Lower-bounds (minimum) versions for direct runtime dependencies +bazel_dep(name = "aspect_bazel_lib", version = "2.7.3") +bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.6") +bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "platforms", version = "0.0.5") -bazel_dep(name = "rules_nodejs", version = "5.8.2") +bazel_dep(name = "rules_nodejs", version = "6.1.0") ####### Dev dependencies ######## diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 5e9913f..bc73ea7 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -11,24 +11,9 @@ load("@aspect_rules_cypress//cypress:dependencies.bzl", "rules_cypress_dependenc # Fetch dependencies which users need as well rules_cypress_dependencies() -load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains") -rules_js_dependencies() - -load("@bazel_features//:deps.bzl", "bazel_features_deps") - -bazel_features_deps() - -load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") - -aspect_bazel_lib_dependencies(override_local_config_platform = True) - -load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") - -nodejs_register_toolchains( - name = "nodejs", - node_version = DEFAULT_NODE_VERSION, -) +rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION) load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") diff --git a/cypress/defs.bzl b/cypress/defs.bzl index 76030b2..0d0f9e1 100644 --- a/cypress/defs.bzl +++ b/cypress/defs.bzl @@ -23,11 +23,7 @@ def _cypress_test_macro(name, entry_point, cypress, disable_sandbox, **kwargs): cypress, ], enable_runfiles = select({ - "@aspect_rules_js//js/private:enable_runfiles": True, - "//conditions:default": False, - }), - unresolved_symlinks_enabled = select({ - "@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True, + Label("@aspect_bazel_lib//lib:enable_runfiles"): True, "//conditions:default": False, }), tags = tags, diff --git a/cypress/dependencies.bzl b/cypress/dependencies.bzl index a7028ad..9473727 100644 --- a/cypress/dependencies.bzl +++ b/cypress/dependencies.bzl @@ -12,26 +12,27 @@ def http_archive(name, **kwargs): def rules_cypress_dependencies(): http_archive( name = "bazel_skylib", - sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7", - urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz"], + sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", + urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"], ) http_archive( name = "aspect_bazel_lib", - sha256 = "d0529773764ac61184eb3ad3c687fb835df5bee01afedf07f0cf1a45515c96bc", - strip_prefix = "bazel-lib-1.42.3", - url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.42.3/bazel-lib-v1.42.3.tar.gz", + sha256 = "87ab4ec479ebeb00d286266aca2068caeef1bb0b1765e8f71c7b6cfee6af4226", + strip_prefix = "bazel-lib-2.7.3", + url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.3/bazel-lib-v2.7.3.tar.gz", ) http_archive( name = "aspect_rules_js", - sha256 = "bc9b4a01ef8eb050d8a7a050eedde8ffb1e45a56b0e4094e26f06c17d5fcf1d5", - strip_prefix = "rules_js-1.41.2", - url = "https://github.com/aspect-build/rules_js/releases/download/v1.41.2/rules_js-v1.41.2.tar.gz", + sha256 = "03d9e0c1da0ee9dd8ff52ba0f6ee5d173848c00ef4c85ec558aad0a9cf56ac46", + strip_prefix = "rules_js-2.0.0-alpha.6", + url = "https://github.com/aspect-build/rules_js/releases/download/v2.0.0-alpha.6/rules_js-v2.0.0-alpha.6.tar.gz", ) http_archive( name = "rules_nodejs", - sha256 = "764a3b3757bb8c3c6a02ba3344731a3d71e558220adcb0cf7e43c9bba2c37ba8", - urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"], + sha256 = "dddd60acc3f2f30359bef502c9d788f67e33814b0ddd99aa27c5a15eb7a41b8c", + strip_prefix = "rules_nodejs-6.1.0", + url = "https://github.com/bazelbuild/rules_nodejs/releases/download/v6.1.0/rules_nodejs-v6.1.0.tar.gz", ) diff --git a/cypress/private/cypress_test.bzl b/cypress/private/cypress_test.bzl index 1ad972c..e92225f 100644 --- a/cypress/private/cypress_test.bzl +++ b/cypress/private/cypress_test.bzl @@ -39,11 +39,13 @@ def _impl(ctx): runfiles = ctx.runfiles( files = files, - transitive_files = js_lib_helpers.gather_files_from_js_providers( + transitive_files = js_lib_helpers.gather_files_from_js_infos( targets = ctx.attr.data, + include_sources = ctx.attr.include_sources, + include_types = ctx.attr.include_types, include_transitive_sources = ctx.attr.include_transitive_sources, - include_declarations = ctx.attr.include_declarations, - include_npm_linked_packages = ctx.attr.include_npm_linked_packages, + include_transitive_types = ctx.attr.include_transitive_types, + include_npm_sources = ctx.attr.include_npm_sources, ), ).merge(launcher.runfiles).merge_all([ target[DefaultInfo].default_runfiles diff --git a/e2e/workspace/MODULE.bazel b/e2e/workspace/MODULE.bazel index a00f2bb..7da3a10 100644 --- a/e2e/workspace/MODULE.bazel +++ b/e2e/workspace/MODULE.bazel @@ -10,8 +10,8 @@ use_repo(cypress, "cypress_toolchains") register_toolchains("@cypress_toolchains//:all") -bazel_dep(name = "aspect_rules_js", version = "1.41.2", dev_dependency = True) -bazel_dep(name = "bazel_features", version = "1.9.0", dev_dependency = True) +bazel_dep(name = "aspect_bazel_lib", version = "2.7.3", dev_dependency = True) +bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.6", dev_dependency = True) npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True) npm.npm_translate_lock( diff --git a/e2e/workspace/WORKSPACE.bazel b/e2e/workspace/WORKSPACE.bazel index 2ab66fd..fdd0697 100644 --- a/e2e/workspace/WORKSPACE.bazel +++ b/e2e/workspace/WORKSPACE.bazel @@ -25,22 +25,11 @@ cypress_register_toolchains( cypress_version = "13.6.6", ) -load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains") -rules_js_dependencies() +rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION) -load("@bazel_features//:deps.bzl", "bazel_features_deps") - -bazel_features_deps() - -load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") - -nodejs_register_toolchains( - name = "nodejs", - node_version = DEFAULT_NODE_VERSION, -) - -load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock") +load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") npm_translate_lock( name = "npm", diff --git a/e2e/workspace/server_example/cypress.config.js b/e2e/workspace/server_example/cypress.config.js index bc24424..1d1d7fc 100644 --- a/e2e/workspace/server_example/cypress.config.js +++ b/e2e/workspace/server_example/cypress.config.js @@ -20,10 +20,18 @@ module.exports = defineConfig({ const port = "3000"; return new Promise((resolve, reject) => { // Launch the server - const serverProcess = spawn(join(process.cwd(), "server.sh"), [port], { - // js_binary expects to be run at execroot, but cypress rule has changed pwd to where our test target was defined. - cwd: `${process.env.TEST_SRCDIR}/${process.env.TEST_WORKSPACE}`, - }); + const workspaceRoot = join( + process.env.RUNFILES_DIR, + process.env.TEST_WORKSPACE, + ); + const serverProcess = spawn( + join(workspaceRoot, "server_example/server_/server"), + [port], + { + // js_binary expects to be run at execroot, but cypress rule has changed pwd to where our test target was defined. + cwd: workspaceRoot, + }, + ); serverProcess.stdout.on("data", (data) => { data = data.toString();