Skip to content
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

Closed
mklement0 opened this issue Dec 4, 2018 · 4 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module

Comments

@mklement0
Copy link
Contributor

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 Test-ModuleManifest should check the manifest / RootModule for naming consistency with the enclosing directory Test-ModuleManifest should check the manifest / root-module file base name for naming consistency with the enclosing directory Dec 4, 2018
@iSazonov iSazonov added Issue-Enhancement the issue is more of a feature request than a bug WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module labels Dec 4, 2018
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

2 similar comments
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module
Projects
None yet
Development

No branches or pull requests

2 participants