Skip to content

Latest commit

Β 

History

History
175 lines (136 loc) Β· 7.09 KB

File metadata and controls

175 lines (136 loc) Β· 7.09 KB

AGENTS.md β€” AI Agent Instructions

This file provides context for AI agents (Cursor, Claude, Copilot, etc.) working on this repository. Read it in full before making any changes.


Project Overview

react-native-typescript-library-starter is a React Native TypeScript library starter template. It is NOT an application β€” it is a publishable npm package used as a starting point for building React Native component/hook libraries.

  • Build tool: react-native-builder-bob (outputs CJS + ESM + TypeScript declarations)
  • Testing: Jest + @testing-library/react-native
  • Language: TypeScript (strict mode, no any)
  • Linting: ESLint v8 + Prettier
  • CI: GitHub Actions (typecheck + lint + test + build)

Directory Map

react-native-typescript-library-starter/
β”œβ”€β”€ src/                          # ALL library source code lives here
β”‚   β”œβ”€β”€ index.ts                  # Public API β€” only export from here
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── MyComponent/
β”‚   β”‚       β”œβ”€β”€ MyComponent.tsx        # Implementation
β”‚   β”‚       β”œβ”€β”€ MyComponent.types.ts   # Props interface
β”‚   β”‚       └── index.ts               # Barrel export
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   └── useMyHook.ts          # Custom hook with TSDoc
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   └── index.ts              # Shared utility types
β”‚   └── __tests__/
β”‚       β”œβ”€β”€ MyComponent.test.tsx
β”‚       └── useMyHook.test.ts
β”œβ”€β”€ lib/                          # GENERATED by bob β€” do NOT edit manually
β”‚   β”œβ”€β”€ commonjs/                 # CJS output
β”‚   β”œβ”€β”€ module/                   # ESM output
β”‚   └── typescript/               # .d.ts declarations
β”œβ”€β”€ scripts/
β”‚   └── terminal/
β”‚       β”œβ”€β”€ lint.mjs              # Colored ESLint runner
β”‚       └── prettier.mjs          # Colored Prettier runner
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       β”œβ”€β”€ ci.yml                # Runs on PR: typecheck + lint + test + build
β”‚       └── release.yml           # Runs on push to main: release pipeline
β”œβ”€β”€ .husky/                       # Git hooks (pre-commit, commit-msg)
β”œβ”€β”€ AGENTS.md                     # This file
β”œβ”€β”€ CONTRIBUTING.md
β”œβ”€β”€ CHANGELOG.md
β”œβ”€β”€ README.md
β”œβ”€β”€ package.json                  # bob config, jest config, lint-staged config
β”œβ”€β”€ tsconfig.json                 # Base TypeScript config
β”œβ”€β”€ tsconfig.build.json           # bob-specific build config
β”œβ”€β”€ babel.config.js               # metro-react-native-babel-preset (for Jest)
β”œβ”€β”€ .eslintrc.js
β”œβ”€β”€ .prettierrc
└── .commitlintrc.json

Commands

All commands should be run from the repository root.

Command Description
npm run setup Interactive wizard β€” configure name, author, repo URLs
npm install Install all dependencies (also runs husky via prepare)
npm run build Build library to lib/ via bob
npm run typecheck Type-check without emitting files
npm run lint Run ESLint with colored output
npm run lint:ci Run ESLint without spinner (for CI)
npm run prettier Format code with colored output
npm run prettier:ci Check formatting without spinner (for CI)
npm test Run Jest tests
npm run test:watch Run Jest in watch mode
npm run test:coverage Run Jest with coverage report

Conventions

TypeScript

  • Strict mode is enabled ("strict": true). No any, no ts-ignore without a comment explaining why.
  • Use type for type aliases and interface for object shapes.
  • Always use import type for type-only imports.
  • Path alias @/* maps to src/*.

Components

  • One component per folder under src/components/.
  • File naming: MyComponent.tsx (implementation), MyComponent.types.ts (props), index.ts (barrel).
  • Props interface must be named <ComponentName>Props and exported from the barrel.
  • All props must have TSDoc comments with @example tags for non-trivial props.
  • Use StyleSheet.create() β€” no inline style objects.
  • Forward testID and derive child testIDs as ${testID}-<part>.

Hooks

  • One hook per file under src/hooks/.
  • Export the hook as a named export (not default).
  • Export the options interface as Use<HookName>Options.
  • Export the return interface as Use<HookName>Return.
  • All hooks must have full TSDoc with @param, @returns, and @example.

Public API

  • Only add exports to src/index.ts β€” this is the package entry point.
  • Export both the value and its types from src/index.ts.
  • Never import from lib/ β€” always from src/.

Commits

Follow Conventional Commits. Allowed types: feat, fix, perf, refactor, style, test, docs, ci, chore, revert.

Examples:

feat: add PressableCard component
fix: correct button accessibility role
test: add edge cases for useMyHook
docs: update README with new API

Testing

  • Test files live in src/__tests__/.
  • File names match the source: MyComponent.test.tsx, useMyHook.test.ts.
  • Use @testing-library/react-native for component tests (render, fireEvent, getByTestId).
  • Use renderHook + act for hook tests.
  • Group tests with describe blocks: describe("rendering"), describe("interactions"), describe("accessibility").
  • Coverage thresholds: 70% branches, 80% functions/lines/statements.

What NOT to Do

  • Do NOT edit files in lib/ β€” they are generated by bob build.
  • Do NOT use require() β€” use ES module import.
  • Do NOT add peerDependencies as dependencies or devDependencies without justification.
  • Do NOT export internal helpers from src/index.ts β€” only public API.
  • Do NOT disable ESLint rules without an explanatory comment.
  • Do NOT add console.log to source files.
  • Do NOT use default exports for hooks β€” named exports only.
  • Do NOT skip tests when adding new features.

Adding a New Component

  1. Create src/components/NewComponent/NewComponent.types.ts β€” props interface with full TSDoc.
  2. Create src/components/NewComponent/NewComponent.tsx β€” implementation.
  3. Create src/components/NewComponent/index.ts β€” barrel.
  4. Create src/components/NewComponent/__tests__/NewComponent.test.tsx β€” or add to src/__tests__/.
  5. Add exports to src/index.ts.

Adding a New Hook

  1. Create src/hooks/useNewHook.ts with options, return interface, and implementation.
  2. Add exports to src/index.ts.
  3. Add tests to src/__tests__/useNewHook.test.ts.

Environment Notes

  • Node.js: LTS (>=18)
  • React Native: >=0.70.0 (peer dependency)
  • React: >=17.0.0 (peer dependency)
  • Package manager: npm