11require  'puppet/provider/package' 
2+ require  'json' 
23
34Puppet ::Type . type ( :package ) . provide  :psmodule ,  parent : Puppet ::Provider ::Package  do 
45  confine  operatingsystem : :windows 
@@ -25,12 +26,8 @@ def self.invoke_ps_command(command)
2526
2627  def  self . instances 
2728    result  =  invoke_ps_command  instances_command 
28-     result . each_slice ( 2 ) . collect  do  |mod |
29-       new ( 
30-         name : mod [ 0 ] . strip , 
31-         ensure : mod [ 1 ] . strip . split ( ',' ) , 
32-         provider : 'psmodule' 
33-       ) 
29+     result . each . collect  do  |line |
30+       new ( JSON . parse ( line . strip ,  symbolize_names : true ) ) 
3431    end 
3532  end 
3633
@@ -61,17 +58,20 @@ def self.instances_command
6158    # Get-Package is way faster than Get-InstalledModule 
6259    <<-COMMAND 
6360    Get-Package -AllVersions -ProviderName PowerShellGet -Scope AllUsers -Type Module | 
64-       Group-Object -Property Name | % { 
65-         $_.Name 
66-         ($_.Group).Version -join ',' 
61+     Group-Object -Property Name | % { 
62+       [ordered]@{ 
63+         'name' = $_.Name 
64+         'ensure' = @(($_.Group).Version) 
65+         'provider' = 'psmodule' 
66+       } | ConvertTo-Json -Depth 99 -Compress 
6767    } 
6868    COMMAND 
6969  end 
7070
7171  def  install_command 
7272    command  =  "Install-Module #{ @resource [ :name ] }  
7373    command  << " -RequiredVersion #{ @resource [ :ensure ] }   unless  [ :present ,  :latest ] . include?  @resource [ :ensure ] 
74-     command  << " -Source  #{ @resource [ :source ] }   if  @resource [ :source ] 
74+     command  << " -Repository  #{ @resource [ :source ] }   if  @resource [ :source ] 
7575    command 
7676  end 
7777
@@ -85,7 +85,7 @@ def latest_command
8585
8686  def  update_command 
8787    command  =  "Install-Module #{ @resource [ :name ] }  
88-     command  << " -Source  #{ @resource [ :source ] }   if  @resource [ :source ] 
88+     command  << " -Repository  #{ @resource [ :source ] }   if  @resource [ :source ] 
8989    command 
9090  end 
9191end 
0 commit comments