PoshCode / ModuleBuilder

A PowerShell Module to help scripters write, version, sign, package, and publish.
MIT License
445 stars 54 forks source link

Defaults cause hard-to-detect problems on Linux #125

Closed Jaykul closed 1 year ago

Jaykul commented 1 year ago

The result is that if someone uses lowercase "public" and "private" folders, the have to override those parameters in order for their build to work on Linux -- and if they are normally using Windows or MacOS, everything will work fine on their laptops, and only fail on a Linux build agent (see #124). The worst part is that there is no indication of what has gone wrong, because the build is simply not seeing any source files (which is considered a valid choice).

I think the best bet is to support wildcards in both of those parameters (i.e. add support to SourceDirectories). Wildcard support allows us to use [Pp] in place of P we could set the defaults to:

$PublicFilter = "[Pp]ublic\*.ps1"
$SourceDirectories = "[Ee]nums", "[Cc]lasses", "[Pp]rivate", "[Pp]ublic"

This isn't foolproof -- our default $OutputDirectory is "..\Output" which we should at least change to "../Output" -- but would resolve the most common cases where people are having problems on Linux when they use other people's templates.

Jaykul commented 1 year ago

To be clear, we can't just put [Pp] in SourceDirectories currently, because putting a wildcard in the path to a folder makes Get-ChildItem not get child items, and -recurse and -filter don't work as intended. We'll have to explicitly Resolve-Path on those folders before calling Get-ChildItem in the build.

Currently you can just put this in your build.psd1 to make it work with lowercase directories (on Linux, where the filesystem is case-sensitive):

SourceDirectories = 'classes','private','public'
PublicFilter = 'public/*.ps1'
Jaykul commented 1 year ago

It might be a good idea to do something like Get-ChildItem -filter *.ps1 -recurse and if we find any ps1 files, write a warning if we find nothing in the SourceDirectories, so it doesn't look like everything worked, when in fact, you filtered everything out.