Skip to content

Commit 7b83473

Browse files
🪲 [Fix]: Fix output of export/import class/enum (#49)
## Description - Fix an issue where it wouldnt fully resemble the native loader. Now it does :) - Added "Exporting/Importing enum/class ***". ## 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 c467345 commit 7b83473

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

scripts/helpers/Build/Build-PSModuleRootModule.ps1

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,14 @@ function Build-PSModuleRootModule {
5656
$classes = Get-PSModuleClassesToExport -SourceFolderPath $ModuleOutputFolder
5757
if ($classes.count -gt 0) {
5858
$classExports = @'
59-
# Define the types to export with type accelerators.
60-
$ExportableClasses = @(
61-
62-
'@
63-
$classes | Where-Object Type -EQ 'class' | ForEach-Object {
64-
$classExports += " [$($_.Name)]`n"
65-
}
66-
67-
$classExports += @'
59+
# Get the internal TypeAccelerators class to use its static methods.
60+
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
61+
'System.Management.Automation.TypeAccelerators'
6862
)
63+
# Ensure none of the types would clobber an existing type accelerator.
64+
# If a type accelerator with the same name exists, throw an exception.
65+
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
66+
# Define the types to export with type accelerators.
6967
$ExportableEnums = @(
7068
7169
'@
@@ -75,31 +73,34 @@ $ExportableEnums = @(
7573

7674
$classExports += @'
7775
)
78-
# Get the internal TypeAccelerators class to use its static methods.
79-
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
80-
'System.Management.Automation.TypeAccelerators'
81-
)
82-
# Ensure none of the types would clobber an existing type accelerator.
83-
# If a type accelerator with the same name exists, throw an exception.
84-
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
76+
$ExportableEnums | Foreach-Object { Write-Verbose "Exporting enum '$($_.FullName)'." }
8577
foreach ($Type in $ExportableEnums) {
8678
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
8779
Write-Warning "Enum already exists [$($Type.FullName)]. Skipping."
8880
} else {
81+
Write-Verbose "Importing enum '$Type'."
8982
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
90-
Write-Verbose "Exporting enum '$Type'."
9183
}
9284
}
85+
$ExportableClasses = @(
86+
87+
'@
88+
$classes | Where-Object Type -EQ 'class' | ForEach-Object {
89+
$classExports += " [$($_.Name)]`n"
90+
}
91+
92+
$classExports += @'
93+
)
94+
$ExportableClasses | Foreach-Object { Write-Verbose "Exporting class '$($_.FullName)'." }
9395
foreach ($Type in $ExportableClasses) {
9496
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
9597
Write-Warning "Class already exists [$($Type.FullName)]. Skipping."
9698
} else {
99+
Write-Verbose "Importing class '$Type'."
97100
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
98-
Write-Verbose "Exporting class '$Type'."
99101
}
100102
}
101103
102-
103104
# Remove type accelerators when the module is removed.
104105
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
105106
foreach ($Type in ($ExportableEnums + $ExportableClasses)) {

0 commit comments

Comments
 (0)