5 # Copyright:: 2013, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
24 default_action :install
26 property :package, :kind_of => String, :name_property => true
27 property :version, :kind_of => String
30 qualified_name = if new_resource.version
31 "#{new_resource.package}@#{new_resource.version}"
36 if current_version.nil?
37 converge_by "install #{qualified_name}" do
38 shell_out!("npm install --global #{qualified_name}")
40 elsif new_resource.version &&
41 new_resource.version != current_version
42 converge_by "update #{qualified_name}" do
43 shell_out!("npm install --global #{qualified_name}")
49 unless current_version.nil?
50 converge_by "update #{new_resource.package}" do
51 shell_out!("npm update --global #{new_resource.package}")
57 unless current_version.nil?
58 converge_by "remove #{new_resource.package}" do
59 shell_out!("npm remove --global #{new_resource.package}")
66 @current_version ||= JSON.parse(shell_out("npm list --global --json").stdout)
67 .dig("dependencies", new_resource.package, "version")