private/Initialize-WpcDependencies.ps1

function Initialize-WpcDependencies {
    [CmdletBinding()]
    param(
        [string] $JaxRoot
    )

    $resolvedJaxRoot = $null
    if (-not [string]::IsNullOrWhiteSpace($JaxRoot)) {
        $resolvedJaxRoot = [IO.Path]::GetFullPath($JaxRoot)
    } else {
        $jaxModule = Get-Module -Name Jax |
            Sort-Object Version -Descending |
            Select-Object -First 1
        if ($null -eq $jaxModule) {
            $jaxModule = Get-Module -ListAvailable -Name Jax |
                Sort-Object Version -Descending |
                Select-Object -First 1
        }
        if ($null -eq $jaxModule) {
            throw @"
Jax is required by WoodpeckerTools but is not installed.
Install it with:
  Install-PSResource Jax -Scope CurrentUser -Repository PSGallery
"@

        }
        $resolvedJaxRoot = [IO.Path]::GetFullPath($jaxModule.ModuleBase)
    }

    if ($script:WpcDependencyRoot -eq $resolvedJaxRoot -and
        (Get-Command Read-JaxYaml -ErrorAction SilentlyContinue) -and
        (Get-Command Expand-Placeholders -ErrorAction SilentlyContinue)) {
        return
    }

    $coreModulePath = Join-Path $resolvedJaxRoot 'core/Jax.Core.psm1'
    $placeholderModulePath = Join-Path $resolvedJaxRoot 'MustachePlaceholders/MustachePlaceholders.psm1'
    foreach ($requiredPath in @($coreModulePath, $placeholderModulePath)) {
        if (-not (Test-Path -LiteralPath $requiredPath -PathType Leaf)) {
            throw "The Jax installation at '$resolvedJaxRoot' is missing required compiler dependency '$requiredPath'."
        }
    }

    Import-Module $coreModulePath `
        -DisableNameChecking -Verbose:$false -WarningAction SilentlyContinue -ErrorAction Stop
    Import-Module $placeholderModulePath `
        -DisableNameChecking -Verbose:$false -WarningAction SilentlyContinue -ErrorAction Stop

    if (-not (Get-Command ConvertTo-Yaml -ErrorAction SilentlyContinue)) {
        Import-Module powershell-yaml -RequiredVersion 0.4.12 -ErrorAction Stop
    }

    $script:WpcDependencyRoot = $resolvedJaxRoot
}