Agent skill
typescript-tsup-setup
Install, repair, or standardize tsup in TypeScript projects for library and Node app builds. Use when users ask to add tsup, set ESM/CJS outputs, generate `.d.ts`, fix `package.json` `exports`/entry fields, replace legacy build scripts, or verify dist artifacts and runtime entry resolution.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/typescript-tsup-setup
SKILL.md
Setup TSup
Use this workflow to set up tsup with minimal, production-safe defaults.
Inputs to collect
projectRoot(default: current working directory)targetKind:libraryornode-appentry: defaultsrc/index.tsfor libraries,src/main.tsfor appsformats:esm,cjs, or bothgenerateDts: defaulttruefor libraries,falsefor appsaddWatchScript: defaulttrue
Workflow
-
Validate project context
- Check
package.jsonexists. - Detect package manager from lockfile (
package-lock.json,pnpm-lock.yaml,yarn.lock). - Detect module mode from
package.json.type. - Confirm entry file(s) exist before writing config.
- If
tsup.config.tsexists, back up intent by preserving non-default options unless they conflict with explicit user requirements.
- Check
-
Ensure dependency
- Install
tsupas a dev dependency if missing:npm i -D tsuppnpm add -D tsupyarn add -D tsup
- Keep existing pinned version unless the user asks to upgrade.
- Install
-
Create or minimally update
tsup.config.ts- Use
defineConfigfromtsup. - Preserve existing advanced options unless they are clearly wrong.
- Use
-
Apply target profile
- Use this baseline for libraries:
import { defineConfig } from 'tsup'
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
sourcemap: true,
clean: true,
})
- Use this baseline for Node apps:
import { defineConfig } from 'tsup'
export default defineConfig({
entry: ['src/main.ts'],
format: ['cjs'],
platform: 'node',
sourcemap: true,
clean: true,
})
- Match output format to runtime expectations:
- If
package.json.typeis"module", preferesm. - If runtime expects CommonJS, keep
cjs.
- If
-
Update
package.jsonscripts- Add or update:
"build": "tsup""build:watch": "tsup --watch"whenaddWatchScript = true
- For apps, add a production start script that matches output filename.
- Preserve unrelated existing scripts.
- Add or update:
-
Align package entry fields for libraries
- Ensure
main,module,types, andexportspoint to generated files. - Use explicit extensions when dual-format output is needed:
- Ensure
outExtension({ format }) {
return { js: format === 'cjs' ? '.cjs' : '.mjs' }
}
{
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
}
}
- Verify
- Run
npm run build/pnpm build/yarn buildbased on detected package manager. - Confirm expected artifacts exist in
dist/. - For libraries, verify
package.jsonentry fields point to actual emitted files. - For apps, run built output with
nodeto confirm runtime resolution.
- Run
Guardrails
- Do not change module system (
type: modulevs CommonJS) unless explicitly asked. - Do not force minification, treeshaking strategy, or code splitting unless requested.
- Do not overwrite non-trivial existing config; merge minimally.
- For monorepos, run install and build in the package directory, not the repo root.
- Note: tsup upstream is in maintenance mode. Keep using tsup when requested; suggest tsdown only if the user asks about long-term migration.
- Use Node package entry conventions conservatively: treat
exportsas authoritative when present, and keepmainfor backward compatibility where needed.
Output checklist
tsupexists indevDependencies.tsup.config.tsmatches target kind and runtime format.package.jsonscripts build successfully.- Library package entry fields (
exportsandtypes) match generated outputs. - Build verification was executed and result reported.
Additional resources
Use reference.md for advanced options, edge cases, and troubleshooting.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?