You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add-MetadataConverter is always called, even with no converters supplied #49
param(
$Converters=@{},$EnterpriseData,$UserData,$MachineData
)
if ($Converters) {
Add-MetadataConverter$Converters
}
Even empty hashtables are truthy, so the if branch is always followed.
I'm trying to use these modules without exporting to the global scope, and this call causes the import of the Metadata module in the global scope. Without this call, I can import the modules within my own module and not leak to the global scope.
For more context, this is how I'm importing Configuration in my own module. I don't expect this to be a supported scenario, of course!
# MyModule.psm1
#region Import 3rd-party dependencies
$DepRoot = Join-Path $PSScriptRoot Dependency
$ImportParams = @{
PassThru = $true
ErrorAction = 'Stop'
}
$MetadataModule = Import-Module @ImportParams $DepRoot/Metadata/1.5.7/Metadata.psd1
# Pass ArgumentList to prevent call to Metadata function, which triggers global import
# Bug: https://github.com/PoshCode/Configuration/issues/49
# Fix: https://github.com/PoshCode/Configuration/issues/50
$ConfigurationModule = Import-Module @ImportParams $DepRoot/Configuration/1.5.1/Configuration.psd1 -ArgumentList @($null)
# Although both modules are imported into this scope, they can't see each other :-(
# Import Metadata inside Configuration's scope
# Without this, if Metadata is not in the PSModulePath, calls will fail
& $ConfigurationModule {Import-Module $args[0]} $MetadataModule
#endregion Import 3rd-party dependencies
Activity
fsackur commentedon Aug 29, 2022
For more context, this is how I'm importing Configuration in my own module. I don't expect this to be a supported scenario, of course!