Skip to content

Commit b6a8cbb

Browse files
Lukas Holzeralexeagle
authored andcommitted
feat(builtin): yarn install use --frozen-lockfile as default
To be more hermetic with the install of the dependencies use the frozen lockfile flag to install the exact version from the `yarn.lock` file. To update a dependency use the vendored yarn binary with `bazel run @nodejs//:yarn upgrade <dep-name>`. Fixes #941
1 parent abffd7d commit b6a8cbb

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

internal/bazel_integration_test/test_runner.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ if (config.bazelrcAppend) {
219219
const replacement =
220220
`load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")\nhttp_archive(\n name = "${
221221
repositoryKey}",\n url="file:${archiveFile}"\n`;
222-
workspaceContents = workspaceContents.replace(regex, replacement);
222+
223+
workspaceContents = workspaceContents.replace(regex, replacement)
224+
// We have to disable the frozen lockfile option for the tests it won't match with the version
225+
// from the yarn.lock file.
226+
workspaceContents =
227+
workspaceContents.replace(/(yarn_lock[\s\S]+?,)/gm, 'frozen_lockfile = False,\n $1')
228+
223229
if (!workspaceContents.includes(archiveFile)) {
224230
console.error(
225231
`bazel_integration_test: WORKSPACE replacement for repository ${repositoryKey} failed!`)

internal/npm_install/npm_install.bzl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def _add_data_dependencies(repository_ctx):
157157
for f in repository_ctx.attr.data:
158158
to = []
159159
if f.package:
160-
to += [f.package]
161-
to += [f.name]
160+
to.append(f.package)
161+
to.append(f.name)
162162

163163
# Make copies of the data files instead of symlinking
164164
# as yarn under linux will have trouble using symlinked
@@ -326,6 +326,13 @@ def _yarn_install_impl(repository_ctx):
326326
yarn = get_yarn_label(repository_ctx)
327327

328328
yarn_args = []
329+
330+
# Set frozen lockfile as default install to install the exact version from the yarn.lock
331+
# file. To perform an yarn install use the vendord yarn binary with:
332+
# `bazel run @nodejs//:yarn install` or `bazel run @nodejs//:yarn install -- -D <dep-name>`
333+
if repository_ctx.attr.frozen_lockfile:
334+
yarn_args.append("--frozen-lockfile")
335+
329336
if not repository_ctx.attr.use_global_yarn_cache:
330337
yarn_args.extend(["--cache-folder", str(repository_ctx.path("_yarn_cache"))])
331338
else:
@@ -427,6 +434,20 @@ yarn_install = repository_rule(
427434
See yarn CLI docs https://yarnpkg.com/en/docs/cli/install for complete list of supported arguments.""",
428435
default = [],
429436
),
437+
"frozen_lockfile": attr.bool(
438+
default = True,
439+
doc = """Use the `--frozen-lockfile` flag for yarn.
440+
441+
Don’t generate a `yarn.lock` lockfile and fail if an update is needed.
442+
443+
This flag enables an exact install of the version that is specified in the `yarn.lock`
444+
file. This helps to have reproduceable builds across builds.
445+
446+
To update a dependency or install a new one run the `yarn install` command with the
447+
vendored yarn binary. `bazel run @nodejs//:yarn install`. You can pass the options like
448+
`bazel run @nodejs//:yarn install -- -D <dep-name>`.
449+
""",
450+
),
430451
"use_global_yarn_cache": attr.bool(
431452
default = True,
432453
doc = """Use the global yarn cache on the system.

0 commit comments

Comments
 (0)