Publish Config
Validated by requirePublishConfig in @trezor/requirements (packages/requirements/src/requirements/package-json/requirePublishConfig.ts).
Applies to any package with publishConfig.
Rules
- Top-level
main— required (e.g."./src/index.ts"). files— must include"lib/".publishConfig.mainandpublishConfig.types— both required.publishConfig.exports["."].defaultandpublishConfig.exports["."].types— must export the same files as in Rule 3.- Wildcard exports — (
./lib/*) must be a passthrough string ("./lib/*") — an object would double the.jsextension. - Explicit (non-wildcard) exports — not shape-checked (intentional overrides). Typically used to route a directory import to its
index.js, e.g."./lib/protocol-thp": { "types": "./lib/protocol-thp/index.d.ts", "default": "./lib/protocol-thp/index.js" }— without this, the wildcard would resolve toprotocol-thp.jsinstead ofprotocol-thp/index.js. - Key order —
"types"must come before"default"in every condition object (recursive). TypeScript evaluates conditions in declaration order. type— must declare top-level"type": "module". Do not duplicate it underpublishConfig.type—publishConfigwould only shadow the top level with the same value at publish time, so we keep a single source of truth.
Example
{
"name": "@trezor/example",
"main": "./src/index.ts", // Rule 1
"type": "module", // Rule 8
"files": ["lib/", "CHANGELOG.md"], // Rule 2
"publishConfig": {
"main": "./lib/index.js", // Rule 3
"types": "./lib/index.d.ts", // Rule 3
"exports": {
".": {
// Rule 4: exact shape required
"types": "./lib/index.d.ts", // Rule 7: "types" before "default"
"default": "./lib/index.js",
},
// Rule 5: ESM wildcard — passthrough string
"./lib/*": "./lib/*",
},
},
}