Skip to content

Commit

Permalink
Change to esm module (#11)
Browse files Browse the repository at this point in the history
* Change to esm module

* Switch to native esm module

* Fix tests
  • Loading branch information
jrmi authored Oct 9, 2021
1 parent 0886395 commit 2c9e42c
Show file tree
Hide file tree
Showing 7 changed files with 6,361 additions and 9,365 deletions.
13 changes: 0 additions & 13 deletions .babelrc

This file was deleted.

15,636 changes: 6,323 additions & 9,313 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
"version": "3.0.0",
"description": "Socket.io wrapper to enable client to client communications like RPC and pub/sub. Inspired by WAMP protocol.",
"main": "lib/index.js",
"type": "module",
"exports": {
".": "./src/index.js",
"./client": "./src/client.js",
"./server": "./src/server.js",
"./package.json": "./package.json"
},
"keywords": [
"socket",
"client",
Expand All @@ -11,32 +18,23 @@
"author": "Jérémie Pardou",
"license": "ISC",
"bin": {
"wire": "lib/cli.es5.js",
"wire.io": "lib/cli.es5.js"
"wire": "src/cli.js",
"wire.io": "src/cli.js"
},
"scripts": {
"clean": "rm ./lib/ -r",
"test": "jest --watch",
"coverage": "jest --coverage",
"build": "babel src --out-dir lib --ignore '**/*.test.js' --ignore '**/app.js'",
"shebang": "echo '#!/usr/bin/env node' > lib/cli.es5.js && cat lib/cli.js >> lib/cli.es5.js",
"prepare": "npm run build && npm run shebang",
"dev": "nodemon src/cli.js --exec babel-node",
"start": "babel-node src/cli.js",
"coverage": "jest --coverage --detectOpenHandles ",
"dev": "nodemon src/cli.js",
"start": "node src/cli.js",
"ci": "start-server-and-test start http-get://localhost:4000 coverage",
"version": "git changelog -n -t $npm_package_version && git add CHANGELOG.md"
},
"dependencies": {
"nanoid": "^3.1.20"
},
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/node": "^7.14.2",
"@babel/preset-env": "^7.14.2",
"babel-jest": "^26.6.3",
"jest": "^26.6.3",
"jest-transform-stub": "^2.0.0",
"jest-esm-transformer": "^1.0.0",
"nodemon": "^2.0.4",
"prettier": "^2.0.5",
"retry-assert": "^1.0.0",
Expand All @@ -51,8 +49,7 @@
},
"jest": {
"transform": {
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",
"^.+\\.[t|j]sx?$": "babel-jest"
".js": "jest-esm-transformer"
}
}
}
2 changes: 1 addition & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import startServer from './startServer';
import startServer from './startServer.js';
import dotenv from 'dotenv';

dotenv.config();
Expand Down
34 changes: 18 additions & 16 deletions src/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,24 @@ describe('Client', () => {
});

afterEach(async () => {
// Cleanup
if (socket1.connected) {
socket1.disconnect();
}
if (socket2.connected) {
socket2.disconnect();
}
if (socket3.connected) {
socket3.disconnect();
}

await retry(
() => !(socket1.connected && socket2.connected && socket3.connected)
)
.withTimeout(3000)
.untilTruthy();
const disco = () => {
// Cleanup
if (socket1 && socket1.connected) {
socket1.disconnect();
return false;
}
if (socket2 && socket2.connected) {
socket2.disconnect();
return false;
}
if (socket3 && socket3.connected) {
socket3.disconnect();
return false;
}
return true;
};

await retry(disco).withTimeout(3000).untilTruthy();
});

it('connect to room', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import handleWire from './server';
import joinWire from './client';
import handleWire from './server.js';
import joinWire from './client.js';

export { handleWire, joinWire };
6 changes: 3 additions & 3 deletions src/startServer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import express from 'express';
import { createServer } from 'http';
import io from 'socket.io';
import { Server } from 'socket.io';
import cors from 'cors';

import { handleWire } from '.';
import { handleWire } from './server.js';

const startServer = ({ socketIOConfig = {}, port = 4000 }) => {
var app = express();
Expand All @@ -19,7 +19,7 @@ const startServer = ({ socketIOConfig = {}, port = 4000 }) => {

app.use(cors(corsOption));

const ioServer = io(http, {
const ioServer = new Server(http, {
...socketIOConfig,
});

Expand Down

0 comments on commit 2c9e42c

Please sign in to comment.