Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Build and test
run: npm run build && npx vitest run && npm run lint
run: npm run build && npx vitest run && npm run lint && npm run check:types
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Strophe.js Change Log

## Unreleased

### Bug fixes

- #886 TypeScript types now resolve under `"moduleResolution": "node16"` and `"nodenext"`.
Relative imports in the published declarations carry `.js` extensions, and Node consumers
get the Node entry's types (which include `Component` and `ComponentParser`) instead of the
browser ones. These types do not need `@types/node`: `ComponentParser.write()` now takes a
`Uint8Array` (which a `Buffer` is), and the internal `Component.socket` field is now private.
The published types are ESM-only. TypeScript projects that compile to CommonJS need
`"moduleResolution": "nodenext"` with TypeScript 5.8 or later. Under `node16`, or with an older
TypeScript, they get error TS1479. The CommonJS runtime build is unchanged.

## Version 5.0.0 (2026-07-21)

### Breaking changes
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Then import what you need:
import { Strophe, stx } from 'strophe.js';
```

The bundled TypeScript types are ESM-only. A TypeScript project that compiles to
CommonJS needs `"moduleResolution": "nodenext"` and TypeScript 5.8 or later.
Plain JavaScript can still use `require('strophe.js')`.

Or load it from a CDN in a plain web page, which exposes `Strophe`, `stx`,
`$iq`, `$msg`, `$pres` and `$build` as globals:

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"unpkg": "./dist/strophe.umd.min.js",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"browser": {
"types": "./dist/types/index.d.ts",
"import": "./dist/strophe.esm.js",
"require": "./dist/strophe.umd.cjs",
"default": "./dist/strophe.umd.cjs"
Expand All @@ -56,6 +56,7 @@
"require": "./dist/strophe.cjs",
"default": "./dist/strophe.cjs"
},
"types": "./dist/types/index.d.ts",
"default": "./dist/strophe.esm.js"
},
"./package.json": "./package.json"
Expand All @@ -66,7 +67,8 @@
"lint": "eslint src",
"clean": "make clean",
"doc": "make doc",
"test": "npm run build && vitest run && npm run lint",
"test": "npm run build && vitest run && npm run lint && npm run check:types",
"check:types": "scripts/check-consumer-types.sh",
"prettier": "prettier --write \"src/**/*.ts\""
},
"volo": {
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default [
this.emitFile({
type: 'asset',
fileName: 'strophe.node.esm.d.ts',
source: "export * from './types/index-node';\n",
source: "export * from './types/index-node.js';\n",
});
},
},
Expand Down
63 changes: 63 additions & 0 deletions scripts/check-consumer-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# Type-check the packed package the way a consumer would (strophe/strophejs#886).
# For each moduleResolution mode, a tiny project imports strophe.js and makes
# one deliberate type error. The check passes only if tsc reports exactly that
# error, which proves the published types resolve instead of degrading to `any`.
# Run `npm run build` first.
set -euo pipefail

root="$(cd "$(dirname "$0")/.." && pwd)"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT

tarball="$(cd "$root" && npm pack --silent --pack-destination "$work" | tail -n1)"
tsc="$(cd "$root" && node -p "require.resolve('typescript/bin/tsc')")"
# The published types must not need @types/node, so most probes run without
# it. One probe adds it to check the two still agree.
types_node="$(cd "$root" && node -p "require('path').dirname(require.resolve('@types/node/package.json'))")"
status=0

# check <name> <package type: module|commonjs> <module> <moduleResolution> <types: none|node> <source> <expected error>
check() {
local name="$1" pkgtype="$2" module="$3" resolution="$4" types="$5" source="$6" expected="$7"
local dir="$work/$name" types_json='[]'
mkdir -p "$dir/node_modules/strophe.js"
tar -xzf "$work/$tarball" -C "$dir/node_modules/strophe.js" --strip-components=1
if [ "$types" = node ]; then
mkdir -p "$dir/node_modules/@types"
ln -s "$types_node" "$dir/node_modules/@types/node"
types_json='["node"]'
fi
printf '{"type":"%s"}\n' "$pkgtype" > "$dir/package.json"
printf '%s\n' "$source" > "$dir/index.ts"
printf '{"compilerOptions":{"target":"es2022","module":"%s","moduleResolution":"%s","strict":true,"noEmit":true,"types":%s},"files":["index.ts"]}\n' \
"$module" "$resolution" "$types_json" > "$dir/tsconfig.json"
local out
out="$(cd "$dir" && node "$tsc" -p . 2>&1 || true)"
if [ "$(printf '%s\n' "$out" | grep -c 'error TS')" = 1 ] && printf '%s' "$out" | grep -qF "$expected"; then
echo "ok $name"
else
echo "FAIL $name"
printf '%s\n' "$out" | sed 's/^/ /'
status=1
fi
}

shared="import { Strophe } from 'strophe.js';
const x: number = Strophe.NO_SUCH_PROPERTY;"
missing="Property 'NO_SUCH_PROPERTY' does not exist"

check nodenext module nodenext nodenext none "$shared" "$missing"
check node16 module node16 node16 none "$shared" "$missing"
check bundler module esnext bundler none "$shared" "$missing"
# The published types are ESM-only. CommonJS consumers are supported under
# nodenext, where TypeScript (5.8+) models Node's require(esm).
check nodenext-commonjs commonjs nodenext nodenext none "$shared" "$missing"

# Node consumers must get the Node entry's types, which add the component transport.
node_only="import { Component } from 'strophe.js';
const c: number = Component;"
check nodenext-node-entry module nodenext nodenext none "$node_only" "'typeof Component' is not assignable to type 'number'"
check nodenext-node-entry-types-node module nodenext nodenext node "$node_only" "'typeof Component' is not assignable to type 'number'"

exit $status
4 changes: 2 additions & 2 deletions src/builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ElementType, NS } from './constants';
import { copyElement, createHtml, toElement, xmlElement, xmlGenerator, xmlTextNode, xmlescape } from './utils';
import { ElementType, NS } from './constants.js';
import { copyElement, createHtml, toElement, xmlElement, xmlGenerator, xmlTextNode, xmlescape } from './utils.js';

export type StanzaAttrs = Record<string, string | number>;

Expand Down
46 changes: 23 additions & 23 deletions src/connection.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type SASLMechanism from './sasl';
import type Request from './request';
import Handler from './handler';
import TimedHandler from './timed-handler';
import Builder, { $build, $iq, $pres } from './builder';
import log from './log';
import { ErrorCondition, NS, Status } from './constants';
import SASLAnonymous from './sasl-anon';
import SASLExternal from './sasl-external';
import SASLOAuthBearer from './sasl-oauthbearer';
import SASLPlain from './sasl-plain';
import SASLSHA1 from './sasl-sha1';
import SASLSHA256 from './sasl-sha256';
import SASLSHA384 from './sasl-sha384';
import SASLSHA512 from './sasl-sha512';
import SASLXOAuth2 from './sasl-xoauth2';
import type SASLMechanism from './sasl.js';
import type Request from './request.js';
import Handler from './handler.js';
import TimedHandler from './timed-handler.js';
import Builder, { $build, $iq, $pres } from './builder.js';
import log from './log.js';
import { ErrorCondition, NS, Status } from './constants.js';
import SASLAnonymous from './sasl-anon.js';
import SASLExternal from './sasl-external.js';
import SASLOAuthBearer from './sasl-oauthbearer.js';
import SASLPlain from './sasl-plain.js';
import SASLSHA1 from './sasl-sha1.js';
import SASLSHA256 from './sasl-sha256.js';
import SASLSHA384 from './sasl-sha384.js';
import SASLSHA512 from './sasl-sha512.js';
import SASLXOAuth2 from './sasl-xoauth2.js';
import {
addCookies,
forEachChild,
Expand All @@ -25,20 +25,20 @@ import {
handleError,
toElement,
type Cookies,
} from './utils';
import { SessionError } from './errors';
import Bosh from './transports/bosh';
import WorkerWebsocket from './transports/worker-websocket';
import Websocket from './transports/websocket';
import type { Transport } from './transports/types';
} from './utils.js';
import { SessionError } from './errors.js';
import Bosh from './transports/bosh.js';
import WorkerWebsocket from './transports/worker-websocket.js';
import Websocket from './transports/websocket.js';
import type { Transport } from './transports/types.js';
import StreamManagement, {
SessionStorageBackend,
StreamManagementMirror,
isCountableStanza,
toStanzaView,
type StreamManagementController,
type StreamManagementOptions,
} from './stream-management';
} from './stream-management/index.js';

export interface ConnectionOptions {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Strophe as StropheType, Builder, Stanza } from './index';
import type { Strophe as StropheType, Builder, Stanza } from './index.js';

declare global {
const Strophe: typeof StropheType;
Expand Down
2 changes: 1 addition & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBareJidFromJid, getNamespace as getElementNamespace, handleError, isTagEqual } from './utils';
import { getBareJidFromJid, getNamespace as getElementNamespace, handleError, isTagEqual } from './utils.js';

export interface HandlerOptions {
matchBareFromJid?: boolean;
Expand Down
14 changes: 7 additions & 7 deletions src/index-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
// Must be first: installs the DOM globals (via @xmldom/xmldom) and `ws` that the
// rest of the library assumes, before any module touches `document`/`DOMParser`.
import './shims/node-dom';
import Connection from './connection';
import Component from './transports/component';
import ComponentParser from './transports/component-parser';
import { Strophe } from './index';
import './shims/node-dom.js';
import Connection from './connection.js';
import Component from './transports/component.js';
import ComponentParser from './transports/component-parser.js';
import { Strophe } from './index.js';

// Make the component transport selectable via `{ protocol: 'component' }`.
Connection.addProtocol('component', Component);
Expand All @@ -27,6 +27,6 @@ Connection.addProtocol('component', Component);
(Strophe as unknown as { Component: typeof Component }).Component = Component;
(Strophe as unknown as { ComponentParser: typeof ComponentParser }).ComponentParser = ComponentParser;

export * from './index';
export * from './index.js';
export { Component, ComponentParser };
export type { StreamParserHandlers } from './transports/component-parser';
export type { StreamParserHandlers } from './transports/component-parser.js';
50 changes: 25 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import * as utils from './utils';
import Bosh from './transports/bosh';
import Builder, { $build, $msg, $pres, $iq } from './builder';
import Connection from './connection';
import Handler from './handler';
import Request from './request';
import SASLAnonymous from './sasl-anon';
import SASLExternal from './sasl-external';
import SASLMechanism from './sasl';
import SASLOAuthBearer from './sasl-oauthbearer';
import SASLPlain from './sasl-plain';
import SASLSHA1 from './sasl-sha1';
import SASLSHA256 from './sasl-sha256';
import SASLSHA384 from './sasl-sha384';
import SASLSHA512 from './sasl-sha512';
import SASLXOAuth2 from './sasl-xoauth2';
import StreamManagement, { MemoryStorageBackend, SessionStorageBackend, StreamManagementMirror } from './stream-management';
import TimedHandler from './timed-handler';
import Websocket from './transports/websocket';
import WorkerWebsocket from './transports/worker-websocket';
import log from './log';
import { ElementType, ErrorCondition, LOG_LEVELS, LogLevel, NS, Status, XHTML } from './constants';
import { stx, Stanza } from './stanza';
import * as utils from './utils.js';
import Bosh from './transports/bosh.js';
import Builder, { $build, $msg, $pres, $iq } from './builder.js';
import Connection from './connection.js';
import Handler from './handler.js';
import Request from './request.js';
import SASLAnonymous from './sasl-anon.js';
import SASLExternal from './sasl-external.js';
import SASLMechanism from './sasl.js';
import SASLOAuthBearer from './sasl-oauthbearer.js';
import SASLPlain from './sasl-plain.js';
import SASLSHA1 from './sasl-sha1.js';
import SASLSHA256 from './sasl-sha256.js';
import SASLSHA384 from './sasl-sha384.js';
import SASLSHA512 from './sasl-sha512.js';
import SASLXOAuth2 from './sasl-xoauth2.js';
import StreamManagement, { MemoryStorageBackend, SessionStorageBackend, StreamManagementMirror } from './stream-management/index.js';
import TimedHandler from './timed-handler.js';
import Websocket from './transports/websocket.js';
import WorkerWebsocket from './transports/worker-websocket.js';
import log from './log.js';
import { ElementType, ErrorCondition, LOG_LEVELS, LogLevel, NS, Status, XHTML } from './constants.js';
import { stx, Stanza } from './stanza.js';

type StropheType = {
VERSION: string;
Expand Down Expand Up @@ -175,5 +175,5 @@ export type {
SMStorageBackend,
StreamManagementController,
StreamManagementOptions,
} from './stream-management';
export type { ConnectCallback, ConnectionOptions } from './connection';
} from './stream-management/index.js';
export type { ConnectCallback, ConnectionOptions } from './connection.js';
2 changes: 1 addition & 1 deletion src/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LOG_LEVELS, LogLevel } from './constants';
import { LOG_LEVELS, LogLevel } from './constants.js';

let logLevel = LOG_LEVELS.DEBUG;

Expand Down
8 changes: 4 additions & 4 deletions src/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import log from './log';
import Builder from './builder';
import { ErrorCondition } from './constants';
import { getParserError, xmlHtmlNode } from './utils';
import log from './log.js';
import Builder from './builder.js';
import { ErrorCondition } from './constants.js';
import { getParserError, xmlHtmlNode } from './utils.js';

/**
* _Private_ variable that keeps track of the request ids for connections.
Expand Down
4 changes: 2 additions & 2 deletions src/sasl-anon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';

class SASLAnonymous extends SASLMechanism {
constructor(mechname = 'ANONYMOUS', isClientFirst = false, priority = 20) {
Expand Down
4 changes: 2 additions & 2 deletions src/sasl-external.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';

class SASLExternal extends SASLMechanism {
constructor(mechname = 'EXTERNAL', isClientFirst = true, priority = 10) {
Expand Down
6 changes: 3 additions & 3 deletions src/sasl-oauthbearer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import utils from './utils';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';
import utils from './utils.js';

class SASLOAuthBearer extends SASLMechanism {
constructor(mechname = 'OAUTHBEARER', isClientFirst = true, priority = 40) {
Expand Down
6 changes: 3 additions & 3 deletions src/sasl-plain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import utils from './utils';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';
import utils from './utils.js';

class SASLPlain extends SASLMechanism {
constructor(mechname = 'PLAIN', isClientFirst = true, priority = 50) {
Expand Down
6 changes: 3 additions & 3 deletions src/sasl-sha1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import scram from './scram';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';
import scram from './scram.js';

class SASLSHA1 extends SASLMechanism {
constructor(mechname = 'SCRAM-SHA-1', isClientFirst = true, priority = 60) {
Expand Down
6 changes: 3 additions & 3 deletions src/sasl-sha256.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import scram from './scram';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';
import scram from './scram.js';

class SASLSHA256 extends SASLMechanism {
constructor(mechname = 'SCRAM-SHA-256', isClientFirst = true, priority = 70) {
Expand Down
6 changes: 3 additions & 3 deletions src/sasl-sha384.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import scram from './scram';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';
import scram from './scram.js';

class SASLSHA384 extends SASLMechanism {
constructor(mechname = 'SCRAM-SHA-384', isClientFirst = true, priority = 71) {
Expand Down
6 changes: 3 additions & 3 deletions src/sasl-sha512.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Connection from './connection';
import SASLMechanism from './sasl';
import scram from './scram';
import type Connection from './connection.js';
import SASLMechanism from './sasl.js';
import scram from './scram.js';

class SASLSHA512 extends SASLMechanism {
constructor(mechname = 'SCRAM-SHA-512', isClientFirst = true, priority = 72) {
Expand Down
Loading
Loading