Sampler icon indicating copy to clipboard operation
Sampler copied to clipboard

multi-module repository example

Open LarryWisherMan opened this issue 8 months ago • 3 comments

I am exploring how to structure a PowerShell monorepo using Sampler and would like clarification on how multi-module projects should be organized.

Specifically:

  • Should the Git repository root have its own build.ps1 and build.yaml to orchestrate builds across multiple module folders?

  • Should each module folder (such as under src/ or directly under the root) contain its own independent build.ps1, build.yaml, and RequiredModules.psd1, as if it were a standalone Sampler project?

  • Is there a recommended pattern for organizing multiple modules within a single repository, especially when coordinating shared dependencies and CI?

LarryWisherMan avatar Aug 07 '25 07:08 LarryWisherMan

If the modules should be deployed separate you would need to make subfolders and in each subfolder have all pipeline files and src/ folder. Just as you would move separate repositories into one folder. 🤔

johlju avatar Aug 08 '25 13:08 johlju

I would recommend against a monorepo of module repos... While what @johlju mentioned would work, with custom InvokeBuild tasks in a .build\ folder to orchestrate that, it would be tedious to manage... Multi module project should just be multi-repo, and you can use a vscode workspace (as an example) to look and edit everything together... You'd still need to invoke the build.ps1 in the correct "context" (folder).

Monorepos of PowerShell module, in my experience, tend to create tight coupling than solve issues... It's the same problem that we had with git submodules...

Sampler however let's you "embed" dependencies (modules), so that a built module myModule ships with it's required module in a .\Module folder where ModuleA is a nested module, and can be explicitly declared in myModule.psd1. This is not well documented, but that's an approach that works well, because we may or may not pin the submodule in RequiredModules.pd1 and use the path to copy that content to our built module.

Alternatively, in some cases purely to make the Dev workflow more convenient, you can create a symlink from your output\RequiredModules\ModuleA to point to \yourfolder\ModuleA\output\module\ModuleName\... Mileage may vary...

gaelcolas avatar Oct 07 '25 19:10 gaelcolas

And I meant the above when the different module must to be published separately, if you just want to separate some of the code in submodule:

  1. Do you really need to? You can have one big module and some source split in subfolders.
  2. You can have nested modules built, but it will only be shipped with its parent (not very well documented but there are examples in comments I believe).
  3. Some cases won't support nested module when the parser expect the thing (type, attribute) to be there beforehand. In this case precedence must be respected with RequiredModule or ScriptsToProcess (avoid the latest when possible, use ALC, and good luck).

gaelcolas avatar Oct 07 '25 20:10 gaelcolas