Skip to content

Commit 3bfb64e

Browse files
committed
refactor: remove incorrect @__NO_SIDE_EFFECTS__ annotations
Remove @__NO_SIDE_EFFECTS__ annotations from functions that perform side effects: **Process execution (src/agent.ts)**: - execNpm() - spawns npm child processes - execPnpm() - spawns pnpm child processes - execYarn() - spawns yarn child processes - execScript() - spawns script child processes **Filesystem mutations (src/fs.ts)**: - safeDelete() / safeDeleteSync() - delete files/directories - safeMkdir() / safeMkdirSync() - create directories - writeJson() / writeJsonSync() - write to filesystem These functions all have observable side effects and should not be marked as side-effect free for tree-shaking purposes. refactor: add @__NO_SIDE_EFFECTS__ to pure getter functions Add @__NO_SIDE_EFFECTS__ annotations to pure functions for better tree-shaking: **Environment variable getters (src/env/)** (~71 functions): - All getters in ci.ts, debug.ts, github.ts, home.ts, locale.ts, node-auth-token.ts, node-env.ts, npm.ts, package-manager.ts, path.ts, pre-commit.ts, shell.ts, socket-cli-shadow.ts, socket-cli.ts, socket.ts, temp-dir.ts, term.ts, test.ts, windows.ts, xdg.ts - Helpers: envAsBoolean(), envAsNumber(), envAsString() **Package constant getters (src/constants/packages.ts)** (7 functions): - getPackageDefaultNodeRange() - lazy-loads cached constant - getPackageDefaultSocketCategories() - lazy-loads cached constant - getPackageExtensions() - lazy-loads cached constant - getNpmLifecycleEvent() - pure wrapper around env getter - getLifecycleScriptNames() - lazy-loads cached constant - getPackumentCache() - lazy-initializes Map (returns same instance) - getPacoteCachePath() - lazy-loads cached constant These are all pure functions that only read/cache values without observable side effects.
1 parent 02875b3 commit 3bfb64e

24 files changed

Lines changed: 85 additions & 11 deletions

src/agent.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ const yarnInstallLikeCommands = new Set([
8383
* SECURITY: Uses array-based arguments to prevent command injection. All elements
8484
* in the args array are properly escaped by Node.js when passed to spawn().
8585
*/
86-
/*@__NO_SIDE_EFFECTS__*/
8786
export function execNpm(args: string[], options?: SpawnOptions | undefined) {
8887
const useDebug = isDebug()
8988
const terminatorPos = args.indexOf('--')
@@ -146,8 +145,6 @@ export interface PnpmOptions extends SpawnOptions {
146145
* SECURITY: Uses array-based arguments to prevent command injection. All elements
147146
* in the args array are properly escaped by Node.js when passed to execBin().
148147
*/
149-
/*@__NO_SIDE_EFFECTS__*/
150-
151148
export function execPnpm(args: string[], options?: PnpmOptions | undefined) {
152149
const { allowLockfileUpdate, ...extBinOpts } = {
153150
__proto__: null,
@@ -215,7 +212,6 @@ export function execPnpm(args: string[], options?: PnpmOptions | undefined) {
215212
* SECURITY: Uses array-based arguments to prevent command injection. All elements
216213
* in the args array are properly escaped by Node.js when passed to execBin().
217214
*/
218-
/*@__NO_SIDE_EFFECTS__*/
219215
export function execYarn(
220216
args: string[],
221217
options?: import('./spawn').SpawnOptions,
@@ -347,7 +343,6 @@ export interface ExecScriptOptions extends SpawnOptions {
347343
prepost?: boolean | undefined
348344
}
349345

350-
/*@__NO_SIDE_EFFECTS__*/
351346
export function execScript(
352347
scriptName: string,
353348
args?: string[] | readonly string[] | ExecScriptOptions | undefined,

src/constants/packages.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const LATEST = 'latest'
1818
export const PACKAGE_DEFAULT_VERSION = '1.0.0'
1919

2020
// Package default Node range.
21+
/*@__NO_SIDE_EFFECTS__*/
2122
export function getPackageDefaultNodeRange(): string | undefined {
2223
if (_packageDefaultNodeRange === undefined) {
2324
_packageDefaultNodeRange =
@@ -27,6 +28,7 @@ export function getPackageDefaultNodeRange(): string | undefined {
2728
}
2829

2930
// Package default Socket categories.
31+
/*@__NO_SIDE_EFFECTS__*/
3032
export function getPackageDefaultSocketCategories() {
3133
if (_packageDefaultSocketCategories === undefined) {
3234
_packageDefaultSocketCategories =
@@ -36,6 +38,7 @@ export function getPackageDefaultSocketCategories() {
3638
}
3739

3840
// Package extensions.
41+
/*@__NO_SIDE_EFFECTS__*/
3942
export function getPackageExtensions(): Iterable<[string, unknown]> {
4043
if (_packageExtensions === undefined) {
4144
const { packageExtensions } = require('#lib/package-extensions')
@@ -45,11 +48,13 @@ export function getPackageExtensions(): Iterable<[string, unknown]> {
4548
}
4649

4750
// NPM lifecycle event.
51+
/*@__NO_SIDE_EFFECTS__*/
4852
export function getNpmLifecycleEvent(): string | undefined {
4953
return getNpmLifecycleEventEnv()
5054
}
5155

5256
// Lifecycle script names.
57+
/*@__NO_SIDE_EFFECTS__*/
5358
export function getLifecycleScriptNames(): string[] {
5459
if (_lifecycleScriptNames === undefined) {
5560
const { lifecycleScriptNames } = require('#lib/lifecycle-script-names')
@@ -59,6 +64,7 @@ export function getLifecycleScriptNames(): string[] {
5964
}
6065

6166
// Packument cache.
67+
/*@__NO_SIDE_EFFECTS__*/
6268
export function getPackumentCache(): Map<string, unknown> {
6369
if (_packumentCache === undefined) {
6470
_packumentCache = new Map()
@@ -67,6 +73,7 @@ export function getPackumentCache(): Map<string, unknown> {
6773
}
6874

6975
// Pacote cache path.
76+
/*@__NO_SIDE_EFFECTS__*/
7077
export function getPacoteCachePath(): string {
7178
if (_pacoteCachePath === undefined) {
7279
try {

src/env/ci.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { envAsBoolean } from '#env/helpers'
77
import { getEnvValue } from '#env/rewire'
88

9+
/*@__NO_SIDE_EFFECTS__*/
910
export function getCI(): boolean {
1011
return envAsBoolean(getEnvValue('CI'))
1112
}

src/env/debug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { getEnvValue } from '#env/rewire'
77

8+
/*@__NO_SIDE_EFFECTS__*/
89
export function getDebug(): string | undefined {
910
return getEnvValue('DEBUG')
1011
}

src/env/github.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getEnvValue } from '#env/rewire'
99
* GITHUB_API_URL environment variable.
1010
* GitHub API URL (e.g., https://api.github.com).
1111
*/
12+
/*@__NO_SIDE_EFFECTS__*/
1213
export function getGithubApiUrl(): string | undefined {
1314
return getEnvValue('GITHUB_API_URL')
1415
}
@@ -17,6 +18,7 @@ export function getGithubApiUrl(): string | undefined {
1718
* GITHUB_BASE_REF environment variable.
1819
* GitHub pull request base branch.
1920
*/
21+
/*@__NO_SIDE_EFFECTS__*/
2022
export function getGithubBaseRef(): string | undefined {
2123
return getEnvValue('GITHUB_BASE_REF')
2224
}
@@ -25,6 +27,7 @@ export function getGithubBaseRef(): string | undefined {
2527
* GITHUB_REF_NAME environment variable.
2628
* GitHub branch or tag name.
2729
*/
30+
/*@__NO_SIDE_EFFECTS__*/
2831
export function getGithubRefName(): string | undefined {
2932
return getEnvValue('GITHUB_REF_NAME')
3033
}
@@ -33,6 +36,7 @@ export function getGithubRefName(): string | undefined {
3336
* GITHUB_REF_TYPE environment variable.
3437
* GitHub ref type (branch or tag).
3538
*/
39+
/*@__NO_SIDE_EFFECTS__*/
3640
export function getGithubRefType(): string | undefined {
3741
return getEnvValue('GITHUB_REF_TYPE')
3842
}
@@ -41,6 +45,7 @@ export function getGithubRefType(): string | undefined {
4145
* GITHUB_REPOSITORY environment variable.
4246
* GitHub repository name in owner/repo format.
4347
*/
48+
/*@__NO_SIDE_EFFECTS__*/
4449
export function getGithubRepository(): string | undefined {
4550
return getEnvValue('GITHUB_REPOSITORY')
4651
}
@@ -49,6 +54,7 @@ export function getGithubRepository(): string | undefined {
4954
* GITHUB_SERVER_URL environment variable.
5055
* GitHub server URL (e.g., https://github.com).
5156
*/
57+
/*@__NO_SIDE_EFFECTS__*/
5258
export function getGithubServerUrl(): string | undefined {
5359
return getEnvValue('GITHUB_SERVER_URL')
5460
}
@@ -57,6 +63,7 @@ export function getGithubServerUrl(): string | undefined {
5763
* GITHUB_TOKEN environment variable.
5864
* GitHub authentication token for API access.
5965
*/
66+
/*@__NO_SIDE_EFFECTS__*/
6067
export function getGithubToken(): string | undefined {
6168
return getEnvValue('GITHUB_TOKEN')
6269
}
@@ -65,6 +72,7 @@ export function getGithubToken(): string | undefined {
6572
* GH_TOKEN environment variable.
6673
* Alternative GitHub authentication token for API access (used by GitHub CLI).
6774
*/
75+
/*@__NO_SIDE_EFFECTS__*/
6876
export function getGhToken(): string | undefined {
6977
return getEnvValue('GH_TOKEN')
7078
}

src/env/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @fileoverview Environment variable type conversion helpers.
33
*/
44

5+
/*@__NO_SIDE_EFFECTS__*/
56
export function envAsBoolean(value: string | undefined): boolean {
67
if (!value) {
78
return false
@@ -10,6 +11,7 @@ export function envAsBoolean(value: string | undefined): boolean {
1011
return lower === 'true' || lower === '1' || lower === 'yes'
1112
}
1213

14+
/*@__NO_SIDE_EFFECTS__*/
1315
export function envAsNumber(value: string | undefined): number {
1416
if (!value) {
1517
return 0
@@ -18,6 +20,7 @@ export function envAsNumber(value: string | undefined): number {
1820
return Number.isNaN(num) ? 0 : num
1921
}
2022

23+
/*@__NO_SIDE_EFFECTS__*/
2124
export function envAsString(value: string | undefined): string {
2225
return value || ''
2326
}

src/env/home.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { getEnvValue } from '#env/rewire'
77

8+
/*@__NO_SIDE_EFFECTS__*/
89
export function getHome(): string | undefined {
910
return getEnvValue('HOME')
1011
}

src/env/locale.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getEnvValue } from '#env/rewire'
99
* LANG environment variable.
1010
* System locale and language settings.
1111
*/
12+
/*@__NO_SIDE_EFFECTS__*/
1213
export function getLang(): string | undefined {
1314
return getEnvValue('LANG')
1415
}
@@ -17,6 +18,7 @@ export function getLang(): string | undefined {
1718
* LC_ALL environment variable.
1819
* Override for all locale settings.
1920
*/
21+
/*@__NO_SIDE_EFFECTS__*/
2022
export function getLcAll(): string | undefined {
2123
return getEnvValue('LC_ALL')
2224
}
@@ -25,6 +27,7 @@ export function getLcAll(): string | undefined {
2527
* LC_MESSAGES environment variable.
2628
* Locale setting for message translations.
2729
*/
30+
/*@__NO_SIDE_EFFECTS__*/
2831
export function getLcMessages(): string | undefined {
2932
return getEnvValue('LC_MESSAGES')
3033
}

src/env/node-auth-token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { getEnvValue } from '#env/rewire'
77

8+
/*@__NO_SIDE_EFFECTS__*/
89
export function getNodeAuthToken(): string | undefined {
910
return getEnvValue('NODE_AUTH_TOKEN')
1011
}

src/env/node-env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { getEnvValue } from '#env/rewire'
77

8+
/*@__NO_SIDE_EFFECTS__*/
89
export function getNodeEnv(): string | undefined {
910
return getEnvValue('NODE_ENV')
1011
}

0 commit comments

Comments
 (0)