class PoiseJavascript::Resources::NpmInstall::Provider

The default provider for `npm_install`.

@see Resource @provides npm_install

Public Instance Methods

action_install() click to toggle source

The `install` action for the `npm_install` resource.

@return [void]

# File lib/poise_javascript/resources/npm_install.rb, line 78
def action_install
  cmd = [new_resource.npm_binary, 'install']
  cmd << '--production' if new_resource.production
  # Set --unsafe-perm unless the property is nil.
  unless new_resource.unsafe_perm.nil?
    cmd << '--unsafe-perm'
    cmd << new_resource.unsafe_perm.to_s
  end
  # Add the directory for the node binary to $PATH for post-install stuffs.
  new_path = [::File.dirname(new_resource.javascript), ENV['PATH'].to_s].join(::File::PATH_SEPARATOR)
  output = javascript_shell_out!(cmd, cwd: new_resource.path, user: new_resource.user, group: new_resource.group, environment: {'PATH' => new_path}, timeout: new_resource.timeout).stdout
  unless output.strip.empty?
    # Any output means it did something.
    new_resource.updated_by_last_action(true)
  end
end