Javascript npm 包上的“at”(@)前缀是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36667258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the meaning of the "at" (@) prefix on npm packages?
提问by jbandi
In the Angular Component Router documentationI just stumbled over a npm command I have never seen before and I don't understand what is going on:
在Angular Component Router 文档中,我偶然发现了一个我以前从未见过的 npm 命令,我不明白发生了什么:
npm install @angular/router --save
What is the meaning of @angular/router
?
是什么意思@angular/router
?
Is the whole string a package name? But then I dont find that package when I use the search on npmjs.com. And also the commandline search does return no such package:
整个字符串是包名吗?但是当我在npmjs.com上使用搜索时,我没有找到那个包。而且命令行搜索确实不返回这样的包:
npm search @angular/router
:No match found for "@angular/router"
So is the @angular/
some kind of prefix mechanism in npm? And how does it work?
那么是@angular/
npm 中的某种前缀机制吗?它是如何工作的?
回答by Joe Clay
This is a new feature of NPM called 'scoped packages', which effectively allow NPM packages to be namespaced. Every user and organization on NPM has their own scope, and they are the only people can add packages to it.
这是 NPM 的一个新特性,称为“作用域包”,它有效地允许 NPM 包被命名空间。NPM 上的每个用户和组织都有自己的范围,他们是唯一可以向其中添加包的人。
This is useful for several reasons:
这很有用,原因有几个:
- It allows organizations to make it clear which packages are 'official' and which ones are not.
- For example, if a package has the scope
@angular
, you know it was published by the Angular core team.
- For example, if a package has the scope
- The package name only has to be unique to the scope it is published in, not the entire registry.
- For example, the package name
http
is already taken in the main repository, but Angular is able to have@angular/http
as well.
- For example, the package name
- 它允许组织明确哪些软件包是“官方”的,哪些不是。
- 例如,如果一个包有 scope
@angular
,你就知道它是由 Angular 核心团队发布的。
- 例如,如果一个包有 scope
- 包名只需要在它发布的范围内是唯一的,而不是整个注册表。
- 例如,包名
http
已经在主存储库中使用,但 Angular 也可以使用@angular/http
。
- 例如,包名
The reason that scoped packages don't show up in public searchis because a lot of them are private packages created by organizations using NPM's paid services, and they're not comfortable opening the search up until they can be totally certain they're not going to make anything public that shouldn't be public - from a legal perspective, this is pretty understandable.
其原因范围的包不要在公共场所搜索显示出来是因为他们中的很多都是通过NPM的支付服务组织创建的私有包,而且他们不舒服开放搜索,直到他们可以完全肯定他们是不是将不应该公开的任何内容公开 - 从法律角度来看,这是可以理解的。
For more information, see the NPM docsand the Angular docs.
有关更多信息,请参阅NPM 文档和Angular 文档。
EDIT:It appears that public scoped packages now show up properly in search!
编辑:现在看来公共范围的包在搜索中正确显示了!
回答by Pardeep Jain
Basically there are two types of modules on npm, they are -
npm 上基本上有两种类型的模块,它们是 -
Global modules - these are modules that follow the naming convention that exists today. You
require('foo')
and there is much rejoicing. They are owned by one or more people through thenpm install XYZ
command.Scoped modules - these are new modules that are "scoped" under an organization name that begins with an
@
the organisation's name, a slash and finally the package name, e.g.@someOrgScope/packagename
. Scopes are a way of grouping related packages together, and also affect a few things about the way npm treats the package.
全局模块 - 这些是遵循当今存在的命名约定的模块。你
require('foo')
和那里有很多欢乐。它们通过npm install XYZ
命令由一个或多个人拥有。作用域模块 - 这些是在组织名称下“作用域”的新模块,该组织名称以
@
组织名称、斜杠和包名开头,例如@someOrgScope/packagename
. 作用域是将相关包组合在一起的一种方式,也会影响 npm 处理包的方式。
A scoped package is installed by referencing it by name, preceded by an @-symbol, in npm install:
作用域包是通过在 npm install 中通过名称引用它来安装的,前面是 @-symbol:
npm install @myorg/mypackage
see also
也可以看看