Skip to content

Commit

Permalink
Merge pull request #54 from pwsh-cs-tools/feat-v0.6.1
Browse files Browse the repository at this point in the history
Feat: 0.6.1 - Introduce the -SkipDependencies switch
  • Loading branch information
anonhostpi authored Jan 19, 2024
2 parents e583f45 + ed6021a commit f88fd45
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Import-Package/Import-Package.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = '.\Import-Package.psm1'

# Version number of this module.
ModuleVersion = '0.6.0'
ModuleVersion = '0.6.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -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 = ''
Expand Down
22 changes: 16 additions & 6 deletions Import-Package/Import-Package.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -162,6 +165,7 @@ function Import-Package {
[Alias("PackagePath","Source")]
[string] $Path,

[switch] $SkipDependencies,
[switch] $Offline,
[string] $CachePath = "$PSScriptRoot\Packages",
[string] $NativePath
Expand All @@ -176,6 +180,9 @@ function Import-Package {
Build-PackageData -From "Object" -Options @( $Package, @{
"CachePath" = $CachePath
"NativePath" = $NativePath

"Offline" = $Offline
"SkipDependencies" = $SkipDependencies
}) -Bootstrapper $bootstrapper
}
"Managed" {
Expand All @@ -186,6 +193,7 @@ function Import-Package {
"NativePath" = $NativePath

"Offline" = $Offline # If true, do not install
"SkipDependencies" = $SkipDependencies

"Name" = $Name
"Version" = $Version
Expand All @@ -199,6 +207,8 @@ function Import-Package {
"NativePath" = $NativePath

"Source" = $Path

"SkipDependencies" = $true
} -Bootstrapper $bootstrapper
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = @{
Expand Down Expand Up @@ -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 }
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Import-Package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Import-Package/src/Build-PackageData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function Build-PackageData {
"CachePath" = "Undefined"
"NativePath" = "Undefined"
"Offline" = $false
"SkipDependencies" = $false
"Stable" = $true
"Unmanaged" = $false
"Installed" = $false
Expand Down
4 changes: 4 additions & 0 deletions Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f88fd45

Please sign in to comment.