Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

activate.fish erases a pre-existing NODE_PATH and never restores it

未关闭 适合新手
#399 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
fish, python
领域
tooling

调研方向

从 bin/activate.fish 开始,重点关注 deactivate_node 的初始非破坏性处理,以及 NODE_PATH 和两个前缀变量的恢复逻辑。运行 tests/test_activate_shells.py 中受影响的测试,并在该测试对 Fish 通过后移除其 FISH_NODE_PATH_CLOBBER xfail 设置;完成标准是停用后所有原有值都得到恢复。

由索引模型根据 Issue 内容生成。

描述

bug

Summary

Sourcing bin/activate.fish destroys a NODE_PATH the user already had
set. deactivate_node then has nothing to restore, so the variable is gone
for good. NPM_CONFIG_PREFIX and npm_config_prefix have the same defect.

Reproduction

$ nodeenv --prebuilt /tmp/ne
$ fish -c 'set -gx NODE_PATH /my/node_path
           source /tmp/ne/bin/activate.fish
           deactivate_node
           echo "NODE_PATH=[$NODE_PATH]"'
NODE_PATH=[]

Expected NODE_PATH=[/my/node_path], which is what the POSIX bin/activate
does under sh, dash and bash.

Cause

activate.fish calls deactivate_node nondestructive near the top, before
the activation code has saved anything:

# unset irrelevant variables
deactivate_node nondestructive

On that pass _OLD_NODE_PATH is empty, so deactivate_node takes its else
branch and erases the variable:

if test -n "$_OLD_NODE_PATH"
    set -gx NODE_PATH $_OLD_NODE_PATH
    set -e _OLD_NODE_PATH
else
    set -e NODE_PATH
end

The activation code that runs afterwards therefore sees set -q NODE_PATH
as false, never records _OLD_NODE_PATH, and the user's value is lost:

if set -q NODE_PATH
    set -gx _OLD_NODE_PATH $NODE_PATH
    set -gx NODE_PATH "$NODE_VIRTUAL_ENV/lib/node_modules" $NODE_PATH
else
    set -gx NODE_PATH "$NODE_VIRTUAL_ENV/lib/node_modules"
end

b042056 ("fix(nodeenv): guard fish npm config restore") already fixed
exactly this disease, but only for the --isolate-npm variables, by
wrapping the restore in a guard:

# Skip the "deactivate_node nondestructive" pass at the top of
# activate.fish: the variables are only saved after it has run
if set -q NODE_VIRTUAL_ENV

NODE_PATH and the NPM_CONFIG_PREFIX / npm_config_prefix pair never got
that guard.

Scope of the fix

All three variable groups, not just NODE_PATH. The prefix pair is affected
identically; it only looks fine today because the test asserts NODE_PATH
first and stops there.

Test coverage

tests/test_activate_shells.py (added in #397) marks this
xfail(strict=True) as FISH_NODE_PATH_CLOBBER on
test_deactivate_restores_env, via the restoring_shell decorator. When the
fix lands, drop the constant and the decorator and put the test back on
@activating_shell.

主要语言
Python
星标
1.8k
派生
224
平均合并
10 小时 52 分钟
30 天内合并 PR
23

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ekalinin/nodeenv 的其他 Issue

查看 ekalinin/nodeenv 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。