Repository navigation
Description
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 typeThis 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
Socketname 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
exportsmap carries them andpublintandattwstay green.
Scope check
- This is not reconnection, transport fallback, heartbeat, Redis multi-server, or binary encoding
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat: export the contract types for the substitution path
[-]feat: export the socket and server types so substitution keeps them[/-][+]feat: decide what smocket exports as Socket[/+]