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 Apr 29, 2024
1 parent 9b6a225 commit ce34c11
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 86 deletions.
11 changes: 5 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "aspect_bazel_lib", version = "1.32.1")
bazel_dep(name = "aspect_rules_js", version = "1.31.0")
bazel_dep(name = "bazel_features", version = "1.9.0")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "rules_nodejs", version = "5.8.2")
# Lower-bounds (minimum) versions for direct runtime dependencies
bazel_dep(name = "aspect_bazel_lib", version = "2.7.1")
bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.3")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "rules_nodejs", version = "6.1.0")

####### Dev dependencies ########

bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.36.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "rules_go", version = "0.46.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
13 changes: 3 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ load("//jest:dependencies.bzl", "rules_jest_dependencies")
# Fetch dependencies which users need as well
rules_jest_dependencies()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

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)

# For running our own unit tests
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
Expand Down Expand Up @@ -48,7 +41,7 @@ local_repository(
############################################
# Example npm dependencies

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
27 changes: 13 additions & 14 deletions docs/jest_test.md

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

9 changes: 3 additions & 6 deletions e2e/case4/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ load("@aspect_rules_jest//jest:dependencies.bzl", "rules_jest_dependencies")

rules_jest_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_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:npm_import.bzl", "npm_translate_lock")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
Expand Down
4 changes: 2 additions & 2 deletions e2e/npm_packages/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_bazel_lib", version = "1.32.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "1.31.0", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.7.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.3", dev_dependency = True)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
Expand Down
14 changes: 3 additions & 11 deletions e2e/npm_packages/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ load("@aspect_rules_jest//jest:dependencies.bzl", "rules_jest_dependencies")

rules_jest_dependencies()

# Register a nodejs toolchain, if you haven't already done so.
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

nodejs_register_toolchains(
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()
rules_js_register_toolchains(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
14 changes: 7 additions & 7 deletions e2e/npm_packages/packages/lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ npm_link_all_packages(name = "node_modules")

# Basic js with 1 npm dep
js_library(
name = "lib_jslib",
name = "lib",
srcs = ["index.js"],
deps = [
":node_modules/@aspect-test/a",
Expand All @@ -16,20 +16,20 @@ js_library(

# Basic npm package wrapping the js
npm_package(
name = "lib",
name = "pkg",
srcs = [
"package.json",
":lib_jslib",
":lib",
],
visibility = ["//visibility:public"],
)

# Library of tests
js_library(
name = "lib_tests",
name = "test_lib",
srcs = glob(["*.spec.js"]),
deps = [
":lib_jslib",
":lib",
":node_modules/uvu",
],
)
Expand All @@ -40,7 +40,7 @@ jest_test(
config = "//:jest.config.cjs",
data = [
"babel.config.json",
":lib_tests",
":test_lib",
],
node_modules = "//:node_modules",
)
Expand All @@ -50,7 +50,7 @@ jest_test(
config = "//:jest.config.esm",
data = [
"package.json", # required for jest to determine this package .js is esm
":lib_tests",
":test_lib",
],
node_modules = "//:node_modules",
node_options = [
Expand Down
5 changes: 3 additions & 2 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_rules_js", version = "1.31.0", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.4", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.7.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.3", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.9", dev_dependency = True)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
Expand Down
9 changes: 3 additions & 6 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ load("@aspect_rules_jest//jest:dependencies.bzl", "rules_jest_dependencies")

rules_jest_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_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:npm_import.bzl", "npm_translate_lock")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
Expand Down
6 changes: 3 additions & 3 deletions e2e/swc/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_bazel_lib", version = "1.32.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "1.31.0", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.7.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.3", dev_dependency = True)
bazel_dep(name = "aspect_rules_swc", version = "1.2.2", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.4", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.9", dev_dependency = True)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
Expand Down
6 changes: 1 addition & 5 deletions jest/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ def _jest_from_node_modules(jest_rule, name, node_modules, auto_configure_report
jest_rule(
name = name,
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,
"@aspect_bazel_lib//lib:enable_runfiles": True,
"//conditions:default": False,
}),
data = data,
Expand Down
Loading

0 comments on commit ce34c11

Please sign in to comment.