选择命令行版本:
See Details
目录
概要
¥Synopsis
npm dist-tag add <package-spec (with version)> [<tag>]npm dist-tag rm <package-spec> <tag>npm dist-tag ls [<package-spec>]alias: dist-tags
描述
¥Description
在包上添加、删除和枚举分发标签:
¥Add, remove, and enumerate distribution tags on a package:
-
add:使用指定的标记标记指定版本的包,如果没有指定,则标记为
--tag
配置。如果你在 auth-and-writes 上有双重身份验证,那么你需要在命令行中使用--otp <one-time password>
包含一次性密码,或者通过基于你的authtype
的第二重流程。¥add: Tags the specified version of the package with the specified tag, or the
--tag
config if not specified. If you have two-factor authentication on auth-and-writes then you’ll need to include a one-time password on the command line with--otp <one-time password>
, or go through a second factor flow based on yourauthtype
. -
rm:清除封装中不再使用的标签。如果你在 auth-and-writes 上有双重身份验证,那么你需要在命令行中使用
--otp <one-time password>
包含一次性密码,或者通过基于你的authtype
的第二重流程¥rm: Clear a tag that is no longer in use from the package. If you have two-factor authentication on auth-and-writes then you’ll need to include a one-time password on the command line with
--otp <one-time password>
, or go through a second factor flow based on yourauthtype
-
ls:显示包的所有 dist-tags,默认为当前前缀中的包。如果未指定,则这是默认操作。
¥ls: Show all of the dist-tags for a package, defaulting to the package in the current prefix. This is the default action if none is specified.
安装包时可以使用标记作为对版本的引用,而不是使用特定的版本号:
¥A tag can be used when installing packages as a reference to a version instead of using a specific version number:
npm install <name>@<tag>
安装依赖时,可以指定首选标记版本:
¥When installing dependencies, a preferred tagged version may be specified:
npm install --tag <tag>
(这也适用于解析和安装依赖的任何其他命令,例如 npm dedupe
、npm update
和 npm audit fix
。)
¥(This also applies to any other commands that resolve and install dependencies, such as npm dedupe
, npm update
, and npm audit fix
.)
除非使用 --tag
选项,否则发布包会将 latest
标记设置为已发布版本。例如,npm publish --tag=beta
。
¥Publishing a package sets the latest
tag to the published version unless the --tag
option is used. For example, npm publish --tag=beta
.
默认情况下,npm install <pkg>
(没有任何 @<version>
或 @<tag>
说明符)安装 latest
标签。
¥By default, npm install <pkg>
(without any @<version>
or @<tag>
specifier) installs the latest
tag.
目的
¥Purpose
标签可用于提供别名而不是版本号。
¥Tags can be used to provide an alias instead of version numbers.
例如,一个项目可能选择有多个开发流并为每个流使用不同的标签,例如,stable
、beta
、dev
、canary
。
¥For example, a project might choose to have multiple streams of development and use a different tag for each stream, e.g., stable
, beta
, dev
, canary
.
默认情况下,npm 使用 latest
标签来标识包的当前版本,而 npm install <pkg>
(没有任何 @<version>
或 @<tag>
说明符)安装 latest
标签。通常,项目只使用 latest
标签表示稳定版本,而使用其他标签表示不稳定版本,例如 prereleases。
¥By default, the latest
tag is used by npm to identify the current version of a package, and npm install <pkg>
(without any @<version>
or @<tag>
specifier) installs the latest
tag. Typically, projects only use the latest
tag for stable release versions, and use other tags for unstable versions such as prereleases.
一些项目使用 next
标签来标识即将发布的版本。
¥The next
tag is used by some projects to identify the upcoming version.
除了 latest
,没有任何标签对 npm 本身有任何特殊意义。
¥Other than latest
, no tag has any special significance to npm itself.
注意事项
¥Caveats
该命令以前称为 npm tag
,它只创建新标签,因此具有不同的语法。
¥This command used to be known as npm tag
, which only created new tags, and so had a different syntax.
标签必须与版本号共享一个命名空间,因为它们是在同一个插槽中指定的:npm install <pkg>@<version>
对 npm install <pkg>@<tag>
。
¥Tags must share a namespace with version numbers, because they are specified in the same slot: npm install <pkg>@<version>
vs npm install <pkg>@<tag>
.
可以解释为有效 semver 范围的标签将被拒绝。例如,v1.4
不能用作标签,因为它被 semver 解释为 >=1.4.0 <1.5.0
。见 https://github.com/npm/npm/issues/6082。
¥Tags that can be interpreted as valid semver ranges will be rejected. For example, v1.4
cannot be used as a tag, because it is interpreted by semver as >=1.4.0 <1.5.0
. See https://github.com/npm/npm/issues/6082.
避免标签出现语义问题的最简单方法是使用不以数字或字母 v
开头的标签。
¥The simplest way to avoid semver problems with tags is to use tags that do not begin with a number or the letter v
.
配置
¥Configuration
workspace
-
默认值:
¥Default:
-
类型:字符串(可以设置多次)
¥Type: String (can be set multiple times)
启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。
¥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:
-
工作区名称
¥Workspace names
-
工作区目录的路径
¥Path to a workspace directory
-
父工作区目录的路径(将导致选择该文件夹中的所有工作区)
¥Path to a parent workspace directory (will result in selecting all workspaces within that folder)
为 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.
workspaces
-
默认值:null
¥Default: null
-
类型:空值或布尔值
¥Type: null or Boolean
设置为 true 可在所有已配置工作区的上下文中运行该命令。
¥Set to true to run the command in the context of all configured workspaces.
显式将此设置为 false 将导致像 install
这样的命令完全忽略工作区。未明确设置时:
¥Explicitly setting this to false will cause commands like install
to ignore workspaces altogether. When not set explicitly:
-
在
node_modules
树上运行的命令(安装、更新等)会将工作区链接到node_modules
文件夹。* 执行其他操作(测试、执行、发布等)的命令将在根项目上运行,除非在workspace
配置中指定了一个或多个工作区。¥Commands that operate on the
node_modules
tree (install, update, etc.) will link workspaces into thenode_modules
folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, unless one or more workspaces are specified in theworkspace
config.
此值不会导出到子进程的环境中。
¥This value is not exported to the environment for child processes.
include-workspace-root
-
默认值:false
¥Default: false
-
类型:布尔值
¥Type: Boolean
为命令启用工作区时包括工作区根。
¥Include the workspace root when workspaces are enabled for a command.
当为 false 时,通过 workspace
配置指定单个工作区,或通过 workspaces
标志指定所有工作区,将导致 npm 仅在指定的工作区上运行,而不是在根项目上运行。
¥When false, specifying individual workspaces via the workspace
config, or all workspaces via the workspaces
flag, will cause npm to operate only on the specified workspaces, and not on the root project.
此值不会导出到子进程的环境中。
¥This value is not exported to the environment for child processes.
也可以看看
¥See Also