Skip to content

feat: Only format changed files with Prettier - #670

Merged
Lms24 merged 5 commits into
masterfrom
onur/prettier-on-changed
Oct 9, 2024
Merged

Lms24 merged 5 commits into
masterfrom
onur/prettier-on-changed

Conversation

@onurtemizkan

@onurtemizkan onurtemizkan commented Sep 11, 2024 •

Copy link
Copy Markdown
Contributor

Following up on #644

Formatting changed/untracked files only with Prettier.

@onurtemizkan
onurtemizkan requested a review from Lms24 September 11, 2024 08:46
@github-actions

github-actions Bot commented Sep 11, 2024 •

Copy link
Copy Markdown
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 32a1311

Comment thread src/utils/clack-utils.ts Outdated
}
});
childProcess.exec(
`npx prettier --write ${prettierSupportsCache ? '--cache' : ''} .`,

@Lms24 Lms24 Sep 19, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work if users themselves didn't use --cache before? Reading the documentation, I'm not sure because it sounds like a cache already needs to be populated so that a file is skipped.

I'm not really worried about the performance aspect but rather that we format files that users (for whatever reason) haven't formatted before or don't want formatted.

If --cache works for first-time use, no worries, we can use it! Otherwise: We already have some logic around detecting new and changed files via git at the beginning of the wizard. Maybe we could re-use that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. I thought a cache was populated anyway via regular prettier use. But it looks like it was a leftover.

I have switched to using git. Thanks for pointing that out!

@onurtemizkan onurtemizkan changed the title feat: Use Prettier's cache option to only format files that are modified / created feat: Only format changed files with Prettier Sep 20, 2024

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it with a SvelteKit project. Worked like a charm. Thanks Onur (and sorry for the wait, I was ooo last week).

@Lms24
Lms24 merged commit db21946 into master Oct 9, 2024
@Lms24
Lms24 deleted the onur/prettier-on-changed branch October 9, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants