diff --git a/.changeset/tall-carpets-count.md b/.changeset/tall-carpets-count.md new file mode 100644 index 0000000000..b392f71a91 --- /dev/null +++ b/.changeset/tall-carpets-count.md @@ -0,0 +1,5 @@ +--- +"@pnpm/read-modules-dir": patch +--- + +Fix EMFILE error. diff --git a/packages/read-modules-dir/package.json b/packages/read-modules-dir/package.json index 7163b12fe5..c9713c58b7 100644 --- a/packages/read-modules-dir/package.json +++ b/packages/read-modules-dir/package.json @@ -25,5 +25,8 @@ "bugs": { "url": "https://github.com/pnpm/pnpm/issues" }, - "funding": "https://opencollective.com/pnpm" + "funding": "https://opencollective.com/pnpm", + "dependencies": { + "graceful-fs": "^4.2.6" + } } diff --git a/packages/read-modules-dir/src/index.ts b/packages/read-modules-dir/src/index.ts index fa4ed81325..89549702ec 100644 --- a/packages/read-modules-dir/src/index.ts +++ b/packages/read-modules-dir/src/index.ts @@ -1,5 +1,8 @@ -import { promises as fs } from 'fs' +import gracefulFs from 'graceful-fs' import path from 'path' +import util from 'util' + +const readdir = util.promisify(gracefulFs.readdir) export default async function readModulesDir (modulesDir: string) { try { @@ -16,7 +19,7 @@ async function _readModulesDir ( ) { let pkgNames: string[] = [] const parentDir = scope ? path.join(modulesDir, scope) : modulesDir - for (const dir of await fs.readdir(parentDir, { withFileTypes: true })) { + for (const dir of await readdir(parentDir, { withFileTypes: true })) { if (dir.isFile() || dir.name[0] === '.') continue if (!scope && dir.name[0] === '@') { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b690f519f..0f38e1999a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2676,6 +2676,9 @@ importers: packages/read-modules-dir: specifiers: '@pnpm/read-modules-dir': 'link:' + graceful-fs: ^4.2.6 + dependencies: + graceful-fs: 4.2.6 devDependencies: '@pnpm/read-modules-dir': 'link:'