Skip to content

Commit 4d8741e

Browse files
Justin GroteJustin Grote
authored andcommitted
Solve a lot of issues and remove some legacy commented out code
1 parent 28e2bfc commit 4d8741e

1 file changed

Lines changed: 6 additions & 146 deletions

File tree

ModuleFast.ps1

Lines changed: 6 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -544,148 +544,8 @@ function Install-ModuleFastOperation {
544544
$Destination = Join-Path $Destination $Name $Version
545545
Expand-Archive -Path $DownloadPath -DestinationPath $Destination -Force
546546
Write-Host "Installed $Name $Version from $DownloadPath to $Destination"
547-
548-
# region OLDLOGIC
549-
# FIXME: Delete once new logic is in place, this is for reference
550-
# #Do a really crappy guess for the current user modules folder.
551-
# #TODO: "Scope CurrentUser" type logic
552-
# if (-not $Path) {
553-
# if (-not $env:PSModulePath) { throw 'PSModulePath is not defined, therefore the -Path parameter is mandatory' }
554-
# $envSeparator = ';'
555-
# if ($isLinux) { $envSeparator = ':' }
556-
# $Path = ($env:PSModulePath -split $envSeparator)[0]
557-
# }
558-
559-
# if (-not $httpclient) { $SCRIPT:httpClient = [Net.Http.HttpClient]::new() }
560-
# Write-Progress -Id 1 -Activity 'Install-Modulefast' -Status "Creating Download Tasks for $($ModulesToInstall.count) modules"
561-
# $DownloadTasks = foreach ($ModuleItem in $ModulesToInstall) {
562-
# $ModulePackageName = @($ModuleItem.Id, $ModuleItem.Version, 'nupkg') -join '.'
563-
# $ModuleCachePath = [io.path]::Combine(
564-
# [string[]](
565-
# $ModuleCache,
566-
# $ModuleItem.Id,
567-
# $ModuleItem.Version,
568-
# $ModulePackageName
569-
# )
570-
# )
571-
# #TODO: Remove Me
572-
# $ModuleCachePath = "$ModuleCache/$ModulePackageName"
573-
# #$uri = $baseuri + $ModuleName + '/' + $ModuleVersion
574-
# [void][io.directory]::CreateDirectory((Split-Path $ModuleCachePath))
575-
# $ModulePackageTempFile = [io.file]::Create($ModuleCachePath)
576-
# $DownloadTask = $httpclient.GetStreamAsync($ModuleItem.Source)
577-
578-
# #Return a hashtable with the task and file handle which we will need later
579-
# @{
580-
# DownloadTask = $DownloadTask
581-
# FileHandle = $ModulePackageTempFile
582-
# }
583-
# }
584-
585-
# #NOTE: This seems to go much faster when it's not in the same foreach as above, no idea why, seems to be blocking on the call
586-
# $downloadTasks = $DownloadTasks.Foreach{
587-
# $PSItem.CopyTask = $PSItem.DownloadTask.result.CopyToAsync($PSItem.FileHandle)
588-
# return $PSItem
589-
# }
590-
591-
# #TODO: Add timeout via Stopwatch
592-
# [array]$CopyTasks = $DownloadTasks.CopyTask
593-
# while ($false -in $CopyTasks.iscompleted) {
594-
# [int]$remainingTasks = ($CopyTasks | Where-Object iscompleted -EQ $false).count
595-
# $progressParams = @{
596-
# Id = 1
597-
# Activity = 'Install-Modulefast'
598-
# Status = "Downloading $($CopyTasks.count) Modules"
599-
# CurrentOperation = "$remainingTasks Modules Remaining"
600-
# PercentComplete = [int](($CopyTasks.count - $remainingtasks) / $CopyTasks.count * 100)
601-
# }
602-
# Write-Progress @ProgressParams
603-
# Start-Sleep 0.2
604-
# }
605-
606-
# $failedDownloads = $downloadTasks.downloadtask.where{ $PSItem.isfaulted }
607-
# if ($failedDownloads) {
608-
# #TODO: More comprehensive error message
609-
# throw "$($failedDownloads.count) files failed to download. Aborting"
610-
# }
611-
612-
# $failedCopyTasks = $downloadTasks.copytask.where{ $PSItem.isfaulted }
613-
# if ($failedCopyTasks) {
614-
# #TODO: More comprehensive error message
615-
# throw "$($failedCopyTasks.count) files failed to copy. Aborting"
616-
# }
617-
618-
# #Release the files once done downloading. If you don't do this powershell may keep a file locked.
619-
# $DownloadTasks.FileHandle.close()
620-
621-
# #Cleanup
622-
# #TODO: Cleanup should be in a trap or try/catch
623-
# $DownloadTasks.DownloadTask.dispose()
624-
# $DownloadTasks.CopyTask.dispose()
625-
# $DownloadTasks.FileHandle.dispose()
626-
627-
# #Unpack the files
628-
# Write-Progress -Id 1 -Activity 'Install-Modulefast' -Status "Extracting $($modulestoinstall.id.count) Modules"
629-
# $packageConfigPath = Join-Path $ModuleCache 'packages.config'
630-
# if (Test-Path $packageConfigPath) { Remove-Item $packageConfigPath }
631-
# $packageConfig = New-NuGetPackageConfig -modulesToInstall $ModulesToInstall -path $packageConfigPath
632-
633-
# $timer = [diagnostics.stopwatch]::startnew()
634-
# $moduleCount = $modulestoinstall.id.count
635-
# $ipackage = 0
636-
# #Initialize the files in the repository, if relevant
637-
# & nuget.exe init $ModuleCache $ModuleCache | Where-Object { $PSItem -match 'already exists|installing' } | ForEach-Object {
638-
# if ($ipackage -lt $modulecount) { $ipackage++ }
639-
# #Write-Progress has a performance issue if run too frequently
640-
# if ($timer.elapsedmilliseconds -gt 200) {
641-
# $progressParams = @{
642-
# id = 1
643-
# Activity = 'Install-Modulefast'
644-
# Status = "Extracting $modulecount Modules"
645-
# CurrentOperation = "$ipackage of $modulecount Remaining"
646-
# PercentComplete = [int]($ipackage / $modulecount * 100)
647-
# }
648-
# Write-Progress @progressParams
649-
# $timer.restart()
650-
# }
651-
# }
652-
# if ($LASTEXITCODE) { throw 'There was a problem with nuget.exe' }
653-
654-
# #Create symbolic links from the nuget repository to "install" the packages
655-
# foreach ($moduleItem in $modulesToInstall) {
656-
# $moduleRelativePath = [io.path]::Combine($ModuleItem.id, $moduleitem.version)
657-
# #nuget saves as lowercase, matching to avoid Linux case issues
658-
# $moduleNugetPath = (Join-Path $ModuleCache $moduleRelativePath).tolower()
659-
# $moduleTargetPath = Join-Path $Path $moduleRelativePath
660-
661-
# if (-not (Test-Path $moduleNugetPath)) { Write-Error "$moduleNugetPath doesn't exist"; continue }
662-
# if (-not (Test-Path $moduleTargetPath) -and -not $force) {
663-
# $ModuleFolder = (Split-Path $moduleTargetPath)
664-
# #Create the parent target folder (as well as any hierarchy) if it doesn't exist
665-
# [void][io.directory]::createdirectory($ModuleFolder)
666-
667-
# #Create a symlink to the module in the package repository
668-
# if ($PSCmdlet.ShouldProcess($moduleTargetPath, "Install Powershell Module $($ModuleItem.id) $($moduleitem.version)")) {
669-
# $null = New-Item -ItemType SymbolicLink -Path $ModuleFolder -Name $moduleitem.version -Value $moduleNugetPath
670-
# }
671-
# } else {
672-
# Write-Verbose "$moduleTargetPath already exists"
673-
# }
674-
# #Create the parent target folder if it doesn't exist
675-
# #[io.directory]::createdirectory($moduleTargetPath)
676-
# }
677-
# }
678-
#endregion OLDLOGIC
679-
680547
}
681548

682-
683-
#region PlanHelpers
684-
#endregion PlanHelpers
685-
686-
687-
688-
689549
#region Classes
690550

691551
<#
@@ -1194,9 +1054,12 @@ function Add-DestinationToPSModulePath ([string]$Destination, [switch]$NoProfile
11941054
New-Item -ItemType File -Path $Destination -Force
11951055
}
11961056
$ProfileLine = "`$env:PSModulePath += [System.IO.Path]::PathSeparator + $Destination #Added by ModuleFast. If you dont want this, add -NoProfileUpdate to your command."
1197-
#FIXME: Complete this when I get to the Install-Module part
1198-
# if (Get-Content -Raw $Profile) -notmatch
1199-
Add-Content -Path $profile -Value "`$env:PSModulePath += ';$Destination'"
1057+
if ((Get-Content -Raw $myProfile) -notmatch [Regex]::Escape($ProfileLine)) {
1058+
Write-Verbose "Adding $Destination to profile $myProfile"
1059+
Add-Content -Path $myProfile -Value $ProfileLine
1060+
} else {
1061+
Write-Verbose "$Destination PSModulePath addition detected in profile, skipping..."
1062+
}
12001063
} else {
12011064
Write-Warning 'The module repository is not in your PSModulePath. Please add it to use the modules.'
12021065
}
@@ -1323,8 +1186,5 @@ function Limit-ModuleFastSpecs {
13231186
# FIXME: When doing directory match comparison for local modules, need to preserve original folder name. See: Reflection 4.8
13241187
# To fix this we will just use the name out of the module.psd1 when installing
13251188
# FIXME: DBops dependency version issue
1326-
# FIXME: Currently Legacy 1.2.3 will be selected over 1.2.3.1111 due to semver versioning sort order, need additional logic if build is present. This can be implemented in CompareTo based on the build tag.
1327-
# FIXME IN GALLERY: A version not in the latest 100 versions will not be found, we are checking for a NextLink but this needs to be wired up to a page request.
1328-
# TODO: Sort modules before install first by dependency depth and then lexical, so the install order is the same every time and we start with lowest dependencies first so if they fail the upstream module doesn't have to be cleaned up.
13291189

13301190
# Export-ModuleMember -Function Get-ModuleFastPlan

0 commit comments

Comments
 (0)