Skip to content

Commit 90bb01f

Browse files
committed
refactor(cli): route HOME reads through src/env/home.mts
5 commands were reading process env directly to construct paths to ~/.config/socket/config.json or ~/.bashrc. Replace with imports of the typed HOME constant from src/env/home.mts (already used elsewhere in the codebase) so env access stays centralized. Files migrated: - commands/install/cmd-install-completion.mts (bashrc path) - commands/config/cmd-config-auto.mts - commands/config/config-command-factory.mts - commands/login/cmd-login.mts - commands/logout/cmd-logout.mts
1 parent c15caf7 commit 90bb01f

5 files changed

Lines changed: 10 additions & 5 deletions

File tree

packages/cli/src/commands/config/cmd-config-auto.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { handleConfigAuto } from './handle-config-auto.mts'
22
import { FLAG_JSON, FLAG_MARKDOWN } from '../../constants/cli.mts'
3+
import { HOME } from '../../env/home.mts'
34
import { outputDryRunWrite } from '../../utils/dry-run/output.mts'
45
import { defineFlags } from '../../meow.mts'
56
import { commonFlags, outputFlags } from '../../flags.mts'
@@ -101,7 +102,7 @@ ${getSupportedConfigEntries()
101102
}
102103

103104
if (dryRun) {
104-
const configPath = `${process.env['HOME']}/.config/socket/config.json`
105+
const configPath = `${HOME}/.config/socket/config.json`
105106
outputDryRunWrite(
106107
configPath,
107108
`auto-discover and set config value for "${key}"`,

packages/cli/src/commands/config/config-command-factory.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FLAG_JSON, FLAG_MARKDOWN } from '../../constants/cli.mjs'
2+
import { HOME } from '../../env/home.mts'
23
import { outputDryRunWrite } from '../../utils/dry-run/output.mts'
34
import { commonFlags, outputFlags } from '../../flags.mts'
45
import { meowOrExit } from '../../utils/cli/with-subcommands.mjs'
@@ -130,7 +131,7 @@ ${spec.helpExamples.map(ex => ` $ ${command} ${ex}`).join('\n')}
130131
}
131132

132133
if (dryRun) {
133-
const configPath = `${process.env['HOME']}/.config/socket/config.json`
134+
const configPath = `${HOME}/.config/socket/config.json`
134135
const changes = spec.needsValue
135136
? [`Set "${key}" to: ${value}`]
136137
: [`Remove "${key}" from config`]

packages/cli/src/commands/install/cmd-install-completion.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { handleInstallCompletion } from './handle-install-completion.mts'
2+
import { HOME } from '../../env/home.mts'
23
import { outputDryRunWrite } from '../../utils/dry-run/output.mts'
34
import { defineFlags } from '../../meow.mts'
45
import { commonFlags } from '../../flags.mts'
@@ -67,7 +68,7 @@ async function run(
6768
const targetName = cli.input[0] || 'socket'
6869

6970
if (dryRun) {
70-
const bashRcPath = `${process.env['HOME']}/.bashrc`
71+
const bashRcPath = `${HOME}/.bashrc`
7172
outputDryRunWrite(
7273
bashRcPath,
7374
`install bash completion for "${targetName}"`,

packages/cli/src/commands/login/cmd-login.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import isInteractive from '@socketregistry/is-interactive/index.cjs'
22

33
import { attemptLogin } from './attempt-login.mts'
4+
import { HOME } from '../../env/home.mts'
45
import { outputDryRunWrite } from '../../utils/dry-run/output.mts'
56
import { defineFlags } from '../../meow.mts'
67
import { commonFlags } from '../../flags.mts'
@@ -82,7 +83,7 @@ async function run(
8283
const dryRun = !!cli.flags['dryRun']
8384

8485
if (dryRun) {
85-
const configPath = `${process.env['HOME']}/.config/socket/config.json`
86+
const configPath = `${HOME}/.config/socket/config.json`
8687
const changes = [
8788
'Prompt for Socket API token',
8889
'Verify token with Socket API',

packages/cli/src/commands/logout/cmd-logout.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getDefaultLogger } from '@socketsecurity/lib/logger'
22

3+
import { HOME } from '../../env/home.mts'
34
import { outputDryRunDelete } from '../../utils/dry-run/output.mts'
45
import {
56
CONFIG_KEY_API_BASE_URL,
@@ -84,7 +85,7 @@ export async function run(
8485
const dryRun = !!cli.flags['dryRun']
8586

8687
if (dryRun) {
87-
const configPath = `${process.env['HOME']}/.config/socket/config.json`
88+
const configPath = `${HOME}/.config/socket/config.json`
8889
outputDryRunDelete('Socket API credentials', configPath)
8990
return
9091
}

0 commit comments

Comments
 (0)