Skip to content

Commit 6861fcb

Browse files
committed
refactor(env): sort functions alphabetically in env modules
1 parent abc11cf commit 6861fcb

File tree

4 files changed

+87
-87
lines changed

4 files changed

+87
-87
lines changed

src/env/rewire.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ if (isVitestEnv && !globalThis[sharedOverridesSymbol]) {
5151
const sharedOverrides: Map<string, string | undefined> | undefined =
5252
globalThis[sharedOverridesSymbol]
5353

54+
/**
55+
* Clear a specific environment variable override.
56+
*/
57+
export function clearEnv(key: string): void {
58+
sharedOverrides?.delete(key)
59+
}
60+
5461
/**
5562
* Get an environment variable value, checking overrides first.
5663
*
@@ -77,6 +84,14 @@ export function getEnvValue(key: string): string | undefined {
7784
return process.env[key]
7885
}
7986

87+
/**
88+
* Check if an environment variable has been overridden.
89+
*/
90+
export function hasOverride(key: string): boolean {
91+
const isolatedOverrides = isolatedOverridesStorage.getStore()
92+
return !!(isolatedOverrides?.has(key) || sharedOverrides?.has(key))
93+
}
94+
8095
/**
8196
* Check if an environment variable exists (has a key), checking overrides first.
8297
*
@@ -103,6 +118,23 @@ export function isInEnv(key: string): boolean {
103118
return hasOwn(process.env, key)
104119
}
105120

121+
/**
122+
* Clear all environment variable overrides.
123+
* Useful in afterEach hooks to ensure clean test state.
124+
*
125+
* @example
126+
* ```typescript
127+
* import { resetEnv } from './rewire'
128+
*
129+
* afterEach(() => {
130+
* resetEnv()
131+
* })
132+
* ```
133+
*/
134+
export function resetEnv(): void {
135+
sharedOverrides?.clear()
136+
}
137+
106138
/**
107139
* Set an environment variable override for testing.
108140
* This does not modify process.env, only affects env getters.
@@ -132,38 +164,6 @@ export function setEnv(key: string, value: string | undefined): void {
132164
sharedOverrides?.set(key, value)
133165
}
134166

135-
/**
136-
* Clear a specific environment variable override.
137-
*/
138-
export function clearEnv(key: string): void {
139-
sharedOverrides?.delete(key)
140-
}
141-
142-
/**
143-
* Clear all environment variable overrides.
144-
* Useful in afterEach hooks to ensure clean test state.
145-
*
146-
* @example
147-
* ```typescript
148-
* import { resetEnv } from './rewire'
149-
*
150-
* afterEach(() => {
151-
* resetEnv()
152-
* })
153-
* ```
154-
*/
155-
export function resetEnv(): void {
156-
sharedOverrides?.clear()
157-
}
158-
159-
/**
160-
* Check if an environment variable has been overridden.
161-
*/
162-
export function hasOverride(key: string): boolean {
163-
const isolatedOverrides = isolatedOverridesStorage.getStore()
164-
return !!(isolatedOverrides?.has(key) || sharedOverrides?.has(key))
165-
}
166-
167167
/**
168168
* Run code with environment overrides in an isolated AsyncLocalStorage context.
169169
* Creates true context isolation - overrides don't leak to concurrent code.

src/env/socket-cli.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ export function getSocketCliApiToken(): string | undefined {
7676
)
7777
}
7878

79+
/**
80+
* Bootstrap cache directory path.
81+
* Set by bootstrap wrappers to pass dlx cache location to CLI.
82+
*
83+
* @returns Bootstrap cache directory or undefined
84+
*/
85+
/*@__NO_SIDE_EFFECTS__*/
86+
export function getSocketCliBootstrapCacheDir(): string | undefined {
87+
return getEnvValue('SOCKET_CLI_BOOTSTRAP_CACHE_DIR')
88+
}
89+
90+
/**
91+
* Bootstrap package spec (e.g., @socketsecurity/cli@^2.0.11).
92+
* Set by bootstrap wrappers (SEA/smol/npm) to pass package spec to CLI.
93+
*
94+
* @returns Bootstrap package spec or undefined
95+
*/
96+
/*@__NO_SIDE_EFFECTS__*/
97+
export function getSocketCliBootstrapSpec(): string | undefined {
98+
return getEnvValue('SOCKET_CLI_BOOTSTRAP_SPEC')
99+
}
100+
79101
/**
80102
* Socket CLI configuration file path (alternative name).
81103
*
@@ -96,6 +118,21 @@ export function getSocketCliFix(): string | undefined {
96118
return getEnvValue('SOCKET_CLI_FIX')
97119
}
98120

121+
/**
122+
* Socket CLI GitHub authentication token.
123+
* Checks SOCKET_CLI_GITHUB_TOKEN, SOCKET_SECURITY_GITHUB_PAT, then falls back to GITHUB_TOKEN.
124+
*
125+
* @returns GitHub token or undefined
126+
*/
127+
/*@__NO_SIDE_EFFECTS__*/
128+
export function getSocketCliGithubToken(): string | undefined {
129+
return (
130+
getEnvValue('SOCKET_CLI_GITHUB_TOKEN') ||
131+
getEnvValue('SOCKET_SECURITY_GITHUB_PAT') ||
132+
getEnvValue('GITHUB_TOKEN')
133+
)
134+
}
135+
99136
/**
100137
* Whether to skip Socket CLI API token requirement (alternative name).
101138
*
@@ -136,40 +173,3 @@ export function getSocketCliOrgSlug(): string | undefined {
136173
export function getSocketCliViewAllRisks(): boolean {
137174
return envAsBoolean(getEnvValue('SOCKET_CLI_VIEW_ALL_RISKS'))
138175
}
139-
140-
/**
141-
* Socket CLI GitHub authentication token.
142-
* Checks SOCKET_CLI_GITHUB_TOKEN, SOCKET_SECURITY_GITHUB_PAT, then falls back to GITHUB_TOKEN.
143-
*
144-
* @returns GitHub token or undefined
145-
*/
146-
/*@__NO_SIDE_EFFECTS__*/
147-
export function getSocketCliGithubToken(): string | undefined {
148-
return (
149-
getEnvValue('SOCKET_CLI_GITHUB_TOKEN') ||
150-
getEnvValue('SOCKET_SECURITY_GITHUB_PAT') ||
151-
getEnvValue('GITHUB_TOKEN')
152-
)
153-
}
154-
155-
/**
156-
* Bootstrap package spec (e.g., @socketsecurity/cli@^2.0.11).
157-
* Set by bootstrap wrappers (SEA/smol/npm) to pass package spec to CLI.
158-
*
159-
* @returns Bootstrap package spec or undefined
160-
*/
161-
/*@__NO_SIDE_EFFECTS__*/
162-
export function getSocketCliBootstrapSpec(): string | undefined {
163-
return getEnvValue('SOCKET_CLI_BOOTSTRAP_SPEC')
164-
}
165-
166-
/**
167-
* Bootstrap cache directory path.
168-
* Set by bootstrap wrappers to pass dlx cache location to CLI.
169-
*
170-
* @returns Bootstrap cache directory or undefined
171-
*/
172-
/*@__NO_SIDE_EFFECTS__*/
173-
export function getSocketCliBootstrapCacheDir(): string | undefined {
174-
return getEnvValue('SOCKET_CLI_BOOTSTRAP_CACHE_DIR')
175-
}

src/env/temp-dir.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55

66
import { getEnvValue } from './rewire'
77

8-
/**
9-
* TMPDIR environment variable.
10-
* Unix/macOS temporary directory path.
11-
*/
12-
/*@__NO_SIDE_EFFECTS__*/
13-
export function getTmpdir(): string | undefined {
14-
return getEnvValue('TMPDIR')
15-
}
16-
178
/**
189
* TEMP environment variable.
1910
* Windows temporary directory path.
@@ -31,3 +22,12 @@ export function getTemp(): string | undefined {
3122
export function getTmp(): string | undefined {
3223
return getEnvValue('TMP')
3324
}
25+
26+
/**
27+
* TMPDIR environment variable.
28+
* Unix/macOS temporary directory path.
29+
*/
30+
/*@__NO_SIDE_EFFECTS__*/
31+
export function getTmpdir(): string | undefined {
32+
return getEnvValue('TMPDIR')
33+
}

src/env/windows.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ export function getAppdata(): string | undefined {
1414
return getEnvValue('APPDATA')
1515
}
1616

17+
/**
18+
* COMSPEC environment variable.
19+
* Points to the Windows command processor (typically cmd.exe).
20+
*/
21+
/*@__NO_SIDE_EFFECTS__*/
22+
export function getComspec(): string | undefined {
23+
return getEnvValue('COMSPEC')
24+
}
25+
1726
/**
1827
* LOCALAPPDATA environment variable.
1928
* Points to the Local Application Data directory on Windows.
@@ -31,12 +40,3 @@ export function getLocalappdata(): string | undefined {
3140
export function getUserprofile(): string | undefined {
3241
return getEnvValue('USERPROFILE')
3342
}
34-
35-
/**
36-
* COMSPEC environment variable.
37-
* Points to the Windows command processor (typically cmd.exe).
38-
*/
39-
/*@__NO_SIDE_EFFECTS__*/
40-
export function getComspec(): string | undefined {
41-
return getEnvValue('COMSPEC')
42-
}

0 commit comments

Comments
 (0)