v1.0.13 · Release snapshot

Documentation comes from this release commit, without inheriting newer content. Commit: 371ee4692c.

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:

ConcernExisting packages
Domain types / schemas@piano/types
Music-theory primitives@piano/keyboard, @piano/midi
Engine primitives@piano/core
Game modes@piano/gameplay-{learn,magic,zen}
Player progression@piano/progression, @piano/player-data
Content@piano/catalog
External adapters / contracts@piano/network, @piano/analytics, @piano/ads
Public facade@piano/sdk

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:

cp -R packages/types packages/<new-name>
rm -rf packages/<new-name>/dist packages/<new-name>/node_modules

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:

{
  "dependencies": {
    "@piano/types": "workspace:*",
    "@piano/keyboard": "workspace:*"
  }
}

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

bun install

This:

  • Symlinks packages/<new-name> into node_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:

cd packages/<new-name>
bun run build      # one-shot tsup build
bun run typecheck  # tsc --noEmit
bun run dev        # tsup --watch (only if package.json declares dev script)

Or from the root, in topological order:

bunx turbo run build --filter=@piano/<new-name>
bunx turbo run typecheck

6. Add tests

Drop unit tests in packages/<new-name>/tests/. Bun's test runner is preconfigured for every package via the test script:

import { describe, expect, it } from 'bun:test';
import { computeXp } from '../src/index';

describe('computeXp', () => {
  it('returns 0 for missing notes', () => {
    expect(computeXp({ hits: 0, total: 10 })).toBe(0);
  });
});

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:

  1. Add "@piano/<new-name>": "workspace:*" to packages/sdk/package.json dependencies.
  2. Add export * from '@piano/<new-name>'; (or a narrower re-export) at the top of packages/sdk/src/index.ts.
  3. If the package contributes to createPianoSdk(config), extend PianoSdkConfig and PianoSdk accordingly.
  4. Re-run bun install and bunx 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:

import { computeXp } from '@piano/sdk';

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 install succeeds from the repo root.
  • bunx turbo run build succeeds (no broken topological order).
  • bunx turbo run typecheck succeeds across all packages — including any package that depends on the new one.
  • bunx turbo run test passes (or the package ships with green tests).
  • package.json "name" matches @piano/<new-name> and uses workspace:* 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.md says in one paragraph what the package owns and why it exists.

Visual recap