Skip to content

Commit e8ad2f4

Browse files
committed
refactor(cli): replace console.log/error/warn with logger
Refactored all console usage in executable code to use logger from @socketsecurity/lib/logger for CLAUDE.md compliance. Changes: - Replaced 24 console instances across 16 files - CLI entry points: pnpm-cli, npm-cli, npx-cli, yarn-cli (4 files) - Bootstrap: node.mts (7 instances) - Command apps: analytics, audit-log, threat-feed (3 files) - Utilities: with-subcommands, patches, npm-registry, sea/build, FramedHeader, notifier (6 files) Pattern: - console.log → logger.log - console.error → logger.error - console.warn → logger.warn Intentionally preserved: - 33 JSDoc example comments (documentation) - 10 test file fixtures (test content) Build verified: ✓ All tests passing
1 parent aaa4924 commit e8ad2f4

File tree

16 files changed

+85
-35
lines changed

16 files changed

+85
-35
lines changed

packages/cli/src/bootstrap/node.mts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { existsSync, promises as fs } from 'node:fs'
1919
import path from 'node:path'
2020

2121
import { safeMkdir } from '@socketsecurity/lib/fs'
22+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
2223

2324
import { getNodeDisableSigusr1Flags } from './shared/node-flags.mjs'
2425
import {
@@ -28,6 +29,8 @@ import {
2829
getDlxDir,
2930
} from './shared/paths.mjs'
3031

32+
const logger = getDefaultLogger()
33+
3134
/**
3235
* Check if CLI is installed.
3336
*/
@@ -48,7 +51,7 @@ async function downloadCli(): Promise<void> {
4851

4952
await safeMkdir(dlxDir, { recursive: true })
5053

51-
console.error(`Downloading ${packageName}...`)
54+
logger.error(`Downloading ${packageName}...`)
5255

5356
return new Promise((resolve, reject) => {
5457
const npmPackProcess = spawn(
@@ -101,7 +104,7 @@ async function downloadCli(): Promise<void> {
101104
// Ignore cleanup errors.
102105
})
103106

104-
console.error('Socket CLI installed successfully')
107+
logger.error('Socket CLI installed successfully')
105108
resolve()
106109
})
107110
} catch (e) {
@@ -117,11 +120,11 @@ async function downloadCli(): Promise<void> {
117120
async function main(): Promise<void> {
118121
// Check if CLI is already installed.
119122
if (!isCliInstalled()) {
120-
console.error('Socket CLI not installed yet.')
123+
logger.error('Socket CLI not installed yet.')
121124
try {
122125
await downloadCli()
123126
} catch (error) {
124-
console.error('Failed to download Socket CLI:', error)
127+
logger.error('Failed to download Socket CLI:', error)
125128
// eslint-disable-next-line n/no-process-exit
126129
process.exit(1)
127130
}
@@ -141,7 +144,7 @@ async function main(): Promise<void> {
141144
)
142145

143146
child.on('error', error => {
144-
console.error('Failed to spawn CLI:', error)
147+
logger.error('Failed to spawn CLI:', error)
145148
// eslint-disable-next-line n/no-process-exit
146149
process.exit(1)
147150
})
@@ -155,7 +158,7 @@ async function main(): Promise<void> {
155158
// Only run if executed directly (not when loaded as module).
156159
if (import.meta.url === `file://${process.argv[1]}`) {
157160
main().catch(error => {
158-
console.error('Bootstrap error:', error)
161+
logger.error('Bootstrap error:', error)
159162
// eslint-disable-next-line n/no-process-exit
160163
process.exit(1)
161164
})

packages/cli/src/cli-dispatch.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818

1919
import path from 'node:path'
2020

21+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
22+
2123
import { waitForBootstrapHandshake } from './utils/sea/boot.mjs'
2224

25+
const logger = getDefaultLogger()
26+
2327
// Detect how this binary was invoked.
2428
function getInvocationMode(): string {
2529
// Check environment variable first (for explicit mode).
@@ -128,7 +132,7 @@ async function main() {
128132

129133
// Run the appropriate CLI.
130134
main().catch(error => {
131-
console.error('Socket CLI Error:', error)
135+
logger.error('Socket CLI Error:', error)
132136
// eslint-disable-next-line n/no-process-exit -- Required for CLI error handling.
133137
process.exit(1)
134138
})

packages/cli/src/commands/analytics/analytics-app-cli.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import { pathToFileURL } from 'node:url'
55

66
import { render } from 'ink'
7+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
78
import React from 'react'
89

10+
const logger = getDefaultLogger()
11+
912
/**
1013
* Run the Ink AnalyticsApp with data from stdin.
1114
*/
@@ -28,7 +31,7 @@ async function main() {
2831
}
2932

3033
main().catch(e => {
31-
console.error('Error running AnalyticsApp:', e)
34+
logger.error('Error running AnalyticsApp:', e)
3235
// eslint-disable-next-line n/no-process-exit
3336
process.exit(1)
3437
})

packages/cli/src/commands/audit-log/audit-log-app-cli.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import { pathToFileURL } from 'node:url'
55

66
import { render } from 'ink'
7+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
78
import React from 'react'
89

10+
const logger = getDefaultLogger()
11+
912
/**
1013
* Run the Ink AuditLogApp with data from stdin.
1114
*/
@@ -33,7 +36,7 @@ async function main() {
3336
}
3437

3538
main().catch(e => {
36-
console.error('Error running AuditLogApp:', e)
39+
logger.error('Error running AuditLogApp:', e)
3740
// eslint-disable-next-line n/no-process-exit
3841
process.exit(1)
3942
})

packages/cli/src/commands/threat-feed/threat-feed-app-cli.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import { pathToFileURL } from 'node:url'
55

66
import { render } from 'ink'
7+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
78
import React from 'react'
89

10+
const logger = getDefaultLogger()
11+
912
/**
1013
* Run the Ink ThreatFeedApp with data from stdin.
1114
*/
@@ -28,7 +31,7 @@ async function main() {
2831
}
2932

3033
main().catch(e => {
31-
console.error('Error running ThreatFeedApp:', e)
34+
logger.error('Error running ThreatFeedApp:', e)
3235
// eslint-disable-next-line n/no-process-exit
3336
process.exit(1)
3437
})

packages/cli/src/meow.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
*/
55

66
import { parseArgs } from '@socketsecurity/lib/argv/parse'
7+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
78
import { readPackageJsonSync } from '@socketsecurity/lib/packages'
89

910
import type { ParseArgsConfig } from '@socketsecurity/lib/argv/parse'
1011

12+
const logger = getDefaultLogger()
13+
1114
export interface MeowFlag {
1215
readonly type?: 'string' | 'boolean' | 'number'
1316
readonly shortFlag?: string
@@ -173,13 +176,13 @@ export default function meow<
173176
}
174177

175178
const showHelp = (exitCode = 2) => {
176-
console.log(fullHelp)
179+
logger.log(fullHelp)
177180
// eslint-disable-next-line n/no-process-exit -- Required for CLI exit behavior.
178181
process.exit(exitCode)
179182
}
180183

181184
const showVersion = () => {
182-
console.log(pkg['version'] || '0.0.0')
185+
logger.log(pkg['version'] || '0.0.0')
183186
// eslint-disable-next-line n/no-process-exit -- Required for CLI exit behavior.
184187
process.exit(0)
185188
}

packages/cli/src/npm-cli.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env node
22

3+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
4+
35
import shadowNpmBin from './shadow/npm/bin.mts'
46

7+
const logger = getDefaultLogger()
8+
59
export default async function runNpmCli() {
610
process.exitCode = 1
711

@@ -24,7 +28,7 @@ export default async function runNpmCli() {
2428
// Run if invoked directly (not as a module).
2529
if (import.meta.url === `file://${process.argv[1]}`) {
2630
runNpmCli().catch(error => {
27-
console.error('Socket npm wrapper error:', error)
31+
logger.error('Socket npm wrapper error:', error)
2832
// eslint-disable-next-line n/no-process-exit
2933
process.exit(1)
3034
})

packages/cli/src/npx-cli.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env node
22

3+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
4+
35
import shadowNpxBin from './shadow/npx/bin.mts'
46

7+
const logger = getDefaultLogger()
8+
59
export default async function runNpxCli() {
610
process.exitCode = 1
711

@@ -22,7 +26,7 @@ export default async function runNpxCli() {
2226
// Run if invoked directly (not as a module).
2327
if (import.meta.url === `file://${process.argv[1]}`) {
2428
runNpxCli().catch(error => {
25-
console.error('Socket npx wrapper error:', error)
29+
logger.error('Socket npx wrapper error:', error)
2630
// eslint-disable-next-line n/no-process-exit
2731
process.exit(1)
2832
})

packages/cli/src/pnpm-cli.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env node
22

3+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
4+
35
import shadowPnpmBin from './shadow/pnpm/bin.mts'
46

7+
const logger = getDefaultLogger()
8+
59
export default async function runPnpmCli() {
610
process.exitCode = 1
711

@@ -24,7 +28,7 @@ export default async function runPnpmCli() {
2428
// Run if invoked directly (not as a module).
2529
if (import.meta.url === `file://${process.argv[1]}`) {
2630
runPnpmCli().catch(error => {
27-
console.error('Socket pnpm wrapper error:', error)
31+
logger.error('Socket pnpm wrapper error:', error)
2832
// eslint-disable-next-line n/no-process-exit
2933
process.exit(1)
3034
})

packages/cli/src/utils/cli/with-subcommands.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,8 @@ export function meowOrExit(
977977

978978
// Meow doesn't detect 'version' as an unknown flag, so we do the leg work here.
979979
if (versionFlag && !hasOwn(cliConfig.flags, 'version')) {
980-
// Use `console.error` here instead of `getDefaultLogger().error` to match Meow behavior.
981-
console.error('Unknown flag\n--version')
980+
const logger = getDefaultLogger()
981+
logger.error('Unknown flag\n--version')
982982
// eslint-disable-next-line n/no-process-exit
983983
process.exit(2)
984984
// This line is never reached in production, but helps tests.

0 commit comments

Comments
 (0)