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(builtin): gracefully handle the case of empty yarn_urls #2619

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ node_repositories(
Will download yarn from https://github.com/yarnpkg/yarn/releases/download/v1.2.1/yarn-v1.12.1.tar.gz
and expect the file to have sha256sum `09bea8f4ec41e9079fa03093d3b2db7ac5c5331852236d63815f8df42b3ba88d`.

If you don't use Yarn at all, you can skip downloading it by setting `yarn_urls = []`.

### Using a local version

To avoid downloads, you can check in vendored copies of NodeJS and/or Yarn and set vendored_node and or vendored_yarn
Expand Down Expand Up @@ -220,6 +222,8 @@ By default, if this attribute has no items, we'll use a list of all public NodeJ
doc = """custom list of URLs to use to download Yarn

Each entry is a template, similar to the `node_urls` attribute, using `yarn_version` and `yarn_repositories` in the substitutions.

If this list is empty, we won't download yarn at all.
""",
),
"yarn_version": attr.string(
Expand Down Expand Up @@ -313,6 +317,14 @@ def _download_yarn(repository_ctx):
Args:
repository_ctx: The repository rule context
"""
yarn_urls = repository_ctx.attr.yarn_urls

# If there are no URLs to download yarn, skip the download
if not len(yarn_urls):
repository_ctx.file("yarn_info", content = "# no yarn urls")
return

# If yarn is vendored locally, we still need the info file but can skip downloading
if repository_ctx.attr.vendored_yarn:
repository_ctx.file("yarn_info", content = "# vendored_yarn: {vendored_yarn}".format(
vendored_yarn = repository_ctx.attr.vendored_yarn,
Expand All @@ -326,7 +338,6 @@ def _download_yarn(repository_ctx):
# The size of _YARN_VERSIONS constant is huge and not useful to document.
if not yarn_repositories.items():
yarn_repositories = _YARN_VERSIONS
yarn_urls = repository_ctx.attr.yarn_urls

if yarn_version in yarn_repositories:
filename, strip_prefix, sha256 = yarn_repositories[yarn_version]
Expand Down