Skip to content

Commit f8e3b59

Browse files
🩹 [Patch]: Allow more overrides from manifest.psd1 + smarter defaults (#95)
## Description This pull request includes updates to the `Build-PSModuleManifest` function in the `scripts/helpers/Build/Build-PSModuleManifest.ps1` file. The changes aim to improve the handling of manifest properties by preserving existing values when they are present. Key changes include: * **Handling of `RequiredAssemblies`:** - Added logic to preserve existing `RequiredAssemblies` values if they are present, otherwise populate with new values or set to an empty array if none are found. Now also includes `*.dll` files under the `modules` folder of the built module (non recursive). * **Handling of `NestedModules`:** - Added logic to preserve existing `NestedModules` values if they are present, otherwise populate with new values or set to an empty array if none are found. Now also includes *.dll files under the `modules` folder of the built module. Will only look on one level down, not recursively within each subfolder. * **Handling of `ScriptsToProcess`:** - Added logic to preserve existing `ScriptsToProcess` values if they are present, otherwise populate with new values or set to an empty array if none are found. ## 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 9013bab commit f8e3b59

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ During the module manifest build process the following steps are performed:
7979
1. Set the `Description` based on the GitHub repository description. If a value exists in the source manifest file, this value is used.
8080
1. Set various properties in the manifest such as `PowerShellHostName`, `PowerShellHostVersion`, `DotNetFrameworkVersion`, `ClrVersion`, and `ProcessorArchitecture`. There is currently no automation for these properties. If a value exists in the source manifest file, this value is used.
8181
1. Get the list of files in the module source folder and set the `FileList` property in the manifest.
82-
1. Get the list of required assemblies (`*.dll` files) from the `assemblies` folder and set the `RequiredAssemblies` property in the manifest.
83-
1. Get the list of nested modules (`*.psm1` files) from the `modules` folder and set the `NestedModules` property in the manifest.
82+
1. Get the list of required assemblies (`*.dll` files) from the `assemblies` and `modules` (depth = 1) folder and set the `RequiredAssemblies` property in the manifest.
83+
1. Get the list of nested modules (`*.psm1`, `*.ps1` and `*.dll` files one level down) from the `modules` folder and set the `NestedModules` property in the manifest.
8484
1. Get the list of scripts to process (`*.ps1` files) from the `scripts` folders and set the `ScriptsToProcess` property in the manifest. This ensures that the scripts are loaded to the caller session (parent of module session).
8585
1. Get the list of types to process by searching for `*.Types.ps1xml` files in the entire module source folder and set the `TypesToProcess` property in the manifest.
8686
1. Get the list of formats to process by searching for `*.Format.ps1xml` files in the entire module source folder and set the `FormatsToProcess` property in the manifest.
@@ -120,11 +120,11 @@ Linking the description to the module manifest file might show more how this wor
120120
ClrVersion = '' # Get from manifest file, null if not provided.
121121
ProcessorArchitecture = '' # Get from manifest file, null if not provided.
122122
RequiredModules = @() # Get from source files, REQUIRES -Modules <Module-Name> | <Hashtable> -> Need to be installed and loaded on build time. Will be installed in global session state during installtion.
123-
RequiredAssemblies = @() # Get from assemblies\*.dll.
123+
RequiredAssemblies = @() # Get from assemblies\*.dll + modules\*.dll.
124124
ScriptsToProcess = @() # Get from scripts\*.ps1 and classes\*.ps1 ordered by name. These are loaded to the caller session (parent of module session).
125125
TypesToProcess = @() # Get from *.Types.ps1xml anywhere in the source module folder.
126126
FormatsToProcess = @() # Get from *.Format.ps1xml anywhere in the source module folder.
127-
NestedModules = @() # Get from modules\*.psm1.
127+
NestedModules = @() # Get from modules\*.psm1 + modules\*.ps1 + modules\*.dll.
128128
FunctionsToExport = @() # Get from public\*.ps1.
129129
CmdletsToExport = @() # Get from manifest file, @() if not provided.
130130
VariablesToExport = @() # Get from variables\public\*.ps1.

scripts/helpers/Build/Build-PSModuleManifest.ps1

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,38 +108,43 @@ function Build-PSModuleManifest {
108108
$manifest.FileList = $files.count -eq 0 ? @() : @($files)
109109
$manifest.FileList | ForEach-Object { Write-Host "[FileList] - [$_]" }
110110

111-
Write-Host '[RequiredAssemblies]'
112111
$requiredAssembliesFolderPath = Join-Path $ModuleOutputFolder 'assemblies'
113-
$requiredAssemblies = Get-ChildItem -Path $RequiredAssembliesFolderPath -Recurse -File -ErrorAction SilentlyContinue -Filter '*.dll' |
112+
$nestedModulesFolderPath = Join-Path $ModuleOutputFolder 'modules'
113+
114+
Write-Host '[RequiredAssemblies]'
115+
$existingRequiredAssemblies = $manifest.RequiredAssemblies
116+
$requiredAssemblies = Get-ChildItem -Path $requiredAssembliesFolderPath -Recurse -File -ErrorAction SilentlyContinue -Filter '*.dll' |
114117
Select-Object -ExpandProperty FullName |
115-
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) }
116-
$manifest.RequiredAssemblies = $requiredAssemblies.count -eq 0 ? @() : @($requiredAssemblies)
118+
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart([System.IO.Path]::DirectorySeparatorChar) }
119+
$requiredAssemblies += Get-ChildItem -Path $nestedModulesFolderPath -Recurse -Depth 1 -File -ErrorAction SilentlyContinue -Filter '*.dll' |
120+
Select-Object -ExpandProperty FullName |
121+
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart([System.IO.Path]::DirectorySeparatorChar) }
122+
$manifest.RequiredAssemblies = if ($existingRequiredAssemblies) { $existingRequiredAssemblies } elseif ($requiredAssemblies.Count -gt 0) { @($requiredAssemblies) } else { @() }
117123
$manifest.RequiredAssemblies | ForEach-Object { Write-Host "[RequiredAssemblies] - [$_]" }
118124

119125
Write-Host '[NestedModules]'
120-
$nestedModulesFolderPath = Join-Path $ModuleOutputFolder 'modules'
121-
$nestedModules = Get-ChildItem -Path $nestedModulesFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.psm1', '*.ps1' |
126+
$existingNestedModules = $manifest.NestedModules
127+
$nestedModules = Get-ChildItem -Path $nestedModulesFolderPath -Recurse -Depth 1 -File -ErrorAction SilentlyContinue -Include '*.psm1', '*.ps1', '*.dll' |
122128
Select-Object -ExpandProperty FullName |
123-
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) }
124-
$manifest.NestedModules = $nestedModules.count -eq 0 ? @() : @($nestedModules)
129+
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart([System.IO.Path]::DirectorySeparatorChar) }
130+
$manifest.NestedModules = if ($existingNestedModules) { $existingNestedModules } elseif ($nestedModules.Count -gt 0) { @($nestedModules) } else { @() }
125131
$manifest.NestedModules | ForEach-Object { Write-Host "[NestedModules] - [$_]" }
126132

127133
Write-Host '[ScriptsToProcess]'
134+
$existingScriptsToProcess = $manifest.ScriptsToProcess
128135
$allScriptsToProcess = @('scripts') | ForEach-Object {
129136
Write-Host "[ScriptsToProcess] - Processing [$_]"
130137
$scriptsFolderPath = Join-Path $ModuleOutputFolder $_
131-
$scriptsToProcess = Get-ChildItem -Path $scriptsFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.ps1' |
132-
Select-Object -ExpandProperty FullName |
133-
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) }
134-
$scriptsToProcess
135-
}
136-
$manifest.ScriptsToProcess = $allScriptsToProcess.count -eq 0 ? @() : @($allScriptsToProcess)
137-
$manifest.ScriptsToProcess | ForEach-Object { Write-Host "[ScriptsToProcess] - [$_]" }
138+
Get-ChildItem -Path $scriptsFolderPath -Recurse -File -ErrorAction SilentlyContinue -Include '*.ps1' | Select-Object -ExpandProperty FullName | ForEach-Object {
139+
$_.Replace($ModuleOutputFolder, '').TrimStart([System.IO.Path]::DirectorySeparatorChar) }
140+
}
141+
$manifest.ScriptsToProcess = if ($existingScriptsToProcess) { $existingScriptsToProcess } elseif ($allScriptsToProcess.Count -gt 0) { @($allScriptsToProcess) } else { @() }
142+
$manifest.ScriptsToProcess | ForEach-Object { Write-Host "[ScriptsToProcess] - [$_]" }
138143

139-
Write-Host '[TypesToProcess]'
140-
$typesToProcess = Get-ChildItem -Path $ModuleOutputFolder -Recurse -File -ErrorAction SilentlyContinue -Include '*.Types.ps1xml' |
141-
Select-Object -ExpandProperty FullName |
142-
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) }
144+
Write-Host '[TypesToProcess]'
145+
$typesToProcess = Get-ChildItem -Path $ModuleOutputFolder -Recurse -File -ErrorAction SilentlyContinue -Include '*.Types.ps1xml' |
146+
Select-Object -ExpandProperty FullName |
147+
ForEach-Object { $_.Replace($ModuleOutputFolder, '').TrimStart($pathSeparator) }
143148
$manifest.TypesToProcess = $typesToProcess.count -eq 0 ? @() : @($typesToProcess)
144149
$manifest.TypesToProcess | ForEach-Object { Write-Host "[TypesToProcess] - [$_]" }
145150

0 commit comments

Comments
 (0)