From 4405e0129a475803b90df7b70725557754b64f5c Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Mon, 1 Apr 2024 09:43:53 -0400 Subject: [PATCH] (fix): express generation resolves mime library (#3302) --- generators/commons/src/AbstractGeneratorContext.ts | 2 +- generators/csharp/codegen/src/utils/CSharpFile.ts | 2 +- generators/typescript/express/CHANGELOG.md | 14 ++++++++++++++ generators/typescript/express/VERSION | 2 +- .../express/generator/src/ExpressGenerator.ts | 5 ++++- .../typescript/sdk/generator/src/SdkGenerator.ts | 3 ++- .../typescript-project/SimpleTypescriptProject.ts | 12 +++++++++++- .../types/types/UnionWithBaseProperties.d.ts | 5 ++++- .../types/types/UnionWithBaseProperties.d.ts | 5 ++++- .../types/types/UnionWithBaseProperties.js | 10 ++++++++++ 10 files changed, 52 insertions(+), 8 deletions(-) diff --git a/generators/commons/src/AbstractGeneratorContext.ts b/generators/commons/src/AbstractGeneratorContext.ts index 37fdd2bdba0..3065077f8ff 100644 --- a/generators/commons/src/AbstractGeneratorContext.ts +++ b/generators/commons/src/AbstractGeneratorContext.ts @@ -13,7 +13,7 @@ export abstract class AbstractGeneratorContext { public constructor( public readonly config: FernGeneratorExec.config.GeneratorConfig, - public readonly generatorNotificationService: GeneratorNotificationService, + public readonly generatorNotificationService: GeneratorNotificationService ) { this.logger = createLogger((level, ...message) => { CONSOLE_LOGGER.log(level, ...message); diff --git a/generators/csharp/codegen/src/utils/CSharpFile.ts b/generators/csharp/codegen/src/utils/CSharpFile.ts index cc3e84d5350..8e91d8ba1e5 100644 --- a/generators/csharp/codegen/src/utils/CSharpFile.ts +++ b/generators/csharp/codegen/src/utils/CSharpFile.ts @@ -19,7 +19,7 @@ export class CSharpFile extends File { } public async tryWrite(directoryPrefix: AbsoluteFilePath): Promise { - await this.write(directoryPrefix); + await this.write(directoryPrefix); } public static getFilePathFromFernFilePath(fernFilePath: FernFilepath): RelativeFilePath { diff --git a/generators/typescript/express/CHANGELOG.md b/generators/typescript/express/CHANGELOG.md index 8bd030d925e..60cca6bd956 100644 --- a/generators/typescript/express/CHANGELOG.md +++ b/generators/typescript/express/CHANGELOG.md @@ -5,6 +5,20 @@ 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.9.9] - 2024-03-22 +- Fix: Compile started failing for express generators with the following error: + + ``` + error TS2688: Cannot find type definition file for 'mime'. + + The file is in the program because: + Entry point for implicit type library 'mime' + ``` + + The root cause is because a breaking change was released in v4 of the mime library. + This is now fixed because the generator resolves to v3 of the library as + specified in this GitHub [issue](https://github.com/firebase/firebase-admin-node/issues/2512). + ## [0.9.8] - 2024-03-22 - Improvement: Enhance serde performance by reducing reliance on async behavior and lazy async dynamic imports. - Internal: Shared generator notification and config parsing logic. diff --git a/generators/typescript/express/VERSION b/generators/typescript/express/VERSION index b5d0ec558fd..6f060dcbc24 100644 --- a/generators/typescript/express/VERSION +++ b/generators/typescript/express/VERSION @@ -1 +1 @@ -0.9.8 \ No newline at end of file +0.9.9 \ No newline at end of file diff --git a/generators/typescript/express/generator/src/ExpressGenerator.ts b/generators/typescript/express/generator/src/ExpressGenerator.ts index 96539c5ad30..2cea12d9afb 100644 --- a/generators/typescript/express/generator/src/ExpressGenerator.ts +++ b/generators/typescript/express/generator/src/ExpressGenerator.ts @@ -238,7 +238,10 @@ export class ExpressGenerator { extraDependencies: {}, extraDevDependencies: {}, extraFiles: {}, - extraScripts: {} + extraScripts: {}, + resolutions: { + "@types/mime": "3.0.4" + } }); } diff --git a/generators/typescript/sdk/generator/src/SdkGenerator.ts b/generators/typescript/sdk/generator/src/SdkGenerator.ts index b3217446e83..5662a238bd1 100644 --- a/generators/typescript/sdk/generator/src/SdkGenerator.ts +++ b/generators/typescript/sdk/generator/src/SdkGenerator.ts @@ -387,7 +387,8 @@ module.exports = { extraDependencies: this.config.extraDependencies, extraDevDependencies: this.config.extraDevDependencies, extraFiles: this.extraFiles, - extraScripts: this.extraScripts + extraScripts: this.extraScripts, + resolutions: {} }); } diff --git a/generators/typescript/utils/commons/src/typescript-project/SimpleTypescriptProject.ts b/generators/typescript/utils/commons/src/typescript-project/SimpleTypescriptProject.ts index f0790fa0d8f..0197c29fd41 100644 --- a/generators/typescript/utils/commons/src/typescript-project/SimpleTypescriptProject.ts +++ b/generators/typescript/utils/commons/src/typescript-project/SimpleTypescriptProject.ts @@ -14,6 +14,7 @@ export declare namespace SimpleTypescriptProject { npmPackage: NpmPackage | undefined; dependencies: PackageDependencies; outputEsm: boolean; + resolutions: Record; } } @@ -25,12 +26,14 @@ export class SimpleTypescriptProject extends TypescriptProject { private npmPackage: NpmPackage | undefined; private dependencies: PackageDependencies; private outputEsm: boolean; + private resolutions: Record; - constructor({ npmPackage, dependencies, outputEsm, ...superInit }: SimpleTypescriptProject.Init) { + constructor({ npmPackage, dependencies, outputEsm, resolutions, ...superInit }: SimpleTypescriptProject.Init) { super(superInit); this.npmPackage = npmPackage; this.dependencies = dependencies; this.outputEsm = outputEsm; + this.resolutions = resolutions; } protected async addFilesToVolume(): Promise { @@ -138,6 +141,13 @@ export class SimpleTypescriptProject extends TypescriptProject { }; } + if (Object.entries(this.resolutions).length > 0) { + packageJson = { + ...packageJson, + resolutions: this.resolutions + }; + } + packageJson = { ...packageJson, main: "./index.js", diff --git a/seed/ts-express/unions/api/resources/types/types/UnionWithBaseProperties.d.ts b/seed/ts-express/unions/api/resources/types/types/UnionWithBaseProperties.d.ts index 748b7bc3fc2..480169eda09 100644 --- a/seed/ts-express/unions/api/resources/types/types/UnionWithBaseProperties.d.ts +++ b/seed/ts-express/unions/api/resources/types/types/UnionWithBaseProperties.d.ts @@ -2,7 +2,7 @@ * This file was auto-generated by Fern from our API Definition. */ import * as SeedUnions from "../../.."; -export declare type UnionWithBaseProperties = SeedUnions.UnionWithBaseProperties.Integer | SeedUnions.UnionWithBaseProperties.String; +export declare type UnionWithBaseProperties = SeedUnions.UnionWithBaseProperties.Integer | SeedUnions.UnionWithBaseProperties.String | SeedUnions.UnionWithBaseProperties.Foo; export declare namespace UnionWithBaseProperties { interface Integer extends _Base { type: "integer"; @@ -12,6 +12,9 @@ export declare namespace UnionWithBaseProperties { type: "string"; value: string; } + interface Foo extends SeedUnions.Foo, _Base { + type: "foo"; + } interface _Base { id: string; } diff --git a/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.d.ts b/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.d.ts index fbae8390888..3dbbcd74b7c 100644 --- a/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.d.ts +++ b/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.d.ts @@ -6,7 +6,7 @@ import * as serializers from "../../.."; import * as SeedUnions from "../../../../api"; export declare const UnionWithBaseProperties: core.serialization.Schema; export declare namespace UnionWithBaseProperties { - type Raw = UnionWithBaseProperties.Integer | UnionWithBaseProperties.String; + type Raw = UnionWithBaseProperties.Integer | UnionWithBaseProperties.String | UnionWithBaseProperties.Foo; interface Integer extends _Base { type: "integer"; value: number; @@ -15,6 +15,9 @@ export declare namespace UnionWithBaseProperties { type: "string"; value: string; } + interface Foo extends _Base, serializers.Foo.Raw { + type: "foo"; + } interface _Base { id: string; } diff --git a/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.js b/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.js index 31fa451976f..dcb61368f04 100644 --- a/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.js +++ b/seed/ts-express/unions/serialization/resources/types/types/UnionWithBaseProperties.js @@ -25,6 +25,15 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnionWithBaseProperties = void 0; const core = __importStar(require("../../../../core")); @@ -43,6 +52,7 @@ exports.UnionWithBaseProperties = core.serialization value: core.serialization.string(), }) .extend(_Base), + foo: core.serialization.lazyObject(() => __awaiter(void 0, void 0, void 0, function* () { return (yield Promise.resolve().then(() => __importStar(require("../../..")))).Foo; })).extend(_Base), }) .transform({ transform: (value) => value,