From ed6021ad3e3eed9b939c3da8cd568e2d88833c83 Mon Sep 17 00:00:00 2001 From: Blue Falcon Date: Fri, 19 Jan 2024 00:58:44 -0700 Subject: [PATCH] feat: :sparkles: introduce the skipdependencies switch --- Import-Package/Import-Package.psd1 | 4 ++-- Import-Package/Import-Package.psm1 | 22 ++++++++++++++++------ Import-Package/README.md | 5 +++++ Import-Package/src/Build-PackageData.ps1 | 1 + Test.ps1 | 4 ++++ 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Import-Package/Import-Package.psd1 b/Import-Package/Import-Package.psd1 index 30f70c3..df42ac1 100644 --- a/Import-Package/Import-Package.psd1 +++ b/Import-Package/Import-Package.psd1 @@ -12,7 +12,7 @@ RootModule = '.\Import-Package.psm1' # Version number of this module. -ModuleVersion = '0.6.0' +ModuleVersion = '0.6.1' # Supported PSEditions # CompatiblePSEditions = @() @@ -30,7 +30,7 @@ CompanyName = 'github.com/pwsh-cs-tools' Copyright = '(c) anonhostpi. All rights reserved.' # Description of the functionality provided by this module -Description = 'Adds ability to import NuGet/Nupkg packages downloaded by PackageManagement' +Description = 'Adds ability to import NuGet and C# .nupkg packages downloaded by PackageManagement' # Minimum version of the PowerShell engine required by this module # PowerShellVersion = '' diff --git a/Import-Package/Import-Package.psm1 b/Import-Package/Import-Package.psm1 index 63a86fc..57ade77 100644 --- a/Import-Package/Import-Package.psm1 +++ b/Import-Package/Import-Package.psm1 @@ -103,6 +103,9 @@ function Get-Runtime { .Parameter Offline Skip downloading the package from the package provider. + + .Parameter SkipDependencies + Skip automatic dependency handling. .Parameter CachePath The directory to place and load packages not provided by PackageManagement. These can be SemVer2 packages or packages provided with -Path @@ -162,6 +165,7 @@ function Import-Package { [Alias("PackagePath","Source")] [string] $Path, + [switch] $SkipDependencies, [switch] $Offline, [string] $CachePath = "$PSScriptRoot\Packages", [string] $NativePath @@ -176,6 +180,9 @@ function Import-Package { Build-PackageData -From "Object" -Options @( $Package, @{ "CachePath" = $CachePath "NativePath" = $NativePath + + "Offline" = $Offline + "SkipDependencies" = $SkipDependencies }) -Bootstrapper $bootstrapper } "Managed" { @@ -186,6 +193,7 @@ function Import-Package { "NativePath" = $NativePath "Offline" = $Offline # If true, do not install + "SkipDependencies" = $SkipDependencies "Name" = $Name "Version" = $Version @@ -199,6 +207,8 @@ function Import-Package { "NativePath" = $NativePath "Source" = $Path + + "SkipDependencies" = $true } -Bootstrapper $bootstrapper } } @@ -288,7 +298,7 @@ function Import-Package { Write-Verbose "[Import-Package:Framework-Handling] Selected OS-agnostic framework $TargetFramework" Write-Verbose "[Import-Package:Framework-Handling] Selected OS-specific framework $target_rid_framework" - If( $PackageData.Dependencies -and -not $PackageData.Unmanaged ){ + If( $PackageData.Dependencies -and -not $PackageData.SkipDependencies ){ Write-Verbose "[Import-Package:Dependency-Handling] Loading dependencies for $( $PackageData.Name )" If( $PackageData.Dependencies.Agnostic ){ $package_framework = $TargetFramework @@ -331,7 +341,7 @@ function Import-Package { } } } Elseif( $PackageData.Dependencies.Count ) { - Write-Warning "[Import-Package:Dependency-Handling] $($PackageData.Name) has $($PackageData.Dependencies.Count) dependencies, but has been marked for unmanaged loading. Make sure to load the dependencies manually" + Write-Warning "[Import-Package:Dependency-Handling] $($PackageData.Name) has $($PackageData.Dependencies.Count) dependencies, but either -Path or -SkipDependencies was used. Make sure to load the dependencies manually" } $dlls = @{ @@ -415,9 +425,9 @@ function Import-Package { Import-Module $_ -ErrorAction Stop } Catch { Write-Error "[Import-Package:Loading] Unable to load 'lib' dll ($($dll | Split-Path -Leaf)) for $($PackageData.Name)`n$($_.Exception.Message)`n" - If( $PackageData.Unmanaged ){ + If( $PackageData.SkipDependencies ){ Write-Host - Write-Host "[Import-Package:Loading] Package $($PackageData.Name) is marked for Unmanaged loading, which requires dependencies to be imported manually." + Write-Host "[Import-Package:Loading] Package $($PackageData.Name) is marked for manual dependency loading (either -Path or -SkipDependencies were used)." Write-Host "- Did you forget a dependency?" -ForegroundColor Yellow } $_.Exception.GetBaseException().LoaderExceptions | ForEach-Object { Write-Host $_.Message } @@ -439,9 +449,9 @@ function Import-Package { } } Catch { Write-Error "[Import-Package:Loading] Unable to load 'runtime' dll ($($dll | Split-Path -Leaf)) for $($PackageData.Name) for $($bootstrapper.runtime)`n$($_.Exception.Message)`n" - If( $PackageData.Unmanaged ){ + If( $PackageData.SkipDependencies ){ Write-Host - Write-Host "[Import-Package:Loading] Package $($PackageData.Name) is marked for Unmanaged loading, which requires dependencies to be imported manually." + Write-Host "[Import-Package:Loading] Package $($PackageData.Name) is marked for manual dependency loading (either -Path or -SkipDependencies were used)." Write-Host "- Did you forget a dependency?" -ForegroundColor Yellow } return diff --git a/Import-Package/README.md b/Import-Package/README.md index 2306650..ce4b5aa 100644 --- a/Import-Package/README.md +++ b/Import-Package/README.md @@ -47,6 +47,11 @@ Import-Package ` - The target framework of the package to import. - Default: TFM of the current PowerShell session. +- Offline + - Skip downloading the package from the package provider. +- SkipDependencies + - Skip automatic dependency handling. + - CachePath: - The directory to place and load packages not provided by PackageManagement. These can be SemVer2 packages or packages provided with -Path - NativePath: diff --git a/Import-Package/src/Build-PackageData.ps1 b/Import-Package/src/Build-PackageData.ps1 index 6e86b0a..da513e0 100644 --- a/Import-Package/src/Build-PackageData.ps1 +++ b/Import-Package/src/Build-PackageData.ps1 @@ -18,6 +18,7 @@ function Build-PackageData { "CachePath" = "Undefined" "NativePath" = "Undefined" "Offline" = $false + "SkipDependencies" = $false "Stable" = $true "Unmanaged" = $false "Installed" = $false diff --git a/Test.ps1 b/Test.ps1 index 5cf5ecd..b374f5a 100644 --- a/Test.ps1 +++ b/Test.ps1 @@ -71,6 +71,10 @@ If( $ImportPackage ){ Write-Host "[Import-Package:Testing] Testing the Unmanaged Parameterset with a complex package is complete. Continue Testing?" pause; + Measure-Command { Import-Package NLua -SkipDependencies } + Write-Host "[Import-Package:Testing] Testing the -SkipDependencies switch is complete. Continue Testing?" + pause; + Measure-Command { Import-Package IronRuby.Libraries } Write-Host "[Import-Package:Testing] Testing the Semver2 packages (and the package cache) is complete. Continue Testing?" pause;