npm prune doesn't work inside of "scripts" #2827

Open
andrewrk opened this Issue Sep 24, 2012 · 2 comments

Projects

None yet

3 participants

@andrewrk
$ npm -v
1.1.59
$ node -v
v0.8.9
$ cat package.json 
{
  "name": "prune-test",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": { },
  "devDependencies": {},
  "scripts": {
    "doit": "npm prune"
  },
  "repository": "",
  "author": "",
  "license": "BSD"
}
$ ls node_modules/
async
$ npm prune
npm WARN package.json prune-test@0.0.0 No README.md file found!
$ ls node_modules/
$ npm install async
npm WARN package.json prune-test@0.0.0 No README.md file found!
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/async
async@0.1.22 node_modules/async
$ npm run doit
npm WARN package.json prune-test@0.0.0 No README.md file found!

> prune-test@0.0.0 doit /home/andy/tmp/prune-test
> npm prune

npm WARN package.json prune-test@0.0.0 No README.md file found!
$ ls node_modules/
async
@timoxley
npm member

Interesting! I can confirm this is still an issue with node 0.10.24 and npm 1.3.23 / current npm master 823010b.

@timoxley
npm member

Ok, so this has something to do with npm's depth config being different depending on whether you run it from the commandline or inside a script.

Adding a non-zero depth to the npm script command makes prune work correctly:

 "doit": "npm prune --depth Infinity" 

Add a script to compare the depth config setting:

"depth": "npm config get depth"

Running npm config get depth from the commandline depth will be Infinity while the npm run depth script will give a depth of 0.

It's possible this is by design, I vaguely recall bumping up against this depth thing before, perhaps @isaacs knows more?

@iarna iarna added the bug label Oct 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment