@@ -12,64 +12,31 @@ Pre-defined constant values for Node.js versions, npm registry URLs, platform de
1212## Quick Start
1313
1414``` typescript
15- import { MIN_SUPPORTED_NODE_VERSION } from ' @socketsecurity/lib/constants/node'
16- import { MAIN_REGISTRY_URL } from ' @socketsecurity/lib/constants/npm'
15+ import { WIN32 , DARWIN } from ' @socketsecurity/lib/constants/platform'
1716
18- if (process .version < ` v${MIN_SUPPORTED_NODE_VERSION } ` ) {
19- console .error (` Node.js ${MIN_SUPPORTED_NODE_VERSION }+ required ` )
20- process .exit (1 )
17+ if (WIN32 ) {
18+ console .log (' Running on Windows' )
19+ } else if (DARWIN ) {
20+ console .log (' Running on macOS' )
21+ } else {
22+ console .log (' Running on Linux or other Unix-like OS' )
2123}
22-
23- console .log (` Registry: ${MAIN_REGISTRY_URL } ` )
2424```
2525
2626## Node.js Constants
2727
28- ### MIN_SUPPORTED_NODE_VERSION
29-
30- Minimum supported Node.js version for Socket.dev tools.
31-
32- ``` typescript
33- import { MIN_SUPPORTED_NODE_VERSION } from ' @socketsecurity/lib/constants/node'
34-
35- console .log (MIN_SUPPORTED_NODE_VERSION ) // "22.0.0"
36- ```
37-
38- ### Version Checking
39-
40- ``` typescript
41- import { MIN_SUPPORTED_NODE_VERSION } from ' @socketsecurity/lib/constants/node'
42-
43- const currentVersion = process .version .slice (1 ) // Remove 'v' prefix
44-
45- if (currentVersion < MIN_SUPPORTED_NODE_VERSION ) {
46- throw new Error (
47- ` Node.js ${MIN_SUPPORTED_NODE_VERSION }+ required. Current: ${currentVersion } `
48- )
49- }
50- ```
28+ See ` @socketsecurity/lib/constants/node ` for Node.js-related constants.
5129
5230## npm Registry Constants
5331
54- ### MAIN_REGISTRY_URL
55-
56- The main npm registry URL.
32+ For building npm registry URLs, use string literals directly:
5733
5834``` typescript
59- import { MAIN_REGISTRY_URL } from ' @socketsecurity/lib/constants/npm'
60-
61- console .log (MAIN_REGISTRY_URL ) // "https://registry.npmjs.org"
62- ```
63-
64- ### Building Registry URLs
65-
66- ``` typescript
67- import { MAIN_REGISTRY_URL } from ' @socketsecurity/lib/constants/npm'
6835import { httpJson } from ' @socketsecurity/lib/http-request'
6936
70- // Get package metadata
37+ // Get package metadata from npm registry
7138const packageName = ' lodash'
72- const url = ` ${ MAIN_REGISTRY_URL } /${packageName }`
39+ const url = ` https://registry.npmjs.org /${packageName }`
7340const metadata = await httpJson (url )
7441
7542console .log (metadata .name , metadata [' dist-tags' ].latest )
@@ -78,10 +45,8 @@ console.log(metadata.name, metadata['dist-tags'].latest)
7845### Package Tarball URLs
7946
8047``` typescript
81- import { MAIN_REGISTRY_URL } from ' @socketsecurity/lib/constants/npm'
82-
8348function getTarballUrl(name : string , version : string ): string {
84- return ` ${ MAIN_REGISTRY_URL } /${name }/-/${name }-${version }.tgz`
49+ return ` https://registry.npmjs.org /${name }/-/${name }-${version }.tgz`
8550}
8651
8752const url = getTarballUrl (' lodash' , ' 4.17.21' )
@@ -116,28 +81,29 @@ if (DARWIN) {
11681}
11782```
11883
119- ### LINUX
84+ ### Detecting Linux
12085
121- Checks if platform is Linux.
86+ There is no ` LINUX ` constant. To detect Linux or other Unix-like systems, check if the platform is neither Windows nor macOS:
12287
12388``` typescript
124- import { LINUX } from ' @socketsecurity/lib/constants/platform'
89+ import { WIN32 , DARWIN } from ' @socketsecurity/lib/constants/platform'
12590
126- if (LINUX ) {
127- console .log (' Running on Linux' )
91+ const isLinux = ! WIN32 && ! DARWIN
92+ if (isLinux ) {
93+ console .log (' Running on Linux or other Unix-like OS' )
12894 // Use Linux-specific logic
12995}
13096```
13197
13298### Platform-Specific Logic Example
13399
134100``` typescript
135- import { WIN32 , DARWIN , LINUX } from ' @socketsecurity/lib/constants/platform'
136- import { getHome , getUserProfile } from ' @socketsecurity/lib/env'
101+ import { WIN32 , DARWIN } from ' @socketsecurity/lib/constants/platform'
102+ import { getHome } from ' @socketsecurity/lib/env/home '
137103import path from ' node:path'
138104
139105function getConfigDir(): string {
140- const home = getHome () || getUserProfile ()
106+ const home = getHome ()
141107 if (! home ) {
142108 throw new Error (' Cannot determine home directory' )
143109 }
@@ -146,7 +112,8 @@ function getConfigDir(): string {
146112 return path .join (home , ' AppData' , ' Local' , ' MyApp' )
147113 } else if (DARWIN ) {
148114 return path .join (home , ' Library' , ' Application Support' , ' MyApp' )
149- } else if (LINUX ) {
115+ } else {
116+ // Linux or other Unix-like OS
150117 return path .join (home , ' .config' , ' myapp' )
151118 }
152119
@@ -211,10 +178,11 @@ checkNodeVersion()
211178### npm Package Downloader
212179
213180``` typescript
214- import { MAIN_REGISTRY_URL } from ' @socketsecurity/lib/constants/npm'
215181import { httpJson , httpDownload } from ' @socketsecurity/lib/http-request'
216182import { Spinner } from ' @socketsecurity/lib/spinner'
217183
184+ const NPM_REGISTRY = ' https://registry.npmjs.org'
185+
218186interface PackageMetadata {
219187 ' dist-tags' : { latest: string }
220188 versions: Record <string , {
@@ -232,7 +200,7 @@ async function downloadPackage(
232200 // Get package metadata
233201 spinner .start (' Fetching package metadata...' )
234202 const metadata = await httpJson <PackageMetadata >(
235- ` ${MAIN_REGISTRY_URL }/${name } `
203+ ` ${NPM_REGISTRY }/${name } `
236204 )
237205 spinner .success (' Metadata fetched' )
238206
@@ -267,7 +235,7 @@ await downloadPackage('lodash', 'latest', '/tmp')
267235### Cross-Platform Path Builder
268236
269237``` typescript
270- import { WIN32 , DARWIN , LINUX } from ' @socketsecurity/lib/constants/platform'
238+ import { WIN32 , DARWIN } from ' @socketsecurity/lib/constants/platform'
271239import path from ' node:path'
272240
273241class PathBuilder {
@@ -321,10 +289,8 @@ console.log(configPath)
321289### Registry URL Builder
322290
323291``` typescript
324- import { MAIN_REGISTRY_URL } from ' @socketsecurity/lib/constants/npm'
325-
326292class RegistryClient {
327- constructor (private baseUrl : string = MAIN_REGISTRY_URL ) {}
293+ constructor (private baseUrl : string = ' https://registry.npmjs.org ' ) {}
328294
329295 packageUrl(name : string ): string {
330296 return ` ${this .baseUrl }/${name } `
@@ -386,16 +352,10 @@ await Promise.all([
386352
387353## Available Constants
388354
389- ### Node.js
390- - ` MIN_SUPPORTED_NODE_VERSION ` - Minimum Node.js version ("22.0.0")
391-
392- ### npm Registry
393- - ` MAIN_REGISTRY_URL ` - Main npm registry ("https://registry.npmjs.org ")
394-
395355### Platform
396356- ` WIN32 ` - Boolean, true on Windows
397357- ` DARWIN ` - Boolean, true on macOS
398- - ` LINUX ` - Boolean, true on Linux
358+ - For Linux detection, use ` !WIN32 && !DARWIN `
399359
400360### Process
401361- ` getAbortSignal() ` - Function returning global AbortSignal
@@ -435,5 +395,5 @@ if (!semver.gte(process.version, MIN_SUPPORTED_NODE_VERSION)) {
435395** Solution:**
436396Use environment variable or config:
437397``` typescript
438- const registryUrl = process .env .NPM_REGISTRY || MAIN_REGISTRY_URL
398+ const registryUrl = process .env .NPM_REGISTRY || ' https://registry.npmjs.org '
439399```
0 commit comments