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 94%
rename from eslint.config.mjs
rename to eslint.config.js
index af07456e7..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";
@@ -81,16 +82,12 @@ export default [
"unicorn/prefer-export-from": "off",
},
},
- // {
- // files: [
- // "packages/client/**/*.js",
- // "packages/events/**/*.js",
- // "packages/base64/**/*.js",
- // ],
- // languageOptions: {
- // sourceType: "module",
- // },
- // },
+ {
+ files: ["**/*.cjs"],
+ languageOptions: {
+ sourceType: "commonjs",
+ },
+ },
{
files: ["**/*.spec.js", "**/*.test.js", "**/test.js", "**/test/**.js"],
plugins: { jest: pluginJest },
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 45894b3eb..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",
@@ -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",
@@ -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": {
@@ -16315,9 +16316,6 @@
"@xmpp/middleware": "^0.13.2",
"@xmpp/xml": "^0.13.2"
},
- "devDependencies": {
- "@xmpp/middleware": "^0.13.1"
- },
"engines": {
"node": ">= 14.13.1"
}
@@ -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",
@@ -16535,6 +16534,7 @@
"license": "ISC",
"dependencies": {
"@xmpp/connection": "^0.13.2",
+ "@xmpp/events": "^0.13.2",
"@xmpp/xml": "^0.13.2",
"ws": "^8.18.0"
},
diff --git a/package.json b/package.json
index 4e2a5a6b6..b80300121 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,7 +39,7 @@
"uglify-js": "^3.19.3"
},
"scripts": {
- "test": "jest",
+ "test": "npx jest",
"lint": "eslint --cache .",
"preversion": "make bundle"
},
diff --git a/packages/component-core/package.json b/packages/component-core/package.json
index 47d2079a0..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",
diff --git a/packages/connection-tcp/test/Connection.js b/packages/connection-tcp/test/Connection.js
index 6491ee072..fc95f0fe5 100644
--- a/packages/connection-tcp/test/Connection.js
+++ b/packages/connection-tcp/test/Connection.js
@@ -1,4 +1,4 @@
-import { Connection as _Connection } from "@xmpp/connection";
+import _Connection from "@xmpp/connection";
import Connection from "../index.js";
import net from "net";
diff --git a/packages/error/index.js b/packages/error/index.js
index 0d131c466..10936b058 100644
--- a/packages/error/index.js
+++ b/packages/error/index.js
@@ -34,4 +34,4 @@ class XMPPError extends Error {
}
}
-module.exports = XMPPError;
+export default XMPPError;
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 6862e326c..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",
@@ -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 4f8edf7b2..83d574067 100644
--- a/packages/jid/package.json
+++ b/packages/jid/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",
"JID"
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 48e7e04b4..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"
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 d55b0bb9d..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"
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..2b8e98e5a 100644
--- a/packages/resolve/example.js
+++ b/packages/resolve/example.js
@@ -1,7 +1,5 @@
-"use strict";
-
-const resolve = require("./resolve");
+import { resolve } from "@xmpp/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..065057e7b 100644
--- a/packages/resolve/lib/http.js
+++ b/packages/resolve/lib/http.js
@@ -1,11 +1,10 @@
-"use strict";
-
// 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;
+const fetch = globalThis.fetch || import("node-fetch");
+
+import parse from "@xmpp/xml/lib/parse.js";
+import { compare as compareAltConnections } from "./alt-connections.js";
-function resolve(domain) {
+export function resolve(domain) {
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 86a227259..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",
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 b7e21217e..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",
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 53e689b66..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",
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 ad67d5e45..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",
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 6a3467bb3..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",
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 82fd70ef6..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"
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 de0d68cfc..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",
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 e37560249..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"
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 52d60ec58..279524d68 100644
--- a/packages/stream-features/package.json
+++ b/packages/stream-features/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",
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 c7264e7c9..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",
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 cdc19352a..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"
},
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 ad90a2647..b984e12d9 100644
--- a/packages/test/package.json
+++ b/packages/test/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",
"test"
@@ -15,6 +15,7 @@
"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 c2516a1c9..317a0b890 100644
--- a/packages/time/package.json
+++ b/packages/time/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",
"time",
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 453b96a09..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"
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 7dcba91fe..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"
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 8e2e2823c..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"
},
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 a0cd107d9..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",
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 336fa83a7..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",
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..3c96736d3 100644
--- a/server/index.js
+++ b/server/index.js
@@ -1,14 +1,15 @@
-"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 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 +116,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 {
+ 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..503714e71 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";
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);