A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/npm/cli/commit/3ed764aa08f2087fa1d1bd7391a646ba47565294 below:

Clarify script working directory behavior (fixes #8305) (#8308) · npm/cli@3ed764a · GitHub

File tree Expand file treeCollapse file tree 1 file changed

+14

-5

lines changed

Filter options

Expand file treeCollapse file tree 1 file changed

+14

-5

lines changed Original file line number Diff line number Diff line change

@@ -228,6 +228,20 @@ Reasons for a package removal include:

228 228 229 229

Due to the lack of necessary context, `uninstall` lifecycle scripts are not implemented and will not function.

230 230 231 +

### Working Directory for Scripts

232 + 233 +

Scripts are always run from the root of the package folder, regardless of what the current working directory is when `npm` is invoked. This means your scripts can reliably assume they are running in the package root.

234 + 235 +

If you want your script to behave differently based on the directory you were in when you ran `npm`, you can use the `INIT_CWD` environment variable, which holds the full path you were in when you ran `npm run`.

236 + 237 +

#### Historical Behavior in Older npm Versions

238 + 239 +

For npm v6 and earlier, scripts were generally run from the root of the package, but there were rare cases and bugs in older versions where this was not guaranteed. If your package must support very old npm versions, you may wish to add a safeguard in your scripts (for example, by checking process.cwd()).

240 + 241 +

For more details, see:

242 +

- [npm v7 release notes](https://github.com/npm/cli/releases/tag/v7.0.0)

243 +

- [Discussion about script working directory reliability in npm v6 and earlier](https://github.com/npm/npm/issues/12356)

244 + 231 245

### User

232 246 233 247

When npm is run as root, scripts are always run with the effective uid

@@ -350,11 +364,6 @@ file.

350 364

preinstall or install script. If you are doing this, please consider if

351 365

there is another option. The only valid use of `install` or `preinstall`

352 366

scripts is for compilation which must be done on the target architecture.

353 -

* Scripts are run from the root of the package folder, regardless of what the

354 -

current working directory is when `npm` is invoked. If you want your

355 -

script to use different behavior based on what subdirectory you're in, you

356 -

can use the `INIT_CWD` environment variable, which holds the full path you

357 -

were in when you ran `npm run`.

358 367 359 368

### See Also

360 369

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4