Skip to content

Commit

Permalink
Fixed RootModule bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anmenaga committed Jun 10, 2024
1 parent b26a223 commit 4e70e7f
Showing 1 changed file with 17 additions and 3 deletions.
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

0 comments on commit 4e70e7f

Please sign in to comment.