JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 104
  • Score
    100M100P100Q100949F
  • License MIT

Patch Nestjs app ESM bundles to make them work RHRN

Package Exports

    Readme

    nestjs-esm-fix

    CI Maintainability Test Coverage npm (tag)

    Patch Nestjs app ESM bundles to make them work RHRN

    Problem

    1. openapi is not defined. https://github.com/nestjs/swagger/issues/1450
    __decorate([
        Post('event-unsafe-batch'),
        HttpCode(200),
        openapi.ApiResponse({ status: 200, type: String }),
        __param(0, Body()),
        __param(1, Req()),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object, Object]),
        __metadata("design:returntype", Promise)
    ], EventUnsafeController.prototype, "logEventBatch", null);
    1. openapi / class-validator DTOs are referenced by require API.
    export class CspReportDto {
        static _OPENAPI_METADATA_FACTORY() {
            return { timestamp: { required: false, type: () => Object }, 'csp-report': { required: true, type: () => require("./csp.dto.js").CspReport } };
        }
    }

    Solution

    Old good monkey patching.

    Install

    yarn add -D nestjs-esm-fix

    Usage

    CLI

    nestjs-esm-fix target/**/*.js
    Option Description Default
    --openapi-var Inject openapi variable. Set --no-openapi-var to disable. true
    --openapi-type-ref Replace type: () => require statements with import. true

    JS API

    import {fix} from 'nestjs-esm-fix'
    await fix({
      cwd: '.',
      target: 'target/**/*.js',
      openapiVar: true,
      openapiTypeRef: true,
    })

    License

    MIT