Discourse Theme CLI 在使用 pnpm 安装的 node_modules 时由于符号链接而出错

当在一个主题组件仓库中运行 Discourse Theme CLI,并且已安装 pnpm node_modules 时,discourse_theme watch . 命令会返回关于 node_modules/.pnpm 目录已被监视的错误。粗略一看,这是由于包被符号链接所致。

我已在一个新的 GitHub Codespace 中使用官方 mermaid TC 和 discourse_theme v2.1.3 进行了测试。

错误日志摘录
** ERROR: directory is already being watched! **

Directory: /workspaces/discourse-mermaid-theme-component/node_modules/.pnpm/ember-template-recast@6.1.5/node_modules/@glimmer/reference

is already being watched through: /workspaces/discourse-mermaid-theme-component/node_modules/.pnpm/@glimmer+reference@0.84.3/node_modules/@glimmer/reference

MORE INFO: https://github.com/guard/listen/blob/master/README.md
** ERROR: directory is already being watched! **

Directory: /workspaces/discourse-mermaid-theme-component/node_modules/.pnpm/@humanwhocodes+retry@0.3.1/node_modules/@humanwhocodes/retry

is already being watched through: /workspaces/discourse-mermaid-theme-component/node_modules/.pnpm/@humanwhocodes+retry@0.3.1/node_modules/@humanwhocodes/retry

MORE INFO: https://github.com/guard/listen/blob/master/README.md

我怀疑这与 discourse_theme 监视整个目录而没有忽略 node_modules/.pnpmnode_modules 的情况有关。

这不是一个大问题,因为在出现错误后 discourse_theme watch 似乎工作正常,但我没有看到本应来自 https://github.com/discourse/discourse_theme/blob/main/lib/discourse_theme/watcher.rb#L45-L48 的“Watching for changes…”消息,这可能会造成一些困惑。此外,从 npm/yarn 迁移到 pnpm 后,看到 CLI 在屏幕上抛出大量错误,感觉并不好。

3 个赞

通常,我从 discourse 目录运行这个命令,但会监视主题代码文件夹,类似这样:

discourse_theme watch ~code/my-new-theme

你从同一个文件夹运行它的原因是什么?

我怀疑这是否是导致你出现问题的原因?:thinking:

我直接在 TC 目录内使用它,因为我通常会在本地开发实例、非本地的论坛开发副本或主题创建者站点(API 密钥生成器最近似乎不起作用)上开发/测试主题。我试图避免混淆我正在处理哪个环境。

我将 mermaid TC git 克隆到与新安装的 discourse codespace 相同的 codespace 中,并尝试从 discourse 目录运行 discourse_theme watch。它给出了相同的错误。

这没关系,但没有什么能阻止你在另一个终端标签页中运行它……并且从 discourse 目录运行?

当然是任意的,但当正在测试的 discourse 实例不是本地实例时,需要从 discourse 的本地克隆运行 discourse_theme 来说有点太荒谬了。

无论如何,我已经按照您的建议进行了操作,在新的 github codespace 和我自己的开发环境中都进行了操作,但仍然出现相同的错误。


通过阅读所有日志(或所有能装进终端历史记录的日志),它出错的所有目录都是 /node_modules/.pnpm。在测试和运行 discourse_theme 时,我遇到了一个尚未更新为使用 pnpm 而不是 yarn 的 TC,我没有看到任何错误,所以我几乎 100% 确定问题在于它正在监视 .pnpm

Symlinked `node_modules` structure | pnpm 来看,它看起来像 node_modules 的正常结构是通过将所有实际代码移动到 /node_modules/.pnpm 来保留的,而 /node_modules/ 中的其余目录只是指向 .pnpm 的符号链接。因此,忽略 .pnpm 可以避免“目录已在监视!”错误。

我稍微玩了一下 discourse_theme gem,并在 watcher.rb 中添加了 listener.ignore /node_modules\\/\\.pnpm/,它似乎运行正常,没有任何错误消息。它甚至检测到了新安装的 pnpm 包。

3 个赞

此 PR 将应用忽略规则,并消除警告。感谢 @Alteras 创建此主题并进行调查——这些警告也一直让我很烦恼!:sweat_smile:

4 个赞

此主题在上次回复后 30 天自动关闭。不再允许回复。