Documentation comes from this release commit, without inheriting newer content. Commit: 63ea8c2b3d.
Recipe — Adding a new @piano/* package
Companion to adding-a-feature.md. Use this when the new code is pure TypeScript domain logic that should live under packages/*. If you're adding a screen, store, or React hook, you want adding-a-feature.md instead.
Decision tree
If you reach "Add a new @piano/* package", continue below.
Step-by-step
1. Pick a name
Use kebab-case under the @piano scope. Match the existing taxonomy:
If your idea overlaps with an existing package, prefer extending it.
2. Scaffold the folder
Copy packages/types/ (the simplest leaf package) as your starting template:
Then edit:
packages/<new-name>/package.json— change"name"to"@piano/<new-name>".packages/<new-name>/README.md— write one paragraph on what this package owns and why.packages/<new-name>/src/index.ts— wipe it and add your first export.
tsconfig.json and tsup.config.ts need no edits — both extend the shared root configs.
3. Declare workspace dependencies
If your package needs another @piano/*, add it to dependencies (not devDependencies) with the workspace protocol:
Don't add react, react-native, or any RN-only dep here — @piano/* packages must stay platform-agnostic. If you need them, write a thin adapter in src/features/<x>/ and inject the contract.
External npm deps go under dependencies like normal (e.g. valibot, midi-parser-js).
4. Run bun install from the repo root
This:
- Symlinks
packages/<new-name>intonode_modules/@piano/<new-name>. - Resolves any new external deps and writes
bun.lock. - Re-runs the host app's install so Metro will see the package on next start.
5. Implement and build
Inside the new package:
Or from the root, in topological order:
6. Add tests
Drop unit tests in packages/<new-name>/tests/. Bun's test runner is preconfigured for every package via the test script:
Run with bun test inside the package, or bun run test from the root (Turbo runs every package's tests and app shards in parallel; Bun ≥ 1.3.13).
7. Expose through @piano/sdk (if public)
If the new package is part of the SDK's public surface (most are), wire it up:
- Add
"@piano/<new-name>": "workspace:*"topackages/sdk/package.jsondependencies. - Add
export * from '@piano/<new-name>';(or a narrower re-export) at the top ofpackages/sdk/src/index.ts. - If the package contributes to
createPianoSdk(config), extendPianoSdkConfigandPianoSdkaccordingly. - Re-run
bun installandbunx turbo run build --filter=@piano/sdk.
If the package is internal-only (used by other @piano/* packages but not by the host app), skip this step.
8. Use it from the host app
Inside src/features/<x>/ or wherever it makes sense:
Never import { computeXp } from '@piano/<new-name>' directly — the SDK is the only public surface for the host. (See architecture.md "Dependency direction rules".)
Checklist before merging
-
bun installsucceeds from the repo root. -
bunx turbo run buildsucceeds (no broken topological order). -
bunx turbo run typechecksucceeds across all packages — including any package that depends on the new one. -
bunx turbo run testpasses (or the package ships with green tests). -
package.json"name"matches@piano/<new-name>and usesworkspace:*for any internal deps. - The package does not depend on
react,react-native,expo, or any other RN-only module. - If public, the package is re-exported from
@piano/sdk. -
README.mdsays in one paragraph what the package owns and why it exists.