Skip to content

Fixed RootModule bug #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions powershell-adapter/psDscAdapter/psDscAdapter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function FindAndParseResourceDefinitions
return
}

"Loading resources from '$filePath'" | Write-DscTrace -Operation Trace
"Loading resources from file '$filePath'" | Write-DscTrace -Operation Trace
#TODO: Handle class inheritance
#TODO: Ensure embedded instances in properties are working correctly
[System.Management.Automation.Language.Token[]] $tokens = $null
Expand Down Expand Up @@ -161,8 +161,18 @@ function LoadPowerShellClassResourcesFromModule
[PSModuleInfo]$moduleInfo
)

"Loading resources from module '$($moduleInfo.Path)'" | Write-DscTrace -Operation Trace

if ($moduleInfo.RootModule)
{
if (([System.IO.Path]::GetExtension($moduleInfo.RootModule) -ne ".psm1") -and
([System.IO.Path]::GetExtension($moduleInfo.RootModule) -ne ".ps1") -and
(-not $z.NestedModules))
{
"RootModule is neither psm1 nor ps1 '$($moduleInfo.RootModule)'" | Write-DscTrace -Operation Trace
return [System.Collections.Generic.List[DscResourceInfo]]::new()
}

$scriptPath = Join-Path $moduleInfo.ModuleBase $moduleInfo.RootModule
}
else
Expand All @@ -177,7 +187,9 @@ function LoadPowerShellClassResourcesFromModule
foreach ($nestedModule in $moduleInfo.NestedModules)
{
$resourcesOfNestedModules = LoadPowerShellClassResourcesFromModule $nestedModule
$Resources.AddRange($resourcesOfNestedModules)
if ($resourcesOfNestedModules) {
$Resources.AddRange($resourcesOfNestedModules)
}
}
}

Expand Down Expand Up @@ -280,7 +292,9 @@ function Invoke-DscCacheRefresh {
foreach ($mod in $modules)
{
[System.Collections.Generic.List[DscResourceInfo]]$r = LoadPowerShellClassResourcesFromModule -moduleInfo $mod
$DscResources.AddRange($r)
if ($r) {
$DscResources.AddRange($r)
}
}
}

Expand Down
Loading