{"_id":"@dbarrett24/tsup-config","name":"@dbarrett24/tsup-config","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@dbarrett24/tsup-config","version":"1.0.0","description":"Shared tsup configuration for building component libraries","main":"dist/index.js","types":"dist/index.d.ts","dependencies":{"@pnpm/lockfile-file":"^8.1.2","@pnpm/logger":"^5.0.0","es-toolkit":"^1.26.1","tsup":"^8.0.1","typescript":"^5.8.2"},"devDependencies":{"prettier":"^3.4.2","@dbarrett24/eslint-config":"1.0.0","@dbarrett24/prettier-config":"1.0.0","@dbarrett24/typescript-config":"1.0.0"},"peerDependencies":{"prettier":"^3.0.0","tsup":"^8.0.0"},"publishConfig":{"access":"public"},"prettier":"@dbarrett24/prettier-config","keywords":["tsup","config","build","typescript","monorepo"],"author":{"name":"Your Name"},"license":"MIT","scripts":{"build":"tsup","dev":"tsup --watch","lint-ts":"eslint src --cache","lint-ts-fix":"pnpm lint-ts --fix","lint-prettier":"prettier --cache --check \"src/**/*.{json,js,jsx,ts,tsx}\"","lint-prettier-fix":"prettier --cache --write \"src/**/*.{json,js,jsx,ts,tsx}\"","ts-check":"tsc --noEmit","test":"echo 'No tests for tsup-config' && exit 0"},"_id":"@dbarrett24/tsup-config@1.0.0","_integrity":"sha512-sepqhBdnBaJY0zClCGc6smP+0MtYH1KtF8AZStoiuMPDoZUAWk8RUcPIAe/eVYqTfrZoX2Y2wtCCpXuAop7s6g==","_resolved":"/private/var/folders/q_/z4dwy_td5ts0fdx2klqhf_900000gn/T/84915cf6bbd7688b22898c9a8c348cac/dbarrett24-tsup-config-1.0.0.tgz","_from":"file:dbarrett24-tsup-config-1.0.0.tgz","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-sepqhBdnBaJY0zClCGc6smP+0MtYH1KtF8AZStoiuMPDoZUAWk8RUcPIAe/eVYqTfrZoX2Y2wtCCpXuAop7s6g==","shasum":"fe134c7ac445fcb0178dac94ce716e3479e5777f","tarball":"https://registry.npmjs.org/@dbarrett24/tsup-config/-/tsup-config-1.0.0.tgz","fileCount":6,"unpackedSize":33081,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEoSX6aYed6Ct2JrekxoaSd6sz2acmDxo6C576GhxuWWAiAXa+T1ifSMJQDxD0nYv3EUvlQazuy0rVly8diFAVh6Sw=="}]},"_npmUser":{"name":"dbarrett24","email":"dev.davebarrett@gmail.com"},"directories":{},"maintainers":[{"name":"dbarrett24","email":"dev.davebarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tsup-config_1.0.0_1769474807506_0.5726111963536329"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-27T00:46:47.383Z","1.0.0":"2026-01-27T00:46:47.658Z","modified":"2026-01-27T00:46:47.857Z"},"maintainers":[{"name":"dbarrett24","email":"dev.davebarrett@gmail.com"}],"description":"Shared tsup configuration for building component libraries","keywords":["tsup","config","build","typescript","monorepo"],"author":{"name":"Your Name"},"license":"MIT","readme":"# @yourname/tsup-config\n\n> Shared tsup configuration for building component libraries with automatic workspace dependency resolution and client directive injection.\n\n## 🎯 What This Solves\n\nWhen building component libraries in a monorepo, you face these challenges:\n\n1. **Workspace Dependencies**: During development you use `workspace:*`, but published packages need actual version numbers\n2. **Client Directives**: React client components need `'use client';` at the top of every file\n3. **Build Consistency**: Every library needs the same build configuration\n4. **package.json Management**: Published packages need a clean `dist/package.json` with correct entry points\n\nThis package **automates all of that**.\n\n---\n\n## 📦 Installation\n\n```bash\npnpm add -D @yourname/tsup-config tsup prettier\n```\n\n---\n\n## 🚀 Usage\n\n### Basic Setup\n\nIn your component library's `tsup.config.ts`:\n\n```typescript\nimport { makeConfig } from '@yourname/tsup-config';\n\nexport default makeConfig(\n    // Server-safe entries (no 'use client' needed)\n    {\n        index: 'src/index.ts',\n        utils: 'src/utils/index.ts',\n    },\n    // Client component entries (gets 'use client' prepended)\n    {\n        button: 'src/components/Button.tsx',\n        input: 'src/components/Input.tsx',\n    }\n);\n```\n\n### Advanced Setup with Overrides\n\n```typescript\nimport { makeConfig } from '@yourname/tsup-config';\n\nexport default makeConfig(\n    { index: 'src/index.ts' },\n    { button: 'src/components/Button.tsx' },\n    {\n        // Optional overrides\n        format: ['cjs', 'esm'],\n        external: ['react', 'react-dom'],\n        onSuccess: async () => {\n            console.log('Build complete!');\n        },\n    }\n);\n```\n\n---\n\n## ⚙️ What It Does\n\n### 1. Automatic Workspace Dependency Resolution\n\n**Your package.json:**\n\n```json\n{\n    \"dependencies\": {\n        \"@yourname/theme-system\": \"workspace:*\"\n    }\n}\n```\n\n**Generated dist/package.json:**\n\n```json\n{\n    \"dependencies\": {\n        \"@yourname/theme-system\": \"^1.2.3\"\n    }\n}\n```\n\n### 2. Client Directive Injection\n\n**Your component:**\n\n```tsx\n// src/components/Button.tsx\nexport const Button = ({ children }) => {\n    return <button>{children}</button>;\n};\n```\n\n**Built output:**\n\n```javascript\n// dist/button.js\n'use client';\n\nexport const Button = ({ children }) => {\n    return <button>{children}</button>;\n};\n```\n\n### 3. Clean package.json Generation\n\nAutomatically creates `dist/package.json` with only:\n\n- `name`\n- `version`\n- `dependencies`\n- `peerDependencies`\n- `sideEffects`\n- `main` (entry point)\n- `types` (type definitions)\n\n### 4. Consistent Build Configuration\n\nAll libraries get:\n\n- TypeScript declaration files (`.d.ts`)\n- CommonJS and ESM formats\n- Inline source maps\n- Tree-shaking support\n- External node_modules\n\n---\n\n## 📋 API Reference\n\n### `makeConfig(entries, clientEntries?, optionOverrides?)`\n\n**Parameters:**\n\n- **`entries`** (`Record<string, string>`) - Server-safe entry points\n  - Keys: Output file names\n  - Values: Source file paths\n- **`clientEntries`** (`Record<string, string>`, optional) - Client component entry points\n  - Same format as `entries`\n  - Gets `'use client'` prepended automatically\n- **`optionOverrides`** (`Partial<Options>`, optional) - Additional tsup options\n  - Any valid tsup configuration option\n  - Overrides default settings\n\n**Returns:** `Options` - tsup configuration object\n\n### `defaultConfigObject`\n\nThe base configuration applied to all builds:\n\n```typescript\n{\n  dts: true,                      // Generate .d.ts files\n  format: ['cjs', 'esm'],         // Output CommonJS and ESM\n  legacyOutput: true,             // Use legacy output structure\n  clean: true,                    // Clean dist before build\n  sourcemap: 'inline',            // Inline source maps\n  splitting: true,                // Enable code splitting\n  skipNodeModulesBundle: true,    // Don't bundle node_modules\n}\n```\n\n---\n\n## 🏗️ Project Structure Example\n\n```\nbasketball-training-ui/\n├── src/\n│   ├── components/\n│   │   ├── Button.tsx         # Client component\n│   │   └── Input.tsx          # Client component\n│   ├── utils/\n│   │   └── helpers.ts         # Server-safe utilities\n│   └── index.ts               # Main entry\n├── dist/                      # Generated by tsup\n│   ├── index.js\n│   ├── index.d.ts\n│   ├── button.js              # Has 'use client'\n│   ├── button.d.ts\n│   ├── utils.js\n│   ├── utils.d.ts\n│   └── package.json           # Auto-generated with resolved deps\n├── package.json\n└── tsup.config.ts             # Uses makeConfig()\n```\n\n---\n\n## 🔧 Configuration Tips\n\n### Separating Client and Server Code\n\n```typescript\nexport default makeConfig(\n    // Server/universal code\n    {\n        index: 'src/index.ts',\n        hooks: 'src/hooks/index.ts',\n        utils: 'src/utils/index.ts',\n    },\n    // Client components only\n    {\n        button: 'src/components/Button.tsx',\n        input: 'src/components/Input.tsx',\n        modal: 'src/components/Modal.tsx',\n    }\n);\n```\n\n### External Dependencies\n\nMark React and other large dependencies as external:\n\n```typescript\nexport default makeConfig(\n    { index: 'src/index.ts' },\n    { button: 'src/components/Button.tsx' },\n    {\n        external: ['react', 'react-dom', 'jotai', '@tanstack/react-query'],\n    }\n);\n```\n\n### Custom Build Output\n\n```typescript\nexport default makeConfig(\n    { index: 'src/index.ts' },\n    { button: 'src/components/Button.tsx' },\n    {\n        format: ['esm'], // ESM only\n        minify: true, // Minify output\n        target: 'es2020', // Target specific ECMAScript version\n    }\n);\n```\n\n---\n\n## 🧪 Verifying the Build\n\nAfter building, check that:\n\n1. **dist/package.json exists** with resolved workspace dependencies\n2. **Client components have 'use client'** at the top\n3. **Type definitions are generated** (`.d.ts` files)\n\n```bash\npnpm build\n\n# Check package.json\ncat dist/package.json\n\n# Check client directive\nhead -n 1 dist/button.js\n# Should show: 'use client';\n\n# Check types\nls dist/*.d.ts\n```\n\n---\n\n## 🤝 Integration with Changesets\n\nWhen using `@changesets/cli`, this package ensures published versions are correct:\n\n```bash\n# 1. Make changes to your library\n# 2. Create changeset\npnpm changeset\n\n# 3. Version packages (updates version numbers)\npnpm changeset version\n\n# 4. Build (workspace:* gets resolved to actual versions)\npnpm build\n\n# 5. Publish\npnpm changeset publish\n```\n\n---\n\n## 📚 Related Packages\n\n- **[@yourname/prettier-config](../prettier-config)** - Used for formatting generated package.json\n- **[@yourname/typescript-config](../typescript-config)** - TypeScript configuration for building\n- **[@yourname/theme-system](../theme-system)** - Common dependency in component libraries\n\n---\n\n## 🐛 Troubleshooting\n\n### \"Cannot find package.json in lockfile\"\n\n**Cause:** Package not listed in `pnpm-workspace.yaml`\n\n**Fix:**\n\n```yaml\n# pnpm-workspace.yaml\npackages:\n    - 'brand-libraries/*'\n    - 'shared-configs/*'\n```\n\n### \"'use client' not being added\"\n\n**Cause:** Component listed in `entries` instead of `clientEntries`\n\n**Fix:**\n\n```typescript\n// ❌ Wrong\nexport default makeConfig({\n    button: 'src/components/Button.tsx', // In entries - no 'use client'\n});\n\n// ✅ Correct\nexport default makeConfig(\n    {}, // Server entries\n    { button: 'src/components/Button.tsx' } // Client entries - gets 'use client'\n);\n```\n\n### \"Workspace dependencies not resolved\"\n\n**Cause:** Building outside of monorepo or lockfile not present\n\n**Fix:**\n\n- Ensure you're building from within the monorepo\n- Run `pnpm install` to generate/update `pnpm-lock.yaml`\n- Verify `pnpm-workspace.yaml` includes your package\n\n---\n\n## 📄 License\n\nMIT © Your Name\n\n","readmeFilename":"README.md","_rev":"1-ec99fb1c6bbe1f24cc9a54a897e8c3e5"}