| 127 | |
| 128 | // npm cache clean [spec]* |
| 129 | async clean (args) { |
| 130 | // this is a derived value |
| 131 | const cachePath = this.npm.flatOptions.cache |
| 132 | if (args.length === 0) { |
| 133 | if (!this.npm.config.get('force')) { |
| 134 | throw new Error(`As of npm@5, the npm cache self-heals from corruption issues by treating integrity mismatches as cache misses. |
| 135 | As a result, data extracted from the cache is guaranteed to be valid. |
| 136 | If you want to make sure everything is consistent, use \`npm cache verify\` instead. |
| 137 | Deleting the cache can only make npm go slower, and is not likely to correct any problems you may be encountering! |
| 138 | |
| 139 | On the other hand, if you're debugging an issue with the installer, or race conditions that depend on the timing of writing to an empty cache, you can use \`npm install --cache /tmp/empty-cache\` to use a temporary cache instead of removing the actual one. |
| 140 | |
| 141 | If you're sure you want to delete the entire cache, rerun this command with --force.`) |
| 142 | } |
| 143 | return fs.rm(cachePath, { recursive: true, force: true }) |
| 144 | } |
| 145 | for (const key of args) { |
| 146 | let entry |
| 147 | try { |
| 148 | entry = await cacache.get(cachePath, key) |
| 149 | } catch { |
| 150 | log.warn('cache', `Not Found: ${key}`) |
| 151 | break |
| 152 | } |
| 153 | output.standard(`Deleted: ${key}`) |
| 154 | await cacache.rm.entry(cachePath, key) |
| 155 | // XXX this could leave other entries without content! |
| 156 | await cacache.rm.content(cachePath, entry.integrity) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // npm cache add <tarball-url>... |
| 161 | // npm cache add <pkg> <ver>... |