chore(compiler-sfc): specify prettier version (fix #13052)
Created by: ShGKme
close: #13052 (closed)
What kind of change does this PR introduce? (check at least one)
-
Bugfix -
Feature -
Code style update -
Refactor -
Build-related changes -
Other, please describe:
Does this PR introduce a breaking change? (check one)
-
Yes -
No
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
-
It's submitted to the main
branch for v2.x (or to a previous version branch) -
When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx]
, where "xxx" is the issue number) -
All tests are passing: https://github.com/vuejs/vue/blob/dev/.github/CONTRIBUTING.md#development-setup -
New/updated tests are included
If adding a new feature, the PR's description includes:
-
A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)
Other information:
@vue/compiler-sfc
optionally uses Prettier and it is not compatible with Prettier v3.
But prettier
is not listed in the package.json
.
It wasn't a problem with Prettier v2 because prettier is optional dependency of component-compiler-utils
. So Prettier is installed anyway and everything works.
But if some project has Prettier@3
, then @vue/compiler-sfc
uses project's prettier and fails.
There was the same issue early in component-compiler-utils. See:
- https://github.com/vuejs/component-compiler-utils/commit/aea1b79765f0f6d688e64b7698d5ff62862002d1
- https://github.com/vuejs/component-compiler-utils/pull/89
This PR specifies Prettier as an optionalDependency
of @vue/compiler-sfc
. With specified dependency, it will use prettier@2
even if a project has prettier@3
.
P.S. I used the same versions as it was in the component-compiler-utils
. It seems it has the same code.
Alternative solution: make @vue/compiler-sfc
compatible with both Prettier@"1 || 2"
and Prettier@3
. The problem is that it will make the compile function async.