Welcome to mirror list, hosted at ThFree Co, Russian Federation.

npm-link.1 « man1 « man « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f978f281f0ea06761be1d746fe30202fce0ec01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
.TH "NPM\-LINK" "1" "February 2021" "" ""
.SH "NAME"
\fBnpm-link\fR \- Symlink a package folder
.SS Synopsis
.P
.RS 2
.nf
npm link (in package dir)
npm link [<@scope>/]<pkg>[@<version>]

alias: npm ln
.fi
.RE
.SS Description
.P
This is handy for installing your own stuff, so that you can work on it and
test iteratively without having to continually rebuild\.
.P
Package linking is a two\-step process\.
.P
First, \fBnpm link\fP in a package folder will create a symlink in the global
folder \fB{prefix}/lib/node_modules/<package>\fP that links to the package
where the \fBnpm link\fP command was executed\. It will also link any bins in
the package to \fB{prefix}/bin/{name}\fP\|\.  Note that \fBnpm link\fP uses the global
prefix (see \fBnpm prefix \-g\fP for its value)\.
.P
Next, in some other location, \fBnpm link package\-name\fP will create a
symbolic link from globally\-installed \fBpackage\-name\fP to \fBnode_modules/\fP of
the current folder\.
.P
Note that \fBpackage\-name\fP is taken from \fBpackage\.json\fP, \fInot\fR from the
directory name\.
.P
The package name can be optionally prefixed with a scope\. See
npm help \fBscope\fP\|\.  The scope must be preceded by an @\-symbol and
followed by a slash\.
.P
When creating tarballs for \fBnpm publish\fP, the linked packages are
"snapshotted" to their current state by resolving the symbolic links, if
they are included in \fBbundleDependencies\fP\|\.
.P
For example:
.P
.RS 2
.nf
cd ~/projects/node\-redis    # go into the package directory
npm link                    # creates global link
cd ~/projects/node\-bloggy   # go into some other package directory\.
npm link redis              # link\-install the package
.fi
.RE
.P
Now, any changes to \fB~/projects/node\-redis\fP will be reflected in
\fB~/projects/node\-bloggy/node_modules/node\-redis/\fP\|\. Note that the link
should be to the package name, not the directory name for that package\.
.P
You may also shortcut the two steps in one\.  For example, to do the
above use\-case in a shorter way:
.P
.RS 2
.nf
cd ~/projects/node\-bloggy  # go into the dir of your main project
npm link \.\./node\-redis     # link the dir of your dependency
.fi
.RE
.P
The second line is the equivalent of doing:
.P
.RS 2
.nf
(cd \.\./node\-redis; npm link)
npm link redis
.fi
.RE
.P
That is, it first creates a global link, and then links the global
installation target into your project's \fBnode_modules\fP folder\.
.P
Note that in this case, you are referring to the directory name,
\fBnode\-redis\fP, rather than the package name \fBredis\fP\|\.
.P
If your linked package is scoped (see npm help \fBscope\fP) your
link command must include that scope, e\.g\.
.P
.RS 2
.nf
npm link @myorg/privatepackage
.fi
.RE
.SS Caveat
.P
Note that package dependencies linked in this way are \fInot\fR saved to
\fBpackage\.json\fP by default, on the assumption that the intention is to have
a link stand in for a regular non\-link dependency\.  Otherwise, for example,
if you depend on \fBredis@^3\.0\.1\fP, and ran \fBnpm link redis\fP, it would replace
the \fB^3\.0\.1\fP dependency with \fBfile:\.\./path/to/node\-redis\fP, which you
probably don't want!  Additionally, other users or developers on your
project would run into issues if they do not have their folders set up
exactly the same as yours\.
.P
If you are adding a \fInew\fR dependency as a link, you should add it to the
relevant metadata by running \fBnpm install <dep> \-\-package\-lock\-only\fP\|\.
.P
If you \fIwant\fR to save the \fBfile:\fP reference in your \fBpackage\.json\fP and
\fBpackage\-lock\.json\fP files, you can use \fBnpm link <dep> \-\-save\fP to do so\.
.SS See Also
.RS 0
.IP \(bu 2
npm help developers
.IP \(bu 2
npm help package\.json
.IP \(bu 2
npm help install
.IP \(bu 2
npm help folders
.IP \(bu 2
npm help config
.IP \(bu 2
npm help npmrc

.RE