blob: 953e8299138fb29e9e5d37654ae0265221718481 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# frozen_string_literal: true
module Packages
module Npm
class PackageFinder
delegate :find_by_version, to: :execute
delegate :last, to: :execute
# /!\ CAUTION: don't use last_of_each_version: false with find_by_version. Ordering is not
# guaranteed!
def initialize(package_name, project: nil, namespace: nil, last_of_each_version: true)
@package_name = package_name
@project = project
@namespace = namespace
@last_of_each_version = last_of_each_version
end
def execute
result = base.npm
.with_name(@package_name)
.installable
return result unless @last_of_each_version
if Feature.enabled?(:npm_allow_packages_in_multiple_projects)
Packages::Package.id_in(result.last_of_each_version_ids)
else
result.last_of_each_version
end
end
private
def base
if @project
packages_for_project
elsif @namespace
packages_for_namespace
else
::Packages::Package.none
end
end
def packages_for_project
@project.packages
end
def packages_for_namespace
::Packages::Package.for_projects(@namespace.all_projects)
end
end
end
end
|