Skip to content

Commit 0d98e7d

Browse files
🩹 [Patch]: Remove initialization step and dependency on Utilities (#114)
## Description This pull request simplifies the codebase by removing redundant module dependencies and improving code readability across various scripts. It also consolidates file exclusions in the `.jscpd.json` configuration and updates logic for handling module manifest properties. ### Module Dependency Removal: * Removed `#Requires` statements for unused module dependencies (`GitHub`, `Utilities`, `Hashtable`) across multiple scripts, including `Build-PSModule.ps1`, `Build-PSModuleManifest.ps1`, and `Build-PSModuleRootModule.ps1` files. [[1]](diffhunk://#diff-c688e346ad60fbe881bd05b6a5dbc1cd712fdca0bf8b8527965db583af825fd9L11-L12) [[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L14-L15) [[3]](diffhunk://#diff-1d337ff39f37506a54fda1c5d0487f1b2c2ef318f216a4d9a56c3e7248b69879L1-R1) [[4]](diffhunk://#diff-faeb855accbc346b12f7a0ece1d91f67e26e8929ab8133aedca4051d179c66faL18-L19) ### Configuration Updates: * Consolidated file exclusions in `.github/linters/.jscpd.json` by replacing specific file paths with a wildcard (`**/scripts/helpers/**`). ### Workflow Simplification: * Removed the `Initialize-PSModule` step from the `Action-Test.yml` workflow, streamlining the setup process. [[1]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L28-L30) [[2]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L45-L47) [[3]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L62-L64) ### Code Readability Improvements: * Replaced custom `IsNotNullOrEmpty` function calls with native `.NET` methods like `[string]::IsNullOrEmpty` for better clarity and maintainability in scripts such as `Build-PSModuleManifest.ps1` and `Get-PSModuleAliasesToExport.ps1`. [[1]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L63-R64) [[2]](diffhunk://#diff-50cfb011f5c8aeef8145003927ec3e5edfdf26e5d417bcee6e441517c07454f9L76-R74) [[3]](diffhunk://#diff-ae18191466ffa02c1a8429365cf96d8768f5eae03331c4a35199f8cd961e76a7L33-R30) [[4]](diffhunk://#diff-f542f4a75d778df60fee6e176c795e133be2ed109d8212c05aa545383bd26c46L33-R30) ### Suppression Attribute Adjustments: * Updated `Diagnostics.CodeAnalysis.SuppressMessageAttribute` to include `Scope = 'Function'` for consistency in scripts like `Get-PSModuleClassesToExport.ps1` and `Get-PSModuleCmdletsToExport.ps1`. [[1]](diffhunk://#diff-c51cdeca9e44fe598bc10e94c98fc0d72f8a6fb36e872193b2fc9b9b1348f1a9L20-R20) [[2]](diffhunk://#diff-f542f4a75d778df60fee6e176c795e133be2ed109d8212c05aa545383bd26c46L13-R14) ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 3f9d3e8 commit 0d98e7d

12 files changed

+14
-45
lines changed

.github/linters/.jscpd.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"ignore": [
77
"**/tests/**",
88
"**/.github/workflows/Action-Test.yml",
9-
"**/scripts/helpers/Build/Build-PSModuleManifest.ps1",
10-
"**/scripts/helpers/Build/Build-PSModuleRootModule.ps1",
11-
"**/scripts/helpers/Build/PSScriptAnalyzer.Tests.psd1"
9+
"**/scripts/helpers/**"
1210
],
1311
"absolute": true
1412
}

.github/workflows/Action-Test.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ jobs:
2525
- name: Checkout repo
2626
uses: actions/checkout@v4
2727

28-
- name: Initialize environment
29-
uses: PSModule/Initialize-PSModule@v1
30-
3128
- name: Action-Test
3229
uses: ./
3330
with:
@@ -42,9 +39,6 @@ jobs:
4239
- name: Checkout repo
4340
uses: actions/checkout@v4
4441

45-
- name: Initialize environment
46-
uses: PSModule/Initialize-PSModule@v1
47-
4842
- name: Action-Test
4943
uses: ./
5044
with:
@@ -59,9 +53,6 @@ jobs:
5953
- name: Checkout repo
6054
uses: actions/checkout@v4
6155

62-
- name: Initialize environment
63-
uses: PSModule/Initialize-PSModule@v1
64-
6556
- name: Action-Test
6657
uses: ./
6758
with:

scripts/helpers/Build-PSModule.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#>
99
[OutputType([void])]
1010
[CmdletBinding()]
11-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
12-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
1311
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1412
'PSReviewUnusedParameter', '', Scope = 'Function',
1513
Justification = 'LogGroup - Scoping affects the variables line of sight.'

scripts/helpers/Build/Build-PSModuleBase.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Build-PSModuleBase -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
1212
#>
1313
[CmdletBinding()]
14-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
1514
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1615
'PSReviewUnusedParameter', '', Scope = 'Function',
1716
Justification = 'LogGroup - Scoping affects the variables line of sight.'

scripts/helpers/Build/Build-PSModuleManifest.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
Build-PSModuleManifest -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
1212
#>
1313
[CmdletBinding()]
14-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
15-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
1614
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1715
'PSAvoidLongLines', '', Scope = 'Function',
1816
Justification = 'Easier to read the multi ternery operators in a single line.'
@@ -60,10 +58,10 @@
6058
$manifest.ModuleVersion = '999.0.0'
6159
Write-Host "[ModuleVersion] - [$($manifest.ModuleVersion)]"
6260

63-
$manifest.Author = $manifest.Keys -contains 'Author' ? ($manifest.Author | IsNotNullOrEmpty) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER
61+
$manifest.Author = $manifest.Keys -contains 'Author' ? (-not [string]::IsNullOrEmpty($manifest.Author)) ? $manifest.Author : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER
6462
Write-Host "[Author] - [$($manifest.Author)]"
6563

66-
$manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? ($manifest.CompanyName | IsNotNullOrEmpty) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER
64+
$manifest.CompanyName = $manifest.Keys -contains 'CompanyName' ? (-not [string]::IsNullOrEmpty($manifest.CompanyName)) ? $manifest.CompanyName : $env:GITHUB_REPOSITORY_OWNER : $env:GITHUB_REPOSITORY_OWNER
6765
Write-Host "[CompanyName] - [$($manifest.CompanyName)]"
6866

6967
$year = Get-Date -Format 'yyyy'
@@ -73,7 +71,7 @@
7371
Write-Host "[Copyright] - [$($manifest.Copyright)]"
7472

7573
$repoDescription = gh repo view --json description | ConvertFrom-Json | Select-Object -ExpandProperty description
76-
$manifest.Description = $manifest.Keys -contains 'Description' ? ($manifest.Description | IsNotNullOrEmpty) ? $manifest.Description : $repoDescription : $repoDescription
74+
$manifest.Description = $manifest.Keys -contains 'Description' ? (-not [string]::IsNullOrEmpty($manifest.Description)) ? $manifest.Description : $repoDescription : $repoDescription
7775
Write-Host "[Description] - [$($manifest.Description)]"
7876

7977
$manifest.PowerShellHostName = $manifest.Keys -contains 'PowerShellHostName' ? -not [string]::IsNullOrEmpty($manifest.PowerShellHostName) ? $manifest.PowerShellHostName : $null : $null

scripts/helpers/Build/Build-PSModuleRootModule.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
2-
#Requires -Modules @{ ModuleName = 'Hashtable'; ModuleVersion = '1.1.1' }
3-
4-
function Build-PSModuleRootModule {
1+
function Build-PSModuleRootModule {
52
<#
63
.SYNOPSIS
74
Compiles the module root module files.

scripts/helpers/Build/Get-PSModuleAliasesToExport.ps1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
Get-PSModuleAliasesToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
1111
#>
1212
[CmdletBinding()]
13-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
14-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
15-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
16-
Justification = 'Want to just write to the console, not the pipeline.'
17-
)]
13+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')]
14+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')]
1815
param(
1916
# Path to the folder where the module source code is located.
2017
[Parameter(Mandatory)]
@@ -30,7 +27,7 @@
3027
$manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false
3128

3229
Write-Host "[$manifestPropertyName]"
33-
$aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or ($manifest.AliasesToExport | IsNullOrEmpty) ? '*' : $manifest.AliasesToExport
30+
$aliasesToExport = (($manifest.AliasesToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.AliasesToExport) ? '*' : $manifest.AliasesToExport
3431
$aliasesToExport | ForEach-Object {
3532
Write-Host "[$manifestPropertyName] - [$_]"
3633
}

scripts/helpers/Build/Get-PSModuleClassesToExport.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.NOTES
1818
Inspired by [about_Classes | Exporting classes with type accelerators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.4#exporting-classes-with-type-accelerators)
1919
#>
20-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains long links.')]
20+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')]
2121
[CmdletBinding()]
2222
param (
2323
# The path to the module root folder.

scripts/helpers/Build/Get-PSModuleCmdletsToExport.ps1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
Get-PSModuleCmdletsToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
1111
#>
1212
[CmdletBinding()]
13-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
14-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
15-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
16-
Justification = 'Want to just write to the console, not the pipeline.'
17-
)]
13+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')]
14+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')]
1815
param(
1916
# Path to the folder where the module source code is located.
2017
[Parameter(Mandatory)]
@@ -30,7 +27,7 @@
3027
$manifest = Get-ModuleManifest -Path $manifestFilePath -Verbose:$false
3128

3229
Write-Host "[$manifestPropertyName]"
33-
$cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or ($manifest.CmdletsToExport | IsNullOrEmpty) ? '' : $manifest.CmdletsToExport
30+
$cmdletsToExport = (($manifest.CmdletsToExport).count -eq 0) -or [string]::IsNullOrEmpty($manifest.CmdletsToExport) ? '' : $manifest.CmdletsToExport
3431
$cmdletsToExport | ForEach-Object {
3532
Write-Host "[$manifestPropertyName] - [$_]"
3633
}

scripts/helpers/Build/Get-PSModuleFunctionsToExport.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
Get-PSModuleFunctionsToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
1111
#>
1212
[CmdletBinding()]
13-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
14-
'PSAvoidUsingWriteHost', '', Scope = 'Function',
15-
Justification = 'Want to just write to the console, not the pipeline.'
16-
)]
13+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.')]
14+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Scope = 'Function', Justification = 'Contains long links.')]
1715
[OutputType([array])]
1816
param(
1917
# Path to the folder where the module source code is located.

0 commit comments

Comments
 (0)