1
+ import { existsSync } from 'node:fs'
1
2
import path from 'node:path'
2
3
import process from 'node:process'
3
4
@@ -11,7 +12,7 @@ import { isObjectObject } from '@socketsecurity/registry/lib/objects'
11
12
import { readPackageJson } from '@socketsecurity/registry/lib/packages'
12
13
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
13
14
14
- import { findUp , readFileBinary , readFileUtf8 , safeExistsSync } from './fs'
15
+ import { findUp , readFileBinary , readFileUtf8 } from './fs'
15
16
import constants from '../constants'
16
17
17
18
import type { EditablePackageJson } from '@socketsecurity/registry/lib/packages'
@@ -173,9 +174,10 @@ export async function detect({
173
174
const pkgJsonPath = lockPath
174
175
? path . resolve ( lockPath , `${ isHiddenLockFile ? '../' : '' } ../package.json` )
175
176
: await findUp ( 'package.json' , { cwd } )
176
- const pkgPath = safeExistsSync ( pkgJsonPath )
177
- ? path . dirname ( pkgJsonPath ! )
178
- : undefined
177
+ const pkgPath =
178
+ pkgJsonPath && existsSync ( pkgJsonPath )
179
+ ? path . dirname ( pkgJsonPath )
180
+ : undefined
179
181
const editablePkgJson = pkgPath
180
182
? await readPackageJson ( pkgPath , { editable : true } )
181
183
: undefined
0 commit comments