-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Enable esm named exports #2382
Enable esm named exports #2382
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2382 +/- ##
=======================================
Coverage 96.07% 96.07%
=======================================
Files 41 41
Lines 1883 1883
=======================================
Hits 1809 1809
Misses 74 74
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
Hi, Perrin. Thanks for this. As you probably saw in #2361 (comment), I had a go at this and found that, as you say, the best solution would just be to rewrite into ESM. I did have a go, but I found that the stuff I did always broke some kind of use case in some environment, so curious how this checks out. Thanks! |
Honestly I was thinking that even if it's a band-aid, this PR would still require a major version bump just to be on the safe side. |
I was just thinking of these use cases:
Does the second point work with this? Or which envs work and how (i.e. which files need to be imported)? |
1 I haven't tested neither
Node >= 12 behaved as you'd expect |
Related to the discussion in this PR, I added some detail on converting the whole codebase to ESM: #2361 (comment) |
Well, while I can totally get being hesitant about merging this in, this does get the job done for me now, and I am not sure how realistic this esm rewrite really is... |
I think this just stalled on me (and or others) just forgetting about it pre-holiday. Not intentional from my side, in any way. I do not mind merging this (AFAI can remember). |
I'd love to see this merge as this is one of the biggest pain points for me moving to esm modules :) |
Released as Sinon 12! Thanks @perrin4869 <3 |
@perrin4869 Seems this broke webpack bundling for CJS. See #2411. Any quickfix? |
ah dammit ><;; Let me look into this! |
Adds support for esm named exports
Fixes issue #2361
I tried to keep this as backwards compatible as possible, but some minor (undocumented) changes were made which may break people importing from the
pkg
directory directly.Specifically we can't do
require('sinon/pkg/sinon.js')
orrequire('sinon/pkg/sinon-no-sourcemaps.js')
anymore, as these were changed intocjs
files.An additional
pkg/sinon.js
file is produced, identical topkg/sinon.cjs
, to keep the WebWorker functional.importScripts
seems to fail oncjs
files.How to verify
npm ci
npm test
import { stub } from "sinon"
from an esm javascript file on node >= 12 should workEdit: this is more of a band-aid, since the preferred solution would be an esm rewrite and using rollup to produce a cjs and esm build.