-
-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: non-breaking ESM support 🤝 #613
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Codecov Report
@@ Coverage Diff @@
## main #613 +/- ##
=======================================
Coverage 99.57% 99.57%
=======================================
Files 12 12
Lines 1409 1424 +15
Branches 255 261 +6
=======================================
+ Hits 1403 1418 +15
Misses 6 6
📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
at this point it'd probably be better to just write a new file...
Released in v3.5.0-0. |
@ephys @SmashingQuasar @JSteunou @mysuf @papb since you've all commented on #608 and/or #626. I've published this PR, which I hope adds what we can consider "first-class" ESM support, as 3.5.0-0 (under the If you're able, would you be able to try this version and see if it works for you? It does not migrate to ESM-first, but it now uses Worth reading in the PR description, but this doesn't change umzug to be a |
You efforts are very much appreciated. Thanks a lot for taking time to look into this. It will benefit everyone in the long run! |
@mmkal Thank you. I've tried and in my case it works out of the box without custom resolver as expected. |
|
Feedback looks good, I'm merging this. 🤞 |
@mmkal great job, really appreciate the effort! 👏 |
Released in v3.5.0. |
Closes #608
This adds some esm-vs-commonjs "smartness" to umzug:
require
for.cjs
migrations andimport
for.mjs
migrations (and their typescript equivalents)require
for.js
migrations iftypeof require.main === 'object'
, andimport
to.js
migrations otherwise"moduleResolution": "Node16"
to tsconfig.lib.json to make sureimport(filepath)
doesn't get transpiled into__importStar(require(filepath))
(see here and here)Tests/examples:
vanilla-esm
example to make sure usingimport
/ top-level await workstest_pkg
job to make sure vitest isn't hiding gnarly import problems - this is installing the compiled library as a.tgz
, and with no other dev/prod dependencies like vitest or ts-node having been installed, so should be very close to what end users will doDidn't:
original body
Related to #608 - although does not close it.This adds built-in support for.mjs
and.mts
files..mjs
should "just work" - write migrations as ESM modules and they'll be imported in the right way. For the current major version,.js
will continue to be assumed commonjs. ESM-fans will just have to type that extram
in their filenames.This PR doesn't add a wrapper file so that the umzug library itself can be imported as an ES module. That can be done in a follow-up PR. In the meantime, ESM users can usecreateRequire
as in the existing ESM example.