ts-sql-query icon indicating copy to clipboard operation
ts-sql-query copied to clipboard

ESM support

Open lorefnon opened this issue 2 years ago • 4 comments

Would you be open to a PR that exposes es modules in the deployed package as .mjs artifacts ?

This doesn't need to be a breaking change but likely all drivers won't be importable as es modules so only subset of databases would be available through esm.

I am trying to migrate a project to esm and currently ts-sql-query is one of the few dependencies that aren't exposed as esm.

lorefnon avatar Dec 12 '22 09:12 lorefnon

Good, I'm going to investigate how to implement it. If you can provide some hints on this I will appreciate.

juanluispaz avatar Dec 12 '22 10:12 juanluispaz

I was originally thinking I could just add a tsconfig.esm.json which generates modules and have those files alongside commonjs with mjs extension.

However, it looks like tsc does not yet allow specifying an extension, and in esm (when a bundler is not involved) imports must also have the extension. I have an early setup with babel that rewrites the imports - I'll test out what all drivers can be expected to work and update in some time.

Let me know if you have any concerns with the approach.

lorefnon avatar Dec 13 '22 17:12 lorefnon

The linked pr does what it was originally intended to do.

However, I found that node's commonjs->esm interop also works well enough for my project. It was sufficient to just ensure that all the imports to ts-sql-query had an extension - and with the --experimental-specifier-resolution=node option recently added by node even that is optional.

So unless long term you plan to migrate the package to esm, we can close that pr.

lorefnon avatar Dec 18 '22 19:12 lorefnon

Then, I will prefer to archive the PR for now, I will continue investigating this topic more in deep taking as reference your PR. I'm afraid, depending how it is implemented, it could require a major release.

Regarding the future plan, I would like to add support to ESM.

juanluispaz avatar Dec 19 '22 11:12 juanluispaz