1

I've searched the web, but I couldn't get answer to my question. How is:

npm cache clean -f

Different from:

npm cache clean

I suspect -f is shorthand for --force, but even in official docs I wasn't able to find why one would use -f, what are upsides of it and what are downsides. I'm sure there's a warning when using -f, but I don't know why.

1 Answer 1

3

Take a look at npm cache clean source code:

// npm cache clean [<path>]
function clean (args, cb) {
  assert(typeof cb === 'function', 'must include callback')

  if (!args) args = []

  var f = path.join(npm.cache, normalize(args))
  if (f === npm.cache) {
    fs.readdir(npm.cache, function (er, files) {
      if (er) return cb()
      asyncMap(
        files.filter(function (f) {
          return npm.config.get('force') || f !== '-'
        }).map(function (f) {
          return path.join(npm.cache, f)
        }),
        rm,
        cb
      )
    })
  } else {
    rm(f, cb)
  }
}

Link to the source code: https://github.com/npm/npm/blob/master/lib/cache.js#L199

It looks like by default cache clean command browse through default npm cache directory and removes all files except file named -. This file is skipped by default, and is deleted only in force option.

The question is what is the use of dash as a filename? I have found the possible answer in this question. According to information provided in accepted answer, some programs use - file as standard stdout.

To sum up. Standard npm cache clean removes all cache files except - file which is used sometimes to store stdout content. However npm cache clean -f or npm cache clean --force removes all files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.