Skip to content

Commit 414c869

Browse files
authored
fix(go): Add no-op notification service (#6440)
1 parent d239bef commit 414c869

File tree

7 files changed

+55
-7
lines changed

7 files changed

+55
-7
lines changed

generators/base/src/AbstractGeneratorCli.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@ import { readFile } from "fs/promises";
33

44
import {
55
AbstractGeneratorContext,
6+
AbstractGeneratorNotificationService,
67
FernGeneratorExec,
78
GeneratorExecParsing,
8-
GeneratorNotificationService
9+
GeneratorNotificationService,
10+
NopGeneratorNotificationService
911
} from "@fern-api/browser-compatible-base-generator";
1012
import { assertNever } from "@fern-api/core-utils";
1113

14+
export declare namespace AbstractGeneratorCli {
15+
interface Options {
16+
/* Whether to disable notifications */
17+
disableNotifications?: boolean;
18+
}
19+
}
20+
1221
export abstract class AbstractGeneratorCli<
1322
CustomConfig,
1423
IntermediateRepresentation,
1524
GeneratorContext extends AbstractGeneratorContext
1625
> {
17-
public async run(): Promise<void> {
26+
public async run(options: AbstractGeneratorCli.Options = {}): Promise<void> {
1827
const config = await getGeneratorConfig();
19-
const generatorNotificationService = new GeneratorNotificationService(config.environment);
28+
const generatorNotificationService = options.disableNotifications
29+
? new NopGeneratorNotificationService()
30+
: new GeneratorNotificationService(config.environment);
2031
try {
2132
await generatorNotificationService.sendUpdate(
2233
FernGeneratorExec.GeneratorUpdate.initV2({
@@ -85,7 +96,7 @@ export abstract class AbstractGeneratorCli<
8596
ir: IntermediateRepresentation;
8697
customConfig: CustomConfig;
8798
generatorConfig: FernGeneratorExec.GeneratorConfig;
88-
generatorNotificationService: GeneratorNotificationService;
99+
generatorNotificationService: AbstractGeneratorNotificationService;
89100
}): GeneratorContext;
90101

91102
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { FernGeneratorExec } from "@fern-fern/generator-exec-sdk";
2+
3+
export abstract class AbstractGeneratorNotificationService {
4+
public abstract bufferUpdate(update: FernGeneratorExec.GeneratorUpdate): void;
5+
public abstract sendUpdate(update: FernGeneratorExec.GeneratorUpdate): Promise<void>;
6+
}

generators/browser-compatible-base/src/GeneratorNotificationService.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import {
88
} from "@fern-fern/generator-exec-sdk/api";
99
import * as GeneratorExecParsing from "@fern-fern/generator-exec-sdk/serialization";
1010

11+
import { AbstractGeneratorNotificationService } from "./AbstractGeneratorNotificationService";
12+
1113
export { GeneratorExecParsing, ExitStatusUpdate, GeneratorUpdate, LogLevel, FernGeneratorExec };
1214
export type { GeneratorConfig, GithubOutputMode };
1315

14-
export class GeneratorNotificationService {
16+
export class GeneratorNotificationService implements AbstractGeneratorNotificationService {
1517
private client: FernGeneratorExecClient | undefined;
1618
private taskId: FernGeneratorExec.TaskId | undefined;
1719
private buffer: FernGeneratorExec.GeneratorUpdate[] = [];
@@ -52,7 +54,7 @@ export class GeneratorNotificationService {
5254
await this.flush();
5355
}
5456

55-
public async flush(): Promise<void> {
57+
private async flush(): Promise<void> {
5658
if (!this.client || !this.taskId) {
5759
return;
5860
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { FernGeneratorExec } from "@fern-fern/generator-exec-sdk";
2+
3+
import { AbstractGeneratorNotificationService } from "./AbstractGeneratorNotificationService";
4+
5+
export class NopGeneratorNotificationService extends AbstractGeneratorNotificationService {
6+
public bufferUpdate(_: FernGeneratorExec.GeneratorUpdate): void {
7+
// no-op
8+
return;
9+
}
10+
11+
public sendUpdate(_: FernGeneratorExec.GeneratorUpdate): Promise<void> {
12+
// no-op
13+
return Promise.resolve();
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export * from "./AbstractGeneratorContext";
2+
export * from "./AbstractGeneratorNotificationService";
23
export * from "./GeneratorNotificationService";
34
export * from "./ast";
45
export * from "./utils";
56
export * from "./dynamic-snippets";
7+
export * from "./NopGeneratorNotificationService";

generators/go-v2/sdk/src/cli.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ void runCli();
44

55
export async function runCli(): Promise<void> {
66
const cli = new SdkGeneratorCLI();
7-
await cli.run();
7+
await cli.run({
8+
// We disable notifications because the `go-v2` generator notifications
9+
// prevent the `go` generator from succeeding in remote code generation
10+
// environments.
11+
disableNotifications: true
12+
});
813
}

generators/go/sdk/versions.yml

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
- version: 0.37.2
2+
changelogEntry:
3+
- type: fix
4+
summary: >-
5+
Fix an issue where the `go-v2` generator call prevented the `go` generator from succeeding
6+
in remote code generation environments.
7+
irVersion: 57
18
- version: 0.37.1
29
changelogEntry:
310
- type: fix

0 commit comments

Comments
 (0)