Skip to content

Commit

Permalink
Limit Prettier to 25 parallel file I/O operations (#584)
Browse files Browse the repository at this point in the history
This seems to pop up on a large repo (300+ Prettified files) in
Buildkite when our agents are under load.
  • Loading branch information
72636c authored Sep 30, 2021
1 parent b1ed5f7 commit 03d371a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 80 deletions.
7 changes: 7 additions & 0 deletions .changeset/young-seas-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"skuba": patch
---

format, lint: Limit Prettier to 25 parallel file I/O operations

This should alleviate file descriptor issues that are not handled by `graceful-fs` such as `EBADF: bad file description, close`.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"normalize-package-data": "^3.0.0",
"npm-run-path": "^4.0.1",
"npm-which": "^3.0.1",
"p-limit": "3.1.0",
"picomatch": "^2.2.2",
"prettier": "2.4.1",
"read-pkg-up": "^7.0.1",
Expand Down
11 changes: 7 additions & 4 deletions src/cli/adapter/prettier.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import path from 'path';

import fs from 'fs-extra';
import pLimit from 'p-limit';
import { Options, check, format, getFileInfo, resolveConfig } from 'prettier';

import { crawlDirectory } from '../../utils/dir';
import { Logger } from '../../utils/logging';
import { getConsumerManifest } from '../../utils/manifest';

const fsLimit = pLimit(25);

interface File {
data: string;
options: Options;
Expand Down Expand Up @@ -121,10 +124,10 @@ export const runPrettier = async (
const files = await Promise.all(
filepaths.map<Promise<File>>(async (filepath) => {
const [config, data, fileInfo] = await Promise.all([
resolveConfig(filepath),
fs.promises.readFile(filepath, 'utf-8'),
fsLimit(() => resolveConfig(filepath)),
fsLimit(() => fs.promises.readFile(filepath, 'utf-8')),
// Infer parser upfront so we can know to ignore unsupported file types.
getFileInfo(filepath, { resolveConfig: false }),
fsLimit(() => getFileInfo(filepath, { resolveConfig: false })),
]);

return {
Expand All @@ -146,7 +149,7 @@ export const runPrettier = async (

await Promise.all(
result.touched.map(({ data, filepath }) =>
fs.promises.writeFile(filepath, data),
fsLimit(() => fs.promises.writeFile(filepath, data)),
),
);

Expand Down
152 changes: 76 additions & 76 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6080,75 +6080,75 @@ npm@^7.0.0:
resolved "https://registry.yarnpkg.com/npm/-/npm-7.24.1.tgz#4d23670f46c828e88f6b853497d2a896e8fac41b"
integrity sha512-U7/C++ZgB3zNH/kzhSJMnp3pO2iLrZRGUUXAgCCLB/by+sR+dKVhP/ik9+sTOGk9wk3zbmwHAYDT8igkv1ss0g==
dependencies:
"@npmcli/arborist" "*"
"@npmcli/ci-detect" "*"
"@npmcli/config" "*"
"@npmcli/map-workspaces" "*"
"@npmcli/package-json" "*"
"@npmcli/run-script" "*"
abbrev "*"
ansicolors "*"
ansistyles "*"
archy "*"
cacache "*"
chalk "*"
chownr "*"
cli-columns "*"
cli-table3 "*"
columnify "*"
fastest-levenshtein "*"
glob "*"
graceful-fs "*"
hosted-git-info "*"
ini "*"
init-package-json "*"
is-cidr "*"
json-parse-even-better-errors "*"
libnpmaccess "*"
libnpmdiff "*"
libnpmexec "*"
libnpmfund "*"
libnpmhook "*"
libnpmorg "*"
libnpmpack "*"
libnpmpublish "*"
libnpmsearch "*"
libnpmteam "*"
libnpmversion "*"
make-fetch-happen "*"
minipass "*"
minipass-pipeline "*"
mkdirp "*"
mkdirp-infer-owner "*"
ms "*"
node-gyp "*"
nopt "*"
npm-audit-report "*"
npm-install-checks "*"
npm-package-arg "*"
npm-pick-manifest "*"
npm-profile "*"
npm-registry-fetch "*"
npm-user-validate "*"
npmlog "*"
opener "*"
pacote "*"
parse-conflict-json "*"
qrcode-terminal "*"
read "*"
read-package-json "*"
read-package-json-fast "*"
readdir-scoped-modules "*"
rimraf "*"
semver "*"
ssri "*"
tar "*"
text-table "*"
tiny-relative-date "*"
treeverse "*"
validate-npm-package-name "*"
which "*"
write-file-atomic "*"
"@npmcli/arborist" "^2.8.3"
"@npmcli/ci-detect" "^1.2.0"
"@npmcli/config" "^2.3.0"
"@npmcli/map-workspaces" "^1.0.4"
"@npmcli/package-json" "^1.0.1"
"@npmcli/run-script" "^1.8.6"
abbrev "~1.1.1"
ansicolors "~0.3.2"
ansistyles "~0.1.3"
archy "~1.0.0"
cacache "^15.3.0"
chalk "^4.1.2"
chownr "^2.0.0"
cli-columns "^3.1.2"
cli-table3 "^0.6.0"
columnify "~1.5.4"
fastest-levenshtein "^1.0.12"
glob "^7.2.0"
graceful-fs "^4.2.8"
hosted-git-info "^4.0.2"
ini "^2.0.0"
init-package-json "^2.0.5"
is-cidr "^4.0.2"
json-parse-even-better-errors "^2.3.1"
libnpmaccess "^4.0.2"
libnpmdiff "^2.0.4"
libnpmexec "^2.0.1"
libnpmfund "^1.1.0"
libnpmhook "^6.0.2"
libnpmorg "^2.0.2"
libnpmpack "^2.0.1"
libnpmpublish "^4.0.1"
libnpmsearch "^3.1.1"
libnpmteam "^2.0.3"
libnpmversion "^1.2.1"
make-fetch-happen "^9.1.0"
minipass "^3.1.3"
minipass-pipeline "^1.2.4"
mkdirp "^1.0.4"
mkdirp-infer-owner "^2.0.0"
ms "^2.1.2"
node-gyp "^7.1.2"
nopt "^5.0.0"
npm-audit-report "^2.1.5"
npm-install-checks "^4.0.0"
npm-package-arg "^8.1.5"
npm-pick-manifest "^6.1.1"
npm-profile "^5.0.3"
npm-registry-fetch "^11.0.0"
npm-user-validate "^1.0.1"
npmlog "^5.0.1"
opener "^1.5.2"
pacote "^11.3.5"
parse-conflict-json "^1.1.1"
qrcode-terminal "^0.12.0"
read "~1.0.7"
read-package-json "^4.1.1"
read-package-json-fast "^2.0.3"
readdir-scoped-modules "^1.1.0"
rimraf "^3.0.2"
semver "^7.3.5"
ssri "^8.0.1"
tar "^6.1.11"
text-table "~0.2.0"
tiny-relative-date "^1.3.0"
treeverse "^1.0.4"
validate-npm-package-name "~3.0.0"
which "^2.0.2"
write-file-atomic "^3.0.3"

npmlog@*:
version "5.0.1"
Expand Down Expand Up @@ -6338,6 +6338,13 @@ p-is-promise@^3.0.0:
resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-3.0.0.tgz#58e78c7dfe2e163cf2a04ff869e7c1dba64a5971"
integrity sha512-Wo8VsW4IRQSKVXsJCn7TomUaVtyfjVDn3nUP7kE967BQk0CwFpdbZs0X0uk5sW9mkBa9eNM7hCMaG93WUAwxYQ==

[email protected], p-limit@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
dependencies:
yocto-queue "^0.1.0"

p-limit@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8"
Expand All @@ -6352,13 +6359,6 @@ p-limit@^2.2.0:
dependencies:
p-try "^2.0.0"

p-limit@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
dependencies:
yocto-queue "^0.1.0"

p-locate@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43"
Expand Down

0 comments on commit 03d371a

Please sign in to comment.