返回提示词目录第 1165 页

检查并准备npm软件包发布

检查软件包配置、构建产物与打包内容,验证消费者导入方式,并整理安全的首次发布步骤。

完整提示词

<context>
A published npm version can never be republished under the same number, so first releases should be checked before they go out. The usual first-release bugs: the `exports` map does not match the built files, or lists `import` and `require` conditions pointing at the same ESM file, so CommonJS users crash; `types` points to a file that is not in the tarball, or the `types` condition is not listed first inside each `exports` entry; no `files` list or `.npmignore`, so tests, source maps of private code, or a local `.env` ship; a `bin` script without a shebang or executable mode; build output missing because `prepublishOnly` or `prepare` was not set; and `peerDependencies` duplicated as `dependencies`, so users get two copies of React. Scoped packages are private by default and need public access on the first publish. A pre-release published without an explicit dist-tag can end up as `latest`, depending on the npm version, so always pass `--tag`. Accounts should use two-factor authentication, and trusted publishing from CI with provenance removes long-lived tokens.

{{> guardrails/investigate-before-answering}}

Package:
<package>
{{package}}
</package>
</context>

<task>
1. Name and access: check that the intended name is free or is a scope you control (say how to check with `npm view`), and whether it is confusingly close to an existing popular package. Note public access for scoped packages.
2. Read package.json, the build config and the output folder. Fix: `name`, `version` (start at 0.1.0 or 1.0.0 deliberately), `description`, `license` (SPDX), `repository`, `keywords`, `type`, `exports` with correct conditions and `types` first, `main` and `types` fallbacks for older tools, `files`, `bin` with a shebang, `engines`, `sideEffects` if relevant, and peer versus regular dependencies.
3. Make sure the build runs before publishing (`prepublishOnly` or the release pipeline) and that a LICENSE and README exist.
4. Tarball check: run the build and `npm pack --dry-run`, list what would ship, and remove anything that should not be there. If available, run a package checker such as `publint` or a types resolution check, and fix what it reports.
5. Consumer test: install the packed tarball into a scratch project (ESM and CommonJS, and TypeScript if types ship) and import it the way users will.
6. Publishing steps: the exact commands for the first publish (`npm publish --access public` for scoped packages, `--tag next` for pre-releases), enabling 2FA on the account, and moving to trusted publishing with provenance from CI for later releases.
</task>

<constraints>
- Do not run `npm publish`, `npm unpublish` or `npm deprecate`; give the commands for the user to run.
- Do not change the package's runtime code except where the packaging fix requires it, and say why.
- Never put npm tokens in files in the repository.
- Do not claim a name is available without checking; if you cannot run `npm view`, say so.
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
Use the contract's section headings in order. package.json changes as a diff. Tarball check as the list of files that will ship. Publishing steps as exact commands in a fenced block. Verified lists commands run and their results.
</output_format>

可替换内容

  • {{> guardrails/investigate-before-answering}}
  • {{package}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、npm发布、开源维护、软件打包、发布安全

前往 AI 图片创作