diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2bb44d14d..78821e50a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -12,11 +12,8 @@ jobs: strategy: fail-fast: false matrix: - # Do not support --experimental-require-module - # Commented until we have a solution to run tests without it # node: [14, 16, 18, 20, 22] - # node: [20, 22] // fails on 20 with (0 , _getDomain.default) is not a function - node: [22] + node: [20, 22] steps: - uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 4d99866cd..a6a5f83f9 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ test: ci: npm install - npx jest + make unit make lint make restart npx lerna run prepublish @@ -27,8 +27,11 @@ ci: make e2e make bundlesize +unit: + npx jest + e2e: - NODE_TLS_REJECT_UNAUTHORIZED=0 npx jest --runInBand --config e2e.config.js + NODE_TLS_REJECT_UNAUTHORIZED=0 npx jest --runInBand --config e2e.config.cjs clean: make stop diff --git a/babel.config.js b/babel.config.cjs similarity index 100% rename from babel.config.js rename to babel.config.cjs diff --git a/bundle.js b/bundle.js index 8fc3e9b90..e0036eb10 100755 --- a/bundle.js +++ b/bundle.js @@ -1,14 +1,14 @@ #!/usr/bin/env node -'use strict' +import fs from "fs" +import path from "path" +import browserify from "browserify" +import commonShake from "common-shakeify" +import packFlat from "browser-pack-flat" +import exorcist from "exorcist" +import { minify } from "uglify-js" -const fs = require('fs') -const path = require('path') -const browserify = require('browserify') -const commonShake = require('common-shakeify') -const packFlat = require('browser-pack-flat') -const exorcist = require('exorcist') -const {minify} = require('uglify-js') +const __dirname = import.meta.dirname; const dist = path.join(__dirname, 'packages/client/dist') diff --git a/e2e.config.js b/e2e.config.cjs similarity index 100% rename from e2e.config.js rename to e2e.config.cjs diff --git a/eslint.config.mjs b/eslint.config.js similarity index 96% rename from eslint.config.mjs rename to eslint.config.js index c277c75a3..dff1ff482 100644 --- a/eslint.config.mjs +++ b/eslint.config.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line n/no-extraneous-import import js from "@eslint/js"; import eslintConfigPrettier from "eslint-config-prettier"; import globals from "globals"; @@ -26,7 +27,7 @@ export default [ jsx: true, }, }, - sourceType: "commonjs", + sourceType: "module", }, rules: { @@ -78,12 +79,13 @@ export default [ "unicorn/prefer-event-target": 0, "unicorn/prefer-top-level-await": 0, "unicorn/prefer-node-protocol": 0, + "unicorn/prefer-export-from": "off", }, }, { - files: ["packages/client/**/*.js"], + files: ["**/*.cjs"], languageOptions: { - sourceType: "module", + sourceType: "commonjs", }, }, { diff --git a/jest.config.js b/jest.config.cjs similarity index 100% rename from jest.config.js rename to jest.config.cjs diff --git a/package-lock.json b/package-lock.json index 9b6fae37e..b5e057ebc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "eslint-plugin-promise": "^7.2.1", "eslint-plugin-unicorn": "^56.0.1", "exorcist": "^2.0.0", + "globals": "^15.14.0", "husky": "^9.1.7", "jest": "^29.7.0", "jest-extended": "^4.0.2", @@ -44,7 +45,7 @@ "uglify-js": "^3.19.3" }, "engines": { - "node": ">= 14", + "node": ">= 14.13.1", "npm": ">= 7" } }, @@ -976,6 +977,15 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-classes/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/plugin-transform-computed-properties": { "version": "7.25.9", "dev": true, @@ -1818,6 +1828,14 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/traverse/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/types": { "version": "7.26.3", "license": "MIT", @@ -3651,7 +3669,7 @@ "dev": true, "license": "MIT", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/@octokit/core": { @@ -3668,7 +3686,7 @@ "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/@octokit/endpoint": { @@ -3681,7 +3699,7 @@ "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/@octokit/graphql": { @@ -3694,7 +3712,7 @@ "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/@octokit/openapi-types": { @@ -3716,7 +3734,7 @@ "@octokit/types": "^9.2.3" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "peerDependencies": { "@octokit/core": ">=4" @@ -3738,7 +3756,7 @@ "@octokit/types": "^10.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "peerDependencies": { "@octokit/core": ">=3" @@ -3765,7 +3783,7 @@ "universal-user-agent": "^6.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/@octokit/request-error": { @@ -3778,7 +3796,7 @@ "once": "^1.4.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/@octokit/rest": { @@ -3792,7 +3810,7 @@ "@octokit/plugin-rest-endpoint-methods": "^7.1.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/@octokit/tsconfig": { @@ -4443,7 +4461,7 @@ "dev": true, "license": "MIT", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/aggregate-error": { @@ -7306,17 +7324,6 @@ "balanced-match": "^1.0.0" } }, - "node_modules/eslint-plugin-n/node_modules/globals": { - "version": "15.13.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/eslint-plugin-n/node_modules/minimatch": { "version": "9.0.5", "dev": true, @@ -7424,17 +7431,6 @@ "node": ">=8" } }, - "node_modules/eslint-plugin-unicorn/node_modules/globals": { - "version": "15.13.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/eslint-plugin-unicorn/node_modules/semver": { "version": "7.6.3", "dev": true, @@ -8520,10 +8516,15 @@ } }, "node_modules/globals": { - "version": "11.12.0", - "license": "MIT", + "version": "15.14.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.14.0.tgz", + "integrity": "sha512-OkToC372DtlQeje9/zHIo5CT8lRP/FUgEOKBEhU4e0abL7J7CD24fD9ohiLN5hagG/kWCYj4K5oaxxtj2Z0Dig==", + "dev": true, "engines": { - "node": ">=4" + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/globby": { @@ -8809,7 +8810,7 @@ "debug": "^4.3.4" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/https-browserify": { @@ -8826,7 +8827,7 @@ "debug": "4" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/human-signals": { @@ -14692,7 +14693,7 @@ "socks": "^2.8.3" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/sort-keys": { @@ -16118,7 +16119,7 @@ "yaml": "bin.mjs" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "node_modules/yargs": { @@ -16165,7 +16166,7 @@ "base-64": "^1.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/client": { @@ -16197,7 +16198,7 @@ "babel-plugin-jsx-pragmatic": "^1.0.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/client-core": { @@ -16210,7 +16211,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/component": { @@ -16224,7 +16225,7 @@ "@xmpp/reconnect": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/component-core": { @@ -16237,7 +16238,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/connection": { @@ -16251,7 +16252,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/connection-tcp": { @@ -16263,7 +16264,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/debug": { @@ -16275,7 +16276,7 @@ "ltx": "^3.1.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/error": { @@ -16283,7 +16284,7 @@ "version": "0.13.2", "license": "ISC", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/events": { @@ -16294,7 +16295,7 @@ "events": "^3.3.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/id": { @@ -16302,7 +16303,7 @@ "version": "0.13.2", "license": "ISC", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/iq": { @@ -16315,11 +16316,8 @@ "@xmpp/middleware": "^0.13.2", "@xmpp/xml": "^0.13.2" }, - "devDependencies": { - "@xmpp/middleware": "^0.13.1" - }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/jid": { @@ -16327,7 +16325,7 @@ "version": "0.13.2", "license": "ISC", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/middleware": { @@ -16341,7 +16339,7 @@ "koa-compose": "^4.1.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/reconnect": { @@ -16352,7 +16350,7 @@ "@xmpp/events": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/resolve": { @@ -16365,7 +16363,7 @@ "node-fetch": "^2.6.12" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/resource-binding": { @@ -16376,7 +16374,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/sasl": { @@ -16390,7 +16388,7 @@ "saslmechanisms": "^0.1.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/sasl-anonymous": { @@ -16401,7 +16399,7 @@ "sasl-anonymous": "^0.1.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/sasl-plain": { @@ -16412,7 +16410,7 @@ "sasl-plain": "^0.1.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/sasl-scram-sha-1": { @@ -16423,7 +16421,7 @@ "sasl-scram-sha-1": "^1.3.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/session-establishment": { @@ -16434,7 +16432,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/starttls": { @@ -16447,7 +16445,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/stream-features": { @@ -16455,7 +16453,7 @@ "version": "0.13.2", "license": "ISC", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/stream-management": { @@ -16466,7 +16464,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/tcp": { @@ -16477,7 +16475,7 @@ "@xmpp/connection-tcp": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/test": { @@ -16486,6 +16484,7 @@ "license": "ISC", "dependencies": { "@xmpp/client": "^0.13.2", + "@xmpp/client-core": "^0.13.2", "@xmpp/connection": "^0.13.2", "@xmpp/debug": "^0.13.2", "@xmpp/events": "^0.13.2", @@ -16494,7 +16493,7 @@ "ltx": "^3.1.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/time": { @@ -16502,7 +16501,7 @@ "version": "0.13.2", "license": "ISC", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/tls": { @@ -16514,7 +16513,7 @@ "@xmpp/connection-tcp": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/uri": { @@ -16526,7 +16525,7 @@ "iri": "^1.3.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/websocket": { @@ -16535,11 +16534,12 @@ "license": "ISC", "dependencies": { "@xmpp/connection": "^0.13.2", + "@xmpp/events": "^0.13.2", "@xmpp/xml": "^0.13.2", "ws": "^8.18.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/xml": { @@ -16550,7 +16550,7 @@ "ltx": "^3.1.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } }, "packages/xmpp.js": { @@ -16591,7 +16591,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" } } } diff --git a/package.json b/package.json index 27c5a31b9..b60f443a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "type": "commonjs", + "type": "module", "devDependencies": { "@babel/core": "^7.26.0", "@babel/plugin-proposal-object-rest-spread": "^7.16.5", @@ -26,6 +26,7 @@ "eslint-plugin-promise": "^7.2.1", "eslint-plugin-unicorn": "^56.0.1", "exorcist": "^2.0.0", + "globals": "^15.14.0", "husky": "^9.1.7", "jest": "^29.7.0", "jest-extended": "^4.0.2", @@ -38,12 +39,10 @@ "uglify-js": "^3.19.3" }, "scripts": { - "test": "jest", - "lint": "eslint --cache .", "preversion": "make bundle" }, "engines": { - "node": ">= 14", + "node": ">= 14.13.1", "npm": ">= 7" }, "workspaces": [ @@ -52,7 +51,7 @@ "bundlesize": [ { "path": "./packages/client/dist/xmpp.min.js", - "maxSize": "16 KB" + "maxSize": "17 KB" } ], "lint-staged": { diff --git a/packages/base64/browser.js b/packages/base64/browser.js index 608ea935d..94930d26f 100644 --- a/packages/base64/browser.js +++ b/packages/base64/browser.js @@ -1,10 +1,9 @@ /* eslint-disable n/no-unsupported-features/node-builtins */ -"use strict"; -module.exports.encode = function encode(string) { +export function encode(string) { return globalThis.btoa(string); -}; +} -module.exports.decode = function decode(string) { +export function decode(string) { return globalThis.atob(string); -}; +} diff --git a/packages/base64/index.js b/packages/base64/index.js index 5f4e26819..790645809 100644 --- a/packages/base64/index.js +++ b/packages/base64/index.js @@ -1,6 +1,3 @@ -"use strict"; +import { encode, decode } from "base-64"; -const { encode, decode } = require("base-64"); - -module.exports.encode = encode; -module.exports.decode = decode; +export { encode, decode }; diff --git a/packages/base64/package.json b/packages/base64/package.json index 228094b60..bde248d5d 100644 --- a/packages/base64/package.json +++ b/packages/base64/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "base64" @@ -17,7 +17,7 @@ "react-native": "index.js", "browser": "browser.js", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/client-core/index.js b/packages/client-core/index.js index 645b65f59..487b86b80 100644 --- a/packages/client-core/index.js +++ b/packages/client-core/index.js @@ -1,9 +1,5 @@ -"use strict"; +import Client from "./lib/Client.js"; +import xml from "@xmpp/xml"; +import jid from "@xmpp/jid"; -const Client = require("./lib/Client"); -const xml = require("@xmpp/xml"); -const jid = require("@xmpp/jid"); - -module.exports.Client = Client; -module.exports.xml = xml; -module.exports.jid = jid; +export { Client, xml, jid }; diff --git a/packages/client-core/lib/Client.js b/packages/client-core/lib/Client.js index dc56ca506..11c86c6db 100644 --- a/packages/client-core/lib/Client.js +++ b/packages/client-core/lib/Client.js @@ -1,6 +1,4 @@ -"use strict"; - -const Connection = require("@xmpp/connection"); +import Connection from "@xmpp/connection"; class Client extends Connection { constructor(options) { @@ -63,4 +61,4 @@ class Client extends Connection { Client.prototype.NS = "jabber:client"; -module.exports = Client; +export default Client; diff --git a/packages/client-core/package.json b/packages/client-core/package.json index 203a496a9..1fb799849 100644 --- a/packages/client-core/package.json +++ b/packages/client-core/package.json @@ -5,14 +5,14 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "dependencies": { "@xmpp/connection": "^0.13.2", "@xmpp/jid": "^0.13.2", "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/client-core/test/Client.js b/packages/client-core/test/Client.js index b15f0057a..728da9e02 100644 --- a/packages/client-core/test/Client.js +++ b/packages/client-core/test/Client.js @@ -1,6 +1,4 @@ -"use strict"; - -const Client = require("../lib/Client"); +import Client from "../lib/Client.js"; test("_findTransport", () => { class Transport { diff --git a/packages/client/README.md b/packages/client/README.md index 04d729fd2..f0d62f0d6 100644 --- a/packages/client/README.md +++ b/packages/client/README.md @@ -13,7 +13,7 @@ It supports Node.js, browsers and React Native. See [below](#transports) for dif ## Setup ```js -const { client, xml, jid } = require("@xmpp/client"); +import { client, xml, jid } from "@xmpp/client"; ``` or @@ -34,8 +34,8 @@ const { client, xml, jid } = window.XMPP; ## Example ```js -const { client, xml } = require("@xmpp/client"); -const debug = require("@xmpp/debug"); +import { client, xml } from "@xmpp/client"; +import debug from "@xmpp/debug"; const xmpp = client({ service: "ws://localhost:5280/xmpp-websocket", @@ -260,9 +260,9 @@ XMPP supports multiple transports, this table list `@xmpp/client` supported and | transport | protocols | Node.js | Browser | React Native | | :------------------------------: | :--------: | :-----: | :-----: | :----------: | -| [WebSocket](/packages/websocket) | `ws(s)://` | ✔ | ✔ | ✔ | -| [TCP](/packages/tcp) | `xmpp://` | ✔ | ✗ | ✗ | -| [TLS](/packages/tls) | `xmpps://` | ✔ | ✗ | ✗ | +| [WebSocket](/packages/websocket) | `ws(s)://` | ✔ | ✔ | ✔ | +| [TCP](/packages/tcp) | `xmpp://` | ✔ | ✗ | ✗ | +| [TLS](/packages/tls) | `xmpps://` | ✔ | ✗ | ✗ | ## Authentication @@ -271,9 +271,9 @@ PLAIN should only be used over secure WebSocket (`wss://)`, direct TLS (`xmpps:` | SASL | Node.js | Browser | React Native | | :---------------------------------------: | :-----: | :-----: | :----------: | -| [ANONYMOUS](/packages/sasl-anonymous) | ✔ | ✔ | ✔ | -| [PLAIN](/packages/sasl-plain) | ✔ | ✔ | ✔ | -| [SCRAM-SHA-1](/packages/sasl-scram-sha-1) | ✔ | ☐ | ✗ | +| [ANONYMOUS](/packages/sasl-anonymous) | ✔ | ✔ | ✔ | +| [PLAIN](/packages/sasl-plain) | ✔ | ✔ | ✔ | +| [SCRAM-SHA-1](/packages/sasl-scram-sha-1) | ✔ | ☐ | ✗ | - ☐ : Optional - ✗ : Unavailable diff --git a/packages/client/browser.js b/packages/client/browser.js index e4c7f84b9..3812fb455 100644 --- a/packages/client/browser.js +++ b/packages/client/browser.js @@ -9,13 +9,11 @@ import _iqCaller from "@xmpp/iq/caller.js"; import _iqCallee from "@xmpp/iq/callee.js"; import _resolve from "@xmpp/resolve"; -// Stream features - order matters and define priority import _sasl from "@xmpp/sasl"; import _resourceBinding from "@xmpp/resource-binding"; import _sessionEstablishment from "@xmpp/session-establishment"; import _streamManagement from "@xmpp/stream-management"; -// SASL mechanisms - order matters and define priority import plain from "@xmpp/sasl-plain"; import anonymous from "@xmpp/sasl-anonymous"; @@ -74,5 +72,4 @@ function client(options = {}) { }); } -// eslint-disable-next-line unicorn/prefer-export-from export { xml, jid, client }; diff --git a/packages/client/index.js b/packages/client/index.js index cd342425c..e944db401 100644 --- a/packages/client/index.js +++ b/packages/client/index.js @@ -11,14 +11,12 @@ import _iqCaller from "@xmpp/iq/caller.js"; import _iqCallee from "@xmpp/iq/callee.js"; import _resolve from "@xmpp/resolve"; -// Stream features - order matters and define priority import _starttls from "@xmpp/starttls/client.js"; import _sasl from "@xmpp/sasl"; import _resourceBinding from "@xmpp/resource-binding"; import _sessionEstablishment from "@xmpp/session-establishment"; import _streamManagement from "@xmpp/stream-management"; -// SASL mechanisms - order matters and define priority import scramsha1 from "@xmpp/sasl-scram-sha-1"; import plain from "@xmpp/sasl-plain"; import anonymous from "@xmpp/sasl-anonymous"; @@ -86,5 +84,4 @@ function client(options = {}) { }); } -// eslint-disable-next-line unicorn/prefer-export-from export { xml, jid, client }; diff --git a/packages/client/package.json b/packages/client/package.json index 3539c03fc..69f1f6177 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -33,7 +33,7 @@ "browser": "./browser.js", "react-native": "./react-native.js", "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/client/react-native.js b/packages/client/react-native.js index e4c7f84b9..3812fb455 100644 --- a/packages/client/react-native.js +++ b/packages/client/react-native.js @@ -9,13 +9,11 @@ import _iqCaller from "@xmpp/iq/caller.js"; import _iqCallee from "@xmpp/iq/callee.js"; import _resolve from "@xmpp/resolve"; -// Stream features - order matters and define priority import _sasl from "@xmpp/sasl"; import _resourceBinding from "@xmpp/resource-binding"; import _sessionEstablishment from "@xmpp/session-establishment"; import _streamManagement from "@xmpp/stream-management"; -// SASL mechanisms - order matters and define priority import plain from "@xmpp/sasl-plain"; import anonymous from "@xmpp/sasl-anonymous"; @@ -74,5 +72,4 @@ function client(options = {}) { }); } -// eslint-disable-next-line unicorn/prefer-export-from export { xml, jid, client }; diff --git a/packages/component-core/index.js b/packages/component-core/index.js index 49a433148..d95b7722a 100644 --- a/packages/component-core/index.js +++ b/packages/component-core/index.js @@ -1,9 +1,5 @@ -"use strict"; +import Component from "./lib/Component.js"; +import xml from "@xmpp/xml"; +import jid from "@xmpp/jid"; -const Component = require("./lib/Component"); -const xml = require("@xmpp/xml"); -const jid = require("@xmpp/jid"); - -module.exports.Component = Component; -module.exports.xml = xml; -module.exports.jid = jid; +export { Component, xml, jid }; diff --git a/packages/component-core/lib/Component.js b/packages/component-core/lib/Component.js index c129fee0c..6f3cd284d 100644 --- a/packages/component-core/lib/Component.js +++ b/packages/component-core/lib/Component.js @@ -1,8 +1,6 @@ -"use strict"; - -const Connection = require("@xmpp/connection-tcp"); -const { createHash } = require("crypto"); -const xml = require("@xmpp/xml"); +import Connection from "@xmpp/connection-tcp"; +import { createHash } from "crypto"; +import xml from "@xmpp/xml"; /* * References @@ -46,4 +44,4 @@ class Component extends Connection { Component.NS = NS; Component.prototype.NS = NS; -module.exports = Component; +export default Component; diff --git a/packages/component-core/package.json b/packages/component-core/package.json index b2105b20b..d6c459c38 100644 --- a/packages/component-core/package.json +++ b/packages/component-core/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "component", @@ -18,7 +18,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/component-core/test/send.js b/packages/component-core/test/send.js index f36866de2..8bdb7fa8d 100644 --- a/packages/component-core/test/send.js +++ b/packages/component-core/test/send.js @@ -1,6 +1,4 @@ -"use strict"; - -const { Component, xml } = require(".."); +import { Component, xml } from "../index.js"; test("from attribute", () => { const entity = new Component(); diff --git a/packages/component/README.md b/packages/component/README.md index 654bb27ce..5c18dd33b 100644 --- a/packages/component/README.md +++ b/packages/component/README.md @@ -15,8 +15,8 @@ See [XEP-0114: Jabber Component Protocol](https://xmpp.org/extensions/xep-0114.h ## Example ```js -const { component, xml, jid } = require("@xmpp/component"); -const debug = require("@xmpp/debug"); +import { component, xml, jid } from "@xmpp/component"; +import debug from "@xmpp/debug"; const xmpp = component({ service: "xmpp://localhost:5347", diff --git a/packages/component/example.js b/packages/component/example.js index 96b98082e..d29293c7f 100644 --- a/packages/component/example.js +++ b/packages/component/example.js @@ -1,9 +1,6 @@ -/* eslint-disable n/no-extraneous-require */ - -"use strict"; - -const { component, xml } = require("@xmpp/component"); -const debug = require("@xmpp/debug"); +import { component, xml } from "@xmpp/component"; +// eslint-disable-next-line n/no-extraneous-import +import debug from "@xmpp/debug"; const xmpp = component({ service: "xmpp://localhost:5347", diff --git a/packages/component/index.js b/packages/component/index.js index 51528423d..8e3935b08 100644 --- a/packages/component/index.js +++ b/packages/component/index.js @@ -1,11 +1,9 @@ -"use strict"; +import { Component, xml, jid } from "@xmpp/component-core"; -const { Component, xml, jid } = require("@xmpp/component-core"); - -const _reconnect = require("@xmpp/reconnect"); -const _middleware = require("@xmpp/middleware"); -const _iqCaller = require("@xmpp/iq/caller"); -const _iqCallee = require("@xmpp/iq/callee"); +import _reconnect from "@xmpp/reconnect"; +import _middleware from "@xmpp/middleware"; +import _iqCaller from "@xmpp/iq/caller.js"; +import _iqCallee from "@xmpp/iq/callee.js"; function component(options) { const { password, service, domain } = options; @@ -37,6 +35,4 @@ function component(options) { }); } -module.exports.xml = xml; -module.exports.jid = jid; -module.exports.component = component; +export { xml, jid, component }; diff --git a/packages/component/package.json b/packages/component/package.json index a1e63f475..77f90f9fc 100644 --- a/packages/component/package.json +++ b/packages/component/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "component" @@ -18,7 +18,7 @@ "@xmpp/reconnect": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/connection-tcp/index.js b/packages/connection-tcp/index.js index c4aa753c9..398a0188c 100644 --- a/packages/connection-tcp/index.js +++ b/packages/connection-tcp/index.js @@ -1,9 +1,7 @@ -"use strict"; - -const { Socket } = require("net"); -const Connection = require("@xmpp/connection"); -const { Parser } = require("@xmpp/xml"); -const { parseURI } = require("@xmpp/connection/lib/util"); +import { Socket } from "net"; +import Connection from "@xmpp/connection"; +import { Parser } from "@xmpp/xml"; +import { parseURI } from "@xmpp/connection/lib/util.js"; const NS_STREAM = "http://etherx.jabber.org/streams"; @@ -57,4 +55,4 @@ ConnectionTCP.prototype.NS = NS_STREAM; ConnectionTCP.prototype.Socket = Socket; ConnectionTCP.prototype.Parser = Parser; -module.exports = ConnectionTCP; +export default ConnectionTCP; diff --git a/packages/connection-tcp/package.json b/packages/connection-tcp/package.json index 11881687b..8e6c9b0a6 100644 --- a/packages/connection-tcp/package.json +++ b/packages/connection-tcp/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "connection", @@ -17,7 +17,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/connection-tcp/test/Connection.js b/packages/connection-tcp/test/Connection.js index ecc0679a9..fc95f0fe5 100644 --- a/packages/connection-tcp/test/Connection.js +++ b/packages/connection-tcp/test/Connection.js @@ -1,9 +1,8 @@ -"use strict"; +import _Connection from "@xmpp/connection"; +import Connection from "../index.js"; -const _Connection = require("../../../packages/connection"); -const Connection = require(".."); -const net = require("net"); -const xml = require("@xmpp/xml"); +import net from "net"; +import xml from "@xmpp/xml"; const NS_STREAM = "http://etherx.jabber.org/streams"; @@ -26,7 +25,7 @@ test("header()", () => { const conn = new Connection(); conn.NS = "foobar"; expect(conn.header(conn.headerElement())).toBe( - `` + ``, ); }); @@ -46,7 +45,9 @@ test("socketParameters()", () => { host: "foo", }); - expect(Connection.prototype.socketParameters("xmpps://foo:1234")).toEqual(undefined); + expect(Connection.prototype.socketParameters("xmpps://foo:1234")).toEqual( + undefined, + ); }); test("sendMany", async () => { diff --git a/packages/connection/index.js b/packages/connection/index.js index 1773ee656..5ab1a7146 100644 --- a/packages/connection/index.js +++ b/packages/connection/index.js @@ -1,10 +1,8 @@ -"use strict"; - -const { EventEmitter, promise } = require("@xmpp/events"); -const jid = require("@xmpp/jid"); -const xml = require("@xmpp/xml"); -const StreamError = require("./lib/StreamError"); -const { parseHost, parseService } = require("./lib/util"); +import { EventEmitter, promise } from "@xmpp/events"; +import jid from "@xmpp/jid"; +import xml from "@xmpp/xml"; +import StreamError from "./lib/StreamError.js"; +import { parseHost, parseService } from "./lib/util.js"; const NS_STREAM = "urn:ietf:params:xml:ns:xmpp-streams"; const NS_JABBER_STREAM = "http://etherx.jabber.org/streams"; @@ -375,9 +373,9 @@ class Connection extends EventEmitter { socketParameters() {} } -// Overrirde +// Override Connection.prototype.NS = ""; Connection.prototype.Socket = null; Connection.prototype.Parser = null; -module.exports = Connection; +export default Connection; diff --git a/packages/connection/lib/StreamError.js b/packages/connection/lib/StreamError.js index 8a07ee4f0..b591c3770 100644 --- a/packages/connection/lib/StreamError.js +++ b/packages/connection/lib/StreamError.js @@ -1,6 +1,4 @@ -"use strict"; - -const XMPPError = require("@xmpp/error"); +import XMPPError from "@xmpp/error"; // https://xmpp.org/rfcs/rfc6120.html#streams-error @@ -11,4 +9,4 @@ class StreamError extends XMPPError { } } -module.exports = StreamError; +export default StreamError; diff --git a/packages/connection/lib/util.js b/packages/connection/lib/util.js index 212375728..47a791861 100644 --- a/packages/connection/lib/util.js +++ b/packages/connection/lib/util.js @@ -1,5 +1,3 @@ -"use strict"; - function parseURI(URI) { let { port, hostname, protocol } = new URL(URI); // https://github.com/nodejs/node/issues/12410#issuecomment-294138912 @@ -19,4 +17,4 @@ function parseService(service) { return service.includes("://") ? parseURI(service) : parseHost(service); } -Object.assign(module.exports, { parseURI, parseHost, parseService }); +export { parseURI, parseHost, parseService }; diff --git a/packages/connection/package.json b/packages/connection/package.json index cf42e6b0a..31732cdfe 100644 --- a/packages/connection/package.json +++ b/packages/connection/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "connection" @@ -18,7 +18,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/connection/test/close.js b/packages/connection/test/close.js index a9734974a..34441a757 100644 --- a/packages/connection/test/close.js +++ b/packages/connection/test/close.js @@ -1,13 +1,6 @@ -"use strict"; - -const Connection = require(".."); -const { - EventEmitter, - promise, - timeout, - TimeoutError, -} = require("@xmpp/events"); -const xml = require("@xmpp/xml"); +import Connection from "../index.js"; +import { EventEmitter, promise, timeout, TimeoutError } from "@xmpp/events"; +import xml from "@xmpp/xml"; test("resets properties on socket close event", () => { const conn = new Connection(); diff --git a/packages/connection/test/connect.js b/packages/connection/test/connect.js index 5eff449d7..76db2f538 100644 --- a/packages/connection/test/connect.js +++ b/packages/connection/test/connect.js @@ -1,7 +1,5 @@ -"use strict"; - -const Connection = require(".."); -const { EventEmitter, promise } = require("@xmpp/events"); +import Connection from "../index.js"; +import { EventEmitter, promise } from "@xmpp/events"; function socket(fn) { return class Socket extends EventEmitter { diff --git a/packages/connection/test/disconnect.js b/packages/connection/test/disconnect.js index 0052af292..d51885bd1 100644 --- a/packages/connection/test/disconnect.js +++ b/packages/connection/test/disconnect.js @@ -1,7 +1,5 @@ -"use strict"; - -const Connection = require(".."); -const { EventEmitter } = require("@xmpp/events"); +import Connection from "../index.js"; +import { EventEmitter } from "@xmpp/events"; test("rejects with TimeoutError if socket doesn't close", (done) => { expect.assertions(2); diff --git a/packages/connection/test/end.js b/packages/connection/test/end.js index 972bdf654..1feececae 100644 --- a/packages/connection/test/end.js +++ b/packages/connection/test/end.js @@ -1,6 +1,4 @@ -"use strict"; - -const Connection = require(".."); +import Connection from "../index.js"; test("#_end", async () => { const conn = new Connection(); diff --git a/packages/connection/test/error.js b/packages/connection/test/error.js index 4359c2711..8aafee03e 100644 --- a/packages/connection/test/error.js +++ b/packages/connection/test/error.js @@ -1,7 +1,5 @@ -"use strict"; - -const Connection = require(".."); -const { EventEmitter } = require("@xmpp/events"); +import Connection from "../index.js"; +import { EventEmitter } from "@xmpp/events"; test("emit error on socket error", () => { const conn = new Connection(); diff --git a/packages/connection/test/onData.js b/packages/connection/test/onData.js index d73c4c518..58a1f9ef5 100644 --- a/packages/connection/test/onData.js +++ b/packages/connection/test/onData.js @@ -1,6 +1,4 @@ -"use strict"; - -const Connection = require(".."); +import Connection from "../index.js"; test("#_onData", () => { expect.assertions(2); diff --git a/packages/connection/test/onElement.js b/packages/connection/test/onElement.js index 46bcdfa55..c6e558a3e 100644 --- a/packages/connection/test/onElement.js +++ b/packages/connection/test/onElement.js @@ -1,9 +1,7 @@ -"use strict"; +import Connection from "../index.js"; +import xml from "@xmpp/xml"; -const Connection = require(".."); -const xml = require("@xmpp/xml"); - -test("#_onElement", done => { +test("#_onElement", (done) => { expect.assertions(2); const foo = ; const conn = new Connection(); @@ -17,7 +15,7 @@ test("#_onElement", done => { conn._onElement(foo); }); -test("#_onElement stream:error", done => { +test("#_onElement stream:error", (done) => { expect.assertions(7); // prettier-ignore diff --git a/packages/connection/test/parserError.js b/packages/connection/test/parserError.js index 2e9520983..ec851b777 100644 --- a/packages/connection/test/parserError.js +++ b/packages/connection/test/parserError.js @@ -1,7 +1,5 @@ -"use strict"; - -const Connection = require(".."); -const { EventEmitter } = require("@xmpp/events"); +import Connection from "../index.js"; +import { EventEmitter } from "@xmpp/events"; test("calls _detachParser, sends a bad-format stream error and emit an error", async () => { expect.assertions(4); diff --git a/packages/connection/test/send.js b/packages/connection/test/send.js index 3bb106b4f..8eaacd1eb 100644 --- a/packages/connection/test/send.js +++ b/packages/connection/test/send.js @@ -1,7 +1,5 @@ -"use strict"; - -const xml = require("@xmpp/xml"); -const Connection = require(".."); +import Connection from "../index.js"; +import xml from "@xmpp/xml"; test("send", () => { expect.assertions(3); diff --git a/packages/connection/test/socketClose.js b/packages/connection/test/socketClose.js index 72f45d42c..3ff56c1a9 100644 --- a/packages/connection/test/socketClose.js +++ b/packages/connection/test/socketClose.js @@ -1,7 +1,5 @@ -"use strict"; - -const Connection = require(".."); -const { EventEmitter } = require("@xmpp/events"); +import Connection from "../index.js"; +import { EventEmitter } from "@xmpp/events"; test("calls _reset and _status", () => { expect.assertions(3); diff --git a/packages/connection/test/start.js b/packages/connection/test/start.js index 173934fe0..5744871d3 100644 --- a/packages/connection/test/start.js +++ b/packages/connection/test/start.js @@ -1,6 +1,4 @@ -"use strict"; - -const Connection = require(".."); +import Connection from "../index.js"; test("rejects if connection is not offline", () => { const conn = new Connection(); diff --git a/packages/connection/test/stop.js b/packages/connection/test/stop.js index e4990b968..5057068bc 100644 --- a/packages/connection/test/stop.js +++ b/packages/connection/test/stop.js @@ -1,6 +1,4 @@ -"use strict"; - -const Connection = require(".."); +import Connection from "../index.js"; test("resolves if socket property is undefined", async () => { const conn = new Connection(); diff --git a/packages/connection/test/streamError.js b/packages/connection/test/streamError.js index b88c0b4eb..79d8967a4 100644 --- a/packages/connection/test/streamError.js +++ b/packages/connection/test/streamError.js @@ -1,7 +1,5 @@ -"use strict"; - -const Connection = require(".."); -const xml = require("@xmpp/xml"); +import Connection from "../index.js"; +import xml from "@xmpp/xml"; test("#_streamError", async () => { const conn = new Connection(); diff --git a/packages/connection/test/test.js b/packages/connection/test/test.js index 35f9fac3d..2e9c9744f 100644 --- a/packages/connection/test/test.js +++ b/packages/connection/test/test.js @@ -1,8 +1,6 @@ -"use strict"; - -const Connection = require(".."); -const { EventEmitter } = require("@xmpp/events"); -const xml = require("@xmpp/xml"); +import Connection from "../index.js"; +import { EventEmitter } from "@xmpp/events"; +import xml from "@xmpp/xml"; test("new Connection()", () => { const conn = new Connection(); diff --git a/packages/debug/README.md b/packages/debug/README.md index 5184717b5..a4070b685 100644 --- a/packages/debug/README.md +++ b/packages/debug/README.md @@ -11,13 +11,14 @@ Sensitive information (authentication) is replaced with ` { console.debug(`IN\n${format(data)}`); @@ -53,6 +51,4 @@ module.exports = function debug(entity, force) { console.debug("status", status, value ? value.toString() : ""); }); } -}; - -module.exports.hideSensitive = hideSensitive; +} diff --git a/packages/debug/package.json b/packages/debug/package.json index ac4006974..af50a9781 100644 --- a/packages/debug/package.json +++ b/packages/debug/package.json @@ -6,13 +6,13 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "debug" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "dependencies": { "@xmpp/xml": "^0.13.2", diff --git a/packages/debug/test.js b/packages/debug/test.js index 342fc312c..454532059 100644 --- a/packages/debug/test.js +++ b/packages/debug/test.js @@ -1,33 +1,51 @@ -"use strict"; - -const { hideSensitive } = require("."); +import { hideSensitive } from "./index.js"; test("SASL", () => { - expect(hideSensitive(foo)).toEqual( - - ); + expect( + hideSensitive(foo), + ).toEqual( + + + , + ); - expect(hideSensitive( - foo, - )).toEqual( - - ); + expect( + hideSensitive( + foo, + ), + ).toEqual( + + + , + ); - expect(hideSensitive( - foo, - )).toEqual( - - ); + expect( + hideSensitive( + foo, + ), + ).toEqual( + + + , + ); - expect(hideSensitive( - foo, - )).toEqual( - - ); + expect( + hideSensitive( + foo, + ), + ).toEqual( + + + , + ); }); test("component handshake", () => { - expect(hideSensitive(foo)).toEqual( - - ); + expect( + hideSensitive(foo), + ).toEqual( + + + , + ); }); diff --git a/packages/error/README.md b/packages/error/README.md index 697b22c94..55cedbcee 100644 --- a/packages/error/README.md +++ b/packages/error/README.md @@ -9,7 +9,7 @@ XMPP error abstraction for JavaScript. ## Usage ```js -const XMPPError = require("@xmpp/error"); +import XMPPError from "@xmpp/error"; const error = new XMPPError("service-unavailable", "optional text", element); error instanceof Error; // true diff --git a/packages/error/index.js b/packages/error/index.js index e5a7144dc..10936b058 100644 --- a/packages/error/index.js +++ b/packages/error/index.js @@ -1,5 +1,3 @@ -"use strict"; - // https://xmpp.org/rfcs/rfc6120.html#rfc.section.4.9.2 class XMPPError extends Error { @@ -36,4 +34,4 @@ class XMPPError extends Error { } } -module.exports = XMPPError; +export default XMPPError; diff --git a/packages/error/package.json b/packages/error/package.json index fa22d787c..156305cc8 100644 --- a/packages/error/package.json +++ b/packages/error/package.json @@ -6,13 +6,13 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "xmpp", "error" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/error/test.js b/packages/error/test.js index 2aa0cb9ac..da3b38673 100644 --- a/packages/error/test.js +++ b/packages/error/test.js @@ -1,8 +1,6 @@ -"use strict"; - -const XMPPError = require("."); -// eslint-disable-next-line n/no-extraneous-require -const parse = require("@xmpp/xml/lib/parse.js"); +import XMPPError from "./index.js"; +// eslint-disable-next-line n/no-extraneous-import +import parse from "@xmpp/xml/lib/parse.js"; test("fromElement", () => { const application_element = ( @@ -47,5 +45,7 @@ test("fromElement - whitespaces", () => { expect(error.name).toBe("XMPPError"); expect(error.condition).toBe("some-condition"); expect(error.text).toBe("\n foo\n "); - expect(error.application.toString()).toBe(``); + expect(error.application.toString()).toBe( + ``, + ); }); diff --git a/packages/events/index.js b/packages/events/index.js index ee6644532..a2571313d 100644 --- a/packages/events/index.js +++ b/packages/events/index.js @@ -1,15 +1,9 @@ -"use strict"; +import EventEmitter from "events"; -const timeout = require("./lib/timeout"); -const delay = require("./lib/delay"); -const TimeoutError = require("./lib/TimeoutError"); -const promise = require("./lib/promise"); -const EventEmitter = require("events"); -const Deferred = require("./lib/Deferred"); +import timeout from "./lib/timeout.js"; +import delay from "./lib/delay.js"; +import TimeoutError from "./lib/TimeoutError.js"; +import promise from "./lib/promise.js"; +import Deferred from "./lib/Deferred.js"; -exports.EventEmitter = EventEmitter; -exports.timeout = timeout; -exports.delay = delay; -exports.TimeoutError = TimeoutError; -exports.promise = promise; -exports.Deferred = Deferred; +export { EventEmitter, timeout, delay, TimeoutError, promise, Deferred }; diff --git a/packages/events/lib/Deferred.js b/packages/events/lib/Deferred.js index 7c388ec64..1b5631e3b 100644 --- a/packages/events/lib/Deferred.js +++ b/packages/events/lib/Deferred.js @@ -1,8 +1,6 @@ -"use strict"; - -module.exports = function Deferred() { +export default function Deferred() { this.promise = new Promise((resolve, reject) => { this.resolve = resolve; this.reject = reject; }); -}; +} diff --git a/packages/events/lib/TimeoutError.js b/packages/events/lib/TimeoutError.js index 46008e3ba..e6880d4f3 100644 --- a/packages/events/lib/TimeoutError.js +++ b/packages/events/lib/TimeoutError.js @@ -1,8 +1,6 @@ -"use strict"; - -module.exports = class TimeoutError extends Error { +export default class TimeoutError extends Error { constructor(message) { super(message); this.name = "TimeoutError"; } -}; +} diff --git a/packages/events/lib/delay.js b/packages/events/lib/delay.js index 0ef64d1d3..8d2c87984 100644 --- a/packages/events/lib/delay.js +++ b/packages/events/lib/delay.js @@ -1,10 +1,8 @@ -"use strict"; - -module.exports = function delay(ms) { +export default function delay(ms) { let timeout; const promise = new Promise((resolve) => { timeout = setTimeout(resolve, ms); }); promise.timeout = timeout; return promise; -}; +} diff --git a/packages/events/lib/promise.js b/packages/events/lib/promise.js index 3659f4dca..69fb61b45 100644 --- a/packages/events/lib/promise.js +++ b/packages/events/lib/promise.js @@ -1,8 +1,6 @@ -"use strict"; +import TimeoutError from "./TimeoutError.js"; -const TimeoutError = require("./TimeoutError"); - -module.exports = function promise(EE, event, rejectEvent = "error", timeout) { +export default function promise(EE, event, rejectEvent = "error", timeout) { return new Promise((resolve, reject) => { let timeoutId; @@ -34,4 +32,4 @@ module.exports = function promise(EE, event, rejectEvent = "error", timeout) { }, timeout); } }); -}; +} diff --git a/packages/events/lib/timeout.js b/packages/events/lib/timeout.js index 76d63fe0d..e316369d3 100644 --- a/packages/events/lib/timeout.js +++ b/packages/events/lib/timeout.js @@ -1,9 +1,7 @@ -"use strict"; +import TimeoutError from "./TimeoutError.js"; +import delay from "./delay.js"; -const TimeoutError = require("./TimeoutError"); -const delay = require("./delay"); - -module.exports = function timeout(promise, ms) { +export default function timeout(promise, ms) { const promiseDelay = delay(ms); function cancelDelay() { @@ -16,4 +14,4 @@ module.exports = function timeout(promise, ms) { throw new TimeoutError(); }), ]); -}; +} diff --git a/packages/events/package.json b/packages/events/package.json index 1685c1556..d2c7ecd06 100644 --- a/packages/events/package.json +++ b/packages/events/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "event", "events", @@ -14,7 +14,7 @@ "EventEmitter" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/events/test/promise.test.js b/packages/events/test/promise.test.js index 50fe712f9..9568d5c3c 100644 --- a/packages/events/test/promise.test.js +++ b/packages/events/test/promise.test.js @@ -1,7 +1,5 @@ -"use strict"; - -const { promise } = require(".."); -const EventEmitter = require("events"); +import promise from "../lib/promise.js"; +import EventEmitter from "node:events"; class Socket extends EventEmitter { constructor(fn) { @@ -34,21 +32,24 @@ test('resolves if "event" is emitted', async () => { expect(socket.listenerCount("connect")).toBe(0); }); -test('rejects if "errorEvent" is emitted', () => { +test('rejects if "errorEvent" is emitted', async () => { const error = new Error("foobar"); // eslint-disable-next-line func-names const socket = new Socket(function () { this.emit("error", error); }); + socket.connect(); + expect(socket.listenerCount("error")).toBe(0); expect(socket.listenerCount("connect")).toBe(0); - socket.connect(); + const p = promise(socket, "connect", "error"); + expect(socket.listenerCount("error")).toBe(1); expect(socket.listenerCount("connect")).toBe(1); - return p.catch((err) => { - expect(err).toBe(error); - expect(socket.listenerCount("error")).toBe(0); - expect(socket.listenerCount("connect")).toBe(0); - }); + + await expect(p).rejects.toBe(error); + + expect(socket.listenerCount("error")).toBe(0); + expect(socket.listenerCount("connect")).toBe(0); }); diff --git a/packages/id/README.md b/packages/id/README.md index 4ce5cb0fb..941e23434 100644 --- a/packages/id/README.md +++ b/packages/id/README.md @@ -9,7 +9,7 @@ XMPP id generator for JavaScript. ## Usage ```js -const id = require("@xmpp/id"); +import id from "@xmpp/id"; console.log(id()); // ymg806tinn ``` diff --git a/packages/id/index.js b/packages/id/index.js index 361e9a40a..19dcb08d5 100644 --- a/packages/id/index.js +++ b/packages/id/index.js @@ -1,10 +1,8 @@ -"use strict"; - -module.exports = function id() { +export default function id() { let i; while (!i) { i = Math.random().toString(36).slice(2, 12); } return i; -}; +} diff --git a/packages/id/package.json b/packages/id/package.json index 6516eb637..9484842d6 100644 --- a/packages/id/package.json +++ b/packages/id/package.json @@ -6,13 +6,13 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "id" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/id/test.js b/packages/id/test.js index de4cfe1e1..8bd67b4d7 100644 --- a/packages/id/test.js +++ b/packages/id/test.js @@ -1,6 +1,4 @@ -"use strict"; - -const xid = require("."); +import xid from "./index.js"; test("returns a non empty string", () => { expect(typeof xid()).toBe("string"); @@ -9,7 +7,7 @@ test("returns a non empty string", () => { test("duplicates", () => { const id = xid(); - for (let i = 0; i < 100000; i++) { + for (let i = 0; i < 10000; i++) { expect(id).not.toBe(xid()); } }); diff --git a/packages/iq/README.md b/packages/iq/README.md index d05a29caa..8c2dfe544 100644 --- a/packages/iq/README.md +++ b/packages/iq/README.md @@ -11,10 +11,10 @@ Included in `@xmpp/client` and `@xmpp/component`. Implements the caller side of iq semantics. ```js -const {client} = require('@xmpp/client') // or component +import { client } from "@xmpp/client"; // or component -const xmpp = client(...) -const {iqCaller} = xmpp +const xmpp = client(...); +const {iqCaller} = xmpp; ``` ### request @@ -71,10 +71,10 @@ Implements the callee side of iq semantics. You can think of this as http routing except there are only 2 methods; `get` and `set` and you would pass a namespace and a tag name instead of an url. The return value of the handler will be the child element of the response sent to the caller. ```js -const {client} = require('@xmpp/client') // or component +import { client } from "@xmpp/client"; // or component -const xmpp = client(...) -const {iqCallee} = xmpp +const xmpp = client(...); +const {iqCallee} = xmpp; ``` ## get diff --git a/packages/iq/callee.js b/packages/iq/callee.js index 80f38e1f7..c5aaebfa7 100644 --- a/packages/iq/callee.js +++ b/packages/iq/callee.js @@ -1,4 +1,4 @@ -"use strict"; +import xml from "@xmpp/xml"; /** * References @@ -6,8 +6,6 @@ * https://xmpp.org/rfcs/rfc6120.html#stanzas-error */ -const xml = require("@xmpp/xml"); - const NS_STANZA = "urn:ietf:params:xml:ns:xmpp-stanzas"; function isQuery({ name, type }) { @@ -101,7 +99,7 @@ function route(type, ns, name, handler) { }; } -module.exports = function iqCallee({ middleware, entity }) { +export default function iqCallee({ middleware, entity }) { middleware.use(iqHandler(entity)); return { @@ -112,4 +110,4 @@ module.exports = function iqCallee({ middleware, entity }) { middleware.use(route("set", ns, name, handler)); }, }; -}; +} diff --git a/packages/iq/caller.js b/packages/iq/caller.js index 35a322837..2dffe358b 100644 --- a/packages/iq/caller.js +++ b/packages/iq/caller.js @@ -1,10 +1,7 @@ -"use strict"; - -const xid = require("@xmpp/id"); -const StanzaError = require("@xmpp/middleware/lib/StanzaError"); -const { Deferred } = require("@xmpp/events"); -const timeoutPromise = require("@xmpp/events").timeout; -const xml = require("@xmpp/xml"); +import xid from "@xmpp/id"; +import StanzaError from "@xmpp/middleware/lib/StanzaError.js"; +import { Deferred, timeout as timeoutPromise } from "@xmpp/events"; +import xml from "@xmpp/xml"; function isReply({ name, type }) { if (name !== "iq") return false; @@ -79,8 +76,8 @@ class IQCaller { } } -module.exports = function iqCaller(...args) { +export default function iqCaller(...args) { const iqCaller = new IQCaller(...args); iqCaller.start(); return iqCaller; -}; +} diff --git a/packages/iq/package.json b/packages/iq/package.json index 36cec3bf8..0ac5fe93c 100644 --- a/packages/iq/package.json +++ b/packages/iq/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "iq", @@ -14,7 +14,7 @@ "callee" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "dependencies": { "@xmpp/events": "^0.13.2", @@ -22,9 +22,6 @@ "@xmpp/middleware": "^0.13.2", "@xmpp/xml": "^0.13.2" }, - "devDependencies": { - "@xmpp/middleware": "^0.13.1" - }, "publishConfig": { "access": "public" } diff --git a/packages/iq/test/callee.js b/packages/iq/test/callee.js index eb285e4fa..8378d5394 100644 --- a/packages/iq/test/callee.js +++ b/packages/iq/test/callee.js @@ -1,11 +1,4 @@ -"use strict"; - -const { - mockClient, - promiseSend, - mockInput, - promiseError, -} = require("@xmpp/test"); +import { mockClient, promiseSend, mockInput, promiseError } from "@xmpp/test"; test("empty result when the handler returns true", async () => { const xmpp = mockClient(); @@ -55,12 +48,14 @@ test("iqs with multiple element children are invalid", async () => { , ); - expect(await promiseSend(xmpp)).toEqual( - - - - - ); + expect(await promiseSend(xmpp)).toEqual( + + + + + + , + ); }); test("non empty result when the handler returns an xml.Element", async () => { @@ -78,9 +73,11 @@ test("non empty result when the handler returns an xml.Element", async () => { , ); - expect(await promiseSend(xmpp)).toEqual( - - ); + expect(await promiseSend(xmpp)).toEqual( + + + , + ); }); test("service unavailable error reply when there are no handler", async () => { @@ -92,12 +89,14 @@ test("service unavailable error reply when there are no handler", async () => { , ); - expect(await promiseSend(xmpp)).toEqual( - - - - - ); + expect(await promiseSend(xmpp)).toEqual( + + + + + + , + ); }); test("internal server error reply when handler throws an error", async () => { @@ -120,12 +119,14 @@ test("internal server error reply when handler throws an error", async () => { ); expect(await errorPromise).toBe(error); - expect(await outputPromise).toEqual( - - - - - ); + expect(await outputPromise).toEqual( + + + + + + , + ); }); test("internal server error reply when handler rejects with an error", async () => { @@ -148,12 +149,14 @@ test("internal server error reply when handler rejects with an error", async () ); expect(await errorPromise).toBe(error); - expect(await outputPromise).toEqual( - - - - - ); + expect(await outputPromise).toEqual( + + + + + + , + ); }); test("stanza error reply when handler returns an error element", async () => { @@ -179,8 +182,10 @@ test("stanza error reply when handler returns an error element", async () => { , ); - expect(await outputPromise).toEqual( - - {errorElement} - ); + expect(await outputPromise).toEqual( + + + {errorElement} + , + ); }); diff --git a/packages/iq/test/caller.js b/packages/iq/test/caller.js index 03a3e5447..ace185313 100644 --- a/packages/iq/test/caller.js +++ b/packages/iq/test/caller.js @@ -1,7 +1,5 @@ -"use strict"; - -const { mockClient, mockInput } = require("@xmpp/test"); -const StanzaError = require("@xmpp/middleware/lib/StanzaError"); +import { mockClient, mockInput } from "@xmpp/test"; +import StanzaError from "@xmpp/middleware/lib/StanzaError.js"; test("#request", (done) => { const xmpp = mockClient(); diff --git a/packages/jid/README.md b/packages/jid/README.md index c0ddade98..d07248a35 100644 --- a/packages/jid/README.md +++ b/packages/jid/README.md @@ -17,18 +17,18 @@ https://en.wikipedia.org/wiki/XMPP#Decentralization_and_addressing ## Usage ```js -var jid = require("@xmpp/jid"); +import jid from "@xmpp/jid"; /* * All return an instance of jid.JID */ -var addr = jid("alice@wonderland.net/rabbithole"); -var addr = jid("alice", "wonderland.net", "rabbithole"); +const addr = jid("alice@wonderland.net/rabbithole"); +const addr = jid("alice", "wonderland.net", "rabbithole"); addr instanceof jid.JID; // true // domain JIDs are created passing the domain as the first argument -var addr = jid("wonderland.net"); +const addr = jid("wonderland.net"); /* * local diff --git a/packages/jid/index.js b/packages/jid/index.js index 1a03c6e86..04e8d1ca9 100644 --- a/packages/jid/index.js +++ b/packages/jid/index.js @@ -1,8 +1,10 @@ -"use strict"; +import JID from "./lib/JID.js"; +import { detect, escape, unescape } from "./lib/escaping.js"; +import parse from "./lib/parse.js"; -const JID = require("./lib/JID"); -const escaping = require("./lib/escaping"); -const parse = require("./lib/parse"); +export function equal(a, b) { + return a.equals(b); +} function jid(...args) { if (!args[1] && !args[2]) { @@ -12,14 +14,21 @@ function jid(...args) { return new JID(...args); } -module.exports = jid.bind(); -module.exports.jid = jid; -module.exports.JID = JID; -module.exports.equal = function equal(a, b) { - return a.equals(b); -}; +const j = jid.bind(); +j.jid = jid; +j.JID = JID; +j.parse = parse; +j.equal = equal; +j.detectEscape = detect; +j.escapeLocal = escape; +j.unescapeLocal = unescape; -module.exports.detectEscape = escaping.detect; -module.exports.escapeLocal = escaping.escape; -module.exports.unescapeLocal = escaping.unescape; -module.exports.parse = parse; +export default j; + +export { jid, JID, parse }; + +export { + detect as detectEscape, + escape as escapeLocal, + unescape as unescapeLocal, +}; diff --git a/packages/jid/lib/JID.js b/packages/jid/lib/JID.js index 4ebdedb0f..54d2e8592 100644 --- a/packages/jid/lib/JID.js +++ b/packages/jid/lib/JID.js @@ -1,6 +1,4 @@ -"use strict"; - -const escaping = require("./escaping"); +import * as escaping from "./escaping.js"; /** * JID implements @@ -126,4 +124,4 @@ Object.defineProperty(JID.prototype, "resource", { set: JID.prototype.setResource, }); -module.exports = JID; +export default JID; diff --git a/packages/jid/lib/escaping.js b/packages/jid/lib/escaping.js index d89a8b0fe..90fc73d5d 100644 --- a/packages/jid/lib/escaping.js +++ b/packages/jid/lib/escaping.js @@ -1,6 +1,4 @@ -"use strict"; - -module.exports.detect = function detect(local) { +export function detect(local) { if (!local) { return false; } @@ -25,7 +23,7 @@ module.exports.detect = function detect(local) { } return true; -}; +} /** * Escape the local part of a JID. @@ -34,7 +32,7 @@ module.exports.detect = function detect(local) { * @param String local local part of a jid * @return An escaped local part */ -module.exports.escape = function escape(local) { +export function escape(local) { if (local === null) { return null; } @@ -51,7 +49,7 @@ module.exports.escape = function escape(local) { .replaceAll("<", String.raw`\3c`) .replaceAll(">", String.raw`\3e`) .replaceAll("@", String.raw`\40`); -}; +} /** * Unescape a local part of a JID. @@ -60,7 +58,7 @@ module.exports.escape = function escape(local) { * @param String local local part of a jid * @return unescaped local part */ -module.exports.unescape = function unescape(local) { +export function unescape(local) { if (local === null) { return null; } @@ -76,4 +74,4 @@ module.exports.unescape = function unescape(local) { .replaceAll(String.raw`\3e`, ">") .replaceAll(String.raw`\40`, "@") .replaceAll(String.raw`\5c`, "\\"); -}; +} diff --git a/packages/jid/lib/parse.js b/packages/jid/lib/parse.js index 4211a812b..e84e9c6d8 100644 --- a/packages/jid/lib/parse.js +++ b/packages/jid/lib/parse.js @@ -1,8 +1,6 @@ -"use strict"; +import JID from "./JID.js"; -const JID = require("../lib/JID"); - -module.exports = function parse(s) { +export default function parse(s) { let local; let resource; @@ -19,4 +17,4 @@ module.exports = function parse(s) { } return new JID(local, s, resource); -}; +} diff --git a/packages/jid/package.json b/packages/jid/package.json index 933aa79e6..83d574067 100644 --- a/packages/jid/package.json +++ b/packages/jid/package.json @@ -6,13 +6,13 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "JID" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/jid/test/JID.js b/packages/jid/test/JID.js index 5e4234d76..a7c61c63f 100644 --- a/packages/jid/test/JID.js +++ b/packages/jid/test/JID.js @@ -1,6 +1,4 @@ -"use strict"; - -const JID = require("../lib/JID"); +import JID from "../lib/JID.js"; test("throws TypeError for invalid domain", () => { expect(() => new JID("foo")).toThrow(new TypeError("Invalid domain.")); diff --git a/packages/jid/test/equality.js b/packages/jid/test/equality.js index 1e12ef0a7..7f70a0dbc 100644 --- a/packages/jid/test/equality.js +++ b/packages/jid/test/equality.js @@ -1,6 +1,4 @@ -"use strict"; - -const jid = require(".."); +import jid from "../index.js"; test("should parsed JIDs should be equal", () => { const j1 = jid("foo@bar/baz"); diff --git a/packages/jid/test/escapeLocal.js b/packages/jid/test/escapeLocal.js index e87a4d7b8..da7134959 100644 --- a/packages/jid/test/escapeLocal.js +++ b/packages/jid/test/escapeLocal.js @@ -1,6 +1,4 @@ -"use strict"; - -const jid = require(".."); +import jid from "../index.js"; test("Should not change string - issue 43", () => { const test = "test\u001A@example.com"; diff --git a/packages/jid/test/escaping.js b/packages/jid/test/escaping.js index 5bc83e954..34332d260 100644 --- a/packages/jid/test/escaping.js +++ b/packages/jid/test/escaping.js @@ -1,6 +1,4 @@ -"use strict"; - -const JID = require("../lib/JID"); +import JID from "../index.js"; test("escape `space cadet@example.com`", () => { const esc = new JID("space cadet", "example.com"); @@ -10,7 +8,9 @@ test("escape `space cadet@example.com`", () => { test('escape `call me "ishmael"@example.com`', () => { const esc = new JID('call me "ishmael"', "example.com"); - expect(esc.toString()).toBe(String.raw`call\20me\20\22ishmael\22@example.com`); + expect(esc.toString()).toBe( + String.raw`call\20me\20\22ishmael\22@example.com`, + ); expect(esc.toString(true)).toBe('call me "ishmael"@example.com'); }); diff --git a/packages/jid/test/index.js b/packages/jid/test/index.js index f8cf4e296..3fb814075 100644 --- a/packages/jid/test/index.js +++ b/packages/jid/test/index.js @@ -1,13 +1,10 @@ -"use strict"; - -const jid = require(".."); -const JID = require("../lib/JID"); +import jid, { equal, JID } from "../index.js"; test("equal calls equals on the first argument with the second argument", () => { const A = jid("foo"); const B = jid("bar"); const spy_equals = jest.spyOn(A, "equals"); - jid.equal(A, B); + equal(A, B); expect(spy_equals).toHaveBeenCalledWith(B); }); diff --git a/packages/jid/test/parsing.js b/packages/jid/test/parsing.js index b835bbffc..0184ec692 100644 --- a/packages/jid/test/parsing.js +++ b/packages/jid/test/parsing.js @@ -1,6 +1,4 @@ -"use strict"; - -const parse = require("../lib/parse"); +import parse from "../lib/parse.js"; test('should parse a "domain" JID', () => { const j = parse("d"); diff --git a/packages/jid/test/serialization.js b/packages/jid/test/serialization.js index cbf17bb37..fe591f7e9 100644 --- a/packages/jid/test/serialization.js +++ b/packages/jid/test/serialization.js @@ -1,6 +1,4 @@ -"use strict"; - -const JID = require("../lib/JID"); +import JID from "../lib/JID.js"; test('should serialize a "domain" JID', () => { const j = new JID(null, "d"); diff --git a/packages/jid/test/toPrimitive.js b/packages/jid/test/toPrimitive.js index 375458c02..90664eb29 100644 --- a/packages/jid/test/toPrimitive.js +++ b/packages/jid/test/toPrimitive.js @@ -1,6 +1,4 @@ -"use strict"; - -const JID = require("../lib/JID"); +import JID from "../lib/JID.js"; test("cocerce to string", () => { const addr = new JID("foo", "bar"); diff --git a/packages/middleware/README.md b/packages/middleware/README.md index e3612bd33..612f01a4c 100644 --- a/packages/middleware/README.md +++ b/packages/middleware/README.md @@ -13,8 +13,8 @@ npm install @xmpp/middleware ## Usage ```js -const { Client } = require("@xmpp/client"); -const middleware = require("@xmpp/middlware"); +import { Client } from "@xmpp/client"; +import middleware from "@xmpp/middleware"; const client = new Client(); const app = middleware({ entity: client }); diff --git a/packages/middleware/index.js b/packages/middleware/index.js index 39a70dda4..9378b4418 100644 --- a/packages/middleware/index.js +++ b/packages/middleware/index.js @@ -1,9 +1,7 @@ -"use strict"; +import compose from "koa-compose"; -const compose = require("koa-compose"); - -const IncomingContext = require("./lib/IncomingContext"); -const OutgoingContext = require("./lib/OutgoingContext"); +import IncomingContext from "./lib/IncomingContext.js"; +import OutgoingContext from "./lib/OutgoingContext.js"; function listener(entity, middleware, Context) { return (stanza) => { @@ -20,7 +18,7 @@ function errorHandler(entity) { }; } -module.exports = function middleware({ entity }) { +export default function middleware({ entity }) { const incoming = [errorHandler(entity)]; const outgoing = []; @@ -40,4 +38,4 @@ module.exports = function middleware({ entity }) { return fn; }, }; -}; +} diff --git a/packages/middleware/lib/Context.js b/packages/middleware/lib/Context.js index 55587b0dc..cedcb0ffd 100644 --- a/packages/middleware/lib/Context.js +++ b/packages/middleware/lib/Context.js @@ -1,6 +1,4 @@ -"use strict"; - -module.exports = class Context { +export default class Context { constructor(entity, stanza) { this.stanza = stanza; this.entity = entity; @@ -25,4 +23,4 @@ module.exports = class Context { this.domain = ""; this.resource = ""; } -}; +} diff --git a/packages/middleware/lib/IncomingContext.js b/packages/middleware/lib/IncomingContext.js index 4246ca272..33c08001f 100644 --- a/packages/middleware/lib/IncomingContext.js +++ b/packages/middleware/lib/IncomingContext.js @@ -1,9 +1,7 @@ -"use strict"; +import Context from "./Context.js"; +import JID from "@xmpp/jid"; -const Context = require("./Context"); -const JID = require("@xmpp/jid"); - -module.exports = class IncomingContext extends Context { +export default class IncomingContext extends Context { constructor(entity, stanza) { super(entity, stanza); @@ -21,4 +19,4 @@ module.exports = class IncomingContext extends Context { this.resource = this.from.resource; } } -}; +} diff --git a/packages/middleware/lib/OutgoingContext.js b/packages/middleware/lib/OutgoingContext.js index 60c5ab176..88f281ac3 100644 --- a/packages/middleware/lib/OutgoingContext.js +++ b/packages/middleware/lib/OutgoingContext.js @@ -1,9 +1,7 @@ -"use strict"; +import Context from "./Context.js"; +import JID from "@xmpp/jid"; -const Context = require("./Context"); -const JID = require("@xmpp/jid"); - -module.exports = class OutgoingContext extends Context { +export default class OutgoingContext extends Context { constructor(entity, stanza) { super(entity, stanza); @@ -21,4 +19,4 @@ module.exports = class OutgoingContext extends Context { this.resource = this.to.resource; } } -}; +} diff --git a/packages/middleware/lib/StanzaError.js b/packages/middleware/lib/StanzaError.js index c1172d836..c76444ccc 100644 --- a/packages/middleware/lib/StanzaError.js +++ b/packages/middleware/lib/StanzaError.js @@ -1,9 +1,7 @@ -"use strict"; +import XMPPError from "@xmpp/error"; /* https://xmpp.org/rfcs/rfc6120.html#stanzas-error */ -const XMPPError = require("@xmpp/error"); - class StanzaError extends XMPPError { constructor(condition, text, application, type) { super(condition, text, application); @@ -18,4 +16,4 @@ class StanzaError extends XMPPError { } } -module.exports = StanzaError; +export default StanzaError; diff --git a/packages/middleware/package.json b/packages/middleware/package.json index cb8d4c508..2c7db5a40 100644 --- a/packages/middleware/package.json +++ b/packages/middleware/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "middleware" @@ -18,7 +18,7 @@ "koa-compose": "^4.1.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/middleware/test/Context.js b/packages/middleware/test/Context.js index 496f02d1d..01f4b655f 100644 --- a/packages/middleware/test/Context.js +++ b/packages/middleware/test/Context.js @@ -1,6 +1,4 @@ -"use strict"; - -const Context = require("../lib/Context"); +import Context from "../lib/Context.js"; test("sets the entity property", () => { const entity = {}; diff --git a/packages/middleware/test/IncomingContext.js b/packages/middleware/test/IncomingContext.js index 7f53361f4..96c607b71 100644 --- a/packages/middleware/test/IncomingContext.js +++ b/packages/middleware/test/IncomingContext.js @@ -1,8 +1,6 @@ -"use strict"; - -const Context = require("../lib/IncomingContext"); -const { JID } = require("@xmpp/test"); -const _Context = require("../lib/Context"); +import Context from "../lib/IncomingContext.js"; +import { JID } from "@xmpp/test"; +import _Context from "../lib/Context.js"; test("is instance of Context", () => { const entity = { jid: new JID("foo@bar"), domain: "bar" }; diff --git a/packages/middleware/test/OutgoingContext.js b/packages/middleware/test/OutgoingContext.js index 762f20246..6191ed9e9 100644 --- a/packages/middleware/test/OutgoingContext.js +++ b/packages/middleware/test/OutgoingContext.js @@ -1,8 +1,6 @@ -"use strict"; - -const Context = require("../lib/OutgoingContext"); -const { JID } = require("@xmpp/test"); -const _Context = require("../lib/Context"); +import Context from "../lib/OutgoingContext.js"; +import { JID } from "@xmpp/test"; +import _Context from "../lib/Context.js"; test("is instance of Context", () => { const entity = { jid: new JID("foo@bar"), domain: "bar" }; diff --git a/packages/middleware/test/middleware.js b/packages/middleware/test/middleware.js index 3419cf164..f3477fca9 100644 --- a/packages/middleware/test/middleware.js +++ b/packages/middleware/test/middleware.js @@ -1,9 +1,7 @@ -"use strict"; - -const IncomingContext = require("../lib/IncomingContext"); -const OutgoingContext = require("../lib/OutgoingContext"); -const { context, mockClient, mockInput, promiseError } = require("@xmpp/test"); -const _middleware = require(".."); +import IncomingContext from "../lib/IncomingContext.js"; +import OutgoingContext from "../lib/OutgoingContext.js"; +import { context, mockClient, mockInput, promiseError } from "@xmpp/test"; +import _middleware from "../index.js"; let ctx; diff --git a/packages/reconnect/index.js b/packages/reconnect/index.js index 8a8d19e55..0c04cc940 100644 --- a/packages/reconnect/index.js +++ b/packages/reconnect/index.js @@ -1,6 +1,4 @@ -"use strict"; - -const { EventEmitter } = require("@xmpp/events"); +import { EventEmitter } from "@xmpp/events"; class Reconnect extends EventEmitter { constructor(entity) { @@ -56,8 +54,8 @@ class Reconnect extends EventEmitter { } } -module.exports = function reconnect({ entity }) { +export default function reconnect({ entity }) { const r = new Reconnect(entity); r.start(); return r; -}; +} diff --git a/packages/reconnect/package.json b/packages/reconnect/package.json index 0a11b8274..4d7e30bd7 100644 --- a/packages/reconnect/package.json +++ b/packages/reconnect/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "reconnect" @@ -15,7 +15,7 @@ "@xmpp/events": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/reconnect/test.js b/packages/reconnect/test.js index 27bbff77f..c7f325cba 100644 --- a/packages/reconnect/test.js +++ b/packages/reconnect/test.js @@ -1,7 +1,5 @@ -"use strict"; - -const _reconnect = require("."); -const EventEmitter = require("events"); +import _reconnect from "./index.js"; +import { EventEmitter } from "@xmpp/events"; test("it schedule a reconnect when disconnect is emitted", (done) => { const entity = new EventEmitter(); diff --git a/packages/resolve/README.md b/packages/resolve/README.md index 4882315b8..5d598c055 100644 --- a/packages/resolve/README.md +++ b/packages/resolve/README.md @@ -13,7 +13,7 @@ npm install @xmpp/resolve ## Usage ```javascript -const resolve = require("@xmpp/resolve/resolve"); +import resolve from "@xmpp/resolve"; // optional const options = { diff --git a/packages/resolve/example.js b/packages/resolve/example.js index 42777d44e..c5b6efa35 100644 --- a/packages/resolve/example.js +++ b/packages/resolve/example.js @@ -1,7 +1,3 @@ -"use strict"; - -const resolve = require("./resolve"); -// For you -// const resolve = require('@xmpp/resolve') +import { resolve } from "@xmpp/resolve"; resolve("jabberfr.org").then(console.log).catch(console.error); diff --git a/packages/resolve/index.js b/packages/resolve/index.js index 2b90f3173..fb5a27770 100644 --- a/packages/resolve/index.js +++ b/packages/resolve/index.js @@ -1,10 +1,8 @@ -"use strict"; - -const resolve = require("./resolve"); -const { promise } = require("@xmpp/events"); +import _resolve from "./resolve.js"; +import { promise } from "@xmpp/events"; async function fetchURIs(domain) { - const result = await resolve(domain, { + const result = await _resolve(domain, { srv: [ { service: "xmpps-client", @@ -57,7 +55,7 @@ async function fallbackConnect(entity, uris) { entity.Parser = Transport.prototype.Parser; } -module.exports = function resolve({ entity }) { +export default function resolve({ entity }) { const _connect = entity.connect; entity.connect = async function connect(service) { if (!service || /:\/\//.test(service)) { @@ -78,4 +76,6 @@ module.exports = function resolve({ entity }) { throw err; } }; -}; +} + +export { _resolve as resolve }; diff --git a/packages/resolve/lib/alt-connections.js b/packages/resolve/lib/alt-connections.js index 8b66b743a..073d2a53c 100644 --- a/packages/resolve/lib/alt-connections.js +++ b/packages/resolve/lib/alt-connections.js @@ -1,10 +1,8 @@ -"use strict"; - function isSecure(uri) { return uri.startsWith("https") || uri.startsWith("wss"); } -module.exports.compare = function compare(a, b) { +export function compare(a, b) { let secure; if (isSecure(a.uri) && !isSecure(b.uri)) { secure = -1; @@ -42,4 +40,4 @@ module.exports.compare = function compare(a, b) { } return 0; -}; +} diff --git a/packages/resolve/lib/dns.js b/packages/resolve/lib/dns.js index 7096e4144..c5017a048 100644 --- a/packages/resolve/lib/dns.js +++ b/packages/resolve/lib/dns.js @@ -1,7 +1,6 @@ /* eslint-disable promise/no-nesting */ -"use strict"; -const dns = require("dns"); +import dns from "dns"; // eslint-disable-next-line unicorn/prefer-set-has const IGNORE_CODES = ["ENOTFOUND", "ENODATA"]; @@ -147,8 +146,4 @@ function resolve(domain, options = {}) { }); } -module.exports.lookup = lookup; -module.exports.resolveSrv = resolveSrv; -module.exports.lookupSrvs = lookupSrvs; -module.exports.resolve = resolve; -module.exports.sortSrv = sortSrv; +export { lookup, resolveSrv, resolve, lookupSrvs, sortSrv }; diff --git a/packages/resolve/lib/http.js b/packages/resolve/lib/http.js index 5bb893436..cbba7366f 100644 --- a/packages/resolve/lib/http.js +++ b/packages/resolve/lib/http.js @@ -1,11 +1,10 @@ -"use strict"; +import parse from "@xmpp/xml/lib/parse.js"; +import { compare as compareAltConnections } from "./alt-connections.js"; -// eslint-disable-next-line n/no-unsupported-features/node-builtins -const fetch = globalThis.fetch || require("node-fetch"); -const parse = require("@xmpp/xml/lib/parse"); -const compareAltConnections = require("./alt-connections").compare; - -function resolve(domain) { +export async function resolve(domain) { + // eslint-disable-next-line n/no-unsupported-features/node-builtins, unicorn/no-await-expression-member + const fetch = globalThis.fetch || (await import("node-fetch")).default; + return fetch(`https://${domain}/.well-known/host-meta`) .then((res) => res.text()) .then((res) => { @@ -30,5 +29,3 @@ function resolve(domain) { return []; }); } - -module.exports.resolve = resolve; diff --git a/packages/resolve/package.json b/packages/resolve/package.json index a65ad6ca2..448c58b3f 100644 --- a/packages/resolve/package.json +++ b/packages/resolve/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "dns", @@ -27,7 +27,7 @@ "node-fetch": "^2.6.12" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/resolve/resolve.js b/packages/resolve/resolve.js index bdfa9f917..02d38e2f4 100644 --- a/packages/resolve/resolve.js +++ b/packages/resolve/resolve.js @@ -1,17 +1,11 @@ -"use strict"; +import * as dns from "./lib/dns.js"; +import * as http from "./lib/http.js"; -const dns = require("./lib/dns"); -const http = require("./lib/http"); - -module.exports = function resolve(...args) { +export default function resolve(...args) { return Promise.all([ dns.resolve ? dns.resolve(...args) : Promise.resolve([]), http.resolve(...args), ]).then(([records, endpoints]) => [...records, ...endpoints]); -}; - -if (dns.resolve) { - module.exports.dns = dns; } -module.exports.http = http; +export { dns, http }; diff --git a/packages/resolve/test/compareAltConnections.js b/packages/resolve/test/compareAltConnections.js index 4895ba252..9f6c3fff8 100644 --- a/packages/resolve/test/compareAltConnections.js +++ b/packages/resolve/test/compareAltConnections.js @@ -1,31 +1,35 @@ -"use strict"; - -const { compare } = require("../lib/alt-connections"); +import { compare } from "../lib/alt-connections.js"; test("by security", () => { - expect([ - { uri: "http://web.example.org:5280/bosh", method: "xbosh" }, - { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, - ].sort(compare)).toEqual([ + expect( + [ + { uri: "http://web.example.org:5280/bosh", method: "xbosh" }, + { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, + ].sort(compare), + ).toEqual([ { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, { uri: "http://web.example.org:5280/bosh", method: "xbosh" }, ]); - expect([ - { uri: "ws://web.example.com:80/ws", method: "websocket" }, - { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, - ].sort(compare)).toEqual([ + expect( + [ + { uri: "ws://web.example.com:80/ws", method: "websocket" }, + { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, + ].sort(compare), + ).toEqual([ { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, { uri: "ws://web.example.com:80/ws", method: "websocket" }, ]); }); test("by method", () => { - expect([ - { uri: "https://web.example.org:5280/http-poll", method: "httppoll" }, - { uri: "wss://web.example.com:443/ws", method: "websocket" }, - { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, - ].sort(compare)).toEqual([ + expect( + [ + { uri: "https://web.example.org:5280/http-poll", method: "httppoll" }, + { uri: "wss://web.example.com:443/ws", method: "websocket" }, + { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, + ].sort(compare), + ).toEqual([ { uri: "wss://web.example.com:443/ws", method: "websocket" }, { uri: "https://web.example.org:5280/bosh", method: "xbosh" }, { uri: "https://web.example.org:5280/http-poll", method: "httppoll" }, diff --git a/packages/resolve/test/httpParse.js b/packages/resolve/test/httpParse.js index cebe49485..e5b3e08c5 100644 --- a/packages/resolve/test/httpParse.js +++ b/packages/resolve/test/httpParse.js @@ -1,4 +1,4 @@ -"use strict"; +import { resolve } from "../lib/http.js"; const domain = "example.com"; // eslint-disable-next-line n/no-unsupported-features/node-builtins @@ -19,8 +19,6 @@ globalThis.fetch = (url) => { }); }; -const { resolve } = require("../lib/http"); - test("parse", async () => { expect(await resolve(domain)).toEqual([ { diff --git a/packages/resolve/test/sortSrv.js b/packages/resolve/test/sortSrv.js index 23bf2fc65..e63a81510 100644 --- a/packages/resolve/test/sortSrv.js +++ b/packages/resolve/test/sortSrv.js @@ -1,38 +1,44 @@ -"use strict"; - -const sort = require("../lib/dns").sortSrv; +import { sortSrv as sort } from "../lib/dns.js"; test("by priority", () => { - expect(sort([ - { priority: 2, weight: 0 }, - { priority: 1, weight: 0 }, - ])).toEqual([ + expect( + sort([ + { priority: 2, weight: 0 }, + { priority: 1, weight: 0 }, + ]), + ).toEqual([ { priority: 1, weight: 0 }, { priority: 2, weight: 0 }, ]); - expect(sort([ - { priority: 2, weight: 1 }, - { priority: 1, weight: 0 }, - ])).toEqual([ + expect( + sort([ + { priority: 2, weight: 1 }, + { priority: 1, weight: 0 }, + ]), + ).toEqual([ { priority: 1, weight: 0 }, { priority: 2, weight: 1 }, ]); }); test("by weight", () => { - expect(sort([ - { weight: 1, priority: 0 }, - { weight: 2, priority: 0 }, - ])).toEqual([ + expect( + sort([ + { weight: 1, priority: 0 }, + { weight: 2, priority: 0 }, + ]), + ).toEqual([ { weight: 2, priority: 0 }, { weight: 1, priority: 0 }, ]); - expect(sort([ - { weight: 2, priority: 0 }, - { weight: 1, priority: 0 }, - ])).toEqual([ + expect( + sort([ + { weight: 2, priority: 0 }, + { weight: 1, priority: 0 }, + ]), + ).toEqual([ { weight: 2, priority: 0 }, { weight: 1, priority: 0 }, ]); diff --git a/packages/resource-binding/README.md b/packages/resource-binding/README.md index cf13b04f6..6c4ee530e 100644 --- a/packages/resource-binding/README.md +++ b/packages/resource-binding/README.md @@ -11,7 +11,8 @@ Resource is optional and will be chosen by the server if omitted. ### string ```js -const { xmpp } = require("@xmpp/client"); +import { xmpp } from "@xmpp/client"; + const client = xmpp({ resource: "laptop" }); ``` @@ -27,7 +28,8 @@ Uses cases: - Perform an asynchronous operation to get the resource ```js -const { xmpp } = require("@xmpp/client"); +import { xmpp } from "@xmpp/client"; + const client = xmpp({ resource: bindResource }); async function bindResource(bind) { diff --git a/packages/resource-binding/index.js b/packages/resource-binding/index.js index 78a127b35..5a0372e0d 100644 --- a/packages/resource-binding/index.js +++ b/packages/resource-binding/index.js @@ -1,6 +1,4 @@ -"use strict"; - -const xml = require("@xmpp/xml"); +import xml from "@xmpp/xml"; /* * References @@ -30,9 +28,9 @@ function route({ iqCaller }, resource) { }; } -module.exports = function resourceBinding( +export default function resourceBinding( { streamFeatures, iqCaller }, resource, ) { streamFeatures.use("bind", NS, route({ iqCaller }, resource)); -}; +} diff --git a/packages/resource-binding/package.json b/packages/resource-binding/package.json index 3f9080fb1..a436f8940 100644 --- a/packages/resource-binding/package.json +++ b/packages/resource-binding/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "bind", @@ -16,7 +16,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/resource-binding/test.js b/packages/resource-binding/test.js index f4603b111..99fd7f990 100644 --- a/packages/resource-binding/test.js +++ b/packages/resource-binding/test.js @@ -1,6 +1,4 @@ -"use strict"; - -const { mockClient, delay } = require("@xmpp/test"); +import { mockClient, delay } from "@xmpp/test"; test("without resource", async () => { const resource = Math.random().toString(); @@ -47,9 +45,11 @@ test("with string resource", async () => { ); const child = await entity.catchOutgoingSet(); - expect(child).toEqual( - {resource} - ); + expect(child).toEqual( + + {resource} + , + ); await delay(); @@ -81,9 +81,11 @@ test("with function resource", async () => { ); const child = await entity.catchOutgoingSet(); - expect(child).toEqual( - {resource} - ); + expect(child).toEqual( + + {resource} + , + ); await delay(); diff --git a/packages/sasl-anonymous/index.js b/packages/sasl-anonymous/index.js index 35109c461..90935fb76 100644 --- a/packages/sasl-anonymous/index.js +++ b/packages/sasl-anonymous/index.js @@ -1,12 +1,10 @@ -"use strict"; +import mech from "sasl-anonymous"; /** * [XEP-0175: Best Practices for Use of SASL ANONYMOUS](https://xmpp.org/extensions/xep-0175.html) * [RFC-4504: Anonymous Simple Authentication and Security Layer (SASL) Mechanism](https://tools.ietf.org/html/rfc4505) */ -const mech = require("sasl-anonymous"); - -module.exports = function saslAnonymous(sasl) { +export default function saslAnonymous(sasl) { sasl.use(mech); -}; +} diff --git a/packages/sasl-anonymous/package.json b/packages/sasl-anonymous/package.json index ca786f89f..f1c536a8e 100644 --- a/packages/sasl-anonymous/package.json +++ b/packages/sasl-anonymous/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "sasl", @@ -16,7 +16,7 @@ "sasl-anonymous": "^0.1.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/sasl-plain/index.js b/packages/sasl-plain/index.js index a6f5b0450..e6bec8c26 100644 --- a/packages/sasl-plain/index.js +++ b/packages/sasl-plain/index.js @@ -1,7 +1,5 @@ -"use strict"; +import mech from "sasl-plain"; -const mech = require("sasl-plain"); - -module.exports = function saslPlain(sasl) { +export default function saslPlain(sasl) { sasl.use(mech); -}; +} diff --git a/packages/sasl-plain/package.json b/packages/sasl-plain/package.json index b8ac7f6d1..cbf6ebc1f 100644 --- a/packages/sasl-plain/package.json +++ b/packages/sasl-plain/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "sasl", @@ -16,7 +16,7 @@ "sasl-plain": "^0.1.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/sasl-scram-sha-1/index.js b/packages/sasl-scram-sha-1/index.js index 10d67c7e4..e789e8ebc 100644 --- a/packages/sasl-scram-sha-1/index.js +++ b/packages/sasl-scram-sha-1/index.js @@ -1,7 +1,5 @@ -"use strict"; +import mech from "sasl-scram-sha-1"; -const mech = require("sasl-scram-sha-1"); - -module.exports = function saslScramSha1(sasl) { +export default function saslScramSha1(sasl) { sasl.use(mech); -}; +} diff --git a/packages/sasl-scram-sha-1/package.json b/packages/sasl-scram-sha-1/package.json index c7debced6..429c866b9 100644 --- a/packages/sasl-scram-sha-1/package.json +++ b/packages/sasl-scram-sha-1/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "sasl", @@ -16,7 +16,7 @@ "sasl-scram-sha-1": "^1.3.0" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/sasl/README.md b/packages/sasl/README.md index 499e92748..c29bccd22 100644 --- a/packages/sasl/README.md +++ b/packages/sasl/README.md @@ -9,11 +9,14 @@ Included and enabled in `@xmpp/client`. ### object ```js -const {xmpp} = require('@xmpp/client') -const client = xmpp({credentials: { - username: 'foo', - password: 'bar' -}) +import { xmpp } from "@xmpp/client"; + +const client = xmpp({ + credentials: { + username: "foo", + password: "bar", + }, +}); ``` ### function @@ -29,7 +32,8 @@ Uses cases: - Perform an asynchronous operation to get credentials ```js -const { xmpp } = require("@xmpp/client"); +import { xmpp } from "@xmpp/client"; + const client = xmpp({ credentials: authenticate }); async function authenticate(auth, mechanism) { diff --git a/packages/sasl/index.js b/packages/sasl/index.js index 340774227..42f6297d7 100644 --- a/packages/sasl/index.js +++ b/packages/sasl/index.js @@ -1,9 +1,7 @@ -"use strict"; - -const { encode, decode } = require("@xmpp/base64"); -const SASLError = require("./lib/SASLError"); -const xml = require("@xmpp/xml"); -const SASLFactory = require("saslmechanisms"); +import { encode, decode } from "@xmpp/base64"; +import SASLError from "./lib/SASLError.js"; +import xml from "@xmpp/xml"; +import SASLFactory from "saslmechanisms"; // https://xmpp.org/rfcs/rfc6120.html#sasl @@ -76,7 +74,7 @@ async function authenticate(SASL, entity, mechname, credentials) { }); } -module.exports = function sasl({ streamFeatures }, credentials) { +export default function sasl({ streamFeatures }, credentials) { const SASL = new SASLFactory(); streamFeatures.use("mechanisms", NS, async ({ stanza, entity }) => { @@ -109,4 +107,4 @@ module.exports = function sasl({ streamFeatures }, credentials) { return SASL.use(...args); }, }; -}; +} diff --git a/packages/sasl/lib/SASLError.js b/packages/sasl/lib/SASLError.js index d7f17efbe..acb73194d 100644 --- a/packages/sasl/lib/SASLError.js +++ b/packages/sasl/lib/SASLError.js @@ -1,6 +1,4 @@ -"use strict"; - -const XMPPError = require("@xmpp/error"); +import XMPPError from "@xmpp/error"; // https://xmpp.org/rfcs/rfc6120.html#sasl-errors @@ -11,4 +9,4 @@ class SASLError extends XMPPError { } } -module.exports = SASLError; +export default SASLError; diff --git a/packages/sasl/package.json b/packages/sasl/package.json index 9632031f4..7569f138f 100644 --- a/packages/sasl/package.json +++ b/packages/sasl/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "sasl" @@ -18,7 +18,7 @@ "saslmechanisms": "^0.1.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/sasl/test.js b/packages/sasl/test.js index 071038825..2521ada18 100644 --- a/packages/sasl/test.js +++ b/packages/sasl/test.js @@ -1,7 +1,5 @@ -"use strict"; - -const { mockClient, promise } = require("@xmpp/test"); -const parse = require("@xmpp/xml/lib/parse.js"); +import { mockClient, promise } from "@xmpp/test"; +import parse from "@xmpp/xml/lib/parse.js"; const username = "foo"; const password = "bar"; diff --git a/packages/session-establishment/index.js b/packages/session-establishment/index.js index 0fe8ac765..4df331192 100644 --- a/packages/session-establishment/index.js +++ b/packages/session-establishment/index.js @@ -1,15 +1,13 @@ -"use strict"; - -const xml = require("@xmpp/xml"); +import xml from "@xmpp/xml"; // https://tools.ietf.org/html/draft-cridland-xmpp-session-01 const NS = "urn:ietf:params:xml:ns:xmpp-session"; -module.exports = function sessionEstablishment({ iqCaller, streamFeatures }) { +export default function sessionEstablishment({ iqCaller, streamFeatures }) { streamFeatures.use("session", NS, async (context, next, feature) => { if (feature.getChild("optional")) return next(); await iqCaller.set(xml("session", NS)); return next(); }); -}; +} diff --git a/packages/session-establishment/package.json b/packages/session-establishment/package.json index f7af8fd87..647d1ea52 100644 --- a/packages/session-establishment/package.json +++ b/packages/session-establishment/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "session", @@ -16,7 +16,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/session-establishment/test.js b/packages/session-establishment/test.js index aeac9d073..5418ace1b 100644 --- a/packages/session-establishment/test.js +++ b/packages/session-establishment/test.js @@ -1,6 +1,4 @@ -"use strict"; - -const { mockClient, promise, timeout } = require("@xmpp/test"); +import { mockClient, promise, timeout } from "@xmpp/test"; test("mandatory", async () => { const { entity } = mockClient(); @@ -14,7 +12,9 @@ test("mandatory", async () => { entity.scheduleIncomingResult(); const child = await entity.catchOutgoingSet(); - expect(child).toEqual(); + expect(child).toEqual( + , + ); await promise(entity, "online"); }); diff --git a/packages/starttls/client.js b/packages/starttls/client.js index ec71bc761..0ee7c2c43 100644 --- a/packages/starttls/client.js +++ b/packages/starttls/client.js @@ -1,7 +1,5 @@ -"use strict"; - -const xml = require("@xmpp/xml"); -const { canUpgrade, upgrade } = require("./starttls"); +import xml from "@xmpp/xml"; +import { canUpgrade, upgrade } from "./starttls.js"; /* * References @@ -19,7 +17,7 @@ async function negotiate(entity) { throw new Error("STARTTLS_FAILURE"); } -module.exports = function starttls({ streamFeatures }) { +export default function starttls({ streamFeatures }) { return streamFeatures.use("starttls", NS, async ({ entity }, next) => { const { socket, options } = entity; if (!canUpgrade(socket)) { @@ -32,4 +30,4 @@ module.exports = function starttls({ streamFeatures }) { await entity.restart(); }); -}; +} diff --git a/packages/starttls/package.json b/packages/starttls/package.json index 31c829447..8ceab600c 100644 --- a/packages/starttls/package.json +++ b/packages/starttls/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "STARTTLS" @@ -17,7 +17,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/starttls/starttls.js b/packages/starttls/starttls.js index f7b919ab4..0924fd2bd 100644 --- a/packages/starttls/starttls.js +++ b/packages/starttls/starttls.js @@ -1,22 +1,16 @@ -"use strict"; +import tls from "tls"; +import net from "net"; +import { promise } from "@xmpp/events"; +import Socket from "@xmpp/tls/lib/Socket.js"; -const tls = require("tls"); -const net = require("net"); -const { promise } = require("@xmpp/events"); -const Socket = require("@xmpp/tls/lib/Socket"); - -function canUpgrade(socket) { +export function canUpgrade(socket) { return socket instanceof net.Socket && !(socket instanceof tls.TLSSocket); } -module.exports.canUpgrade = canUpgrade; - -async function upgrade(socket, options = {}) { +export async function upgrade(socket, options = {}) { const tlsSocket = new Socket(); tlsSocket.connect({ socket, ...options }); await promise(tlsSocket, "connect"); return tlsSocket; } - -module.exports.upgrade = upgrade; diff --git a/packages/starttls/starttls.test.js b/packages/starttls/starttls.test.js index 0bb11f222..3cad7750c 100644 --- a/packages/starttls/starttls.test.js +++ b/packages/starttls/starttls.test.js @@ -1,9 +1,8 @@ -"use strict"; - -const tls = require("tls"); -const { canUpgrade } = require("./starttls"); -const net = require("net"); -const WebSocket = require("../websocket/lib/Socket"); +import tls from "tls"; +import { canUpgrade } from "./starttls.js"; +import net from "net"; +// eslint-disable-next-line n/no-extraneous-import +import WebSocket from "@xmpp/websocket/lib/Socket.js"; test("canUpgrade", () => { expect(canUpgrade(new WebSocket())).toBe(false); diff --git a/packages/starttls/test.js b/packages/starttls/test.js index 7fc0b2408..6c5e618f2 100644 --- a/packages/starttls/test.js +++ b/packages/starttls/test.js @@ -1,11 +1,9 @@ -"use strict"; - jest.mock("tls"); -const { mockClient, promise, delay } = require("@xmpp/test"); -const tls = require("tls"); -const net = require("net"); -const EventEmitter = require("events"); +import { mockClient, promise, delay } from "@xmpp/test"; +import tls from "tls"; +import net from "net"; +import { EventEmitter } from "@xmpp/events"; function mockSocket() { const socket = new net.Socket(); diff --git a/packages/stream-features/index.js b/packages/stream-features/index.js index e891460a2..bf41a2db8 100644 --- a/packages/stream-features/index.js +++ b/packages/stream-features/index.js @@ -1,4 +1,4 @@ -"use strict"; +import route from "./route.js"; /** * References @@ -7,9 +7,7 @@ * https://xmpp.org/registrar/stream-features.html XML Stream Features */ -const route = require("./route"); - -module.exports = function streamFeatures({ middleware }) { +export default function streamFeatures({ middleware }) { middleware.use(route()); function use(name, xmlns, handler) { @@ -26,4 +24,4 @@ module.exports = function streamFeatures({ middleware }) { return { use, }; -}; +} diff --git a/packages/stream-features/package.json b/packages/stream-features/package.json index 715a562ef..279524d68 100644 --- a/packages/stream-features/package.json +++ b/packages/stream-features/package.json @@ -6,14 +6,14 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "stream", "features" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/stream-features/route.js b/packages/stream-features/route.js index bd6d64b59..03e6ceb88 100644 --- a/packages/stream-features/route.js +++ b/packages/stream-features/route.js @@ -1,6 +1,4 @@ -"use strict"; - -module.exports = function route() { +export default function route() { return async ({ stanza, entity }, next) => { if (!stanza.is("features", "http://etherx.jabber.org/streams")) return next(); @@ -8,4 +6,4 @@ module.exports = function route() { const prevent = await next(); if (!prevent && entity.jid) entity._status("online", entity.jid); }; -}; +} diff --git a/packages/stream-features/test.js b/packages/stream-features/test.js index 840b887fa..e0900d533 100644 --- a/packages/stream-features/test.js +++ b/packages/stream-features/test.js @@ -1,7 +1,5 @@ -"use strict"; - -const streamfeatures = require("."); -const { xml } = require("@xmpp/test"); +import streamfeatures from "./index.js"; +import { xml } from "@xmpp/test"; test.skip("selectFeature", () => { const features = []; diff --git a/packages/stream-management/index.js b/packages/stream-management/index.js index f7deb0378..4ec2bff72 100644 --- a/packages/stream-management/index.js +++ b/packages/stream-management/index.js @@ -1,6 +1,4 @@ -"use strict"; - -const xml = require("@xmpp/xml"); +import xml from "@xmpp/xml"; // https://xmpp.org/extensions/xep-0198.html @@ -40,7 +38,7 @@ async function resume(entity, h, previd) { return response; } -module.exports = function streamManagement({ +export default function streamManagement({ streamFeatures, entity, middleware, @@ -128,4 +126,4 @@ module.exports = function streamManagement({ }); return sm; -}; +} diff --git a/packages/stream-management/package.json b/packages/stream-management/package.json index 6d8f985bc..af53447fc 100644 --- a/packages/stream-management/package.json +++ b/packages/stream-management/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "stream", @@ -16,7 +16,7 @@ "@xmpp/xml": "^0.13.2" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/stream-management/test.js b/packages/stream-management/test.js index af706e4bf..7f2e81cf0 100644 --- a/packages/stream-management/test.js +++ b/packages/stream-management/test.js @@ -1,6 +1,4 @@ -"use strict"; - -const { mockClient } = require("@xmpp/test"); +import { mockClient } from "@xmpp/test"; function tick() { return new Promise((resolve) => { @@ -19,7 +17,9 @@ test("enable - enabled", async () => { entity.streamManagement.outbound = 45; - expect(await entity.catchOutgoing()).toEqual(); + expect(await entity.catchOutgoing()).toEqual( + , + ); await tick(); @@ -72,7 +72,9 @@ test("enable - message - enabled", async () => { entity.streamManagement.outbound = 45; - expect(await entity.catchOutgoing()).toEqual(); + expect(await entity.catchOutgoing()).toEqual( + , + ); expect(entity.streamManagement.outbound).toBe(0); expect(entity.streamManagement.enabled).toBe(false); @@ -111,7 +113,9 @@ test("enable - failed", async () => { entity.streamManagement.outbound = 45; - expect(await entity.catchOutgoing()).toEqual(); + expect(await entity.catchOutgoing()).toEqual( + , + ); expect(entity.streamManagement.outbound).toBe(0); entity.streamManagement.enabled = true; @@ -139,7 +143,9 @@ test("resume - resumed", async () => { entity.streamManagement.outbound = 45; - expect(await entity.catchOutgoing()).toEqual(); + expect(await entity.catchOutgoing()).toEqual( + , + ); expect(entity.streamManagement.enabled).toBe(false); @@ -167,7 +173,9 @@ test("resume - failed", async () => { , ); - expect(await entity.catchOutgoing()).toEqual(); + expect(await entity.catchOutgoing()).toEqual( + , + ); entity.mockInput(); diff --git a/packages/tcp/index.js b/packages/tcp/index.js index 228e6feda..1debaa42a 100644 --- a/packages/tcp/index.js +++ b/packages/tcp/index.js @@ -1,7 +1,5 @@ -"use strict"; +import ConnectionTCP from "./lib/Connection.js"; -const ConnectionTCP = require("./lib/Connection"); - -module.exports = function tcp({ entity }) { +export default function tcp({ entity }) { entity.transports.push(ConnectionTCP); -}; +} diff --git a/packages/tcp/lib/Connection.js b/packages/tcp/lib/Connection.js index 71c4789b2..797041e47 100644 --- a/packages/tcp/lib/Connection.js +++ b/packages/tcp/lib/Connection.js @@ -1,6 +1,4 @@ -"use strict"; - -const Connection = require("@xmpp/connection-tcp"); +import Connection from "@xmpp/connection-tcp"; class ConnectionTCP extends Connection { socketParameters(service) { @@ -13,4 +11,4 @@ class ConnectionTCP extends Connection { ConnectionTCP.prototype.NS = "jabber:client"; -module.exports = ConnectionTCP; +export default ConnectionTCP; diff --git a/packages/tcp/package.json b/packages/tcp/package.json index 7ec589774..4f7ca405b 100644 --- a/packages/tcp/package.json +++ b/packages/tcp/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "dependencies": { "@xmpp/connection-tcp": "^0.13.2" }, @@ -15,7 +15,7 @@ "tcp" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/tcp/test.js b/packages/tcp/test.js index 3b49cb517..c7307a52f 100644 --- a/packages/tcp/test.js +++ b/packages/tcp/test.js @@ -1,6 +1,4 @@ -"use strict"; - -const ConnectionTCP = require("./lib/Connection"); +import ConnectionTCP from "./lib/Connection.js"; test("socketParameters()", () => { let params; diff --git a/packages/test/client.js b/packages/test/client.js index d4be7a9cf..103edfa3c 100644 --- a/packages/test/client.js +++ b/packages/test/client.js @@ -1,11 +1,9 @@ -"use strict"; +import { Client } from "@xmpp/client-core"; +import JID from "@xmpp/jid"; +import mockSocket from "./mockSocket"; -const { Client } = require("../client-core"); -const JID = require("@xmpp/jid"); -const mockSocket = require("./mockSocket"); - -module.exports = function client(entity = new Client()) { +export default function client(entity = new Client()) { entity.socket = mockSocket(); entity.jid = new JID("foo@bar/test"); return entity; -}; +} diff --git a/packages/test/context.js b/packages/test/context.js index facfe4f46..52dae74d7 100644 --- a/packages/test/context.js +++ b/packages/test/context.js @@ -1,14 +1,12 @@ -"use strict"; +import client from "./client.js"; +import { promise } from "@xmpp/events"; +import { xml } from "@xmpp/xml"; +import debug from "@xmpp/debug"; +import JID from "@xmpp/jid"; +import mockSocket from "./mockSocket.js"; +import clone from "ltx/lib/clone.js"; -const client = require("./client"); -const { promise } = require("@xmpp/events"); -const xml = require("@xmpp/xml"); -const debug = require("@xmpp/debug"); -const JID = require("@xmpp/jid"); -const mockSocket = require("./mockSocket"); -const clone = require("ltx/lib/clone.js"); - -module.exports = function context(entity = client()) { +export default function context(entity = client()) { debug(entity); entity.socket = mockSocket(); @@ -148,4 +146,4 @@ module.exports = function context(entity = client()) { }; return ctx; -}; +} diff --git a/packages/test/index.js b/packages/test/index.js index 78a61145a..0c534d586 100644 --- a/packages/test/index.js +++ b/packages/test/index.js @@ -1,30 +1,22 @@ -"use strict"; +import context from "./context.js"; +import xml from "@xmpp/xml"; +import jid from "@xmpp/jid"; +import mockClient from "./mockClient.js"; +import { delay, promise, timeout } from "@xmpp/events"; -const context = require("./context"); -const xml = require("@xmpp/xml"); -const jid = require("@xmpp/jid"); -const mockClient = require("./mockClient"); -const { delay, promise, timeout } = require("@xmpp/events"); +export { context, xml, jid, jid as JID, mockClient, delay, promise, timeout }; -module.exports.context = context; -module.exports.xml = xml; -module.exports.jid = jid; -module.exports.JID = jid; -module.exports.mockClient = mockClient; -module.exports.delay = delay; -module.exports.promise = promise; -module.exports.timeout = timeout; -module.exports.mockInput = (entity, el) => { +export function mockInput(entity, el) { entity.emit("input", el.toString()); entity._onElement(el); -}; +} -module.exports.promiseSend = async (entity) => { +export async function promiseSend(entity) { const stanza = await promise(entity, "send", ""); delete stanza.attrs.xmlns; return stanza; -}; +} -module.exports.promiseError = (entity) => { +export function promiseError(entity) { return promise(entity, "error", ""); -}; +} diff --git a/packages/test/mockClient.js b/packages/test/mockClient.js index f090d2385..c7025edd5 100644 --- a/packages/test/mockClient.js +++ b/packages/test/mockClient.js @@ -1,12 +1,10 @@ -"use strict"; +import { client } from "@xmpp/client"; +import Connection from "@xmpp/connection"; +import context from "./context.js"; -const { client } = require("@xmpp/client"); -const Connection = require("@xmpp/connection"); -const context = require("./context"); - -module.exports = function mockClient(options) { +export default function mockClient(options) { const xmpp = client(options); xmpp.send = Connection.prototype.send; const ctx = context(xmpp); return Object.assign(xmpp, ctx); -}; +} diff --git a/packages/test/mockSocket.js b/packages/test/mockSocket.js index 69d59ad29..d2ca0e59a 100644 --- a/packages/test/mockSocket.js +++ b/packages/test/mockSocket.js @@ -1,6 +1,4 @@ -"use strict"; - -const { EventEmitter } = require("@xmpp/events"); +import { EventEmitter } from "@xmpp/events"; class MockSocket extends EventEmitter { write(data, cb) { @@ -8,6 +6,6 @@ class MockSocket extends EventEmitter { } } -module.exports = function mockSocket() { +export default function mockSocket() { return new MockSocket(); -}; +} diff --git a/packages/test/package.json b/packages/test/package.json index de0128b37..b984e12d9 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -6,15 +6,16 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "test" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "dependencies": { + "@xmpp/client-core": "^0.13.2", "@xmpp/client": "^0.13.2", "@xmpp/connection": "^0.13.2", "@xmpp/debug": "^0.13.2", diff --git a/packages/time/README.md b/packages/time/README.md index 58d3f47e4..922d31563 100644 --- a/packages/time/README.md +++ b/packages/time/README.md @@ -9,7 +9,7 @@ XMPP [Date and Time Profiles](https://xmpp.org/extensions/xep-0082.html) for Jav ## Usage ```javascript -const time = require("@xmpp/time"); +import * as time from "@xmpp/time"; time.date(); // '2016-11-18' time.time(); // '20:45:30.221Z' diff --git a/packages/time/index.js b/packages/time/index.js index 285b65570..2ea2f7ce3 100644 --- a/packages/time/index.js +++ b/packages/time/index.js @@ -1,5 +1,3 @@ -"use strict"; - function date(d = new Date()) { if (typeof d === "string") { d = new Date(d); @@ -42,7 +40,4 @@ function offset(d = new Date()) { return formatOffset(d.getTimezoneOffset()); } -module.exports.date = date; -module.exports.time = time; -module.exports.datetime = datetime; -module.exports.offset = offset; +export { date, time, datetime, offset }; diff --git a/packages/time/package.json b/packages/time/package.json index 7bb410496..317a0b890 100644 --- a/packages/time/package.json +++ b/packages/time/package.json @@ -6,14 +6,14 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "time", "date" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/time/test.js b/packages/time/test.js index ced5edbe6..dcb5b9c24 100644 --- a/packages/time/test.js +++ b/packages/time/test.js @@ -1,6 +1,4 @@ -"use strict"; - -const time = require("."); +import * as time from "./index.js"; const s = "21 Jully 1969 02:56 UTC"; const d = new Date(s); diff --git a/packages/tls/index.js b/packages/tls/index.js index 8aabe7218..39940fb07 100644 --- a/packages/tls/index.js +++ b/packages/tls/index.js @@ -1,7 +1,5 @@ -"use strict"; +import ConnectionTLS from "./lib/Connection.js"; -const ConnectionTLS = require("./lib/Connection"); - -module.exports = function tls({ entity }) { +export default function tls({ entity }) { entity.transports.push(ConnectionTLS); -}; +} diff --git a/packages/tls/lib/Connection.js b/packages/tls/lib/Connection.js index c9557b569..c1fa7d23d 100644 --- a/packages/tls/lib/Connection.js +++ b/packages/tls/lib/Connection.js @@ -1,8 +1,6 @@ -"use strict"; - -const { parseURI } = require("@xmpp/connection/lib/util"); -const ConnectionTCP = require("@xmpp/connection-tcp"); -const Socket = require("./Socket.js"); +import { parseURI } from "@xmpp/connection/lib/util"; +import ConnectionTCP from "@xmpp/connection-tcp"; +import Socket from "./Socket.js"; class ConnectionTLS extends ConnectionTCP { socketParameters(service) { @@ -19,4 +17,4 @@ class ConnectionTLS extends ConnectionTCP { ConnectionTLS.prototype.Socket = Socket; ConnectionTLS.prototype.NS = "jabber:client"; -module.exports = ConnectionTLS; +export default ConnectionTLS; diff --git a/packages/tls/lib/Socket.js b/packages/tls/lib/Socket.js index f6f9d781c..0f0c5ad4a 100644 --- a/packages/tls/lib/Socket.js +++ b/packages/tls/lib/Socket.js @@ -1,7 +1,5 @@ -"use strict"; - -const tls = require("tls"); -const EventEmitter = require("events"); +import tls from "tls"; +import { EventEmitter } from "events"; class Socket extends EventEmitter { constructor() { @@ -66,4 +64,4 @@ class Socket extends EventEmitter { } } -module.exports = Socket; +export default Socket; diff --git a/packages/tls/package.json b/packages/tls/package.json index 662d88198..ac43574bf 100644 --- a/packages/tls/package.json +++ b/packages/tls/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "dependencies": { "@xmpp/connection": "^0.13.2", "@xmpp/connection-tcp": "^0.13.2" @@ -16,7 +16,7 @@ "tls" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/tls/test.js b/packages/tls/test.js index e745c2258..064435626 100644 --- a/packages/tls/test.js +++ b/packages/tls/test.js @@ -1,10 +1,9 @@ -"use strict"; +import ConnectionTLS from "./lib/Connection.js"; -const ConnectionTLS = require("./lib/Connection"); -const tls = require("tls"); -const { promise } = require("@xmpp/test"); -// eslint-disable-next-line n/no-extraneous-require -const selfsigned = require("selfsigned"); +import tls from "tls"; +import { promise } from "@xmpp/test"; +// eslint-disable-next-line n/no-extraneous-import +import selfsigned from "selfsigned"; test("socketParameters()", () => { expect(ConnectionTLS.prototype.socketParameters("xmpps://foo")).toEqual({ @@ -17,9 +16,13 @@ test("socketParameters()", () => { host: "foo", }); - expect(ConnectionTLS.prototype.socketParameters("xmpp://foo")).toEqual(undefined); + expect(ConnectionTLS.prototype.socketParameters("xmpp://foo")).toEqual( + undefined, + ); - expect(ConnectionTLS.prototype.socketParameters("xmpp://foo:1234")).toEqual(undefined); + expect(ConnectionTLS.prototype.socketParameters("xmpp://foo:1234")).toEqual( + undefined, + ); }); test("rejects expired certificates", async () => { diff --git a/packages/uri/README.md b/packages/uri/README.md index e76e143f1..1ef3f9b90 100644 --- a/packages/uri/README.md +++ b/packages/uri/README.md @@ -6,16 +6,16 @@ Only parsing is supported at the moment. ## Install -``` +```sh npm install @xmpp/uri ``` ## Usage ```javascript -const URI = require('@xmpp/uri') +import { parse } from "@xmpp/uri"; -URI.parse('xmpp://guest@example.com/support@example.com/truc?message;subject=Hello%20World') +parse('xmpp://guest@example.com/support@example.com/truc?message;subject=Hello%20World'); { authority: jid('guest@example.com'), // see https://github.com/xmppjs/xmpp.js/tree/main/packages/jid diff --git a/packages/uri/index.js b/packages/uri/index.js index eb52774e9..38b22f3b7 100644 --- a/packages/uri/index.js +++ b/packages/uri/index.js @@ -1,8 +1,6 @@ -"use strict"; - -const jid = require("@xmpp/jid"); -const { IRI } = require("iri"); -const querystring = require("querystring"); +import jid from "@xmpp/jid"; +import { IRI } from "iri"; +import querystring from "querystring"; function findQueryType(params) { return Object.getOwnPropertyNames(params).find((k) => { @@ -10,7 +8,7 @@ function findQueryType(params) { }); } -function parse(str) { +export function parse(str) { const iri = new IRI(str); const uri = {}; @@ -39,5 +37,3 @@ function parse(str) { return uri; } - -module.exports.parse = parse; diff --git a/packages/uri/package.json b/packages/uri/package.json index 41d9cbe41..be9aea1a9 100644 --- a/packages/uri/package.json +++ b/packages/uri/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "URI" @@ -16,7 +16,7 @@ "iri": "^1.3.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/uri/test.js b/packages/uri/test.js index 5dab6ab14..5834fb630 100644 --- a/packages/uri/test.js +++ b/packages/uri/test.js @@ -1,12 +1,12 @@ -"use strict"; - -const { parse } = require("."); -const jid = require("@xmpp/jid"); +import { parse } from "./index.js"; +import jid from "@xmpp/jid"; test("parse", () => { - expect(parse( - "xmpp://guest@example.com/support@example.com/truc?message;subject=Hello%20World", - )).toEqual({ + expect( + parse( + "xmpp://guest@example.com/support@example.com/truc?message;subject=Hello%20World", + ), + ).toEqual({ authority: jid("guest@example.com"), path: jid("support@example.com/truc"), query: { @@ -19,9 +19,11 @@ test("parse", () => { expect(jid("foobar")).toEqual(jid("foobar")); - expect(parse( - "xmpp:support@example.com/truc?message;subject=Hello%20World;body=foobar", - )).toEqual({ + expect( + parse( + "xmpp:support@example.com/truc?message;subject=Hello%20World;body=foobar", + ), + ).toEqual({ path: jid("support@example.com/truc"), query: { type: "message", diff --git a/packages/websocket/README.md b/packages/websocket/README.md index 42842ee96..8bc5e2b0a 100644 --- a/packages/websocket/README.md +++ b/packages/websocket/README.md @@ -3,3 +3,7 @@ WebSocket transport for `@xmpp/client`. Included and enabled in `@xmpp/client`. + +## References + +[RFC 7395 An Extensible Messaging and Presence Protocol (XMPP) Subprotocol for WebSocket](https://datatracker.ietf.org/doc/html/rfc7395) diff --git a/packages/websocket/index.js b/packages/websocket/index.js index def28bf43..6688bfbe1 100644 --- a/packages/websocket/index.js +++ b/packages/websocket/index.js @@ -1,7 +1,5 @@ -"use strict"; +import ConnectionWebSocket from "./lib/Connection.js"; -const ConnectionWebSocket = require("./lib/Connection"); - -module.exports = function websocket({ entity }) { +export default function websocket({ entity }) { entity.transports.push(ConnectionWebSocket); -}; +} diff --git a/packages/websocket/lib/Connection.js b/packages/websocket/lib/Connection.js index 4df45f45c..335b76616 100644 --- a/packages/websocket/lib/Connection.js +++ b/packages/websocket/lib/Connection.js @@ -1,9 +1,7 @@ -"use strict"; - -const Socket = require("./Socket"); -const Connection = require("@xmpp/connection"); -const xml = require("@xmpp/xml"); -const FramedParser = require("./FramedParser"); +import Socket from "./Socket.js"; +import Connection from "@xmpp/connection"; +import xml from "@xmpp/xml"; +import FramedParser from "./FramedParser.js"; const NS_FRAMING = "urn:ietf:params:xml:ns:xmpp-framing"; @@ -52,4 +50,4 @@ ConnectionWebSocket.prototype.Socket = Socket; ConnectionWebSocket.prototype.NS = "jabber:client"; ConnectionWebSocket.prototype.Parser = FramedParser; -module.exports = ConnectionWebSocket; +export default ConnectionWebSocket; diff --git a/packages/websocket/lib/FramedParser.js b/packages/websocket/lib/FramedParser.js index 18ee9ee20..4d80e1c2c 100644 --- a/packages/websocket/lib/FramedParser.js +++ b/packages/websocket/lib/FramedParser.js @@ -1,8 +1,6 @@ -"use strict"; +import { Parser, Element, XMLError } from "@xmpp/xml"; -const { Parser, Element, XMLError } = require("@xmpp/xml"); - -module.exports = class FramedParser extends Parser { +export default class FramedParser extends Parser { onStartElement(name, attrs) { const element = new Element(name, attrs); @@ -38,4 +36,4 @@ module.exports = class FramedParser extends Parser { this.cursor = null; } -}; +} diff --git a/packages/websocket/lib/Socket.js b/packages/websocket/lib/Socket.js index a1b585d19..ba703aae1 100644 --- a/packages/websocket/lib/Socket.js +++ b/packages/websocket/lib/Socket.js @@ -1,13 +1,13 @@ -"use strict"; +import WS from "ws"; -const WS = require("ws"); // eslint-disable-next-line n/no-unsupported-features/node-builtins const WebSocket = globalThis.WebSocket || WS; -const EventEmitter = require("events"); + +import { EventEmitter } from "@xmpp/events"; const CODE = "ECONNERROR"; -class Socket extends EventEmitter { +export default class Socket extends EventEmitter { constructor() { super(); this.listeners = Object.create(null); @@ -76,5 +76,3 @@ class Socket extends EventEmitter { } } } - -module.exports = Socket; diff --git a/packages/websocket/package.json b/packages/websocket/package.json index 33240f065..eaf747956 100644 --- a/packages/websocket/package.json +++ b/packages/websocket/package.json @@ -6,9 +6,10 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "dependencies": { "@xmpp/connection": "^0.13.2", + "@xmpp/events": "^0.13.2", "@xmpp/xml": "^0.13.2", "ws": "^8.18.0" }, @@ -20,7 +21,7 @@ "websocket" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/websocket/test/FramedParser.js b/packages/websocket/test/FramedParser.js index c906417a9..ff1c786d5 100644 --- a/packages/websocket/test/FramedParser.js +++ b/packages/websocket/test/FramedParser.js @@ -1,14 +1,14 @@ -"use strict"; +import Parser from "../lib/FramedParser.js"; -const Parser = require("../lib/FramedParser"); - -test("framed parser", done => { +test("framed parser", (done) => { const parser = new Parser(); expect.assertions(4); parser.on("start", (el) => { - expect(el.toString()).toBe(''); + expect(el.toString()).toBe( + '', + ); }); parser.on("element", (el) => { @@ -17,7 +17,9 @@ test("framed parser", done => { }); parser.on("end", (el) => { - expect(el.toString()).toBe(''); + expect(el.toString()).toBe( + '', + ); done(); }); diff --git a/packages/websocket/test/test.js b/packages/websocket/test/test.js index 9c22532c9..742cd1c41 100644 --- a/packages/websocket/test/test.js +++ b/packages/websocket/test/test.js @@ -1,9 +1,7 @@ -"use strict"; - -const ConnectionWebSocket = require("../lib/Connection"); -const Socket = require("../lib/Socket"); -const EventEmitter = require("events"); -const xml = require("@xmpp/xml"); +import ConnectionWebSocket from "../lib/Connection.js"; +import Socket from "../lib/Socket.js"; +import { EventEmitter } from "@xmpp/events"; +import xml from "@xmpp/xml"; test("send() adds jabber:client xmlns", () => { const connection = new ConnectionWebSocket(); diff --git a/packages/xml/README.md b/packages/xml/README.md index 12ce34694..30597fe70 100644 --- a/packages/xml/README.md +++ b/packages/xml/README.md @@ -7,9 +7,9 @@ Note, if you're using `@xmpp/client` or `@xmpp/component`, you don't need to ins `npm install @xmpp/xml` ```js -const xml = require("@xmpp/xml"); -const { xml } = require("@xmpp/client"); -const { xml } = require("@xmpp/component"); +import xml from "@xmpp/xml"; +import { xml } from "@xmpp/client"; +import { xml } from "@xmpp/component"; ``` ## Writing @@ -19,7 +19,7 @@ There's 2 methods for writing XML with xmpp.js ### factory ```js -const xml = require("@xmpp/xml"); +import xml from "@xmpp/xml"; const recipient = "user@example.com"; const days = ["Monday", "Tuesday", "Wednesday"]; @@ -48,7 +48,7 @@ xml("time", { xmlns: "urn:xmpp:time" }); ```js /** @jsx xml */ -const xml = require("@xmpp/xml"); +import xml from "@xmpp/xml"; const recipient = "user@example.com"; const days = ["Monday", "Tuesday"]; @@ -232,8 +232,8 @@ See also [JSON Containers](https://xmpp.org/extensions/xep-0335.html) and [Simpl ⚠ Use with care. Untrusted input or substitutions can result in invalid XML and side effects. ```js -const { escapeXML, escapeXMLText }; -const parse = require("@xmpp/xml/lib/parse"); +import { escapeXML, escapeXMLText } from "@xmpp/xml"; +import parse from "@xmpp/xml/lib/parse.js"; const ctx = parse("hello world"); ctx.getChildText("body"); // hello world @@ -242,9 +242,6 @@ ctx.getChildText("body"); // hello world If you must use with untrusted input, escape it with `escapeXML` and `escapeXMLText`. ```js -const { escapeXML, escapeXMLText } = require("@xmpp/xml"); -const parse = require("@xmpp/xml/lib/parse"); - const message = parse(` ${escapeXMLText(body)} diff --git a/packages/xml/index.js b/packages/xml/index.js index b8ec232eb..efb06e0c7 100644 --- a/packages/xml/index.js +++ b/packages/xml/index.js @@ -1,23 +1,19 @@ -"use strict"; - -const Element = require("ltx/lib/Element.js"); -const createElement = require("ltx/lib/createElement.js"); -const Parser = require("./lib/Parser.js"); -const { +import Element from "ltx/lib/Element.js"; +import createElement from "ltx/lib/createElement.js"; +import Parser from "./lib/Parser.js"; +import { escapeXML, unescapeXML, escapeXMLText, unescapeXMLText, -} = require("ltx/lib/escape.js"); -const XMLError = require("./lib/XMLError.js"); +} from "ltx/lib/escape.js"; +import XMLError from "./lib/XMLError.js"; -function xml(...args) { +export default function xml(...args) { return createElement(...args); } -module.exports = xml; - -Object.assign(module.exports, { +Object.assign(xml, { Element, createElement, Parser, @@ -26,4 +22,17 @@ Object.assign(module.exports, { escapeXMLText, unescapeXMLText, XMLError, + xml, }); + +export { + Element, + createElement, + Parser, + escapeXML, + unescapeXML, + escapeXMLText, + unescapeXMLText, + XMLError, + xml, +}; diff --git a/packages/xml/lib/Parser.js b/packages/xml/lib/Parser.js index 5e8c857f4..69138e185 100644 --- a/packages/xml/lib/Parser.js +++ b/packages/xml/lib/Parser.js @@ -1,9 +1,7 @@ -"use strict"; - -const LtxParser = require("ltx/lib/parsers/ltx.js"); -const Element = require("ltx/lib/Element.js"); -const EventEmitter = require("events"); -const XMLError = require("./XMLError.js"); +import LtxParser from "ltx/lib/parsers/ltx.js"; +import Element from "ltx/lib/Element.js"; +import EventEmitter from "events"; +import XMLError from "./XMLError.js"; class Parser extends EventEmitter { constructor() { @@ -80,4 +78,4 @@ class Parser extends EventEmitter { Parser.XMLError = XMLError; -module.exports = Parser; +export default Parser; diff --git a/packages/xml/lib/XMLError.js b/packages/xml/lib/XMLError.js index 73f98e77f..5163f7be4 100644 --- a/packages/xml/lib/XMLError.js +++ b/packages/xml/lib/XMLError.js @@ -1,8 +1,6 @@ -"use strict"; - -module.exports = class XMLError extends Error { +export default class XMLError extends Error { constructor(...args) { super(...args); this.name = "XMLError"; } -}; +} diff --git a/packages/xml/lib/parse.js b/packages/xml/lib/parse.js index 3106981a8..44ee0e3b0 100644 --- a/packages/xml/lib/parse.js +++ b/packages/xml/lib/parse.js @@ -1,8 +1,6 @@ -"use strict"; +import Parser from "./Parser.js"; -const Parser = require("./Parser"); - -module.exports = function parse(data) { +export default function parse(data) { const p = new Parser(); let result = null; @@ -26,4 +24,4 @@ module.exports = function parse(data) { } else { return result; } -}; +} diff --git a/packages/xml/package.json b/packages/xml/package.json index 8559c552a..536f8eeb9 100644 --- a/packages/xml/package.json +++ b/packages/xml/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "stanza", @@ -18,7 +18,7 @@ "ltx": "^3.1.1" }, "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "publishConfig": { "access": "public" diff --git a/packages/xml/test/Parser.js b/packages/xml/test/Parser.js index eca7891ed..4cd3be92a 100644 --- a/packages/xml/test/Parser.js +++ b/packages/xml/test/Parser.js @@ -1,6 +1,4 @@ -"use strict"; - -const Parser = require("../lib/Parser"); +import Parser from "../lib/Parser.js"; test("stream parser", (done) => { const parser = new Parser(); diff --git a/packages/xml/test/xml.js b/packages/xml/test/xml.js index 083f09d13..2c473dd5c 100644 --- a/packages/xml/test/xml.js +++ b/packages/xml/test/xml.js @@ -1,15 +1,14 @@ -"use strict"; +import xml from "../index.js"; -const xml = require(".."); -const createElement = require("ltx/lib/createElement.js"); -const Element = require("ltx/lib/Element.js"); -const Parser = require("../lib/Parser.js"); -const { +import createElement from "ltx/lib/createElement.js"; +import Element from "ltx/lib/Element.js"; +import Parser from "../lib/Parser.js"; +import { escapeXML, unescapeXML, escapeXMLText, unescapeXMLText, -} = require("ltx/lib/escape.js"); +} from "ltx/lib/escape.js"; test("exports createElement", () => { expect(xml.createElement).toBe(createElement); diff --git a/packages/xmpp.js/package.json b/packages/xmpp.js/package.json index cc0733ca2..1b123e8d1 100644 --- a/packages/xmpp.js/package.json +++ b/packages/xmpp.js/package.json @@ -6,7 +6,7 @@ "bugs": "http://github.com/xmppjs/xmpp.js/issues", "version": "0.13.2", "license": "ISC", - "type": "commonjs", + "type": "module", "keywords": [ "XMPP", "jabber", @@ -14,7 +14,7 @@ "component" ], "engines": { - "node": ">= 14" + "node": ">= 14.13.1" }, "dependencies": { "@xmpp/base64": "^0.13.2", diff --git a/packages/xmpp.js/script.js b/packages/xmpp.js/script.js index 78a5f1433..a789a3d55 100644 --- a/packages/xmpp.js/script.js +++ b/packages/xmpp.js/script.js @@ -1,17 +1,21 @@ -"use strict"; +import fs from "fs"; +import path from "path"; -// Makes xmpp.js package require and exports all other packages +function readJSON(path) { + return JSON.parse(fs.readFileSync(path, "utf8")); +} + +const __dirname = import.meta.dirname; -const fs = require("fs"); -const path = require("path"); +// Makes xmpp.js package require and exports all other packages const packages = fs .readdirSync(path.join(__dirname, "..")) // For some reason there's a * file on travis .filter((p) => !["*"].includes(p) && !p.includes(".")) - .map((name) => require(path.join(__dirname, "..", name, "package.json"))); + .map((name) => readJSON(path.join(__dirname, "..", name, "package.json"))); -const xmppjsPackage = require(path.join(__dirname, "package.json")); +const xmppjsPackage = readJSON(path.join(__dirname, "package.json")); // Write package.json dependencies xmppjsPackage.dependencies = Object.fromEntries( @@ -19,6 +23,7 @@ xmppjsPackage.dependencies = Object.fromEntries( return [pkg.name, `^${pkg.version}`]; }), ); + fs.writeFileSync( path.join(__dirname, "package.json"), JSON.stringify(xmppjsPackage, null, 2) + "\n", diff --git a/packages/xmpp.js/test.js b/packages/xmpp.js/test.js index c822e8002..bb0cdb89a 100644 --- a/packages/xmpp.js/test.js +++ b/packages/xmpp.js/test.js @@ -1,7 +1,9 @@ -"use strict"; +import fs from "fs"; +import path from "path"; -const fs = require("fs"); -const path = require("path"); +function readJSON(path) { + return JSON.parse(fs.readFileSync(path, "utf8")); +} const packages = Object.fromEntries( fs @@ -9,14 +11,14 @@ const packages = Object.fromEntries( // For some reason there's a "*" file on travis .filter((p) => !["*"].includes(p) && !p.includes(".")) .map((dirname) => { - const { name, version } = require( + const { name, version } = readJSON( path.join(__dirname, "..", dirname, "package.json"), ); return [name, `^${version}`]; }), ); -const { dependencies } = require("./package.json"); +const { dependencies } = readJSON(path.join(__dirname, "package.json")); test("depends on all other packages", () => { expect(Object.keys(dependencies)).toHaveLength(Object.keys(packages).length); diff --git a/server/ctl.js b/server/ctl.js index 379528240..37b0a12df 100755 --- a/server/ctl.js +++ b/server/ctl.js @@ -1,8 +1,6 @@ #!/usr/bin/env node -"use strict"; - -const server = require("."); +import server from "./index.js"; const method = process.argv[2]; diff --git a/server/index.js b/server/index.js index e7fe82905..e9b405f9c 100644 --- a/server/index.js +++ b/server/index.js @@ -1,14 +1,18 @@ -"use strict"; - -const { promisify } = require("util"); -const path = require("path"); -const readFile = promisify(require("fs").readFile); -const exec = promisify(require("child_process").exec); -const removeFile = promisify(require("fs").unlink); -const net = require("net"); -const { promise, delay } = require("../packages/events"); -const selfsigned = require("selfsigned"); -const { writeFileSync } = require("fs"); +import { promisify } from "util"; +import path from "path"; +import fs, { writeFileSync } from "fs"; +import child_process from "child_process"; +import net from "net"; +// eslint-disable-next-line n/no-extraneous-import +import { promise, delay } from "@xmpp/events"; +import selfsigned from "selfsigned"; + +const __dirname = "./server"; +// const __dirname = import.meta.dirname; + +const readFile = promisify(fs.readFile); +const exec = promisify(child_process.exec); +const removeFile = promisify(fs.unlink); const DATA_PATH = path.join(__dirname); const PID_PATH = path.join(DATA_PATH, "prosody.pid"); @@ -115,11 +119,13 @@ async function restart(signal) { return _start(); } -exports.isPortOpen = isPortOpen; -exports.waitPortClose = waitPortClose; -exports.waitPortOpen = waitPortOpen; -exports.getPid = getPid; -exports.start = start; -exports.stop = stop; -exports.restart = restart; -exports.kill = kill; +export default { + isPortOpen, + waitPortClose, + waitPortOpen, + getPid, + start, + stop, + restart, + kill, +}; diff --git a/test/browser.js b/test/browser.js index 6323e7d49..31de18f4a 100644 --- a/test/browser.js +++ b/test/browser.js @@ -1,12 +1,10 @@ -"use strict"; +import { jid } from "../packages/client/index.js"; +import debug from "../packages/debug/index.js"; +import server from "../server/index.js"; -const { JSDOM } = require("jsdom"); -const fetch = require("node-fetch"); -const { readFileSync } = require("fs"); - -const { jid } = require("../packages/client"); -const debug = require("../packages/debug"); -const server = require("../server"); +import { JSDOM } from "jsdom"; +import fetch from "node-fetch"; +import { readFileSync } from "fs"; const username = "client"; const password = "foobar"; diff --git a/test/client.js b/test/client.js index 31f5d3fbc..167eb1f45 100644 --- a/test/client.js +++ b/test/client.js @@ -1,8 +1,6 @@ -"use strict"; - -const { client, xml, jid } = require("../packages/client"); -const debug = require("../packages/debug"); -const server = require("../server"); +import { client, xml, jid } from "../packages/client/index.js"; +import debug from "../packages/debug/index.js"; +import server from "../server/index.js"; const username = "client"; const password = "foobar"; diff --git a/test/component.js b/test/component.js index 54a612adb..aa922dc6a 100644 --- a/test/component.js +++ b/test/component.js @@ -1,8 +1,6 @@ -"use strict"; - -const { component, xml, jid } = require("../packages/component"); -const debug = require("../packages/debug"); -const server = require("../server"); +import { component, xml, jid } from "../packages/component/index.js"; +import debug from "../packages/debug/index.js"; +import server from "../server/index.js"; const password = "mysecretcomponentpassword"; const service = "xmpp://localhost:5347"; @@ -11,10 +9,10 @@ const options = { password, service, domain }; let xmpp; -beforeEach(() => { +beforeEach(async () => { xmpp = component(options); debug(xmpp); - return server.restart(); + await server.restart(); }); afterEach(async () => { diff --git a/test/see-other-host.js b/test/see-other-host.js index 0348b5951..0b4f0d1ee 100644 --- a/test/see-other-host.js +++ b/test/see-other-host.js @@ -1,8 +1,10 @@ -"use strict"; +import { client, jid } from "../packages/client/index.js"; +import debug from "../packages/debug/index.js"; +import server from "../server/index.js"; -const { client, jid } = require("../packages/client"); -const debug = require("../packages/debug"); -const server = require("../server"); +import net from "net"; +import Connection from "../packages/connection-tcp/index.js"; +import { promise } from "../packages/events/index.js"; const username = "client"; const password = "foobar"; @@ -21,10 +23,6 @@ afterEach(async () => { }); test("see-other-host", async () => { - const net = require("net"); - const Connection = require("../packages/connection-tcp"); - const { promise } = require("../packages/events"); - const seeOtherHostServer = net.createServer((socket) => { const conn = new Connection(); conn._attachSocket(socket);