fix(read-project-manifest): avoid EMFILE errors (#3381)

close #3378
This commit is contained in:
Zoltan Kochan
2021-04-24 21:11:16 +03:00
committed by GitHub
parent 05baaa6e74
commit 6e9c112afd
4 changed files with 14 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/read-project-manifest": patch
---
Use graceful-fs in order to avoid EMFILE errors.

View File

@@ -33,6 +33,7 @@
"@pnpm/write-project-manifest": "workspace:2.0.0",
"detect-indent": "^6.0.0",
"fast-deep-equal": "^3.1.3",
"graceful-fs": "^4.2.6",
"is-windows": "^1.0.2",
"json5": "^2.1.3",
"parse-json": "^5.1.0",

View File

@@ -1,9 +1,13 @@
import { promises as fs } from 'fs'
import { promisify } from 'util'
import gracefulFs from 'graceful-fs'
import { ProjectManifest } from '@pnpm/types'
import JSON5 from 'json5'
import parseJson from 'parse-json'
import stripBom from 'strip-bom'
// We use graceful-fs to avoid EMFILE errors.
const readFile = promisify(gracefulFs.readFile)
export async function readJson5File (filePath: string) {
const text = await readFileWithoutBom(filePath)
try {
@@ -32,5 +36,5 @@ export async function readJsonFile (filePath: string) {
}
async function readFileWithoutBom (path: string) {
return stripBom(await fs.readFile(path, 'utf8'))
return stripBom(await readFile(path, 'utf8'))
}

2
pnpm-lock.yaml generated
View File

@@ -2530,6 +2530,7 @@ importers:
'@types/parse-json': ^4.0.0
detect-indent: ^6.0.0
fast-deep-equal: ^3.1.3
graceful-fs: ^4.2.6
is-windows: ^1.0.2
json5: ^2.1.3
parse-json: ^5.1.0
@@ -2543,6 +2544,7 @@ importers:
'@pnpm/write-project-manifest': link:../write-project-manifest
detect-indent: 6.0.0
fast-deep-equal: 3.1.3
graceful-fs: 4.2.6
is-windows: 1.0.2
json5: 2.2.0
parse-json: 5.2.0