From cbabb0308ef4f7d302654755e08fe2103b9f22c8 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Mon, 12 Oct 2020 14:59:42 +0200 Subject: [PATCH] feat: add ES6 module export - with `{ "type": "commonjs" }` in the package.json file ```js const io = require("socket.io-client"); const socket = io("/"); ``` - with `{ "type": "module" }` ```js import io from "socket.io-client"; const socket = io("/"); // or import { Manager } from "socket.io-client"; const manager = new Manager(); const socket = manager.socket("/"); ``` Related: https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages --- package.json | 10 ++++++++++ wrapper.mjs | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 wrapper.mjs diff --git a/package.json b/package.json index 484e7eebf..289eb9748 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,17 @@ "dist/", "build/" ], + "type": "commonjs", "main": "./build/index.js", + "exports": { + "./package.json": "./package.json", + "./dist/socket.io.js": "./dist/socket.io.js", + "./dist/socket.io.js.map": "./dist/socket.io.js.map", + ".": { + "import": "./wrapper.mjs", + "require": "./build/index.js" + } + }, "types": "./build/index.d.ts", "dependencies": { "backo2": "1.0.2", diff --git a/wrapper.mjs b/wrapper.mjs new file mode 100644 index 000000000..b914d4cdd --- /dev/null +++ b/wrapper.mjs @@ -0,0 +1,4 @@ +import io from "./build/index.js"; + +export const Manager = io.Manager; +export default io;