package-spec

包名称说明符

选择 CLI 版本:

描述

¥Description

npm installpackage.json 中的依赖部分这样的命令使用包名称说明符。这可以是许多不同的东西,都指的是 "包"。示例包括包名称、git url、tarball 或本地目录。在使用此包名称说明符的 npm 命令的帮助输出中,这些通常称为 <package-spec>

¥Commands like npm install and the dependency sections in the package.json use a package name specifier. This can be many different things that all refer to a "package". Examples include a package name, git url, tarball, or local directory. These will generally be referred to as <package-spec> in the help output for the npm commands that use this package name specifier.

包名

¥Package name

  • [<@scope>/]<pkg>

  • [<@scope>/]<pkg>@<tag>

  • [<@scope>/]<pkg>@<version>

  • [<@scope>/]<pkg>@<version range>

按名称引用包,有或没有范围,以及可选的标记、版本或版本范围。这通常与 注册表 配置结合使用以引用注册表中的包。

¥Refers to a package by name, with or without a scope, and optionally tag, version, or version range. This is typically used in combination with the registry config to refer to a package in a registry.

示例:

¥Examples:

  • npm

  • @npmcli/arborist

  • @npmcli/arborist@latest

  • npm@6.13.1

  • npm@^4.0.0

别名

¥Aliases

  • <alias>@npm:<name>

主要由 npm install 之类的命令和 package.json 的依赖部分使用,this 通过别名引用包。<alias> 是在 node_modules 文件夹中具体化的包的名称,而 <name> 指的是在配置的注册表中找到的包名称。

¥Primarily used by commands like npm install and in the dependency sections in the package.json, this refers to a package by an alias. The <alias> is the name of the package as it is reified in the node_modules folder, and the <name> refers to a package name as found in the configured registry.

有关按名称引用包的更多信息,请参阅上面的 Package name,而 注册表 用于配置在按名称引用包时使用哪个注册表。

¥See Package name above for more info on referring to a package by name, and registry for configuring which registry is used when referring to a package by name.

示例:

¥Examples:

  • semver:@npm:@npmcli/semver-with-patch

  • semver:@npm:semver@7.2.2

  • semver:@npm:semver@legacy

文件夹

¥Folders

  • <folder>

这是指本地文件系统上的包。具体来说,这是一个包含 package.json 文件的文件夹。这应该始终以 /./(或你的操作系统等效项)为前缀,以减少混淆。npm 当前会将包含多个 / 的字符串解析为文件夹,但这是可能在未来版本中删除的旧版行为。

¥This refers to a package on the local filesystem. Specifically this is a folder with a package.json file in it. This should always be prefixed with a / or ./ (or your OS equivalent) to reduce confusion. npm currently will parse a string with more than one / in it as a folder, but this is legacy behavior that may be removed in a future version.

示例:

¥Examples:

  • ./my-package

  • /opt/npm/my-package

压缩包

¥Tarballs

  • <tarball file>

  • <tarball url>

示例:

¥Examples:

  • ./my-package.tgz

  • https://registry.npmjs.org/semver/-/semver-1.0.0.tgz

指的是 tarball 格式的包,可以在本地文件系统上或通过 url 远程。这是上传到注册表时包存在的格式。

¥Refers to a package in a tarball format, either on the local filesystem or remotely via url. This is the format that packages exist in when uploaded to a registry.

git url

  • <git:// url>

  • <github username>/<github project>

指 git repo 中的包。这可以是完整的 git url、git 速记或 GitHub 上的用户名/包。你可以通过附加 #ref 来指定 git 标记、分支或其他 git ref。

¥Refers to a package in a git repo. This can be a full git url, git shorthand, or a username/package on GitHub. You can specify a git tag, branch, or other git ref by appending #ref.

示例:

¥Examples:

  • https://github.com/npm/cli.git

  • git@github.com:npm/cli.git

  • git+ssh://git@github.com/npm/cli#v6.0.0

  • github:npm/cli#HEAD

  • npm/cli#c12ea07

也可以看看

¥See also

npm 中文网 - 粤ICP备13048890号