psake / PowerShellBuild

Common build tasks for psake and Invoke-Build that build and test PowerShell modules
MIT License
133 stars 24 forks source link

CompileModule Flag results in bad PSM1 file #25

Closed PshMike closed 5 years ago

PshMike commented 5 years ago

Using option to CompileModule results in original PSM1 file having *.ps1 files appended.

Expected Behavior

new PSM1 file should have code from all *.ps1 files, and nothing else.

Current Behavior

original PSM1 file is copied (which includes code to dot-source .ps1 files ) AND the contents of .ps1 files is appended to the original PSM1 file

Possible Solution

When using CompileModule flag the original PSM1 file should NOT be copied to OUTPUT directory

Steps to Reproduce (for bugs)

  1. Use Stucco and Plaster to create a new module
  2. Change "CompileModule" flag in psakeFile.ps1 to $true
  3. Build module
  4. Resulting PSM1 file in output directory has content from original PSM1 file + the code from *.ps1 files.

Context

Resulting PSM1 file is incorrect.

Your Environment

devblackops commented 5 years ago

Hi @mjenne, thanks for reporting this.

This is intended behavior. It is expected that if you wish to compile the module, that you'll need to comment out/remove any logic in your PSM1 that is dot sourcing the public/private functions. We're still copying the PSM1 because it is common to have initialization logic in the PSM1 and the way it's currently designed, you wouldn't have a place to define that without copying the existing PSM1.

I think a better option is to model what ModuleBuild does, and add support for prefix/suffix strings or file paths. These would be added to a (newly built) PSM1 before and after public and private functions. This should add extra flexibility so people can structure the compiled PSM1 the way they need.

devblackops commented 5 years ago

PR #28 introduced a fix for this.