npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

create-npkg

v0.0.12

Published

Create a new TypeScript npm package with best practices

Readme

create-npkg

快速创建符合最佳实践的 TypeScript npm 包

CI npm Node Tests

特性

  • ✅ 现代化 TypeScript 配置(严格模式)
  • ✅ ES2022 + NodeNext 模块系统
  • ✅ 标准的 package.json 配置(含 exports 字段)
  • ✅ 可选的 Git 初始化
  • ✅ 可选的自动依赖安装
  • ✅ 交互式命令行界面
  • ✅ 快速模式支持(--yes 标志)
  • ✅ 完善的测试套件(36 个测试)
  • ✅ 类型安全的源代码
  • ✅ 完善的 .gitignore 配置
  • ✅ 支持路径别名(@src/*)

使用方法

交互式模式

npm create npkg@latest

快速模式(使用默认配置)

npm create npkg@latest my-package -- --yes

带选项的创建

npm create npkg@latest my-package -- --yes --no-git --no-install

使用 npx

npx create-npkg my-package

使用 Yarn

yarn create npkg my-package

命令行选项

| 标志 | 说明 | |------|------| | --yes / -y | 跳过交互式提示,使用默认配置 | | --no-git | 跳过 Git 仓库初始化 | | --no-install | 跳过依赖安装 |

生成的项目结构

my-package/
├── .gitignore              # 完善的忽略规则配置
├── package.json            # 现代化 npm 配置(含 exports)
├── tsconfig.json           # 严格模式的 TypeScript 配置
├── README.md               # 自动生成的项目文档
└── src/
    └── index.ts            # 示例 TypeScript 代码

生成的 package.json

{
  "name": "your-package",
  "version": "1.0.0",
  "type": "module",
  "main": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "import": "./dist/index.js",
      "types": "./dist/index.d.ts"
    }
  },
  "scripts": {
    "build": "tsc",
    "dev": "tsc --watch",
    "prepublishOnly": "npm run build"
  },
  "engines": {
    "node": ">=18.0.0"
  }
}

TypeScript 配置

生成的 tsconfig.json 包含以下特性:

  • ✅ 启用严格模式
  • ✅ ES2022 目标版本
  • ✅ NodeNext 模块解析
  • ✅ 路径别名(@src/*)
  • ✅ 声明文件映射
  • ✅ 源码映射
  • ✅ 所有严格检查选项

测试

create-npkg 拥有完善的测试套件:

# 运行测试
npm test

# 监听模式运行测试
npm run test:watch

测试覆盖范围

  • ✅ 包名验证(有效/无效用例)
  • ✅ package.json 生成
  • ✅ tsconfig.json 生成
  • ✅ .gitignore 生成
  • ✅ README.md 生成
  • ✅ 源代码生成
  • ✅ 测试文件生成
  • ✅ 完整包创建流程
  • ✅ 目录结构验证
  • ✅ 不同许可证类型(MIT、Apache-2.0、ISC、BSD-3-Clause)
  • ✅ 作者字段处理
  • ✅ TypeScript 严格模式选项

36 个测试覆盖所有功能

开发

# 克隆仓库
git clone https://github.com/yourusername/create-npkg.git
cd create-npkg

# 安装依赖
npm install

# 构建
npm run build

# 运行测试
npm test

# 监听模式
npm run dev

为什么选择 create-npkg?

vs Yeoman

  • ✅ 无需全局安装
  • ✅ 使用现代 npm 标准
  • ✅ 更简单的 API
  • ✅ 更快的执行速度

vs Shell 脚本

  • ✅ 类型安全(TypeScript)
  • ✅ 跨平台兼容
  • ✅ 更好的错误处理
  • ✅ 交互式命令行
  • ✅ 美观的输出效果

vs 自定义脚本

  • ✅ 完善的测试套件
  • ✅ 内置最佳实践
  • ✅ 持续更新
  • ✅ 社区支持

许可证

MIT © [Your Name]