Skip to content

Check whether a module references itself in 'NestedModules' field in the .psd1 file #997

@daxian-dbw

Description

@daxian-dbw

This feature ask is per discussion in PowerShell/PowerShell#6843 (comment).

Importing a ill-structured module could result in a circular nested module. For example, for the following code, you will see 'True' as the output.

$testdir = Join-Path $env:TEMP test
$testpsm1 = Join-Path $testdir test.psm1
$testpsd1 = Join-Path $testdir test.psd1
mkdir $testdir > $null
Set-Content $testpsm1 -Value "function bar {}"
Set-Content $testpsd1 -Value "@{ ModuleVersion = '0.0.1'; RootModule = 'test'; NestedModules = @('test') }"

$m = Import-Module $testpsd1 -Pass
$m -eq $m.NestedModules[0]
> True

So maybe a rule can be written to check the bold part of test.psd1 "@{ ModuleVersion = '0.0.1'; RootModule = 'test'; NestedModules = @('test') }", to make sure the author is warned when a module like test.psd1 has itself as a nested module.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions