Back to Skills

ts-library

Use when authoring TypeScript libraries or npm packages - covers project setup, package.json exports, build tooling (tsdown/unbuild), API design patterns, type inference tricks, testing, and publishing to npm. Use when bundling, configuring dual CJS/ESM output, or setting up release workflows.

688stars34forksUpdated 7/16/2026

Security Assessment

High Risk(30/100)

Detected risks:

Destructive Operations([references/project-setup.md] rm -rf, [setup/project.md] rm -rf)
Sensitive File Access([references/build-tooling.md] .env)
Security Score30/100

About ts-library

ts-library is a guidance skill for authoring high-quality TypeScript libraries and npm packages, with patterns extracted from studying projects such as unocss, shiki, unplugin, vite, vitest, vueuse, zod, trpc, and drizzle-orm. It solves the recurring problems of setting up a new library project, configuring package.json exports for dual CJS/ESM output, choosing and configuring build tooling, designing type-safe public APIs, writing advanced TypeScript types, testing, and publishing to npm. It is organized so the agent loads only the reference files relevant to the current task rather than everything at once.

The skill centers on a New Library Workflow: create the project structure, configure package.json exports, set up the build with tsdown, verify the build with pnpm build && pnpm pack --dry-run (checking that output includes .mjs, .cjs, and .d.ts), add tests, and configure release. A Quick Reference table maps tasks to on-demand reference files including references/project-setup.md, references/package-exports.md, references/typescript-config.md, references/build-tooling.md, references/eslint-config.md, references/api-design.md, references/type-patterns.md, references/testing.md, references/release.md, and references/ci-workflows.md. It ships quick-start snippets for a minimal package.json (with exports, main, module, types, and files fields) and a tsdown.config.ts using defineConfig with entry, format ['esm','cjs'], and dts: true. Key principles include ESM-first with "type": "module" and .mjs outputs, always supporting both CJS and ESM, moduleResolution: "Bundler", using tsdown for most builds and unbuild for complex cases, smart defaults over forced config, and tree-shakeable output via lazy getters and sideEffects: false.

Target users are developers building single-package or monorepo TypeScript libraries who need consistent, modern conventions for bundling, dual-format output, API design patterns (builder, factory, plugin), advanced type inference, vitest-based testing, and release/CI workflows. The skill notes that for Nuxt module development the separate nuxt-modules skill should be used instead. It is explicitly token-efficient, with the main skill around 300 tokens and each reference roughly 800-1200 tokens, and instructs the agent not to load all files at once.

FAQ

What does the recommended new library workflow look like?

Create the project structure, configure package.json exports, set up the build with tsdown, verify with pnpm build && pnpm pack --dry-run (confirming output includes .mjs, .cjs, and .d.ts), add tests, and configure the release, loading the matching reference file at each step.

Which build tools does the skill recommend?

It recommends tsdown for most builds and unbuild for complex cases. The quick-start tsdown.config.ts uses defineConfig with entry ['src/index.ts'], format ['esm','cjs'], and dts: true.

How does it handle dual CJS/ESM output?

It is ESM-first with "type": "module" and .mjs outputs while always supporting both CJS and ESM consumers. The minimal package.json defines exports with import (.mjs) and require (.cjs) plus main, module, types, and a files array.

Do I need to load every reference file to use the skill?

No. The skill explicitly says not to load all files at once and to load only the reference relevant to the current task, using the Quick Reference table to map tasks like package exports, tsconfig, build configuration, testing, and release to their files.

Does this skill cover Nuxt module development?

No. For Nuxt module development the skill directs you to use the separate nuxt-modules skill instead.

All Files

19 files
patterns/types.md4.1 KB
View
references/project-setup.md2.7 KB
View
setup/project.md2.7 KB
View
references/api-design.md4.3 KB
View
references/release.md2.7 KB
View
setup/tsconfig.md3.3 KB
View
references/eslint-config.md3.2 KB
View
references/ci-workflows.md5.9 KB
View
references/type-patterns.md4.1 KB
View
workflows/ci.md5.9 KB
View
patterns/api.md4.3 KB
View
references/package-exports.md2.9 KB
View
setup/exports.md2.9 KB
View
workflows/testing.md3.5 KB
View
references/build-tooling.md3.2 KB
View
references/testing.md3.5 KB
View
SKILL.md4.8 KB
View
references/typescript-config.md3.3 KB
View
workflows/release.md2.7 KB
View

Install ts-library

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill