When you build a PowerShell project from multiple files, the natural structure is clear: enums first, then classes, then functions. Each group has its own place, and as long as dependencies only flow in one direction, that structure works perfectly.
But sometimes a function depends on a class, and that class calls the function. There is no longer a clean boundary between the two groups — they need to be interleaved in the output. That's a cross-dependency, and handling it manually is where things get fragile.
What a Cross-Dependency Looks Like
Consider this scenario:
# New-Report.ps1 function New-Report ([ ReportConfig ] $config ) { # uses ReportConfig as a parameter type }
# ReportConfig.ps1 class ReportConfig { [ string ] $Title
[ void ] Generate () { New-Report $this # calls New-Report } }
Enter fullscreen mode
Exit fullscreen mode
New-Report references ReportConfig as a parameter type — so ReportConfig must be defined before New-Report is loaded.…