选择命令行版本:
🌐 Synopsis
npm hook add <pkg> <url> <secret> [--type=<type>]npm hook ls [pkg]npm hook rm <id>npm hook update <id> <url> <secret>
注意:此命令不支持工作区。
🌐 Note: This command is unaware of workspaces.
🌐 Description
允许你管理 npm hooks,包括添加、删除、列出和更新。
🌐 Allows you to manage npm hooks, including adding, removing, listing, and updating.
钩子允许你配置 URL 端点,当任何受支持的实体类型发生更改时,这些端点会收到通知。钩子可以监视三种不同类型的实体:包、所有者和作用域。
🌐 Hooks allow you to configure URL endpoints that will be notified whenever a change happens to any of the supported entity types. Three different types of entities can be watched by hooks: packages, owners, and scopes.
要创建包钩子,只需引用包名称。
🌐 To create a package hook, simply reference the package name.
要创建一个所有者钩子,请在所有者名称前加上 ~ 前缀(如 ~youruser)。
🌐 To create an owner hook, prefix the owner name with ~ (as in, ~youruser).
要创建一个作用域钩子,请在作用域名称前加上 @(例如 @yourscope)。
🌐 To create a scope hook, prefix the scope name with @ (as in, @yourscope).
update 和 rm 使用的钩子 id 是 npm hook ls 中列出的该特定钩子的 ID。
🌐 The hook id used by update and rm are the IDs listed in npm hook ls for that particular hook.
共享密钥将被发送到 URL 端点,因此你可以验证请求来自你自己配置的钩子。
🌐 The shared secret will be sent along to the URL endpoint so you can verify the request came from your own configured hook.
🌐 Example
添加一个钩子来观察一个包的变化:
🌐 Add a hook to watch a package for changes:
$ npm hook add lodash https://example.com/ my-shared-secret
添加一个钩子来监视属于用户 substack 的包:
🌐 Add a hook to watch packages belonging to the user substack:
$ npm hook add ~substack https://example.com/ my-shared-secret
添加一个钩子以监视 @npm 范围内的包
🌐 Add a hook to watch packages in the scope @npm
$ npm hook add @npm https://example.com/ my-shared-secret
列出所有活动的钩子:
🌐 List all your active hooks:
$ npm hook ls
列出 lodash 包的所有活动钩子:
🌐 List your active hooks for the lodash package:
$ npm hook ls lodash
更新现有钩子的 url:
🌐 Update an existing hook's url:
$ npm hook update id-deadbeef https://my-new-website.here/
移除一个钩子:
🌐 Remove a hook:
$ npm hook rm id-deadbeef
🌐 Configuration
registrynpm 注册表的基本 URL。
🌐 The base URL of the npm registry.
otp这是来自双因素认证器的一次性密码。在使用 npm access 发布或更改软件包权限时需要此密码。
🌐 This is a one-time password from a two-factor authenticator. It's needed when publishing or changing package permissions with npm access.
如果未设置,并且注册表响应失败并询问一次性密码,npm 将在命令行上提示输入一次密码。
🌐 If not set, and a registry response fails with a challenge for a one-time password, npm will prompt on the command line for one.
🌐 See Also