I'd expect nx to use the installed prettier version for formatting.
Running prettier or nx format on the command line for the same file should yield the SAME results.
Nx uses a fixed internal version of prettier and ignores the installed prettier version
E.g. use else in an Angular template
<div *ngIf="someBoolean; else otherTemplate">
</div>
now the following checks should yield the same result:
$ nx format:check --files login.component.html
$ prettier -c login.component.html
But since nx version 8.5.0 uses an older version of prettier (1.16.4), the results are inconsistent.
When nx uses the installed prettier version this can avoid
Notes:
nx format docs should mention that nx ignores the installed prettier versionThis is inconsistency is confusing and detrimental to the dev experience. Unfortunately, the team probably won't get to this anytime soon. Would someone in the community be interested in working on a fix?
Ping @FrozenPandaz. I will take a look into this today and open a PR to fix this
PR #1869 does not fix the issue at all: you just updated the internal prettier version to 1.18.2..
@tmtron Sorry, you're right - the PR shouldn't have closed this issue. It's a temporary band aid for now.
Personally, I would be very surprised if a project used my globally installed version of a tool rather than the package-local version. The current behavior is exactly what I would expect. Running prettier (globally installed) vs. running yarn prettier (or nx format:check in this case) mean different things. Is this more of a documentation opportunity rather than a code/behavior change?
Maybe I am in the minority here and checking for a globally installed version of something to take precedence over a package-local version is more conventional than I realize. If so, can someone point to a common/popular example of where this happens? Always happy to educate myself.
Thanks.
@wKovacs64 : Good point!
One thing I did not explain exactly, is that our prettier version is not really installed globally, but in the project (node_modules).
So in our case, we had specified a prettier version in our package.json and were very surprised that nx does not use this version.
Is see pros for both ways:
internal prettier version:
external prettier version:
I think this would be ideal
Ah, based on that above info, I think maybe this item should be titled something more like:
“Make prettier a peerDependency instead of a dependency”
I don't know if this is a good idea or if the Nx team wants it, but it's much more plausibly good than the earlier interpretation "use the globally installed prettier" that a bunch of us immediately dismissed.
Would be great if NX could use the projects prettier version.
Atm we are using prettier: 1.19.1
[email protected] /home/the_ult/dev/bereslim/bsm-ui
├─┬ @nrwl/[email protected]
│ └── [email protected]
└── [email protected]
(which is know for this bug: https://github.com/prettier/prettier/issues/6921)
In VsCode (and running tslint with "tslint-plugin-prettier","tslint-config-prettier")
causes
stream1$.pipe(
withLatestFrom(stream2$),
distinctUntilChanged(),
debounceTime(50)
)
to be formatted to
stream1$.pipe(withLatestFrom(stream2$), distinctUntilChanged(), debounceTime(50));
But running npm run format reformats it to:
stream1$.pipe(
withLatestFrom(stream2$),
distinctUntilChanged(),
debounceTime(50)
)
On the one hand this is great. But on the other it creates unexpected output. Since it differs from what happens with VSCode and Tslint (in combination with prettier).
I would expect the result of npm run format and npm run prettier to be the same.
Most helpful comment
Ah, based on that above info, I think maybe this item should be titled something more like:
“Make prettier a peerDependency instead of a dependency”
I don't know if this is a good idea or if the Nx team wants it, but it's much more plausibly good than the earlier interpretation "use the globally installed prettier" that a bunch of us immediately dismissed.