Skip to content

Commit 0fd280b

Browse files
authored
Keep RequiredModules for Debug configuraiton during add psm1 dependency (#15658)
1 parent 5794114 commit 0fd280b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

tools/AddModulePsm1Dependency.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ if ($ModuleMetadata.RootModule) {
5656
Add-PSM1Dependency -Path $moduleSourcePath
5757
}
5858

59-
Remove-ModuleDependencies -Path $moduleSourcePath
59+
Remove-ModuleDependencies -Path $moduleSourcePath -KeepRequiredModules

tools/PublishModules.psm1

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,26 @@ function Get-AllModules {
309309
.PARAMETER Path
310310
Path to the psd1 file.
311311
312+
.PARAMETER KeepRequiredModules
313+
Switch to keep RequiredModules.
314+
312315
#>
313316
function Remove-ModuleDependencies {
314317
[CmdletBinding()]
315318
param(
316-
[string]$Path
319+
[string]$Path,
320+
321+
[Parameter(Mandatory=$false)]
322+
[switch]$KeepRequiredModules
317323
)
318324

319325
PROCESS {
320-
$regex = New-Object System.Text.RegularExpressions.Regex "RequiredModules\s*=\s*@\([^\)]+\)"
321-
$content = (Get-Content -Path $Path) -join "`r`n"
322-
$text = $regex.Replace($content, "RequiredModules = @()")
323-
Out-FileNoBom -File $Path -Text $text
326+
if (-not $KeepRequiredModules.IsPresent){
327+
$regex = New-Object System.Text.RegularExpressions.Regex "RequiredModules\s*=\s*@\([^\)]+\)"
328+
$content = (Get-Content -Path $Path) -join "`r`n"
329+
$text = $regex.Replace($content, "RequiredModules = @()")
330+
Out-FileNoBom -File $Path -Text $text
331+
}
324332

325333
$regex = New-Object System.Text.RegularExpressions.Regex "NestedModules\s*=\s*@\([^\)]+\)"
326334
$content = (Get-Content -Path $Path) -join "`r`n"

0 commit comments

Comments
 (0)