prettier_d_slim
prettier_d_slim copied to clipboard
Support setting path to prettier in CLI
The eslint_d CLI allows you to set --eslint-path which is helpful when using things like yarn pnp sdks which wires modules together in a non-standard way. It would be nice to support a --prettier-path CLI option or similar.
https://github.com/mantoni/eslint_d.js/issues/174 https://github.com/mantoni/eslint_d.js/issues/177
Good idea, I'm not familiar with yarn pnp, would the path you're passing with --prettier-path be the path to a directory containing the whole prettier package, or directly to a .js file?
Or does that not really matter, as long as you can pass something.
tl;dr: The entry file for the prettier JS api.
Yarn's Plug'n'Play (pnp) system keeps modules in zip files in a cache directory, then does some runtime magic to make things work. This means there is no node_modules directory. This means projects take up less hard drive space, but it also has some unfortunate side effects (like everything living in zip files).
They built an sdks feature which gives you back some files on disk that will link into those zips so that editor plugins have a foothold into this weird setup. For prettier, it looks like this:
▾ .yarn/
▸ cache/
▸ plugins/
▸ releases/
▾ sdks/
▸ eslint/
▾ prettier/
index.js*
package.json
▸ typescript/
integrations.yml
▸ unplugged/
install-state.gz
If you import that index.js file, you'll get access to the prettier JS api:
console.log(require('./.yarn/sdks/prettier'));
// -> { formatWithCursor: [Function], ... }
or
console.log(require('./.yarn/sdks/prettier/index.js'));
// -> { formatWithCursor: [Function], ... }
For eslint and typescript they also expose the bin files, but not prettier. I bet yarn would accept a PR to add that if needed.