kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
895 stars 237 forks source link

Add support for ESM-based projects #810

Closed robertkiel closed 2 years ago

robertkiel commented 2 years ago

Still WIP, postponed until release of Typescript 4.7

Adds support for ESM-based projects

Main change:

https://github.com/hoprnet/open-api/blob/4d00559ee5e445f1f176f494ebcc4a9e26da978c/packages/openapi-framework/index.ts#L233-L236

Context

Within the Node.js ecosystem, there exist two package formats, CommonJS and the new de-facto standard ECMAScript Modules aka ESM.

CommonJS modues are usually loaded synchronously using require(), whereas ES modules are loaded either using the import keyword or are loaded dynamically, but asynchronously, using the builtin import() function.

To support loading both types of modules, the de-facto way to go is using import() as it supports both formats, CommonJS and ESM. Changing this turns various synchronous functions into asynchronous ones.

Changes

jsdevel commented 2 years ago

@robertkiel can you get the build to pass?

robertkiel commented 2 years ago

@robertkiel can you get the build to pass?

Yes, for sure. Currently awaiting the final release of Typescript 4.7 to have proper builds. Will add some commits in the next days.

robertkiel commented 2 years ago

Managed to squeeze the last burning issue regarding default exports of CommonJS scripts and default exports of ECMAScript modules. Tests are supposed to run green now.

jsdevel commented 2 years ago

thank you @robertkiel !! huge lift!