diff --git a/.gitignore b/.gitignore index 44d646d..d872d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules dist/ +build/ diff --git a/lib/binary.ts b/lib/binary.ts index 89956c2..18700e6 100644 --- a/lib/binary.ts +++ b/lib/binary.ts @@ -1,4 +1,4 @@ -import { isBinary } from "./is-binary"; +import { isBinary } from "./is-binary.js"; /** * Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder. diff --git a/lib/index.ts b/lib/index.ts index 636df23..d1ba02a 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,8 +1,9 @@ -import Emitter = require("component-emitter"); -import { deconstructPacket, reconstructPacket } from "./binary"; -import { isBinary, hasBinary } from "./is-binary"; +import Emitter from "@socket.io/component-emitter"; +import { deconstructPacket, reconstructPacket } from "./binary.js"; +import { isBinary, hasBinary } from "./is-binary.js"; +import debugModule from "debug"; // debug() -const debug = require("debug")("socket.io-parser"); +const debug = debugModule("socket.io-parser"); // debug() /** * Protocol version. diff --git a/package-lock.json b/package-lock.json index 1453adf..58368f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -908,10 +908,10 @@ "to-fast-properties": "^2.0.0" } }, - "@types/component-emitter": { - "version": "1.2.10", - "resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.10.tgz", - "integrity": "sha512-bsjleuRKWmGqajMerkzox19aGbscQX5rmmvvXl3wlIp5gMG1HgkiwPxsN5p070fBDKTNSPgojVbuY1+HWMbFhg==" + "@socket.io/component-emitter": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-2.0.0.tgz", + "integrity": "sha512-tfCc1aFpZQtnVXQhZDlwefCmT03U75O/NNd65X37U20r6vfERhwRBcZYANnFt0/GEU/Acb3Z1ZVeK+qbV32VJw==" }, "@types/debug": { "version": "4.1.5", @@ -2079,7 +2079,8 @@ "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", - "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==" + "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==", + "dev": true }, "compress-commons": { "version": "0.2.9", diff --git a/package.json b/package.json index f15f403..223d4e0 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,20 @@ "url": "https://github.com/socketio/socket.io-parser.git" }, "files": [ - "dist/" + "build/" ], - "main": "./dist/index.js", - "types": "./dist/index.d.ts", + "main": "./build/cjs/index.js", + "module": "./build/esm/index.js", + "types": "./build/esm/index.d.ts", + "exports": { + "import": { + "node": "./build/esm-debug/index.js", + "default": "./build/esm/index.js" + }, + "require": "./build/cjs/index.js" + }, "dependencies": { - "@types/component-emitter": "^1.2.10", - "component-emitter": "~1.3.0", + "@socket.io/component-emitter": "~2.0.0", "debug": "~4.3.1" }, "devDependencies": { @@ -33,7 +40,7 @@ "zuul-ngrok": "4.0.0" }, "scripts": { - "compile": "rimraf ./dist && tsc", + "compile": "rimraf ./build && tsc && tsc -p tsconfig.esm.json && ./postcompile.sh", "test": "npm run format:check && npm run compile && if test \"$BROWSERS\" = \"1\" ; then npm run test:browser; else npm run test:node; fi", "test:node": "mocha --reporter dot --bail test/index.js", "test:browser": "zuul test/index.js --no-coverage", diff --git a/postcompile.sh b/postcompile.sh new file mode 100755 index 0000000..5c3aa39 --- /dev/null +++ b/postcompile.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cp ./support/package.cjs.json ./build/cjs/package.json +cp ./support/package.esm.json ./build/esm/package.json + +cp -r ./build/esm/ ./build/esm-debug/ + +sed -i '/debug(/d' ./build/esm/*.js diff --git a/support/package.cjs.json b/support/package.cjs.json new file mode 100644 index 0000000..5bbefff --- /dev/null +++ b/support/package.cjs.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/support/package.esm.json b/support/package.esm.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/support/package.esm.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..2805bb3 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "outDir": "build/esm/", + "target": "es2018", + "module": "esnext", + "moduleResolution": "node", + "declaration": true + }, + "include": [ + "./lib/**/*" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 87d51bf..f033355 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,9 @@ { "compilerOptions": { - "outDir": "./dist", - "allowJs": false, - "target": "es2017", + "outDir": "build/cjs/", + "target": "es2018", // Node.js 10 (https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping) "module": "commonjs", - "declaration": true + "declaration": false }, "include": [ "./lib/**/*"