-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
update wrapper.mjs so it provides the same default
as for CommonJS users
#4100
Conversation
…with npm works The downside of this is that yarn doesn't follow npm spec, and yarn needs prepack instead of prepare, so install from git with yarn will no longer work. Either npm works, or yarn works. I think it's a better choice to support the standard tool for npmjs.com.
@@ -42,7 +42,7 @@ | |||
"test:unit": "nyc mocha --require ts-node/register --reporter spec --slow 200 --bail --timeout 10000 test/socket.io.ts", | |||
"format:check": "prettier --check \"lib/**/*.ts\" \"test/**/*.ts\"", | |||
"format:fix": "prettier --write \"lib/**/*.ts\" \"test/**/*.ts\"", | |||
"prepack": "npm run compile" | |||
"prepare": "npm run compile" |
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.
use prepare instead of prepack so that installing socket.io from git with npm works
The downside of this is that yarn doesn't follow npm spec, and yarn needs prepack instead of prepare, so install from git with yarn will no longer work. Either npm works, or yarn works. I think it's a better choice to support the standard tool for npmjs.com.
default
as for CommonJS usersdefault
as for CommonJS users
default
as for CommonJS usersdefault
as for CommonJS users
I was wrong above, actually if a user tries to import
So that option is not even on the table, unless they perform an import using a relative path that includes the import io from '../node_modules/socket.io/dist/index.js' But as you know, this is less reliable because the structure inside Another workaround is the user can easily define this function too, though of course it would be better if it existed symmetrically for both CJS or ESM users: import {Server} from 'socket.io'
const io = (srv, opts) => new Server(srv, opts);
export default io This has the downside that if |
Hi! This is deliberate. ESM users should use the named export: import { Server } from "socket.io"; |
The kind of change this PR does introduce
Current behavior
When migrating from CommonJS to ESM, the end user no longer had the default option available unless they
import io from 'socket.io/dist/index.js'
.You can see at the bottom of this file: https://unpkg.com/socket.io@4.2.0/dist/index.js
There is this line:
which is a convenience for CommonJS users, but ESM users don't have this option (unless they import
dist/index.js
)New behavior
Now they can
import io from 'socket.io'
which is similar toconst io = require('socket.io')
as they had when using CommonJS.Other information (e.g. related issues)
n/a