Class: Homebrew::Bundle::Npm Private

Inherits:
Extension show all
Defined in:
bundle/extensions/npm.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Methods inherited from Extension

add_supported?, check, cleanup!, cleanup_disable_description, cleanup_disable_env, cleanup_item_name, cleanup_items, cleanup_supported?, disable_predicate_method, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_name, dump_output, dump_supported?, dump_with, entry, #failure_reason, fetchable_name, flag, inherited, install!, install_supported?, install_verb, #installed_and_up_to_date?, legacy_check_step, package_description, package_installed?, package_manager_env, package_manager_executable!, package_manager_installed?, package_record, predicate_method, preinstall!, quote, remove_supported?, switch_description, with_package_manager_env

Methods inherited from PackageType

check, #checkable_entries, dump, dump_output, dump_supported?, #exit_early_check, #failure_reason, fetchable_name, #find_actionable, #format_checkable, #full_check, inherited, install!, install_supported?, install_verb, #installed_and_up_to_date?, preinstall!

Class Method Details

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



18
# File 'bundle/extensions/npm.rb', line 18

def banner_name = "npm packages"

.check_labelString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



15
# File 'bundle/extensions/npm.rb', line 15

def check_label = "npm Package"

.cleanup_headingString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



27
28
29
# File 'bundle/extensions/npm.rb', line 27

def cleanup_heading
  banner_name
end

.install_package!(name, with: nil, verbose: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'bundle/extensions/npm.rb', line 64

def install_package!(name, with: nil, verbose: false)
  _ = with

  npm = package_manager_executable!

  Bundle.system(npm.to_s, "install", *Language::Node.npm_install_security_args, "-g", name, verbose:)
end

.installed_packagesArray<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



73
74
75
76
77
78
# File 'bundle/extensions/npm.rb', line 73

def installed_packages
  installed_packages = @installed_packages
  return installed_packages if installed_packages

  @installed_packages = packages.dup
end

.package_manager_executablePathname?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



37
38
39
# File 'bundle/extensions/npm.rb', line 37

def package_manager_executable
  which("npm", ORIGINAL_PATHS)
end

.package_manager_nameString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



32
33
34
# File 'bundle/extensions/npm.rb', line 32

def package_manager_name
  "node"
end

.packagesArray<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'bundle/extensions/npm.rb', line 42

def packages
  packages = @packages
  return packages if packages

  @packages = if (npm = package_manager_executable) &&
                 (!npm.to_s.start_with?("/") || npm.exist?)
    with_env(package_manager_env(npm)) do
      parse_package_list(`#{npm} list -g --depth=0 --json 2>/dev/null`)
    end
  end
  return [] if @packages.nil?

  @packages
end

.parse_package_list(output) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



86
87
88
89
90
91
92
93
94
# File 'bundle/extensions/npm.rb', line 86

def parse_package_list(output)
  return [] if output.blank?

  json = JSON.parse(output)
  deps = json.fetch("dependencies", {})
  deps.keys.reject { |name| name == "npm" }
rescue JSON::ParserError
  []
end

.reset!void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



21
22
23
24
# File 'bundle/extensions/npm.rb', line 21

def reset!
  @packages = T.let(nil, T.nilable(T::Array[String]))
  @installed_packages = T.let(nil, T.nilable(T::Array[String]))
end

.typeSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



12
# File 'bundle/extensions/npm.rb', line 12

def type = :npm

.uninstall_package!(name, executable: Pathname.new("")) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



81
82
83
# File 'bundle/extensions/npm.rb', line 81

def uninstall_package!(name, executable: Pathname.new(""))
  Bundle.system(executable.to_s, "uninstall", "-g", name, verbose: false)
end