Skip to content

Commit

Permalink
fix(pacmak): go docs overview displays repeating description (#4081)
Browse files Browse the repository at this point in the history
Our `go docs` have been broken since jsii `v1.65.0`. This was due to moving to emitting one file per type and headers being added to all those files: [Impacting PR](https://github.com/aws/jsii/pull/3698/files#diff-0a99c713a1282d6efe349c932d74dbfbdf1d926834c46ebfb5d65daeb27073f3R263)

The first occurrence was in [docs for cdk v2.39.0](https://pkg.go.dev/github.com/aws/aws-cdk-go/awscdk/v2@v2.39.0) and is still present in the [latest version](https://pkg.go.dev/github.com/aws/aws-cdk-go/awscdk/v2).

The header being added is `Version 2 of the AWS Cloud Development Kit library` to multiple files. It's determining this value from the [package.json](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/package.json#L4) file of `aws-cdk-lib`. I see adding this is most relevant for [maven](https://github.com/aws/jsii/blob/main/packages/jsii-reflect/lib/assembly.ts#L46-L52), hence removing it from `go` since I do not believe it's bringing much value to our documentation. Let me know if you feel otherwise :) 

---

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
vinayak-kukreja committed May 9, 2023
1 parent e708e6b commit 4fd596a
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 787 deletions.
8 changes: 8 additions & 0 deletions packages/codemaker/src/codemaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ export class CodeMaker {
return caseutils.toSnakeCase(s, sep);
}

/**
* Gets currently opened file path.
* @returns Currently opened file path.
*/
public getCurrentFilePath(): string | undefined {
return this.currentFile?.filePath;
}

private makeIndent(): string {
const length = this.currentIndentLength;
if (length <= 0) {
Expand Down
13 changes: 9 additions & 4 deletions packages/jsii-pacmak/lib/targets/go/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { VersionFile } from './version-file';

export const GOMOD_FILENAME = 'go.mod';
export const GO_VERSION = '1.18';
const MAIN_FILE = 'main.go';

/*
* Package represents a single `.go` source file within a package. This can be the root package file or a submodule
Expand Down Expand Up @@ -203,10 +204,9 @@ export abstract class Package {
if (this.types.length > 0) {
const { code } = context;

const initFile = join(this.directory, `main.go`);
const initFile = join(this.directory, MAIN_FILE);
code.openFile(initFile);
code.line(`package ${this.packageName}`);
code.line();
this.emitHeader(code);
importGoModules(code, [GO_REFLECT, JSII_RT_MODULE]);
code.line();
code.openBlock('func init()');
Expand Down Expand Up @@ -470,7 +470,12 @@ export class RootPackage extends Package {
}

protected emitHeader(code: CodeMaker) {
if (this.assembly.description !== '') {
const currentFilePath = code.getCurrentFilePath();
if (
this.assembly.description !== '' &&
currentFilePath !== undefined &&
currentFilePath.includes(MAIN_FILE)
) {
code.line(`// ${this.assembly.description}`);
}
code.line(`package ${this.packageName}`);
Expand Down

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

0 comments on commit 4fd596a

Please sign in to comment.