prettier / pretty-quick

⚡ Get Pretty Quick
https://npm.im/pretty-quick
MIT License
2.2k stars 82 forks source link

pretty-quick will break with prettier v3 #164

Closed joshwooding closed 6 months ago

joshwooding commented 1 year ago

Not an issue right now, but pretty-quick will break with v3 due to the removal of resolveConfig.sync (https://github.com/prettier/prettier/pull/12788).

omarkhatibco commented 1 year ago

I can confirm this issue as well

meabed commented 1 year ago

Yes it breaks

/pretty-quick/dist/isSupportedExtension.js:12
  ..._prettier.resolveConfig.sync(file, {
                             ^

TypeError: _prettier.resolveConfig.sync is not a function
li-jia-nan commented 1 year ago

mark

johnhunter commented 1 year ago

Just experienced this too.

emanuelasistensi commented 1 year ago

Same problem

johnhunter commented 1 year ago

Dependabot / Renovate bots mean this is going to hit a lot of people now when they rebase and try and commit.

steveariss commented 1 year ago

Joining the club. Experiencing same problem

jakubwolny commented 1 year ago

We had the same issue - the solution was to switch back to lint-staged, as described in: https://prettier.io/docs/en/precommit.html

steveariss commented 1 year ago

You didn't have the same problem?

The issue seems to be with Prettier v3.

I tried switching to Lint-staged and it also doesn't seem to be happy with Prettier v3.

My fix for now is to stick with Prettier v2.8.8

jakubwolny commented 1 year ago

interesting - after following the https://github.com/okonet/lint-staged#installation-and-setup for lint-staged it seems to be working, I don't have any issues with prettier@3

imho it makes sense because lint-staged makes it possible to run anything: i.e. just "prettier" command, it doesn't rely on any prettier internals (like pretty-quick does)

steveariss commented 1 year ago

I'll give it another try. I did give up on troubleshooting pretty quick :P

meabed commented 1 year ago

Seems the library is not maintained? How about forking and fixing?

dwiyatci commented 1 year ago

Seems the library is not maintained?

Maybe it still is? It could be that the author @azz only needs more time and prioritises this? 🤞 🙏 😇

mgabeler-lee-6rs commented 1 year ago

Threw together #165 as a first attempt at supporting 3.0. I don't know if those changes are 100%, nor if they will still work with 2.x, but it's a start

LukasKlement commented 1 year ago

The last release was more than 1.5 years ago, the lint-staged package is a viable alternative that supports prettier v3 already: https://github.com/okonet/lint-staged

LautaroJayat commented 1 year ago

If you are using npx you can just use something like:

npx -p prettier@^2 -p pretty-quick pretty-quick
ptpaterson commented 1 year ago

Dependabot / Renovate bots mean this is going to hit a lot of people now when they rebase and try and commit.

Yep, this happened to me.

cope commented 1 year ago

Same here :(

> pretty-quick --staged --pattern "src/**/*.ts"
🔍  Finding changed files since git revision 83ec8716.
C:\git\projects\server\node_modules\.pnpm\pretty-quick@3.1.3_prettier@3.0.0\node_modules\pretty-quick\dist\isSupportedExtension.js:12
  ..._prettier.resolveConfig.sync(file, {
                             ^
TypeError: _prettier.resolveConfig.sync is not a function
    at C:\git\projects\server\node_modules\.pnpm\pretty-quick@3.1.3_prettier@3.0.0\node_modules\pretty-quick\dist\isSupportedExtension.js:12:30
    at Array.filter (<anonymous>)
    at _default (C:\git\projects\server\node_modules\.pnpm\pretty-quick@3.1.3_prettier@3.0.0\node_modules\pretty-quick\dist\index.js:53:157)
    at Object.<anonymous> (C:\git\projects\server\node_modules\.pnpm\pretty-quick@3.1.3_prettier@3.0.0\node_modules\pretty-quick\bin\pretty-quick.js:17:27)
    at Module._compile (node:internal/modules/cjs/loader:1267:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47
Node.js v20.0.0
 ELIFECYCLE  Command failed with exit code 1.
husky - pre-commit hook exited with code 1 (error)
MrSwitch commented 1 year ago

Or without pretty-quick, replacing the line in Husky(other task runners are available)'s ./.husky/pre-commit with...

LIST=`git diff-index --name-only --cached HEAD`; if [ "$LIST" ]; then npx prettier --write $LIST; git add $LIST; fi

UPDATE use --cached to only check cached files.

ggualiato commented 1 year ago

Or without pretty-quick, replacing the line in Husky(other task runners are available)'s ./.husky/pre-commit with...

LIST=`git diff-index --name-only HEAD`; if [ "$LIST" ]; then npx prettier --write $LIST; git add $LIST; fi

It doesn't work, this solution adds to the commit all the changed files, and not only the staged ones.

MrSwitch commented 1 year ago

It doesn't work, this solution adds to the commit all the changed files, and not only the staged ones.

Brutal! Updated with flag --cached

ggualiato commented 1 year ago

It doesn't work, this solution adds to the commit all the changed files, and not only the staged ones.

Brutal! Updated with flag --cached

Now it works better, but if you're using the --staged flag from pretty-quick, it will not have the same behaviour

murtuzaalisurti commented 11 months ago

facing the same issue, moved to lint-staged for this reason

bennycode commented 7 months ago

I replaced pretty-quick (because it is incompatible with Prettier v3) with lefthook.

Here is a PR of mine that shows how to migrate to lefthook: https://github.com/bennycode/ts-node-starter/pull/601/files

Kordrad commented 6 months ago

I am working on a CLI tool to automatically configure projects. I decided to change pretty-quick in favor of lint-staged, precisely because lint-staged works perfectly without any problems.

If anyone wants to see the configuration files they can be found here: .husky/pre-commit .lintstagedrc package.json

JounQin commented 6 months ago

I don't know why you haven't made it work, but I can offer some help or raise a PR for it.

Two options:

  1. keep commonjs w/wo synckit
  2. migrate to pure ESM

What do you prefer?


Just found #165

JounQin commented 6 months ago

See https://github.com/prettier/pretty-quick/pull/165#issuecomment-1891463129

I'll take over @azz's place and help to maintain this package in few days. 🍻

bennycode commented 6 months ago

I am working on a CLI tool to automatically configure projects. I decided to change pretty-quick in favor of lint-staged, precisely because lint-staged works perfectly without any problems.

Another option would be using "lefthook": https://typescript.tv/hands-on/typeerror-prettierresolveconfigsync-is-not-a-function/#replacing-pretty-quick-with-lefthook

murtuzaalisurti commented 6 months ago

moved to lint-staged just because of this issue

JounQin commented 6 months ago

I have to reset the related PR #165 because it is full of bugs actually...

I'll rewrite the whole package with TypeScript.

JounQin commented 6 months ago

I've just finished my promise.

pretty-quick v4 has just been released with prettier v3 support! Thanks @SukkaW for helping as always! ❤️

taylorkline commented 1 month ago

Should prettier/prettier#15337 be reverted and pretty-quick be added back to the docs of pre-commit solutions?