From be120ffe6d0d036fb3ae1f05aa8b9b75c0788b44 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Sat, 20 Apr 2024 15:26:26 -0700 Subject: [PATCH] feat: upgrade to rules_js 2.0 --- .aspect/bazelrc/ci.bazelrc | 7 ----- .bazeliskrc | 2 +- .bazelversion | 2 +- .gitignore | 9 ++++++ .pre-commit-config.yaml | 2 +- BUILD.bazel | 3 +- MODULE.bazel | 13 +++++--- WORKSPACE | 22 +++---------- docs/esbuild.md | 2 +- e2e/bundle/MODULE.bazel | 6 ++-- e2e/bundle/WORKSPACE | 16 ++-------- e2e/npm-links/MODULE.bazel | 14 +++------ e2e/npm-links/WORKSPACE | 17 ++-------- e2e/smoke/MODULE.bazel | 6 ++-- e2e/smoke/WORKSPACE.bazel | 16 ++-------- e2e/sourcemaps/MODULE.bazel | 6 ++-- e2e/sourcemaps/WORKSPACE | 18 ++--------- e2e/tsconfig/MODULE.bazel | 6 ++-- e2e/tsconfig/WORKSPACE | 15 ++------- esbuild/dependencies.bzl | 17 +++++----- esbuild/private/esbuild.bzl | 63 +++++++++++++++++++------------------ esbuild/repositories.bzl | 6 ++-- internal_deps.bzl | 8 ----- 23 files changed, 94 insertions(+), 182 deletions(-) diff --git a/.aspect/bazelrc/ci.bazelrc b/.aspect/bazelrc/ci.bazelrc index 4d91ee0..11aae33 100644 --- a/.aspect/bazelrc/ci.bazelrc +++ b/.aspect/bazelrc/ci.bazelrc @@ -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. diff --git a/.bazeliskrc b/.bazeliskrc index 2f6e07f..269fbb0 100644 --- a/.bazeliskrc +++ b/.bazeliskrc @@ -1,2 +1,2 @@ BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download -USE_BAZEL_VERSION=aspect/5.8.19 +USE_BAZEL_VERSION=aspect/5.9.25 diff --git a/.bazelversion b/.bazelversion index 69f2020..2b1ea10 100644 --- a/.bazelversion +++ b/.bazelversion @@ -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. diff --git a/.gitignore b/.gitignore index 2c96879..421da56 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,12 @@ bazel-* .bazelrc.user node_modules .DS_Store + +# 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 +# https://github.com/bazelbuild/bazel/issues/20272 +# https://github.com/bazelbuild/bazel/issues/20369 +MODULE.bazel.lock diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4358e3..cb16842 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: - id: buildifier-lint # Enforce that commit messages allow for later changelog generation - repo: https://github.com/commitizen-tools/commitizen - rev: v3.13.0 + rev: v3.24.0 hooks: # Requires that commitizen is already installed - id: commitizen diff --git a/BUILD.bazel b/BUILD.bazel index 7d0ad61..301748f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1,5 @@ load("@buildifier_prebuilt//:rules.bzl", "buildifier") -#gazelle:exclude internal_deps.bzl buildifier( name = "buildifier", exclude_patterns = ["./.git/*"], @@ -16,3 +15,5 @@ buildifier( mode = "diff", tags = ["manual"], # tag as manual so windows ci does not build it by default ) + +# gazelle:exclude internal_deps.bzl diff --git a/MODULE.bazel b/MODULE.bazel index a2a3e9f..4d329f2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,11 +6,12 @@ module( compatibility_level = 1, ) -bazel_dep(name = "aspect_bazel_lib", version = "1.40.0") -bazel_dep(name = "aspect_rules_js", version = "1.35.0") +# 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 = "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( @@ -19,7 +20,9 @@ esbuild.toolchain( ) use_repo(esbuild, "esbuild_toolchains") +register_toolchains("@esbuild_toolchains//:all") + +####### Dev dependencies ######## + 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") - -register_toolchains("@esbuild_toolchains//:all") diff --git a/WORKSPACE b/WORKSPACE index 77a538c..d1ee64f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,8 +1,4 @@ -# Declare the local Bazel workspace. -workspace( - # see https://docs.bazel.build/versions/main/skylark/deploying.html#workspace - name = "aspect_rules_esbuild", -) +workspace(name = "aspect_rules_esbuild") load(":internal_deps.bzl", "rules_esbuild_internal_deps") @@ -14,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") - -rules_js_dependencies() - -load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains", "register_yq_toolchains") +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_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") @@ -48,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", diff --git a/docs/esbuild.md b/docs/esbuild.md index 50c5508..aed67bb 100644 --- a/docs/esbuild.md +++ b/docs/esbuild.md @@ -27,7 +27,7 @@ Note: to prevent esbuild from following symlinks and leaving the bazel sandbox, | name | A unique name for this target. | Name | required | | | deps | A list of direct dependencies that are required to build the bundle | List of labels | optional | `[]` | | srcs | Source files to be made available to esbuild | List of labels | optional | `[]` | -| data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the `data` attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide `JsInfo`, `NpmPackageStoreInfo` providers are gathered from `JsInfo`. This is done directly from the `npm_package_store_deps` field of these. For linked npm package targets, the underlying `npm_package_store` target(s) that back the links is used. Gathered `NpmPackageStoreInfo` providers are propagated to the direct dependencies of downstream linked `npm_package` targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying `npm_package_store` target(s) through `npm_package_store_deps` and will therefore not be propagated to the direct dependencies of downstream linked `npm_package` targets. npm packages that come in from `npm_translate_lock` are considered "dev" dependencies if they are have `dev: true` set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all `package.json` files within the pnpm workspace. This behavior is intentional to mimic how `devDependencies` work in published npm packages. | List of labels | optional | `[]` | +| data | 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. | List of labels | optional | `[]` | | args_file | Internal use only | Label | optional | `None` | | bazel_sandbox_plugin | If true, a custom bazel-sandbox plugin will be enabled that prevents esbuild from leaving the Bazel sandbox. See https://github.com/aspect-build/rules_esbuild/pull/160 for more info. | Boolean | optional | `True` | | bundle | If true, esbuild will bundle the input files, inlining their dependencies recursively | Boolean | optional | `True` | diff --git a/e2e/bundle/MODULE.bazel b/e2e/bundle/MODULE.bazel index 8ac6add..57088ed 100644 --- a/e2e/bundle/MODULE.bazel +++ b/e2e/bundle/MODULE.bazel @@ -1,9 +1,7 @@ -"Bazel dependencies" - bazel_dep(name = "aspect_rules_esbuild", version = "0.0.0", dev_dependency = True) -bazel_dep(name = "aspect_bazel_lib", version = "2.2.0", dev_dependency = True) - local_path_override( module_name = "aspect_rules_esbuild", path = "../..", ) + +bazel_dep(name = "aspect_bazel_lib", version = "2.7.1", dev_dependency = True) diff --git a/e2e/bundle/WORKSPACE b/e2e/bundle/WORKSPACE index cb2984b..ee2a858 100644 --- a/e2e/bundle/WORKSPACE +++ b/e2e/bundle/WORKSPACE @@ -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") diff --git a/e2e/npm-links/MODULE.bazel b/e2e/npm-links/MODULE.bazel index cc68347..4099327 100644 --- a/e2e/npm-links/MODULE.bazel +++ b/e2e/npm-links/MODULE.bazel @@ -1,19 +1,13 @@ -"Bazel dependencies" - bazel_dep(name = "aspect_rules_esbuild", version = "0.0.0", dev_dependency = True) -bazel_dep(name = "aspect_rules_js", version = "1.34.1", dev_dependency = True) -bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) - local_path_override( module_name = "aspect_rules_esbuild", path = "../..", ) -npm = use_extension( - "@aspect_rules_js//npm:extensions.bzl", - "npm", - 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 = "//:pnpm-lock.yaml", diff --git a/e2e/npm-links/WORKSPACE b/e2e/npm-links/WORKSPACE index 1da8816..3c6b8b2 100644 --- a/e2e/npm-links/WORKSPACE +++ b/e2e/npm-links/WORKSPACE @@ -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", diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel index 065d5dd..81fd66f 100644 --- a/e2e/smoke/MODULE.bazel +++ b/e2e/smoke/MODULE.bazel @@ -1,9 +1,7 @@ -"Bazel dependencies" - bazel_dep(name = "aspect_rules_esbuild", version = "0.0.0", dev_dependency = True) -bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) - local_path_override( module_name = "aspect_rules_esbuild", path = "../..", ) + +bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) diff --git a/e2e/smoke/WORKSPACE.bazel b/e2e/smoke/WORKSPACE.bazel index 66d4967..91f71db 100644 --- a/e2e/smoke/WORKSPACE.bazel +++ b/e2e/smoke/WORKSPACE.bazel @@ -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") diff --git a/e2e/sourcemaps/MODULE.bazel b/e2e/sourcemaps/MODULE.bazel index 065d5dd..81fd66f 100644 --- a/e2e/sourcemaps/MODULE.bazel +++ b/e2e/sourcemaps/MODULE.bazel @@ -1,9 +1,7 @@ -"Bazel dependencies" - bazel_dep(name = "aspect_rules_esbuild", version = "0.0.0", dev_dependency = True) -bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) - local_path_override( module_name = "aspect_rules_esbuild", path = "../..", ) + +bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) diff --git a/e2e/sourcemaps/WORKSPACE b/e2e/sourcemaps/WORKSPACE index c4074bf..91f71db 100644 --- a/e2e/sourcemaps/WORKSPACE +++ b/e2e/sourcemaps/WORKSPACE @@ -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") diff --git a/e2e/tsconfig/MODULE.bazel b/e2e/tsconfig/MODULE.bazel index 8ac6add..57088ed 100644 --- a/e2e/tsconfig/MODULE.bazel +++ b/e2e/tsconfig/MODULE.bazel @@ -1,9 +1,7 @@ -"Bazel dependencies" - bazel_dep(name = "aspect_rules_esbuild", version = "0.0.0", dev_dependency = True) -bazel_dep(name = "aspect_bazel_lib", version = "2.2.0", dev_dependency = True) - local_path_override( module_name = "aspect_rules_esbuild", path = "../..", ) + +bazel_dep(name = "aspect_bazel_lib", version = "2.7.1", dev_dependency = True) diff --git a/e2e/tsconfig/WORKSPACE b/e2e/tsconfig/WORKSPACE index f3f0d48..f1e2e90 100644 --- a/e2e/tsconfig/WORKSPACE +++ b/e2e/tsconfig/WORKSPACE @@ -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") diff --git a/esbuild/dependencies.bzl b/esbuild/dependencies.bzl index d7441f0..7dfb8b6 100644 --- a/esbuild/dependencies.bzl +++ b/esbuild/dependencies.bzl @@ -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 = "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 = "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 = "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 = "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", ) diff --git a/esbuild/private/esbuild.bzl b/esbuild/private/esbuild.bzl index 10d6616..88c2c70 100644 --- a/esbuild/private/esbuild.bzl +++ b/esbuild/private/esbuild.bzl @@ -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) @@ -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, )], ) @@ -388,31 +397,26 @@ 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 @@ -420,16 +424,16 @@ def _esbuild_impl(ctx): 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, @@ -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, ), ] diff --git a/esbuild/repositories.bzl b/esbuild/repositories.bzl index 2cf8b05..a032749 100644 --- a/esbuild/repositories.bzl +++ b/esbuild/repositories.bzl @@ -4,7 +4,7 @@ These are needed for local dev, and users must install them as well. See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies """ -load("@aspect_rules_js//npm:npm_import.bzl", "npm_import") +load("@aspect_rules_js//npm:repositories.bzl", "npm_import") load("@bazel_skylib//lib:versions.bzl", "versions") load("//esbuild/private:toolchains_repo.bzl", "get_platforms", "toolchains_repo") load("//esbuild/private:versions.bzl", "TOOL_VERSIONS") @@ -126,10 +126,8 @@ If you need custom versions, please file an issue.""".format(esbuild_version, TO npm_import( name = "npm__esbuild_" + esbuild_version, - run_lifecycle_hooks = False, + lifecycle_hooks = [], integrity = TOOL_VERSIONS[esbuild_version]["npm"], package = "esbuild", version = esbuild_version, - register_copy_directory_toolchains = register, - register_copy_to_directory_toolchains = register, ) diff --git a/internal_deps.bzl b/internal_deps.bzl index 7052980..4e287b1 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -10,14 +10,6 @@ load("//esbuild/private:maybe.bzl", http_archive = "maybe_http_archive") def rules_esbuild_internal_deps(): "Fetch deps needed for local development" - # opt-in to 2.0 without forcing users to do so - http_archive( - name = "aspect_bazel_lib", - sha256 = "8d71a578e4e1b6a54aea7598ebfbd8fc9e3be5da881ff9d2b80249577b933a40", - strip_prefix = "bazel-lib-2.2.0", - url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.2.0/bazel-lib-v2.2.0.tar.gz", - ) - http_archive( name = "io_bazel_stardoc", sha256 = "62bd2e60216b7a6fec3ac79341aa201e0956477e7c8f6ccc286f279ad1d96432",