npm-outdated

检查过时的包

选择命令行版本:

概要

🌐 Synopsis

npm outdated [<package-spec> ...]

描述

🌐 Description

此命令将检查注册表以查看当前是否有任何(或特定)已安装的包已过时。

🌐 This command will check the registry to see if any (or, specific) installed packages are currently outdated.

默认情况下,仅显示根项目的直接依赖以及你配置的 workspaces 的直接依赖。也可以使用 --all 来查找所有过时的元依赖。

🌐 By default, only the direct dependencies of the root project and direct dependencies of your configured workspaces are shown. Use --all to find all outdated meta-dependencies as well.

在输出中:

🌐 In the output:

  • wanted 是满足 package.json 中指定的 semver 范围的包的最大版本。如果没有可用的 semver 范围(即,你正在运行 npm outdated --global,或者包未包含在 package.json 中),那么 wanted 会显示最新版本。
  • latest 是在注册表中标记为最新版本的包。运行 npm publish 并且没有特殊配置时,将会以 latest 的 dist-tag 发布该包。该版本可能是包的最大版本,也可能是最新发布的版本,这取决于包的开发者如何管理最新的 dist-tag
  • location 表示软件包在物理树中的位置。
  • depended by 显示哪个软件包依赖于所显示的依赖
  • package type(在使用 --long / -l 时)会告诉你这个包是 dependency 还是开发/同伴/可选依赖。未包含在 package.json 中的包总是标记为 dependencies
  • homepage(当使用 --long / -l 时)是包的 packument 中包含的 homepage
  • depended by location(在使用 --long / -l 时)显示依赖于所显示依赖的软件包的位置
  • 红色表示有更新的版本符合你的 semver 要求,因此你应该立即更新。
  • 黄色表示存在一个比你的 semver 要求更新的版本(通常是新的主要版本,或新的 0.x 次要版本),因此请谨慎操作。

一个示例

🌐 An example

$ npm outdated
Package Current Wanted Latest Location Depended by
glob 5.0.15 5.0.15 6.0.1 node_modules/glob dependent-package-name
nothingness 0.0.3 git git node_modules/nothingness dependent-package-name
npm 3.5.1 3.5.2 3.5.1 node_modules/npm dependent-package-name
local-dev 0.0.3 linked linked local-dev dependent-package-name
once 1.3.2 1.3.3 1.3.3 node_modules/once dependent-package-name

使用这些 dependencies

🌐 With these dependencies:

{
"glob": "^5.0.15",
"nothingness": "github:othiym23/nothingness#master",
"npm": "^3.5.1",
"once": "^1.3.1"
}

需要注意的几点:

🌐 A few things to note:

  • glob 需要 ^5,这导致 npm 无法安装 glob@6,因为它不在 semver 范围内。
  • 由于 Git 依赖的指定方式,Git 依赖总是会被重新安装。安装的提交可能满足依赖规范(如果它是某个不可变的东西,比如提交 SHA),也可能不满足,因此 npm outdatednpm update 必须获取 Git 仓库以进行检查。这就是为什么目前重新安装 Git 依赖总是会强制进行新的克隆和安装的原因。
  • npm@3.5.2 被标记为“所需”,但“最新”是 npm@3.5.1,因为 npm 使用 dist-tags 来管理它的 latestnext 发布渠道。npm update 将安装最新版本,但 npm install npm(没有语义化版本范围)将安装被标记为 latest 的版本。
  • once 已经过时了。重新从头安装 node_modules 或运行 npm update 就可以使其符合规范。

配置

🌐 Configuration

all

  • 默认:否
  • 类型:布尔

显示或操作所有包,而不仅仅是你的项目直接依赖的包。对于 npm outdatednpm ls,它会列出每个过时或已安装的包。对于 npm approve-scriptsnpm deny-scripts,它会选择每个有待执行安装脚本的包。

🌐 Show or act on all packages, not just the ones your project directly depends on. For npm outdated and npm ls this lists every outdated or installed package. For npm approve-scripts and npm deny-scripts it selects every package with pending install scripts.

json

  • 默认:否
  • 类型:布尔

是否输出 JSON 数据,而不是正常输出。

🌐 Whether or not to output JSON data, rather than the normal output.

  • npm pkg set 中,它可以在将值保存到你的 package.json 之前使用 JSON.parse() 解析设置的值。

并非所有 npm 命令都支持。

🌐 Not supported by all npm commands.

long

  • 默认:否
  • 类型:布尔

lssearchhelp-search 中显示扩展信息。

🌐 Show extended information in ls, search, and help-search.

parseable

  • 默认:否
  • 类型:布尔

从写入标准输出的命令中输出可解析的结果。对于 npm search,这将是制表符分隔的表格格式。

🌐 Output parseable results from commands that write to standard output. For npm search, this will be tab-separated table format.

global

  • 默认:否
  • 类型:布尔

以“全局”模式运行,因此软件包会安装到 prefix 文件夹中,而不是当前工作目录。有关行为差异的更多信息,请参见 folders

🌐 Operates in "global" mode, so that packages are installed into the prefix folder instead of the current working directory. See folders for more on the differences in behavior.

  • 软件包被安装到 {prefix}/lib/node_modules 文件夹中,而不是当前工作目录。
  • bin 文件与 {prefix}/bin 关联
  • 手册页已链接到 {prefix}/share/man

workspace

  • 默认值:
  • 类型:字符串(可以多次设置)

启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。

🌐 Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.

workspace 配置的有效值为以下之一:

🌐 Valid values for the workspace config are either:

  • 工作区名称
  • 工作区目录的路径
  • 父工作区目录的路径(将导致选择该文件夹中的所有工作区)

对于 npm init 命令设置时,可以将其设置为一个尚不存在的工作区文件夹,以创建该文件夹并将其作为项目内全新的工作区进行设置。

🌐 When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.

此值不会导出到子进程的环境中。

🌐 This value is not exported to the environment for child processes.

before

  • 默认值:空
  • 类型:空或日期

如果传递给 npm install,将重建 npm 树,使得只安装在指定日期当日或之前可用的版本。如果当前依赖集没有可用版本,该命令将报错。

🌐 If passed to npm install, will rebuild the npm tree such that only versions that were available on or before the given date are installed. If there are no versions available for the current set of dependencies, the command will error.

如果请求的版本是 dist-tag,且给定的标签未通过 --before 过滤器,则将使用小于或等于该标签的最新版本。例如,foo@latest 可能会安装 foo@1.2,即使 latest2.0

🌐 If the requested version is a dist-tag and the given tag does not pass the --before filter, the most recent version less than or equal to that tag will be used. For example, foo@latest might install foo@1.2 even though latest is 2.0.

如果 beforemin-release-age 都在同一个来源中设置,before 会生效(一个明确的绝对日期会覆盖相对时间窗口)。在不同来源之间,标准优先级适用(cli > env > project > user > global),因此高优先级的来源总是可以放宽或覆盖低优先级的来源。

🌐 If before and min-release-age are both set in the same source, before wins (an explicit absolute date overrides a relative window). Across sources, the standard precedence applies (cli > env > project > user > global), so a higher-priority source can always relax or override a lower-priority one.

min-release-age 一样,当这个截止点阻止了 npm audit fix 本可以安装的修复时,npm 会保留易受攻击的版本,发出警告,并以非零代码退出。

🌐 As with min-release-age, when this cutoff blocks a fix that npm audit fix would install, npm keeps the vulnerable version, warns, and exits with a non-zero code.

名称与 min-release-age-exclude 匹配的包不受此过滤器限制。

🌐 Packages whose names match min-release-age-exclude are exempt from this filter.

min-release-age

  • 默认值:空
  • 类型:空或数字

如果设置,npm 将构建 npm 树,使得只安装在指定天数之前可用的版本。如果当前依赖的版本不可用,该命令将报错。

🌐 If set, npm will build the npm tree such that only versions that were available more than the given number of days ago will be installed. If there are no versions available for the current set of dependencies, the command will error.

这个标志是对 before 的补充,后者接受的是确切日期而不是相对的天数。两者可以共存(例如,当 npm 在内部生成子进程以准备 git:github: 依赖时,你的 .npmrc 中的 min-release-age 会被保留);当两者同时适用时,在单个来源中 before 优先,而在多个来源之间则适用标准优先规则。

🌐 This flag is a complement to before, which accepts an exact date instead of a relative number of days. The two may coexist (e.g. min-release-age in your .npmrc is preserved when npm internally spawns a sub-process with --before while preparing a git: or github: dependency); when both apply, before wins within a single source and across sources the standard precedence rules apply.

当此窗口阻止 npm audit fix 安装补丁版本(因为修复发布得太新)时,npm 会将软件包保持在易受攻击的版本,警告修复被阻止,并以非零代码退出。要安装修复,请将软件包添加到 min-release-age-exclude,或放宽 min-release-agebefore

🌐 When this window stops npm audit fix from installing a patched version (because the fix was published too recently), npm keeps the package at its vulnerable version, warns that the fix was blocked, and exits with a non-zero code. To install the fix, add the package to min-release-age-exclude, or relax min-release-age or before.

名称与 min-release-age-exclude 匹配的包不受此过滤器限制。

🌐 Packages whose names match min-release-age-exclude are exempt from this filter.

此值不会导出到子进程的环境中。

🌐 This value is not exported to the environment for child processes.

min-release-age-exclude

  • 默认值:
  • 类型:字符串(可以多次设置)

一个包名称列表或 minimatch 通配符模式,这些包不受 min-release-age(和 before)过滤器的限制。即使设置了发布年龄窗口,匹配的包也总是可以解析到其最新版本。

🌐 A list of package names or minimatch glob patterns that are exempt from the min-release-age (and before) filter. A matching package can always resolve to its newest version, even when a release-age window is set.

例如,对第三方依赖应用发布年龄窗口,同时允许内部维护的软件包立即更新:

🌐 For example, to apply a release-age window to third-party dependencies while letting internally maintained packages update immediately:

min-release-age=7
min-release-age-exclude[]=@myorg/*
min-release-age-exclude[]=my-internal-pkg

只有指定的软件包是例外;其自身的依赖仍然遵循发布时间政策,除非它们也匹配某个模式。模式是针对软件包名称匹配的,所以 @myorg/* 可以匹配 @myorg/shared-utils

🌐 Only the named package is exempt; its own dependencies still follow the release-age policy unless they also match a pattern. Patterns match against the package name, so @myorg/* matches @myorg/shared-utils.

排除一个包不会改变它从哪个注册表获取。你应该在公共注册表上拥有自己的私有范围,这样就不会有人发布同名的包。

🌐 Excluding a package does not change which registry it is fetched from. You should own your private scope on the public registry so that nobody else can publish a package with the same name.

此值不会导出到子进程的环境中。

🌐 This value is not exported to the environment for child processes.

也可以看看

🌐 See Also