1、npm explain
1.1 Command usage
npm explain <package-spec>
别名: why
1.2 Description
This command will print the dependency chain leading to packages that are referenced by other packages in the current project.
If one or more package specifications are provided, only packages that match one of the specifiers will have their relationship interpreted.
Package specifications can also reference ./node_modules
folders in
For example, running unpipe in npm's source tree npm explain
will show:
If you want to specify a package in a specific folder, pass it as an argument to the command. This can be useful when trying to figure out why a given dependency is being copied to satisfy conflicting version requirements in a project.
1.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 the collection values before saving them to yourpackage.json
.
Not all npm commands are supported.
workspace
- Defaults:
- Type: String (can be set multiple times)
Enables running commands in the context of the current project's configured workspace, while filtering by running only workspaces defined by this configuration option.
workspace
Valid values for the configuration are:
- workspace name
- The path to the workspace directory
- Path to the parent workspace directory (will cause all workspaces in that folder to be selected)
When setting for npm init
a command, you can set it to a folder for a workspace that doesn't yet exist, to create a folder and set it as a completely new workspace in the project.
2、npm explore
2.1 Using commands
npm explore <pkg> [ -- <command>]
2.2 Description
Spawns a subshell in the specified directory of the installed package.
If a command is specified, it is run in a subshell and terminates immediately.
This node_modules
is convenient in the case of git submodules in a folder:
npm explore some-dependency -- git pull origin master
Note that the package will not automatically rebuild afterwards, so be sure to use that if you make any changes
npm rebuild <pkg>
.In actual use, this command is rarely used and is a bit useless. Basically, most packages rarely have git submodules. There are advantages and disadvantages to git submodules in actual use. They may be used in some scenarios.
2.3 Configuration
shell
- Default: SHELL environment variable, or "bash" on Posix, or "cmd.exe" on Windows
- Type: string
The shell for npm explore
the command to run in.
3、npm find-dupes
3.1 Command usage
npm find-dupes
3.2 Description
Run in --dry-run
mode npm dedupe
so that npm only outputs duplicates without actually changing the package tree.
3.3 Configuration
install-strategy
- Default value: "hoisted"
- Type: "hoisted", "nested", "shallow" or "linked"
Sets the policy for installing packages in node_modules. hoisted (default): Install non-replication at the top level, with replication as needed in the directory structure. nested: (formerly --legacy-bundling) Installed in place, no promotion required. shallow (formerly --global-style) only installs direct deps at the top level. linked: (Experimental) Installed in node_modules/.store, linked in place, not promoted.
legacy-bundling
- Default: false
- Type: boolean
- Deprecated: This option has been enabled and replaced by
--install-strategy=nested
Do not node_modules
elevate package installation in , but install packages in the same way as they depend on. This can lead to very deep directory structures and duplicate package installations because there is no data deduplication. settings --install-strategy=nested
.
global-style
- Default: false
- Type: boolean
- Deprecated: This option has been deprecated and replaced by
--install-strategy=shallow
Only node_modules
installs direct dependencies in the top level, but promotes deeper dependencies. settings --install-strategy=shallow
.
strict-peer-deps
- Default: false
- Type: boolean
If set to true
, and --legacy-peer-deps
not set, any conflicts peerDependencies
will be treated as installation failures, even if npm can reasonably guess an appropriate solution based on the non-peer dependencies.
By default, conflicts in the dependency graph peerDependencies
will be resolved using the nearest non-peer dependency specification, even if doing so causes some packages to receive peer peerDependencies
dependencies beyond the range set in their package's object.
When performing such an override, a warning is printed explaining the conflict and the packages involved. If set --strict-peer-deps
, this warning is treated as a failure.
package-lock
- Default value: true
- Type: boolean
If set to false, package-lock.json
the file is ignored when installing. If set to true, this will also prevent writes package-lock.json
.
omit
- Default: 'dev' if
NODE_ENV
the environment variable is set to 'production', empty otherwise. - Type: "dev", "optional", "peer" (can be set multiple times)
Dependency types to omit from the installation tree on disk.
Note that these dependencies will still be resolved and added to the package-lock.json
or npm-shrinkwrap.json
file. They're just not physically installed on the disk.
If a package type appears in both the --include
and --omit
list, it is included.
If the generated omitted list contains 'dev'
, NODE_ENV
the environment variable will be set to for all lifecycle scripts 'production'
.
ignore-scripts
- Default: false
- Type: boolean
If true, npm will not run the script specified in the package.json file.
Note that if set ignore-scripts
, commands explicitly intended to run a specific script (such as npm start
, npm stop
, npm restart
, npm test
and npm run-script
) will still run their intended script, but they will not run any pre- or post-scripts.
audit
- Default value: true
- Type: boolean
When "true" submits audit reports with the current npm command to the default registry and all registries configured for the scope.
bin-links
- Default value: true
- Type: boolean
Tells npm to create symlinks (or shims on Windows .cmd
) to the package's executable.
Set to false to not do this. This can be used to work around the fact that some file systems do not support symbolic links, even on ostensibly Unix systems.
fund
- Default value: true
- Type: boolean
When "true" npm install
is displayed at the end of each message, confirming that the number of dependencies is looking for funds.
workspace
- Defaults:
- Type: String (can be set multiple times)
Enables running commands in the context of the current project's configured workspace, while filtering by running only workspaces defined by this configuration option.
workspace
Valid values for the configuration are:
- workspace name
- The path to the workspace directory
- Path to the parent workspace directory (will cause all workspaces in that folder to be selected)
When setting for npm init
a command, you can set it to a folder for a workspace that doesn't yet exist, to create a folder and set it as a completely new workspace in the project.
This value is not exported to the child process's environment.
workspaces
- Default: null
- Type: null or boolean
Set to true to run the command in the context of all configured workspaces.
Explicitly setting this to false will cause install
commands like this to ignore workspaces entirely. When not explicitly set:
- Commands run on
node_modules
the tree (install, update, etc.) link workspaces tonode_modules
folders. - Commands that perform other operations (test, execute, publish, etc.) will run on the root project unlessworkspace
one or more workspaces are specified in the configuration.
This value is not exported to the child process's environment.
include-workspace-root
- Default: false
- Type: boolean
Include the workspace root when enabling the workspace for a command.
When false, workspace
specifying a single workspace via the configuration, or workspaces
all workspaces via a flag, will cause npm to run only on the specified workspace, rather than the root project.
This value is not exported to the child process's environment.
install-links
- Default: false
- Type: boolean
When setting the file: protocol dependencies will be packaged and installed as regular dependencies instead of creating symlinks. This option has no effect on the workspace.
4、npm fund
4.1 Command usage
npm fund [<package-spec>]
4.2 Description
This command retrieves information about how a given project's dependencies are funded. If no package name is provided, it will list all the dependencies it is looking for in a tree structure, listing the type of fund and the url to access. If a package name is provided, then it will try to
open its funding URL using the --browser configuration parameter; if the package has multiple funding sources, the user will be prompted with --which
options to disambiguate it.
The list will avoid duplicate entries and stack all packages sharing the same url into a single entry. Therefore, the list has npm ls
a different output shape than .
4.3 Workspace support
Results can be filtered to include only a single workspace and its dependencies using the following example options.
Example:
Here's an example running in a configured workspace npm fund
:
b
Here's an example of what to expect when filtering by only specific workspaces within the same project :
4.4 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 the collection values before saving them to yourpackage.json
.
Not all npm commands are supported.
browser
- Default: OS X:
"open"
, Windows:"start"
, Others:"xdg-open"
- Type: null, boolean, or string
The npm command is called by the browser to open the website.
Set to false
suppress browser behavior and print the url to the terminal instead.
Set to true
use the default system URL opener.
unicode
- Default: false on Windows, true on mac/unix systems with unicode locale, as defined by
LC_ALL
,LC_CTYPE
or environment variables.LANG
- Type: boolean
When set to true, npm uses unicode characters in tree output. When false, it uses ascii characters instead of unicode glyphs.
workspace
- Defaults:
- Type: String (can be set multiple times)
Enables running commands in the context of the current project's configured workspace, while filtering by running only workspaces defined by this configuration option.
workspace
Valid values for the configuration are:
- workspace name
- The path to the workspace directory
- Path to the parent workspace directory (will cause all workspaces in that folder to be selected)
When setting for npm init
a command, you can set it to a folder for a workspace that doesn't yet exist, to create a folder and set it as a completely new workspace in the project.
This value is not exported to the child process's environment.
which
- Default: null
- Type: null or number
If there are multiple funding sources, open the source URL of the corresponding index. If there is only 1, you can add --which1, or add no parameters.
The corresponding page will pop up, and one or more people can sponsor.