NPM Common Commands (3)

Table of contents

1、npm compltion 

1.1 Description

2、npm config

2.1 Common commands

2.2 Description

set

get

list

delete

edit

fix

2.3 configuration

json

global

editor

location

long

3、asl dedupe

3.1 Description

3.2 configuration

4、npm deprecate

4.1 Command usage

4.2 Description

4.3 configuration

registry

otp


1、npm compltion 

1.1 Description

Enables tab completion in all npm commands.

The above profile will finish loading into your current shell. Adding this to your ~/.bashrc or ~/.zshrc will make completion available everywhere:

npm completion >> ~/.bashrc

npm completion >> ~/.zshrc

 Of course  , if you have a system that can read that file for you, you can of course also pipe the output  npm completion of   ./usr/local/etc/bash_completion.d/npm/etc/bash_completion.d/npm

 Acts in "pipeline mode" when , , and are defined in the environment, and completes according to  the COMP_CWORDparameter COMP_LINE output  COMP_POINTnpm completion

For detailed parameters, you can execute npm completion to see the following parameters:

2、npm config

2.1 Common commands

npm config set <key>=<value> [<key>=<value> ...]
npm config get [<key> [<key> ...]]
npm config delete <key> [<key> ...]
npm config list [--json]
npm config edit
npm config fix

// 别名: c

2.2 Description

 npm gets its configuration settings from the command line, from environment variables, npmrc from files, and in some cases from  files.package.json

set

npm config set key=value [key=value...]
npm set key=value [key=value...]

If the value is omitted, the key will be completely removed from your configuration file.

Note : For backwards compatibility,  an alias of npm config set key value as  is supported npm config set key=value .

get

npm config get [key ...]
npm get [key ...]

If multiple keys are provided, the value will be prefixed with the key name.

If no key is provided, this command behaves the  npm config list same as .

list

npm config list

Displays all configuration settings. Use  -l can also display default values. Use  --json Display settings in json format.

delete

npm config delete key [key ...]

 Remove the specified key from all configuration files.

edit

npm config edit

Open the configuration file in an editor. Use  --global flags to edit global configuration.

fix

npm config fix

Attempt to fix invalid configuration items. Usually this means attaching the authentication configuration (ie  _auth, _authToken) to the configuration's  registry.

2.3 configuration

json

  • Default: false
  • Type: Boolean

Whether to output JSON data instead of normal output.

  • In  npm pkg set it, it can use JSON.parse() to parse collection values ​​before saving them to your  package.json.

Not all npm commands support it.

global

  • Default: false
  • Type: Boolean

Run in "global" mode so that packages are installed to  prefix folders instead of the current working directory.

editor

  • Default: EDITOR or VISUAL environment variable, or '%SYSTEMROOT%\notepad.exe' on Windows, or 'vi' on Unix systems
  • Type: string

for  npm edit and  npm config edit run commands.

location

  • Default: "user" Unless passed  --global, this value is also set to "global"
  • Type: "global", "user", or "project"

When passed to  npm config , this refers to the configuration file to use.

When set to "global" mode, packages will be installed to  prefix folders instead of the current working directory.

  • Packages are installed to  {prefix}/lib/node_modules folders, not the current working directory.
  • bin file linked to {prefix}/bin
  • The man page links to {prefix}/share/man

long

  • Default: false
  • Type: Boolean

 Display extended information in  ls, search and  .help-search

3、asl dedupe

3.1 Description

Search the local package tree and try to simplify the overall structure by moving dependencies further up the tree so they can be more efficiently shared by multiple dependent packages.

For example, consider this dependency graph:

a
+-- b <-- depends on [email protected]
|   `-- [email protected]
`-- d <-- depends on c@~1.0.9
    `-- [email protected]

In this case, npm dedupe the tree is converted to:

a
+-- b
+-- d
`-- [email protected]

Due to the hierarchical nature of node module lookup, both b and d will have their dependencies satisfied through the single c package at the root level of the tree.

In some cases you may have a dependency graph like this:

a
+-- b <-- depends on [email protected]
+-- [email protected]
`-- d <-- depends on [email protected]
    `-- [email protected]

During the installation process, b the  [email protected] dependencies are placed in the root of the tree. Even  [email protected] though   dependencies  d on   .[email protected][email protected]

Running  npm dedupe causes npm to note the duplicates and re-evaluate, removing nested  c modules, since the one at the root is sufficient.

To prefer data deduplication to overduplication during installation, run  npm install --prefer-dedupe or  npm config set prefer-dedupe true.

Arguments are ignored. Data deduplication always works on the entire tree.

Note that this operation transforms the dependency tree, but does not cause new modules to be installed.

Use  npm find-dupes will  --dry-run run the command in mode.

Note:   The semver value directly dependent on  npm dedupe the project will never be updated  , if you want to update  the value in you can run :   instead.package.jsonpackage.jsonnpm update --save

3.2 configuration

For configuration, refer to the configuration section of npm ci .

4、npm deprecate

4.1 Command usage

npm deprecate <package-spec> <message>

4.2 Description

This command will update the package's npm registry key, providing a deprecation warning to anyone trying to install it.

It works for version ranges
 as well as specific versions, so you can do something like:

npm deprecate my-thing@"< 0.2.3" "critical bug fixed in v0.2.3"

SemVer ranges passed to this command are interpreted as containing pre-release versions. For example:

npm deprecate [email protected] "1.x is no longer supported"

In this case the version  [email protected] will also be deprecated.

You have to be the package owner to deprecate something.

4.3 configuration

registry

The base URL for the npm registry.

otp

  • Default: null
  • Type: null or string

This is a one-time password from a two-factor authenticator. It is required when using  npm access publish or change package permissions.

If not set, and the registry responds with a failure asking for a one-time password, npm will prompt for the one-time password on the command line.

Guess you like

Origin blog.csdn.net/u014388408/article/details/132671043