Skip to content

Commit

Permalink
feat!: support prettier v3 (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Jan 17, 2024
1 parent 5055759 commit f1cacb2
Show file tree
Hide file tree
Showing 26 changed files with 4,853 additions and 5,197 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-shirts-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pretty-quick": major
---

feat!: support prettier v3
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
strategy:
matrix:
node:
- 10
- 12
- 14
- 16
- 18
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist
lib
node_modules
*.log
/.yarn/*
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
coverage
dist
lib
/.yarn
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions .yarn/releases/yarn-2.4.3.cjs

This file was deleted.

874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.4.cjs

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ nodeLinker: node-modules

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

yarnPath: .yarn/releases/yarn-2.4.3.cjs
yarnPath: .yarn/releases/yarn-3.6.4.cjs
28 changes: 13 additions & 15 deletions __mocks__/prettier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/* eslint-disable @typescript-eslint/require-await */

import path from 'path'

export = {
format: jest.fn((input: string) => 'formatted:' + input),
resolveConfig: {
sync: jest.fn((file: string) => ({ file })),
},
getFileInfo: {
sync: jest.fn((file: string) => {
const ext = path.extname(file)
if (ext === '.js' || ext === '.md') {
return { ignored: false, inferredParser: 'babel' }
}
return { ignored: false, inferredParser: null }
}),
},
}
export const format = jest.fn(async (input: string) => 'formatted:' + input)

export const resolveConfig = jest.fn(async (file: string) => ({ file }))

export const getFileInfo = jest.fn(async (file: string) => {
const ext = path.extname(file)
return {
ignored: false,
inferredParser: ext === '.js' || ext === '.md' ? 'babel' : null,
}
})
3 changes: 0 additions & 3 deletions bin/pretty-quick.js

This file was deleted.

59 changes: 34 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@
"JounQin (https://www.1stG.me) <[email protected]>"
],
"license": "MIT",
"packageManager": "yarn@2.4.3",
"packageManager": "yarn@3.6.4",
"engines": {
"node": ">=10.13"
"node": ">=14"
},
"bin": "dist/cli.js",
"main": "dist/index.js",
"module": "dist/index.esm.mjs",
"types": "dist/index.d.ts",
"bin": "lib/cli.mjs",
"main": "lib/index.js",
"module": "lib/index.esm.mjs",
"exports": {
".": {
"types": "./lib/index.d.ts",
"require": "./lib/index.js",
"default": "./lib/index.esm.mjs"
},
"./*": "./lib/*.js",
"./package.json": "./package.json"
},
"types": "lib/index.d.ts",
"files": [
"bin",
"dist",
"img",
"lib",
"!**/*.tsbuildinfo"
],
"keywords": [
Expand All @@ -35,7 +44,7 @@
],
"scripts": {
"build": "run-p 'build:*'",
"build:r": "r -f esm -o dist || exit 0",
"build:r": "r -f esm",
"build:tsc": "tsc -b",
"lint": "run-p 'lint:*'",
"lint:es": "eslint . --cache",
Expand All @@ -45,49 +54,48 @@
"test": "jest"
},
"peerDependencies": {
"prettier": "^2.0.0"
"prettier": "^3.0.0"
},
"dependencies": {
"execa": "^4.1.0",
"find-up": "^4.1.0",
"execa": "^5.1.1",
"find-up": "^5.0.0",
"ignore": "^5.3.0",
"mri": "^1.2.0",
"picocolors": "^1.0.0",
"picomatch": "^3.0.1",
"tslib": "^2.6.2"
},
"devDependencies": {
"@1stg/lib-config": "^12.0.0",
"@1stg/lib-config": "^12.0.1",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^17.8.1",
"@pkgr/rollup": "^4.1.1",
"@pkgr/rollup": "^4.1.3",
"@total-typescript/ts-reset": "^0.5.1",
"@types/jest": "^29.5.11",
"@types/mock-fs": "^4.13.4",
"@types/picomatch": "^2.3.3",
"@unts/patch-package": "^8.0.0",
"clean-pkg-json": "^1.2.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^26.6.3",
"lint-staged": "^13.2.2",
"jest": "^29.7.0",
"lint-staged": "^13.3.0",
"mock-fs": "^4.14.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"prettier": "^3.2.3",
"pretty-quick": "link:.",
"simple-git-hooks": "^2.9.0",
"size-limit": "^11.0.1",
"size-limit": "^11.0.2",
"size-limit-preset-node-lib": "^0.3.0",
"ts-jest": "^26.5.6",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "~4.4.4"
"typescript": "^5.3.3"
},
"resolutions": {
"typescript": "~4.4.4",
"yaml": "^1.10.2"
"@1stg/prettier-config": "^4.0.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.2.3"
},
"commitlint": {
"extends": "@1stg"
Expand All @@ -108,7 +116,7 @@
},
"eslintIgnore": [
"coverage",
"dist",
"lib",
"!/.*.js"
],
"jest": {
Expand All @@ -118,6 +126,7 @@
],
"collectCoverage": true,
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1",
"^pretty-quick$": "<rootDir>/src",
"^pretty-quick/(.+)$": "<rootDir>/src/$1"
}
Expand Down
80 changes: 80 additions & 0 deletions src/cli.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env node

import mri from 'mri'
import picocolors from 'picocolors'

import prettyQuick from './index.js'

const args = mri(process.argv.slice(2), {
alias: {
'resolve-config': 'resolveConfig',
'ignore-path': 'ignorePath',
},
})

const main = async () => {
const prettyQuickResult = await prettyQuick(process.cwd(), {
...args,
onFoundSinceRevision: (scm, revision) => {
console.log(
`🔍 Finding changed files since ${picocolors.bold(
scm,
)} revision ${picocolors.bold(revision)}.`,
)
},

onFoundChangedFiles: changedFiles => {
console.log(
`🎯 Found ${picocolors.bold(changedFiles.length)} changed ${
changedFiles.length === 1 ? 'file' : 'files'
}.`,
)
},

onPartiallyStagedFile: file => {
console.log(
`✗ Found ${picocolors.bold('partially')} staged file ${file}.`,
)
},

onWriteFile: file => {
console.log(`✍️ Fixing up ${picocolors.bold(file)}.`)
},

onCheckFile: (file, isFormatted) => {
if (!isFormatted) {
console.log(`⛔️ Check failed: ${picocolors.bold(file)}`)
}
},

onExamineFile: file => {
console.log(`🔍 Examining ${picocolors.bold(file)}.`)
},
})

if (prettyQuickResult.success) {
console.log('✅ Everything is awesome!')
} else {
if (prettyQuickResult.errors.includes('PARTIALLY_STAGED_FILE')) {
console.log(
'✗ Partially staged files were fixed up.' +
` ${picocolors.bold('Please update stage before committing')}.`,
)
}
if (prettyQuickResult.errors.includes('BAIL_ON_WRITE')) {
console.log(
'✗ File had to be prettified and prettyQuick was set to bail mode.',
)
}
if (prettyQuickResult.errors.includes('CHECK_FAILED')) {
console.log(
'✗ Code style issues found in the above file(s). Forgot to run Prettier?',
)
}
// eslint-disable-next-line n/no-process-exit
process.exit(1) // ensure git hooks abort
}
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
main()
73 changes: 0 additions & 73 deletions src/cli.ts

This file was deleted.

Loading

0 comments on commit f1cacb2

Please sign in to comment.