Contributing
Thank you for your interest in contributing to webserial-core!
Development setup
bash
git clone https://github.com/danidoble/webserial-core.git
cd webserial-core
npm installStart the Vite dev server to test the demos interactively:
bash
npm run devThen open any of the demo pages in your browser:
http://localhost:5173/— Web Serial (native)http://localhost:5173/demos/web-usb/— WebUSB Polyfillhttp://localhost:5173/demos/web-bluetooth/— Web Bluetoothhttp://localhost:5173/demos/websocket/— WebSocket Bridge
Code style
- TypeScript strict mode — no
any, all public APIs fully typed. - ESM imports — use
.jsextension on relative imports (e.g.import x from "./foo.js"). Vite resolves these to the.tssource files. - English only — all comments, JSDoc, variable names, and string literals must be in English.
- JSDoc — all exported symbols must have JSDoc with
@param,@returns, and@throwswhere applicable.
Run lint and format checks before pushing:
bash
npm run lint
npm run formatBuilding
bash
npm run buildProduces:
dist/
webserial-core.mjs ← ESM (tree-shakeable, for bundlers)
webserial-core.cjs ← CommonJS (Node.js / legacy bundlers)
webserial-core.umd.cjs ← UMD (standalone <script> tag / CDN)
index.d.ts ← Bundled TypeScript declarationsBuilding the docs
bash
npm run docs:dev # Live preview
npm run docs:build # Static output → docs/.vitepress/distSubmitting a pull request
- Fork the repository and create a branch:
git checkout -b feat/my-feature - Make your changes and add JSDoc to any new public symbols.
- Run
npm run lintandnpm run format. - Verify the build:
npm run build. - Push and open a PR against
main.
Adding a new adapter
Place adapter code under src/adapters/<name>/:
src/adapters/my-adapter/
MyAdapter.ts ← implements SerialProvider
index.ts ← re-exportsThen re-export from src/index.ts:
ts
export * from "./adapters/my-adapter/index.js";Add a demo under demos/my-adapter/ following the existing demo structure.