@@ -82,6 +82,10 @@ type ENV = Remap<
8282 } >
8383>
8484
85+ type ProcessEnv = {
86+ [ K in keyof ENV ] ?: string
87+ }
88+
8589type IPC = Readonly < {
8690 SOCKET_CLI_FIX ?: string | undefined
8791 SOCKET_CLI_OPTIMIZE ?: boolean | undefined
@@ -162,6 +166,7 @@ type Constants = Remap<
162166 readonly minimumVersionByAgent : Map < Agent , string >
163167 readonly nmBinPath : string
164168 readonly nodeHardenFlags : string [ ]
169+ readonly processEnv : ProcessEnv
165170 readonly rootPath : string
166171 readonly shadowBinPath : string
167172 readonly shadowNpmBinPath : string
@@ -508,6 +513,28 @@ const lazyNpmNmNodeGypPath = () =>
508513 '../../node_modules/node-gyp/bin/node-gyp.js' ,
509514 )
510515
516+ const lazyProcessEnv = ( ) =>
517+ // Lazily access constants.ENV.
518+ Object . setPrototypeOf (
519+ Object . fromEntries (
520+ Object . entries ( constants . ENV ) . reduce (
521+ ( entries , entry ) => {
522+ const { 0 : key , 1 : value } = entry
523+ if ( typeof value === 'string' ) {
524+ if ( value ) {
525+ entries . push ( entry as [ string , string ] )
526+ }
527+ } else if ( typeof value === 'boolean' ) {
528+ entries . push ( [ key , value ? '1' : '0' ] )
529+ }
530+ return entries
531+ } ,
532+ [ ] as Array < [ string , string ] > ,
533+ ) ,
534+ ) ,
535+ null ,
536+ )
537+
511538const lazyRootPath = ( ) => path . join ( realpathSync . native ( __dirname ) , '..' )
512539
513540const lazyShadowBinPath = ( ) =>
@@ -638,6 +665,7 @@ const constants: Constants = createConstantsObject(
638665 nmBinPath : undefined ,
639666 nodeHardenFlags : undefined ,
640667 npmNmNodeGypPath : undefined ,
668+ processEnv : undefined ,
641669 rootPath : undefined ,
642670 shadowBinPath : undefined ,
643671 shadowNpmInjectPath : undefined ,
@@ -669,6 +697,7 @@ const constants: Constants = createConstantsObject(
669697 nmBinPath : lazyNmBinPath ,
670698 nodeHardenFlags : lazyNodeHardenFlags ,
671699 npmNmNodeGypPath : lazyNpmNmNodeGypPath ,
700+ processEnv : lazyProcessEnv ,
672701 rootPath : lazyRootPath ,
673702 shadowBinPath : lazyShadowBinPath ,
674703 shadowNpmBinPath : lazyShadowNpmBinPath ,
0 commit comments