Class: PackageJson::Managers::NpmLike

Inherits:
Base
  • Object
show all
Defined in:
lib/package_json/managers/npm_like.rb

Instance Attribute Summary

Attributes inherited from Base

#binary

Instance Method Summary collapse

Methods inherited from Base

#add!, #install!, #remove!, #run!, #version

Constructor Details

#initialize(package_json) ⇒ NpmLike

Returns a new instance of NpmLike.



4
5
6
# File 'lib/package_json/managers/npm_like.rb', line 4

def initialize(package_json)
  super(package_json, binary_name: "npm")
end

Instance Method Details

#add(packages, type: :production, exact: false) ⇒ Object

Adds the given packages



25
26
27
28
# File 'lib/package_json/managers/npm_like.rb', line 25

def add(packages, type: :production, exact: false)
  flags = [package_type_install_flag(type), exact_flag(exact)].compact
  raw("install", flags + packages)
end

#install(frozen: false) ⇒ Object

Installs the dependencies specified in the ‘package.json` file



9
10
11
12
13
14
# File 'lib/package_json/managers/npm_like.rb', line 9

def install(frozen: false)
  cmd = "install"
  cmd = "ci" if frozen

  raw(cmd, [])
end

#native_exec_command(script_name, args = []) ⇒ Object



53
54
55
56
57
58
# File 'lib/package_json/managers/npm_like.rb', line 53

def native_exec_command(
  script_name,
  args = []
)
  build_full_cmd("exec", ["--no", "--offline"] + build_run_args(script_name, args, silent: false))
end

#native_install_command(frozen: false) ⇒ Object

Provides the “native” command for installing dependencies with this package manager for embedding into scripts



17
18
19
20
21
22
# File 'lib/package_json/managers/npm_like.rb', line 17

def native_install_command(frozen: false)
  cmd = "install"
  cmd = "ci" if frozen

  build_full_cmd(cmd, [])
end

#native_run_command(script_name, args = [], silent: false) ⇒ Object

Provides the “native” command for running the script with args for embedding into shell scripts



45
46
47
48
49
50
51
# File 'lib/package_json/managers/npm_like.rb', line 45

def native_run_command(
  script_name,
  args = [],
  silent: false
)
  build_full_cmd("run", build_run_args(script_name, args, silent: silent))
end

#remove(packages) ⇒ Object

Removes the given packages



31
32
33
# File 'lib/package_json/managers/npm_like.rb', line 31

def remove(packages)
  raw("remove", packages)
end

#run(script_name, args = [], silent: false) ⇒ Object

Runs the script assuming it is defined in the ‘package.json` file



36
37
38
39
40
41
42
# File 'lib/package_json/managers/npm_like.rb', line 36

def run(
  script_name,
  args = [],
  silent: false
)
  raw("run", build_run_args(script_name, args, silent: silent))
end