@@ -7,30 +7,42 @@ import semver from 'semver'
77
88const { PACKAGE_JSON } = constants
99
10+ export const SUPPORTS_SYNC_ESM = semver . satisfies (
11+ process . versions . node ,
12+ '>=22.12'
13+ )
14+
1015export const API_V0_URL = 'https://api.socket.dev/v0'
1116
17+ export const DIST_TYPE = SUPPORTS_SYNC_ESM ? 'module-sync' : 'require'
18+
1219export const ENV = Object . freeze ( {
1320 // Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
1421 UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE : envAsBoolean (
1522 process . env [ 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE' ]
1623 )
1724} )
1825
19- export const SUPPORTS_SYNC_ESM = semver . satisfies (
20- process . versions . node ,
21- '>=22.12'
22- )
26+ export const LOOP_SENTINEL = 1_000_000
2327
28+ export const NPM_REGISTRY_URL = 'https://registry.npmjs.org'
29+
30+ // Dynamically detect the rootPath so constants.ts can be used in tests.
2431export const rootPath = ( ( ) => {
2532 let oldPath
2633 let currPath = realpathSync ( __dirname )
34+ // Dirname stops when at the filepath root, e.g. '/' for posix and 'C:\\' for win32,
35+ // so `currPath` equal `oldPath`.
2736 while ( currPath !== oldPath ) {
2837 const pkgJsonPath = path . join ( currPath , PACKAGE_JSON )
2938 if ( existsSync ( pkgJsonPath ) ) {
3039 try {
31- // SOCKET_PACKAGE_NAME is replaced by .config/rollup.base.config.mjs
40+ // Content matching REPLACED_WITH_SOCKET_PACKAGE_NAME is replaced by
41+ // the @rollup /plugin-replace plugin used in .config/rollup.base.config.mjs
3242 // with either 'socket' or '@socketsecurity/cli'.
33- if ( require ( pkgJsonPath ) ?. name === 'SOCKET_PACKAGE_NAME' ) {
43+ if (
44+ require ( pkgJsonPath ) ?. name === 'REPLACED_WITH_SOCKET_PACKAGE_NAME'
45+ ) {
3446 return currPath
3547 }
3648 } catch { }
@@ -45,13 +57,6 @@ export const rootBinPath = path.join(rootPath, 'bin')
4557export const rootPkgJsonPath = path . join ( rootPath , PACKAGE_JSON )
4658export const nmBinPath = path . join ( rootPath , 'node_modules/.bin' )
4759export const cdxgenBinPath = path . join ( nmBinPath , 'cdxgen' )
48- export const distPath = path . join (
49- rootDistPath ,
50- SUPPORTS_SYNC_ESM ? 'module-sync' : 'require'
51- )
52- export const shadowBinPath = path . join (
53- rootPath ,
54- 'shadow' ,
55- SUPPORTS_SYNC_ESM ? 'module-sync' : 'require'
56- )
60+ export const distPath = path . join ( rootDistPath , DIST_TYPE )
61+ export const shadowBinPath = path . join ( rootPath , 'shadow' , DIST_TYPE )
5762export const synpBinPath = path . join ( nmBinPath , 'synp' )
0 commit comments