Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting path to prettier in CLI #12

Open
shannonmoeller opened this issue Nov 23, 2021 · 2 comments
Open

Support setting path to prettier in CLI #12

shannonmoeller opened this issue Nov 23, 2021 · 2 comments

Comments

@shannonmoeller
Copy link
Contributor

shannonmoeller commented Nov 23, 2021

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.

mantoni/eslint_d.js#174
mantoni/eslint_d.js#177

@mikew
Copy link
Owner

mikew commented Nov 24, 2021

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.

@shannonmoeller
Copy link
Contributor Author

shannonmoeller commented Nov 24, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants