jscheid / prettier.el

Prettier code formatting for Emacs.
GNU General Public License v3.0
164 stars 11 forks source link

Fix prettier detection in yarn workspaces with PnP #47

Closed jscheid closed 3 years ago

jscheid commented 3 years ago

Closes #46

@asbish I think this should work, but need to test it more with older Node versions etc.

Curious to hear what you think of it.

asbish commented 3 years ago

Thank you very much @jscheid, I totally agree. I've checked below three cases in Node v12.19.0 and these work correctly under this commit.

1.

workspace/package.json # `"dependencies": {"prettier: "2.1.2"}, "workspaces": ["child", "child1"]`
workspace/child/package.json # `"dependencies": {}`
workspace/child1/package.json # `"dependencies": {}`

2.

workspace/package.json # `"dependencies": {}, "workspaces": ["child", "child1"]`
workspace/child/package.json # `"dependencies": {"prettier: "2.1.2"}`
workspace/child1/package.json # `"dependencies": {}`

3.

workspace/package.json # `"dependencies": {}, "workspaces": ["child", "child1"]`
workspace/child/package.json # `"dependencies": {"prettier: "2.1.2"}`
workspace/child1/package.json # `"dependencies": {"prettier: "2.1.0"}`

I didn't expect there was a possibility that a project would have several prettier versions then. One of the reasons was yarn pnpify --sdk command only supports root package.json. By the way, if .yarn/sdks/prettier the command generates is changed, we'll need to add some fix to prettier.el.

jscheid commented 3 years ago

@asbish thank you for the thoughtful review. I've been dogfooding this (via the branch tarball) and might do so for a couple days longer before I merge this, just to be extra sure it doesn't break anything.

By the way, if .yarn/sdks/prettier the command generates is changed, we'll need to add some fix to prettier.el.

I wasn't aware of the yarn sdk command until now, I'm going to take a closer look.