Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
Signed-off-by: Vinayak Kukreja <vinakuk@amazon.com>
  • Loading branch information
vinayak-kukreja committed May 9, 2023
1 parent cc6d294 commit 1ccf8f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 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
12 changes: 9 additions & 3 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,9 +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}`);
this.emitHeader(code);
code.line();
importGoModules(code, [GO_REFLECT, JSII_RT_MODULE]);
code.line();
Expand Down Expand Up @@ -470,7 +471,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

0 comments on commit 1ccf8f3

Please sign in to comment.