Skip to content
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

fix(manifest): Load yml module only if using yml manifest #206

Merged
merged 4 commits into from
Sep 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
}
}

Join-Path $PSScriptRoot '..\supporting\yaml\bin\powershell-yaml.psd1' | Import-Module -Prefix 'CloudBase' -Verbose:$false

$ALLOWED_MANIFEST_EXTENSION = @('json', 'yaml', 'yml')
$ALLOWED_MANIFEST_EXTENSION_REGEX = $ALLOWED_MANIFEST_EXTENSION -join '|'

Expand Down Expand Up @@ -42,6 +40,10 @@ function ConvertFrom-Manifest {
$result = ConvertFrom-Json -InputObject $content -ErrorAction 'Stop'
}
{ $_ -in '.yaml', '.yml' } {
if (!(Get-Module -Name 'powershell-yaml')) {
Join-Path $PSScriptRoot '..\supporting\yaml\bin\powershell-yaml.psd1' | Import-Module -Prefix 'CloudBase' -Verbose:$false
}

# Ugly hotfix to prevent ordering of properties and PSCustomObject
$result = ConvertFrom-CloudBaseYaml -Yaml $content -Ordered | ConvertTo-Json -Depth 100 | ConvertFrom-Json
}
Expand Down Expand Up @@ -89,6 +91,10 @@ function ConvertTo-Manifest {
$content = $content -replace "`t", (' ' * 4)
}
{ $_ -in 'yaml', 'yml' } {
if (!(Get-Module -Name 'powershell-yaml')) {
Join-Path $PSScriptRoot '..\supporting\yaml\bin\powershell-yaml.psd1' | Import-Module -Prefix 'CloudBase' -Verbose:$false
}

$content = ConvertTo-CloudBaseYaml -Data $Manifest
$content = $content.TrimEnd("`r`n") # For some reason it produces two line endings at the end
}
Expand Down Expand Up @@ -533,7 +539,7 @@ function installed_manifest($app, $version, $global) {

# Different extension types
if (!(Test-Path $manifestPath)) {
$installedManifests = Get-ChildItem -LiteralPath $d -Include 'scoop-manifest.*'
$installedManifests = Get-ChildItem -LiteralPath $d -Include 'scoop-manifest.*' -ErrorAction 'SilentlyContinue'
if ($installedManifests.Count -gt 0) {
$manifestPath = $installedManifests[0].FullName
}
Expand Down