Skip to content

Commit b354632

Browse files
committed
package_managers: yarn: Disable corepack prompt when fetching yarn
Starting with corepack 0.25.0 [1], corepack now defaults to asking users if they're okay if its yarn shim downloads a particular version from the registry: ! Corepack is about to download https://repo.yarnpkg.com/.../yarn.js ? Do you want to continue? [Y/n] ^This will break tests once we either explicitly move our corepack == 0.20.0 to corepack >= 0.25.0 implicitly by adopting a newer NodeJS releases in the multi-stage Docker build conversion future patches will bring. Either way, let's prepare for it by setting the new env variable corepack introduced for this COREPACK_ENABLE_DOWNLOAD_PROMPT [2]. [1] https://github.com/nodejs/corepack/releases/tag/v0.25.0 [2] nodejs/corepack#360 (comment) Signed-off-by: Erik Skultety <eskultet@redhat.com>
1 parent fc7e6f8 commit b354632

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

cachi2/core/package_managers/yarn/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ def _generate_environment_variables() -> list[EnvironmentVariable]:
228228

229229
def _verify_corepack_yarn_version(expected_version: semver.Version, source_dir: RootedPath) -> None:
230230
"""Verify that corepack installed the correct version of yarn by checking `yarn --version`."""
231-
installed_yarn_version = run_yarn_cmd(["--version"], source_dir).strip()
231+
installed_yarn_version = run_yarn_cmd(
232+
["--version"], source_dir, env={"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0"}
233+
).strip()
232234
try:
233235
if installed_yarn_version != expected_version:
234236
raise PackageManagerError(

tests/unit/package_managers/yarn/test_main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def test_corepack_installed_correct_yarn_version(
151151
mock_run_yarn_cmd.return_value = corepack_yarn_version
152152

153153
_verify_corepack_yarn_version(expected_yarn_version, rooted_tmp_path)
154-
mock_run_yarn_cmd.assert_called_once_with(["--version"], rooted_tmp_path)
154+
mock_run_yarn_cmd.assert_called_once_with(
155+
["--version"], rooted_tmp_path, env={"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0"}
156+
)
155157

156158

157159
@pytest.mark.parametrize(
@@ -173,7 +175,9 @@ def test_corepack_installed_correct_yarn_version_fail(
173175
with pytest.raises(PackageManagerError):
174176
_verify_corepack_yarn_version(expected_yarn_version, rooted_tmp_path)
175177

176-
mock_run_yarn_cmd.assert_called_once_with(["--version"], rooted_tmp_path)
178+
mock_run_yarn_cmd.assert_called_once_with(
179+
["--version"], rooted_tmp_path, env={"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0"}
180+
)
177181

178182

179183
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)