Skip to content

Commit 3cb7578

Browse files
committed
fix(imports): node-builtin — 7 files converted to named imports
1 parent 53ddb3a commit 3cb7578

7 files changed

Lines changed: 32 additions & 30 deletions

File tree

packages/cli/src/constants/agents.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Functions for package manager version requirements and execution paths.
44
*/
55

6-
import fs from 'node:fs'
6+
import { existsSync } from 'node:fs'
77
import path from 'node:path'
88

99
import { whichReal } from '@socketsecurity/lib/bin'
@@ -63,7 +63,7 @@ export async function getNpmExecPath(): Promise<string> {
6363
// Check npm in the same directory as node.
6464
const nodeDir = path.dirname(process.execPath)
6565
const npmInNodeDir = path.join(nodeDir, NPM)
66-
if (fs.existsSync(npmInNodeDir)) {
66+
if (existsSync(npmInNodeDir)) {
6767
return npmInNodeDir
6868
}
6969
// Fall back to whichReal.

packages/cli/src/utils/cli/completion.mts

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

44
import { getSocketAppDataPath, rootPath } from '../../constants/paths.mts'
@@ -70,7 +70,7 @@ export function getCompletionSourcingCommand(): CResult<string> {
7070
'socket-completion.bash',
7171
)
7272

73-
if (!fs.existsSync(completionScriptPath)) {
73+
if (!existsSync(completionScriptPath)) {
7474
return {
7575
ok: false,
7676
message: 'Tab Completion script not found',

packages/cli/src/utils/ecosystem/environment.mts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* - Configuring concurrent execution limits
2626
*/
2727

28-
import fs from 'node:fs'
28+
import { existsSync } from 'node:fs'
2929
import path from 'node:path'
3030

3131
import browserslist from 'browserslist'
@@ -287,7 +287,7 @@ export async function detectPackageEnvironment({
287287
)
288288
: await findUp(PACKAGE_JSON, { cwd })
289289
const pkgPath =
290-
pkgJsonPath && fs.existsSync(pkgJsonPath)
290+
pkgJsonPath && existsSync(pkgJsonPath)
291291
? path.dirname(pkgJsonPath)
292292
: undefined
293293
const pkgJson = pkgPath ? await readPackageJson(pkgPath) : undefined
@@ -447,20 +447,20 @@ export async function getAgentExecPath(agent: Agent): Promise<string> {
447447
if (binName === NPM) {
448448
// Try to use getNpmExecPath() first, but verify it exists.
449449
const npmPath = preferWindowsCmdShim(await getNpmExecPath(), NPM)
450-
if (fs.existsSync(npmPath)) {
450+
if (existsSync(npmPath)) {
451451
return npmPath
452452
}
453453
// If getNpmExecPath() doesn't exist, try common locations.
454454
// Check npm in the same directory as node.
455455
const nodeDir = path.dirname(process.execPath)
456456
if (WIN32) {
457457
const npmCmdInNodeDir = path.join(nodeDir, `${NPM}.cmd`)
458-
if (fs.existsSync(npmCmdInNodeDir)) {
458+
if (existsSync(npmCmdInNodeDir)) {
459459
return npmCmdInNodeDir
460460
}
461461
}
462462
const npmInNodeDir = path.join(nodeDir, NPM)
463-
if (fs.existsSync(npmInNodeDir)) {
463+
if (existsSync(npmInNodeDir)) {
464464
return preferWindowsCmdShim(npmInNodeDir, NPM)
465465
}
466466
// Fall back to which.
@@ -473,7 +473,7 @@ export async function getAgentExecPath(agent: Agent): Promise<string> {
473473
if (binName === PNPM) {
474474
// Try to use getPnpmExecPath() first, but verify it exists.
475475
const pnpmPath = await getPnpmExecPath()
476-
if (fs.existsSync(pnpmPath)) {
476+
if (existsSync(pnpmPath)) {
477477
return pnpmPath
478478
}
479479
// Fall back to which.

packages/cli/src/utils/ecosystem/windows-shims.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* when one exists (so child_process can spawn it without `shell: true`).
1010
*/
1111

12-
import fs from 'node:fs'
12+
import { existsSync, readFileSync } from 'node:fs'
1313
import path from 'node:path'
1414

1515
import { WIN32 } from '@socketsecurity/lib/constants/platform'
@@ -46,7 +46,7 @@ export function preferWindowsCmdShim(binPath: string, binName: string): string {
4646
}
4747

4848
const cmdShim = path.join(path.dirname(binPath), `${binName}.cmd`)
49-
return fs.existsSync(cmdShim) ? cmdShim : binPath
49+
return existsSync(cmdShim) ? cmdShim : binPath
5050
}
5151

5252
/**
@@ -60,12 +60,12 @@ export function preferWindowsCmdShim(binPath: string, binName: string): string {
6060
* `npm-cli.js` entry point so we can spawn them via Node directly.
6161
*/
6262
export function resolveBinPathSync(binPath: string): string {
63-
if (!fs.existsSync(binPath)) {
63+
if (!existsSync(binPath)) {
6464
return binPath
6565
}
6666

6767
try {
68-
const content = fs.readFileSync(binPath, 'utf8')
68+
const content = readFileSync(binPath, 'utf8')
6969
// Look for common shim patterns:
7070
// node "C:\path\to\npm-cli.js" "$@"
7171
// "%_prog%" "%dp0%\node_modules\npm\bin\npm-cli.js" %*

packages/cli/src/utils/npm/paths.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from 'node:fs'
1+
import { existsSync } from 'node:fs'
22
import Module from 'node:module'
33
import path from 'node:path'
44

@@ -83,7 +83,7 @@ export function getNpmRequire(): NodeJS.Require {
8383
const npmNmPath = path.join(npmDirPath, `${NODE_MODULES}/npm`)
8484
_npmRequire = Module.createRequire(
8585
path.join(
86-
fs.existsSync(npmNmPath) ? npmNmPath : npmDirPath,
86+
existsSync(npmNmPath) ? npmNmPath : npmDirPath,
8787
'<placeholder-basename>',
8888
),
8989
)

packages/cli/src/utils/process/os.mts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
* - File permission management
2727
*/
2828

29-
import fs from 'node:fs'
29+
import { existsSync, readFileSync } from 'node:fs'
30+
import { chmod } from 'node:fs/promises'
3031

3132
import { errorMessage } from '@socketsecurity/lib/errors'
3233
import { getDefaultLogger } from '@socketsecurity/lib/logger'
@@ -143,8 +144,8 @@ export function detectMusl(): boolean {
143144

144145
// Method 1: Check /etc/os-release for Alpine.
145146
try {
146-
if (fs.existsSync('/etc/os-release')) {
147-
const osRelease = fs.readFileSync('/etc/os-release', 'utf8')
147+
if (existsSync('/etc/os-release')) {
148+
const osRelease = readFileSync('/etc/os-release', 'utf8')
148149
if (osRelease.includes('Alpine') || osRelease.includes('alpine')) {
149150
cachedLibc = 'musl'
150151
return true
@@ -157,8 +158,8 @@ export function detectMusl(): boolean {
157158
// Method 2: Check if ldd references musl.
158159
try {
159160
if (
160-
fs.existsSync('/lib/ld-musl-x86_64.so.1') ||
161-
fs.existsSync('/lib/ld-musl-aarch64.so.1')
161+
existsSync('/lib/ld-musl-x86_64.so.1') ||
162+
existsSync('/lib/ld-musl-aarch64.so.1')
162163
) {
163164
cachedLibc = 'musl'
164165
return true
@@ -169,8 +170,8 @@ export function detectMusl(): boolean {
169170

170171
// Method 3: Check /proc/version for musl indicators.
171172
try {
172-
if (fs.existsSync('/proc/version')) {
173-
const version = fs.readFileSync('/proc/version', 'utf8')
173+
if (existsSync('/proc/version')) {
174+
const version = readFileSync('/proc/version', 'utf8')
174175
if (version.includes('musl')) {
175176
cachedLibc = 'musl'
176177
return true
@@ -249,7 +250,7 @@ export async function ensureExecutable(filePath: string): Promise<void> {
249250
}
250251

251252
try {
252-
await fs.promises.chmod(filePath, 0o755)
253+
await chmod(filePath, 0o755)
253254
logger.log('Set executable permissions')
254255
} catch (e) {
255256
logger.warn(`Failed to set executable permissions: ${errorMessage(e)}`)

packages/cli/src/utils/socket/json.mts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
* - Supports both read and write operations
1919
*/
2020

21-
import fs from 'node:fs'
21+
import { existsSync, readFileSync } from 'node:fs'
22+
import { readFile, writeFile } from 'node:fs/promises'
2223
import path from 'node:path'
2324

2425
import { debugDirNs, debugNs } from '@socketsecurity/lib/debug'
@@ -127,14 +128,14 @@ export async function readSocketJson(
127128
defaultOnError = false,
128129
): Promise<CResult<SocketJson>> {
129130
const sockJsonPath = path.join(cwd, SOCKET_JSON)
130-
if (!fs.existsSync(sockJsonPath)) {
131+
if (!existsSync(sockJsonPath)) {
131132
debugNs('notice', `miss: ${SOCKET_JSON} not found at ${cwd}`)
132133
return { ok: true, data: getDefaultSocketJson() }
133134
}
134135

135136
let json = undefined
136137
try {
137-
json = await fs.promises.readFile(sockJsonPath, 'utf8')
138+
json = await readFile(sockJsonPath, 'utf8')
138139
} catch (e) {
139140
if (defaultOnError) {
140141
logger.warn(`Failed to read ${SOCKET_JSON}, using default`)
@@ -188,13 +189,13 @@ export function readSocketJsonSync(
188189
defaultOnError = false,
189190
): CResult<SocketJson> {
190191
const sockJsonPath = path.join(cwd, SOCKET_JSON)
191-
if (!fs.existsSync(sockJsonPath)) {
192+
if (!existsSync(sockJsonPath)) {
192193
debugNs('notice', `miss: ${SOCKET_JSON} not found at ${cwd}`)
193194
return { ok: true, data: getDefaultSocketJson() }
194195
}
195196
let jsonContent = undefined
196197
try {
197-
jsonContent = fs.readFileSync(sockJsonPath, 'utf8')
198+
jsonContent = readFileSync(sockJsonPath, 'utf8')
198199
} catch (e) {
199200
if (defaultOnError) {
200201
logger.warn(`Failed to read ${SOCKET_JSON}, using default`)
@@ -262,7 +263,7 @@ export async function writeSocketJson(
262263
}
263264

264265
const filepath = path.join(cwd, SOCKET_JSON)
265-
await fs.promises.writeFile(filepath, `${jsonContent}\n`, 'utf8')
266+
await writeFile(filepath, `${jsonContent}\n`, 'utf8')
266267

267268
return { ok: true, data: undefined }
268269
}

0 commit comments

Comments
 (0)