ModuleBuilder icon indicating copy to clipboard operation
ModuleBuilder copied to clipboard

Mac, APFS, and file system ordering

Open indented-automation opened this issue 4 years ago • 0 comments
trafficstars

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

indented-automation avatar Apr 22 '21 08:04 indented-automation