Skip to content

Commit 88c2bf5

Browse files
docs: simplify folder tree annotations, revise dependency docs, add maintainability principle
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 0f9c85c commit 88c2bf5

File tree

1 file changed

+14
-44
lines changed

1 file changed

+14
-44
lines changed

README.md

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ How the module is built.
919919
│ ├── formats/ # Formatting metadata registered during build
920920
│ │ ├── CultureInfo.Format.ps1xml # Example format included in manifest
921921
│ │ └── Mygciview.Format.ps1xml # Additional format loaded at import
922-
│ ├── functions/ # Function scripts exported by the module; #Requires -Modules statements here are compiled into RequiredModules
922+
│ ├── functions/ # Function scripts exported by the module
923923
│ │ ├── private/ # Helper functions scoped to the module
924924
│ │ │ ├── Get-InternalPSModule.ps1 # Sample internal helper
925925
│ │ │ └── Set-InternalPSModule.ps1 # Sample internal helper
@@ -949,57 +949,24 @@ How the module is built.
949949
│ │ └── SolarSystems.ps1 # Example variable surfaced in generated docs
950950
│ ├── finally.ps1 # Cleanup script appended to the root module
951951
│ ├── header.ps1 # Optional header injected at the top of the module
952-
│ ├── manifest.psd1 (optional) # Source manifest reused when present; RequiredModules is not propagated — use #Requires -Modules in function files instead (see "Declaring module dependencies" below)
952+
│ ├── manifest.psd1 (optional) # Source manifest reused when present
953953
│ └── README.md # Module-level docs ingested by Document-PSModule
954954
```
955955

956956
### Declaring module dependencies
957957

958-
Module dependencies are declared using [`#Requires -Modules`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires)
959-
statements at the top of individual PowerShell function files under `src/functions/public/` and `src/functions/private/`.
960-
The build system ([Build-PSModule](https://github.com/PSModule/Build-PSModule)) collects all `#Requires -Modules`
961-
declarations across every source file, de-duplicates them, and writes the merged result into the `RequiredModules` field
962-
of the compiled module manifest.
958+
Declare module dependencies using
959+
[`#Requires -Modules`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires)
960+
statements at the top of function files in `src/functions/public/` or `src/functions/private/` that require external modules.
961+
[Build-PSModule](https://github.com/PSModule/Build-PSModule) collects every `#Requires -Modules` declaration across all
962+
source files, de-duplicates the list, and writes it into the `RequiredModules` field of the compiled manifest
963+
automatically. For the full range of supported syntax variants, see the
964+
[about_Requires](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires)
965+
documentation.
963966

964967
> [!IMPORTANT]
965968
> Adding `RequiredModules` to `src/manifest.psd1` is **not** supported for this purpose. Those entries are silently
966-
> ignored by the build — they will not appear in the built manifest. Use `#Requires -Modules` in function files instead.
967-
968-
#### Supported syntax variants
969-
970-
```powershell
971-
# Bare module name — any version is acceptable
972-
#Requires -Modules Microsoft.Graph.Authentication
973-
974-
# Minimum version constraint
975-
#Requires -Modules @{ ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '2.28.0' }
976-
977-
# Exact version constraint
978-
#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.1.4' }
979-
```
980-
981-
#### Example
982-
983-
A function that calls into `Microsoft.Graph.Authentication` declares its dependency at the top of the file:
984-
985-
```powershell
986-
#Requires -Modules @{ ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '2.28.0' }
987-
988-
function Get-GraphToken {
989-
...
990-
}
991-
```
992-
993-
When the module is built, the compiled manifest automatically includes:
994-
995-
```powershell
996-
RequiredModules = @(
997-
@{ ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '2.28.0' }
998-
)
999-
```
1000-
1001-
This co-location approach keeps dependency declarations next to the functions that need them, making it immediately
1002-
clear which commands drive each external dependency.
969+
> ignored by the build and will not appear in the compiled manifest. Use `#Requires -Modules` in function files instead.
1003970
1004971
## Principles and practices
1005972

@@ -1013,6 +980,9 @@ For each topic or feature to add to the release, open a new branch representing
1013980
branch. Optionally add the `Prerelease` label on the PR for the release branch, to release preview versions before merging and releasing a published
1014981
version of the PowerShell module.
1015982

983+
Co-locate concerns for long-term maintainability. For example, `#Requires -Modules` statements belong in the function files that use them, not in a
984+
central manifest — this makes it immediately visible which functions drive each external dependency, and avoids silent drift between the manifest and
985+
the actual code.
1016986

1017987
The process is compatible with:
1018988

0 commit comments

Comments
 (0)