diff --git a/cachi2/core/package_managers/yarn_classic/workspaces.py b/cachi2/core/package_managers/yarn_classic/workspaces.py index de1b0c6e0..314bcc82c 100644 --- a/cachi2/core/package_managers/yarn_classic/workspaces.py +++ b/cachi2/core/package_managers/yarn_classic/workspaces.py @@ -76,7 +76,14 @@ def _extract_workspaces_globs( package: dict[str, Any], ) -> list[str]: """Extract globs from workspaces entry in package dict.""" + # This could be an Array or an Array nested in an Object. + # Official docs mentioning the former: + # https://classic.yarnpkg.com/lang/en/docs/workspaces/ + # Official blog containing a hint about the latter: + # https://classic.yarnpkg.com/lang/en/docs/workspaces/ workspaces_globs = package.get("workspaces", []) + if isinstance(workspaces_globs, dict): + workspaces_globs = workspaces_globs.get("packages", []) return workspaces_globs diff --git a/tests/unit/package_managers/yarn_classic/test_workspaces.py b/tests/unit/package_managers/yarn_classic/test_workspaces.py index e9aaea70e..778e357c2 100644 --- a/tests/unit/package_managers/yarn_classic/test_workspaces.py +++ b/tests/unit/package_managers/yarn_classic/test_workspaces.py @@ -56,10 +56,26 @@ def test_workspaces_could_be_parsed( assert result == expected_result -def test_extracting_workspace_globs_works_with_globs_deined_in_list() -> None: - package = {"workspaces": ["foo"]} +@pytest.mark.parametrize( + "package, expected", + [ + pytest.param( + {"workspaces": ["foo"]}, + ["foo"], + id="workspaces_defined_in_an_array", + ), + pytest.param( + {"workspaces": {"packages": ["foo"]}}, + ["foo"], + id="workspaces_defined_in_an_array_within_an_object", + ), + ], +) +def test_extracting_workspace_globs_works_for_all_types_of_workspaces( + package: dict, + expected: list, +) -> None: - expected = ["foo"] result = _extract_workspaces_globs(package) assert expected == result