Skip to content

Commit e505e49

Browse files
committed
Fixed RootModule bug
1 parent 5b9ce43 commit e505e49

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

powershell-adapter/psDscAdapter/psDscAdapter.psm1

+17-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function FindAndParseResourceDefinitions
6767
return
6868
}
6969

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

164+
"Loading resources from module '$($moduleInfo.Path)'" | Write-DscTrace -Operation Trace
165+
164166
if ($moduleInfo.RootModule)
165167
{
168+
if (([System.IO.Path]::GetExtension($moduleInfo.RootModule) -ne ".psm1") -and
169+
([System.IO.Path]::GetExtension($moduleInfo.RootModule) -ne ".ps1") -and
170+
(-not $z.NestedModules))
171+
{
172+
"RootModule is neither psm1 nor ps1 '$($moduleInfo.RootModule)'" | Write-DscTrace -Operation Trace
173+
return [System.Collections.Generic.List[DscResourceInfo]]::new()
174+
}
175+
166176
$scriptPath = Join-Path $moduleInfo.ModuleBase $moduleInfo.RootModule
167177
}
168178
else
@@ -177,7 +187,9 @@ function LoadPowerShellClassResourcesFromModule
177187
foreach ($nestedModule in $moduleInfo.NestedModules)
178188
{
179189
$resourcesOfNestedModules = LoadPowerShellClassResourcesFromModule $nestedModule
180-
$Resources.AddRange($resourcesOfNestedModules)
190+
if ($resourcesOfNestedModules) {
191+
$Resources.AddRange($resourcesOfNestedModules)
192+
}
181193
}
182194
}
183195

@@ -280,7 +292,9 @@ function Invoke-DscCacheRefresh {
280292
foreach ($mod in $modules)
281293
{
282294
[System.Collections.Generic.List[DscResourceInfo]]$r = LoadPowerShellClassResourcesFromModule -moduleInfo $mod
283-
$DscResources.AddRange($r)
295+
if ($r) {
296+
$DscResources.AddRange($r)
297+
}
284298
}
285299
}
286300

0 commit comments

Comments
 (0)