Skip to content

Commit

Permalink
package_managers: yarn: Disable corepack prompt when fetching yarn
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
eskultety committed Jun 27, 2024
1 parent 695de20 commit 5144af5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cachi2/core/package_managers/yarn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def _generate_environment_variables() -> list[EnvironmentVariable]:

def _verify_corepack_yarn_version(expected_version: semver.Version, source_dir: RootedPath) -> None:
"""Verify that corepack installed the correct version of yarn by checking `yarn --version`."""
installed_yarn_version = run_yarn_cmd(["--version"], source_dir).strip()
installed_yarn_version = run_yarn_cmd(
["--version"], source_dir, env={"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0"}
).strip()
try:
if installed_yarn_version != expected_version:
raise PackageManagerError(
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/package_managers/yarn/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def test_corepack_installed_correct_yarn_version(
mock_run_yarn_cmd.return_value = corepack_yarn_version

_verify_corepack_yarn_version(expected_yarn_version, rooted_tmp_path)
mock_run_yarn_cmd.assert_called_once_with(["--version"], rooted_tmp_path)
mock_run_yarn_cmd.assert_called_once_with(
["--version"], rooted_tmp_path, env={"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0"}
)


@pytest.mark.parametrize(
Expand All @@ -173,7 +175,9 @@ def test_corepack_installed_correct_yarn_version_fail(
with pytest.raises(PackageManagerError):
_verify_corepack_yarn_version(expected_yarn_version, rooted_tmp_path)

mock_run_yarn_cmd.assert_called_once_with(["--version"], rooted_tmp_path)
mock_run_yarn_cmd.assert_called_once_with(
["--version"], rooted_tmp_path, env={"COREPACK_ENABLE_DOWNLOAD_PROMPT": "0"}
)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 5144af5

Please sign in to comment.