@@ -28,8 +28,8 @@ type Constants = {
2828} & typeof registryConstants
2929
3030const {
31- kInternalsSymbol,
3231 PACKAGE_JSON ,
32+ kInternalsSymbol,
3333 [ kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)' ] : {
3434 createConstantsObject
3535 }
@@ -41,52 +41,87 @@ const NPM_REGISTRY_URL = 'https://registry.npmjs.org'
4141const SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues'
4242const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE =
4343 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
44- const ENV : Constants [ 'ENV' ] = Object . freeze ( {
45- ...registryConstants . ENV ,
46- // Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
47- [ UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE ] : envAsBoolean (
48- process . env [ UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE ]
49- )
50- } )
51-
52- const rootPath = path . resolve ( realpathSync ( __dirname ) , '..' )
53- const rootDistPath = path . join ( rootPath , 'dist' )
54- const rootBinPath = path . join ( rootPath , 'bin' )
55- const rootPkgJsonPath = path . join ( rootPath , PACKAGE_JSON )
56- const nmBinPath = path . join ( rootPath , 'node_modules/.bin' )
57- const cdxgenBinPath = path . join ( nmBinPath , 'cdxgen' )
58- const shadowBinPath = path . join ( rootPath , 'shadow-bin' )
59- const synpBinPath = path . join ( nmBinPath , 'synp' )
6044
6145const LAZY_DIST_TYPE = ( ) =>
6246 registryConstants . SUPPORTS_NODE_REQUIRE_MODULE ? 'module-sync' : 'require'
6347
64- const lazyDistPath = ( ) => path . join ( rootDistPath , constants . DIST_TYPE )
48+ const LAZY_ENV = ( ) =>
49+ Object . freeze ( {
50+ // Lazily access registryConstants.ENV.
51+ ...registryConstants . ENV ,
52+ // Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
53+ [ UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE ] : envAsBoolean (
54+ process . env [ UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE ]
55+ )
56+ } )
57+
58+ const lazyCdxgenBinPath = ( ) =>
59+ // Lazily access constants.nmBinPath.
60+ path . join ( constants . nmBinPath , 'cdxgen' )
61+
62+ const lazyDistPath = ( ) =>
63+ // Lazily access constants.rootDistPath and constants.DIST_TYPE.
64+ path . join ( constants . rootDistPath , constants . DIST_TYPE )
65+
66+ const lazyNmBinPath = ( ) =>
67+ // Lazily access constants.rootPath.
68+ path . join ( constants . rootPath , 'node_modules/.bin' )
69+
70+ const lazyRootBinPath = ( ) =>
71+ // Lazily access constants.rootPath.
72+ path . join ( constants . rootPath , 'bin' )
73+
74+ const lazyRootDistPath = ( ) =>
75+ // Lazily access constants.rootPath.
76+ path . join ( constants . rootPath , 'dist' )
77+
78+ const lazyRootPath = ( ) => path . resolve ( realpathSync ( __dirname ) , '..' )
79+
80+ const lazyRootPkgJsonPath = ( ) =>
81+ // Lazily access constants.rootPath.
82+ path . join ( constants . rootPath , PACKAGE_JSON )
83+
84+ const lazyShadowBinPath = ( ) =>
85+ // Lazily access constants.rootPath.
86+ path . join ( constants . rootPath , 'shadow-bin' )
87+
88+ const lazySynpBinPath = ( ) =>
89+ // Lazily access constants.nmBinPath.
90+ path . join ( constants . nmBinPath , 'synp' )
6591
6692const constants = < Constants > createConstantsObject (
6793 {
6894 API_V0_URL ,
6995 BABEL_RUNTIME ,
70- ENV ,
96+ ENV : undefined ,
7197 // Lazily defined values are initialized as `undefined` to keep their key order.
7298 DIST_TYPE : undefined ,
7399 NPM_REGISTRY_URL ,
74100 SOCKET_CLI_ISSUES_URL ,
75101 UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE ,
76- cdxgenBinPath,
102+ cdxgenBinPath : undefined ,
77103 distPath : undefined ,
78- nmBinPath,
79- rootBinPath,
80- rootDistPath,
81- rootPath,
82- rootPkgJsonPath,
83- shadowBinPath,
84- synpBinPath
104+ nmBinPath : undefined ,
105+ rootBinPath : undefined ,
106+ rootDistPath : undefined ,
107+ rootPath : undefined ,
108+ rootPkgJsonPath : undefined ,
109+ shadowBinPath : undefined ,
110+ synpBinPath : undefined
85111 } ,
86112 {
87113 getters : {
88114 DIST_TYPE : LAZY_DIST_TYPE ,
89- distPath : lazyDistPath
115+ ENV : LAZY_ENV ,
116+ distPath : lazyDistPath ,
117+ cdxgenBinPath : lazyCdxgenBinPath ,
118+ nmBinPath : lazyNmBinPath ,
119+ rootBinPath : lazyRootBinPath ,
120+ rootDistPath : lazyRootDistPath ,
121+ rootPath : lazyRootPath ,
122+ rootPkgJsonPath : lazyRootPkgJsonPath ,
123+ shadowBinPath : lazyShadowBinPath ,
124+ synpBinPath : lazySynpBinPath
90125 } ,
91126 mixin : registryConstants
92127 }
0 commit comments