Skip to content

Commit

Permalink
refactor: drop support for Bazel 5
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Apr 3, 2024
1 parent e1b21f5 commit d4dde37
Show file tree
Hide file tree
Showing 45 changed files with 1,062 additions and 5,732 deletions.
9 changes: 4 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ docs/*_*.md
e2e/**/*-docs.md
examples/**/*-docs.md
js/private/coverage/coverage.js
js/private/js_image_layer.mjs
js/private/node-patches/fs.js
js/private/node-patches_legacy/fs.js
min/
npm/private/test/vendored/
js/private/worker/worker.js
js/private/worker/src/worker_protocol.ts
js/private/js_image_layer.mjs
js/private/worker/worker.js
min/
npm/private/test/vendored/
11 changes: 10 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,16 @@ npm.npm_translate_lock(
verify_node_modules_ignored = "//:.bazelignore",
verify_patches = "//examples/npm_deps/patches:patches",
)
use_repo(npm, "npm", "npm__rollup__2.70.2", "npm__webpack-bundle-analyzer__4.5.0__bufferutil_4.0.7")
use_repo(
npm,
"npm",
"npm__chalk__5.0.1__links",
"npm__fsevents__2.3.2__links",
"npm__rollup__2.70.2",
"npm__rollup__2.70.2__links",
"npm__unused__0.2.2__links",
"npm__webpack-bundle-analyzer__4.5.0__bufferutil_4.0.7",
)

# As an example, manually import a package using explicit coordinates.
# Just a demonstration of the syntax de-sugaring.
Expand Down
7 changes: 2 additions & 5 deletions docs/js_binary.md

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

4 changes: 2 additions & 2 deletions e2e/gyp_no_install_script/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ write_source_files(
"test/segfault-handler_defs.bzl.checked": "@npm__segfault-handler__1.3.0__links//:defs.bzl",
},
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
"@aspect_bazel_lib//lib:bzlmod": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
7 changes: 0 additions & 7 deletions js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
"Public API"

load("@aspect_bazel_lib//lib:utils.bzl", "is_bazel_7_or_greater")
load("@bazel_features//:features.bzl", "bazel_features")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files(
glob(["*.bzl"]),
visibility = ["//docs:__pkg__"],
)

config_setting(
name = "allow_unresolved_symlinks",
values = {bazel_features.flags.allow_unresolved_symlinks: "true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "enable_runfiles",
values = {"enable_runfiles": "true"},
Expand Down
8 changes: 0 additions & 8 deletions js/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def js_binary(**kwargs):
Label("@aspect_rules_js//js:enable_runfiles"): True,
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
Label("@aspect_rules_js//js:allow_unresolved_symlinks"): True,
"//conditions:default": False,
}),
**kwargs
)

Expand All @@ -45,10 +41,6 @@ def js_test(**kwargs):
Label("@aspect_rules_js//js:enable_runfiles"): True,
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
Label("@aspect_rules_js//js:allow_unresolved_symlinks"): True,
"//conditions:default": False,
}),
**kwargs
)

Expand Down
39 changes: 5 additions & 34 deletions js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ js_binary(
load("@aspect_bazel_lib//lib:windows_utils.bzl", "create_windows_native_launcher_script")
load("@aspect_bazel_lib//lib:expand_make_vars.bzl", "expand_locations", "expand_variables")
load("@aspect_bazel_lib//lib:directory_path.bzl", "DirectoryPathInfo")
load("@aspect_bazel_lib//lib:utils.bzl", "consistent_label_str", "is_bazel_6_or_greater")
load("@aspect_bazel_lib//lib:utils.bzl", "consistent_label_str")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load(":js_helpers.bzl", "LOG_LEVELS", "envs_for_log_level", "gather_runfiles")
Expand Down Expand Up @@ -257,18 +257,6 @@ _ATTRS = {
to use npm.
""",
),
"unresolved_symlinks_enabled": attr.bool(
doc = """Whether unresolved symlinks are enabled in the current build configuration.
These are enabled with the `--allow_unresolved_symlinks` flag
(named `--experimental_allow_unresolved_symlinks in Bazel versions prior to 7.0).
Typical usage of this rule is via a macro which automatically sets this
attribute based on a `config_setting` rule.
See /js/private/BUILD.bazel in rules_js for an example.
""",
mandatory = True,
),
"node_toolchain": attr.label(
doc = """The Node.js toolchain to use for this target.
Expand Down Expand Up @@ -300,14 +288,6 @@ _ATTRS = {
allow_single_file = True,
),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
"_node_patches_legacy_files": attr.label_list(
allow_files = True,
default = ["@aspect_rules_js//js/private/node-patches_legacy:fs.js"],
),
"_node_patches_legacy": attr.label(
allow_single_file = True,
default = "@aspect_rules_js//js/private/node-patches_legacy:register.js",
),
"_node_patches_files": attr.label_list(
allow_files = True,
default = ["@aspect_rules_js//js/private/node-patches:fs.js"],
Expand All @@ -329,7 +309,7 @@ _NODE_OPTION = """JS_BINARY__NODE_OPTIONS+=(\"{value}\")"""
def _target_tool_path_to_short_path(tool_path):
return ("../" + tool_path[len("external/"):]) if tool_path.startswith("external/") else tool_path

def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows, use_legacy_node_patches):
def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows):
# Explicitly disable node fs patches on Windows:
# https://github.com/aspect-build/rules_js/issues/1137
if is_windows:
Expand Down Expand Up @@ -459,7 +439,7 @@ def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, l
"{{log_prefix_rule_set}}": log_prefix_rule_set,
"{{log_prefix_rule}}": log_prefix_rule,
"{{node_options}}": "\n".join(node_options),
"{{node_patches}}": ctx.file._node_patches_legacy.short_path if use_legacy_node_patches else ctx.file._node_patches.short_path,
"{{node_patches}}": ctx.file._node_patches.short_path,
"{{node_wrapper}}": node_wrapper.short_path,
"{{node}}": node_path,
"{{npm}}": npm_path,
Expand All @@ -478,11 +458,6 @@ def _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, l

def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [], fixed_env = {}):
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
is_bazel_6 = is_bazel_6_or_greater()
unresolved_symlinks_enabled = False
if hasattr(ctx.attr, "unresolved_symlinks_enabled"):
unresolved_symlinks_enabled = ctx.attr.unresolved_symlinks_enabled
use_legacy_node_patches = not is_bazel_6 or not unresolved_symlinks_enabled

if ctx.attr.node_toolchain:
node_toolchain = ctx.attr.node_toolchain[platform_common.ToolchainInfo]
Expand All @@ -504,15 +479,11 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
entry_point = ctx.files.entry_point[0]
entry_point_path = entry_point.short_path

bash_launcher, toolchain_files = _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows, use_legacy_node_patches)
bash_launcher, toolchain_files = _bash_launcher(ctx, node_toolchain, entry_point_path, log_prefix_rule_set, log_prefix_rule, fixed_args, fixed_env, is_windows)
launcher = create_windows_native_launcher_script(ctx, bash_launcher) if is_windows else bash_launcher

launcher_files = [bash_launcher] + toolchain_files
if use_legacy_node_patches:
launcher_files.extend(ctx.files._node_patches_legacy_files + [ctx.file._node_patches_legacy])
else:
launcher_files.extend(ctx.files._node_patches_files + [ctx.file._node_patches])

launcher_files.extend(ctx.files._node_patches_files + [ctx.file._node_patches])
launcher_files.extend(node_toolchain.nodeinfo.tool_files)
if ctx.attr.include_npm:
launcher_files.extend(node_toolchain.nodeinfo.npm_files)
Expand Down
4 changes: 0 additions & 4 deletions js/private/js_run_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ def js_run_devserver(
"@aspect_rules_js//js:enable_runfiles": True,
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
entry_point = "@aspect_rules_js//js/private:js_devserver_entrypoint",
# This rule speaks the ibazel protocol
tags = kwargs.pop("tags", []) + ["ibazel_notify_changes"],
Expand Down
13 changes: 0 additions & 13 deletions js/private/node-patches_legacy/BUILD.bazel

This file was deleted.

Loading

0 comments on commit d4dde37

Please sign in to comment.