NODE_PATH 被原子消耗,它取代了我已经存在的 NODE_PATH

NODE_PATH is consumed by atom, it replaces my already in place NODE_PATH

我在 windows 10 环境中为 Atom 文本编辑器编写插件,以允许 运行 通过量角器黄瓜从 Atom 中进行测试,它使用 PlatformIO-Terminal 插件提供的服务。当我从 Atom 中激活该终端插件时,我希望能够从它执行我可以从我的终端通过 pty 模拟的任何旧程序。

我在执行我在 Atom 的 apm 之外通过 npm 安装的任何节点程序时遇到问题。通过从该终端内打印环境变量 NODE_PATH 进一步挖掘,发现 Atom 已经吃掉了我的 NODE_PATH 值,不是附加它自己的值,而是完全消耗并替换了它。从 pty window 中重置它不起作用,从 PlatformIO 配置终端中将它添加到 "Shell Environment Variables" 也不起作用。我已经安装了 3 个允许从 OS 中提取环境变量的插件,其中 none 已成功。

有没有办法解决这个问题?我可以直接访问可执行模块,但它们会调用其他模块并依赖于 NODE_PATH.

如果您没有成功使用终端包,您可以尝试 process-palette。它允许您精确定义命令的所有细节,包括环境变量。我制作了一个 Atom 命令,在执行终端命令之前将 NODE_ENV 设置为任意字符串。截图如下:

下面是一个 process-palette.json 文件,它定义了我编写的命令。您需要做的就是开始安装包,使用以下代码制作该文件,然后 select Packages -> Process Palette -> Edit Configuration.

{
  "patterns": {
    "P1": {
      "expression": "(path):(line)"
    },
    "P2": {
      "expression": "(path)\s+(line)",
      "path": "(?:\/[\w\.\-]+)+"
    }
  },
  "commands": [
    {
      "namespace": "process-palette",
      "action": "env",
      "command": "echo %NODE_PATH%",
      "arguments": [],
      "cwd": null,
      "inputDialogs": [],
      "env": {
        "NODE_PATH": "wargarble"
      },
      "keystroke": null,
      "stream": true,
      "outputTarget": "panel",
      "outputBufferSize": 80000,
      "maxCompleted": 3,
      "autoShowOutput": true,
      "autoHideOutput": false,
      "scrollLockEnabled": false,
      "singular": false,
      "promptToSave": true,
      "saveOption": "none",
      "patterns": [
        "default"
      ],
      "successOutput": "{stdout}",
      "errorOutput": "{stdout}\n{stderr}",
      "fatalOutput": "Failed to execute : {fullCommand}\n{stdout}\n{stderr}",
      "startMessage": null,
      "successMessage": "Executed : {fullCommand}",
      "errorMessage": "Executed : {fullCommand}\nReturned with code {exitStatus}\n{stderr}",
      "fatalMessage": "Failed to execute : {fullCommand}\n{stdout}\n{stderr}",
      "menus": [
        "env"
      ],
      "startScript": null,
      "successScript": null,
      "errorScript": null,
      "scriptOnStart": false,
      "scriptOnSuccess": false,
      "scriptOnError": false,
      "notifyOnStart": false,
      "notifyOnSuccess": true,
      "notifyOnError": true,
      "input": null
    }
  ]
}