Skip to content

feat: decide what smocket exports as Socket #178

Closed

Description

@electrohyun

Problem

An application that swaps socket.io-client for smocket can annotate its test code, and cannot use the name socket.io gave it.

// app code, unchanged between the real run and the test run
import { io, type Socket } from 'socket.io-client';
//            ^^^^^^ smocket exports no such type

This issue used to cover both halves of that. The first half shipped, and this is now only the second.

What already shipped

The contract types are exported, in 0.4.1. src/index.ts exports nineteen types, including all five entry points (ServerContract, ServerSocketContract, ClientSocketContract, NamespaceContract, Handshake) and the nine those reach through their own members, so nothing is reachable but unnameable. An application writes let client: ClientSocketContract today and gets a checked surface. Landed in #179 and verified from outside the repository against the published package under moduleResolution bundler and node16, in both a CJS and an ESM consumer.

SmocketServer followed in #188, for the two server members differences.md section B documents and ServerContract cannot carry, since that interface is the subset real socket.io is verified against.

ConnectedClient and ServerContext stay unexported. They are the dual-run test setup's shape, not an application-facing surface.

What is left, and the question in it

The Socket name. socket.io's Socket is the server socket and socket.io-client's Socket is the client socket. smocket is one package, so it can give that name to one of them, not both.

Aliasing ClientSocketContract to Socket makes import { type Socket } from 'socket.io-client' resolve after substitution, and makes the same import from socket.io resolve to the wrong side in silence. Silently wrong is worse than absent here, which is why the name was not simply taken when the contract types went out.

Supporting both directions needs subpath exports, smocket/client and smocket/server. That is a change to the exports map, which currently declares . only, so it is in scope for the surface freeze in a way the first half was not. It also has to keep attw green in both resolution modes, which the packaging job already checks.

There is no name collision to work around. Socket is unused in the public surface, and the ServerSocket / ClientSocket classes never leave src/mock-server.ts.

Socket.IO behavior

socket.io socket.io-client smocket today
Socket yes yes missing
Server yes (class) - yes (class)
Namespace yes - as NamespaceContract
DefaultEventsMap yes yes missing

DefaultEventsMap belongs to #171 rather than here, since it only means something once the event maps are generic.

Version impact

A subpath export is an addition to the exports map, which none of 0019's rows covers directly. Adding a subpath breaks nothing that resolves today, so it reads as a minor above 1.0.0, but the row is missing and this is the change that should add it rather than assume it.

Completion

  • Either the Socket name is exported, with the side it names decided and the other side's collision handled, or the decision is recorded as deferred with its reason.
  • If subpath exports are the answer, the exports map carries them and publint and attw stay green.

Scope check

  • This is not reconnection, transport fallback, heartbeat, Redis multi-server, or binary encoding

Activity

  1. added this to the v1.0.0 milestone on Aug 7, 2026
  2. self-assigned this
    on Aug 7, 2026
  3. added
    enhancement
    on Aug 7, 2026
  4. changed the title [-]feat: export the socket and server types so substitution keeps them[/-] [+]feat: decide what smocket exports as Socket[/+] on Aug 7, 2026
  5. modified the milestones: v1.0.0, on Aug 7, 2026
  6. added
    needs decision
    on Aug 12, 2026
  7. moved this from Backlog to In progress in smocketon Aug 12, 2026
  8. moved this from In progress to Done in smocketon Aug 12, 2026
  9. modified the milestones: v1.0.0, v0.5.0 on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementneeds decision

Type

No type

Projects

  • Status
    Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions