-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fnm): Automatic version switching failed. (#1064)
- Loading branch information
Showing
1 changed file
with
47 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
export-env { | ||
def fnm-env [] { | ||
mut env_vars = {} | ||
let pwsh_vars = ( | ||
^fnm env --shell power-shell | | ||
lines | | ||
parse "$env:{key} = \"{value}\"" | ||
) | ||
|
||
# fnm-prefixed vars | ||
for v in ($pwsh_vars | slice 1..) { | ||
$env_vars = ($env_vars | insert $v.key $v.value) | ||
} | ||
|
||
# path | ||
let env_used_path = ($env | columns | where {str downcase | $in == "path"} | get 0) | ||
let path_value = ($pwsh_vars | get 0.value | split row (char esep)) | ||
$env_vars = ($env_vars | insert $env_used_path $path_value) | ||
|
||
return $env_vars | ||
} | ||
|
||
if not (which fnm | is-empty) { | ||
fnm-env | load-env | ||
|
||
$env.config = ( | ||
$env.config? | ||
| default {} | ||
| upsert hooks { default {} } | ||
| upsert hooks.env_change { default {} } | ||
| upsert hooks.env_change.PWD { default [] } | ||
) | ||
let __fnm_hooked = ( | ||
$env.config.hooks.env_change.PWD | any { try { get __fnm_hook } catch { false } } | ||
) | ||
if not $__fnm_hooked { | ||
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { | ||
__fnm_hook: true, | ||
code: {|before, after| | ||
if ('FNM_DIR' in $env) and ([.nvmrc .node-version] | path exists | any { |it| $it }) { | ||
(^fnm use); (fnm-env | load-env) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
export-env { | ||
def fnm-env [] { | ||
mut env_vars = {} | ||
let pwsh_vars = ( | ||
^fnm env --shell power-shell | lines | parse "$env:{key} = \"{value}\"" | ||
) | ||
|
||
# fnm-prefixed vars | ||
for v in ($pwsh_vars | slice 1..) { | ||
$env_vars = ($env_vars | insert $v.key $v.value) | ||
} | ||
|
||
# path | ||
let env_used_path = ($env | columns | where { str downcase | $in == "path" } | get 0) | ||
let path_value = ($pwsh_vars | get 0.value | split row (char esep)) | ||
$env_vars = ($env_vars | insert $env_used_path $path_value) | ||
|
||
return $env_vars | ||
} | ||
|
||
if not (which fnm | is-empty) { | ||
fnm-env | load-env | ||
|
||
$env.config = ( | ||
$env.config? | ||
| default {} | ||
| upsert hooks { default {} } | ||
| upsert hooks.env_change { default {} } | ||
| upsert hooks.env_change.PWD { default [] } | ||
) | ||
let __fnm_hooked = ( | ||
$env.config.hooks.env_change.PWD | any { try { get __fnm_hook } catch { false } } | ||
) | ||
if not $__fnm_hooked { | ||
$env.config.hooks.env_change.PWD = ( | ||
$env.config.hooks.env_change.PWD | append { | ||
__fnm_hook: true | ||
code: {|before, after| | ||
if ('FNM_DIR' in $env) and ([.nvmrc .node-version] | path exists | any {|it| $it }) { | ||
^fnm use | ||
} | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} |