package-spec

包名称说明符

选择命令行版本:

描述

🌐 Description

npm install 这样的命令以及 package.json 中的依赖部分使用包名说明符。这可以是许多不同的东西,都指代“包”。示例包括包名、git URL、压缩包或本地目录。在使用此包名说明符的 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>

指通过名称引用一个包,可以带或不带作用域,并可选择标签、版本或版本范围。通常与 registry 配置结合使用,以引用注册表中的包。

🌐 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 中的依赖部分,这指的是通过别名引用的包。<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,有关配置在按名称引用软件包时使用哪个注册表,请参见 registry

🌐 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

指以 tar 包格式存在的软件包,可以位于本地文件系统上,也可以通过 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 urls

  • <git:// url>
  • <github username>/<github project>

指的是 git 仓库中的一个包。这可以是完整的 git URL、git 简写,或者 GitHub 上的用户名/包。你可以通过在末尾添加 #ref 来指定 git 标签、分支或其他 git 引用。

🌐 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