Background
In this question I describe how I have a custom PSModule setup and include various other .ps1 files using the module manifest NestedModules node.
The problem I describe in this question is how I can call any function in the NestedModule files, from the main PSModule script files, but one NestedModule script can NOT call functions in the other NestedModule script file.
I believe I got around this problem by exporting the functions I wanted to call in the NestedModules. Then it was possible to call the (exported) function from one NestedModule, where that function was defined in another NestedModule.
Variable vs Functions
Now, using the exact same setup (NestedModules), I include a script file that defines a number of constant variables, so that I can use these throughout my scripts, rather than having magic strings littered throughout.
I found that the constant variables worked, without any need to export them. I can use them in the main PSModule script files, or in other NestedModule script files without any issue or need to export or treat specially in any way!
This is great. But I'd love it if somebody can give a definitive explanation why this works? Is it known that variables are treated more simply within PSModules / NestedModules? It did occur to me that maybe even a PowerShell version increment has allowed this to work - it's been a long time since I asked the original question - and maybe even the Functions would work without the explicit exports in the current version?
Any comments or conclusive explanations much appreciated.
$global:myVarwould behave differently to$script:myVarfor example. Also, it would be a stylistic preference for me (rather than any sort of best-practise), but to avoid polluting the global namespace with variables that might clash with other modules, you could consider a function that returns either the individual values (Get-MyVar) or returns a pacustomobject with all your values as properties (Get-ManofestConstantsor whatever).