MCPcopy Create free account
hub / github.com/nodejs/node / clean

Method clean

deps/npm/lib/commands/cache.js:129–158  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

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.
135As a result, data extracted from the cache is guaranteed to be valid.
136If you want to make sure everything is consistent, use \`npm cache verify\` instead.
137Deleting the cache can only make npm go slower, and is not likely to correct any problems you may be encountering!
138
139On 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
141If 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>...

Callers 1

execMethod · 0.95

Calls 5

warnMethod · 0.80
getMethod · 0.65
rmMethod · 0.45
entryMethod · 0.45
contentMethod · 0.45

Tested by

no test coverage detected