Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pacmak): fix Maven dependency collector. #449

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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