Skip to content

Commit

Permalink
Yarn Berry: remove unused code
Browse files Browse the repository at this point in the history
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 <bpimente@redhat.com>
  • Loading branch information
brunoapimentel committed Jan 3, 2025
1 parent 5ef2ee1 commit 15cac3c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
13 changes: 0 additions & 13 deletions cachi2/core/package_managers/yarn/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/package_managers/yarn/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
Expand All @@ -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

Expand Down

0 comments on commit 15cac3c

Please sign in to comment.