Skip to content

Replace modules.json with RequiredModules #1457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andyleejordan opened this issue Apr 15, 2021 · 3 comments · Fixed by #1562
Closed

Replace modules.json with RequiredModules #1457

andyleejordan opened this issue Apr 15, 2021 · 3 comments · Fixed by #1562
Labels
Area-Build & Release Issue-Enhancement A feature request (enhancement).

Comments

@andyleejordan
Copy link
Member

This awesome tool RequiredModules is a complete implementation of our partial modules.json PowerShell module dependency specification, and our Invoke-Build task for parsing and installing them:

task RestorePsesModules -After Build {
$submodulePath = (Resolve-Path $PsesSubmodulePath).Path + [IO.Path]::DirectorySeparatorChar
Write-Host "`nRestoring EditorServices modules..."
# Read in the modules.json file as a hashtable so it can be splatted
$moduleInfos = @{}
(Get-Content -Raw $ModulesJsonPath | ConvertFrom-Json).PSObject.Properties | ForEach-Object {
$name = $_.Name
$body = @{
Name = $name
MinimumVersion = $_.Value.MinimumVersion
MaximumVersion = $_.Value.MaximumVersion
AllowPrerelease = $script:IsPreview
Repository = if ($_.Value.Repository) { $_.Value.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
}
if (-not $name)
{
throw "EditorServices module listed without name in '$ModulesJsonPath'"
}
$moduleInfos.Add($name, $body)
}
if ($moduleInfos.Keys.Count -gt 0) {
# `#Requires` doesn't display the version needed in the error message and `using module` doesn't work with InvokeBuild in Windows PowerShell
# so we'll just use Import-Module to check that PowerShellGet 1.6.0 or higher is installed.
# This is needed in order to use the `-AllowPrerelease` parameter
Import-Module -Name PowerShellGet -MinimumVersion 1.6.0 -ErrorAction Stop
}
# Save each module in the modules.json file
foreach ($moduleName in $moduleInfos.Keys)
{
if (Test-Path -Path (Join-Path -Path $submodulePath -ChildPath $moduleName))
{
Write-Host "`tModule '${moduleName}' already detected. Skipping"
continue
}
$moduleInstallDetails = $moduleInfos[$moduleName]
$splatParameters = @{
Name = $moduleName
AllowPrerelease = $moduleInstallDetails.AllowPrerelease
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
}
# Only add Min and Max version if we're doing a stable release.
# This is due to a PSGet issue with AllowPrerelease not installing the latest preview.
if (!$moduleInstallDetails.AllowPrerelease) {
$splatParameters.MinimumVersion = $moduleInstallDetails.MinimumVersion
$splatParameters.MaximumVersion = $moduleInstallDetails.MaximumVersion
}
Write-Host "`tInstalling module: ${moduleName} with arguments $(ConvertTo-Json $splatParameters)"
Save-Module @splatParameters
}
Write-Host "`n"
}

Thanks for the tip @JustinGrote

@andyleejordan andyleejordan added Issue-Enhancement A feature request (enhancement). Area-Build & Release labels Apr 15, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Apr 15, 2021
@andyleejordan andyleejordan removed the Needs: Triage Maintainer attention needed! label Apr 20, 2021
@andyleejordan
Copy link
Member Author

That module hasn't been touched since December 2019, so actually just going to improve our own logic.

@JustinGrote
Copy link
Collaborator

@andschwa PSGetv3 will have a manifest restore feature down the line (probably in a year or so given their current pace) so worth revisiting then.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Aug 25, 2021
@andyleejordan
Copy link
Member Author

Oh yeah, that'll be really cool!

@andyleejordan andyleejordan removed the Needs: Maintainer Attention Maintainer attention needed! label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Build & Release Issue-Enhancement A feature request (enhancement).
Projects
None yet
2 participants