From 15cac3c05974287f3946c62e75aecd79b7706efb Mon Sep 17 00:00:00 2001 From: Bruno Pimentel Date: Fri, 3 Jan 2025 17:11:35 -0300 Subject: [PATCH] Yarn Berry: remove unused code There's no need for Cachi2 to directly access the contents of the "npmRegistryServer" yarn_rc variable, since Yarn itself will read it when we execute "yarn install". The code refering to it is a leftover of the development phase. In a similar way, there's no use in setting "unsafeHttpWhitelist" as an empty list by default, since Cachi2 will purposefully set it to an empty list as a way to overwrite any unwanted user configuration. Signed-off-by: Bruno Pimentel --- cachi2/core/package_managers/yarn/project.py | 13 ------------- tests/unit/package_managers/yarn/test_project.py | 8 +++----- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/cachi2/core/package_managers/yarn/project.py b/cachi2/core/package_managers/yarn/project.py index 858ecfb5e..f9ef2b8b5 100644 --- a/cachi2/core/package_managers/yarn/project.py +++ b/cachi2/core/package_managers/yarn/project.py @@ -68,22 +68,9 @@ class YarnRc(ConfigurationFile): _defaults = { "cacheFolder": "./.yarn/cache", "lockfileFilename": "yarn.lock", - "unsafeHttpWhitelist": [], "plugins": [], - "npmRegistryServer": "https://registry.yarnpkg.com", } - def registry_server_for_scope(self, scope: str) -> str: - """Get the configured registry server for a scoped package. - - Fallback to the global defined registry server if there's no configuration for this specific - scope. - - See: https://v3.yarnpkg.com/configuration/yarnrc#npmScopes - """ - registry = self.data.get("npmScopes", {}).get(scope, {}).get("npmRegistryServer") - return registry or self["npmRegistryServer"] - def write(self) -> None: """Write the data to the yarnrc file.""" with self._path.path.open("w") as f: diff --git a/tests/unit/package_managers/yarn/test_project.py b/tests/unit/package_managers/yarn/test_project.py index 01146205e..4f6cee16d 100644 --- a/tests/unit/package_managers/yarn/test_project.py +++ b/tests/unit/package_managers/yarn/test_project.py @@ -104,8 +104,7 @@ def test_parse_yarnrc(rooted_tmp_path: RootedPath) -> None: assert yarn_rc["pnpMode"] == "loose" assert yarn_rc["pnpUnpluggedFolder"] == "/some/unplugged/folder" assert yarn_rc["npmRegistryServer"] == "https://registry.alternative.com" - assert yarn_rc.registry_server_for_scope("foobar") == "https://registry.foobar.com" - assert yarn_rc.registry_server_for_scope("barfoo") == "https://registry.alternative.com" + assert yarn_rc["npmScopes"]["foobar"]["npmRegistryServer"] == "https://registry.foobar.com" assert yarn_rc["unsafeHttpWhitelist"] == ["example.org", "foo.bar"] assert yarn_rc["yarnPath"] == ".custom/path/yarn-3.6.1.cjs" assert yarn_rc["virtualFolder"] == "/custom/__virtual__" @@ -131,9 +130,8 @@ def test_parse_empty_yarnrc(rooted_tmp_path: RootedPath) -> None: assert yarn_rc["pnpDataPath"] is None assert yarn_rc["pnpMode"] is None assert yarn_rc["pnpUnpluggedFolder"] is None - assert yarn_rc["npmRegistryServer"] == "https://registry.yarnpkg.com" - assert yarn_rc.registry_server_for_scope("foobar") == "https://registry.yarnpkg.com" - assert yarn_rc["unsafeHttpWhitelist"] == [] + assert yarn_rc["npmRegistryServer"] is None + assert yarn_rc["unsafeHttpWhitelist"] is None assert yarn_rc["yarnPath"] is None assert yarn_rc["virtualFolder"] is None