Skip to content

Commit

Permalink
feat: upgrade to rules_js 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed May 17, 2024
1 parent f037327 commit aba0ee2
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 59 deletions.
1 change: 1 addition & 0 deletions .aspect/bazelrc/javascript.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 ########

Expand Down
19 changes: 2 additions & 17 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 1 addition & 5 deletions cypress/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 11 additions & 10 deletions cypress/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
8 changes: 5 additions & 3 deletions cypress/private/cypress_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions e2e/workspace/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 3 additions & 14 deletions e2e/workspace/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions e2e/workspace/server_example/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit aba0ee2

Please sign in to comment.