This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The Ghost SDK is a monorepo containing a collection of JavaScript/TypeScript packages for interacting with Ghost's APIs. It uses Lerna for monorepo management and Yarn workspaces.
- Initial setup:
yarn setup(mapped tolerna bootstrap)- Installs all external dependencies
- Links all internal dependencies
- Install dependencies:
yarn
- Run all tests:
yarn test(runslerna run test)- This runs tests in all packages
- Run tests in specific package:
cd packages/<package-name> && yarn test - Run tests with coverage: Most packages use
NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js' - Run specific test file:
NODE_ENV=testing mocha './test/specific.test.js' - Run tests matching pattern:
NODE_ENV=testing mocha './test/**/*.test.js' --grep "pattern"
- Run all linters:
yarn lint(runslerna run lint) - Run linter in specific package:
cd packages/<package-name> && yarn lint - Fix linting issues:
yarn lint -- --fix
- Build packages with build scripts: Individual packages have their own build commands
- For packages with Rollup:
yarn build - TypeScript packages: Check for
tsconfig.jsonand build scripts
- For packages with Rollup:
- Version packages:
yarn ship(runslerna version) — runs tests, prompts for version bumps, and pushes the version commit tomain- CI automatically publishes the updated packages to npm via the
publish.ymlworkflow - Use
yarn ship --git-remote upstreamwhenoriginpoints to a fork andupstreampoints to the original TryGhost/SDK repo
- CI automatically publishes the updated packages to npm via the
- CI publish (used by CI only):
yarn ship:ci(runslerna publish from-package)
All packages are located in the /packages directory:
- @tryghost/admin-api: Admin API client for Ghost
- @tryghost/content-api: Content API client for Ghost
- @tryghost/helpers: Template helpers (reading time, tags, etc.)
- @tryghost/helpers-gatsby: Gatsby-specific helpers
- @tryghost/url-utils: URL manipulation utilities
- @tryghost/string: String manipulation (slugify, escapeHtml, etc.)
- @tryghost/color-utils: Color manipulation utilities
- @tryghost/config-url-helpers: URL configuration helpers
- @tryghost/social-urls: Social media URL generation
- @tryghost/schema-org: Schema.org structured data generation
- @tryghost/timezone-data: Timezone data utilities
- @tryghost/html-to-plaintext: HTML to plaintext conversion
- @tryghost/html-to-mobiledoc: HTML to Mobiledoc conversion
- @tryghost/image-transform: Image transformation utilities
- @tryghost/limit-service: Centralized limit enforcement
- @tryghost/referrer-parser: Referrer parsing utilities
- @tryghost/custom-fonts: Custom font utilities
- Testing framework: Mocha with Should.js for assertions
- Mocking: Sinon for stubs and mocks
- Coverage: c8 for code coverage
- Environment: Set
NODE_ENV=testingwhen running tests
packages/<package-name>/
├── test/
│ ├── unit/ # Unit tests (if separated)
│ ├── integration/ # Integration tests (if separated)
│ ├── fixtures/ # Test fixtures and mock data
│ └── utils/ # Test utilities
│ ├── assertions.js
│ ├── index.js
│ └── overrides.js
To add a new package to the repo:
- Install slimer
- Run
slimer new <package name>
Different packages use different build systems:
- content-api, timezone-data, helpers, color-utils
- Build command:
yarn build - Configuration:
rollup.config.js - Outputs:
cjs/,es/,umd/directories
- color-utils, timezone-data, custom-fonts, referrer-parser
- Configuration:
tsconfig.json - Some use Vite for building
- Most other packages don't require building
- Source in
lib/directory
- This is a Yarn workspaces monorepo - always use
yarn, notnpm - The main branch is
mainfor pull requests - All packages are published under the
@tryghostscope - Packages have independent versioning
- ESLint configuration uses
eslint-plugin-ghost - Most packages follow similar patterns for structure and testing
NODE_ENV=testing- Required for running testsGHOST_UPSTREAM- Set remote for publishing (defaults toorigin)
- Default branch for PRs:
main - Publishing allowed from:
mainbranch - Commit message for version updates: "Published new versions"
- Most packages use
@tryghost/errorsfor consistent error formatting
- Packages expecting database access use Knex instances
- Support for transactions via
options.transacting
- API packages support multiple versions (v2, v3, v4, v5, v6, canary)
- Version-specific tests in
test/<package>-test/v*.test.js
- Run tests before committing
- Use
yarn lintto check code style - Follow existing patterns in the codebase
- Add tests for new functionality
- Update README.md in package directory for significant changes
- Use semantic versioning for package updates