diff --git a/.bazelversion b/.bazelversion index 6c7efdc..2b1ea10 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1,4 +1,4 @@ -6.3.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 30953a3..59b1306 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,11 @@ bazel-* node_modules + +# 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 e4ea8f6..cb16842 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/BUILD.bazel b/BUILD.bazel index e9377ca..249e8b6 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,11 +1,17 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@buildifier_prebuilt//:rules.bzl", "buildifier") +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 diff --git a/MODULE.bazel b/MODULE.bazel index dac5dfa..b3552d7 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,12 +6,11 @@ module( compatibility_level = 1, ) -bazel_dep(name = "aspect_bazel_lib", version = "1.30.2") - -# Note: only used for provider symbols, we don't spawn nodejs actions -bazel_dep(name = "aspect_rules_js", version = "1.29.2") -bazel_dep(name = "bazel_skylib", version = "1.4.1") -bazel_dep(name = "platforms", version = "0.0.4") +# 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") # Note: only used for provider symbols, we don't spawn nodejs actions +bazel_dep(name = "bazel_skylib", version = "1.5.0") +bazel_dep(name = "platforms", version = "0.0.5") swc = use_extension("@aspect_rules_swc//swc:extensions.bzl", "swc") swc.toolchain( diff --git a/WORKSPACE b/WORKSPACE index 12b4d9a..75bd928 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -19,24 +19,11 @@ swc_register_toolchains( swc_version = LATEST_SWC_VERSION, ) -load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_jq_toolchains") +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains") -aspect_bazel_lib_dependencies(override_local_config_platform = True) +rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION) -register_jq_toolchains() - -load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") - -rules_js_dependencies() - -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", diff --git a/docs/swc.md b/docs/swc.md index 609b8fb..9a9fd5f 100644 --- a/docs/swc.md +++ b/docs/swc.md @@ -39,7 +39,7 @@ for example to set your own output labels for `js_outs`. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | args | Additional arguments to pass to swcx cli (NOT swc!).

NB: this is not the same as the CLI arguments for @swc/cli npm package. For performance, rules_swc does not call a Node.js program wrapping the swc rust binding. Instead, we directly spawn the (somewhat experimental) native Rust binary shipped inside the @swc/core npm package, which the swc project calls "swcx" Tracking issue for feature parity: https://github.com/swc-project/swc/issues/4017 | List of strings | 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 | [] | | js_outs | list of expected JavaScript output files.

There should be one for each entry in srcs. | List of labels | optional | | | map_outs | list of expected source map output files.

Can be empty, meaning no source maps should be produced. If non-empty, there should be one for each entry in srcs. | List of labels | optional | | | out_dir | With output_dir=False, output files will have this directory prefix.

With output_dir=True, this is the name of the output directory. | String | optional | "" | diff --git a/e2e/smoke/BUILD.bazel b/e2e/smoke/BUILD.bazel index 26bd1ea..b8fba46 100644 --- a/e2e/smoke/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -1,5 +1,5 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@aspect_rules_swc//swc:defs.bzl", "swc") +load("@bazel_skylib//rules:build_test.bzl", "build_test") swc( name = "compile", diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel index 94a67ff..4595e0b 100644 --- a/e2e/smoke/MODULE.bazel +++ b/e2e/smoke/MODULE.bazel @@ -1,15 +1,13 @@ -"Bazel dependencies" - bazel_dep(name = "aspect_rules_swc", version = "0.0.0", dev_dependency = True) -bazel_dep(name = "bazel_skylib", version = "1.4.1", dev_dependency = True) - local_path_override( module_name = "aspect_rules_swc", path = "../..", ) +bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) + # Optional: specify a custom swc toolchain instead of the default -swc = use_extension("@aspect_rules_swc//swc:extensions.bzl", "swc") +swc = use_extension("@aspect_rules_swc//swc:extensions.bzl", "swc", dev_dependency = True) swc.toolchain( name = "swc", swc_version = "v1.3.78", diff --git a/examples/opaque_src/BUILD.bazel b/examples/opaque_src/BUILD.bazel index f37cf7c..537db6b 100644 --- a/examples/opaque_src/BUILD.bazel +++ b/examples/opaque_src/BUILD.bazel @@ -3,8 +3,8 @@ Note that this example also depends on the setup in /WORKSPACE at the root of this repository. """ -load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@aspect_bazel_lib//lib:output_files.bzl", "output_files") +load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@aspect_rules_swc//swc:defs.bzl", "swc") filegroup( diff --git a/examples/out_dir/BUILD.bazel b/examples/out_dir/BUILD.bazel index 855b32c..38e0703 100644 --- a/examples/out_dir/BUILD.bazel +++ b/examples/out_dir/BUILD.bazel @@ -1,6 +1,6 @@ -load("@aspect_rules_swc//swc:defs.bzl", "swc") -load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches") +load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") +load("@aspect_rules_swc//swc:defs.bzl", "swc") swc( name = "compile", diff --git a/examples/plugins/BUILD.bazel b/examples/plugins/BUILD.bazel index 44fc619..cbc7539 100644 --- a/examples/plugins/BUILD.bazel +++ b/examples/plugins/BUILD.bazel @@ -3,9 +3,9 @@ See https://github.com/swc-project/plugins """ -load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") -load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path") load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file") +load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path") +load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@aspect_rules_swc//swc:defs.bzl", "swc", "swc_plugin") load("@npm//:defs.bzl", "npm_link_all_packages") diff --git a/examples/root_dir/BUILD.bazel b/examples/root_dir/BUILD.bazel index 5eca696..a041bb3 100644 --- a/examples/root_dir/BUILD.bazel +++ b/examples/root_dir/BUILD.bazel @@ -1,6 +1,6 @@ -load("@aspect_rules_swc//swc:defs.bzl", "swc") load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches") load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") +load("@aspect_rules_swc//swc:defs.bzl", "swc") swc( name = "compile", diff --git a/examples/source_map_support/BUILD.bazel b/examples/source_map_support/BUILD.bazel index 0f87204..fef9556 100644 --- a/examples/source_map_support/BUILD.bazel +++ b/examples/source_map_support/BUILD.bazel @@ -1,5 +1,5 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") exports_files([ "defs.bzl", diff --git a/examples/source_root/BUILD.bazel b/examples/source_root/BUILD.bazel index c34d1a4..fdfc669 100644 --- a/examples/source_root/BUILD.bazel +++ b/examples/source_root/BUILD.bazel @@ -1,5 +1,5 @@ -load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches") +load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@aspect_rules_swc//swc:defs.bzl", "swc") # Specifies a custom location where a debugger should locate source files instead of relative source diff --git a/examples/transitive/app/BUILD.bazel b/examples/transitive/app/BUILD.bazel index 8c0c13a..13b3709 100644 --- a/examples/transitive/app/BUILD.bazel +++ b/examples/transitive/app/BUILD.bazel @@ -1,5 +1,5 @@ -load("@aspect_rules_swc//swc:defs.bzl", "swc") load("@aspect_rules_js//js:defs.bzl", "js_binary") +load("@aspect_rules_swc//swc:defs.bzl", "swc") package(default_visibility = ["//:__subpackages__"]) diff --git a/internal_deps.bzl b/internal_deps.bzl index 6b9e286..9f16145 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -15,15 +15,13 @@ def rules_swc_internal_deps(): 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 = "e46c16180bc49487bfd0f1ffa7345364718c57334fa0b5b67cb5f27eba10f309", - strip_prefix = "buildifier-prebuilt-6.1.0", - urls = [ - "https://github.com/keith/buildifier-prebuilt/archive/6.1.0.tar.gz", - ], + sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e", + strip_prefix = "buildifier-prebuilt-6.4.0", + urls = ["http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz"], ) diff --git a/swc/defs.bzl b/swc/defs.bzl index 23d98db..1e9f707 100644 --- a/swc/defs.bzl +++ b/swc/defs.bzl @@ -12,11 +12,11 @@ swc( ``` """ -load("//swc/private:swc.bzl", _swc_lib = "swc") -load("//swc/private:swc_plugin.bzl", _swc_plugin_lib = "swc_plugin") load("@aspect_bazel_lib//lib:utils.bzl", "file_exists", "to_label") load("@bazel_skylib//lib:types.bzl", "types") load("@bazel_skylib//rules:write_file.bzl", "write_file") +load("//swc/private:swc.bzl", _swc_lib = "swc") +load("//swc/private:swc_plugin.bzl", _swc_plugin_lib = "swc_plugin") swc_compile = rule( doc = """Underlying rule for the `swc` macro. diff --git a/swc/dependencies.bzl b/swc/dependencies.bzl index b73d4d9..82cec54 100644 --- a/swc/dependencies.bzl +++ b/swc/dependencies.bzl @@ -15,20 +15,27 @@ def http_archive(**kwargs): def rules_swc_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 = "97fa63d95cc9af006c4c7b2123ddd2a91fb8d273012f17648e6423bae2c69470", - strip_prefix = "bazel-lib-1.30.2", - url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.30.2/bazel-lib-v1.30.2.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 = "7cb2d84b7d5220194627c9a0267ae599e357350e75ea4f28f337a25ca6219b83", - strip_prefix = "rules_js-1.29.2", - url = "https://github.com/aspect-build/rules_js/releases/download/v1.29.2/rules_js-v1.29.2.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 = "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/swc/private/swc.bzl b/swc/private/swc.bzl index 0d20dd1..1093e5c 100644 --- a/swc/private/swc.bzl +++ b/swc/private/swc.bzl @@ -42,7 +42,14 @@ _attrs = { If out_dir is also specified, it is used as the name of the output directory. Otherwise, the directory is named the same as the target.""", ), - "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, + ), "swcrc": attr.label( doc = "label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc", allow_single_file = True, @@ -326,18 +333,18 @@ def _swc_impl(ctx): targets = ctx.attr.srcs, ) - transitive_declarations = js_lib_helpers.gather_transitive_declarations( - declarations = [], + transitive_types = js_lib_helpers.gather_transitive_types( + types = [], targets = ctx.attr.srcs, ) - npm_linked_packages = js_lib_helpers.gather_npm_linked_packages( + 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( - targets = ctx.attr.data, + npm_package_store_infos = js_lib_helpers.gather_npm_package_store_infos( + targets = ctx.attr.srcs + ctx.attr.data, ) runfiles = js_lib_helpers.gather_runfiles( @@ -349,14 +356,13 @@ def _swc_impl(ctx): return [ 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_declarations = transitive_declarations, - transitive_npm_linked_package_files = npm_linked_packages.transitive_files, - transitive_npm_linked_packages = npm_linked_packages.transitive, + types = depset(), # swc does not emit types directly transitive_sources = transitive_sources, + transitive_types = transitive_types, + npm_sources = npm_sources, + npm_package_store_infos = npm_package_store_infos, ), DefaultInfo( files = output_sources_depset,