头图

Look at such a command:

npm install @angular/router --save

What does this @angular/router mean?

We cannot search for this package using the following command:

npm search @angular/router
:No match found for "@angular/router"

This is a new feature of NPM called "scoped packages", which effectively allows NPM packages to be namespaced. Every user and organization on NPM has its own scope, and they are the only ones who can add packages to it.

This is useful for several reasons:

  • It allows organizations to specify which packages are "official" and which are not.
    For example, if the scope of a package is @angular, you know that it was released by the Angular core team.
  • The package name only needs to be unique within the scope of its release, not the entire registry.
    For example, the package name http has been adopted in the main repository, but Angular can also use @angular/http.

The reason that scope packages do not appear in public searches is because many of them are private packages created by organizations that use NPM paid services, and they are reluctant to open the search until they are completely sure that they are not publishing anything that shouldn’t be made public. -From a legal point of view, this is understandable.

There are basically two types of modules on npm, they are:

(1) Global modules-These modules follow the naming conventions that exist today. You need ('foo') and are very happy. They are owned by one or more people through the npm install XYZ command.

(2) Scope modules-these are new modules that are "scoped" under the organization name, the organization name starts with @ organization name, slash and package name, for example @someOrgScope/package name. Scope is a way of grouping related packages together, and it also affects how npm processes packages.

The scope package is installed by referencing it by name in npm install, preceded by @-symbol:

npm install @myorg/mypackage
Scope is a way to group related packages together, and it also affects how npm processes packages. Each npm user/organization has its own scope, and only you can add packages in your scope. This means you don't have to worry about someone taking your package name before you. Therefore, this is also a good way to signal an official package to the organization.

SAP Spartacus also uses a large number of scoped modules, as shown in the figure below:


注销
1k 声望1.6k 粉丝

invalid