diff --git a/.github/workflows/source-pipe.yml b/.github/workflows/source-pipe.yml new file mode 100644 index 0000000..b11a865 --- /dev/null +++ b/.github/workflows/source-pipe.yml @@ -0,0 +1,15 @@ +name: Pipe source checks +on: + push: + branches: [fix/build-pipe] + pull_request: + branches: [Pipe/develop] +permissions: + contents: read +jobs: + source: + uses: stadub/PowershellScripts/.github/workflows/validate-module-source.yml@d3fa5897213e3ff4e0d64897559bdfb516356512 + with: + module: Pipe + source_sha: ${{ github.event.pull_request.head.sha || github.sha }} + automation_sha: d3fa5897213e3ff4e0d64897559bdfb516356512 diff --git a/.gitignore b/.gitignore index 931f30c..e4d962c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # File types to ignore globally .history .vscode +TestResults/ diff --git a/Shared-Functions/Pipe/Aliases.ps1 b/Shared-Functions/Pipe/Aliases.ps1 index a91d2de..2a0d1ad 100644 --- a/Shared-Functions/Pipe/Aliases.ps1 +++ b/Shared-Functions/Pipe/Aliases.ps1 @@ -1,9 +1,11 @@ -Set-Alias skip Skip-Items -Scope Global -Set-Alias wtype Where-Type -Scope Global -Set-Alias take Limit-Items -Scope Global +Set-Alias skip Skip-Items +Set-Alias wtype Limit-Type +Set-Alias take Limit-Items -Set-Alias first Limit-First -Scope Global -Set-Alias last Limit-Last -Scope Global +Set-Alias first Limit-First +Set-Alias last Limit-Last -Set-Alias suppress Hide-Out -Scope Global +Set-Alias suppress Hide-Out +Set-Alias filter-type Limit-Type +Set-Alias where-type Limit-Type diff --git a/Shared-Functions/Pipe/Pipe.Tests.ps1 b/Shared-Functions/Pipe/Pipe.Tests.ps1 new file mode 100644 index 0000000..765c71c --- /dev/null +++ b/Shared-Functions/Pipe/Pipe.Tests.ps1 @@ -0,0 +1,42 @@ +$manifest = Join-Path $PSScriptRoot 'Pipe.psd1' +Describe 'Pipe source imports and aliases' { + BeforeAll { + $script:importOutput = @(Import-Module $manifest -Force -PassThru -WarningAction SilentlyContinue) + } + AfterAll { Remove-Module Pipe -ErrorAction SilentlyContinue } + + It 'validates the source manifest and imports without example output' { + (Test-ModuleManifest $manifest).Name | Should -Be 'Pipe' + $script:importOutput.Count | Should -Be 1 + $script:importOutput[0] | Should -BeOfType System.Management.Automation.PSModuleInfo + } + It 'exports six filters and eight aliases with valid targets' { + $module = Get-Module Pipe + $module.ExportedFunctions.Count | Should -Be 6 + $module.ExportedAliases.Count | Should -Be 8 + foreach ($alias in $module.ExportedAliases.Values) { + $module.ExportedFunctions.ContainsKey($alias.Definition) | Should -BeTrue + } + } + It 'filters type through each reconciled alias' -TestCases @( + @{ Name = 'wtype' }, @{ Name = 'filter-type' }, @{ Name = 'where-type' } + ) { + param($Name) + @('text', 1, 2 | & $Name -TypeName String).Count | Should -Be 1 + 'text', 1, 2 | & $Name -TypeName String | Should -BeExactly 'text' + } + It 'supports assignable types and wildcard names' { + @(1, 'text' | Limit-Type -Type ([object]) -Strict $false).Count | Should -Be 2 + 1, 'text' | Limit-Type -TypeName '*str*' -Strict $false | Should -BeExactly 'text' + } + It 'preserves skip, take, last, and suppression behavior' { + (1..5 | skip -Count 2 | take -Count 2) -join ',' | Should -BeExactly '3,4' + 1..5 | last | Should -Be 5 + @(1..5 | suppress).Count | Should -Be 0 + } + It 'exports aliases through a second clean import' { + Remove-Module Pipe + Import-Module $manifest -Force -WarningAction SilentlyContinue + (Get-Alias wtype).Definition | Should -BeExactly 'Limit-Type' + } +} diff --git a/Shared-Functions/Pipe/Pipe.psd1 b/Shared-Functions/Pipe/Pipe.psd1 index 302274f..741f509 100644 --- a/Shared-Functions/Pipe/Pipe.psd1 +++ b/Shared-Functions/Pipe/Pipe.psd1 @@ -20,20 +20,20 @@ Description = 'Powershell Pipe filtering functions. Full documentation at the Github: https://github.com/stadub/PowershellScripts/tree/master/Shared-Functions/Pipe ' - NestedModules = @('Limit-First.ps1','Limit-Last.ps1', 'Hide-Out.ps1', 'Limit-Items.ps1', 'Limit-Type.ps1', 'Skip-Items.ps1', 'Aliases.ps1') + RootModule = 'Pipe.psm1' #RootModule = "Base64String.psm1" # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = @('*') + FunctionsToExport = @('Limit-First', 'Limit-Last', 'Hide-Out', 'Limit-Items', 'Limit-Type', 'Skip-Items') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = @('Limit-First', 'Limit-Last', 'Hide-Out', 'Limit-Items', 'Limit-Type', 'Skip-Items') + CmdletsToExport = @() # Variables to export from this module - VariablesToExport = '*' + VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = @('*') + AliasesToExport = @('skip', 'wtype', 'filter-type', 'where-type', 'take', 'first', 'last', 'suppress') # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. PrivateData = @{ diff --git a/Shared-Functions/Pipe/Pipe.psm1 b/Shared-Functions/Pipe/Pipe.psm1 new file mode 100644 index 0000000..7655042 --- /dev/null +++ b/Shared-Functions/Pipe/Pipe.psm1 @@ -0,0 +1,6 @@ +# Load only the maintained source filters; exclude historical examples and out/. +foreach ($name in @('Limit-First', 'Limit-Last', 'Hide-Out', 'Limit-Items', 'Limit-Type', 'Skip-Items')) { + . (Join-Path $PSScriptRoot "Functions/$name.ps1") +} +. (Join-Path $PSScriptRoot 'Aliases.ps1') +Export-ModuleMember -Function Limit-First, Limit-Last, Hide-Out, Limit-Items, Limit-Type, Skip-Items -Alias skip, wtype, filter-type, where-type, take, first, last, suppress diff --git a/Shared-Functions/Pipe/README.md b/Shared-Functions/Pipe/README.md index aecf8fe..6266bf5 100644 --- a/Shared-Functions/Pipe/README.md +++ b/Shared-Functions/Pipe/README.md @@ -153,3 +153,12 @@ Import-Module Pipe ### 📬 Suggestions and feedback If you have any idea or suggestion - please add a github issue. + +## Source layout and validation + +Import `Pipe.psd1` from the source directory. `Pipe.psm1` loads the six filters +from `Functions/` and exports their aliases. `wtype`, `filter-type`, and +`where-type` all resolve to `Limit-Type`; historical example scripts are not loaded. +Run `Invoke-Pester ./Pipe.Tests.ps1` with Pester 4.10.1 to validate the real source +manifest, imports, exports, aliases, and filtering. Release `out/` packages are +reviewed separately and are unchanged by this source fix.