@@ -496,6 +496,26 @@ function readExistingEnvironmentValueSource(params: {
496496 return undefined ;
497497}
498498
499+ function omitEnvironmentEntriesShadowedBy (
500+ entries : Record < string , string | undefined > ,
501+ shadowEntries : Array < Record < string , string | undefined > > ,
502+ ) : Record < string , string | undefined > {
503+ const shadowKeys = new Set (
504+ shadowEntries . flatMap ( ( environment ) =>
505+ Object . keys ( environment ) . flatMap ( ( key ) => {
506+ const normalized = normalizeEnvVarKey ( key , { portable : true } ) ?. toUpperCase ( ) ;
507+ return normalized ? [ normalized ] : [ ] ;
508+ } ) ,
509+ ) ,
510+ ) ;
511+ return Object . fromEntries (
512+ Object . entries ( entries ) . filter ( ( [ key ] ) => {
513+ const normalized = normalizeEnvVarKey ( key , { portable : true } ) ?. toUpperCase ( ) ;
514+ return ! normalized || ! shadowKeys . has ( normalized ) ;
515+ } ) ,
516+ ) ;
517+ }
518+
499519function resolveGatewayInstallWorkingDirectory ( params : {
500520 env : Record < string , string | undefined > ;
501521 platform : NodeJS . Platform ;
@@ -550,24 +570,32 @@ async function buildGatewayInstallEnvironment(params: {
550570 authStore,
551571 warn : params . warn ,
552572 } ) ;
573+ const stateDirDotEnvRenderEnvironment = omitEnvironmentEntriesShadowedBy (
574+ stateDirDotEnvEnvironment ,
575+ [
576+ configEnvironment ,
577+ configSecretRefEnvironment ,
578+ execSecretRefPassEnvEnvironment ,
579+ authProfileEnvironment ,
580+ ] ,
581+ ) ;
553582 const preservedExistingEnvironment = collectPreservedExistingServiceEnvVars (
554583 params . existingEnvironment ,
555584 readManagedServiceEnvKeysFromEnvironment ( params . existingEnvironment ) ,
556585 ) ;
557586 const plan = createMutableServiceEnvPlan ( ) ;
558587 addServiceEnvPlanEntries ( plan , preservedExistingEnvironment , {
559- source : "existing-preserved" ,
560588 valueSource : ( { normalizedKey } ) =>
561589 readExistingEnvironmentValueSource ( {
562590 existingEnvironmentValueSources : params . existingEnvironmentValueSources ,
563591 normalizedKey,
564592 } ) ?? "inline" ,
565593 } ) ;
566- addServiceEnvPlanEntries ( plan , stateDirDotEnvEnvironment , { source : "state-dotenv" } ) ;
567- addServiceEnvPlanEntries ( plan , configEnvironment , { source : "config-env" } ) ;
568- addServiceEnvPlanEntries ( plan , configSecretRefEnvironment , { source : "config-secretref-env" } ) ;
569- addServiceEnvPlanEntries ( plan , execSecretRefPassEnvEnvironment , { source : "exec-passenv" } ) ;
570- addServiceEnvPlanEntries ( plan , authProfileEnvironment , { source : "auth-profile-env" } ) ;
594+ addServiceEnvPlanEntries ( plan , stateDirDotEnvEnvironment , { } ) ;
595+ addServiceEnvPlanEntries ( plan , configEnvironment , { } ) ;
596+ addServiceEnvPlanEntries ( plan , configSecretRefEnvironment , { } ) ;
597+ addServiceEnvPlanEntries ( plan , execSecretRefPassEnvEnvironment , { } ) ;
598+ addServiceEnvPlanEntries ( plan , authProfileEnvironment , { } ) ;
571599 const managedServiceEnvKeys = formatManagedServiceEnvKeys (
572600 {
573601 ...durableEnvironment ,
@@ -580,9 +608,10 @@ async function buildGatewayInstallEnvironment(params: {
580608 managedServiceEnvKeys,
581609 serviceEnvironment : params . serviceEnvironment ,
582610 platform : params . platform ,
611+ stateDirDotEnvEnvironment : stateDirDotEnvRenderEnvironment ,
612+ configSecretRefEnvironment,
583613 } ) ;
584614 addServiceEnvPlanEntries ( plan , params . serviceEnvironment , {
585- source : "service-generated" ,
586615 includeRawKeys : true ,
587616 } ) ;
588617 const mergedPath = mergeServicePath (
0 commit comments