Skip to content

Commit

Permalink
fix(jsii): submodules of dependencies show up in assembly (#2481)
Browse files Browse the repository at this point in the history
The `submodules` key of an assembly is expected to hold the submodules
found in that assembly, but also contain the submodules of dependencies.

Exclude those.



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
rix0rrr authored Jan 26, 2021
1 parent a30a996 commit 2630a80
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
8 changes: 1 addition & 7 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@
},
"schema": "jsii/0.10.0",
"submodules": {
"@scope/jsii-calc-lib.submodule": {
"locationInModule": {
"filename": "../@scope/jsii-calc-lib/build/index.d.ts",
"line": 157
}
},
"jsii-calc.DerivedClassHasNoProperties": {
"locationInModule": {
"filename": "lib/compliance.ts",
Expand Down Expand Up @@ -14441,5 +14435,5 @@
}
},
"version": "0.0.0",
"fingerprint": "4fJXgLfvFXFeZPUflIUswNxZKtt1vgIANXs/lWot+qg="
"fingerprint": "2KFlnOkWR5oOwLlri+7JlkA0BsYvnRkpBrk4nPWnJfw="
}
25 changes: 21 additions & 4 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export class Assembler implements Emitter {

/** Map of Symbol to namespace export Symbol */
private readonly _submoduleMap = new Map<ts.Symbol, ts.Symbol>();

/**
* Submodule information
*
* Contains submodule information for all namespaces that have been seen
* across all assemblies (this and dependencies).
*
* Filtered to local submodules only at time of writing the assembly out to disk.
*/
private readonly _submodules = new Map<ts.Symbol, SubmoduleSpec>();

/**
Expand Down Expand Up @@ -192,9 +201,7 @@ export class Assembler implements Emitter {
),
bundled: this.projectInfo.bundleDependencies,
types: this._types,
submodules: noEmptyDict(
toSubmoduleDeclarations(this._submodules.values()),
),
submodules: noEmptyDict(toSubmoduleDeclarations(this.mySubmodules())),
targets: this.projectInfo.targets,
metadata: this.projectInfo.metadata,
docs,
Expand Down Expand Up @@ -2555,6 +2562,16 @@ export class Assembler implements Emitter {
}
return docs;
}

/**
* Return only those submodules from the submodules list that are submodules inside this
* assembly.
*/
private mySubmodules() {
return Array.from(this._submodules.values()).filter((m) =>
m.fqn.startsWith(`${this.projectInfo.name}.`),
);
}
}

interface SubmoduleSpec {
Expand Down Expand Up @@ -2875,7 +2892,7 @@ function toDependencyClosure(
}

function toSubmoduleDeclarations(
submodules: IterableIterator<SubmoduleSpec>,
submodules: Iterable<SubmoduleSpec>,
): spec.Assembly['submodules'] {
const result: spec.Assembly['submodules'] = {};

Expand Down

0 comments on commit 2630a80

Please sign in to comment.