js-library-packaging
Pack placement.
engineering-base. The step asked for it to be suggested by the
reactandtypescriptpacks, and the skill schema carries nosuggested_bykey — so the
intent is recorded here rather than expressed in frontmatter that would fail validation.
A React or TypeScript consumer receives this skill through
engineering-base, which both
of those packs require.
The JavaScript twin of composer-packages. A component is
a file; a library is a package with a public surface, and that surface is declared in
package.json rather than inferred. Most of the failures below are silent at author time
and loud at the consumer's — which is why the surface is read, not assumed.
The Iron Law
`react` AND `react-dom` ARE peerDependencies. NEVER dependencies.
`types` IS THE FIRST KEY OF EVERY CONDITIONS OBJECT.
DECIDE buildable-VS-source-consumed BEFORE WRITING THE EXPORTS MAP.
NEVER HAND-BUMP A VERSION.
When to use
A package in the repository is imported by another package, or is about to be published:
an exports map is being written or changed, a hook fails at runtime with *"invalid hook
call"*, an install fails on a workspace: range, a release needs cutting, or the
buildable-vs-source question has not been answered yet.
Procedure
- Answer buildable-vs-source-consumed FIRST. It determines the exports map, the
files
list, and whether a build step exists at all — deciding it after writing the map means
rewriting the map.
- Source of truth: is the package published to a registry, or only consumed inside
this workspace?
- Verify: the exports targets all point into one of the two worlds (
src/or the
build directory), never a mix.
- Read the surface rather than asserting it. Run the check below over the package root.
- Source of truth:
package.json—exports,dependencies,peerDependencies,
files, private, publishConfig.
- Verify: zero
error-severity findings.
- Fix peer placement before anything else. A library carrying
reactin
dependencies gives the consumer a second copy of React.
- Verify:
reactandreact-domappear underpeerDependenciesonly.
- Order the conditions.
typesfirst, thenimport/require.
- Verify: the check reports no
types-not-first.
- Cut the release through the repository's own mechanism — never by editing a version
field. See § Release.
- Verify: the version change is produced by the tool the repository already carries.
Read the surface
node <skills-root>/js-library-packaging/scripts/check_package_surface.mjs \
<library-root> [<library-root> …]
scripts/check_package_surface.ts beside this skill, shipped as the .mjs the line above
names. Deterministic, JSON on stdout, no network and no subprocess. It reports:
| Code | Severity | Why |
|---|---|---|
| peer-as-dependency | error | two copies of React in one tree break hooks at runtime, with a message that names neither package |
| export-target-missing | error | the manifest promises a file the package does not ship |
| no-exports-map | warn | main/module without exports — the entry point resolves by bundler convention, not by declaration |
| types-not-first | warn | conditions match in declaration order, so a later types is never seen and the package silently ships untyped |
| workspace-range-publishable | warn | a workspace: range does not resolve outside the workspace; published, the consumer's install fails |
It classifies from the declared export targets, never from a directory name. A package
directory called ui-lib-vite is not evidence about Vite, and one called buildable is not
evidence that anything builds. A mixed declaration is reported as undeclared rather
than resolved to a guess — declaring both is the ambiguity worth surfacing.
What it does not do: it never compiles and never runs a bundler, so it cannot tell you
the declared layout is producible. A checker that grew a parser would report compile errors
as packaging errors, and the two have different fixes.
Buildable vs. source-consumed
| | source-consumed | buildable |
|---|---|---|
| exports point at | src/ | the build directory |
| build step | none | one, and it must run before publish |
| files | not needed (nothing published) | the build directory, as an allow-list |
| private | true on a workspace-only package | absent; publishConfig.access set instead |
| cost | consumer compiles it | a build to maintain, and output that can go stale |
Default to source-consumed inside a workspace. A build step exists to serve publication;
adding one for a package nobody publishes is a maintenance cost with no consumer.
Release
Read the repository, then take exactly one branch — Class A, per