paperclip/doc/PUBLISHING.md

120 lines
4 KiB
Markdown
Raw Normal View History

# Publishing to npm
2026-03-09 08:49:42 -05:00
Low-level reference for how Paperclip packages are built for npm.
2026-03-09 08:49:42 -05:00
For the maintainer release workflow, use [doc/RELEASING.md](RELEASING.md). This document is only about packaging internals and the scripts that produce publishable artifacts.
2026-03-09 08:49:42 -05:00
## Current Release Entry Points
2026-03-09 08:49:42 -05:00
Use these scripts instead of older one-off publish commands:
2026-03-09 08:49:42 -05:00
- [`scripts/release.sh`](../scripts/release.sh) for canary and stable npm publishes
- [`scripts/rollback-latest.sh`](../scripts/rollback-latest.sh) to repoint `latest` during rollback
- [`scripts/create-github-release.sh`](../scripts/create-github-release.sh) after a stable push
2026-03-09 08:49:42 -05:00
## Why the CLI needs special packaging
2026-03-09 08:49:42 -05:00
The CLI package, `paperclipai`, imports code from workspace packages such as:
2026-03-09 08:49:42 -05:00
- `@paperclipai/server`
- `@paperclipai/db`
- `@paperclipai/shared`
- adapter packages under `packages/adapters/`
2026-03-09 08:49:42 -05:00
Those workspace references use `workspace:*` during development. npm cannot install those references directly for end users, so the release build has to transform the CLI into a publishable standalone package.
2026-03-09 08:49:42 -05:00
## `build-npm.sh`
2026-03-09 08:49:42 -05:00
Run:
```bash
./scripts/build-npm.sh
```
2026-03-09 08:49:42 -05:00
This script does six things:
2026-03-09 08:49:42 -05:00
1. Runs the forbidden token check unless `--skip-checks` is supplied
2. Runs `pnpm -r typecheck`
3. Bundles the CLI entrypoint with esbuild into `cli/dist/index.js`
4. Verifies the bundled entrypoint with `node --check`
5. Rewrites `cli/package.json` into a publishable npm manifest and stores the dev copy as `cli/package.dev.json`
6. Copies the repo `README.md` into `cli/README.md` for npm package metadata
2026-03-09 08:49:42 -05:00
`build-npm.sh` is used by the release script so that npm users install a real package rather than unresolved workspace dependencies.
2026-03-09 08:49:42 -05:00
## Publishable CLI layout
2026-03-09 08:49:42 -05:00
During development, [`cli/package.json`](../cli/package.json) contains workspace references.
2026-03-09 08:49:42 -05:00
During release preparation:
2026-03-09 08:49:42 -05:00
- `cli/package.json` becomes a publishable manifest with external npm dependency ranges
- `cli/package.dev.json` stores the development manifest temporarily
- `cli/dist/index.js` contains the bundled CLI entrypoint
- `cli/README.md` is copied in for npm metadata
2026-03-09 08:49:42 -05:00
After release finalization, the release script restores the development manifest and removes the temporary README copy.
2026-03-09 08:49:42 -05:00
## Package discovery
2026-03-09 08:49:42 -05:00
The release tooling scans the workspace for public packages under:
2026-03-09 08:49:42 -05:00
- `packages/`
- `server/`
- `cli/`
2026-03-09 08:49:42 -05:00
`ui/` remains ignored for npm publishing because it is private.
2026-03-09 08:49:42 -05:00
This matters because all public packages are versioned and published together as one release unit.
2026-03-09 08:49:42 -05:00
## Canary packaging model
2026-03-09 08:49:42 -05:00
Canaries are published as semver prereleases such as:
2026-03-09 08:49:42 -05:00
- `1.2.3-canary.0`
- `1.2.3-canary.1`
2026-03-09 08:49:42 -05:00
They are published under the npm dist-tag `canary`.
2026-03-09 08:49:42 -05:00
This means:
2026-03-09 08:49:42 -05:00
- `npx paperclipai@canary onboard` can install them explicitly
- `npx paperclipai onboard` continues to resolve `latest`
- the stable changelog can stay at `releases/v1.2.3.md`
2026-03-09 08:49:42 -05:00
## Stable packaging model
2026-03-09 08:49:42 -05:00
Stable releases publish normal semver versions such as `1.2.3` under the npm dist-tag `latest`.
2026-03-09 08:49:42 -05:00
The stable publish flow also creates the local release commit and git tag. Pushing the commit/tag and creating the GitHub Release happen afterward as separate maintainer steps.
2026-03-09 08:49:42 -05:00
## Rollback model
2026-03-09 08:49:42 -05:00
Rollback does not unpublish packages.
2026-03-09 08:49:42 -05:00
Instead, the maintainer should move the `latest` dist-tag back to the previous good stable version with:
2026-03-09 08:49:42 -05:00
```bash
./scripts/rollback-latest.sh <stable-version>
```
2026-03-09 08:49:42 -05:00
That keeps history intact while restoring the default install path quickly.
2026-03-09 08:49:42 -05:00
## Notes for CI
2026-03-09 08:49:42 -05:00
The repo includes a manual GitHub Actions release workflow at [`.github/workflows/release.yml`](../.github/workflows/release.yml).
2026-03-09 08:49:42 -05:00
Recommended CI release setup:
2026-03-09 08:49:42 -05:00
- use npm trusted publishing via GitHub OIDC
- require approval through the `npm-release` environment
- run releases from `master`
- use canary first, then stable
2026-03-09 08:49:42 -05:00
## Related Files
2026-03-09 08:49:42 -05:00
- [`scripts/build-npm.sh`](../scripts/build-npm.sh)
- [`scripts/generate-npm-package-json.mjs`](../scripts/generate-npm-package-json.mjs)
- [`cli/esbuild.config.mjs`](../cli/esbuild.config.mjs)
- [`doc/RELEASING.md`](RELEASING.md)