Skip to content

Commit

Permalink
(ts, feature): introduce custom config for tolerateRepublish to re …
Browse files Browse the repository at this point in the history
…publish npm versions (#3093)

* (ts, feature): introduce  custom config

* fix compile
  • Loading branch information
dsinghvi authored Mar 1, 2024
1 parent f8206c8 commit caeffc1
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 10 deletions.
4 changes: 4 additions & 0 deletions generators/csharp/model/src/ModelGeneratorCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export class ModelGeneratorCLI extends AbstractGeneratorCli<ModelCustomConfigSch
generatorContext.logger.info("Received IR", JSON.stringify(intermediateRepresentation, null, 2));
await writeFile(`/${config.output.path}/ir.json`, JSON.stringify(intermediateRepresentation, null, 2));
}

protected shouldTolerateRepublish(customConfig: ModelCustomConfigSchema): boolean {
return false;
}
}
4 changes: 4 additions & 0 deletions generators/typescript/express/cli/src/ExpressGeneratorCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ export class ExpressGeneratorCli extends AbstractGeneratorCli<ExpressCustomConfi
protected outputSourceFiles(customConfig: ExpressCustomConfig): boolean {
return customConfig.outputSourceFiles;
}

protected shouldTolerateRepublish(customConfig: ExpressCustomConfig): boolean {
return false;
}
}
22 changes: 19 additions & 3 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.12.3-rc1] - 2024-02-27
## [0.12.5] - 2024-02-27

- Introduce a custom configuration called `tolerateRepublish` which supports running
npm publish with the flag `--tolerateRepublish`. This flag allows you to publish
on top of an existing npm package.

To turn on this flag, update your generators.yml:

```yaml
groups:
generators:
- name: fernapi/fern-typscript-node-sdk
version: 0.12.5
...
config:
tolerateRepublish: true
```
## [0.12.4] - 2024-02-27
- Fix: Previously reference.md was just leveraging the function name for the reference, now it leverages the full package-scoped path, mirroring how the function would be used in reality.
Expand All @@ -17,8 +35,6 @@ seedExamples.getException(...)
seedExamples.file.notification.service.getException(...)
```

## [0.12.3-rc1] - 2024-02-27

- Fix: Previously SDK code snippets would not support generation with undiscriminated unions. Now, it does.

## [0.12.2] - 2024-02-27
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.4
0.12.5
10 changes: 8 additions & 2 deletions generators/typescript/sdk/cli/src/SdkGeneratorCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class SdkGeneratorCli extends AbstractGeneratorCli<SdkCustomConfig> {
includeContentHeadersOnFileDownloadResponse: parsed?.includeContentHeadersOnFileDownloadResponse ?? false,
noSerdeLayer,
noOptionalProperties: parsed?.noOptionalProperties ?? false,
includeApiReference: parsed?.includeApiReference ?? false
includeApiReference: parsed?.includeApiReference ?? false,
tolerateRepublish: parsed?.tolerateRepublish ?? false
};
}

Expand Down Expand Up @@ -99,7 +100,8 @@ export class SdkGeneratorCli extends AbstractGeneratorCli<SdkCustomConfig> {
includeContentHeadersOnFileDownloadResponse: customConfig.includeContentHeadersOnFileDownloadResponse,
includeSerdeLayer: !customConfig.noSerdeLayer,
noOptionalProperties: customConfig.noOptionalProperties,
includeApiReference: customConfig.includeApiReference ?? false
includeApiReference: customConfig.includeApiReference ?? false,
tolerateRepublish: customConfig.tolerateRepublish
}
});
const typescriptProject = await sdkGenerator.generate();
Expand All @@ -118,4 +120,8 @@ export class SdkGeneratorCli extends AbstractGeneratorCli<SdkCustomConfig> {
protected outputSourceFiles(customConfig: SdkCustomConfig): boolean {
return customConfig.outputSourceFiles;
}

protected shouldTolerateRepublish(customConfig: SdkCustomConfig): boolean {
return customConfig.tolerateRepublish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export interface SdkCustomConfig {
noSerdeLayer: boolean;
noOptionalProperties: boolean;
includeApiReference: boolean | undefined;
tolerateRepublish: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const SdkCustomConfigSchema = z.strictObject({
treatUnknownAsAny: z.optional(z.boolean()),
noSerdeLayer: z.optional(z.boolean()),
noOptionalProperties: z.optional(z.boolean()),
tolerateRepublish: z.optional(z.boolean()),

// beta (not in docs)
includeContentHeadersOnFileDownloadResponse: z.optional(z.boolean()),
Expand Down
1 change: 1 addition & 0 deletions generators/typescript/sdk/generator/src/SdkGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export declare namespace SdkGenerator {
includeSerdeLayer: boolean;
noOptionalProperties: boolean;
includeApiReference: boolean;
tolerateRepublish: boolean;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export abstract class AbstractGeneratorCli<CustomConfig> {
npmPackage,
dryRun: config.dryRun,
generatorNotificationService,
typescriptProject
typescriptProject,
shouldTolerateRepublish: this.shouldTolerateRepublish(customConfig)
});
await typescriptProject.npmPackAsZipTo({
logger,
Expand Down Expand Up @@ -170,6 +171,7 @@ export abstract class AbstractGeneratorCli<CustomConfig> {
}): Promise<PersistedTypescriptProject>;
protected abstract isPackagePrivate(customConfig: CustomConfig): boolean;
protected abstract outputSourceFiles(customConfig: CustomConfig): boolean;
protected abstract shouldTolerateRepublish(customConfig: CustomConfig): boolean;
}

class GeneratorContextImpl implements GeneratorContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export async function publishPackage({
logger,
npmPackage,
dryRun,
typescriptProject
typescriptProject,
shouldTolerateRepublish
}: {
generatorNotificationService: GeneratorNotificationService | undefined;
logger: Logger;
npmPackage: NpmPackage | undefined;
dryRun: boolean;
typescriptProject: PersistedTypescriptProject;
shouldTolerateRepublish: boolean;
}): Promise<void> {
if (npmPackage?.publishInfo == null) {
throw new Error("npmPackage.publishInfo is not defined.");
Expand All @@ -30,7 +32,8 @@ export async function publishPackage({
await typescriptProject.publish({
logger,
dryRun,
publishInfo: npmPackage.publishInfo
publishInfo: npmPackage.publishInfo,
shouldTolerateRepublish
});

await generatorNotificationService?.sendUpdate(FernGeneratorExec.GeneratorUpdate.published(packageCoordinate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ export class PersistedTypescriptProject {
public async publish({
logger,
publishInfo,
dryRun
dryRun,
shouldTolerateRepublish
}: {
logger: Logger;
publishInfo: PublishInfo;
dryRun: boolean;
shouldTolerateRepublish: boolean;
}): Promise<void> {
await this.build(logger);

Expand All @@ -212,6 +214,9 @@ export class PersistedTypescriptProject {
if (dryRun) {
publishCommand.push("--dry-run");
}
if (shouldTolerateRepublish) {
publishCommand.push("--tolerate-republish");
}
await npm(publishCommand);
}

Expand Down

0 comments on commit caeffc1

Please sign in to comment.