Revert "Allow empty prefix string in 'Import-Module -Prefix' to override default prefix in manifest (#20409)" (#25462)

This commit is contained in:
MartinGC94
2025-04-28 08:34:49 +05:00
committed by GitHub
parent ca7038b7c5
commit 2fc4821e53
2 changed files with 11 additions and 13 deletions
@@ -1620,7 +1620,17 @@ namespace Microsoft.PowerShell.Commands
if (bailOnFirstError) return null;
}
string resolvedCommandPrefix = BasePrefix ?? defaultCommandPrefix ?? string.Empty;
string resolvedCommandPrefix = string.Empty;
if (!string.IsNullOrEmpty(defaultCommandPrefix))
{
resolvedCommandPrefix = defaultCommandPrefix;
}
if (!string.IsNullOrEmpty(this.BasePrefix))
{
resolvedCommandPrefix = this.BasePrefix;
}
if (!string.IsNullOrEmpty(actualRootModule))
{
@@ -57,18 +57,6 @@ Describe "Import-Module" -Tags "CI" {
(Get-Module TestModule).Version | Should -BeIn "1.1"
}
It 'Should override default command prefix if an empty string is provided' {
$ModuleName = "PrefixTestModule"
$ModulePath = Join-Path -Path $testdrive -ChildPath $ModuleName
$null = New-Item -Path $ModulePath -ItemType Directory -Force
'function Use-Something{}' | Set-Content -Path "$ModulePath\$ModuleName.psm1" -Force
New-ModuleManifest -Path "$ModulePath\$ModuleName.psd1" -DefaultCommandPrefix MyPrefix -FunctionsToExport Use-Something -RootModule "$ModuleName.psm1"
$ImportedModule = Import-Module -Name "$ModulePath\$ModuleName.psd1" -Prefix "" -PassThru
$ImportedModule.ExportedCommands.ContainsKey('Use-Something') | Should -Be $true
Remove-Module -ModuleInfo $ImportedModule
}
It 'ProcessorArchitecture should work' {
$currentProcessorArchitecture = switch ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) {
'X86' { 'x86' }