Generate a complete TypeScript library project with ESM/CJS dual output, testing, documentation, linting, and automated npm publishing.
## ROLE You are a JavaScript ecosystem expert who has published and maintained dozens of npm packages with millions of weekly downloads. You understand the complexities of modern JavaScript packaging: ESM/CJS dual output, proper TypeScript declaration files, tree-shaking support, subpath exports, peer dependencies, and the publishing workflow. You create library starter kits that handle all this complexity so developers can focus on their library's functionality. ## CONTEXT Publishing a TypeScript library to npm should be simple, but the current ecosystem makes it surprisingly complex. You need to: output both ESM and CJS for maximum compatibility, generate proper .d.ts files, configure package.json exports correctly, set up tree-shaking, handle peer dependencies, write tests that cover both module systems, and automate the publishing process. Getting any of these wrong results in "cannot find module" errors for your users. A proper starter kit handles all of this correctly from day one. ## TASK Generate a complete TypeScript library starter kit: 1. **Build Configuration**: Set up tsup (or rollup) for dual ESM/CJS output: entry point configuration, declaration file generation, source maps, external dependencies, and bundle analysis. Configure package.json with proper exports, main, module, types, and files fields. 2. **TypeScript Configuration**: Create tsconfig.json optimized for library authoring: strict mode, declaration generation, path aliases for internal imports, and separate configs for source and tests. 3. **Testing Setup**: Configure Vitest with: unit test examples, coverage reporting with thresholds, test utilities, and a CI-friendly configuration. Show patterns for testing exported functions, classes, and async operations. 4. **Linting & Formatting**: Set up ESLint flat config + Prettier with: TypeScript-specific rules, import sorting, no unused exports detection, and format-on-save configuration. 5. **Documentation**: Set up documentation generation: TSDoc comments on all exports, automatic API documentation generation (TypeDoc or similar), README template with badges, installation, usage examples, and API reference. 6. **Publishing Workflow**: Create a GitHub Actions workflow for automated publishing: version bump (conventional commits + semantic-release or changesets), changelog generation, npm publish on tag creation, GitHub release creation, and provenance attestation. 7. **Development Workflow**: Configure: dev mode with watch (rebuild on file change), playground or example project for manual testing, pre-commit hooks (lint-staged + husky), and a CONTRIBUTING guide for external contributors. 8. **Package Metadata**: Configure all package.json fields: name, description, keywords, repository, license, engines, sideEffects (for tree-shaking), and browserslist (if the library targets browsers). ## INFORMATION ABOUT ME - [LIBRARY PURPOSE — WHAT IT DOES] - [TARGET ENVIRONMENT] (browser, Node.js, or both) - [DEPENDENCIES] (if any external dependencies are needed) - [PUBLISHING SCOPE] (public npm, private registry, GitHub packages) ## RESPONSE FORMAT Deliver: complete project structure, all configuration files, example source code with proper exports, test examples, CI workflow, and README template.
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[TARGET ENVIRONMENT][DEPENDENCIES][PUBLISHING SCOPE]