From 78e941f1b479a307d25e3ab36a69f7b85f97521e Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Thu, 11 Apr 2019 16:27:15 +0200 Subject: [PATCH] fix(pacmak): fix Maven dependency collector. Stop the Maven dependency collector from recursing into directories it's already seen. This avoids finding adding the same directories over and over again, which Maven subsequently can't deal with. Fixes #447, and probably the hanging build. --- packages/jsii-pacmak/lib/target.ts | 45 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/jsii-pacmak/lib/target.ts b/packages/jsii-pacmak/lib/target.ts index 5551846652..48d40eaf9e 100644 --- a/packages/jsii-pacmak/lib/target.ts +++ b/packages/jsii-pacmak/lib/target.ts @@ -79,32 +79,37 @@ export abstract class Target { * * @param packageDir The directory of the package to resolve from. */ - protected async findLocalDepsOutput(packageDir: string, isRoot = true) { - const results = new Array(); - const pkg = await fs.readJson(path.join(packageDir, 'package.json')); + protected async findLocalDepsOutput(rootPackageDir: string) { + const results = new Set(); - // no jsii or jsii.outdir - either a misconfigured jsii package or a non-jsii dependency. either way, we are done here. - if (!pkg.jsii || !pkg.jsii.outdir) { - return []; - } + const self = this; + async function recurse(packageDir: string, isRoot: boolean) { + const pkg = await fs.readJson(path.join(packageDir, 'package.json')); - // if an output directory exists for this module, then we add it to our - // list of results (unless it's the root package, which we are currently building) - const outdir = path.join(packageDir, pkg.jsii.outdir, this.targetName); - if (!isRoot && await fs.pathExists(outdir)) { - logging.debug(`Found ${outdir} as a local dependency output`); - results.push(outdir); - } + // no jsii or jsii.outdir - either a misconfigured jsii package or a non-jsii dependency. either way, we are done here. + if (!pkg.jsii || !pkg.jsii.outdir) { + return; + } + + // if an output directory exists for this module, then we add it to our + // list of results (unless it's the root package, which we are currently building) + const outdir = path.join(packageDir, pkg.jsii.outdir, self.targetName); + if (results.has(outdir)) { return; } // Already visited, don't recurse again + + if (!isRoot && await fs.pathExists(outdir)) { + logging.debug(`Found ${outdir} as a local dependency output`); + results.add(outdir); + } - // now descend to dependencies - for (const dependencyName of Object.keys(pkg.dependencies || {})) { - const dependencyDir = resolveDependencyDirectory(packageDir, dependencyName); - for (const dir of await this.findLocalDepsOutput(dependencyDir, /* isRoot */ false)) { - results.push(dir); + // now descend to dependencies + for (const dependencyName of Object.keys(pkg.dependencies || {})) { + const dependencyDir = resolveDependencyDirectory(packageDir, dependencyName); + await recurse(dependencyDir, false); } } - return results; + await recurse(rootPackageDir, true); + return Array.from(results); } }