-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathModuleFast.psm1
More file actions
60 lines (54 loc) · 2.39 KB
/
Copy pathModuleFast.psm1
File metadata and controls
60 lines (54 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#requires -version 7.6
# Load the C# binary module — probe Artifacts Output Layout paths first, then
# the classic deployed path (bin/ModuleFast/ModuleFast.dll).
$binaryModulePaths = @(
if ($env:MODULEFASTDEBUG) {
Write-Host -Fore Green "ModuleFast Debug Mode Enabled: Looking for binary module in Artifacts Output Layout"
$buildTypes = 'debug', 'release'
$artifactsDir = Join-Path $PSScriptRoot 'Artifacts'
$buildDir = Join-Path $artifactsDir 'bin' 'PowerShell'
$publishDir = Join-Path $artifactsDir 'publish' 'PowerShell'
foreach ($buildType in $buildTypes) {
# Build artifacts first
(Join-Path $buildDir $buildType 'ModuleFast.dll')
# Publish Artifacts Next
(Join-Path $publishDir $buildType 'ModuleFast.dll')
}
}
# Classic deployed layout in same folder
(Join-Path $PSScriptRoot 'ModuleFast.dll')
# Published Output as a debug fallback
(Join-Path $PSScriptRoot 'Artifacts', 'Module', 'ModuleFast.dll')
)
$binaryModulePath = foreach ($path in $binaryModulePaths) {
Write-Debug "Looking for binary module at path: $path"
if (Test-Path $path) {
Write-Debug "✅ Found binary module at path: $path"
$path
break
}
}
if (-not $binaryModulePath) {
throw "Binary module DLL not found in expected paths: $($binaryModulePaths -join ', '). This is probably a bug."
}
Write-Debug "Importing binary module from path: $binaryModulePath"
Import-Module $binaryModulePath -Force
#Register type accelerators so [ModuleFastSpec], [ModuleFastInfo], etc. work without namespace
$accelerators = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')
foreach ($pair in @{
'ModuleFastSpec' = [ModuleFast.ModuleFastSpec]
'ModuleFastInfo' = [ModuleFast.ModuleFastInfo]
'SpecFileType' = [ModuleFast.SpecFileType]
'InstallScope' = [ModuleFast.InstallScope]
}.GetEnumerator()) {
if (-not $accelerators::Get.ContainsKey($pair.Key)) {
[void]$accelerators::Add($pair.Key, $pair.Value)
}
}
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
$accelerators = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')
'ModuleFastSpec', 'ModuleFastInfo', 'SpecFileType', 'InstallScope' | ForEach-Object {
[void]$accelerators::Remove($_)
}
}
Set-Alias imf -Value Install-ModuleFast