Private/Get-NSPConditionalAccessStateRoot.ps1

function Get-NSPConditionalAccessStateRoot {
    <#
    .SYNOPSIS
        The folder that holds local state when no -ConfigRoot is given.
    .DESCRIPTION
        In order: $env:NSP_CONDITIONALACCESS_ROOT; the module folder when it is a Git checkout
        (state stays in the ignored Config\Local and .nsp-conditionalaccess folders there);
        otherwise %LOCALAPPDATA%\NSP\ConditionalAccess, so an installed copy never writes into its
        versioned module folder (read-only under Program Files, synced when Documents is in
        OneDrive, and left behind on upgrade).
    #>

    [CmdletBinding()]
    [OutputType([string])]
    param()

    if ($env:NSP_CONDITIONALACCESS_ROOT) { return $env:NSP_CONDITIONALACCESS_ROOT }
    if (Test-Path -LiteralPath (Join-Path $script:ModuleRoot '.git')) { return $script:ModuleRoot }
    $base = if ($env:LOCALAPPDATA) { $env:LOCALAPPDATA } else { [Environment]::GetFolderPath('LocalApplicationData') }
    Join-Path $base 'NSP\ConditionalAccess'
}