npm-package by jwynia/agent-skills
npx skills add https://github.com/jwynia/agent-skills --skill npm-package使用 Bun 作为主要运行时和工具链来构建和发布 npm 包,生成可在所有使用 npm 包的地方工作的输出。
在以下情况下使用:
不要在以下情况下使用:
npx-cli 技能)| 关注点 | 工具 | 原因 |
|---|---|---|
| 运行时 / 包管理器 | Bun | 安装、运行、转译速度快 |
| 打包器 | Bunup | Bun 原生,双格式输出,生成 .d.ts |
| 类型声明 | Bunup(通过 tsc) | 与构建集成 |
| TypeScript | , + 额外选项 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
module: "nodenext"strict: true| 为发布代码提供最大正确性 |
| 格式化 + 基础代码检查 | Biome v2 | 比 ESLint 快 10-25 倍,单一工具 |
| 类型感知的代码检查 | ESLint + typescript-eslint | 40+ 条 Biome 无法处理的类型感知规则 |
| 测试 | Vitest | 测试隔离,成熟的模拟,覆盖率 |
| 版本管理 | Changesets | 基于文件,显式,支持 monorepo |
| 发布 | npm publish --provenance | 可信发布 / OIDC |
运行脚手架脚本以生成完整项目:
bun run <skill-path>/scripts/scaffold.ts ./my-package \
--name my-package \
--description "What this package does" \
--author "Your Name" \
--license MIT
选项:
--dual — 生成 CJS/ESM 双格式输出(默认:仅 ESM)--no-eslint — 跳过 ESLint,仅使用 Biome然后安装依赖项:
cd my-package
bun install
bun add -d bunup typescript vitest @vitest/coverage-v8 @biomejs/biome @changesets/cli
bun add -d eslint typescript-eslint # 除非使用了 --no-eslint
my-package/
├── src/
│ ├── index.ts # 包入口点 — 所有公共 API 导出在此
│ └── index.test.ts # 与源代码放在一起的测试
├── dist/ # 构建输出(被 git 忽略,包含在发布的 tarball 中)
├── .changeset/
│ └── config.json
├── package.json
├── tsconfig.json
├── bunup.config.ts
├── biome.json
├── eslint.config.ts # 仅类型感知规则
├── vitest.config.ts
├── .gitignore
├── README.md
└── LICENSE
在修改任何配置之前,请阅读这些参考文档。它们包含了每个决策背后的理由以及导致细微错误的棘手之处:
exports 映射配置,双包风险,module-sync,常见错误files 字段,可信发布,CI 流水线这些规则一旦违反,会导致已发布包中最常见和最棘手的错误。请务必遵守,无一例外。
"type": "module"。 仅 ESM 是正确的默认设置。在所有支持的 Node.js 版本中,require(esm) 都有效。exports 字段,而不是 main。 main 是遗留字段。exports 可以精确控制使用者可以访问的内容。types 必须是第一个条件。 如果不是,TypeScript 会静默地无法解析类型。"./package.json": "./package.json"。 许多工具需要访问 package.json,而 exports 会完全封装它。files: ["dist"]。 白名单方法可以防止泄露密钥。永远不要使用 .npmignore。npm pack --dry-run。 验证 tarball 包含的正是你打算发布的内容。module: "nodenext"。 而不是 "bundler"。满足 nodenext 的代码在任何地方都能工作;反之则不然。strict: true 是不可协商的。 没有它,你的 .d.ts 文件可能包含在使用严格模式的使用者那里会报错的类型。noUncheckedIndexedAccess。 捕获因未经保护的数组/对象访问而导致的真实运行时错误。declarationMap: true。 使使用者能够通过"转到定义"跳转到原始源代码。paths)。 tsc 不会在生成的代码中重写它们。使用者无法解析它们。any。 使用 unknown 并进行类型收窄。仅在确实无法避免时,使用 // biome-ignore suspicious/noExplicitAny: <原因> 来抑制,并且必须包含原因。import type。 这由 verbatimModuleSyntax 和 Biome 的 useImportType 规则强制执行。format: ['esm'](或对于双格式输出使用 ['esm', 'cjs'])。Bunup 处理 .d.ts 生成、外部依赖检测和正确的文件扩展名。engines.node 为 >=20.19.0。 这记录了最低支持的 Node.js 版本(首个具有稳定 require(esm) 的 LTS 版本)。# 编写代码和测试
bun run test:watch # Vitest 监视模式
# 检查所有内容
bun run lint # Biome + ESLint
bun run typecheck # tsc --noEmit
bun run test # Vitest 运行
# 构建
bun run build # Bunup → dist/
# 准备发布
bunx changeset # 创建描述变更的 changeset
bunx changeset version # 提升版本,更新 CHANGELOG
# 发布
bun run release # 构建 + npm publish --provenance
当包需要暴露多个入口点时:
src/utils.tsentry: ['src/index.ts', 'src/utils.ts']{
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./utils": {
"types": "./dist/utils.d.ts",
"default": "./dist/utils.js"
},
"./package.json": "./package.json"
}
}
提醒: 添加或删除导出路径是一个 semver-major 变更。
如果使用者需要 CJS 支持以兼容 Node.js < 20.19.0:
format: ['esm', 'cjs']module-sync、import 和 require 条件bun build 不生成 .d.ts 文件。 使用 Bunup(它委托给 tsc)或单独运行 tsc --emitDeclarationOnly。bun build 的 CJS 输出是实验性的。 对于可发布到 npm 的 CJS,始终使用 target: "node"。target: "bun" 会产生 Bun 特有的包装器。bun build 不会降级语法。 现代 ES2022+ 语法会原样发布。如果目标运行时较旧,则需要额外的转译。bun publish 不支持 --provenance。 使用 npm publish 进行来源证明签名。bun publish 使用 NPM_CONFIG_TOKEN,而不是 NODE_AUTH_TOKEN。CI 流水线可能需要调整。每周安装量
78
仓库
GitHub 星标
38
首次出现
2026年2月16日
安全审计
安装于
codex72
opencode72
gemini-cli71
github-copilot70
kimi-cli69
amp69
Build and publish npm packages using Bun as the primary runtime and toolchain, producing output that works everywhere npm packages are consumed.
Use when:
Do NOT use when:
npx-cli skill)| Concern | Tool | Why |
|---|---|---|
| Runtime / package manager | Bun | Fast install, run, transpile |
| Bundler | Bunup | Bun-native, dual output, .d.ts generation |
| Type declarations | Bunup (via tsc) | Integrated with build |
| TypeScript | module: "nodenext", strict: true + extras | Maximum correctness for published code |
| Formatting + basic linting | Biome v2 | 10-25x faster than ESLint, single tool |
| Type-aware linting | ESLint + typescript-eslint | 40+ type-aware rules Biome can't do |
| Testing | Vitest | Test isolation, mature mocking, coverage |
| Versioning | Changesets | File-based, explicit, monorepo-ready |
| Publishing | npm publish --provenance | Trusted Publishing / OIDC |
Run the scaffold script to generate a complete project:
bun run <skill-path>/scripts/scaffold.ts ./my-package \
--name my-package \
--description "What this package does" \
--author "Your Name" \
--license MIT
Options:
--dual — Generate dual CJS/ESM output (default: ESM-only)--no-eslint — Skip ESLint, use Biome onlyThen install dependencies:
cd my-package
bun install
bun add -d bunup typescript vitest @vitest/coverage-v8 @biomejs/biome @changesets/cli
bun add -d eslint typescript-eslint # unless --no-eslint
my-package/
├── src/
│ ├── index.ts # Package entry point — all public API exports here
│ └── index.test.ts # Tests co-located with source
├── dist/ # Built output (gitignored, included in published tarball)
├── .changeset/
│ └── config.json
├── package.json
├── tsconfig.json
├── bunup.config.ts
├── biome.json
├── eslint.config.ts # Type-aware rules only
├── vitest.config.ts
├── .gitignore
├── README.md
└── LICENSE
Read these reference docs before modifying any configuration. They contain the reasoning behind each decision and the sharp edges that cause subtle breakage:
exports map configuration, dual package hazard, module-sync, common mistakesfiles field, Trusted Publishing, CI pipelineThese are the rules that, when violated, cause the most common and painful bugs in published packages. Follow these without exception.
Always use"type": "module" in package.json. ESM-only is the correct default. require(esm) works in all supported Node.js versions.
Always useexports field, not main. main is legacy. exports gives precise control over what consumers can access.
types must be the first condition in every exports block. TypeScript silently fails to resolve types if it isn't.
Always export"./package.json": "./package.json". Many tools need access to the package.json and encapsulates completely.
Usemodule: "nodenext" for published packages. Not "bundler". Code satisfying nodenext works everywhere; the reverse is not true.
strict: true is non-negotiable. Without it, your .d.ts files can contain types that error for consumers using strict mode.
EnablenoUncheckedIndexedAccess. Catches real runtime bugs from unguarded array/object access.
ShipdeclarationMap: true. Enables "Go to Definition" to reach original source for consumers.
Do not use path aliases (paths) in published packages. tsc does not rewrite them in emitted code. Consumers can't resolve them.
any is banned. Use unknown and narrow. Suppress with // biome-ignore suspicious/noExplicitAny: <reason> only when genuinely unavoidable, and always include the reason.
Prefer named exports over default exports. Default exports behave differently across CJS/ESM boundaries.
Always useimport type for type-only imports. Enforced by both verbatimModuleSyntax and Biome's useImportType rule.
Build with Bunup using format: ['esm'] (or ['esm', 'cjs'] for dual). Bunup handles .d.ts generation, external detection, and correct file extensions.
Setengines.node to >=20.19.0 in package.json. This documents the minimum supported Node.js version (first LTS with stable require(esm)).
Use Vitest, not bun:test. bun:test lacks test isolation — module mocks leak between files. Vitest runs each test file in its own worker.
Set coverage thresholds (branches, functions, lines, statements all ≥ 80%). Enforced in vitest.config.ts.
# Write code and tests
bun run test:watch # Vitest watch mode
# Check everything
bun run lint # Biome + ESLint
bun run typecheck # tsc --noEmit
bun run test # Vitest run
# Build
bun run build # Bunup → dist/
# Prepare release
bunx changeset # Create changeset describing changes
bunx changeset version # Bump version, update CHANGELOG
# Publish
bun run release # Build + npm publish --provenance
When the package needs to expose multiple entry points:
src/utils.tsentry: ['src/index.ts', 'src/utils.ts']{
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./utils": {
"types": "./dist/utils.d.ts",
"default": "./dist/utils.js"
},
"./package.json": "./package.json"
}
}
Reminder: Adding or removing export paths is a semver-major change.
If consumers require CJS support for Node.js < 20.19.0:
format: ['esm', 'cjs']module-sync, import, and require conditionsbun build does not generate .d.ts files. Use Bunup (which delegates to tsc) or run tsc --emitDeclarationOnly separately.bun build CJS output is experimental. Always use target: "node" for npm-publishable CJS. target: "bun" produces Bun-specific wrappers.bun build does not downlevel syntax. Modern ES2022+ syntax ships as-is. If targeting older runtimes, additional transpilation is needed.bun publish does not support --provenance. Use npm publish for provenance signing.Weekly Installs
78
Repository
GitHub Stars
38
First Seen
Feb 16, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex72
opencode72
gemini-cli71
github-copilot70
kimi-cli69
amp69
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
120,000 周安装
精准肿瘤治疗顾问:基于分子谱的AI治疗建议工具,整合CIViC/OpenTargets/临床试验数据
178 周安装
LLM合成数据生成指南:如何创建多样化测试输入覆盖AI管道故障空间
180 周安装
响应式编程实战指南:RxJS异步数据流处理、状态管理与最佳实践
182 周安装
阿里云ESA边缘安全加速管理:Python SDK实现Pages、Edge Routine、KV与站点管理
180 周安装
SAST 安全扫描插件 | 多语言代码漏洞检测工具(Bandit/Semgrep/CodeQL)
188 周安装
SQL专家技能:数据库性能优化、云原生架构与高级查询技术指南
188 周安装
exportsUsefiles: ["dist"] in package.json. Whitelist approach prevents shipping secrets. Never use .npmignore.
Runnpm pack --dry-run before every publish. Verify the tarball contains exactly what you intend.
bun publish uses NPM_CONFIG_TOKEN, not NODE_AUTH_TOKEN. CI pipelines may need adjustment.