From fa832e18535c9a58207da8a6d3fe82a54c63e263 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sat, 24 Jan 2026 21:20:52 -0500 Subject: [PATCH] Update src/core.ps1 --- src/core.ps1 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/core.ps1 b/src/core.ps1 index 8c69a5a..51ad763 100644 --- a/src/core.ps1 +++ b/src/core.ps1 @@ -1,3 +1,57 @@ +# --- core.ps1: ensure functions are available without double-loading --- + +function Ensure-SamyFunctionsLoaded { + [CmdletBinding()] + param() + + # Pick a "canary" function that DEFINITELY lives in samy.functions.ps1 + # Replace this with a function name you know is in samy.functions.ps1. + $canary = 'Initialize-NuGetProvider' + + if (Get-Command $canary -ErrorAction SilentlyContinue) { + # Functions already loaded by bootstrap (or previously in session) + return + } + + # If SamyFunctionsUrl isn't set, build it from known bases + if ([string]::IsNullOrWhiteSpace($Script:SamyFunctionsUrl)) { + + if (-not [string]::IsNullOrWhiteSpace($Script:ChunkBase)) { + # Bootstrap path (matches your chunk downloader) + $Script:SamyFunctionsUrl = "$Script:ChunkBase/samy.functions.ps1?raw=1" + } + elseif (-not [string]::IsNullOrWhiteSpace($Script:SamyGitRepo)) { + # Repo base (your config usually sets this) + $Script:SamyFunctionsUrl = "$Script:SamyGitRepo/src/samy.functions.ps1?raw=1" + } + elseif ( + -not [string]::IsNullOrWhiteSpace($Script:SamyGitURL) -and + -not [string]::IsNullOrWhiteSpace($Script:SamyGitBranch) + ) { + # Last-resort rebuild + $Script:SamyGitRepo = "$Script:SamyGitURL/$Script:SamyGitBranch" + $Script:SamyFunctionsUrl = "$Script:SamyGitRepo/src/samy.functions.ps1?raw=1" + } + else { + throw "SamyFunctionsUrl is empty and no base URL variables are set (ChunkBase/SamyGitRepo/SamyGitURL+SamyGitBranch). Cannot load samy.functions.ps1." + } + } + + Write-Host "[Info] Loading functions from: $Script:SamyFunctionsUrl" -ForegroundColor Cyan + + try { + $functionsContent = (Invoke-WebRequest -UseBasicParsing -Uri $Script:SamyFunctionsUrl -ErrorAction Stop).Content + . ([ScriptBlock]::Create($functionsContent)) + } + catch { + throw "Failed to load samy.functions.ps1 from $Script:SamyFunctionsUrl. $($_.Exception.Message)" + } + + if (-not (Get-Command $canary -ErrorAction SilentlyContinue)) { + throw "Loaded samy.functions.ps1 but '$canary' still wasn't found. The file content may not be what we expect." + } +} + function Invoke-ScriptAutomationMonkey { [CmdletBinding(