Skip to content

Commit

Permalink
package_managers: yarn: project: Add RC property for 'enableGlobalCache'
Browse files Browse the repository at this point in the history
We shouldn't need to mirror fetched dependencies back to user defined
'cacheFolder' from Yarn RC. Mirroring is only required during the
actual container build, but not from dep fetching POV.

This patch adds a new YarnRc property wrapping the global cache setting
and makes our Yarn RC override code default it to True.

Signed-off-by: Erik Skultety <[email protected]>
  • Loading branch information
eskultety committed Nov 30, 2023
1 parent cfa828b commit fbbfa19
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions cachi2/core/package_managers/yarn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def _set_yarnrc_configuration(project: Project, output_dir: RootedPath) -> None:
yarn_rc.unsafe_http_whitelist = []
yarn_rc.enable_mirror = True
yarn_rc.enable_scripts = False
yarn_rc.enable_global_cache = True
yarn_rc.global_folder = str(output_dir.join_within_root("deps", "yarn"))

yarn_rc.write()
Expand Down
9 changes: 9 additions & 0 deletions cachi2/core/package_managers/yarn/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def yarn_path(self) -> Optional[str]:
"""Path to the yarn script present in this directory."""
return self._data.get("yarnPath")

@property
def enable_global_cache(self) -> Optional[bool]:
"""Get the enableGlobalCache configuration."""
return self._data.get("enableGlobalCache", None)

@enable_global_cache.setter
def enable_global_cache(self, enable_global_cache: Optional[bool]) -> None:
self._data["enableGlobalCache"] = enable_global_cache

def registry_server_for_scope(self, scope: str) -> str:
"""Get the configured registry server for a scoped package.
Expand Down
1 change: 1 addition & 0 deletions tests/unit/package_managers/yarn/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def test_set_yarnrc_configuration(mock_write: mock.Mock) -> None:

expected_data = {
"checksumBehavior": "throw",
"enableGlobalCache": True,
"enableImmutableInstalls": True,
"enableMirror": True,
"enableScripts": False,
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/package_managers/yarn/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
VALID_YARNRC_FILE = """
cacheFolder: ./.custom/cache
checksumBehavior: ignore
enableGlobalCache: true
enableImmutableCache: true
enableImmutableInstalls: true
enableInlineBuilds: true
Expand Down Expand Up @@ -82,6 +83,7 @@ def test_parse_yarnrc(rooted_tmp_path: RootedPath) -> None:

assert yarn_rc.cache_folder == "./.custom/cache"
assert yarn_rc.checksum_behavior == "ignore"
assert yarn_rc.enable_global_cache is True
assert yarn_rc.enable_immutable_cache is True
assert yarn_rc.enable_immutable_installs is True
assert yarn_rc.enable_mirror is False
Expand All @@ -104,6 +106,7 @@ def test_parse_empty_yarnrc(rooted_tmp_path: RootedPath) -> None:

assert yarn_rc.cache_folder == "./.yarn/cache"
assert yarn_rc.checksum_behavior is None
assert yarn_rc.enable_global_cache is None
assert yarn_rc.enable_immutable_cache is None
assert yarn_rc.enable_immutable_installs is None
assert yarn_rc.enable_mirror is None
Expand Down

0 comments on commit fbbfa19

Please sign in to comment.