Skip to content

Commit f1cacb2

Browse files
authoredJan 17, 2024
feat!: support prettier v3 (#182)
1 parent 5055759 commit f1cacb2

26 files changed

+4853
-5197
lines changed
 

‎.changeset/real-shirts-share.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"pretty-quick": major
3+
---
4+
5+
feat!: support prettier v3

‎.github/workflows/ci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010
strategy:
1111
matrix:
1212
node:
13-
- 10
14-
- 12
1513
- 14
1614
- 16
1715
- 18

‎.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dist
1+
lib
22
node_modules
33
*.log
44
/.yarn/*

‎.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
coverage
2-
dist
2+
lib
33
/.yarn

‎.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

+541
Large diffs are not rendered by default.

‎.yarn/releases/yarn-2.4.3.cjs

-55
This file was deleted.

‎.yarn/releases/yarn-3.6.4.cjs

+874
Large diffs are not rendered by default.

‎.yarnrc.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ nodeLinker: node-modules
44

55
plugins:
66
- path: .yarn/plugins/plugin-prepare-lifecycle.cjs
7-
spec: 'https://github.com/un-es/yarn-plugin-prepare-lifecycle/releases/download/v0.0.1/index.js'
7+
spec: "https://github.com/un-es/yarn-plugin-prepare-lifecycle/releases/download/v0.0.1/index.js"
8+
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
9+
spec: "@yarnpkg/plugin-interactive-tools"
810

9-
yarnPath: .yarn/releases/yarn-2.4.3.cjs
11+
yarnPath: .yarn/releases/yarn-3.6.4.cjs

‎__mocks__/prettier.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1+
/* eslint-disable @typescript-eslint/require-await */
2+
13
import path from 'path'
24

3-
export = {
4-
format: jest.fn((input: string) => 'formatted:' + input),
5-
resolveConfig: {
6-
sync: jest.fn((file: string) => ({ file })),
7-
},
8-
getFileInfo: {
9-
sync: jest.fn((file: string) => {
10-
const ext = path.extname(file)
11-
if (ext === '.js' || ext === '.md') {
12-
return { ignored: false, inferredParser: 'babel' }
13-
}
14-
return { ignored: false, inferredParser: null }
15-
}),
16-
},
17-
}
5+
export const format = jest.fn(async (input: string) => 'formatted:' + input)
6+
7+
export const resolveConfig = jest.fn(async (file: string) => ({ file }))
8+
9+
export const getFileInfo = jest.fn(async (file: string) => {
10+
const ext = path.extname(file)
11+
return {
12+
ignored: false,
13+
inferredParser: ext === '.js' || ext === '.md' ? 'babel' : null,
14+
}
15+
})

‎bin/pretty-quick.js

-3
This file was deleted.

‎package.json

+34-25
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@
88
"JounQin (https://www.1stG.me) <admin@1stg.me>"
99
],
1010
"license": "MIT",
11-
"packageManager": "yarn@2.4.3",
11+
"packageManager": "yarn@3.6.4",
1212
"engines": {
13-
"node": ">=10.13"
13+
"node": ">=14"
1414
},
15-
"bin": "dist/cli.js",
16-
"main": "dist/index.js",
17-
"module": "dist/index.esm.mjs",
18-
"types": "dist/index.d.ts",
15+
"bin": "lib/cli.mjs",
16+
"main": "lib/index.js",
17+
"module": "lib/index.esm.mjs",
18+
"exports": {
19+
".": {
20+
"types": "./lib/index.d.ts",
21+
"require": "./lib/index.js",
22+
"default": "./lib/index.esm.mjs"
23+
},
24+
"./*": "./lib/*.js",
25+
"./package.json": "./package.json"
26+
},
27+
"types": "lib/index.d.ts",
1928
"files": [
2029
"bin",
21-
"dist",
2230
"img",
31+
"lib",
2332
"!**/*.tsbuildinfo"
2433
],
2534
"keywords": [
@@ -35,7 +44,7 @@
3544
],
3645
"scripts": {
3746
"build": "run-p 'build:*'",
38-
"build:r": "r -f esm -o dist || exit 0",
47+
"build:r": "r -f esm",
3948
"build:tsc": "tsc -b",
4049
"lint": "run-p 'lint:*'",
4150
"lint:es": "eslint . --cache",
@@ -45,49 +54,48 @@
4554
"test": "jest"
4655
},
4756
"peerDependencies": {
48-
"prettier": "^2.0.0"
57+
"prettier": "^3.0.0"
4958
},
5059
"dependencies": {
51-
"execa": "^4.1.0",
52-
"find-up": "^4.1.0",
60+
"execa": "^5.1.1",
61+
"find-up": "^5.0.0",
5362
"ignore": "^5.3.0",
5463
"mri": "^1.2.0",
5564
"picocolors": "^1.0.0",
5665
"picomatch": "^3.0.1",
5766
"tslib": "^2.6.2"
5867
},
5968
"devDependencies": {
60-
"@1stg/lib-config": "^12.0.0",
69+
"@1stg/lib-config": "^12.0.1",
6170
"@changesets/changelog-github": "^0.5.0",
6271
"@changesets/cli": "^2.27.1",
6372
"@commitlint/cli": "^17.8.1",
64-
"@pkgr/rollup": "^4.1.1",
73+
"@pkgr/rollup": "^4.1.3",
6574
"@total-typescript/ts-reset": "^0.5.1",
6675
"@types/jest": "^29.5.11",
6776
"@types/mock-fs": "^4.13.4",
6877
"@types/picomatch": "^2.3.3",
6978
"@unts/patch-package": "^8.0.0",
7079
"clean-pkg-json": "^1.2.0",
7180
"eslint": "^8.56.0",
72-
"eslint-config-prettier": "^9.1.0",
73-
"eslint-plugin-jest": "^27.6.3",
74-
"eslint-plugin-prettier": "^4.2.1",
75-
"jest": "^26.6.3",
76-
"lint-staged": "^13.2.2",
81+
"jest": "^29.7.0",
82+
"lint-staged": "^13.3.0",
7783
"mock-fs": "^4.14.0",
7884
"npm-run-all": "^4.1.5",
79-
"prettier": "^2.8.8",
85+
"prettier": "^3.2.3",
8086
"pretty-quick": "link:.",
8187
"simple-git-hooks": "^2.9.0",
82-
"size-limit": "^11.0.1",
88+
"size-limit": "^11.0.2",
8389
"size-limit-preset-node-lib": "^0.3.0",
84-
"ts-jest": "^26.5.6",
90+
"ts-jest": "^29.1.1",
8591
"ts-node": "^10.9.2",
86-
"typescript": "~4.4.4"
92+
"typescript": "^5.3.3"
8793
},
8894
"resolutions": {
89-
"typescript": "~4.4.4",
90-
"yaml": "^1.10.2"
95+
"@1stg/prettier-config": "^4.0.1",
96+
"eslint-config-prettier": "^9.1.0",
97+
"eslint-plugin-prettier": "^5.1.3",
98+
"prettier": "^3.2.3"
9199
},
92100
"commitlint": {
93101
"extends": "@1stg"
@@ -108,7 +116,7 @@
108116
},
109117
"eslintIgnore": [
110118
"coverage",
111-
"dist",
119+
"lib",
112120
"!/.*.js"
113121
],
114122
"jest": {
@@ -118,6 +126,7 @@
118126
],
119127
"collectCoverage": true,
120128
"moduleNameMapper": {
129+
"^(\\.{1,2}/.*)\\.js$": "$1",
121130
"^pretty-quick$": "<rootDir>/src",
122131
"^pretty-quick/(.+)$": "<rootDir>/src/$1"
123132
}

‎src/cli.mts

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env node
2+
3+
import mri from 'mri'
4+
import picocolors from 'picocolors'
5+
6+
import prettyQuick from './index.js'
7+
8+
const args = mri(process.argv.slice(2), {
9+
alias: {
10+
'resolve-config': 'resolveConfig',
11+
'ignore-path': 'ignorePath',
12+
},
13+
})
14+
15+
const main = async () => {
16+
const prettyQuickResult = await prettyQuick(process.cwd(), {
17+
...args,
18+
onFoundSinceRevision: (scm, revision) => {
19+
console.log(
20+
`🔍 Finding changed files since ${picocolors.bold(
21+
scm,
22+
)} revision ${picocolors.bold(revision)}.`,
23+
)
24+
},
25+
26+
onFoundChangedFiles: changedFiles => {
27+
console.log(
28+
`🎯 Found ${picocolors.bold(changedFiles.length)} changed ${
29+
changedFiles.length === 1 ? 'file' : 'files'
30+
}.`,
31+
)
32+
},
33+
34+
onPartiallyStagedFile: file => {
35+
console.log(
36+
`✗ Found ${picocolors.bold('partially')} staged file ${file}.`,
37+
)
38+
},
39+
40+
onWriteFile: file => {
41+
console.log(`✍️ Fixing up ${picocolors.bold(file)}.`)
42+
},
43+
44+
onCheckFile: (file, isFormatted) => {
45+
if (!isFormatted) {
46+
console.log(`⛔️ Check failed: ${picocolors.bold(file)}`)
47+
}
48+
},
49+
50+
onExamineFile: file => {
51+
console.log(`🔍 Examining ${picocolors.bold(file)}.`)
52+
},
53+
})
54+
55+
if (prettyQuickResult.success) {
56+
console.log('✅ Everything is awesome!')
57+
} else {
58+
if (prettyQuickResult.errors.includes('PARTIALLY_STAGED_FILE')) {
59+
console.log(
60+
'✗ Partially staged files were fixed up.' +
61+
` ${picocolors.bold('Please update stage before committing')}.`,
62+
)
63+
}
64+
if (prettyQuickResult.errors.includes('BAIL_ON_WRITE')) {
65+
console.log(
66+
'✗ File had to be prettified and prettyQuick was set to bail mode.',
67+
)
68+
}
69+
if (prettyQuickResult.errors.includes('CHECK_FAILED')) {
70+
console.log(
71+
'✗ Code style issues found in the above file(s). Forgot to run Prettier?',
72+
)
73+
}
74+
// eslint-disable-next-line n/no-process-exit
75+
process.exit(1) // ensure git hooks abort
76+
}
77+
}
78+
79+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
80+
main()

‎src/cli.ts

-73
This file was deleted.

0 commit comments

Comments
 (0)