@@ -65,32 +65,11 @@ else {
6565 }
6666}
6767
68- # Import PathResolution for path operations
68+ # PathResolution import is deferred - only loaded when Get-ProfileDirectory is actually needed
69+ # This avoids parse-time errors when FileSystemPathType is not yet available
6970# PathResolution is in scripts/lib/path/, not scripts/lib/fragment/
70- $pathModulePath = Join-Path (Split-Path - Parent $PSScriptRoot ) ' path' ' PathResolution.psm1'
71- if (Get-Command Import-ModuleSafely - ErrorAction SilentlyContinue) {
72- $null = Import-ModuleSafely - ModulePath $pathModulePath - ErrorAction SilentlyContinue
73- }
74- else {
75- # Fallback to manual validation
76- if ($pathModulePath -and -not [string ]::IsNullOrWhiteSpace($pathModulePath ) -and (Test-Path - LiteralPath $pathModulePath )) {
77- try {
78- Import-Module $pathModulePath - ErrorAction Stop
79- }
80- catch {
81- $debugLevel = 0
82- if ($env: PS_PROFILE_DEBUG -and [int ]::TryParse($env: PS_PROFILE_DEBUG , [ref ]$debugLevel )) {
83- if ($debugLevel -ge 2 ) {
84- Write-Verbose " [fragment-config.init] Failed to import PathResolution module: $ ( $_.Exception.Message ) . Path resolution features may be limited."
85- }
86- # Level 3: Log detailed error information
87- if ($debugLevel -ge 3 ) {
88- Write-Host " [fragment-config.init] PathResolution import error details - Exception: $ ( $_.Exception.GetType ().FullName) , Message: $ ( $_.Exception.Message ) " - ForegroundColor DarkGray
89- }
90- }
91- }
92- }
93- }
71+ # Note: PathResolution uses Validation which requires FileSystemPathType from CommonEnums
72+ # CommonEnums should be imported early in the profile before this module is loaded
9473
9574# Import Logging for consistent output
9675# Logging is in scripts/lib/core/, not scripts/lib/fragment/
@@ -168,6 +147,29 @@ function Get-FragmentConfig {
168147 if (-not $ConfigPath ) {
169148 if (-not $ProfileDir ) {
170149 # Try to resolve from current context
150+ # Lazy-load PathResolution only when Get-ProfileDirectory is needed
151+ if (-not (Get-Command Get-ProfileDirectory - ErrorAction SilentlyContinue)) {
152+ # Try to import PathResolution if not already available
153+ $pathModulePath = Join-Path (Split-Path - Parent $PSScriptRoot ) ' path' ' PathResolution.psm1'
154+ if ($pathModulePath -and -not [string ]::IsNullOrWhiteSpace($pathModulePath ) -and (Test-Path - LiteralPath $pathModulePath )) {
155+ try {
156+ if (Get-Command Import-ModuleSafely - ErrorAction SilentlyContinue) {
157+ $null = Import-ModuleSafely - ModulePath $pathModulePath - ErrorAction SilentlyContinue
158+ }
159+ else {
160+ Import-Module $pathModulePath - ErrorAction SilentlyContinue - DisableNameChecking
161+ }
162+ }
163+ catch {
164+ # PathResolution import failed - non-fatal, will use fallback
165+ $debugLevel = 0
166+ if ($env: PS_PROFILE_DEBUG -and [int ]::TryParse($env: PS_PROFILE_DEBUG , [ref ]$debugLevel ) -and $debugLevel -ge 2 ) {
167+ Write-Verbose " [fragment-config.get] Failed to import PathResolution module: $ ( $_.Exception.Message ) . Using fallback path resolution."
168+ }
169+ }
170+ }
171+ }
172+
171173 if (Get-Command Get-ProfileDirectory - ErrorAction SilentlyContinue) {
172174 try {
173175 $ProfileDir = Get-ProfileDirectory - ScriptPath $PSScriptRoot
0 commit comments