@@ -411,26 +411,37 @@ function fileReferenceDirective(keyName: string, meta: ParsedValueMetadata): Par
411
411
SchemaBuilder . emptySchema ( )
412
412
. addString ( 'path' )
413
413
. addBoolean ( 'optional' , { } , false )
414
- . addString ( 'select' , { } , false ) ,
414
+ . addString ( 'select' , { } , false )
415
+ . addString ( 'env' , { } , false ) ,
415
416
) ;
416
417
417
418
return SchemaBuilder . oneOf ( reference , SchemaBuilder . arraySchema ( reference ) ) ;
418
419
} ,
419
- ( value ) => async ( _ , __ , context , extensions ) => {
420
- const retrieveFile = async ( filepath : string , subselector ?: string , isOptional = false ) => {
421
- const resolvedPath = resolveFilepath ( context , filepath ) ;
420
+ ( value , _ , context ) => async ( _ , __ , originalSource , extensions ) => {
421
+ const retrieveFile = async (
422
+ filepath : string ,
423
+ subselector ?: string ,
424
+ isOptional = false ,
425
+ env ?: string ,
426
+ ) => {
427
+ const resolvedPath = resolveFilepath ( originalSource , filepath ) ;
422
428
423
429
logger . verbose ( `Loading file for ${ keyName } : ${ resolvedPath } ` ) ;
424
430
425
431
const source = new FileSource ( resolvedPath ) ;
426
432
427
- const parsed = await source . read ( extensions ) . catch ( ( error ) => {
428
- if ( error instanceof NotFoundError && isOptional ) {
429
- return ParsedValue . literal ( { } ) ;
430
- }
433
+ const parsed = await source
434
+ . read ( extensions , {
435
+ ...context ,
436
+ environmentOverride : env ?? context . environmentOverride ,
437
+ } )
438
+ . catch ( ( error ) => {
439
+ if ( error instanceof NotFoundError && isOptional ) {
440
+ return ParsedValue . literal ( { } ) ;
441
+ }
431
442
432
- throw error ;
433
- } ) ;
443
+ throw error ;
444
+ } ) ;
434
445
435
446
if ( subselector ) {
436
447
const found = parsed . property ( subselector . split ( '.' ) ) ;
@@ -458,15 +469,15 @@ function fileReferenceDirective(keyName: string, meta: ParsedValueMetadata): Par
458
469
if ( typeof ext === 'string' ) {
459
470
parsed = ParsedValue . merge ( parsed , await retrieveFile ( ext ) ) ;
460
471
} else {
461
- const { path, optional, select } = ext ;
472
+ const { path, optional, select, env } = ext ;
462
473
463
- parsed = ParsedValue . merge ( parsed , await retrieveFile ( path , select , optional ) ) ;
474
+ parsed = ParsedValue . merge ( parsed , await retrieveFile ( path , select , optional , env ) ) ;
464
475
}
465
476
}
466
477
} else {
467
- const { path, optional, select } = value ;
478
+ const { path, optional, select, env } = value ;
468
479
469
- parsed = await retrieveFile ( path , select , optional ) ;
480
+ parsed = await retrieveFile ( path , select , optional , env ) ;
470
481
}
471
482
472
483
return parsed . assignMeta ( meta ) ;
0 commit comments