Skip to content

Commit e64483c

Browse files
committed
Move fs methods to registry package
1 parent a37eb35 commit e64483c

File tree

12 files changed

+70
-195
lines changed

12 files changed

+70
-195
lines changed

package-lock.json

Lines changed: 41 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
"@socketregistry/is-interactive": "1.0.6",
112112
"@socketregistry/packageurl-js": "1.0.8",
113113
"@socketsecurity/config": "3.0.1",
114-
"@socketsecurity/registry": "1.0.256",
115-
"@socketsecurity/sdk": "1.4.67",
114+
"@socketsecurity/registry": "1.0.258",
115+
"@socketsecurity/sdk": "1.4.68",
116116
"@types/blessed": "0.1.25",
117117
"@types/cmd-shim": "5.0.2",
118118
"@types/js-yaml": "4.0.9",
@@ -126,7 +126,7 @@
126126
"@types/which": "3.0.4",
127127
"@types/yargs-parser": "21.0.3",
128128
"@typescript-eslint/parser": "8.38.0",
129-
"@typescript/native-preview": "7.0.0-dev.20250801.1",
129+
"@typescript/native-preview": "7.0.0-dev.20250802.1",
130130
"@vitest/coverage-v8": "3.2.4",
131131
"blessed": "0.1.81",
132132
"blessed-contrib": "4.11.0",

src/commands/fix/pull-request.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import semver from 'semver'
1111

1212
import { PackageURL } from '@socketregistry/packageurl-js'
1313
import { debugDir, debugFn, isDebug } from '@socketsecurity/registry/lib/debug'
14-
import { readJson, writeJson } from '@socketsecurity/registry/lib/fs'
14+
import {
15+
readJson,
16+
safeStatsSync,
17+
writeJson,
18+
} from '@socketsecurity/registry/lib/fs'
1519
import { spawn } from '@socketsecurity/registry/lib/spawn'
1620
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
1721

@@ -22,7 +26,6 @@ import {
2226
getSocketPullRequestTitle,
2327
} from './socket-git.mts'
2428
import constants from '../../constants.mts'
25-
import { safeStatsSync } from '../../utils/fs.mts'
2629
import { getPurlObject } from '../../utils/purl.mts'
2730

2831
import type { SocketArtifact } from '../../utils/alert/artifact.mts'

src/commands/json/output-cmd-json.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { existsSync } from 'node:fs'
22
import path from 'node:path'
33

4+
import {
5+
safeReadFileSync,
6+
safeStatsSync,
7+
} from '@socketsecurity/registry/lib/fs'
48
import { logger } from '@socketsecurity/registry/lib/logger'
59

610
import constants from '../../constants.mts'
7-
import { safeReadFileSync, safeStatsSync } from '../../utils/fs.mts'
811
import { tildify } from '../../utils/tildify.mts'
912

1013
export async function outputCmdJson(cwd: string) {

src/commands/manifest/convert_sbt_to_maven.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { safeReadFile } from '@socketsecurity/registry/lib/fs'
12
import { logger } from '@socketsecurity/registry/lib/logger'
23
import { spawn } from '@socketsecurity/registry/lib/spawn'
34

45
import constants from '../../constants.mts'
5-
import { safeReadFile } from '../../utils/fs.mts'
66

77
export async function convertSbtToMaven({
88
bin,

src/utils/config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import path from 'node:path'
33

44
import config from '@socketsecurity/config'
55
import { debugFn } from '@socketsecurity/registry/lib/debug'
6+
import { safeReadFileSync } from '@socketsecurity/registry/lib/fs'
67
import { logger } from '@socketsecurity/registry/lib/logger'
78
import { naturalCompare } from '@socketsecurity/registry/lib/sorts'
89

910
import constants from '../constants.mts'
10-
import { safeReadFileSync } from './fs.mts'
1111

1212
import type { CResult } from '../types.mts'
1313

src/utils/fs.mts

Lines changed: 1 addition & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, promises as fs, readFileSync, statSync } from 'node:fs'
1+
import { promises as fs } from 'node:fs'
22
import path from 'node:path'
33

44
import { remove } from '@socketsecurity/registry/lib/fs'
@@ -7,19 +7,6 @@ import { pEach } from '@socketsecurity/registry/lib/promises'
77
import constants from '../constants.mts'
88
import { globNodeModules } from './glob.mts'
99

10-
import type { Remap } from '@socketsecurity/registry/lib/objects'
11-
import type { Abortable } from 'node:events'
12-
import type {
13-
BigIntStats,
14-
ObjectEncodingOptions,
15-
OpenMode,
16-
PathLike,
17-
PathOrFileDescriptor,
18-
StatSyncOptions,
19-
Stats,
20-
} from 'node:fs'
21-
import type { FileHandle } from 'node:fs/promises'
22-
2310
export async function removeNodeModules(cwd = process.cwd()) {
2411
const nodeModulesPaths = await globNodeModules(cwd)
2512
await pEach(
@@ -64,118 +51,3 @@ export async function findUp(
6451
}
6552
return undefined
6653
}
67-
68-
export function isDirectorySync(filepath: string): boolean {
69-
return existsSync(filepath) && !!safeStatsSync(filepath)?.isDirectory()
70-
}
71-
72-
export type ReadFileOptions = Remap<
73-
ObjectEncodingOptions &
74-
Abortable & {
75-
flag?: OpenMode | undefined
76-
}
77-
>
78-
79-
export async function readFileBinary(
80-
filepath: PathLike | FileHandle,
81-
options?: ReadFileOptions | undefined,
82-
): Promise<Buffer> {
83-
return (await fs.readFile(filepath, {
84-
// Lazily access constants.abortSignal.
85-
signal: constants.abortSignal,
86-
...options,
87-
encoding: 'binary',
88-
} as ReadFileOptions)) as Buffer
89-
}
90-
91-
export async function readFileUtf8(
92-
filepath: PathLike | FileHandle,
93-
options?: ReadFileOptions | undefined,
94-
): Promise<string> {
95-
return await fs.readFile(filepath, {
96-
// Lazily access constants.abortSignal.
97-
signal: constants.abortSignal,
98-
...options,
99-
encoding: 'utf8',
100-
})
101-
}
102-
103-
export async function safeReadFile(
104-
filepath: PathLike | FileHandle,
105-
options?: 'utf8' | 'utf-8' | { encoding: 'utf8' | 'utf-8' } | undefined,
106-
): Promise<string | undefined>
107-
108-
export async function safeReadFile(
109-
filepath: PathLike | FileHandle,
110-
options?: ReadFileOptions | NodeJS.BufferEncoding | undefined,
111-
): Promise<Awaited<ReturnType<typeof fs.readFile>> | undefined> {
112-
try {
113-
return await fs.readFile(filepath, {
114-
encoding: 'utf8',
115-
// Lazily access constants.abortSignal.
116-
signal: constants.abortSignal,
117-
...(typeof options === 'string' ? { encoding: options } : options),
118-
})
119-
} catch {}
120-
return undefined
121-
}
122-
123-
export function safeReadFileSync(
124-
filepath: PathOrFileDescriptor,
125-
options?: 'utf8' | 'utf-8' | { encoding: 'utf8' | 'utf-8' } | undefined,
126-
): string | undefined
127-
128-
export function safeReadFileSync(
129-
filepath: PathOrFileDescriptor,
130-
options?:
131-
| {
132-
encoding?: NodeJS.BufferEncoding | undefined
133-
flag?: string | undefined
134-
}
135-
| NodeJS.BufferEncoding
136-
| undefined,
137-
): ReturnType<typeof readFileSync> | undefined {
138-
try {
139-
return readFileSync(filepath, {
140-
encoding: 'utf8',
141-
...(typeof options === 'string' ? { encoding: options } : options),
142-
})
143-
} catch {}
144-
return undefined
145-
}
146-
147-
export function safeStatsSync(
148-
filepath: PathLike,
149-
options?: undefined,
150-
): Stats | undefined
151-
152-
export function safeStatsSync(
153-
filepath: PathLike,
154-
options?: StatSyncOptions & {
155-
bigint?: false | undefined
156-
},
157-
): Stats | undefined
158-
159-
export function safeStatsSync(
160-
filepath: PathLike,
161-
options: StatSyncOptions & {
162-
bigint: true
163-
},
164-
): BigIntStats | undefined
165-
166-
export function safeStatsSync(
167-
filepath: PathLike,
168-
options: StatSyncOptions & {
169-
bigint: boolean
170-
},
171-
): Stats | BigIntStats | undefined
172-
173-
export function safeStatsSync(
174-
filepath: PathLike,
175-
options?: StatSyncOptions,
176-
): Stats | BigIntStats | undefined {
177-
try {
178-
return statSync(filepath, { throwIfNoEntry: false, ...options })
179-
} catch {}
180-
return undefined
181-
}

0 commit comments

Comments
 (0)