Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Removed dynamic require which cause issues with esmbuild, make it wor… #141

Closed mattiasrunge closed 2 years ago

mattiasrunge commented 2 years ago

Thanks for a great project!

I am trying to use openapi-enforcer in Deno via https://esm.sh as described here: https://deno.land/manual@v1.12.2/npm_nodejs/cdns#esmsh

Though it requires the modules to not have any dynamic imports. I get this error:

error: Uncaught Error: Dynamic require of "./enforcers/Contact" is not supported
    at https://cdn.esm.sh/v78/openapi-enforcer@1.19.0/deno/openapi-enforcer.bundle.js:2:1038
    at zs (https://cdn.esm.sh/v78/openapi-enforcer@1.19.0/deno/openapi-enforcer.bundle.js:36:12917)
    at https://cdn.esm.sh/v78/openapi-enforcer@1.19.0/deno/openapi-enforcer.bundle.js:40:5526
    at https://cdn.esm.sh/v78/openapi-enforcer@1.19.0/deno/openapi-enforcer.bundle.js:2:1118
    at https://cdn.esm.sh/v78/openapi-enforcer@1.19.0/deno/openapi-enforcer.bundle.js:40:7355

Looking at the code it seems it is the require in Super which causes this, but Super already has support for passing in a module object. So my hope is that this PR could be allowed to remove the use of dynamic requires and allow the esm transformation that esm.sh does to work so this awesome project is usable in Deno as well.

Gi60s commented 2 years ago

Hey @mattiasrunge.

I'm glad you like the project and thanks for the PR.

I'll take some time later today to run this PR through the tests. Assuming that nothing has broken I'll then publish this to NPM.

Thank you for contributing.

Gi60s commented 2 years ago

Thanks for the PR. I've merged it and published to NPM under version 1.20.0.

mattiasrunge commented 2 years ago

Thank you very much! It works! Or at least the parts I have tried so far!