@@ -11,6 +11,7 @@ import path from "node:path";
1111import prettyHrtime from "pretty-hrtime" ;
1212import semver from "semver" ;
1313import { RE2JS } from "re2js" ;
14+ import { globbySync } from "globby" ;
1415
1516type ParserIncludesInitOptions = {
1617 argv : Argv ;
@@ -147,13 +148,16 @@ export class ParserIncludes {
147148 } else if ( value [ "project" ] ) {
148149 for ( const fileValue of Array . isArray ( value [ "file" ] ) ? value [ "file" ] : [ value [ "file" ] ] ) {
149150 const mergedInputs = { ...( value . inputs ?? { } ) , ...globalInputs } ;
150- const fileDoc = await Parser . loadYaml (
151- `${ cwd } /${ stateDir } /includes/${ gitData . remote . host } /${ value [ "project" ] } /${ value [ "ref" ] || "HEAD" } /${ fileValue } `
152- , { inputs : mergedInputs }
153- , expandVariables , writeStreams ) ;
154- // Expand local includes inside a "project"-like include
155- fileDoc [ "include" ] = this . expandInnerLocalIncludes ( fileDoc [ "include" ] , value [ "project" ] , value [ "ref" ] , opts ) ;
156- includeDatas = includeDatas . concat ( await this . init ( fileDoc , opts ) ) ;
151+ const includeDir = `${ cwd } /${ stateDir } /includes/${ gitData . remote . host } /${ value [ "project" ] } /${ value [ "ref" ] || "HEAD" } ` ;
152+ const normalizedFile = fileValue . replace ( / ^ \/ + / , "" ) ;
153+ const matches = globbySync ( normalizedFile , { cwd : includeDir , absolute : true } ) . sort ( ) ;
154+ const filePaths = matches . length > 0 ? matches : [ `${ includeDir } /${ normalizedFile } ` ] ;
155+ for ( const filePath of filePaths ) {
156+ const fileDoc = await Parser . loadYaml ( filePath , { inputs : mergedInputs } , expandVariables , writeStreams ) ;
157+ // Expand local includes inside a "project"-like include
158+ fileDoc [ "include" ] = this . expandInnerLocalIncludes ( fileDoc [ "include" ] , value [ "project" ] , value [ "ref" ] , opts ) ;
159+ includeDatas = includeDatas . concat ( await this . init ( fileDoc , opts ) ) ;
160+ }
157161 }
158162 } else if ( value [ "component" ] ) {
159163 const component = componentParseCache . get ( index ) ;
@@ -387,7 +391,7 @@ export class ParserIncludes {
387391 `git sparse-checkout set --no-cone ${ normalizedFile } ` ,
388392 isCommitSha ? "git checkout FETCH_HEAD" : "git checkout" ,
389393 `cd ${ cwd } /${ stateDir } ` ,
390- `cp ${ tmpDir } /${ normalizedFile } ${ cwd } /${ target } /${ normalizedFile } ` ,
394+ `cp ${ tmpDir } /${ normalizedFile } ${ path . dirname ( ` ${ cwd } /${ target } /${ normalizedFile } ` ) } / ` ,
391395 ] , cwd ) ;
392396 } else {
393397 await fs . mkdirp ( `${ cwd } /${ target } ` ) ;
0 commit comments