Skip to content

Commit 91f9e06

Browse files
🩹 [Patch]: Remove other modules before reimporting reqs for processed module (#80)
## Description This pull request includes changes to the `scripts/helpers/Build` directory, focusing on improving the handling of module outputs and dependencies. The most important changes are as follows: Improvements to module output handling: * [`scripts/helpers/Build/Build-PSModuleRootModule.ps1`](diffhunk://#diff-1d337ff39f37506a54fda1c5d0487f1b2c2ef318f216a4d9a56c3e7248b69879R39-R42): Suppressed the 'PSAvoidUsingWriteHost' warning to allow direct console output instead of writing to the pipeline. * [`scripts/helpers/Build/Build-PSModuleRootModule.ps1`](diffhunk://#diff-1d337ff39f37506a54fda1c5d0487f1b2c2ef318f216a4d9a56c3e7248b69879L245-R249): Changed `Show-FileContent` calls to use `Write-Host` for direct console output in the 'Build root module - Result' sections. [[1]](diffhunk://#diff-1d337ff39f37506a54fda1c5d0487f1b2c2ef318f216a4d9a56c3e7248b69879L245-R249) [[2]](diffhunk://#diff-1d337ff39f37506a54fda1c5d0487f1b2c2ef318f216a4d9a56c3e7248b69879L256-R260) Enhancements to module dependency handling: * [`scripts/helpers/Build/Import-PSModule.ps1`](diffhunk://#diff-15f2301e39f56f54fa469db56cc7c487e2df36eb295bb74e8d2325aabcd164c0L31-R34): Added logic to remove required and nested modules of an existing module before re-importing it, ensuring a clean state. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent b3a20a9 commit 91f9e06

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

scripts/helpers/Build/Build-PSModuleRootModule.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function Build-PSModuleRootModule {
3636
'PSReviewUnusedParameter', '', Scope = 'Function',
3737
Justification = 'LogGroup - Scoping affects the variables line of sight.'
3838
)]
39+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
40+
'PSAvoidUsingWriteHost', '', Scope = 'Function',
41+
Justification = 'Want to just write to the console, not the pipeline.'
42+
)]
3943
param(
4044
# Name of the module.
4145
[Parameter(Mandatory)]
@@ -242,7 +246,7 @@ Export-ModuleMember @exports
242246
}
243247

244248
LogGroup 'Build root module - Result - Before format' {
245-
Show-FileContent -Path $rootModuleFile
249+
Write-Host (Show-FileContent -Path $rootModuleFile)
246250
}
247251

248252
LogGroup 'Build root module - Format' {
@@ -253,7 +257,7 @@ Export-ModuleMember @exports
253257
}
254258

255259
LogGroup 'Build root module - Result - After format' {
256-
Show-FileContent -Path $rootModuleFile
260+
Write-Host (Show-FileContent -Path $rootModuleFile)
257261
}
258262

259263
LogGroup 'Build root module - Validate - Import' {

scripts/helpers/Build/Import-PSModule.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
$manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose
2929

3030
Write-Verbose "Manifest file path: [$($manifestFile.FullName)]" -Verbose
31-
Get-Module -Name $ModuleName -ListAvailable | Remove-Module -Force -Verbose:$false
31+
$existingModule = Get-Module -Name $ModuleName -ListAvailable
32+
$existingModule | Remove-Module -Force -Verbose
33+
$existingModule.RequiredModules | ForEach-Object { Remove-Module -Name $_ -Force -Verbose }
34+
$existingModule.NestedModules | ForEach-Object { Remove-Module -Name $_ -Force -Verbose }
3235
# Get-InstalledPSResource | Where-Object Name -EQ $ModuleName | Uninstall-PSResource -SkipDependencyCheck -Verbose:$false
3336
Resolve-PSModuleDependencies -ManifestFilePath $manifestFile
3437
Import-Module -Name $ModuleName -RequiredVersion '999.0.0'

0 commit comments

Comments
 (0)