mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
feat(read-project-manifest): safeReadProjectManifestOnly added
This commit is contained in:
5
.changeset/famous-parrots-fold.md
Normal file
5
.changeset/famous-parrots-fold.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/read-project-manifest": minor
|
||||
---
|
||||
|
||||
safeReadProjectManifestOnly() added.
|
||||
@@ -2,7 +2,7 @@ import PnpmError from '@pnpm/error'
|
||||
import binify, { Command } from '@pnpm/package-bins'
|
||||
import readModulesDir from '@pnpm/read-modules-dir'
|
||||
import { fromDir as readPackageJsonFromDir } from '@pnpm/read-package-json'
|
||||
import { readProjectManifestOnly } from '@pnpm/read-project-manifest'
|
||||
import { safeReadProjectManifestOnly } from '@pnpm/read-project-manifest'
|
||||
import { DependencyManifest } from '@pnpm/types'
|
||||
import Module = require('module')
|
||||
import cmdShim = require('@zkochan/cmd-shim')
|
||||
@@ -125,7 +125,7 @@ async function getPackageBins (
|
||||
target: string
|
||||
) {
|
||||
const manifest = opts.allowExoticManifests
|
||||
? await safeReadProjectManifestOnly(target) : await safeReadPkgJson(target)
|
||||
? (await safeReadProjectManifestOnly(target) as DependencyManifest) : await safeReadPkgJson(target)
|
||||
|
||||
if (!manifest) {
|
||||
// There's a directory in node_modules without package.json: ${target}.
|
||||
@@ -185,14 +185,3 @@ async function safeReadPkgJson (pkgDir: string): Promise<DependencyManifest | nu
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
async function safeReadProjectManifestOnly (projectDir: string) {
|
||||
try {
|
||||
return await readProjectManifestOnly(projectDir) as DependencyManifest
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === 'ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND') {
|
||||
return null
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,17 @@ const stat = promisify(fs.stat)
|
||||
|
||||
type WriteProjectManifest = (manifest: ProjectManifest, force?: boolean) => Promise<void>
|
||||
|
||||
export async function safeReadProjectManifestOnly (projectDir: string) {
|
||||
try {
|
||||
return await readProjectManifestOnly(projectDir)
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === 'ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND') {
|
||||
return null
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
export default async function readProjectManifest (projectDir: string): Promise<{
|
||||
fileName: string
|
||||
manifest: ProjectManifest
|
||||
|
||||
Reference in New Issue
Block a user