@@ -18,10 +18,10 @@ def initialize
1818 end
1919 end
2020
21- def use! ( pm )
22- @pm = pm . to_sym
21+ def use! ( manager )
22+ @pm = manager . to_sym
2323 raise ( ArgumentError , "Unsupported manager: #{ @pm } " ) unless %i[ npm yarn ] . include? ( @pm )
24- raise ( VueCli ::Rails ::Error , "Not installed: #{ @pm } " ) unless self . try ( :"#{ @pm } ?" )
24+ raise ( VueCli ::Rails ::Error , "Not installed: #{ @pm } " ) unless try ( :"#{ @pm } ?" )
2525 end
2626
2727 def package_manager
@@ -30,15 +30,15 @@ def package_manager
3030
3131 def exec ( command , args = nil , extra = nil , env : { } )
3232 cmd = COMMAND_LINE [ command . to_sym ] || { }
33- if @pm == :yarn && cmd [ :yarn ]
34- cmd = cmd [ :yarn ]
35- elsif @pm == :npm && cmd [ :npm ]
36- cmd = cmd [ :npm ]
37- elsif cmd [ :npx ]
38- cmd = @pm == :yarn ? "yarn exec #{ cmd [ :npx ] } " : "npx #{ cmd [ :npx ] } "
39- else
40- cmd = @pm == :yarn ? "yarn exec #{ command } " : "npx #{ command } "
41- end
33+ cmd = if @pm == :yarn && cmd [ :yarn ]
34+ cmd [ :yarn ]
35+ elsif @pm == :npm && cmd [ :npm ]
36+ cmd [ :npm ]
37+ elsif cmd [ :npx ]
38+ @pm == :yarn ? "yarn exec #{ cmd [ :npx ] } " : "npx #{ cmd [ :npx ] } "
39+ else
40+ @pm == :yarn ? "yarn exec #{ command } " : "npx #{ command } "
41+ end
4242
4343 cmd = "#{ cmd } #{ args } " if args . present?
4444 cmd = "#{ cmd } #{ @pm == :yarn ? '-- ' : '' } #{ extra } " if extra . present?
@@ -53,7 +53,7 @@ def exec(command, args = nil, extra = nil, env: {})
5353 } ,
5454 global_add : {
5555 yarn : 'yarn global add' ,
56- npm : 'npm i -g'
56+ npm : 'npm i -g' ,
5757 } ,
5858 } . freeze
5959
@@ -66,14 +66,14 @@ def method_missing(cmd, *args)
6666 def get_version_of ( bin )
6767 return @versions [ bin ] if @versions . key? ( bin )
6868
69- r = `#{ bin } --version` . strip . presence rescue nil
69+ r = begin
70+ `#{ bin } --version` . strip . presence
71+ rescue StandardError
72+ nil
73+ end
7074 @versions [ bin ] = r && r . start_with? ( 'v' ) ? r [ 1 ..-1 ] : r
7175 @versions [ bin ]
7276 end
73-
74- def version_ge? ( v1 , v2 )
75- Gem ::Version . new ( v1 ) >= Gem ::Version . new ( v2 )
76- end
7777 end
7878 end
7979end
0 commit comments