|
1 | 1 | .\" Generated with Ronnjs/v0.1
|
2 | 2 | .\" http://github.com/kapouer/ronnjs/
|
3 | 3 | .
|
4 |
| -.TH "NPM\-SCRIPTS" "1" "August 2010" "" "" |
| 4 | +.TH "NPM\-SCRIPTS" "1" "September 2010" "" "" |
5 | 5 | .
|
6 | 6 | .SH "NAME"
|
7 | 7 | \fBnpm-scripts\fR \-\- How npm handles the "scripts" field
|
@@ -148,3 +148,44 @@ process\.
|
148 | 148 | .P
|
149 | 149 | Note that these script files don\'t have to be nodejs or even javascript
|
150 | 150 | programs\. They just have to be some kind of executable file\.
|
| 151 | +. |
| 152 | +.SH "HOOK SCRIPTS" |
| 153 | +If you want to run a specific script at a specific lifecycle event for ALL |
| 154 | +packages, then you can use a hook script\. |
| 155 | +. |
| 156 | +.P |
| 157 | +Place an executable file at \fB{root}/\.npm/\.hooks/{eventname}\fR, and it\'ll get |
| 158 | +run for all packages when they are going through that point in the package |
| 159 | +lifecycle\. |
| 160 | +. |
| 161 | +.P |
| 162 | +Hook scripts are run exactly the same way as package\.json scripts\. That is, |
| 163 | +they are in a separate child process, with the env described above\. |
| 164 | +. |
| 165 | +.SH "BEST PRACTICES" |
| 166 | +. |
| 167 | +.IP "\(bu" 4 |
| 168 | +Don\'t exit with a non\-zero error code unless you \fIreally\fR mean it\. |
| 169 | +Except for uninstall/deactivate scripts, this will cause the npm action |
| 170 | +to fail, and potentially be rolled back\. If the failure is minor or |
| 171 | +only will prevent some optional features, then it\'s better to just |
| 172 | +print a warning and exit successfully\. |
| 173 | +. |
| 174 | +.IP "\(bu" 4 |
| 175 | +Try not to use scripts to do what npm can do for you\. Read through \fBnpm help json\fR to see all the things that you can specify and enable |
| 176 | +by simply describing your package appropriately\. In general, this will |
| 177 | +lead to a more robust and consistent state\. |
| 178 | +. |
| 179 | +.IP "\(bu" 4 |
| 180 | +Inspect the env to determine where to put things\. For instance, if |
| 181 | +the \fBnpm_config_binroot\fR environ is set to \fB/home/user/bin\fR, then don\'t |
| 182 | +try to install executables into \fB/usr/local/bin\fR\|\. The user probably |
| 183 | +set it up that way for a reason\. |
| 184 | +. |
| 185 | +.IP "\(bu" 4 |
| 186 | +Don\'t prefix your script commands with "sudo"\. If root permissions are |
| 187 | +required for some reason, then it\'ll fail with that error, and the user |
| 188 | +will sudo the npm command in question\. |
| 189 | +. |
| 190 | +.IP "" 0 |
| 191 | + |
0 commit comments