Skip to content

Commit 1e3d612

Browse files
🪲 [Fix]: Fix Variables being $null (#110)
## Description This pull request includes a minor change to the `Get-PSModuleVariablesToExport.ps1` script. The change involves moving the initialization of the `$variablesToExport` variable to an earlier point in the script to ensure it is defined before any potential early returns. * [`scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1`](diffhunk://#diff-e2148fcf63283d70b3d432f67fc98191e2cc712dc3f4d30914c8c0810d11a6deR28-L35): Moved the initialization of `$variablesToExport` to before the folder existence check to ensure it is always defined. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [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 d454e3a commit 1e3d612

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

.github/workflows/Action-Test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ jobs:
3535
Path: tests/src
3636
ModulesOutputPath: tests/outputs/modules
3737

38+
ActionTestMinimal:
39+
name: Action-Test - [Minimal]
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout repo
43+
uses: actions/checkout@v4
44+
45+
- name: Initialize environment
46+
uses: PSModule/Initialize-PSModule@main
47+
48+
- name: Action-Test
49+
uses: ./
50+
with:
51+
Name: PSModuleTest
52+
Path: tests/srcMinimal
53+
ModulesOutputPath: tests/outputs/modules
54+
ModuleArtifactName: moduleMinimal
55+
3856
ActionTestWithManifest:
3957
name: Action-Test - [DefaultWithManifest]
4058
runs-on: ubuntu-24.04

scripts/helpers/Build/Get-PSModuleVariablesToExport.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
.EXAMPLE
1010
Get-PSModuleVariablesToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
1111
#>
12-
[OutputType([Collections.Generic.List[string]])]
1312
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1413
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1514
Justification = 'Want to just write to the console, not the pipeline.'
1615
)]
16+
[OutputType([string])]
17+
[OutputType([Collections.Generic.List[string]])]
1718
[CmdletBinding()]
1819
param(
1920
# Path to the folder where the module source code is located.
@@ -25,14 +26,14 @@
2526

2627
Write-Host "[$manifestPropertyName]"
2728

29+
$variablesToExport = [Collections.Generic.List[string]]::new()
2830
$variableFolderPath = Join-Path -Path $SourceFolderPath -ChildPath 'variables/public'
2931
if (-not (Test-Path -Path $variableFolderPath -PathType Container)) {
3032
Write-Host "[$manifestPropertyName] - [Folder not found] - [$variableFolderPath]"
31-
return $variablesToExport
33+
return ''
3234
}
3335
$scriptFilePaths = Get-ChildItem -Path $variableFolderPath -Recurse -File -Filter *.ps1 | Select-Object -ExpandProperty FullName
3436

35-
$variablesToExport = [Collections.Generic.List[string]]::new()
3637
$scriptFilePaths | ForEach-Object {
3738
$ast = [System.Management.Automation.Language.Parser]::ParseFile($_, [ref]$null, [ref]$null)
3839
$variables = Get-RootLevelVariable -Ast $ast
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function Test-PSModuleTest {
2+
<#
3+
.SYNOPSIS
4+
Performs tests on a module.
5+
6+
.EXAMPLE
7+
Test-PSModule -Name 'World'
8+
9+
"Hello, World!"
10+
#>
11+
[CmdletBinding()]
12+
param (
13+
# Name of the person to greet.
14+
[Parameter(Mandatory)]
15+
[string] $Name
16+
)
17+
Write-Output "Hello, $Name!"
18+
}

0 commit comments

Comments
 (0)