Guidance for coding agents working in this repository.
@y/websocket — WebSocket provider for Yjs. Client library that connects a Y.Doc to a y-websocket-compatible backend and syncs document updates + awareness. Also supports cross-tab communication via BroadcastChannel / localStorage.
The server implementation lives in a separate repo: @y/websocket-server.
src/y-websocket.js— the entire provider implementation (single file, ESM).test/index.js— test runner entry point.test/y-websocket.test.js— integration tests; spin up@y/websocket-serverin-process and exercise a real client.dist/— generated bynpm run dist(rollup CJS bundle +tscdeclarations from JSDoc). Do not edit by hand.rollup.config.mjs,tsconfig.json— build config.
npm test— runsnode ./test/index.js. Tests require a real backend (started inside the test file).npm run lint— runsstandard+tsc --skipLibCheck. Must pass before shipping.npm run dist— clean + rollup + emit.d.tsfrom JSDoc.
- JavaScript + JSDoc, not TypeScript. Types are emitted from JSDoc annotations via
tsc; keep annotations accurate. standardstyle (no semicolons, 2-space indent, single quotes).npm run lintenforces it.- ESM only (
"type": "module"). The CJS build exists only indist/. - Dependencies are kept minimal:
lib0(utilities) and@y/protocols(sync + awareness wire protocol). Prefer reusing what's inlib0over adding new deps. - Peer dep on
@y/y(Yjs).
Use the lib0/testing framework (see the lib0-testing skill for patterns). Tests run against a live @y/websocket-server started via import '@y/websocket-server/server' — don't mock the socket layer.
preversion runs npm run dist and asserts the CJS bundle and .d.ts exist before npm version proceeds. Current version is a 4.0.0-rc line.