Skip to content

Commit

Permalink
feat: upgrade to rules_js 2.0 (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored May 22, 2024
1 parent a0aade3 commit 7c994eb
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 257 deletions.
7 changes: 0 additions & 7 deletions .aspect/bazelrc/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# We recommend enforcing a policy that keeps your CI from being slowed down
# by individual test targets that should be optimized
# or split up into multiple test targets with sharding or manually.
# Set this flag to exclude targets that have their timeout set to eternal (>15m) from running on CI.
# Docs: https://bazel.build/docs/user-manual#test-timeout-filters
test --test_timeout_filters=-eternal

# Set this flag to enable re-tries of failed tests on CI.
# When any test target fails, try one or more times. This applies regardless of whether the "flaky"
# tag appears on the target definition.
Expand Down
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
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module(
)

# Lower-bounds (minimum) versions for direct runtime dependencies
bazel_dep(name = "aspect_bazel_lib", version = "1.40.0")
bazel_dep(name = "aspect_rules_js", version = "1.35.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
bazel_dep(name = "aspect_rules_js", version = "2.0.0-rc0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_nodejs", version = "5.8.3")
bazel_dep(name = "rules_nodejs", version = "6.1.0")

esbuild = use_extension("@aspect_rules_esbuild//esbuild:extensions.bzl", "esbuild")
esbuild.toolchain(
Expand Down
16 changes: 3 additions & 13 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@ load("//esbuild:dependencies.bzl", "rules_esbuild_dependencies")
# Fetch dependencies which users need as well
rules_esbuild_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("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains", "register_yq_toolchains")

aspect_bazel_lib_dependencies()

register_coreutils_toolchains()

register_yq_toolchains(
version = DEFAULT_YQ_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")

Expand All @@ -44,7 +34,7 @@ esbuild_register_toolchains(
)

# Install additional packages to test esbuild plugins
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 = "esbuild_plugins",
Expand Down
2 changes: 1 addition & 1 deletion docs/esbuild.md

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

2 changes: 1 addition & 1 deletion e2e/bundle/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_bazel_lib", version = "2.2.0", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3", dev_dependency = True)
16 changes: 2 additions & 14 deletions e2e/bundle/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,9 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_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()

# If you didn't already register a toolchain providing nodejs, do that:
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

# Register a toolchain containing esbuild npm package and native bindings
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_ESBUILD_VERSION", "esbuild_register_toolchains")
Expand Down
2 changes: 1 addition & 1 deletion e2e/npm-links/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_rules_js", version = "1.34.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "2.0.0-rc0", 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)
Expand Down
17 changes: 3 additions & 14 deletions e2e/npm-links/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,11 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_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()
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 = "node",
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
13 changes: 8 additions & 5 deletions e2e/npm-links/pnpm-lock.yaml

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

16 changes: 2 additions & 14 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,9 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_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()

# If you didn't already register a toolchain providing nodejs, do that:
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

# Register a toolchain containing esbuild npm package and native bindings
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_ESBUILD_VERSION", "esbuild_register_toolchains")
Expand Down
18 changes: 2 additions & 16 deletions e2e/sourcemaps/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,9 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_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()

# For convenience, npm_translate_lock does this call automatically.
# You can omit this if you have any npm_translate_lock calls.
load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

# If you didn't already register a toolchain providing nodejs, do that:
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

# Register a toolchain containing esbuild npm package and native bindings
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_ESBUILD_VERSION", "esbuild_register_toolchains")
Expand Down
2 changes: 1 addition & 1 deletion e2e/tsconfig/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_bazel_lib", version = "2.2.0", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3", dev_dependency = True)
15 changes: 2 additions & 13 deletions e2e/tsconfig/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,9 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_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("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_ESBUILD_VERSION", "esbuild_register_toolchains")

Expand Down
17 changes: 9 additions & 8 deletions esbuild/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ def rules_esbuild_dependencies():

http_archive(
name = "aspect_bazel_lib",
sha256 = "f6ef68871d206cf8f5f4eea83d26a366563a631b020afe1da2f838a9bff035c0",
strip_prefix = "bazel-lib-1.40.0",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.40.0/bazel-lib-v1.40.0.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 = "76a04ef2120ee00231d85d1ff012ede23963733339ad8db81f590791a031f643",
strip_prefix = "rules_js-1.34.1",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.1/rules_js-v1.34.1.tar.gz",
sha256 = "389021e29b3aeed2f6fb3a7a1478f8fc52947a6500b198a7ec0f3358c2842415",
strip_prefix = "rules_js-2.0.0-rc0",
url = "https://github.com/aspect-build/rules_js/releases/download/v2.0.0-rc0/rules_js-v2.0.0-rc0.tar.gz",
)

http_archive(
name = "rules_nodejs",
sha256 = "8fc8e300cb67b89ceebd5b8ba6896ff273c84f6099fc88d23f24e7102319d8fd",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.4/rules_nodejs-core-5.8.4.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",
)
63 changes: 33 additions & 30 deletions esbuild/private/esbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ See https://esbuild.github.io/api/#define for more details
doc = "A list of direct dependencies that are required to build the bundle",
providers = [JsInfo],
),
"data": js_lib_helpers.JS_LIBRARY_DATA_ATTR,
"data": attr.label_list(
doc = """Runtime dependencies to include in binaries/tests that depend on this target.
Follows the same semantics as `js_library` `data` attribute. See
https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#data for more info.
""",
allow_files = True,
),
"entry_point": attr.label(
allow_single_file = True,
doc = """The bundle's entry point (e.g. your main.js or app.js or index.js)
Expand Down Expand Up @@ -365,11 +372,13 @@ def _esbuild_impl(ctx):
for file in ctx.files.srcs
if not (file.path.endswith(".d.ts") or file.path.endswith(".tsbuildinfo"))
]) + entry_points_bin_copy + [tsconfig_bin_copy] + other_inputs + node_toolinfo.tool_files + esbuild_toolinfo.tool_files,
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,
)],
)

Expand All @@ -388,48 +397,43 @@ def _esbuild_impl(ctx):
output_sources_depset = depset(output_sources)

if ctx.attr.bundle:
# If we're bundling we don't propogate any transitive sources or declarations since sources
# are typically bundled into the output. 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.
# When bundling don't propogate any transitive sources or declarations since sources
# are typically bundled into the output.
transitive_sources = output_sources_depset
transitive_declarations = depset()
npm_linked_packages = js_lib_helpers.gather_npm_linked_packages(
transitive_types = depset()

# 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_linked_packages = struct(
direct_files = npm_linked_packages.direct_files,
direct = npm_linked_packages.direct,
transitive_files = npm_linked_packages.direct_files,
transitive = npm_linked_packages.direct,
)
npm_package_store_deps = js_lib_helpers.gather_npm_package_store_deps(
npm_package_store_infos = js_lib_helpers.gather_npm_package_store_infos(
targets = ctx.attr.data,
)
runfiles = js_lib_helpers.gather_runfiles(
ctx = ctx,
sources = output_sources_depset,
data = ctx.attr.data,
deps = [],
deps = [], # when bundling, don't propogate any transitive runfiles from dependencies
)
else:
# If we're not bundling then include all transitive files
transitive_sources = js_lib_helpers.gather_transitive_sources(
sources = output_sources_depset,
targets = ctx.attr.srcs + ctx.attr.deps,
)
transitive_declarations = js_lib_helpers.gather_transitive_declarations(
declarations = [],
transitive_types = js_lib_helpers.gather_transitive_types(
types = [],
targets = ctx.attr.srcs + ctx.attr.deps,
)
npm_linked_packages = js_lib_helpers.gather_npm_linked_packages(
npm_sources = js_lib_helpers.gather_npm_sources(
srcs = ctx.attr.srcs,
deps = ctx.attr.deps,
)
npm_package_store_deps = js_lib_helpers.gather_npm_package_store_deps(
targets = ctx.attr.data + ctx.attr.deps,
npm_package_store_infos = js_lib_helpers.gather_npm_package_store_infos(
targets = ctx.attr.srcs + ctx.attr.data + ctx.attr.deps,
)
runfiles = js_lib_helpers.gather_runfiles(
ctx = ctx,
Expand All @@ -444,14 +448,13 @@ def _esbuild_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,
transitive_npm_linked_package_files = npm_linked_packages.transitive_files,
transitive_npm_linked_packages = npm_linked_packages.transitive,
types = depset(), # esbuild does not emit types directly
transitive_sources = transitive_sources,
transitive_declarations = transitive_declarations,
transitive_types = transitive_types,
npm_sources = npm_sources,
npm_package_store_infos = npm_package_store_infos,
),
]

Expand Down
Loading

0 comments on commit 7c994eb

Please sign in to comment.