nestjs / mapped-types

Configuration module for Nest framework (node.js) 🐺
https://nestjs.com
MIT License
379 stars 60 forks source link

Update Class Transformer Package v0.5.1 #1526

Open john-shika opened 1 week ago

john-shika commented 1 week ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

I am trying to bundle all files into single main file, it's work until supposed conflict with some dependencies, because @nestjs /mapped-types required class-transformer@0.3.x for work, but my project need class-transfomer@0.5.1. trying run this command with bun and esbuild

bun run nest build
esbuild --bundle --minify --sourcemap=external --platform=node --target=es2020 --outdir=bin .\dist\main.js
X [ERROR] Could not resolve "class-transformer/storage"

    node_modules/.pnpm/@nestjs+mapped-types@2.0.5_@nestjs+common@10.4.7_class-transformer@0.5.1_class-validator@0.14_mu3cclgr33ip2qq3tugjdeyzwe/node_modules/@nestjs/mapped-types/dist/type-helpers.utils.js:80:35:
      80 │ ...lassTransformer = require('class-transformer/storage');
         ╵                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "class-transformer/storage" as external to
  exclude it from the bundle, which will remove this error and leave
  the unresolved path in the bundle. You can also surround this
  "require" call with a try/catch block to handle this failure at
  run-time instead of bundle-time.

Describe the solution you'd like

I have new solution! let me explain.

class-transformer@0.5.1 keep it class-transformer/cjs/storage.js until now, so replacing from

let classTransformer;
    try {
        classTransformer = require('class-transformer/cjs/storage');
    }
    catch {
        classTransformer = require('class-transformer/storage');
    }

with

const classTransformer = require('class-transformer/cjs/storage');

it's work. no error message from my console! but idk this is make some bad decision in the feature. :)

Teachability, documentation, adoption, migration strategy

no migration, but not tested as well

What is the motivation / use case for changing the behavior?

to make it single bundle file or compile it to executable exe if supported by platform like bun, deno, or something similarity, make it fast because bundle with minify.

kamilmysliwiec commented 1 week ago

Yeah, we can't do that yet as this would introduce a breaking change. We'll address that in the next major release

john-shika commented 1 week ago

Yeah, we can't do that yet as this would introduce a breaking change. We'll address that in the next major release

Not bad, I have another solution with my problem, thanks for sharing your time, my another solution to built single file with injection link script to class-transformer to link /storage.js to /cjs/storage.js, yea it's work, I am built with powershell script build.ps1 👌🏻✨ source ready to compile 😎