# Library Authors
URL: /react/getting-started/library-authors
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/getting-started/library-authors.mdx
Learn about dependency declaration, version ranges, and 2.0 migration methods when creating shared packages and SDKs using Crispy.
This guide is for teams \*\*distributing components created with Crispy as npm packages (SDKs, shared component libraries, etc.)\*\*. If you're using Crispy directly in an app (project), see the [installation guide](/react/getting-started/installation/vite).
In this guide, we call packages using Crispy **libraries**, and apps that install these libraries to create final bundles **projects**.
## Three Core Principles
Breaking any of these can result in \**two copies of Crispy CSS in your project bundle, breaking styles.*\*
1. Declare Crispy packages only in `peerDependencies`. (`dependencies` prohibited)
2. Don't include Crispy code in build output (dist). (Handle as external)
3. Delegate CSS file imports to projects. (Prohibited: importing `@seed-design/css/*.css` in library code)
The rationale for these three principles is explained below in \*\*Why do this?\*\*, and how to apply each principle is covered in **Declaring dependencies and setting up builds**.
## Why do this?
Crispy's class names (`.seed-action-button`) and tokens (`--seed-*`) have **the same name regardless of version**. Component CSS also comes along without separate import because the recipe modules used by `@seed-design/react` import their own CSS internally.
So if a library declares Crispy in `dependencies` or includes it in the bundle, **two different versions of Crispy CSS** load with the same class names as the Crispy in the project. Which styles win is determined by load order, and since bundlers' production CSS order can differ from dev environments, **breakage is often discovered only after deployment**.
Declaring in `peerDependencies` and handling as external in builds creates a contract saying "this library shares the Crispy from the project", leaving only one copy of Crispy in the bundle. Peer declarations are just contracts — bundlers don't automatically remove them, so you must handle externals separately.
## Diagnose Your Library Status
First, check the current state of your library. Depending on the four items below, you may have different tasks to do. To automate this diagnosis, use the prompt from **Self-diagnose with AI** at the bottom.
| Item to Check | Problem Status | Task to Do |
| ------------------------------ | ---------------------------------------------------------------------- | ------------------------------------------------------------------ |
| Where did you declare Crispy? | In `dependencies` | **If already declared in `dependencies`** section — switch to peer |
| Is the peer range honest? | No upper bound like `>=1.x` or spans 1.x minor with `^1.x` | **Setting version ranges** section |
| Is Crispy included in the build? | `seed-*` classes visible in dist | **Handling external in builds** section |
| Do you support Crispy 2.0? | peer accepts `^1` only, making 2.0 projects unable to use this library | **Expanding to Crispy 2.0** section |
## Declaring Dependencies and Configuring Builds
These are the declarations and build configurations a healthy library should have. This is where you actually apply the above **three core principles**.
### Declaring with peerDependencies
Declare Crispy packages in `peerDependencies`, and use `devDependencies` for development and testing installations.
```json title="package.json"
{
"peerDependencies": {
"@seed-design/css": "~1.2.0",
"@seed-design/react": "~1.2.0",
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
},
"devDependencies": {
"@seed-design/css": "1.2.14",
"@seed-design/react": "1.2.12"
}
}
```
### Setting Version Ranges
Crispy has different [**versioning policies with 2.0 as a breakpoint**](/react/updates/upgrade#versioning-policy), so peer ranges should also align with that breakpoint.
| Support Target | Recommended Range | Reason |
| -------------------- | -------------------- | ----------------------------------------------------------------------------------- |
| **2.0 and above** | `^2.0.0` (caret) | From 2.0, strict semver — minor and patch are backward compatible, so caret is safe |
| **1.x** | `~1.2.0` (tilde) | 1.x may have breaking changes in minor, so you must not span minor |
| **Both 1.x and 2.0** | `~1.2.0 \|\| ^2.0.0` | Transition period — see **Expanding to Crispy 2.0** below |
In 1.x, you must not use caret that spans minor like `^1.2.0`. Conversely, caret is normal in 2.0 and above. For the reason this difference exists, see [versioning policy](/react/updates/upgrade#versioning-policy).
When determining the lower bound for the 1.x range, use the **inter-package version compatibility** table from [Crispy React 1 and older](/react/updates/upgrade/v1) as a reference. During this period, `peerDependencies` declarations lack upper bounds or have missing ranges, so copying declarations directly may accept combinations that don't actually match.
If you have multiple verified ranges, you can connect them with OR(`||`) to widen the range. For example, if you support both the 1.2 range and 2.0 and above, declare it like this:
```json title="package.json"
{
"peerDependencies": {
"@seed-design/css": "~1.2.0 || ^2.0.0"
}
}
```
When widening with OR, also set **upper bounds** on each range. Without an upper bound like `>=1.2.11`, you're declaring that you accept even future majors that haven't been verified yet.
**Declare react and css separately.** Since `@seed-design/react` [uses css on a runtime basis](/react/updates/upgrade#compatibility-react--css), if you omit css from peer, there's no way to prevent the project from installing an incompatible css. Also, the majors of the two packages can go up independently (for example, react becomes major without css changes), so don't assume they're bundled as `^2`; validate and declare each package's range separately.
When new versions are released, verify functionality in the library and then widen the range. It's recommended to also specify the Crispy version range supported in the library README.
### Handling external in builds
Mark `@seed-design/*` as external so Crispy code isn't included in the build output.
Vite's lib mode doesn't automatically treat dependencies as external, so you need to specify them yourself.
```ts title="vite.config.ts"
import { defineConfig } from "vite";
export default defineConfig({
build: {
lib: {
entry: "src/index.ts",
formats: ["es"],
},
rollupOptions: {
external: [
/^@seed-design\//, // [!code highlight]
"react",
"react-dom",
"react/jsx-runtime",
],
},
},
});
```
tsup treats `dependencies` and `peerDependencies` as external by default. If you've correctly declared Crispy in `peerDependencies`, it works without extra configuration, but writing it explicitly is safer.
```ts title="tsup.config.ts"
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
format: ["esm"],
external: [/^@seed-design\//], // [!code highlight]
});
```
After building, verify that Crispy code and CSS aren't included in the dist output. If it was properly treated as external, the **import statements pointing to `@seed-design/*` remain as-is** in dist.
```sh
grep -rhoE '@seed-design/[a-z-]+' dist/ | sort -u
```
It's normal if the packages the library uses show up in the list. If it's empty, the imports are gone — meaning the code was inlined into the bundle.
```sh
grep -rl '\.seed-' dist/ # should have no results
```
This checks whether Crispy CSS got mixed into the bundle. Since it only catches **class definitions** for `.seed-`, referencing `var(--seed-*)` tokens in the library's own styles is not flagged.
### Delegate CSS imports to the project
In library code, don't import the CSS files from `@seed-design/css` directly.
```ts title="src/index.ts"
import "@seed-design/css/base.css"; // [!code --]
```
Instead, guide the project on what to do in the library's README.
````md title="README.md"
## Prerequisites
This package uses Crispy as a peer dependency.
Your project must have @seed-design/react and @seed-design/css installed,
and you must import base.css once at your app's entry point.
```ts
import "@seed-design/css/base.css";
```
````
## If you've already declared it in `dependencies`
Some libraries put Crispy in `dependencies` or include it in the bundle to avoid 1.x compatibility confusion. This still carries the risk of two copies of the CSS, so you need to move it to `peerDependencies`.
Switching from `dependencies` to `peerDependencies` **is itself a behavior-changing change**. The Crispy that the library used to keep bottled up inside itself now merges with the project's Crispy, which can surface version mismatches that were previously hidden. Follow the steps below to switch over safely.
### Move to peerDependencies
Move `@seed-design/*` from `dependencies` to `peerDependencies`, and declare it with a verified range (see **Setting Version Ranges** above). Also add a specific version to `devDependencies` for development and testing.
### Handle external in builds
Treat Crispy as external (see **Handling external in builds** above). Verify that Crispy code is absent from dist.
### Verify compatibility
```bash
npx @seed-design/cli@latest compat
```
Verifies snippet and peer compatibility.
### Bump the library's major version and ship
Since the way consumers install it changes (the project now needs to install Crispy directly), **bump the library's major version and ship it**. Guide consumers in the README that they need to "install Crispy in the project + import `base.css`."
## Expanding to Crispy 2.0
For projects (apps) to move up to Crispy 2.0, the libraries they use must also **accept** 2.0. If a library only accepts `^1`, that single library can block the entire project that uses it from moving to 2.0.
"Supporting 2.0" \**doesn't mean rebuilding the library for 2.0.*\* In most cases, it's just **a declaration change that widens the accepted version range**. You leave the library code as-is and declare "I work with either 1 or 2" (dual-compat).
First, [check the changelog](/react/updates/upgrade#check-changes) to see whether the components you use changed in 2.0. Then the most reliable approach is to bump Crispy in your dev dependencies to 2.0 and see whether the library's tests and build pass.
- npm: npm install @seed-design/react@2 @seed-design/css@2
- pnpm: pnpm add @seed-design/react@2 @seed-design/css@2
- yarn: yarn add @seed-design/react@2 @seed-design/css@2
- bun: bun add @seed-design/react@2 @seed-design/css@2
Your options depend on the result of that check.
| Situation | Option | What to do |
| ------------------------------------------------------------ | -------------------------------- | ----------------------------------------------------------------------------------------- |
| 2.0 breaking changes are **unrelated to the parts I use** | **A. Widen the range only** | Widen peer to `~1.2.0 \|\| ^2.0.0`. No code changes |
| The parts I use changed, but **supporting both is possible** | **B. Adjust code + dual-compat** | Adjust only the changed parts to work on both 1.x and 2.0, then widen the range |
| Supporting both at once is **difficult** | **C. Split by major version** | Bump the library's major version too, and split it (vN = Crispy 1 only, vN+1 = Crispy 2 only) |
| Supporting 2.0 isn't needed right now | **D. Stay on 1.x** | Keep `~1.2.0`. But verify you aren't blocking the project's 2.0 transition |
A and B are changes that widen the range the library accepts. Because changing the peer range affects how consumers' installs resolve, ship it as at least a minor release and update the supported range in the README. C is clearly a major release.
B (supporting both 1.x and 2.0 from one codebase) is only possible when the component exists on both sides, and it's harder to maintain as branching code grows. If you use a component that was renamed or removed, **C (splitting by major version) is usually cleaner**. If it's hard to decide, consult the `/seed-design` skill or the design system team.
## Don't import component vars directly
`@seed-design/css/vars/component/*` are internal-facing variables generated to implement component recipes.
Aside from `typography`, paths under `@seed-design/css/vars/component/*` [are not covered by SemVer guarantees](/react/updates/upgrade#versioning-policy). If the underlying component spec changes, their names and structure can change even in a minor or patch release.
If your library's public API or runtime logic uses these paths directly, it can break from nothing more than a minor or patch Crispy upgrade in the project. For styles you need, use the public components and recipe classes, or, if you need a raw value, look it up in [design tokens](/foundations/color) (`@seed-design/css/vars`).
The difference between the two paths comes down to what's guaranteed when you move to design tokens. Tokens **only change their name or value on a major release** — not just renames or removals, but even a color changing due to a design decision only happens on a major. Component vars, on the other hand, can change even on a minor or patch. Because a library has to pass its own version promise on to its consumers, this difference matters especially for libraries. See the [versioning policy](/react/updates/upgrade#versioning-policy) for the detailed rules.
A component's internal CSS variables (like `--seed-action-button-*`) share the same `--seed-` prefix, but they are not part of the public surface. If you need a button's background color, don't pull it from the button's internal variable — look up the same value from a design token (`fg`/`bg`/`palette`) instead.
## When installing snippets into a library
A snippet installed via the [CLI](/react/getting-started/cli/commands) becomes part of the library's source. Each snippet has the Crispy version range it requires, so you can check its compatibility with your package version using the `compat` command.
- npm: npx @seed-design/cli@latest compat
- pnpm: pnpm dlx @seed-design/cli@latest compat
- yarn: yarn dlx @seed-design/cli@latest compat
- bun: bun x @seed-design/cli@latest compat
Since `compat` [exits with code `1` if there's a compatibility issue](/react/updates/upgrade#checking-snippet-compatibility), adding it to your library's CI lets you automatically know whether snippets need to be reinstalled when you bump the Crispy version.
## Self-diagnose with AI
Give an AI (e.g. Claude Code) the prompt below based on this document, and it can check your library's Crispy dependency status and suggest migration options.
```text title="Prompt"
My library is a shared package that uses @seed-design/react (and @seed-design/css).
Please review it based on the guide at
https://crispy.carrot-soft.tech/react/getting-started/library-authors.
1. In package.json, check whether the @seed-design/* dependency is declared under
dependencies or peerDependencies, with what range, and point out any problems.
2. Check whether @seed-design/* is treated as external in the build config (vite/tsup, etc.).
3. Find any place in the library code that directly imports *.css from @seed-design/css.
4. Find any direct imports of @seed-design/css/vars/component/*, and check whether
any use of component vars other than typography has leaked into the public API
or runtime logic.
5. Find the Crispy components/hooks I actually use, and check the changelog to see
whether any of Crispy 2.0's breaking changes affect that list.
When determining the 1.x range, base it on the "inter-package version compatibility"
table at https://crispy.carrot-soft.tech/react/updates/upgrade/v1
(1.x can't be judged from the peer declaration alone).
6. Based on the above, recommend which option (A widen the range only / B adjust code
then dual-compat / C split by major version / D stay on 1.x) is appropriate, and
propose a revised peer range for package.json.
```
For a complex version jump or handling multiple packages at once, asking the `/seed-design` skill in Claude Code, etc. will pull together the changelog and `compat` into a step-by-step strategy.
## What to tell projects that use your library
These are the things a project (app) that uses your library should check. Include this guidance in the library's README as well.
- \[ ] The bundle contains **exactly one version each** of `@seed-design/css` and `@seed-design/react`. Check for duplicates in the lockfile, and force it with your package manager's `overrides` (npm) / `resolutions` (yarn) if needed.
- \[ ] The peer ranges of the libraries you install and the project's Crispy version have an **intersection**. Don't ignore your package manager's peer dependency warnings.
- \[ ] `@seed-design/css/base.css` is imported **only once**, at the app's entry point.
If the libraries you use require non-overlapping Crispy versions, loading two copies of the styles on one screen won't fix it. Coordinate version alignment with the teams providing the libraries, and reach out to the design system team channel if it's difficult.