-
Notifications
You must be signed in to change notification settings - Fork 811
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
fix: remove require
usages in esm build
#2467
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2467 +/- ##
==========================================
- Coverage 92.62% 92.20% -0.42%
==========================================
Files 137 132 -5
Lines 5017 4632 -385
Branches 1060 989 -71
==========================================
- Hits 4647 4271 -376
+ Misses 370 361 -9 |
d416479
to
caeff83
Compare
Also fixes that assuming esmodule namespace object as callable in tests
caeff83
to
a174294
Compare
In addition to this comment #2464 (comment), For example: |
@meteorlxy That use pattern is explained here #2467 (comment). Of course, we can change all of these namespace imports to default imports. However, in this PR for now I just changed the imports that didn't work with I don't have a strong opinion to enforce the default import pattern. If people are fine with it, we can do it. |
Is there any chance to add a test for ESM executed on each PR? |
As the matter of fact, Node.js native ESM support requires module specifiers to have extensions like However, OTEL packages currently work with Node.js modules, interpreted as CJS modules. as Node.js automatically bridges CJS modules to ESM. The The current esm build product is originally generated for transpilers like webpack and rollup to tree shaking unused code pieces (#2112). So what I can tell by now is that maybe we can add a karma configuration to test with esm.
Setting "esModuleInterop" ensures generated js code importing behavior complies with the ESM standard (except features like direct references to |
@meteorlxy can you provide an example of what you mean by "contagious" behavior? I wasn't aware that enabling esmoduleinterop put additional requirements on dependent packages. |
@legendecas @dyladan Sure. Just made a demo repo: https://github.com/meteorlxy/esmoduleinterop-issue |
Ah I see. The way we are imported doesn't change, but the libcheck fails because it traverses up dependencies. |
That's it. So I personally recommend never enabling it in library projects. |
I can share @meteorlxy's sentiments about enabling Currently, in published code, the only package that is not compatible is |
Or if people are preferring not aggressive with strict esm compliant, and with push-backs from Node.js esm behavior disalignment even when |
The compatibility tests use the base tsconfig so they will also inherit the esmoduleinterop flag. @legendecas it sounds like you think there would still be issues if we just chose a different esm-friendly alternative for lodash.merge? Is there a way we can enforce in CI that our packages are truly esm friendly? Perhaps it's time for true integration tests where a fake "customer" project is compiled against each PR. |
@dyladan Edit: |
We had a discussion about this at SIG. @obecny is going to copy the functionality from lodash.merge into core for our purposes. In the future though, how do we make sure this isn't going to cause problems? Can we make a test application which compiles against the esm target to ensure it is working properly? |
@dyladan maybe we can add a test harness that doesn't interpret |
@legendecas sounds like a good idea to me. Would you have time to contribute a test like that? |
@dyladan yeah, I can do it. Closing this PR as there is nothing left to be done. |
Which problem is this PR solving?
Short description of the changes
esModuleInterop
flag intsconfig.base.json
.require
usages in esm build.sinon.stub
cannot be used with esmodule namespace objects as fields of namespace objects are readonly. Instead, we should stub on the modules' default exported object, likesinon.useFakeTimers
andsinon.clock
cannot be used with star import anymore assinon.clock
was defined aftersinon.useFakeTimers()
but not statically