From 6780f29624372a76aafb0bbd6975864280239f26 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sun, 17 Oct 2021 01:00:28 +0200 Subject: [PATCH] fix: restore the default export (bis) The previous commit, while successfully restoring support for: ```js const socket = require("socket.io-client")(...); ``` breaks for some other cases: - https://github.com/socketio/socket.io/issues/4128 - https://github.com/socketio/socket.io-client/issues/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 --- lib/index.ts | 4 ---- postcompile.sh | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index cfae547d..958cb623 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -80,10 +80,6 @@ Object.assign(lookup, { connect: lookup, }); -if (typeof module !== "undefined") { - module.exports = lookup; -} - /** * Protocol version. * diff --git a/postcompile.sh b/postcompile.sh index 5c3aa390..e243e869 100755 --- a/postcompile.sh +++ b/postcompile.sh @@ -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