prettier icon indicating copy to clipboard operation
prettier copied to clipboard

@prettier/next: Prettier 4 does not resolve `prettier` key in package.json when importing external configs

Open boyum opened this issue 2 years ago • 6 comments

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:

  1. Clone https://github.com/boyum/prettier-resolve-issue
  2. Install dependencies
  3. Run npm run format:check
  4. 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.

boyum avatar Dec 01 '23 10:12 boyum

Ah interesting, I missed this detail, I'll get it fixed :+1:

fabiospampinato avatar Dec 16 '23 15:12 fabiospampinato

Thanks!

(I have since added plugins to the package, but that shouldn't matter. In any case you can use v1.0.0.)

boyum avatar Dec 16 '23 21:12 boyum

@boyum it should be implemented in v4-alpha8, could you check if it works for you?

fabiospampinato avatar Dec 22 '23 14:12 fabiospampinato

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.

boyum avatar Dec 23 '23 16:12 boyum

It sounds like there is some bug 🤔 I'll look into it, thanks 👍

fabiospampinato avatar Dec 23 '23 17:12 fabiospampinato

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 👍

fabiospampinato avatar Apr 19 '24 18:04 fabiospampinato