Skip to content

Commit

Permalink
yarn-v1: Don't return chain object as return value for resolved packages
Browse files Browse the repository at this point in the history
The result of the function `resolve_packages` is a chain object that
behaves similarly as iterator, therefore can only be iterated over once.
The packages variables must preserve for
`verify_offline_mirror_collision` and later for creating SBOM
components.

Signed-off-by: Michal Šoltis <[email protected]>
  • Loading branch information
slimreaper35 committed Dec 17, 2024
1 parent 3319797 commit 5d0c8cd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cachi2/core/package_managers/yarn_classic/resolver.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import re
from abc import ABC, abstractmethod
from dataclasses import dataclass
from itertools import chain
from pathlib import Path
from typing import Iterable, Optional, Union
from typing import Optional, Union
from urllib.parse import urlparse

from packageurl import PackageURL
Expand Down Expand Up @@ -338,14 +337,15 @@ def _get_workspace_packages(
]


def resolve_packages(project: Project) -> Iterable[YarnClassicPackage]:
def resolve_packages(project: Project) -> list[YarnClassicPackage]:
"""Return a list of Packages corresponding to all project dependencies."""
workspaces = extract_workspace_metadata(project.source_dir)
yarn_lock = YarnLock.from_file(project.source_dir.join_within_root("yarn.lock"))
runtime_deps = find_runtime_deps(project.package_json, yarn_lock, workspaces)

return chain(
[_get_main_package(project.source_dir, project.package_json)],
_get_workspace_packages(project.source_dir, workspaces),
_get_packages_from_lockfile(project.source_dir, yarn_lock, runtime_deps),
)
result: list[YarnClassicPackage] = []

result.append(_get_main_package(project.source_dir, project.package_json))
result.extend(_get_workspace_packages(project.source_dir, workspaces))
result.extend(_get_packages_from_lockfile(project.source_dir, yarn_lock, runtime_deps))
return result

0 comments on commit 5d0c8cd

Please sign in to comment.