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

Test-ModuleManifest should check the manifest / root-module file base name for naming consistency with the enclosing directory #8391

Open
mklement0 opened this Issue Dec 4, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@mklement0
Contributor

mklement0 commented Dec 4, 2018

For a module to be picked up merely by the name of its containing directory, its manifest must have the same name as that directory; e.g., a module directory foo must contain a manifest named foo.psd1.

Auto-loading and discovery of not-yet-loaded modules relies on this convention.

There are two pitfalls, both of which Test-ModuleManifest should detect, but currently doesn't:

  • (a) Your *.psd1 file's base name may differ from the enclosing directory name (assuming that your root *.psm1 file doesn't match the name either), so loading the module by its directory name / path will fail.

  • (b) A *.psm1 file that matches the enclosing directory name may be present, but the *.psd1 file may have a different name, in which case loading the module by directory name will use the *.psm1 directly, bypassing the manifest altogether.

Steps to reproduce

Scenario (a)

# Create a manifest in subdir. "tmpMod1", but with the wrong name.
New-ModuleManifest (Join-Path (New-Item -Force -Type Directory tmpMod1) wrongName.psd1) -RootModule wrongName.psm1 -function foo
# Create the associated *.psm1 file with the same wrong name.
'function foo { "foo" }' > tmpMod1/wrongName.psm1

Test-ModuleManifest tmpMod1/wrongName.psd1

Scenario (b)

# Create a manifest in subdir. "tmpMod2", but with the wrong name, but pointing
# to a *.psm1 file with the RIGHT name.
New-ModuleManifest (Join-Path (New-Item -Force -Type Directory tmpMod2) wrongName.psd1) -RootModule tmpMod2.psm1 -function foo
# Create the associated *.psm1 file with the RIGHT Name
'function foo { "foo2" }' > tmpMod2/tmpMod2.psm1

Test-ModuleManifest tmpMod2/wrongName.psd1 -vb

Expected behavior

Scenario (a)

Test-ModuleManifest should report an error that the *.psd1 file's base name doesn't match the name of the enclosing directory.

Scenario (b)

Test-ModuleManifest should report an error or at least warn that no *.psd1 file (manifest) with the expected name was found, only a *.psm1 file.

Actual behavior

Scenario (a)

Test-ModuleManifest succeeds.

Scenario (b)

Test-ModuleManifest succeeds, and the verbose output indicates that it was the *.psm1 file rather than the manifest (*.psd1) that was imported (and would be with Import-Module).

Environment data

PowerShell Core v6.2.0-preview.2 (6.2.0-preview.2) on Ubuntu 18.04.1 LTS

@mklement0 mklement0 changed the title from Test-ModuleManifest should check the manifest / RootModule for naming consistency with the enclosing directory to Test-ModuleManifest should check the manifest / root-module file base name for naming consistency with the enclosing directory Dec 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment