Skip to content

Commit

Permalink
yarn: 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 <[email protected]>
  • Loading branch information
brunoapimentel committed Jan 9, 2025
1 parent 6e3e77f commit 87638b4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 16 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 @@ -43,9 +43,7 @@ class YarnRc(UserDict):
_defaults = {
"cacheFolder": "./.yarn/cache",
"lockfileFilename": "yarn.lock",
"unsafeHttpWhitelist": [],
"plugins": [],
"npmRegistryServer": "https://registry.yarnpkg.com",
}

def __init__(self, path: RootedPath, data: dict[str, Any]) -> None:
Expand All @@ -57,17 +55,6 @@ def __init__(self, path: RootedPath, data: dict[str, Any]) -> None:
self._path = path
super().__init__(self._defaults | data)

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
1 change: 0 additions & 1 deletion tests/unit/package_managers/yarn/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ def test_set_yarnrc_configuration(
"globalFolder": "/tmp/output/deps/yarn",
"ignorePath": True,
"lockfileFilename": "yarn.lock",
"npmRegistryServer": "https://registry.yarnpkg.com",
"unsafeHttpWhitelist": [],
"pnpMode": "strict",
"plugins": expected_plugins,
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/package_managers/yarn/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ def test_write_yarnrc(rooted_tmp_path: RootedPath) -> None:
"""
cacheFolder: .cache/folder
lockfileFilename: yarn.lock
npmRegistryServer: https://registry.yarnpkg.com
plugins:
path: .path/to/plugin
spec: '@yarnpkg/nice-plugin'
unsafeHttpWhitelist: []
"""
).lstrip()

Expand Down

0 comments on commit 87638b4

Please sign in to comment.