From 40a8571156712e8b2475f2b8d01a8dec126b175e Mon Sep 17 00:00:00 2001 From: Khoi Ky Date: Mon, 26 Aug 2024 14:09:39 -0700 Subject: [PATCH 1/2] Add ability to install or update a subset of the modules listed in the prism.json file. --- Prism/Functions/Install-PrivateModule.ps1 | 25 ++- Prism/Functions/Invoke-Prism.ps1 | 40 ++-- Prism/Functions/Update-ModuleLock.ps1 | 63 +++++- Tests/install.Tests.ps1 | 160 ++++++++++++- Tests/update.Tests.ps1 | 259 +++++++++++++++++++++- 5 files changed, 501 insertions(+), 46 deletions(-) diff --git a/Prism/Functions/Install-PrivateModule.ps1 b/Prism/Functions/Install-PrivateModule.ps1 index f4f2bdd..487ab99 100644 --- a/Prism/Functions/Install-PrivateModule.ps1 +++ b/Prism/Functions/Install-PrivateModule.ps1 @@ -5,7 +5,10 @@ function Install-PrivateModule [CmdletBinding()] param( [Parameter(Mandatory, ValueFromPipeline)] - [Object] $Configuration + [Object] $Configuration, + + # A subset of the required modules to install or update. + [String[]] $Name ) begin @@ -18,7 +21,7 @@ function Install-PrivateModule process { - if( -not (Test-Path -Path $Configuration.LockPath) ) + if (-not (Test-Path -Path $Configuration.LockPath)) { $Configuration | Update-ModuleLock | Format-Table } @@ -37,14 +40,20 @@ function Install-PrivateModule $privateModulePathWildcard = Join-Path -Path $config.PSModulesPath -ChildPath '*' $locks = Get-Content -Path $Configuration.LockPath | ConvertFrom-Json $locks | Add-Member -Name 'PSModules' -MemberType NoteProperty -Value @() -ErrorAction Ignore - foreach( $module in $locks.PSModules ) + + if ($Name) + { + $locks.PSModules = $locks.PSModules | Where-Object {$_.Name -in $Name} + } + + foreach ($module in $locks.PSModules) { $installedModules = Get-Module -Name $module.name -ListAvailable -ErrorAction Ignore | Where-Object 'Path' -Like $privateModulePathWildcard | Add-Member -Name 'SemVer' -MemberType ScriptProperty -PassThru -Value { $prerelease = $this.PrivateData['PSData']['PreRelease'] - if( $prerelease ) + if ($prerelease) { $prerelease = "-$($prerelease)" } @@ -55,17 +64,17 @@ function Install-PrivateModule Join-Path -Path $Configuration.File.DirectoryName -ChildPath $Configuration.PSModulesDirectoryName $installedModule = $installedModules | Where-Object SemVer -EQ $module.version - if( -not $installedModule ) + if (-not $installedModule) { $sourceUrl = $module.repositorySourceLocation $repoName = $repoByLocation[$sourceUrl] - if( -not $repoName ) + if (-not $repoName) { # Ignore slashes at the end of URLs. $sourceUrl = $sourceUrl.TrimEnd('/') } $repoName = $repoByLocation[$sourceUrl] - if( -not $repoName ) + if (-not $repoName) { $msg = "PowerShell repository at ""$($module.repositorySourceLocation)"" does not exist. Use " + '"Get-PSRepository" to see the current list of repositories, "Register-PSRepository" ' + @@ -74,7 +83,7 @@ function Install-PrivateModule continue } - if( -not (Test-Path -Path $savePath) ) + if (-not (Test-Path -Path $savePath)) { New-Item -Path $savePath -ItemType 'Directory' -Force | Out-Null } diff --git a/Prism/Functions/Invoke-Prism.ps1 b/Prism/Functions/Invoke-Prism.ps1 index d094db2..73fb6f3 100644 --- a/Prism/Functions/Invoke-Prism.ps1 +++ b/Prism/Functions/Invoke-Prism.ps1 @@ -13,14 +13,28 @@ function Invoke-Prism Invoke-Prism 'install' Demonstrates how to call this function to install required PSModules. + + .EXAMPLE + Invoke-Prism 'install' -Name 'Module1', 'Module2' + + Demonstrates how to install a subset of the required PSModules. + + .EXAMPLE + Invoke-Prism 'update' -Name 'Module1', 'Module2' + + Demonstrates how to update a subset of the required PSModules. #> [CmdletBinding()] param( - [Parameter(Mandatory)] + [Parameter(Mandatory, Position=0)] [ValidateSet('install', 'update')] [String] $Command, + # A subset of the required modules to install or update. + [Parameter(Position=1)] + [String[]] $Name, + # The path to a prism.json file or a directory where Prism can find a prism.json file. If path is to a file, # the "FileName" parameter is ignored, if given. # @@ -70,14 +84,14 @@ function Invoke-Prism try { $startIn = '.' - if( $Path ) + if ($Path) { - if( (Test-Path -Path $Path -PathType Leaf) ) + if ((Test-Path -Path $Path -PathType Leaf)) { $FileName = $Path | Split-Path -Leaf $startIn = $Path | Split-Path -Parent } - elseif( (Test-Path -Path $Path -PathType Container) ) + elseif ((Test-Path -Path $Path -PathType Container)) { $startIn = $Path } @@ -90,18 +104,18 @@ function Invoke-Prism $Force = $FileName.StartsWith('.') $prismJsonFiles = Get-ChildItem -Path $startIn -Filter $FileName -Recurse:$Recurse -Force:$Force -ErrorAction Ignore - if( -not $prismJsonFiles ) + if (-not $prismJsonFiles) { $msg = '' $suffix = '' - if( $Recurse ) + if ($Recurse) { $suffix = 's' $msg = ' or any of its sub-directories' } $locationMsg = 'the current directory' - if( $startIn -ne '.' -and $startIn -ne (Get-Location).Path ) + if ($startIn -ne '.' -and $startIn -ne (Get-Location).Path) { $locationMsg = """$($startIn | Resolve-Path -Relative)""" } @@ -111,11 +125,11 @@ function Invoke-Prism return } - foreach( $prismJsonFile in $prismJsonFiles ) + foreach ($prismJsonFile in $prismJsonFiles) { $prismJsonPath = $prismJsonFile.FullName $config = Get-Content -Path $prismJsonPath | ConvertFrom-Json - if( -not $config ) + if (-not $config) { Write-Warning "File ""$($prismJsonPath | Resolve-Path -Relative) is empty." continue @@ -124,7 +138,7 @@ function Invoke-Prism $lockBaseName = [IO.Path]::GetFileNameWithoutExtension($prismJsonPath) $lockExtension = [IO.Path]::GetExtension($prismJsonPath) # Hidden file with no extension, e.g. `.prism` - if( -not $lockBaseName -and $lockExtension ) + if (-not $lockBaseName -and $lockExtension) { $lockBaseName = $lockExtension $lockExtension = '' @@ -173,15 +187,15 @@ function Invoke-Prism $env:PSModulePath = $privateModulePath -join [IO.Path]::PathSeparator Write-Debug -Message "env:PSModulePath $($env:PSModulePath)" - switch( $Command ) + switch ($Command) { 'install' { - $config | Install-PrivateModule + $config | Install-PrivateModule -Name $Name } 'update' { - $config | Update-ModuleLock + $config | Update-ModuleLock -Name $Name } } } diff --git a/Prism/Functions/Update-ModuleLock.ps1 b/Prism/Functions/Update-ModuleLock.ps1 index 80cd116..1660268 100644 --- a/Prism/Functions/Update-ModuleLock.ps1 +++ b/Prism/Functions/Update-ModuleLock.ps1 @@ -4,7 +4,10 @@ function Update-ModuleLock [CmdletBinding()] param( [Parameter(Mandatory, ValueFromPipeline)] - [Object] $Configuration + [Object] $Configuration, + + # A subset of the required modules to install or update. + [String[]] $Name ) begin @@ -19,12 +22,28 @@ function Update-ModuleLock { $modulesNotFound = [Collections.ArrayList]::New() $moduleNames = $Configuration.PSModules | Select-Object -ExpandProperty 'Name' - if( -not $moduleNames ) + if (-not $moduleNames) { Write-Warning "There are no modules listed in ""$($Configuration.Path | Resolve-Path -Relative)""." return } + [Collections.Generic.List[String]]$nameCopy = $Name + foreach ($item in $Name) + { + if ($item -notin $moduleNames) + { + Write-Warning "The given module ""$item"" does not exist in the prism.json file." + $nameCopy.Remove($item) + } + } + + if ($Name -and -not $nameCopy) + { + return + } + $Name = $nameCopy + $numFinds = $moduleNames | Measure-Object | Select-Object -ExpandProperty 'Count' $numFinds = $numFinds + 2 Write-Debug " numSteps $($numFinds)" @@ -48,6 +67,21 @@ function Update-ModuleLock Join-Path -Path $Configuration.File.DirectoryName -ChildPath $Configuration.PSModulesDirectoryName foreach( $pxModule in $Configuration.PSModules ) { + $currentLock = $null + if ($Name) + { + if ($Configuration.LockPath -and (Test-Path -Path $Configuration.LockPath)) + { + $currentLock = Get-Content -Path $Configuration.LockPath | ConvertFrom-Json + } + + # If current module is not in the given list of modules and doesn't already exist in the lock file, skip. + if ($currentLock -and ($pxModule.Name -notin $Name) -and ($pxModule.Name -notin $currentLock.PSModules.Name)) + { + continue + } + } + $optionalParams = @{} # Make sure these members are present and have default values. @@ -56,13 +90,20 @@ function Update-ModuleLock Add-Member -Name 'AllowPrerelease' -MemberType NoteProperty -Value $false -ErrorAction Ignore $versionDesc = 'latest' - if( $pxModule.Version ) + if ($pxModule.Version) { $versionDesc = $optionalParams['Version'] = $pxModule.Version + + # If current module is not in the given list of modules, use it's version from lock file. + if ($Name -and $pxModule.Name -notin $Name) + { + $lockedModule = $currentLock.PSModules | Where-Object {$_.Name -eq $pxModule.Name} + $versionDesc = $optionalParams['Version'] = $lockedModule.Version + } } $allowPrerelease = $false - if( $pxModule.AllowPrerelease -or $pxModule.Version -match '-' ) + if ($pxModule.AllowPrerelease -or $pxModule.Version -match '-') { $allowPrerelease = $optionalParams['AllowPrerelease'] = $true } @@ -72,15 +113,15 @@ function Update-ModuleLock Write-Debug " curStep $($curStep)" $moduleToInstall = $modules | Select-Module -Name $pxModule.Name @optionalParams | Select-Object -First 1 - if( -not $moduleToInstall ) + if (-not $moduleToInstall) { $status = "Find-Module -Name '$($pxModule.Name)' -AllVersions" - if( $allowPrerelease ) + if ($allowPrerelease) { $status = "$($status) -AllowPrerelease" } - if( -not $findModuleCache.ContainsKey($status) ) + if (-not $findModuleCache.ContainsKey($status)) { Write-Progress @activity -Status $status -PercentComplete ($curStep/$numFinds * 100) $findModuleCache[$status] = Find-Module -Name $pxModule.Name ` @@ -95,7 +136,7 @@ function Update-ModuleLock Select-Object -First 1 } - if( -not $moduleToInstall ) + if (-not $moduleToInstall) { [void]$modulesNotFound.Add($pxModule.Name) continue @@ -108,7 +149,7 @@ function Update-ModuleLock } [void]$locks.Add( $pin ) - if( -not (Test-Path -Path $Configuration.LockPath) ) + if (-not (Test-Path -Path $Configuration.LockPath)) { New-Item -Path $Configuration.LockPath ` -ItemType 'File' ` @@ -133,10 +174,10 @@ function Update-ModuleLock } $prismLock | ConvertTo-Json -Depth 2 | Set-Content -Path $Configuration.LockPath -NoNewline - if( $modulesNotFound.Count ) + if ($modulesNotFound.Count) { $suffix = '' - if( $modulesNotFound.Count -gt 1 ) + if ($modulesNotFound.Count -gt 1) { $suffix = 's' } diff --git a/Tests/install.Tests.ps1 b/Tests/install.Tests.ps1 index 83089aa..788d649 100644 --- a/Tests/install.Tests.ps1 +++ b/Tests/install.Tests.ps1 @@ -36,7 +36,7 @@ BeforeAll { ) $path = 'prism.json' - if( $In ) + if ($In) { New-Item -Path $In -ItemType 'Directory' -Force | Out-Null $path = Join-Path -Path $In -ChildPath $path @@ -55,7 +55,7 @@ BeforeAll { ) $path = 'prism.lock.json' - if( $In ) + if ($In) { New-Item -Path $In -ItemType 'Directory' -Force | Out-Null $path = Join-Path -Path $In -ChildPath $path @@ -76,17 +76,17 @@ BeforeAll { ) $savePath = $UsingDirName - if( $In ) + if ($In) { $savePath = Join-Path -Path $In -ChildPath $savePath } # Make sure *only* the modules we requested are installed. $expectedCount = 0 - foreach( $moduleName in $Module.Keys ) + foreach ($moduleName in $Module.Keys) { $modulePath = Join-Path -Path $savePath -ChildPath $moduleName - foreach( $semver in $Module[$moduleName] ) + foreach ($semver in $Module[$moduleName]) { $expectedCount += 1 $version,$prerelease = $semver -split '-' @@ -97,7 +97,7 @@ BeforeAll { Test-ModuleManifest -Path $manifestPath | Add-Member -Name 'SemVer' -MemberType ScriptProperty -Value { $prerelease = $this.PrivateData['PSData']['PreRelease'] - if( $prerelease ) + if ($prerelease) { $prerelease = "-$($prerelease)" } @@ -115,6 +115,34 @@ BeforeAll { Should -HaveCount $expectedCount } + function ThenNotInstalled + { + param( + [Parameter(Mandatory)] + [String] $Module, + + [String] $In = $script:testRoot, + + [String] $UsingDirName = 'PSModules' + ) + + $savePath = $UsingDirName + if ($In) + { + $savePath = Join-Path -Path $In -ChildPath $savePath + } + + if (Test-Path -Path $savePath) + { + $installed = Get-ChildItem -Path $savePath + $installed | Should -Not -Contain $Module + } + else + { + Test-Path -Path $savePath | Should -BeFalse + } + } + function ThenSucceeded { $Global:Error | Should -BeNullOrEmpty @@ -331,7 +359,6 @@ Describe 'prism install' { ThenInstalled @{ 'NoOp' = '1.0.0' } } - It 'should handle extra forward slash on PSGallery location' { GivenPrismFile @' { @@ -393,4 +420,123 @@ Describe 'prism install' { ThenSucceeded ThenInstalled @{ 'NoOp' = '1.0.0' } } + + It 'should only install the specified modules' { + GivenPrismFile @' +{ + "PSModules": [ + { + "Name": "NoOp", + "Version": "1.*" + }, + { + "Name": "Carbon", + "Version": "2.*" + }, + { + "Name": "Whiskey", + "Version": "0.*" + } + ] +} +'@ + GivenLockFile @" +{ + "PSModules": [ + { + "name": "NoOp", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Carbon", + "version": "2.11.1", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Whiskey", + "version": "0.61.0", + "repositorySourceLocation": "$($script:defaultLocation)" + } + ] +} +"@ + WhenInstalling -WithParameters @{ Name = 'NoOp', 'Carbon' } + ThenInstalled @{ 'NoOp' = '1.0.0' ; 'Carbon' = '2.11.1' } + ThenNotInstalled 'Whiskey' + } + + It 'should accept short hand syntax for array of names when installing modules' { + GivenPrismFile @' +{ + "PSModules": [ + { + "Name": "NoOp", + "Version": "1.*" + }, + { + "Name": "Carbon", + "Version": "2.*" + }, + { + "Name": "Whiskey", + "Version": "0.*" + } + ] +} +'@ + GivenLockFile @" +{ + "PSModules": [ + { + "name": "NoOp", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Carbon", + "version": "2.11.1", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Whiskey", + "version": "0.61.0", + "repositorySourceLocation": "$($script:defaultLocation)" + } + ] +} +"@ + Push-Location $script:testRoot + # Testing shorthand syntax + prism install 'NoOp', 'Carbon' + Pop-Location + ThenInstalled @{ 'NoOp' = '1.0.0' ; 'Carbon' = '2.11.1' } + ThenNotInstalled 'Whiskey' + } + + It 'should do nothing when module specified does not exist in the prism.lock.json file' { + GivenPrismFile @' +{ + "PSModules": [ + { + "Name": "NoOp", + "Version": "1.*" + } + ] +} +'@ + GivenLockFile @" +{ + "PSModules": [ + { + "name": "NoOp", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + } + ] +} +"@ + WhenInstalling -WithParameters @{ Name = 'Carbon'} + ThenNotInstalled 'Carbon' + } } diff --git a/Tests/update.Tests.ps1 b/Tests/update.Tests.ps1 index 8fac480..3c8e7a0 100644 --- a/Tests/update.Tests.ps1 +++ b/Tests/update.Tests.ps1 @@ -21,7 +21,7 @@ BeforeAll { ) $directory = $At | Split-Path -Parent - if( $directory ) + if ($directory) { New-Item -Path $directory -ItemType 'Directory' -Force | Out-Null } @@ -29,6 +29,24 @@ BeforeAll { New-Item -Path $testRoot -ItemType 'File' -Name $At -Value $Contents } + function GivenLockFile + { + param( + [Parameter(Mandatory, Position=0)] + [string] $Contents, + + [String] $At = 'prism.lock.json' + ) + + $directory = $At | Split-Path -Parent + if ($directory) + { + New-Item -Path $directory -ItemType 'Directory' -Force | Out-Null + } + + $Contents | Set-Content -Path $At -NoNewline + } + function ThenLockFileIs { [CmdletBinding()] @@ -45,18 +63,34 @@ BeforeAll { Get-Content -Raw -Path $path | Should -Be ($ExpectedConfiguration | ConvertTo-Json) } + function ThenLockFileDoesntExist + { + param( + [String] $In = $script:testRoot + ) + $path = Join-Path -Path $In -ChildPath 'prism.lock.json' + Test-Path -Path $path | Should -BeFalse + } + function WhenLocking { [CmdletBinding()] param( - [switch] $Recursively + [switch] $Recursively, + + [String[]] $Name ) $optionalParams = @{} - if( $Recursively ) + if ($Recursively) { $optionalParams['Recurse'] = $true } + + if ($Name) + { + $optionalParams['Name'] = $Name + } $result = Invoke-Prism -Command 'update' @optionalParams $result | Out-String | Write-Verbose -Verbose } @@ -230,25 +264,25 @@ Describe 'prism update' { }) } - # This test is only valid if the module being managed only has prerelease versions. When Carbon.Permissions no + # This test is only valid if the module being managed only has prerelease versions. When Carbon.Accounts no # longer has only prerelease versions, the test will become invalid. But its valid now. It 'handles module that only has prerelease version' { GivenPrismFile @' { "PSModules": [ - { "Name": "Carbon.Permissions", "Version": "1.*-*" } + { "Name": "Carbon.Accounts", "Version": "1.*-*" } ] } '@ WhenLocking $expectedModule = - Find-Module -Name 'Carbon.Permissions' -AllVersions -AllowPrerelease | ` + Find-Module -Name 'Carbon.Accounts' -AllVersions -AllowPrerelease | ` Where-Object 'Version' -like '1.*-*' | ` Select-Object -First 1 ThenLockFileIs ([pscustomobject]@{ PSModules = @( [pscustomobject]@{ - name = 'Carbon.Permissions'; + name = 'Carbon.Accounts'; version = $expectedModule.Version; repositorySourceLocation = $script:defaultLocation; } @@ -256,4 +290,215 @@ Describe 'prism update' { }) } + It 'should only update specified modules' { + GivenPrismFile @' +{ + "PSModules": [ + { + "Name": "NoOp", + "Version": "1.*" + }, + { + "Name": "Carbon", + "Version": "1.*" + }, + { + "Name": "Whiskey", + "Version": "0.*" + } + ] +} +'@ + GivenLockFile @" +{ + "PSModules": [ + { + "name": "NoOp", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Carbon", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Whiskey", + "version": "0.14.0", + "repositorySourceLocation": "$($script:defaultLocation)" + } + ] +} +"@ + WhenLocking -Name ('NoOp', 'Carbon', 'Bogus') + # Latest NoOp version 1 should be >= 1.1.0, set at 1.0.0 for testing. This should get updated. + # Latest Carbon version 1 should be 1.9.0, set at 1.0.0 for testing. This should get updated. + # Latest Whiskey version 0 should be >= 0.61.0, set at 0.14.0 for testing. This should remain unchanged. + $expectedCarbonModule = + Find-Module -Name 'Carbon' -AllVersions | Where-Object 'Version' -like '1.*' | Select-Object -First 1 + $carbonV0DefaultLocation = + Get-PSRepository -Name $expectedCarbonModule.Repository | Select-Object -ExpandProperty 'SourceLocation' + ThenLockFileIs ([pscustomobject]@{ + PSModules = @( + [pscustomobject]@{ + name = 'NoOp'; + version = $script:latestNoOpModule.Version; + repositorySourceLocation = $script:defaultLocation; + }, + [pscustomobject]@{ + name = 'Carbon'; + version = $expectedCarbonModule.Version; + repositorySourceLocation = $carbonV0DefaultLocation; + }, + [pscustomobject]@{ + name = 'Whiskey'; + version = '0.14.0'; + repositorySourceLocation = $script:defaultLocation; + } + ) + }) + } + + It 'should ignore modules that are not currently in the lock file when updating a specific set of modules' { + GivenPrismFile @' +{ + "PSModules": [ + { + "Name": "NoOp", + "Version": "1.*" + }, + { + "Name": "Carbon", + "Version": "1.*" + }, + { + "Name": "Whiskey", + "Version": "0.*" + } + ] +} +'@ + GivenLockFile @" +{ + "PSModules": [ + { + "name": "NoOp", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Carbon", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + } + ] +} +"@ + WhenLocking -Name ('NoOp', 'Carbon') + # Latest NoOp version 1 should be >= 1.1.0, set at 1.0.0 for testing. This should get updated. + # Latest Carbon version 1 should be 1.9.0, set at 1.0.0 for testing. This should get updated. + $expectedCarbonModule = + Find-Module -Name 'Carbon' -AllVersions | Where-Object 'Version' -like '1.*' | Select-Object -First 1 + $carbonV0DefaultLocation = + Get-PSRepository -Name $expectedCarbonModule.Repository | Select-Object -ExpandProperty 'SourceLocation' + ThenLockFileIs ([pscustomobject]@{ + PSModules = @( + [pscustomobject]@{ + name = 'NoOp'; + version = $script:latestNoOpModule.Version; + repositorySourceLocation = $script:defaultLocation; + }, + [pscustomobject]@{ + name = 'Carbon'; + version = $expectedCarbonModule.Version; + repositorySourceLocation = $carbonV0DefaultLocation; + } + ) + }) + } + + It 'should accept short hand syntax for array of names when updating modules' { + GivenPrismFile @' +{ + "PSModules": [ + { + "Name": "NoOp", + "Version": "1.*" + }, + { + "Name": "Carbon", + "Version": "1.*" + }, + { + "Name": "Whiskey", + "Version": "0.*" + } + ] +} +'@ + GivenLockFile @" +{ + "PSModules": [ + { + "name": "NoOp", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Carbon", + "version": "1.0.0", + "repositorySourceLocation": "$($script:defaultLocation)" + }, + { + "name": "Whiskey", + "version": "0.14.0", + "repositorySourceLocation": "$($script:defaultLocation)" + } + ] +} +"@ + # Testing shorthand syntax + prism update 'NoOp', 'Carbon' + # Latest NoOp version 1 should be >= 1.1.0, set at 1.0.0 for testing. This should get updated. + # Latest Carbon version 1 should be 1.9.0, set at 1.0.0 for testing. This should get updated. + # Latest Whiskey version 0 should be >= 0.61.0, set at 0.14.0 for testing. This should remain unchanged. + $expectedCarbonModule = + Find-Module -Name 'Carbon' -AllVersions | Where-Object 'Version' -like '1.*' | Select-Object -First 1 + $carbonV0DefaultLocation = + Get-PSRepository -Name $expectedCarbonModule.Repository | Select-Object -ExpandProperty 'SourceLocation' + ThenLockFileIs ([pscustomobject]@{ + PSModules = @( + [pscustomobject]@{ + name = 'NoOp'; + version = $script:latestNoOpModule.Version; + repositorySourceLocation = $script:defaultLocation; + }, + [pscustomobject]@{ + name = 'Carbon'; + version = $expectedCarbonModule.Version; + repositorySourceLocation = $carbonV0DefaultLocation; + }, + [pscustomobject]@{ + name = 'Whiskey'; + version = '0.14.0'; + repositorySourceLocation = $script:defaultLocation; + } + ) + }) + } + + It 'should do nothing when module given does not exist in the prism.json' { + GivenPrismFile @' +{ + "PSModules": [ + { + "Name": "NoOp", + "Version": "1.0.0" + } + ] +} +'@ + WhenLocking -Name ('Whiskey', 'Carbon') + ThenLockFileDoesntExist + } } From 5b21191fea1b13beced660897ccb61814ab517ca Mon Sep 17 00:00:00 2001 From: Khoi Ky Date: Mon, 26 Aug 2024 14:12:11 -0700 Subject: [PATCH 2/2] Update version and changelog. --- CHANGELOG.md | 8 ++++++++ Prism/Prism.psd1 | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b627d24..bbe9642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ # Prism Changelog +## 0.7.0 + +> Released 27 Aug 2024 + +Added the ability to install or update a subset of the modules listed in the prism.json file. Specify the subset of +modules by passing it to the `Name` parameter when invoking prism. + + ## 0.6.1 > Released 29 Jan 2024 diff --git a/Prism/Prism.psd1 b/Prism/Prism.psd1 index ce1d816..dbad3a1 100644 --- a/Prism/Prism.psd1 +++ b/Prism/Prism.psd1 @@ -18,7 +18,7 @@ RootModule = 'Prism.psm1' # Version number of this module. - ModuleVersion = '0.6.1' + ModuleVersion = '0.7.0' # ID used to uniquely identify this module GUID = '5b244346-40c9-4a50-a098-8758c19f7f25'