Typecheck
Checks source and tests. It should create no files.
Use one TypeScript configuration to check the repository and another to emit the files consumers need.
Checks source and tests. It should create no files.
Checks package source and writes JavaScript, declarations, and maps to dist.
One large emitting configuration often compiles tests and unrelated workspace packages. Separate configurations make the publication boundary visible.
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"exactOptionalPropertyTypes": true,
"noUncheckedIndexedAccess": true,
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"skipLibCheck": true,
"noEmit": true
},
"include": ["packages/**/*.ts"]
}
strict is the baseline for a library whose types become someone else's editor experience. NodeNext makes TypeScript follow Node.js module rules, including explicit .js extensions in relative ESM imports.
ES2022 is a compatibility target, not the current year. Pick the oldest JavaScript level supported by every runtime you promise to support, then test those runtimes in CI.
Place this file at packages/sdk/tsconfig.build.json:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"noEmit": false,
"declaration": true,
"declarationMap": true,
"sourceMap": true
},
"include": ["src/index.ts"]
}
extendsrootDir and outDirnoEmit: falsedeclaration.d.ts files so TypeScript consumers receive the public API.declarationMapsourceMapinclude{
"scripts": {
"build": "tsc -p tsconfig.build.json"
}
}
cd packages/sdk
pnpm build
tsc preserves imports. If the SDK imports ArkType or a contracts package, those remain dependencies in the emitted JavaScript. The package manager installs them for consumers.
Add a bundler only for a measured requirement such as browser bundles, multiple module formats, code splitting, or reducing many internal files. A bundler adds configuration, declaration handling, and another compatibility layer.
sed -n '1,120p' dist/index.js
sed -n '1,160p' dist/index.d.ts
Confirm that JavaScript imports use resolvable package names and that declarations expose only intended public types. A successful compiler exit proves type correctness, not package correctness.
Why does the root configuration use noEmit: true?
The root command checks all source and tests without scattering build output through the workspace. Each publishable package controls its own emitted files.
Does pnpm pack automatically run a script named build?
No. A later lesson adds the special prepack lifecycle script, which pnpm runs before packing.