-
Notifications
You must be signed in to change notification settings - Fork 2
feat: compile as ES Module #431
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
Conversation
If your project has
Either we:
|
For "Add .js to the end of the source code's import statements (and configure our editor/linter to enforce it)" we have to switch eslint to eslint-import-resolver-typescript |
I also checked if it is possible to go Full ESM -- and use |
… version, due to yarn patches)
After struggling for a long while with trying to "shim" isomorphic-ws to work normally in a jest environment, it is easier to just run this test only in a Node environment. Here are the issues why this test fails in JSDOM: 1. Imports fail The statement `import WebSocket from 'isomorphic-ws';` is passed to the Jest module resolver, which utilises `ts-jest-resolver` (in our case) to find the right file to load. Sadly, it will always load the "main" module of a node package. 2. isomorphic-ws "browser" option is ESM for some reason If we use jest.config.cjs "resolver" field [1] to define a custom script, we will be able to modify the "main" field by patching package.json in memory. This works fine, however isomorphic-ws's browser version is an ES Module for some reason, even if the package.json > "type" is "commonjs". 3. Something inside jest doesn't want me to hack it to support ESM If I override the package.json even harder to also change the "type" to "module" just for isomorphic-ws, Jest doesn't respect it 4. ts-jest doesn't want to change the ESM imports to CJS imports Since... we told it to not change ESM imports to CJS imports, it will not. [1]: https://jestjs.io/docs/configuration#resolver-string
Stopped trying to make the subscriptions tests work across two different jest environments. Explanation here db48074 |
Codecov ReportBase: 74.66% // Head: 75.96% // Increases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #431 +/- ##
==========================================
+ Coverage 74.66% 75.96% +1.29%
==========================================
Files 12 12
Lines 671 674 +3
Branches 137 136 -1
==========================================
+ Hits 501 512 +11
+ Misses 169 153 -16
- Partials 1 9 +8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@boxmein should se still test on different NodeJS versions? Currently we have test matrix for v12, 14, 15 & 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Description of the change
Set package.json
"type": "module"
Set tsconfig.json
"module": "nodenext"
import
andexport
statements, adding new interoperability considerationsConfigure eslint to operate in
ES Modules
contextimport
plugin, so that it works after extensions are specifiedConfigure Jest to operate in ES Modules mode
ts-jest-resolver
will provide proper filename lookup, so that it works after extensions are specifiedUpdate tests
cross-fetch
works better thanisomorphic-fetch
in ES Modules mode, so using that nowisomorphic-ws
had no alternative that worked correctly in ES Modules mode... after trying multiple different approaches to work around it, I opted to only run WebSocket tests on Node.Type of change
Related issues
Checklists
Development
Code review