Skip to content

Commit

Permalink
fix(): remove node and use toolchain (#3144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan authored Dec 16, 2021
1 parent 55a7521 commit cb83746
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 37 deletions.
16 changes: 2 additions & 14 deletions docs/Built-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Defaults to `"1.22.11"`

<pre>
nodejs_binary(<a href="#nodejs_binary-name">name</a>, <a href="#nodejs_binary-chdir">chdir</a>, <a href="#nodejs_binary-configuration_env_vars">configuration_env_vars</a>, <a href="#nodejs_binary-data">data</a>, <a href="#nodejs_binary-default_env_vars">default_env_vars</a>, <a href="#nodejs_binary-entry_point">entry_point</a>, <a href="#nodejs_binary-env">env</a>,
<a href="#nodejs_binary-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_binary-node">node</a>, <a href="#nodejs_binary-templated_args">templated_args</a>, <a href="#nodejs_binary-toolchain">toolchain</a>)
<a href="#nodejs_binary-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_binary-templated_args">templated_args</a>, <a href="#nodejs_binary-toolchain">toolchain</a>)
</pre>

Runs some JavaScript code in NodeJS.
Expand Down Expand Up @@ -397,12 +397,6 @@ If source files need to be required then they can be copied to the bin_dir with

Defaults to `False`

<h4 id="nodejs_binary-node">node</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*)

Defaults to `@nodejs//:node_bin`

<h4 id="nodejs_binary-templated_args">templated_args</h4>

(*List of strings*): Arguments which are passed to every execution of the program.
Expand Down Expand Up @@ -497,7 +491,7 @@ Defaults to `None`

<pre>
nodejs_test(<a href="#nodejs_test-name">name</a>, <a href="#nodejs_test-chdir">chdir</a>, <a href="#nodejs_test-configuration_env_vars">configuration_env_vars</a>, <a href="#nodejs_test-data">data</a>, <a href="#nodejs_test-default_env_vars">default_env_vars</a>, <a href="#nodejs_test-entry_point">entry_point</a>, <a href="#nodejs_test-env">env</a>,
<a href="#nodejs_test-expected_exit_code">expected_exit_code</a>, <a href="#nodejs_test-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_test-node">node</a>, <a href="#nodejs_test-templated_args">templated_args</a>, <a href="#nodejs_test-toolchain">toolchain</a>)
<a href="#nodejs_test-expected_exit_code">expected_exit_code</a>, <a href="#nodejs_test-link_workspace_root">link_workspace_root</a>, <a href="#nodejs_test-templated_args">templated_args</a>, <a href="#nodejs_test-toolchain">toolchain</a>)
</pre>


Expand Down Expand Up @@ -663,12 +657,6 @@ If source files need to be required then they can be copied to the bin_dir with

Defaults to `False`

<h4 id="nodejs_test-node">node</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*)

Defaults to `@nodejs//:node_bin`

<h4 id="nodejs_test-templated_args">templated_args</h4>

(*List of strings*): Arguments which are passed to every execution of the program.
Expand Down
8 changes: 1 addition & 7 deletions docs/Cypress.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Defaults to `None`

<pre>
cypress_web_test(<a href="#cypress_web_test-name">name</a>, <a href="#cypress_web_test-chdir">chdir</a>, <a href="#cypress_web_test-config_file">config_file</a>, <a href="#cypress_web_test-configuration_env_vars">configuration_env_vars</a>, <a href="#cypress_web_test-cypress_npm_package">cypress_npm_package</a>, <a href="#cypress_web_test-data">data</a>,
<a href="#cypress_web_test-default_env_vars">default_env_vars</a>, <a href="#cypress_web_test-entry_point">entry_point</a>, <a href="#cypress_web_test-env">env</a>, <a href="#cypress_web_test-expected_exit_code">expected_exit_code</a>, <a href="#cypress_web_test-link_workspace_root">link_workspace_root</a>, <a href="#cypress_web_test-node">node</a>,
<a href="#cypress_web_test-default_env_vars">default_env_vars</a>, <a href="#cypress_web_test-entry_point">entry_point</a>, <a href="#cypress_web_test-env">env</a>, <a href="#cypress_web_test-expected_exit_code">expected_exit_code</a>, <a href="#cypress_web_test-link_workspace_root">link_workspace_root</a>,
<a href="#cypress_web_test-plugin_file">plugin_file</a>, <a href="#cypress_web_test-srcs">srcs</a>, <a href="#cypress_web_test-templated_args">templated_args</a>, <a href="#cypress_web_test-toolchain">toolchain</a>)
</pre>

Expand Down Expand Up @@ -250,12 +250,6 @@ If source files need to be required then they can be copied to the bin_dir with

Defaults to `False`

<h4 id="cypress_web_test-node">node</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*)

Defaults to `@nodejs//:node_bin`

<h4 id="cypress_web_test-plugin_file">plugin_file</h4>

(*<a href="https://bazel.build/docs/build-ref.html#labels">Label</a>*): Your cypress plugin file. See https://docs.cypress.io/guides/tooling/plugins-guide
Expand Down
11 changes: 2 additions & 9 deletions internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ load("//internal/common:path_utils.bzl", "strip_external")
load("//internal/common:preserve_legacy_templated_args.bzl", "preserve_legacy_templated_args")
load("//internal/common:windows_utils.bzl", "create_windows_native_launcher_script", "is_windows")
load("//internal/linker:link_node_modules.bzl", "LinkerPackageMappingInfo", "module_mappings_aspect", "write_node_modules_manifest")
load("//nodejs:repositories.bzl", "BUILT_IN_NODE_PLATFORMS")

def _trim_package_node_modules(package_name):
# trim a package name down to its path prior to a node_modules
Expand Down Expand Up @@ -248,13 +247,13 @@ fi
#
# Rules such as nodejs_image should use only ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"].nodeinfo
# when building the image as that will reflect the selected --platform.
node_tool_files = ctx.files.node[:]

if ctx.attr.toolchain:
node_toolchain = ctx.attr.toolchain[platform_common.ToolchainInfo]
else:
node_toolchain = ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"]

node_tool_files = []
node_tool_files.extend(node_toolchain.nodeinfo.tool_files)
node_tool_files.append(ctx.file._link_modules_script)
node_tool_files.append(ctx.file._runfile_helpers_bundle)
Expand All @@ -263,8 +262,6 @@ fi
node_tool_files.append(ctx.file._lcov_merger_script)
node_tool_files.append(node_modules_manifest)

is_builtin = ctx.attr.node.label.workspace_name in ["nodejs_%s" % p for p in BUILT_IN_NODE_PLATFORMS]

runfiles = runfiles[:]
runfiles.extend(node_tool_files)
runfiles.extend(ctx.files._bash_runfile_helper)
Expand Down Expand Up @@ -322,7 +319,7 @@ fi
"TEMPLATED_repository_args": _to_manifest_path(ctx, ctx.file._repository_args),
"TEMPLATED_require_patch_script": _to_manifest_path(ctx, ctx.outputs.require_patch_script),
"TEMPLATED_runfiles_helper_script": _to_manifest_path(ctx, ctx.file._runfile_helpers_main),
"TEMPLATED_vendored_node": "" if is_builtin else strip_external(ctx.file.node.path),
"TEMPLATED_vendored_node": strip_external(node_toolchain.nodeinfo.target_tool_path),
}

# TODO when we have "link_all_bins" we will only need to look in one place for the entry point
Expand Down Expand Up @@ -596,10 +593,6 @@ Predefined genrule variables are not supported in this context.
default = Label("//internal/node:loader.js"),
allow_single_file = True,
),
"node": attr.label(
default = Label("@nodejs//:node_bin"),
allow_single_file = True,
),
"toolchain": attr.label(),
"_repository_args": attr.label(
default = Label("@nodejs//:bin/node_repo_args.sh"),
Expand Down
11 changes: 4 additions & 7 deletions internal/node/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ nodejs_binary(
entry_point = "binary_version.js",
# using the select statement will download toolchains for all three platforms
# you can also just provide an individual toolchain if you don't want to download them all
node = select({
toolchain = select({
"@bazel_tools//src/conditions:linux_x86_64": "@node15_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node15_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node15_windows_amd64//:node_toolchain",
Expand All @@ -569,7 +569,7 @@ nodejs_binary(
entry_point = "binary_version.js",
# using the select statement will download toolchains for all three platforms
# you can also just provide an individual toolchain if you don't want to download them all
node = select({
toolchain = select({
"@bazel_tools//src/conditions:linux_x86_64": "@node16_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node16_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node16_windows_amd64//:node_toolchain",
Expand All @@ -586,7 +586,7 @@ nodejs_test(
entry_point = "toolchain_test_v15.14.0.js",
# using the select statement will download toolchains for all three platforms
# you can also just provide an individual toolchain if you don't want to download them all
node = select({
toolchain = select({
"@bazel_tools//src/conditions:linux_x86_64": "@node15_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node15_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node15_windows_amd64//:node_toolchain",
Expand All @@ -598,7 +598,7 @@ nodejs_test(
entry_point = "toolchain_test_v16.js",
# using the select statement will download toolchains for all three platforms
# you can also just provide an individual toolchain if you don't want to download them all
node = select({
toolchain = select({
"@bazel_tools//src/conditions:linux_x86_64": "@node16_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node16_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node16_windows_amd64//:node_toolchain",
Expand All @@ -615,7 +615,6 @@ nodejs_test(
nodejs_binary(
name = "main_multiple_loop_" + id,
entry_point = "binary_version.js",
node = tc,
toolchain = tc,
)
for id, tc in zip(
Expand Down Expand Up @@ -651,7 +650,6 @@ nodejs_test(
"data/data.json",
],
entry_point = ":data_resolution.spec.js",
node = tc,
toolchain = tc,
)
for id, tc in zip(
Expand Down Expand Up @@ -684,7 +682,6 @@ nodejs_test(
nodejs_test(
name = "main_test_multiple_version_" + id,
entry_point = entry,
node = tc,
toolchain = tc,
)
for id, entry, tc in zip(
Expand Down

0 comments on commit cb83746

Please sign in to comment.