Skip to content

Commit

Permalink
fix: C# NamespaceDoc emitted to wrong location (#3183)
Browse files Browse the repository at this point in the history
The namespace determination for the `NamespaceDoc` class generated for
submodules was incorrect, as the `jsiiNs` passed to the type resovler
was absolute, instead of being the required assembly-relative form.

Additionally, removed the `readme` and `locationInSource` property from
submodule descriptors included in the jsii assembly under
`dependencyClosure`, as those are not necessary and needlessly bloat the
assembly document.



---

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
Romain Marcadier authored Nov 18, 2021
1 parent 92a7d5e commit 0f5f349
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 56 deletions.
18 changes: 15 additions & 3 deletions packages/@jsii/spec/lib/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ export const SPEC_FILE_NAME = '.jsii';
/**
* A JSII assembly specification.
*/
export interface Assembly extends AssemblyConfiguration, Documentable {
export interface Assembly
extends AssemblyConfiguration,
Documentable,
ReadMeContainer {
/**
* The version of the spec schema
*/
Expand Down Expand Up @@ -120,7 +123,7 @@ export interface Assembly extends AssemblyConfiguration, Documentable {
*
* @default none
*/
dependencyClosure?: { [assembly: string]: AssemblyConfiguration };
dependencyClosure?: { [assembly: string]: DependencyConfiguration };

/**
* List if bundled dependencies (these are not expected to be jsii
Expand Down Expand Up @@ -157,6 +160,10 @@ export interface AssemblyConfiguration extends Targetable {
submodules?: { [fqn: string]: Submodule };
}

export interface DependencyConfiguration extends Targetable {
submodules?: { [fqn: string]: Targetable };
}

/**
* A targetable module-like thing
*
Expand All @@ -170,7 +177,12 @@ export interface Targetable {
* @default none
*/
targets?: AssemblyTargets;
}

/**
* Elements that can contain a `readme` property.
*/
export interface ReadMeContainer {
/**
* The readme document for this module (if any).
*
Expand All @@ -192,7 +204,7 @@ export interface ReadMe {
* The difference between a top-level module (the assembly) and a submodule is
* that the submodule is annotated with its location in the repository.
*/
export type Submodule = SourceLocatable & Targetable;
export type Submodule = ReadMeContainer & SourceLocatable & Targetable;

/**
* Versions of the JSII Assembly Specification.
Expand Down
3 changes: 3 additions & 0 deletions packages/@scope/jsii-calc-lib/lib/submodule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Submodule Readme

This is a submodule readme.
5 changes: 4 additions & 1 deletion packages/@scope/jsii-calc-lib/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
"filename": "lib/index.ts",
"line": 130
},
"readme": {
"markdown": "# Submodule Readme\n\nThis is a submodule readme.\n"
},
"targets": {
"dotnet": {
"namespace": "Amazon.JSII.Tests.CustomSubmoduleName"
Expand Down Expand Up @@ -948,5 +951,5 @@
}
},
"version": "0.0.0",
"fingerprint": "LN1bs46m2O4aR6AhHvi6UDh/f90EoUT3n5apMPzr9+c="
"fingerprint": "fCLOsQQLslSg+W8rn7XDZ1RSenH5QeaoTna+j7o+URc="
}
6 changes: 1 addition & 5 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@
"@scope/jsii-calc-lib": {
"submodules": {
"@scope/jsii-calc-lib.submodule": {
"locationInModule": {
"filename": "lib/index.ts",
"line": 130
},
"targets": {
"dotnet": {
"namespace": "Amazon.JSII.Tests.CustomSubmoduleName"
Expand Down Expand Up @@ -16779,5 +16775,5 @@
}
},
"version": "3.20.120",
"fingerprint": "XZczlgiEPAQC/n86Dqa40vixNH4txnPoyuF1Q+jR6I0="
"fingerprint": "WpcHNV2L+v3B7Ou+8xsRMzye4rf1U+SURQA97A3JT6g="
}
6 changes: 4 additions & 2 deletions packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ export class DotNetGenerator extends Generator {
const dotnetNs = this.typeresolver.resolveNamespace(
this.assembly,
this.assembly.name,
jsiiNs,
// Strip the `${assmName}.` prefix here, as the "assembly-relative" NS
// is expected by `this.typeResolver.resovleNamespace`.
jsiiNs.substr(this.assembly.name.length + 1),
);
this.emitNamespaceDocs(dotnetNs, jsiiNs, submodule);
}
Expand Down Expand Up @@ -1158,7 +1160,7 @@ export class DotNetGenerator extends Generator {
private emitNamespaceDocs(
namespace: string,
jsiiFqn: string,
docSource: spec.Targetable,
docSource: spec.Targetable & spec.ReadMeContainer,
) {
if (!docSource.readme) {
return;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3100,19 +3100,44 @@ function noEmptyDict<T>(
}

function toDependencyClosure(assemblies: readonly spec.Assembly[]): {
[name: string]: spec.AssemblyConfiguration;
[name: string]: spec.DependencyConfiguration;
} {
const result: { [name: string]: spec.AssemblyTargets } = {};
const result: { [name: string]: spec.DependencyConfiguration } = {};
for (const assembly of assemblies) {
if (!assembly.targets) {
continue;
}
result[assembly.name] = {
submodules: assembly.submodules,
submodules: cleanUp(assembly.submodules),
targets: assembly.targets,
};
}
return result;

/**
* Removes unneeded fields from the entries part of the `dependencyClosure`
* property. Fields such as `readme` are not necessary and can bloat up the
* assembly object.
*
* This removes the `readme` and `locationInModule` fields from the submodule
* descriptios if present.
*
* @param submodules the submodules list to clean up.
*
* @returns the cleaned up submodules list.
*/
function cleanUp(
submodules: spec.Assembly['submodules'],
): spec.DependencyConfiguration['submodules'] {
if (submodules == null) {
return submodules;
}
const result: spec.DependencyConfiguration['submodules'] = {};
for (const [fqn, { targets }] of Object.entries(submodules)) {
result[fqn] = { targets };
}
return result;
}
}

function toSubmoduleDeclarations(
Expand Down

0 comments on commit 0f5f349

Please sign in to comment.