First-publish packaging contract
Dual ESM/CJS emit, types-first exports ordering, tsup dir-style entries, tsc-built DTS, sourcemap-free tarballs, peer-dep tightening — the package-build conventions every @pleach/* SKU follows at 1.0.
Every @pleach/* SKU follows the same packaging conventions at its
first 1.x publish. For day-to-day consumers, this page is
informational — knowing the contract makes debugging install or
import issues faster. For forkers and vendored installs, it's
load-bearing: a fork that diverges from it can stop installing or
importing cleanly for its own consumers.
Dual ESM + CJS emit
Every @pleach/* package ships both module systems from a single
TypeScript source tree. ESM (.mjs) is the primary distribution;
CJS (.js) is a compatibility layer for Node consumers on older
toolchains that can't resolve native ESM cleanly.
The package.json exports block routes the right format per
resolver. ESM consumers resolve .mjs; CJS consumers resolve
.js; TypeScript reads .d.ts. The dual emit is non-negotiable —
dropping CJS would break a substantial fraction of consumers on
Node 18 and below.
| Format | Extension | Resolver |
|---|---|---|
| ESM | .mjs | import condition |
| CJS | .js | require condition |
| Types | .d.ts | types condition |
Types-first exports ordering
The Node spec walks exports conditions top-to-bottom and picks
the first match. The types condition must come first in each
export entry. Wrong order → TypeScript falls through to import
or default, reads the JavaScript file as if it were types, and
the consumer sees "no type declarations" errors.
{
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
}
}This is a Node spec rule, not a Pleach convention. Every @pleach/*
package follows it.
Dir-style tsup entries
Build entries are directories (src/audit/, src/cache/,
src/sessions/), not single files. tsup walks each entry
directory's index.ts and emits a matching
dist/<dir>/index.{mjs,js,d.ts} triple.
{
"tsup": {
"entry": ["src/audit", "src/cache", "src/sessions"],
"format": ["esm", "cjs"]
}
}The directory convention keeps the entry list compact as the package grows. Adding a new subpath is one entry, not three artifact paths.
DTS via tsc --build, not tsup's dts block
tsup's bundled-DTS mode tends to break with complex type
re-exports — it loses some declarations and mangles others when
a module re-exports a generic across barrels. The convention is
to disable tsup's DTS output entirely and run tsc --build for
declarations.
{
"scripts": {
"build": "tsup && tsc --build tsconfig.build.json"
}
}tsup emits JS only; the separate tsc pass emits .d.ts. The
build script runs both in order. The tsconfig.build.json
typically sets emitDeclarationOnly: true and declarationMap: false.
Sourcemap exclusion from the published tarball
Sourcemaps live on disk in dev (dist/*.map) but the files
field in package.json excludes them from npm pack.
{
"files": [
"dist/**/*.mjs",
"dist/**/*.js",
"dist/**/*.d.ts",
"LICENSE",
"NOTICE",
"README.md"
]
}The empirical reason: including sourcemaps pushed the published tarball from ~25 MB to >100 MB, which slowed CI installs across every consumer. Sourcemaps remain available in the git repo for debugging — clone the source tag and rebuild locally if you need them.
PeerDep tightening
At 1.x, peer-dep ranges tighten. The typical pattern is a caret on a single major version, sometimes narrower for packages with known breakage windows.
| Range style | When |
|---|---|
^18.0.0 | Stable peer with predictable semver |
>=18.0.0 <20 | Peer with known breakage in 20.x |
^18.2.0 | Pinning to a specific minor for a bug-fix floor |
The discipline avoids the "two copies of React" duplicate-install class of bug, where the consumer pulls one major and a transitive dep pulls another. Consumer responsibility: install peers explicitly rather than relying on transitive resolution.
NOTICE, CHANGELOG, provenance, sideEffects
Four baselines every 1.x publish carries.
NOTICE
License-attribution file referenced from package.json via the
files array. Required at first 1.x publish. Carries the
package's own license notice plus third-party attributions for
any bundled or derived code.
CHANGELOG.md
Keep a Changelog format. By release convention, every publish writes an entry with no "Unreleased" tail, and the top entry names the version being published.
npm provenance
Publishes use npm publish --provenance, which ties the tarball
to the GitHub Actions workflow that built it via a signed SLSA
attestation. Consumers verify with:
npm audit signaturesThe attestation links the tarball hash to the commit SHA, the workflow file, and the runner. Useful for supply-chain auditing and for confirming a published artifact matches the source tag.
sideEffects: false
Set in package.json where accurate — for @pleach/*, every
published package qualifies. The flag lets bundlers tree-shake
unused exports out of consumer bundles.
{
"sideEffects": false
}The setting is honored by Webpack, Rollup, esbuild, and Vite.
Roughly a 30% bundle reduction for apps that only import a
handful of named subpaths from @pleach/core.
What's checked before a release
CI checks these before a release.
- Exports. The install rehearsal below imports each runtime subpath
in
package.json#exportsfrom the packed tarball and type-checks a consumer of the root entry. - Version. The in-tree
package.json#versionis compared to the latest version on the registry.
Install rehearsal
CI runs each published package through an end-to-end simulation of
what a real npm consumer experiences. It runs through npm pack, installs into a
scratch directory outside the source tree, and exercises the published
surface the way a consumer would.
| Step | What it does | What it catches |
|---|---|---|
| 1 | Pack the package and its peers, and install the tarballs into a scratch directory | Tarball-shape problems, missing files entries, peer resolution failures |
| 2 | Import each facet from the installed package | Facet barrel breakage, missing re-exports |
| 3 | Import each runtime subpath in package.json#exports | Subpath resolution failures, missing dist/ files |
| 4 | Type-check a consumer file with tsc --noEmit under strict NodeNext | .d.ts problems a source-tree tsc can't see |
| 5 | Run each example | Breakage on the public surface |
You can run the same rehearsal on your own package: npm pack, install
the tarball in an empty directory, import each subpath, and type-check
a consumer file under strict.
For consumers — debugging install issues
Three common symptoms and what they usually mean.
| Symptom | Likely cause |
|---|---|
Cannot find module "@pleach/core/<subpath>" | The subpath isn't in the exports map — check Subpath exports |
Module has no exported member on a type-only import | types condition out of order in the consumer's bundler resolver — pin to a recent bundler version |
| Sourcemap warnings in dev tools | Benign — the tarball deliberately excludes sourcemaps |
The first one is the most common: a deep import that worked
against @pleach/core/* (wildcard) before a named barrel
landed, then stopped resolving the way the consumer expected.
The fix is to import from the barrel, not the deep path.
The second usually means an old bundler or moduleResolution: "node" instead of "bundler" / "node16" in the consumer's
tsconfig.json. The types-first ordering is correct on the
package side; the resolver needs to honor it.
For forkers and vendored installs
If you vendor @pleach/* into a private registry or fork the source,
mirror the conventions above and rehearse the install before you
publish.
Where to go next
When a check fails
What you see when your code breaks a Pleach rule, what it means, and the fix — the lookup an agent can read straight from an error to the change.
Cycle-break contract packages
Why Pleach extracts a zero-dependency `@pleach/<sku>-contract` package when a sibling SKU's type contract needs to be referenced from inside `@pleach/core`. The pattern, the boundary it protects, and when to use it.