-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpm.ts
More file actions
94 lines (88 loc) · 2.54 KB
/
npm.ts
File metadata and controls
94 lines (88 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @file NPM environment variable getters. Provides access to NPM and package
* manager environment variables.
*/
import { getEnvValue } from './rewire'
/**
* Npm_config_registry environment variable. NPM registry URL configured by
* package managers.
*
* @example
* ;```typescript
* import { getNpmConfigRegistry } from '@socketsecurity/lib/env/npm'
*
* const registry = getNpmConfigRegistry()
* // e.g. 'https://registry.npmjs.org/' or undefined
* ```
*
* @returns The configured NPM registry URL, or `undefined` if not set
*/
export function getNpmConfigRegistry(): string | undefined {
return /*@__NO_SIDE_EFFECTS__*/ getEnvValue('npm_config_registry')
}
/**
* Npm_config_user_agent environment variable. User agent string set by
* npm/pnpm/yarn package managers.
*
* @example
* ;```typescript
* import { getNpmConfigUserAgent } from '@socketsecurity/lib/env/npm'
*
* const ua = getNpmConfigUserAgent()
* // e.g. 'pnpm/9.0.0 npm/? node/v20.0.0 darwin arm64'
* ```
*
* @returns The package manager user agent string, or `undefined` if not set
*/
export function getNpmConfigUserAgent(): string | undefined {
return getEnvValue('npm_config_user_agent')
}
/**
* Npm_lifecycle_event environment variable. The name of the npm lifecycle event
* that's currently running.
*
* @example
* ;```typescript
* import { getNpmLifecycleEvent } from '@socketsecurity/lib/env/npm'
*
* const event = getNpmLifecycleEvent()
* // e.g. 'install', 'postinstall', or 'test'
* ```
*
* @returns The current lifecycle event name, or `undefined` if not set
*/
export function getNpmLifecycleEvent(): string | undefined {
return getEnvValue('npm_lifecycle_event')
}
/**
* NPM_REGISTRY environment variable. NPM registry URL override.
*
* @example
* ;```typescript
* import { getNpmRegistry } from '@socketsecurity/lib/env/npm'
*
* const registry = getNpmRegistry()
* // e.g. 'https://registry.npmjs.org/' or undefined
* ```
*
* @returns The NPM registry URL override, or `undefined` if not set
*/
export function getNpmRegistry(): string | undefined {
return getEnvValue('NPM_REGISTRY')
}
/**
* NPM_TOKEN environment variable. Authentication token for NPM registry access.
*
* @example
* ;```typescript
* import { getNpmToken } from '@socketsecurity/lib/env/npm'
*
* const token = getNpmToken()
* // e.g. 'npm_abc123...' or undefined
* ```
*
* @returns The NPM auth token, or `undefined` if not set
*/
export function getNpmToken(): string | undefined {
return getEnvValue('NPM_TOKEN')
}