Publishing to npm
Hatch's packages are published under the @hatchmd scope: @hatch/vault in this repo installs as @hatchmd/vault. The @hatch scope on npm belongs to someone else. The scope, the version and the packages left out are in scripts/publish.json.
Build and publish
npx tsx scripts/build-packages.ts # every package into packages/<name>/dist
npx tsx scripts/build-packages.ts --pack /tmp/pkgs # plus a tarball of each, to try in a fresh app
npx tsx scripts/build-packages.ts --publish --dry-run
NPM_TOKEN=... npx tsx scripts/build-packages.ts --publish
--publish skips any version npm already has, so a failed run can be started again. --only vault,markdown builds just those. Raise version in scripts/publish.json before each release: every package goes out at the same version, and Hatch's packages depend on each other at that version.
npm needs a token with publish rights to the scope. Either sign in with npm login, or put //registry.npmjs.org/:_authToken=${NPM_TOKEN} in ~/.npmrc and set NPM_TOKEN.
What a package looks like
- Plain ESM JavaScript, one file per entry in the package's
exports, with shared code in chunks. Not minified. - Type declarations in
types/, andexportspoints at them. Imports between Hatch's packages name the scoped package. - Its dependencies stay imports. Hatch's own are pinned to the release version.
binentries (hatch-mcp,hatch-site,hatch-migrate) run with plain Node.- The MIT license and the package's
README.md, when it has one.
@hatch/editor keeps its own build (scripts/build-editor-package.ts): one bundle with Hatch's packages inside, plus its stylesheets. See packages/editor/README.md.
Left out
The app (@hatch/app), the demo vault (@hatch/starter), the plugin API and the built-in plugins need the app's Vite build, so they aren't published. The shadcn registry's grid item imports @hatch/app/grid, so it only works inside this repo until the grid is split out.
The shadcn registry (apps/registry) names the scoped packages too: its build (apps/registry/src/scope.ts) rewrites @hatch/ to the scope in what /r serves.
Checking a build
The way the first release was checked: pack every package, install the tarballs in an empty folder outside the repo with npm install /tmp/pkgs/*.tgz react @types/node typescript, then import every entry in Node and type-check a file that imports every entry with "moduleResolution": "NodeNext" and skipLibCheck: false.