@@ -23,7 +23,46 @@ internals.toArray = (v) => {
2323} ;
2424
2525
26- internals . scan = async ( travisYaml ) => {
26+ internals . normalizeImports = ( travisYaml ) => {
27+
28+ return internals . toArray ( travisYaml . import ) . map ( ( entry ) => {
29+
30+ if ( typeof entry === 'string' ) {
31+ entry = { source : entry } ;
32+ }
33+
34+ return entry ;
35+ } ) ;
36+ } ;
37+
38+
39+ internals . applyImports = async ( yaml , { loadFile } ) => {
40+
41+ if ( ! yaml . import ) {
42+ return ;
43+ }
44+
45+ const imports = internals . normalizeImports ( yaml ) ;
46+
47+ for ( const entry of imports ) {
48+
49+ const buffer = await loadFile ( entry . source ) ;
50+
51+ const imported = Yaml . safeLoad ( buffer , {
52+ schema : Yaml . FAILSAFE_SCHEMA ,
53+ json : true
54+ } ) ;
55+
56+ for ( const key in imported ) {
57+ yaml [ key ] = imported [ key ] ;
58+ }
59+ }
60+ } ;
61+
62+
63+ internals . scan = async ( travisYaml , options ) => {
64+
65+ await internals . applyImports ( travisYaml , options ) ;
2766
2867 const rawSet = new Set ( ) ;
2968
@@ -35,7 +74,7 @@ internals.scan = async (travisYaml) => {
3574
3675 for ( const env of internals . toArray ( travisYaml . env . matrix ) ) {
3776
38- const matches = env . match ( / (?: N O D E J S _ V E R | T R A V I S _ N O D E _ V E R S I O N | N O D E _ V E R ) = " ? ( n o d e \/ ) ? (?< version > [ \w . / * ] + ) " ? / ) ; /* hack syntax highlighter 🤦♂️ */
77+ const matches = env . match ( / (?: N O D E J S _ V E R | T R A V I S _ N O D E _ V E R S I O N | N O D E _ V E R ) = " ? ( n o d e \/ ) ? (?< version > [ \w . / * ] + ) " ? / ) ;
3978
4079 if ( matches ) {
4180 rawSet . add ( matches . groups . version ) ;
@@ -96,6 +135,6 @@ exports.detect = async ({ loadFile }) => {
96135 } ) ;
97136
98137 return {
99- travis : await internals . scan ( travisYaml )
138+ travis : await internals . scan ( travisYaml , { loadFile } )
100139 } ;
101140} ;
0 commit comments