[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10362":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":19,"hasPages":19,"topics":21,"createdAt":9,"pushedAt":9,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":15,"starSnapshotCount":15,"syncStatus":16,"lastSyncTime":34,"discoverSource":35},10362,"np","sindresorhus\u002Fnp","sindresorhus","A better `npm publish`",null,"JavaScript",7699,310,29,6,0,2,38.48,"MIT License",false,"main",[22,23,24,25,26,27,28,29,30],"cli","cli-app","javascript","nodejs","npm","npm-package","npm-publish","publish","yarn","2026-06-12 02:02:20","# np [![XO code style](https:\u002F\u002Fshields.io\u002Fbadge\u002Fcode_style-5ed9c7?logo=xo&labelColor=gray&logoSize=auto&logoWidth=20)](https:\u002F\u002Fgithub.com\u002Fxojs\u002Fxo)\n\n> A better `npm publish`\n\n\u003Cimg src=\"media\u002Fscreenshot.gif\" width=\"688\">\n\n## Why\n\n- [Interactive UI](#interactive-ui)\n- Ensures you are publishing from your release branch (`main` and `master` by default)\n- Ensures the working directory is clean and that there are no unpulled changes\n- Reinstalls dependencies to ensure your project works with the latest dependency tree\n- Ensures your Node.js and npm versions are supported by the project and its dependencies\n- Runs the tests\n- Bumps the version in package.json and npm-shrinkwrap.json (if present) and creates a git tag\n- Prevents [accidental publishing](https:\u002F\u002Fgithub.com\u002Fnpm\u002Fnpm\u002Fissues\u002F13248) of pre-release versions under the `latest` [dist-tag](https:\u002F\u002Fdocs.npmjs.com\u002Fcli\u002Fdist-tag)\n- Publishes the new version to npm, optionally under a dist-tag\n- Rolls back the project to its previous state in case publishing fails\n- Pushes commits and tags (newly & previously created) to GitHub\u002FGitLab\n- Supports [two-factor authentication](https:\u002F\u002Fdocs.npmjs.com\u002Fgetting-started\u002Fusing-two-factor-authentication)\n- Enables two-factor authentication on new repositories\n  \u003Cbr>\n  \u003Csub>(does not apply to external registries)\u003C\u002Fsub>\n- Opens a prefilled GitHub Releases draft after publish\n- Warns about the possibility of extraneous files being published\n- See exactly what will be executed with [dry-run mode](https:\u002F\u002Fgithub.com\u002Fsindresorhus\u002Fnp\u002Fissues\u002F391), without pushing or publishing anything remotely\n- Supports [GitHub Packages](https:\u002F\u002Fgithub.com\u002Ffeatures\u002Fpackages)\n- Supports npm 9+, Yarn (Classic and Berry), pnpm 8+, and Bun\n\n### Why not\n\n- Monorepos are not supported.\n- CI is [not an ideal environment](https:\u002F\u002Fgithub.com\u002Fsindresorhus\u002Fnp\u002Fissues\u002F619#issuecomment-994493179) for `np`. It's meant to be used locally as an interactive tool.\n\n## Prerequisite\n\n- Node.js 20 or later\n- npm 9 or later\n- Git 2.11 or later\n\n## Install\n\n```sh\nnpm install --global np\n```\n\n## Usage\n\n```\n$ np --help\n\n  Usage\n    $ np \u003Cversion>\n\n    Version can be:\n      patch | minor | major | prepatch | preminor | premajor | prerelease | 1.2.3\n\n  Options\n    --any-branch            Allow publishing from any branch\n    --branch                Name of the release branch (default: main | master)\n    --no-cleanup            Skips np's node_modules cleanup step before install\n    --no-tests              Skips tests\n    --yolo                  Skips cleanup and testing\n    --no-publish            Skips publishing\n    --dry-run               Show tasks without actually executing them\n    --tag                   Publish under a given dist-tag\n    --contents              Subdirectory to publish\n    --no-release-draft      Skips opening a GitHub release draft\n    --release-draft-only    Only opens a GitHub release draft for the latest published version\n    --no-release-notes      Skips generating release notes when opening a GitHub release draft\n    --test-script           Name of npm run script to run tests before publishing (default: test)\n    --no-2fa                Don't enable 2FA on new packages (not recommended)\n    --message               Version bump commit message, '%s' will be replaced with version (default: '%s' with npm and 'v%s' with yarn)\n    --package-manager       Use a specific package manager (default: package.json packageManager\u002FdevEngines)\n    --provenance            Publish with npm provenance statements (CI-only)\n    --remote                Git remote to push to (default: origin)\n\n  Examples\n    $ np\n    $ np patch\n    $ np 1.0.2\n    $ np 1.0.2-beta.3 --tag=beta\n    $ np 1.0.2-beta.3 --tag=beta --contents=dist\n```\n\n## Interactive UI\n\nRun `np` without arguments to launch the interactive UI that guides you through publishing a new version.\n\n\u003Cimg src=\"media\u002Fscreenshot-ui.png\" width=\"1290\">\n\n## Config\n\n`np` can be configured both globally and locally. When using the global `np` binary, you can configure any of the CLI flags in either a `.np-config.js` (as CJS), `.np-config.cjs`, `.np-config.mjs`, or `.np-config.json` file in the home directory. When using the local `np` binary, for example, in a `npm run` script, you can configure `np` by setting the flags in either a top-level `np` field in `package.json` or in one of the aforementioned file types in the project directory. If it exists, the local installation will always take precedence. This ensures any local config matches the version of `np` it was designed for.\n\nCurrently, these are the flags you can configure:\n\n- `anyBranch` - Allow publishing from any branch (`false` by default).\n- `branch` - Name of the release branch (`main` or `master` by default).\n- `cleanup` - Delete `node_modules` before installing dependencies (`true` by default). Setting it to `false` only skips np's explicit cleanup step; the package manager install command still runs and may replace `node_modules` itself. Use `yolo` to skip install entirely.\n- `tests` - Run `npm test` (`true` by default).\n- `yolo` - Skip cleanup and testing (`false` by default).\n- `publish` - Publish (`true` by default).\n- `dryRun` - Show tasks without actually executing them (`false` by default). The CLI also accepts `--preview` as an alias.\n- `tag` - Publish under a given dist-tag (`latest` by default).\n- `contents` - Subdirectory to publish (`.` by default).\n- `releaseDraft` - Open a GitHub release draft after releasing (`true` by default).\n- `releaseNotes` - Auto-generate release notes when opening a GitHub release draft (`true` by default).\n- `testScript` - Name of npm run script to run tests before publishing (`test` by default).\n- `2fa` - Enable 2FA on new packages (`true` by default) (setting this to `false` is not recommended).\n- `message` - The commit message used for the version bump. Any `%s` in the string will be replaced with the new version. By default, npm uses `%s` and Yarn uses `v%s`.\n- `packageManager` - Set the package manager to be used. Defaults to the [`packageManager`](https:\u002F\u002Fnodejs.org\u002Fapi\u002Fpackages.html#packagemanager) or [`devEngines.packageManager`](https:\u002F\u002Fdocs.npmjs.com\u002Fcli\u002Fv11\u002Fconfiguring-npm\u002Fpackage-json#devengines) field in package.json, so only use if you can't update package.json for some reason.\n- `provenance` - Publish with [npm provenance statements](https:\u002F\u002Fdocs.npmjs.com\u002Fgenerating-provenance-statements) (`false` by default). Requires npm 9.5.0+ and a supported CI environment (GitHub Actions or GitLab CI\u002FCD).\n- `remote` - Git remote to push tags and commits to. Useful when publishing from a fork where `origin` is your fork and `upstream` is the main repository.\n\nFor example, this configures `np` to use `unit-test` as a test script, and to use `dist` as the subdirectory to publish:\n\n`package.json`\n```json\n{\n\t\"name\": \"superb-package\",\n\t\"np\": {\n\t\t\"testScript\": \"unit-test\",\n\t\t\"contents\": \"dist\"\n\t}\n}\n```\n\n`.np-config.json`\n```json\n{\n\t\"testScript\": \"unit-test\",\n\t\"contents\": \"dist\"\n}\n```\n\n`.np-config.js` or `.np-config.cjs`\n```js\nmodule.exports = {\n\ttestScript: 'unit-test',\n\tcontents: 'dist'\n};\n```\n\n`.np-config.mjs`\n```js\nexport default {\n\ttestScript: 'unit-test',\n\tcontents: 'dist'\n};\n```\n\n_**Note:** The global config only applies when using the global `np` binary, and is never inherited when using a local binary._\n\n## Tips\n\n### npm hooks\n\nYou can use any of the test\u002Fversion\u002Fpublish related [npm lifecycle hooks](https:\u002F\u002Fdocs.npmjs.com\u002Fmisc\u002Fscripts) in your package.json to add extra behavior.\n\nFor example, here we build the documentation before tagging the release:\n\n```json\n{\n\t\"name\": \"my-awesome-package\",\n\t\"scripts\": {\n\t\t\"version\": \".\u002Fbuild-docs && git add docs\"\n\t}\n}\n```\n\n### Release script\n\nYou can also add `np` to a custom script in `package.json`. This can be useful if you want all maintainers of a package to release the same way (Not forgetting to push Git tags, for example). However, you can't use `publish` as name of your script because it's an [npm defined lifecycle hook](https:\u002F\u002Fdocs.npmjs.com\u002Fmisc\u002Fscripts).\n\n```json\n{\n\t\"name\": \"my-awesome-package\",\n\t\"scripts\": {\n\t\t\"release\": \"np\"\n\t},\n\t\"devDependencies\": {\n\t\t\"np\": \"*\"\n\t}\n}\n```\n\n### User-defined tests\n\nIf you want to run a user-defined test script before publishing instead of the normal `npm test` or `yarn test`, you can use `--test-script` flag or the `testScript` config. This can be useful when your normal test script is running with a `--watch` flag or in case you want to run some specific tests (maybe on the packaged files) before publishing.\n\nFor example, `np --test-script=publish-test` would run the `publish-test` script instead of the default `test`.\n\n```json\n{\n\t\"name\": \"my-awesome-package\",\n\t\"scripts\": {\n\t\t\"test\": \"ava --watch\",\n\t\t\"publish-test\": \"ava\"\n\t},\n\t\"devDependencies\": {\n\t\t\"np\": \"*\"\n\t}\n}\n```\n\n### Signed Git tag\n\nSet the [`sign-git-tag`](https:\u002F\u002Fdocs.npmjs.com\u002Fmisc\u002Fconfig#sign-git-tag) npm config to have the Git tag signed:\n\n```\n$ npm config set sign-git-tag true\n```\n\nOr set the [`version-sign-git-tag`](https:\u002F\u002Fyarnpkg.com\u002Flang\u002Fen\u002Fdocs\u002Fcli\u002Fversion\u002F#toc-git-tags) Yarn config:\n\n```\n$ yarn config set version-sign-git-tag true\n```\n\n### Private packages\n\n\u003Cimg src=\"media\u002Fprivate-packages.png\" width=\"260\" align=\"right\">\n\nYou can use `np` for packages that aren't publicly published to npm (perhaps installed from a private git repo).\n\nSet `\"private\": true` in your `package.json` and the publishing step will be skipped. All other steps\nincluding versioning and pushing tags will still be completed.\n\n### Public scoped packages\n\nTo publish [scoped packages](https:\u002F\u002Fdocs.npmjs.com\u002Fmisc\u002Fscope#publishing-public-scoped-packages-to-the-public-npm-registry) to the public registry, you need to set the access level to `public`. You can do that by adding the following to your `package.json`:\n\n```json\n\"publishConfig\": {\n\t\"access\": \"public\"\n}\n```\n\nIf publishing a scoped package for the first time, `np` will prompt you to ask if you want to publish it publicly.\n\n**Note:** When publishing a scoped package, the first ever version you publish has to be done interactively using `np`. If not, you cannot use `np` to publish future versions of the package.\n\n### Private Org-scoped packages\n\nTo publish a [private Org-scoped package](https:\u002F\u002Fdocs.npmjs.com\u002Fcreating-and-publishing-an-org-scoped-package#publishing-a-private-org-scoped-package), you need to set the access level to `restricted`. You can do that by adding the following to your `package.json`:\n\n```json\n\"publishConfig\": {\n\t\"access\": \"restricted\"\n}\n```\n\n### Publish to a custom registry\n\nSet the [`registry` option](https:\u002F\u002Fdocs.npmjs.com\u002Fmisc\u002Fconfig#registry) in package.json to the URL of your registry:\n\n```json\n\"publishConfig\": {\n\t\"registry\": \"https:\u002F\u002Fmy-internal-registry.local\"\n}\n```\n\n### Package managers\n\nIf a package manager is not set in package.json (`packageManager` or `devEngines.packageManager`), via configuration (`packageManager`), or via the CLI (`--package-manager`), `np` will attempt to infer the best package manager to use by looking for lockfiles. But it's recommended to set the [`packageManager` field](https:\u002F\u002Fnodejs.org\u002Fapi\u002Fpackages.html#packagemanager) in your package.json to be consistent with other tools. See also the [corepack docs](https:\u002F\u002Fnodejs.org\u002Fapi\u002Fcorepack.html).\n\n### Publish with a CI\n\nIf you use a Continuous Integration server to publish your tagged commits, use the `--no-publish` flag to skip the publishing step of `np`.\n\n### Publish to gh-pages\n\nTo publish to `gh-pages` (or any other branch that serves your static assets), install [`branchsite`](https:\u002F\u002Fgithub.com\u002Fenriquecaballero\u002Fbranchsite), an `np`-like CLI tool aimed to complement `np`, and create an [npm \"post\" hook](https:\u002F\u002Fdocs.npmjs.com\u002Fmisc\u002Fscripts) that runs after `np`.\n\n```sh\nnpm install --save-dev branchsite\n```\n\n```json\n\"scripts\": {\n\t\"deploy\": \"np\",\n\t\"postdeploy\": \"bs\"\n}\n```\n\n### Initial version\n\nFor new packages, start the `version` field in package.json at `0.0.0` and let `np` bump it to `1.0.0` or `0.1.0` when publishing.\n\n### Release an update to an old major version\n\nTo release a minor\u002Fpatch version for an old major version, create a branch from the major version's git tag and run `np`:\n\n```console\n$ git checkout -b fix-old-bug v1.0.0 # Where 1.0.0 is the previous major version\n# Create some commits…\n$ git push --set-upstream origin HEAD\n$ np patch --any-branch --tag=v1\n```\n\n### The prerequisite step runs forever on macOS\n\nIf you're using macOS Sierra 10.12.2 or later, your SSH key passphrase is no longer stored into the keychain by default. This may cause the `prerequisite` step to run forever because it prompts for your passphrase in the background. To fix this, add the following lines to your `~\u002F.ssh\u002Fconfig` and run a simple Git command like `git fetch`.\n\n```\nHost *\n AddKeysToAgent yes\n UseKeychain yes\n```\n\nIf you're running into other issues when using SSH, please consult [GitHub's support article](https:\u002F\u002Fhelp.github.com\u002Farticles\u002Fconnecting-to-github-with-ssh\u002F).\n\n### Ignore strategy\n\nThe [ignore strategy](https:\u002F\u002Fdocs.npmjs.com\u002Ffiles\u002Fpackage.json#files), either maintained in the `files`-property in `package.json` or in `.npmignore`, is meant to help reduce the package size. To avoid broken packages caused by essential files being accidentally ignored, `np` prints out all the new and unpublished files added to Git. Test files and other [common files](https:\u002F\u002Fdocs.npmjs.com\u002Ffiles\u002Fpackage.json#files) that are never published are not considered. `np` assumes either a standard directory layout or a customized layout represented in the `directories` property in `package.json`.\n\n## FAQ\n\n### I get an error when publishing my package through Yarn\n\nIf you get an error like this…\n\n```shell\n❯ Prerequisite check\n✔ Ping npm registry\n✔ Check npm version\n✔ Check yarn version\n✖ Verify user is authenticated\n\nnpm ERR! code E403\nnpm ERR! 403 Forbidden - GET https:\u002F\u002Fregistry.yarnpkg.com\u002F-\u002Fpackage\u002Fmy-awesome-package\u002Fcollaborators?format=cli - Forbidden\n```\n\n…please check whether the command `npm access list collaborators my-awesome-package` succeeds. If it doesn't, Yarn has overwritten your registry URL. To fix this, add the correct registry URL to `package.json`:\n\n```json\n\"publishConfig\": {\n\t\"registry\": \"https:\u002F\u002Fregistry.npmjs.org\"\n}\n```\n\n### np hangs during the \"Publishing package\" step\n\nIf `np` hangs indefinitely during publishing, common causes include:\n\n**Lifecycle scripts that don't exit**\n\nnpm automatically runs lifecycle hooks like `prepublish`, `publish`, and `postpublish` during publishing. If these scripts don't exit (e.g., running in watch mode), `np` will hang.\n\n```json\n{\n\t\"scripts\": {\n\t\t\"test\": \"vitest\",\n\t\t\"publish\": \"npm run test && np\"\n\t}\n}\n```\n\n**Solution**: Don't name your scripts `publish`, `prepublish`, or `postpublish` (these are reserved npm lifecycle hooks). Use names like `release` instead:\n\n```json\n{\n\t\"scripts\": {\n\t\t\"test\": \"vitest run\",\n\t\t\"release\": \"np\"\n\t}\n}\n```\n\n**Tests running in watch mode**\n\nIf your test script runs in watch mode, it won't exit after running tests.\n\n**Solution**: Ensure your test command exits after running:\n\n```json\n{\n\t\"scripts\": {\n\t\t\"test\": \"vitest run\",\n\t\t\"test:dev\": \"vitest\"\n\t}\n}\n```\n\n**Registry configuration issues**\n\nA missing trailing slash in `.npmrc` registry configuration can cause hangs.\n\n**Solution**: Ensure registry URLs have a trailing slash:\n\n```npmrc\n@ORG:registry=https:\u002F\u002Fnpm.pkg.github.com\u002F\n```\n\n## Maintainers\n\n- [Sindre Sorhus](https:\u002F\u002Fgithub.com\u002Fsindresorhus)\n- [Tommy Mitchell](https:\u002F\u002Fgithub.com\u002Ftommy-mitchell)\n","np 是一个用于改进 npm 发布流程的工具。它通过提供交互式界面、确保从正确的分支发布、保持工作目录清洁、重新安装依赖项、检查 Node.js 和 npm 版本兼容性、运行测试、自动更新版本号并创建 Git 标签等功能，简化了发布过程。此外，np 支持两步验证、GitHub Packages 以及多种包管理器如 Yarn 和 pnpm。该工具适用于需要更安全、便捷地发布 npm 包的开发者，在本地环境中使用效果最佳，不推荐在 CI 环境中使用。","2026-06-11 03:27:59","top_topic"]