PoshCode / ModuleBuilder

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

Mac, APFS, and file system ordering #105

Closed indented-automation closed 1 year ago

indented-automation commented 3 years ago

Good morning!

On Windows and in the NTFS file system, modules which require content to be inserted in a particular order (typically anything class-based) can rely on the naming of files in the file system to insert content into a root module in the right order.

On Mac and in the APFS file system ordering is not guaranteed to be alphabetical and therefore modules are built in a manner inconsistent with builds executed on Windows.

Would the ability to add a custom sorter to Build-Module / build.psd1 be appropriate to address this problem? It will mean adding complexity to the code used to merge the module which is currently a nice simple statement passed to Get-ChildItem. Or are you aware of any other ways to work-around this problem?

Related exploration of the problem:

https://indiestack.com/2017/09/unordered-directory-contents/

For example, the change from:

$AllScripts = Get-ChildItem -Path @($ModuleInfo.SourceDirectories).ForEach{ Join-Path $ModuleInfo.ModuleBase $_ } -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue

To this, or some variation of, would explicitly sort by FullName rather than depending on the underlying file system to get it right:

$AllScripts = $ModuleInfo.SourceDirectories |
    Join-Path -Path $ModuleInfo.ModuleBase -ChildPath { $_ } |
    ForEach-Object {
        Get-ChildItem -Path $_ -Filter *.ps1 -Recurse | Sort-Object FullName
    }

Cheers!

Chris

Jaykul commented 1 year ago

This was fixed by @gaelcolas in February. I guess we're not great at paperwork.