Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(yarn): when running vendored yarn, prefix command with path to node #3255

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ example_integration_test(
npm_packages = {
"//packages/jasmine:npm_package": "@bazel/jasmine",
},
# Needs some thought about how to invoke "node.exe path/to/yarn.js on windows to avoid
# Error in fail: yarn --version failed: (java.io.IOException: ERROR: src/main/native/windows/process.cc(202):
# CreateProcessW("C:\users\b\_bazel_b\ag3rxjdr\external\vendored_yarn_1_10_0\yarn-v1.10.0\bin\yarn.js" --version):
# %1 is not a valid Win32 application.
# TODO: make it find node.exe rather than rely on us writing a .cmd wrapper
tags = ["no-bazelci-windows"],
)

Expand Down
5 changes: 3 additions & 2 deletions examples/vendored_node_and_yarn/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ http_archive(

http_archive(
name = "vendored_yarn_1_10_0",
build_file_content = """exports_files(["vendored_yarn_1_10_0/yarn-v1.10.0/bin/yarn.js"])""",
build_file_content = """exports_files(["bin/yarn.js"])""",
sha256 = "83277bd505c7f4009c13077266020c97298727de7edf67af5ca66eccae9d4632",
strip_prefix = "yarn-v1.10.0",
urls = ["https://github.com/yarnpkg/yarn/releases/download/v1.10.0/yarn-v1.10.0.tar.gz"],
)

Expand All @@ -67,6 +68,6 @@ yarn_install(
exports_directories_only = False,
node_repository = "vendored_node",
package_json = "//:package.json",
yarn = "@vendored_yarn_1_10_0//:yarn-v1.10.0/bin/yarn.js",
yarn = "@vendored_yarn_1_10_0//:bin/yarn.js",
yarn_lock = "//:yarn.lock",
)
19 changes: 14 additions & 5 deletions internal/npm_install/npm_install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ check if yarn is being run by the `npm_install` repository rule.""",
)

def _detect_yarn_version(rctx, yarn):
result = rctx.execute([yarn, "--version"])
result = rctx.execute(yarn + ["--version"])
if result.return_code:
fail("yarn --version failed: %s (%s)" % (result.stdout, result.stderr))
if result.stdout.startswith("1."):
Expand All @@ -828,8 +828,17 @@ def _yarn_install_impl(repository_ctx):
# A custom yarn won't have our special wrapper batch script
if is_windows_host and _repository_contains_file(repository_ctx, yarn_label.workspace_name, "bin/yarn.cmd"):
yarn_label = yarn_label.relative(":bin/yarn.cmd")
yarn = repository_ctx.path(yarn_label)
yarn_version = _detect_yarn_version(repository_ctx, yarn)

if yarn_label.name.endswith(".js"):
yarn_cmd = [node, yarn_label]
else:
# Our wrapper scripts include the "node" executable
yarn_cmd = [yarn_label]

yarn_version = _detect_yarn_version(repository_ctx, yarn_cmd)

# Quoted command line for use in scripts
yarn = " ".join(["\"%s\"" % repository_ctx.path(s) for s in yarn_cmd])
yarn_args = []

# CLI arguments changed in yarn 2+
Expand Down Expand Up @@ -898,7 +907,7 @@ set -e
unset YARN_IGNORE_PATH
unset INIT_CWD
unset npm_config_registry
(cd "{root}"; "{yarn}" {yarn_args})
(cd "{root}"; {yarn} {yarn_args})
""".format(
root = root,
yarn = yarn,
Expand All @@ -913,7 +922,7 @@ unset npm_config_registry
set "YARN_IGNORE_PATH="
set “INIT_CWD=”
set “npm_config_registry=”
cd /D "{root}" && "{yarn}" {yarn_args}
cd /D "{root}" && {yarn} {yarn_args}
""".format(
root = root,
yarn = yarn,
Expand Down