All skills
onmax avatar

/ts-library

@50538df

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.

  • 20 files
  • 73.4 KB
  • MIT
  • Updated 7 months ago
  • GitHub

Use this Skill: https://skilld.dev/gh/onmax/claude-config/ts-library

This session only. Nothing lands on disk.

setupexports.md

≈732 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Package Exports

Basic Single Entry

{
  "name": "my-lib",
  "version": "1.0.0",
  "type": "module",
  "exports": {
    ".": {
      "types": "./dist/index.d.mts",
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  },
  "main": "./dist/index.cjs",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.mts",
  "sideEffects": false,
  "files": ["dist"]
}

Multiple Entry Points

{
  "exports": {
    ".": {
      "types": "./dist/index.d.mts",
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    },
    "./utils": {
      "types": "./dist/utils.d.mts",
      "import": "./dist/utils.mjs",
      "require": "./dist/utils.cjs"
    },
    "./*": "./dist/*"
  }
}

Plugin Entry Pattern (unplugin-*)

{
  "exports": {
    ".": {
      "types": "./dist/index.d.mts",
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    },
    "./vite": {
      "types": "./dist/vite.d.mts",
      "import": "./dist/vite.mjs",
      "require": "./dist/vite.cjs"
    },
    "./webpack": {
      "types": "./dist/webpack.d.mts",
      "import": "./dist/webpack.mjs",
      "require": "./dist/webpack.cjs"
    },
    "./nuxt": {
      "types": "./dist/nuxt.d.mts",
      "import": "./dist/nuxt.mjs",
      "require": "./dist/nuxt.cjs"
    }
  }
}

Environment-Aware Exports

{
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "node": {
        "import": { "production": "./dist/index.prod.mjs", "development": "./dist/index.mjs" },
        "require": { "production": "./dist/index.prod.cjs", "development": "./dist/index.cjs" }
      },
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  }
}

typesVersions Fallback

For older TypeScript versions without exports support:

{
  "typesVersions": {
    "*": {
      "*": ["./dist/*", "./*"]
    }
  }
}

Field Reference

Field Purpose
exports Modern entry points (Node 12.7+)
main CJS fallback for older bundlers
module ESM fallback for bundlers
types TypeScript fallback
sideEffects false enables tree-shaking
files What gets published to npm

Condition Order

Order matters! Put most specific first:

{
  ".": {
    "types": "...",      // Always first
    "import": "...",     // ESM
    "require": "..."     // CJS fallback
  }
}

Peer Dependencies

External deps that consumers must provide:

{
  "peerDependencies": {
    "vue": "^3.0.0"
  },
  "peerDependenciesMeta": {
    "vue": { "optional": true }
  }
}

Package Validation

# Check exports are correct
pnpm dlx publint
pnpm dlx @arethetypeswrong/cli

Add to CI for continuous validation.

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at 50538df. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 14 hours ago.

Activeupdated 7 months ago

README badge

README badge for onmax/claude-config/ts-library