Add prettier caching (#2212)

Adds `--cache` flag to prettier which significantly speeds up `yarn
format`:
https://prettier.io/docs/en/cli#--cache

One downside is that changing the plugins we use with prettier will not
cause the cache to invalidate. Stills seems worth it though.

> Plugins version and implementation are not used as cache keys. We
recommend that you delete the cache when updating plugins.

### Change Type

- [ ] `patch` — Bug fix
- [ ] `minor` — New feature
- [ ] `major` — Breaking change
- [ ] `dependencies` — Changes to package dependencies[^1]
- [ ] `documentation` — Changes to the documentation only[^2]
- [ ] `tests` — Changes to any test code only[^2]
- [x] `internal` — Any other changes that don't affect the published
package[^2]
- [ ] I don't know

[^1]: publishes a `patch` release, for devDependencies use `internal`
[^2]: will not publish a new version

### Test Plan

1. Run `yarn format`
2. Run `yarn format` again, this time it should be significantly faster.

### Release Notes

- Speed up formatting of files via `yarn format`.
This commit is contained in:
Mitja Bezenšek 2023-11-14 10:06:52 +01:00 committed by GitHub
parent 64451bf4d7
commit 9e7d258b5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View file

@ -43,7 +43,7 @@
"build-api": "lazy build-api", "build-api": "lazy build-api",
"build-package": "lazy build-package", "build-package": "lazy build-package",
"lint": "lazy lint", "lint": "lazy lint",
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json}\"", "format": "prettier --write --cache \"**/*.{ts,tsx,js,jsx,json}\"",
"typecheck": "yarn refresh-assets && tsx scripts/typecheck.ts", "typecheck": "yarn refresh-assets && tsx scripts/typecheck.ts",
"check-scripts": "tsx scripts/check-scripts.ts", "check-scripts": "tsx scripts/check-scripts.ts",
"api-check": "lazy api-check", "api-check": "lazy api-check",
@ -56,7 +56,7 @@
"packageManager": "yarn@3.5.0", "packageManager": "yarn@3.5.0",
"lint-staged": { "lint-staged": {
"*.{js,jsx,ts,tsx,json}": [ "*.{js,jsx,ts,tsx,json}": [
"prettier --write" "prettier --write --cache"
] ]
}, },
"devDependencies": { "devDependencies": {

View file

@ -34,7 +34,7 @@
"test": "lazy inherit", "test": "lazy inherit",
"test-coverage": "lazy inherit", "test-coverage": "lazy inherit",
"index": "node ./scripts/build-index.js && yarn format", "index": "node ./scripts/build-index.js && yarn format",
"format": "yarn run -T prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"", "format": "yarn run -T prettier --write --cache \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
"build": "yarn run -T tsx ../../scripts/build-package.ts", "build": "yarn run -T tsx ../../scripts/build-package.ts",
"build-api": "yarn run -T tsx ../../scripts/build-api.ts", "build-api": "yarn run -T tsx ../../scripts/build-api.ts",
"prepack": "yarn run -T tsx ../../scripts/prepack.ts", "prepack": "yarn run -T tsx ../../scripts/prepack.ts",

View file

@ -54,6 +54,7 @@ async function main() {
'-T', '-T',
'prettier', 'prettier',
shouldFix ? '--write' : '--check', shouldFix ? '--write' : '--check',
'--cache',
...prettierFiles, ...prettierFiles,
]) ])
await exec('yarn', [ await exec('yarn', [