nova-prettier icon indicating copy to clipboard operation
nova-prettier copied to clipboard

Not finding prettier in pnpm monorepo unless packages.json workspace config also present

Open battis opened this issue 5 months ago • 0 comments

This is a variation on #94, I think. Here's the setup:

  • Working in a monorepo with the workspace configured in pnpm-workspace.yaml and not in package.json
  • @battis/prettier-config is installed and configured in the root package.json, but none of the workspace packages
  • The prettier module config is blank both globally and for the project

With this config, the actual prettier module is...

  • Installed in pnpm's cache elsewhere on disk
  • A symlink to that installation is present at <monorepo-root>/node_modules/prettier
  • No prettier module is present in any subpackage node_modules directory
  • within the repo, I can invoke prettier at the command line with npx prettier -w <path-to-file>

I had tweaked @battis/prettier-config to add a few more prettier plugins, and then all of a sudden things started getting erased on save. Which really cramped my style in TypeScript! I happened to be working on a file in a subpackage of the monorepo.

  • My initial assumption was that it was just one of the prettier plugins I had just installed, but it turned out that running prettier from the command line and through the Nova UI had different end results (and my angle brackets only disappeared in the UI) -- and the extension console confirmed that the bundled prettier was being loaded.
  • When I manually set the prettier module in the extension to the path to the symlink in the root node_modules, the Prettier extension leaves my angle brackets unmolested -- and the extension console confirmed that the package prettier was loaded.
  • Operating on the theory that maybe, because neither a prettier configuration nor prettier was present in the subpackage, we were reverting to the packaged prettier instance and configuration, I installed @battis/prettier-config and prettier in the subpackage. My angle brackets still disappeared -- and the extension console confirmed the bundled prettier was being loaded.

In the end, when I added my workspace configuration to the root package.json in the monorepo, the extension did identify the locally installed prettier module and prettier configuration and worked.

battis avatar Sep 13 '24 12:09 battis