Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Node.js LTS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: lts/*
cache: yarn
Expand All @@ -34,6 +34,6 @@ jobs:
run: yarn format

- name: Apply autofix.ci
uses: autofix-ci/action@2891949f3779a1cafafae1523058501de3d4e944 # v1
uses: autofix-ci/action@c5b2d67aa2274e7b5a18224e8171550871fc7e4a # v1
with:
fail-fast: false
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ matrix.node }}
cache: yarn
Expand All @@ -51,6 +51,6 @@ jobs:
PARSER_NO_WATCH: true

- name: Codecov
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/pkg-pr-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:

steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Node.js LTS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: lts/*
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkg-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Package Size Report
uses: pkg-size/action@a637fb0897b6f14f18e776d8c3dbccb34a1ad27b # v1.1.1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js LTS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: lts/*
cache: yarn
Expand All @@ -38,7 +38,7 @@ jobs:
run: yarn build

- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1
uses: changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2
with:
commit: 'chore: release pretty-quick'
title: 'chore: release pretty-quick'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
size-limit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Setup Node.js LTS
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: lts/*
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
26
1,000 changes: 1,000 additions & 0 deletions .yarn/releases/yarn-4.18.1.cjs

Large diffs are not rendered by default.

948 changes: 0 additions & 948 deletions .yarn/releases/yarn-4.9.1.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ 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'

yarnPath: .yarn/releases/yarn-4.9.1.cjs
yarnPath: .yarn/releases/yarn-4.18.1.cjs
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"funding": "https://opencollective.com/pretty-quick",
"license": "MIT",
"packageManager": "yarn@4.9.1",
"packageManager": "yarn@4.18.1",
"engines": {
"node": "^14.18.0 || >=16.0.0"
},
Expand Down Expand Up @@ -75,30 +75,30 @@
"tinyexec": "^1.0.1"
},
"devDependencies": {
"@1stg/common-config": "^14.1.0",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.29.4",
"@commitlint/cli": "^19.8.1",
"@1stg/common-config": "^16.0.0",
"@changesets/changelog-github": "^1.0.0",
"@changesets/cli": "^3.0.0",
"@commitlint/cli": "^21.0.0",
"@total-typescript/ts-reset": "^0.6.1",
"@types/jest": "^29.5.14",
"@types/jest": "^30.0.0",
"@types/mock-fs": "^4.13.4",
"@types/picomatch": "^4.0.0",
"@unts/patch-package": "^8.1.1",
"clean-pkg-json": "^1.3.0",
"eslint": "^9.28.0",
"jest": "^29.7.0",
"clean-pkg-json": "^2.0.0",
"eslint": "^10.0.0",
"jest": "^30.0.0",
"mock-fs": "^5.5.0",
"nano-staged": "^0.8.0",
"nano-staged": "^1.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.5.3",
"pretty-quick": "link:.",
"simple-git-hooks": "^2.13.0",
"size-limit": "^11.2.0",
"size-limit-preset-node-lib": "^0.4.0",
"size-limit": "^14.0.0",
"size-limit-preset-node-lib": "^0.5.0",
"ts-jest": "^29.3.4",
"ts-node": "^10.9.2",
"tsdown": "^0.12.5",
"typescript": "^5.8.3"
"tsdown": "^0.23.0",
"typescript": "^7.0.0"
},
"resolutions": {
"prettier": "^3.5.3"
Expand Down
12 changes: 3 additions & 9 deletions src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const main = async () => {
},

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

onWriteFile: file => {
Expand Down Expand Up @@ -66,14 +64,10 @@ const main = async () => {
)
}
if (prettyQuickResult.errors.includes('BAIL_ON_WRITE')) {
console.log(
'✗ File had to be prettified and prettyQuick was set to bail mode.',
)
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?',
)
console.log('✗ Code style issues found in the above file(s). Forgot to run Prettier?')
}
if (prettyQuickResult.errors.includes('STAGE_FAILED')) {
console.log(
Expand Down
5 changes: 1 addition & 4 deletions src/createIgnorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import path from 'path'
import { tryFile } from '@pkgr/core'
import ignore from 'ignore'

export default async function createIgnorer(
directory: string,
filename = '.prettierignore',
) {
export default async function createIgnorer(directory: string, filename = '.prettierignore') {
const file = path.join(directory, filename)

if (tryFile(file)) {
Expand Down
23 changes: 5 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,28 @@ export = async function prettyQuick(
}
const directory = scm.rootDirectory

const revision =
since || (await scm.getSinceRevision(directory, { staged, branch }))
const revision = since || (await scm.getSinceRevision(directory, { staged, branch }))

onFoundSinceRevision?.(scm.name, revision)

const rootIgnorer = await createIgnorer(directory, ignorePath)
const cwdIgnorer =
currentDirectory === directory
? () => true
: await createIgnorer(currentDirectory, ignorePath)
currentDirectory === directory ? () => true : await createIgnorer(currentDirectory, ignorePath)

const patternMatcher = createMatcher(pattern)

const isFileSupportedExtension = isSupportedExtension(resolveConfig)

const unfilteredChangedFiles = await scm.getChangedFiles(
directory,
revision,
staged,
)
const unfilteredChangedFiles = await scm.getChangedFiles(directory, revision, staged)
const changedFiles = await filterAsync(
unfilteredChangedFiles
.filter(patternMatcher)
.filter(rootIgnorer)
.filter(cwdIgnorer),
unfilteredChangedFiles.filter(patternMatcher).filter(rootIgnorer).filter(cwdIgnorer),
isFileSupportedExtension,
)

const unfilteredStagedFiles = await scm.getUnstagedChangedFiles(directory)
const unstagedFiles = staged
? await filterAsync(
unfilteredStagedFiles
.filter(patternMatcher)
.filter(rootIgnorer)
.filter(cwdIgnorer),
unfilteredStagedFiles.filter(patternMatcher).filter(rootIgnorer).filter(cwdIgnorer),
isFileSupportedExtension,
)
: []
Expand Down
45 changes: 20 additions & 25 deletions src/isSupportedExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,27 @@

import fs from 'fs/promises'

import {
type FileInfoOptions,
getFileInfo,
resolveConfig as prettierResolveConfig,
} from 'prettier'
import { type FileInfoOptions, getFileInfo, resolveConfig as prettierResolveConfig } from 'prettier'

const isSupportedExtension =
(resolveConfig?: boolean) => async (file: string) => {
const stat = await fs.stat(file).catch(_error => null)
/* If file exists but is actually a directory, getFileInfo might end up trying
* to open it and read it as a file, so let's not let that happen. On the
* other hand, the tests depend on our not failing out with files that don't
* exist, so permit nonexistent files to go through (they appear to be
* detected by suffix, so never get read).
*/
if (stat?.isDirectory()) {
return false
}
const config = (await prettierResolveConfig(file, {
editorconfig: true,
})) as FileInfoOptions
const fileInfo = await getFileInfo(file, {
resolveConfig,
...config,
})
return !!fileInfo.inferredParser
const isSupportedExtension = (resolveConfig?: boolean) => async (file: string) => {
const stat = await fs.stat(file).catch(_error => null)
/* If file exists but is actually a directory, getFileInfo might end up trying
* to open it and read it as a file, so let's not let that happen. On the
* other hand, the tests depend on our not failing out with files that don't
* exist, so permit nonexistent files to go through (they appear to be
* detected by suffix, so never get read).
*/
if (stat?.isDirectory()) {
return false
}
const config = (await prettierResolveConfig(file, {
editorconfig: true,
})) as FileInfoOptions
const fileInfo = await getFileInfo(file, {
resolveConfig,
...config,
})
return !!fileInfo.inferredParser
}

export default isSupportedExtension
8 changes: 1 addition & 7 deletions src/processFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ import type { PrettyQuickOptions } from './types.js'
export default async function processFiles(
directory: string,
files: string[],
{
check,
config,
onExamineFile,
onCheckFile,
onWriteFile,
}: Partial<PrettyQuickOptions> = {},
{ check, config, onExamineFile, onCheckFile, onWriteFile }: Partial<PrettyQuickOptions> = {},
) {
return Promise.all(
files.map(async relative => {
Expand Down
25 changes: 4 additions & 21 deletions src/scms/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,15 @@ export const getSinceRevision = async (
try {
let revision = 'HEAD'
if (!staged) {
const revisionOutput = await runGit(directory, [
'merge-base',
'HEAD',
branch || 'master',
])
const revisionOutput = await runGit(directory, ['merge-base', 'HEAD', branch || 'master'])
revision = revisionOutput.stdout.trim()
}

const revParseOutput = await runGit(directory, [
'rev-parse',
'--short',
revision,
])
const revParseOutput = await runGit(directory, ['rev-parse', '--short', revision])
return revParseOutput.stdout.trim()
} catch (err) {
const error = err as Error
if (
/HEAD/.test(error.message) ||
(staged && /Needed a single revision/.test(error.message))
) {
if (/HEAD/.test(error.message) || (staged && /Needed a single revision/.test(error.message))) {
return null
}
throw error
Expand All @@ -76,13 +65,7 @@ export const getChangedFiles = async (
),
...(staged
? []
: getLines(
await runGit(directory, [
'ls-files',
'--others',
'--exclude-standard',
]),
)),
: getLines(await runGit(directory, ['ls-files', '--others', '--exclude-standard']))),
].filter(Boolean)

export const getUnstagedChangedFiles = (directory: string) =>
Expand Down
11 changes: 2 additions & 9 deletions src/scms/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@ const runHg = (directory: string, args: string[]) =>

const getLines = (tinyexecOutput: Output) => tinyexecOutput.stdout.split('\n')

export const getSinceRevision = async (
directory: string,
{ branch }: { branch?: string },
) => {
const revisionOutput = await runHg(directory, [
'debugancestor',
'tip',
branch || 'default',
])
export const getSinceRevision = async (directory: string, { branch }: { branch?: string }) => {
const revisionOutput = await runHg(directory, ['debugancestor', 'tip', branch || 'default'])
const revision = revisionOutput.stdout.trim()
const hgOutput = await runHg(directory, ['id', '-i', '-r', revision])
return hgOutput.stdout.trim()
Expand Down
5 changes: 1 addition & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export const filterAsync = async <T>(
items: T[],
predicate: (item: T) => Promise<boolean>,
) => {
export const filterAsync = async <T>(items: T[], predicate: (item: T) => Promise<boolean>) => {
const boolItems = await Promise.all(items.map(predicate))
return items.filter((_, i) => boolItems[i])
}
Loading
Loading