When running the Discourse Theme CLI in a theme component repo with pnpm node_modules installed, the discourse_theme watch . command will return errors about node_modules/.pnpm directories already being watched. At a cursory glance, this due to the packages being symlinked.
I have tested this in a fresh GitHub Codespace using the official mermaid TC, using discourse_theme v2.1.3.
Excerpt of error logs
** 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
I suspect it has to do with discourse_theme watching the whole directory without any ignores for node_modules/.pnpm or node_modules in general.
It’s not a major issue since discourse_theme watch seems to work just fine after the errors, but I’m not seeing the "Watching for changes..." message after the errors that’s supposed to come from https://github.com/discourse/discourse_theme/blob/main/lib/discourse_theme/watcher.rb#L45-L48, so it could cause some confusion. Plus, it doesn’t feel great moving from npm/yarn to pnpm to only see the CLI throw a bunch of errors onto the screen.
I use it from within the TC directory itself since I’m usually developing/testing the theme either against my local dev instance, a dev copy of the forum not on my machine, or the Theme Creator site (which the API key generator doesn’t seem to be working lately). Trying to avoid getting confused about which environment I’m working in.
I’ve git cloned the mermaid TC into the same codespace as a fresh discourse codespace install and tried to run the discourse_theme watch from the discourse directory instead. Gives the same errors.
Certainly its arbitrary, but its a bit ridiculous to need to run the discourse_theme from a local clone of discourse when the discourse instance being tested is not the local instance.
Anyway, I have done as you suggested, both in a fresh github codespace, and in my own dev environment, and it still throws the same errors.
Reading through all of the log (or all the ones that will fit in the terminal history), all the directories it is erroring on is /node_modules/.pnpm. Testing and running discourse_theme against a different TC that has yet to be updated to use pnpm instead of yarn, I don’t see any errors, so I’m almost 100% certain the issue is with it watching .pnpm.
From Symlinked `node_modules` structure | pnpm, it looks like the normal structure of node_modules is preserved by moving all the actual code into /node_modules/.pnpm and the rest of directories in /node_modules/ are just symlinks to .pnpm. So ignoring .pnpm avoids the “directory is already being watched!” error.
I’ve played a bit with the discourse_theme gem and added listener.ignore /node_modules\/\.pnpm/ to the watcher.rb, and it seems to work fine without any error messages. It even detected a new pnpm package install.