@prettier/next: Prettier 4 does not resolve `prettier` key in package.json when importing external configs
In earlier versions of the Prettier CLI, it is possible to set a string value to the prettier property in package.json. If a string is set, the CLI will use that dependency's exported main field (or something like that) as a Prettier config (documentation). This does not work in Prettier 4.
Environments:
- Prettier Version: 4.0.0-alpha.3
- Running Prettier via: CLI
- Runtime: Node v20.2.0
- Operating System: macOS Sonoma 14.1.1
- Prettier plugins (if any): N/A
Steps to reproduce:
- Clone https://github.com/boyum/prettier-resolve-issue
- Install dependencies
- Run
npm run format:check - See that there are code style issues in
index.js, even though the file follows the rules set in https://github.com/boyum/prettier-config/blob/main/index.json
Expected behavior:
The Prettier CLI implements this behaviour: https://prettier.io/docs/en/configuration#sharing-configurations
Actual behavior:
It does not read external configurations, but falls back to the default configuration.
Ah interesting, I missed this detail, I'll get it fixed :+1:
Thanks!
(I have since added plugins to the package, but that shouldn't matter. In any case you can use v1.0.0.)
@boyum it should be implemented in v4-alpha8, could you check if it works for you?
Hmm I can't seem to get it working - it still assumes arrowParens: always, even though it's explicitly set to avoid in the config. I might be doing something wrong?
From the same project:
➜ prettier-resolve-issue git:(main) ✗ npm i [email protected] --save-exact && npm run format:check
up to date, audited 45 packages in 542ms
3 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
> [email protected] format:check
> prettier --check .
Checking formatting...
[warn] index.js
[warn] Code style issues found in 1 file. Run Prettier to fix.
It sounds like there is some bug 🤔 I'll look into it, thanks 👍
This issue will be fixed in the next release and can be closed.
The fix was this, basically I've never seen a package pointing to a non-javascript file in its main field, so I didn't think about accounting for that, I'm not actually sure if that's something that Node itself supports too, but I guess no reason to break something that works in the v3 CLI 👍