@@ -79,32 +79,37 @@ export abstract class Target {
7979 *
8080 * @param packageDir The directory of the package to resolve from.
8181 */
82- protected async findLocalDepsOutput ( packageDir : string , isRoot = true ) {
83- const results = new Array < string > ( ) ;
84- const pkg = await fs . readJson ( path . join ( packageDir , 'package.json' ) ) ;
82+ protected async findLocalDepsOutput ( rootPackageDir : string ) {
83+ const results = new Set < string > ( ) ;
8584
86- // no jsii or jsii.outdir - either a misconfigured jsii package or a non-jsii dependency. either way, we are done here.
87- if ( ! pkg . jsii || ! pkg . jsii . outdir ) {
88- return [ ] ;
89- }
85+ const self = this ;
86+ async function recurse ( packageDir : string , isRoot : boolean ) {
87+ const pkg = await fs . readJson ( path . join ( packageDir , 'package.json' ) ) ;
9088
91- // if an output directory exists for this module, then we add it to our
92- // list of results (unless it's the root package, which we are currently building)
93- const outdir = path . join ( packageDir , pkg . jsii . outdir , this . targetName ) ;
94- if ( ! isRoot && await fs . pathExists ( outdir ) ) {
95- logging . debug ( `Found ${ outdir } as a local dependency output` ) ;
96- results . push ( outdir ) ;
97- }
89+ // no jsii or jsii.outdir - either a misconfigured jsii package or a non-jsii dependency. either way, we are done here.
90+ if ( ! pkg . jsii || ! pkg . jsii . outdir ) {
91+ return ;
92+ }
93+
94+ // if an output directory exists for this module, then we add it to our
95+ // list of results (unless it's the root package, which we are currently building)
96+ const outdir = path . join ( packageDir , pkg . jsii . outdir , self . targetName ) ;
97+ if ( results . has ( outdir ) ) { return ; } // Already visited, don't recurse again
98+
99+ if ( ! isRoot && await fs . pathExists ( outdir ) ) {
100+ logging . debug ( `Found ${ outdir } as a local dependency output` ) ;
101+ results . add ( outdir ) ;
102+ }
98103
99- // now descend to dependencies
100- for ( const dependencyName of Object . keys ( pkg . dependencies || { } ) ) {
101- const dependencyDir = resolveDependencyDirectory ( packageDir , dependencyName ) ;
102- for ( const dir of await this . findLocalDepsOutput ( dependencyDir , /* isRoot */ false ) ) {
103- results . push ( dir ) ;
104+ // now descend to dependencies
105+ for ( const dependencyName of Object . keys ( pkg . dependencies || { } ) ) {
106+ const dependencyDir = resolveDependencyDirectory ( packageDir , dependencyName ) ;
107+ await recurse ( dependencyDir , false ) ;
104108 }
105109 }
106110
107- return results ;
111+ await recurse ( rootPackageDir , true ) ;
112+ return Array . from ( results ) ;
108113 }
109114}
110115
0 commit comments