Skip to content

Commit 728e13e

Browse files
committed
Remove safeExistsSync
1 parent 61c3ffd commit 728e13e

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/utils/fs.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
promises as fs,
3-
existsSync as fsExistsSync,
4-
readFileSync as fsReadFileSync
5-
} from 'node:fs'
1+
import { promises as fs, readFileSync as fsReadFileSync } from 'node:fs'
62
import path from 'node:path'
73
import process from 'node:process'
84

@@ -58,13 +54,6 @@ export async function readFileUtf8(
5854
})
5955
}
6056

61-
export function safeExistsSync(filepath: PathLike | undefined): boolean {
62-
try {
63-
return filepath ? fsExistsSync(filepath) : false
64-
} catch {}
65-
return false
66-
}
67-
6857
export function safeReadFile(
6958
...args: Parameters<typeof fs.readFile>
7059
): ReturnType<typeof fs.readFile> | undefined {

src/utils/package-manager-detector.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from 'node:fs'
12
import path from 'node:path'
23
import process from 'node:process'
34

@@ -11,7 +12,7 @@ import { isObjectObject } from '@socketsecurity/registry/lib/objects'
1112
import { readPackageJson } from '@socketsecurity/registry/lib/packages'
1213
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
1314

14-
import { findUp, readFileBinary, readFileUtf8, safeExistsSync } from './fs'
15+
import { findUp, readFileBinary, readFileUtf8 } from './fs'
1516
import constants from '../constants'
1617

1718
import type { EditablePackageJson } from '@socketsecurity/registry/lib/packages'
@@ -173,9 +174,10 @@ export async function detect({
173174
const pkgJsonPath = lockPath
174175
? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`)
175176
: 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
179181
const editablePkgJson = pkgPath
180182
? await readPackageJson(pkgPath, { editable: true })
181183
: undefined

0 commit comments

Comments
 (0)