Skip to content

Commit

Permalink
fix: restore the default export (bis)
Browse files Browse the repository at this point in the history
The previous commit, while successfully restoring support for:

```js
const socket = require("socket.io-client")(...);
```

breaks for some other cases:

- socketio/socket.io#4128
- #1509

According to [1], we should use `export = `, but this is not supported
by module "esnext":

> Export assignment cannot be used when targeting ECMAScript modules

So we'll go for this ugly workaround, at least until we remove the
default export in the next major release.

[1]: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
  • Loading branch information
darrachequesne committed Oct 16, 2021
1 parent ca614b2 commit 6780f29
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 0 additions & 4 deletions lib/index.ts
Expand Up @@ -80,10 +80,6 @@ Object.assign(lookup, {
connect: lookup,
});

if (typeof module !== "undefined") {
module.exports = lookup;
}

/**
* Protocol version.
*
Expand Down
3 changes: 3 additions & 0 deletions postcompile.sh
Expand Up @@ -6,3 +6,6 @@ cp ./support/package.esm.json ./build/esm/package.json
cp -r ./build/esm/ ./build/esm-debug/

sed -i '/debug(/d' ./build/esm/*.js

# for backward compatibility with `const socket = require("socket.io-client")(...)`
echo -e '\nmodule.exports = lookup;' >> ./build/cjs/index.js

0 comments on commit 6780f29

Please sign in to comment.