Skip to content

Commit e340cf6

Browse files
committed
docs: explain through run-script
PR-URL: npm#2330 Credit: @isaacs Close: npm#2330
1 parent 7a4f0c9 commit e340cf6

18 files changed

+351
-234
lines changed

docs/content/commands/npm-explain.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ description: Explain installed packages
88

99
```bash
1010
npm explain <folder | specifier>
11+
12+
alias: why
1113
```
1214

1315
### Description

docs/content/commands/npm-link.md

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,44 @@ alias: npm ln
1515

1616
### Description
1717

18+
This is handy for installing your own stuff, so that you can work on it and
19+
test iteratively without having to continually rebuild.
20+
1821
Package linking is a two-step process.
1922

20-
First, `npm link` in a package folder will create a symlink in the global folder
21-
`{prefix}/lib/node_modules/<package>` that links to the package where the `npm
22-
link` command was executed. It will also link any bins in the package to `{prefix}/bin/{name}`.
23-
Note that `npm link` uses the global prefix (see `npm prefix -g` for its value).
23+
First, `npm link` in a package folder will create a symlink in the global
24+
folder `{prefix}/lib/node_modules/<package>` that links to the package
25+
where the `npm link` command was executed. It will also link any bins in
26+
the package to `{prefix}/bin/{name}`. Note that `npm link` uses the global
27+
prefix (see `npm prefix -g` for its value).
2428

2529
Next, in some other location, `npm link package-name` will create a
26-
symbolic link from globally-installed `package-name` to `node_modules/`
27-
of the current folder.
30+
symbolic link from globally-installed `package-name` to `node_modules/` of
31+
the current folder.
2832

29-
Note that `package-name` is taken from `package.json`,
30-
not from directory name.
33+
Note that `package-name` is taken from `package.json`, _not_ from the
34+
directory name.
3135

32-
The package name can be optionally prefixed with a scope. See [`scope`](/using-npm/scope).
33-
The scope must be preceded by an @-symbol and followed by a slash.
36+
The package name can be optionally prefixed with a scope. See
37+
[`scope`](/using-npm/scope). The scope must be preceded by an @-symbol and
38+
followed by a slash.
3439

3540
When creating tarballs for `npm publish`, the linked packages are
36-
"snapshotted" to their current state by resolving the symbolic links.
37-
38-
This is handy for installing your own stuff, so that you can work on it and
39-
test it iteratively without having to continually rebuild.
41+
"snapshotted" to their current state by resolving the symbolic links, if
42+
they are included in `bundleDependencies`.
4043

4144
For example:
4245

4346
```bash
44-
cd ~/projects/node-redis # go into the package directory
45-
npm link # creates global link
46-
cd ~/projects/node-bloggy # go into some other package directory.
47-
npm link redis # link-install the package
47+
cd ~/projects/node-redis # go into the package directory
48+
npm link # creates global link
49+
cd ~/projects/node-bloggy # go into some other package directory.
50+
npm link redis # link-install the package
4851
```
4952

50-
Now, any changes to ~/projects/node-redis will be reflected in
51-
~/projects/node-bloggy/node_modules/node-redis/. Note that the link should
52-
be to the package name, not the directory name for that package.
53+
Now, any changes to `~/projects/node-redis` will be reflected in
54+
`~/projects/node-bloggy/node_modules/node-redis/`. Note that the link
55+
should be to the package name, not the directory name for that package.
5356

5457
You may also shortcut the two steps in one. For example, to do the
5558
above use-case in a shorter way:
@@ -69,15 +72,33 @@ npm link redis
6972
That is, it first creates a global link, and then links the global
7073
installation target into your project's `node_modules` folder.
7174

72-
Note that in this case, you are referring to the directory name, `node-redis`,
73-
rather than the package name `redis`.
75+
Note that in this case, you are referring to the directory name,
76+
`node-redis`, rather than the package name `redis`.
7477

75-
If your linked package is scoped (see [`scope`](/using-npm/scope)) your link command must include that scope, e.g.
78+
If your linked package is scoped (see [`scope`](/using-npm/scope)) your
79+
link command must include that scope, e.g.
7680

7781
```bash
7882
npm link @myorg/privatepackage
7983
```
8084

85+
### Caveat
86+
87+
Note that package dependencies linked in this way are _not_ saved to
88+
`package.json` by default, on the assumption that the intention is to have
89+
a link stand in for a regular non-link dependency. Otherwise, for example,
90+
if you depend on `redis@^3.0.1`, and ran `npm link redis`, it would replace
91+
the `^3.0.1` dependency with `file:../path/to/node-redis`, which you
92+
probably don't want! Additionally, other users or developers on your
93+
project would run into issues if they do not have their folders set up
94+
exactly the same as yours.
95+
96+
If you are adding a _new_ dependency as a link, you should add it to the
97+
relevant metadata by running `npm install <dep> --package-lock-only`.
98+
99+
If you _want_ to save the `file:` reference in your `package.json` and
100+
`package-lock.json` files, you can use `npm link <dep> --save` to do so.
101+
81102
### See Also
82103

83104
* [npm developers](/using-npm/developers)

docs/content/commands/npm-logout.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ npm logout [--registry=<url>] [--scope=<@scope>]
1212

1313
### Description
1414

15-
When logged into a registry that supports token-based authentication, tell the
16-
server to end this token's session. This will invalidate the token everywhere
17-
you're using it, not just for the current environment.
15+
When logged into a registry that supports token-based authentication, tell
16+
the server to end this token's session. This will invalidate the token
17+
everywhere you're using it, not just for the current environment.
1818

19-
When logged into a legacy registry that uses username and password authentication, this will
20-
clear the credentials in your user configuration. In this case, it will _only_ affect
21-
the current environment.
19+
When logged into a legacy registry that uses username and password
20+
authentication, this will clear the credentials in your user configuration.
21+
In this case, it will _only_ affect the current environment.
2222

2323
If `--scope` is provided, this will find the credentials for the registry
2424
connected to that scope, if set.

docs/content/commands/npm-ls.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ aliases: list, la, ll
1515
### Description
1616

1717
This command will print to stdout all the versions of packages that are
18-
installed, as well as their dependencies, in a tree-structure.
18+
installed, as well as their dependencies when `--all` is specified, in a
19+
tree structure.
1920

20-
Positional arguments are `name@version-range` identifiers, which will
21-
limit the results to only the paths to the packages named. Note that
22-
nested packages will *also* show the paths to the specified packages.
23-
For example, running `npm ls promzard` in npm's source tree will show:
21+
Note: to get a "bottoms up" view of why a given package is included in the
22+
tree at all, use [`npm explain`](/commands/npm-explain).
23+
24+
Positional arguments are `name@version-range` identifiers, which will limit
25+
the results to only the paths to the packages named. Note that nested
26+
packages will *also* show the paths to the specified packages. For
27+
example, running `npm ls promzard` in npm's source tree will show:
2428

2529
```bash
26-
npm@@VERSION@ /path/to/npm
27-
└─┬ init-package-json@0.0.4
28-
└── promzard@0.1.5
30+
npm@@VERSION@ /path/to/npm
31+
└─┬ init-package-json@0.0.4
32+
└── promzard@0.1.5
2933
```
3034

3135
It will print out extraneous, missing, and invalid packages.
@@ -35,12 +39,49 @@ in parentheses after the name@version to make it easier for users to
3539
recognize potential forks of a project.
3640

3741
The tree shown is the logical dependency tree, based on package
38-
dependencies, not the physical layout of your node_modules folder.
42+
dependencies, not the physical layout of your `node_modules` folder.
3943

4044
When run as `ll` or `la`, it shows extended information by default.
4145

46+
### Note: Design Changes Pending
47+
48+
The `npm ls` command's output and behavior made a _ton_ of sense when npm
49+
created a `node_modules` folder that naively nested every dependency. In
50+
such a case, the logical dependency graph and physical tree of packages on
51+
disk would be roughly identical.
52+
53+
With the advent of automatic install-time deduplication of dependencies in
54+
npm v3, the `ls` output was modified to display the logical dependency
55+
graph as a tree structure, since this was more useful to most users.
56+
However, without using `npm ls -l`, it became impossible show _where_ a
57+
package was actually installed much of the time!
58+
59+
With the advent of automatic installation of `peerDependencies` in npm v7,
60+
this gets even more curious, as `peerDependencies` are logically
61+
"underneath" their dependents in the dependency graph, but are always
62+
physically at or above their location on disk.
63+
64+
Also, in the years since npm got an `ls` command (in version 0.0.2!),
65+
dependency graphs have gotten much larger as a general rule. Therefor, in
66+
order to avoid dumping an excessive amount of content to the terminal, `npm
67+
ls` now only shows the _top_ level dependencies, unless `--all` is
68+
provided.
69+
70+
A thorough re-examination of the use cases, intention, behavior, and output
71+
of this command, is currently underway. Expect significant changes to at
72+
least the default human-readable `npm ls` output in npm v8.
73+
4274
### Configuration
4375

76+
#### all
77+
78+
* Default: `false`
79+
* Type: Boolean
80+
81+
When running `npm outdated` and `npm ls`, setting `--all` will show all
82+
outdated or installed packages, rather than only those directly depended
83+
upon by the current project.
84+
4485
#### json
4586

4687
* Default: false
@@ -115,6 +156,7 @@ Set it to false in order to use all-ansi output.
115156

116157
### See Also
117158

159+
* [npm explain](/commands/npm-explain)
118160
* [npm config](/commands/npm-config)
119161
* [npmrc](/configuring-npm/npmrc)
120162
* [npm folders](/configuring-npm/folders)

docs/content/commands/npm-org.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ $ npm org ls my-org @mx-santos
5252

5353
### Description
5454

55-
You can use the `npm org` commands to manage and view users of an organization.
56-
It supports adding and removing users, changing their roles, listing them, and
57-
finding specific ones and their roles.
55+
You can use the `npm org` commands to manage and view users of an
56+
organization. It supports adding and removing users, changing their roles,
57+
listing them, and finding specific ones and their roles.
5858

5959
### See Also
6060

61+
* [using orgs](/using-npm/orgs)
6162
* [Documentation on npm Orgs](https://docs.npmjs.com/orgs/)

docs/content/commands/npm-outdated.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,34 @@ npm outdated [[<@scope>/]<pkg> ...]
1515
This command will check the registry to see if any (or, specific) installed
1616
packages are currently outdated.
1717

18+
By default, only the direct dependencies of the root project are shown.
19+
Use `--all` to find all outdated meta-dependencies as well.
20+
1821
In the output:
1922

2023
* `wanted` is the maximum version of the package that satisfies the semver
21-
range specified in `package.json`. If there's no available semver range (i.e.
22-
you're running `npm outdated --global`, or the package isn't included in
23-
`package.json`), then `wanted` shows the currently-installed version.
24+
range specified in `package.json`. If there's no available semver range
25+
(i.e. you're running `npm outdated --global`, or the package isn't
26+
included in `package.json`), then `wanted` shows the currently-installed
27+
version.
2428
* `latest` is the version of the package tagged as latest in the registry.
25-
Running `npm publish` with no special configuration will publish the package
26-
with a dist-tag of `latest`. This may or may not be the maximum version of
27-
the package, or the most-recently published version of the package, depending
28-
on how the package's developer manages the latest [dist-tag](npm-dist-tag).
29+
Running `npm publish` with no special configuration will publish the
30+
package with a dist-tag of `latest`. This may or may not be the maximum
31+
version of the package, or the most-recently published version of the
32+
package, depending on how the package's developer manages the latest
33+
[dist-tag](/commands/npm-dist-tag).
2934
* `location` is where in the physical tree the package is located.
3035
* `depended by` shows which package depends on the displayed dependency
31-
* `package type` (when using `--long` / `-l`) tells you whether this package is
32-
a `dependency` or a dev/peer/optional dependency. Packages not included in `package.json`
33-
are always marked `dependencies`.
34-
* `homepage` (when using `--long` / `-l`) is the `homepage` value contained in the package's packument
35-
* Red means there's a newer version matching your semver requirements, so you should update now.
36-
* Yellow indicates that there's a newer version above your semver requirements (usually new major, or new 0.x minor) so proceed with caution.
36+
* `package type` (when using `--long` / `-l`) tells you whether this
37+
package is a `dependency` or a dev/peer/optional dependency. Packages not
38+
included in `package.json` are always marked `dependencies`.
39+
* `homepage` (when using `--long` / `-l`) is the `homepage` value contained
40+
in the package's packument
41+
* Red means there's a newer version matching your semver requirements, so
42+
you should update now.
43+
* Yellow indicates that there's a newer version _above_ your semver
44+
requirements (usually new major, or new 0.x minor) so proceed with
45+
caution.
3746

3847
### An example
3948

@@ -59,19 +68,20 @@ With these `dependencies`:
5968

6069
A few things to note:
6170

62-
* `glob` requires `^5`, which prevents npm from installing `glob@6`, which is
63-
outside the semver range.
64-
* Git dependencies will always be reinstalled, because of how they're specified.
65-
The installed committish might satisfy the dependency specifier (if it's
66-
something immutable, like a commit SHA), or it might not, so `npm outdated` and
67-
`npm update` have to fetch Git repos to check. This is why currently doing a
68-
reinstall of a Git dependency always forces a new clone and install.
69-
* `npm@3.5.2` is marked as "wanted", but "latest" is `npm@3.5.1` because npm
70-
uses dist-tags to manage its `latest` and `next` release channels. `npm update`
71-
will install the _newest_ version, but `npm install npm` (with no semver range)
72-
will install whatever's tagged as `latest`.
73-
* `once` is just plain out of date. Reinstalling `node_modules` from scratch or
74-
running `npm update` will bring it up to spec.
71+
* `glob` requires `^5`, which prevents npm from installing `glob@6`, which
72+
is outside the semver range.
73+
* Git dependencies will always be reinstalled, because of how they're
74+
specified. The installed committish might satisfy the dependency
75+
specifier (if it's something immutable, like a commit SHA), or it might
76+
not, so `npm outdated` and `npm update` have to fetch Git repos to check.
77+
This is why currently doing a reinstall of a Git dependency always forces
78+
a new clone and install.
79+
* `npm@3.5.2` is marked as "wanted", but "latest" is `npm@3.5.1` because
80+
npm uses dist-tags to manage its `latest` and `next` release channels.
81+
`npm update` will install the _newest_ version, but `npm install npm`
82+
(with no semver range) will install whatever's tagged as `latest`.
83+
* `once` is just plain out of date. Reinstalling `node_modules` from
84+
scratch or running `npm update` will bring it up to spec.
7585

7686
### Configuration
7787

docs/content/commands/npm-owner.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,24 @@ aliases: author
1818

1919
Manage ownership of published packages.
2020

21-
* ls:
22-
List all the users who have access to modify a package and push new versions.
23-
Handy when you need to know who to bug for help.
24-
* add:
25-
Add a new user as a maintainer of a package. This user is enabled to modify
26-
metadata, publish new versions, and add other owners.
27-
* rm:
28-
Remove a user from the package owner list. This immediately revokes their
29-
privileges.
21+
* ls: List all the users who have access to modify a package and push new
22+
versions. Handy when you need to know who to bug for help.
23+
* add: Add a new user as a maintainer of a package. This user is enabled
24+
to modify metadata, publish new versions, and add other owners.
25+
* rm: Remove a user from the package owner list. This immediately revokes
26+
their privileges.
3027

3128
Note that there is only one level of access. Either you can modify a package,
3229
or you can't. Future versions may contain more fine-grained access levels, but
3330
that is not implemented at this time.
3431

35-
If you have two-factor authentication enabled with `auth-and-writes` then
36-
you'll need to include an otp on the command line when changing ownership
37-
with `--otp`.
32+
If you have two-factor authentication enabled with `auth-and-writes` (see
33+
[`npm-profile`](/commands/npm-profile)) then you'll need to include an otp
34+
on the command line when changing ownership with `--otp`.
3835

3936
### See Also
4037

38+
* [npm profile](/commands/npm-profile)
4139
* [npm publish](/commands/npm-publish)
4240
* [npm registry](/using-npm/registry)
4341
* [npm adduser](/commands/npm-adduser)

docs/content/commands/npm-pack.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ npm pack [[<@scope>/]<pkg>...] [--dry-run]
1313
### Description
1414

1515
For anything that's installable (that is, a package folder, tarball,
16-
tarball url, name@tag, name@version, name, or scoped name), this
17-
command will fetch it to the cache, and then copy the tarball to the
18-
current working directory as `<name>-<version>.tgz`, and then write
19-
the filenames out to stdout.
16+
tarball url, git url, name@tag, name@version, name, or scoped name), this
17+
command will fetch it to the cache, copy the tarball to the current working
18+
directory as `<name>-<version>.tgz`, and then write the filenames out to
19+
stdout.
2020

2121
If the same package is specified multiple times, then the file will be
2222
overwritten the second time.
2323

2424
If no arguments are supplied, then npm packs the current package folder.
2525

2626
The `--dry-run` argument will do everything that pack usually does without
27-
actually packing anything. Reports on what would have gone into the tarball.
27+
actually packing anything. That is, it reports on what would have gone
28+
into the tarball, but nothing else.
2829

2930
### See Also
3031

32+
* [npm-packlist package](http://npm.im/npm-packlist)
3133
* [npm cache](/commands/npm-cache)
3234
* [npm publish](/commands/npm-publish)
3335
* [npm config](/commands/npm-config)

docs/content/commands/npm-ping.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ Ping error: {*Detail about error}
2525

2626
### See Also
2727

28+
* [npm doctor](/commands/npm-doctor)
2829
* [npm config](/commands/npm-config)
2930
* [npmrc](/configuring-npm/npmrc)

0 commit comments

Comments
 (0)