Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade to rules_js 2.0
Browse files Browse the repository at this point in the history
gregmagolan committed Apr 22, 2024
1 parent a3d9a46 commit 9c3f647
Showing 11 changed files with 72 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download
USE_BAZEL_VERSION=aspect/5.7.2
USE_BAZEL_VERSION=aspect/5.9.25
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
7.0.2
7.1.1
# The first line of this file is used by Bazelisk and Bazel to be sure
# the right version of Bazel is used to build and test this repo.
# This also defines which version is used on CI.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@ bazel-*
.bazelrc.user
node_modules

# Don't share lockfile for now. It is unstable.
# Don't commit lockfile for now as it is unstable. Do allow for it to be
# created, however, since it gives a performance boost for local development.
# https://github.com/bazelbuild/bazel/issues/19026
# https://github.com/bazelbuild/bazel/issues/19621
# https://github.com/bazelbuild/bazel/issues/19971
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -9,18 +9,18 @@ default_stages: [commit]
repos:
# Check formatting and lint for starlark code
- repo: https://github.com/keith/pre-commit-buildifier
rev: 4.0.1.1
rev: 6.4.0
hooks:
- id: buildifier
- id: buildifier-lint
# Enforce that commit messages allow for later changelog generation
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.18.0
rev: v3.24.0
hooks:
# Requires that commitizen is already installed
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: 'v2.4.0'
rev: v3.1.0
hooks:
- id: prettier
13 changes: 10 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -4,13 +4,20 @@ load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

buildifier(
name = "buildifier",
exclude_patterns = ["./.git/*"],
lint_mode = "fix",
mode = "fix",
tags = ["manual"], # tag as manual so windows ci does not build it by default
)

buildifier(
name = "buildifier.check",
exclude_patterns = [
"./.git/*",
],
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "diff",
tags = ["manual"], # tag as manual so windows ci does not build it by default
)

bzl_library(
34 changes: 10 additions & 24 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -6,15 +6,11 @@ module(
compatibility_level = 1,
)

# Lower-bound (minimum) versions of direct dependencies
bazel_dep(name = "bazel_skylib", version = "1.3.0")

# Need feat: backport 2.x features for interoperability by @kormide in #657
bazel_dep(name = "aspect_bazel_lib", version = "1.38.0")

# Need feat: import toolchains to use for copy actions by @kormide in #1355
bazel_dep(name = "aspect_rules_js", version = "1.34.0")
bazel_dep(name = "rules_nodejs", version = "5.5.3")
# 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.2")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "rules_nodejs", version = "6.1.0")
bazel_dep(name = "platforms", version = "0.0.5")

rollup = use_extension("@aspect_rules_rollup//rollup:extensions.bzl", "rollup")
@@ -24,26 +20,16 @@ rollup.toolchain(
)
use_repo(rollup, "rollup")

bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True)
####### Dev dependencies ########

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
dev_dependency = True,
)
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")

# We want the stardoc handling from bazel-lib 2.x for dev use here,
# but not force users to upgrade yet.
archive_override(
module_name = "aspect_bazel_lib",
integrity = "sha256-9ep2aCsgnMC9kND1o7JtL3pqKIXwxfYV5ykT9IBduw0=",
strip_prefix = "bazel-lib-2.5.0",
urls = ["https://github.com/aspect-build/bazel-lib/releases/download/v2.5.0/bazel-lib-v2.5.0.tar.gz"],
)
12 changes: 5 additions & 7 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
"Bazel dependencies"

bazel_dep(name = "aspect_rules_rollup", version = "0.0.0", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.2.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.3.0", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "1.35.0", dev_dependency = True)

local_path_override(
module_name = "aspect_rules_rollup",
path = "../..",
)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.2", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
pnpm_lock = "@aspect_rules_rollup//:pnpm-lock.yaml",
10 changes: 4 additions & 6 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -23,14 +23,12 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies()

# Fetch and register a node toolchain, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

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",
12 changes: 5 additions & 7 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
@@ -11,15 +11,13 @@ def rules_rollup_internal_deps():
"Fetch deps needed for local development"
http_archive(
name = "io_bazel_stardoc",
sha256 = "3fd8fec4ddec3c670bd810904e2e33170bedfe12f90adf943508184be458c8bb",
urls = ["https://github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz"],
sha256 = "62bd2e60216b7a6fec3ac79341aa201e0956477e7c8f6ccc286f279ad1d96432",
urls = ["https://github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz"],
)

http_archive(
name = "buildifier_prebuilt",
sha256 = "72b5bb0853aac597cce6482ee6c62513318e7f2c0050bc7c319d75d03d8a3875",
strip_prefix = "buildifier-prebuilt-6.3.3",
urls = [
"http://github.com/keith/buildifier-prebuilt/archive/6.3.3.tar.gz",
],
sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e",
strip_prefix = "buildifier-prebuilt-6.4.0",
urls = ["http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz"],
)
21 changes: 11 additions & 10 deletions rollup/dependencies.bzl
Original file line number Diff line number Diff line change
@@ -5,26 +5,27 @@ load("//rollup/private:maybe.bzl", http_archive = "maybe_http_archive")
def rules_rollup_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 = "b848cd8e93be7f18c3deda6d2f3ade92a657d3585e119953bc50dc75fef535c2",
strip_prefix = "bazel-lib-1.38.0",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.38.0/bazel-lib-v1.38.0.tar.gz",
sha256 = "b554eb7942a5ab44c90077df6a0c76fc67c5874c9446a007e9ba68be82bd4796",
strip_prefix = "bazel-lib-2.7.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.1/bazel-lib-v2.7.1.tar.gz",
)

http_archive(
name = "aspect_rules_js",
sha256 = "7b2a4d1d264e105eae49a27e2e78065b23e2e45724df2251eacdd317e95bfdfd",
strip_prefix = "rules_js-1.31.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.31.0/rules_js-v1.31.0.tar.gz",
sha256 = "b627acf34f928507dfabae69d3fd8702ce3d45bed568ad4c44b243cb789f08c6",
strip_prefix = "rules_js-2.0.0-alpha.2",
url = "https://github.com/aspect-build/rules_js/releases/download/v2.0.0-alpha.2/rules_js-v2.0.0-alpha.2.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",
)
44 changes: 20 additions & 24 deletions rollup/private/rollup.bzl
Original file line number Diff line number Diff line change
@@ -137,9 +137,8 @@ def _impl(ctx):
# Add user specified arguments *before* rule supplied arguments
args.add_all(ctx.attr.args)

# List entry point argument first to save some argv space
# Rollup doc says
# When provided as the first options, it is equivalent to not prefix them with --input
# List entry point argument first to save some argv space. Rollup doc says when provided as the
# first options, it is equivalent to not prefix them with --input.
entry_points = _desugar_entry_points(ctx.label.name, ctx.attr.entry_point, ctx.attr.entry_points, inputs).items()

output_sources = [getattr(ctx.outputs, o) for o in dir(ctx.outputs)]
@@ -173,11 +172,13 @@ def _impl(ctx):
arguments = [args],
inputs = depset(
inputs,
transitive = [js_lib_helpers.gather_files_from_js_providers(
transitive = [js_lib_helpers.gather_files_from_js_infos(
targets = ctx.attr.srcs + ctx.attr.deps,
include_sources = True,
include_types = False,
include_transitive_sources = True,
include_declarations = False,
include_npm_linked_packages = True,
include_transitive_types = False,
include_npm_sources = True,
)],
),
outputs = output_sources,
@@ -188,14 +189,14 @@ def _impl(ctx):
},
)

npm_linked_packages = js_lib_helpers.gather_npm_linked_packages(
# If a subset of linked npm dependencies are not bundled, it is up to the user to re-specify
# these in `data` if they are runtime dependencies to progagate to binary rules or `srcs` if
# they are to be propagated to downstream build targets.
npm_sources = js_lib_helpers.gather_npm_sources(
srcs = ctx.attr.srcs,
deps = [],
)

npm_package_store_deps = js_lib_helpers.gather_npm_package_store_deps(
# Since we're bundling, only propagate `data` npm packages to the direct dependencies of
# downstream linked `npm_package` targets instead of the common `data` and `deps` pattern.
npm_package_store_infos = js_lib_helpers.gather_npm_package_store_infos(
targets = ctx.attr.data,
)

@@ -205,8 +206,7 @@ def _impl(ctx):
ctx = ctx,
sources = output_sources_depset,
data = ctx.attr.data,
# Since we're bundling, we don't propogate any transitive runfiles from dependencies
deps = [],
deps = [], # since we're bundling, don't propogate any transitive runfiles from dependencies
)

return [
@@ -215,19 +215,15 @@ def _impl(ctx):
runfiles = runfiles,
),
js_info(
npm_linked_package_files = npm_linked_packages.direct_files,
npm_linked_packages = npm_linked_packages.direct,
npm_package_store_deps = npm_package_store_deps,
target = ctx.label,
sources = output_sources_depset,
# Since we're bundling, we don't propogate linked npm packages from dependencies since
# they are bundled and the dependencies are dropped. If a subset of linked npm
# dependencies are not bundled it is up the the user to re-specify these in `data` if
# they are runtime dependencies to progagate to binary rules or `srcs` if they are to be
# propagated to downstream build targets.
transitive_npm_linked_package_files = npm_linked_packages.direct_files,
transitive_npm_linked_packages = npm_linked_packages.direct,
# Since we're bundling, we don't propogate any transitive sources from dependencies
types = depset(), # rollup does not emit types directly
# Since we're bundling, don't propogate any transitive sources or declarations since sources
# are typically bundled into the output.
transitive_sources = output_sources_depset,
transitive_types = depset(),
npm_sources = npm_sources,
npm_package_store_infos = npm_package_store_infos,
),
]

0 comments on commit 9c3f647

Please sign in to comment.