Skip to content

Commit

Permalink
fix(pacmak): fix Maven dependency collector. (#449)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr authored Apr 11, 2019
1 parent 21e485a commit 675b86a
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions packages/jsii-pacmak/lib/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
const pkg = await fs.readJson(path.join(packageDir, 'package.json'));
protected async findLocalDepsOutput(rootPackageDir: string) {
const results = new Set<string>();

// 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);
}
}

Expand Down

0 comments on commit 675b86a

Please sign in to comment.