Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM migration #37

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ module.exports = {

'tsdoc/syntax': [ 'warn' ],
'jsdoc/check-alignment': [ 'warn' ],
'jsdoc/check-examples': [ 'warn' ],
'jsdoc/check-param-names': [ 'warn', {
checkDestructured: false
} ],
Expand All @@ -202,7 +201,7 @@ module.exports = {
definedTags: [ 'remarks', 'typeParam' ]
} ],

'import/extensions': [ 'error' ],
'import/extensions': [ 'error', 'ignorePackages' ],
'import/first': [ 'warn' ],
'import/no-self-import': [ 'error' ],

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node: [ 12.x, 14.x, 16.x ]
node: [ 16.x, 18.x ]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

apidocs
node_modules
dist
Expand Down
4 changes: 2 additions & 2 deletions examples/helpers/counter.js → examples/helpers/counter.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { NamedGroup } = require('../../packages/core');
import { NamedGroup } from 'ataraxia';

module.exports = async function(net) {
export async function counter(net) {
let counter = 0;

const group = new NamedGroup(net, 'counter');
Expand Down
17 changes: 8 additions & 9 deletions examples/hyperswarm.js → examples/hyperswarm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
* broadcasts a counter every 5 seconds to all current nodes.
*/

const { Network, AnonymousAuth } = require('../packages/core');
const { HyperswarmTransport } = require('../packages/hyperswarm');
import { Network, AnonymousAuth } from 'ataraxia';
import { HyperswarmTransport } from 'ataraxia-hyperswarm';

import { counter } from './helpers/counter.mjs';

const net = new Network({
name: 'example',
Expand Down Expand Up @@ -39,11 +41,8 @@ net.onMessage(msg => {
});

// Start the network
net.join()
.then(() => {
console.log('Network has been joined with id', net.networkId);
await net.join();
console.log('Network has been joined with id', net.networkId);

// Start our helper
return require('./helpers/counter')(net);
})
.catch(err => console.error(err));
// Start our helper
counter(net);
21 changes: 10 additions & 11 deletions examples/local-tcp.js → examples/local-tcp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
* broadcasts a counter every 5 seconds to all current nodes.
*/

const { Network, AnonymousAuth } = require('../packages/core');
const { MachineLocalTransport } = require('../packages/local');
const { TCPTransport, TCPPeerMDNSDiscovery } = require('../packages/tcp');
import { Network, AnonymousAuth } from 'ataraxia';
import { MachineLocalTransport } from 'ataraxia-local';
import { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';

import { counter } from './helpers/counter.mjs';

const net = new Network({
name: 'example'
Expand Down Expand Up @@ -46,11 +48,8 @@ net.onMessage(msg => {
});

// Start the network
net.join()
.then(() => {
console.log('Network has been joined with id', net.networkId);

// Start our helper
return require('./helpers/counter')(net);
})
.catch(err => console.error(err));
await net.join();
console.log('Network has been joined with id', net.networkId);

// Start our helper
counter(net);
18 changes: 8 additions & 10 deletions examples/local.js → examples/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* In addition to this it sends a hello to nodes when they are seen and
* broadcasts a counter every 5 seconds to all current nodes.
*/
import { Network } from 'ataraxia';
import { MachineLocalTransport } from 'ataraxia-local';

const { Network, AnonymousAuth } = require('../packages/core');
const { MachineLocalTransport } = require('../packages/local');
import { counter } from './helpers/counter.mjs';

const net = new Network({
name: 'example',
Expand All @@ -33,11 +34,8 @@ net.onMessage(msg => {
});

// Start the network
net.join()
.then(() => {
console.log('Network has been joined with id', net.networkId);

// Start our helper
return require('./helpers/counter')(net);
})
.catch(err => console.error(err));
await net.join();
console.log('Network has been joined with id', net.networkId);

// Start our helper
counter(net);
19 changes: 9 additions & 10 deletions examples/tcp.js → examples/tcp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
* broadcasts a counter every 5 seconds to all current nodes.
*/

const { Network, AnonymousAuth } = require('../packages/core');
const { TCPTransport, TCPPeerMDNSDiscovery } = require('../packages/tcp');
import { Network, AnonymousAuth } from 'ataraxia';
import { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';

import { counter } from './helpers/counter.mjs';

const net = new Network({
name: 'example',
Expand Down Expand Up @@ -38,11 +40,8 @@ net.onMessage(msg => {
});

// Start the network
net.join()
.then(() => {
console.log('Network has been joined with id', net.networkId);

// Start our helper
return require('./helpers/counter')(net);
})
.catch(err => console.error(err));
await net.join();
console.log('Network has been joined with id', net.networkId);

// Start our helper
counter(net);
21 changes: 10 additions & 11 deletions examples/ws-client.js → examples/ws-client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* In addition to this it sends a hello to nodes when they are seen and
* broadcasts a counter every 5 seconds to all current nodes.
*/
const WebSocket = require('../packages/ws-server/node_modules/ws');
import WebSocket from 'ws';

const { Network, AnonymousAuth } = require('../packages/core');
const { WebSocketClientTransport } = require('../packages/ws-client');
import { Network, AnonymousAuth } from 'ataraxia';
import { WebSocketClientTransport } from 'ataraxia-ws-client';

import { counter } from './helpers/counter.mjs';

const net = new Network({
name: 'example',
Expand Down Expand Up @@ -42,11 +44,8 @@ net.onMessage(msg => {
});

// Start the network
net.join()
.then(() => {
console.log('Network has been joined with id', net.networkId);

// Start our helper
return require('./helpers/counter')(net);
})
.catch(err => console.error(err));
await net.join();
console.log('Network has been joined with id', net.networkId);

// Start our helper
counter(net);
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* It will log when new nodes are discovered.
*/

const { Network, AnonymousAuth } = require('../packages/core');
const { WebSocketServerTransport } = require('../packages/ws-server');
const { TCPTransport, TCPPeerMDNSDiscovery } = require('../packages/tcp');
import { Network, AnonymousAuth } from 'ataraxia';
import { WebSocketServerTransport } from 'ataraxia-ws-server';
import { TCPTransport, TCPPeerMDNSDiscovery } from 'ataraxia-tcp';

const net = new Network({
name: 'example',
Expand Down Expand Up @@ -44,6 +44,5 @@ net.onNodeUnavailable(node => {
});

// Start the network
net.join()
.then(() => console.log('Network has been joined with id', net.networkId))
.catch(err => console.error(err));
await net.join();
console.log('Network has been joined with id', net.networkId);
20 changes: 10 additions & 10 deletions examples/ws-server.js → examples/ws-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
* broadcasts a counter every 5 seconds to all current nodes.
*/

const { Network, AnonymousAuth } = require('../packages/core');
const { WebSocketServerTransport } = require('../packages/ws-server');
import { Network, AnonymousAuth } from 'ataraxia';
import { WebSocketServerTransport } from 'ataraxia-ws-server';

import { counter } from './helpers/counter.mjs';

const net = new Network({
name: 'example',
Expand Down Expand Up @@ -40,11 +42,9 @@ net.onMessage(msg => {
});

// Start the network
net.join()
.then(() => {
console.log('Network has been joined with id', net.networkId);

// Start our helper
return require('./helpers/counter')(net);
})
.catch(err => console.error(err));
await net.join();
console.log('Network has been joined with id', net.networkId);

// Start our helper
counter(net);

15 changes: 6 additions & 9 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
module.exports = {
transform: {
".(ts|tsx)": "ts-jest"
},
preset: 'ts-jest/presets/default-esm',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.build.json'
tsconfig: '<rootDir>/tsconfig.test.json',
useESM: true
},
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/"
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/jest": "^26.0.23",
"@types/node": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"eslint": "^7.28.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-tsdoc": "^0.2.14",
"jest": "^27.0.3",
"lerna": "^4.0.0",
"ts-jest": "^27.1.2",
"typedoc": "^0.22.10",
"typescript": "^4.5.4"
"@types/jest": "^28.1.6",
"@types/node": "^18.7.2",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"cross-env": "^7.0.3",
"eslint": "^8.21.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-tsdoc": "^0.2.16",
"jest": "^28.1.3",
"lerna": "^5.4.1",
"ts-jest": "^28.0.7",
"typedoc": "^0.23.10",
"typescript": "^4.7.4"
}
}
14 changes: 7 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"mesh networking",
"messaging"
],
"main": "./dist/cjs/index.js",
"type": "module",
"bin": {
"ataraxia": "./dist/cjs/index.js"
"ataraxia": "./dist/esm/index.js"
},
"scripts": {
"build": "tsc --project tsconfig.build.json --module commonjs --target es5 --outDir dist/cjs",
"build": "tsc --project tsconfig.build.json --outDir dist/esm",
"prebuild": "rimraf dist",
"prepublishOnly": "npm run build"
},
Expand All @@ -24,10 +24,10 @@
"ataraxia-hyperswarm": "^0.12.0",
"ataraxia-local": "^0.12.0",
"ataraxia-tcp": "^0.12.0",
"chalk": "^5.0.0",
"minimatch": "^3.0.4",
"prettyjson": "^1.2.1",
"yargs": "^17.3.0"
"chalk": "^5.0.1",
"minimatch": "^5.1.0",
"prettyjson": "^1.2.5",
"yargs": "^17.5.1"
},
"devDependencies": {
"@types/minimatch": "^3.0.5",
Expand Down
Loading