Skip to content

Commit

Permalink
fix: replace rimraf with fs.rm
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Dec 17, 2022
1 parent b82c1a6 commit 28ec922
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 27 deletions.
1 change: 0 additions & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ graph LR;
npm-->remark-gfm;
npm-->remark-github;
npm-->remark;
npm-->rimraf;
npm-->semver;
npm-->spawk;
npm-->ssri;
Expand Down
5 changes: 2 additions & 3 deletions lib/commands/cache.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const cacache = require('cacache')
const Arborist = require('@npmcli/arborist')
const { promisify } = require('util')
const pacote = require('pacote')
const fs = require('fs/promises')
const path = require('path')
const rimraf = promisify(require('rimraf'))
const semver = require('semver')
const BaseCommand = require('../base-command.js')
const npa = require('npm-package-arg')
Expand Down Expand Up @@ -130,7 +129,7 @@ class Cache extends BaseCommand {
If you're sure you want to delete the entire cache, rerun this command
with --force.`)
}
return rimraf(cachePath)
return fs.rm(cachePath, { recursive: true, force: true })
}
for (const key of args) {
let entry
Expand Down
9 changes: 3 additions & 6 deletions lib/commands/ci.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const util = require('util')
const Arborist = require('@npmcli/arborist')
const rimraf = util.promisify(require('rimraf'))
const reifyFinish = require('../utils/reify-finish.js')
const runScript = require('@npmcli/run-script')
const fs = require('fs')
const readdir = util.promisify(fs.readdir)
const fs = require('fs/promises')
const log = require('../utils/log-shim.js')
const validateLockfile = require('../utils/validate-lockfile.js')

Expand Down Expand Up @@ -69,8 +66,8 @@ class CI extends ArboristWorkspaceCmd {
await this.npm.time('npm-ci:rm', async () => {
const path = `${where}/node_modules`
// get the list of entries so we can skip the glob for performance
const entries = await readdir(path, null).catch(er => [])
return Promise.all(entries.map(f => rimraf(`${path}/${f}`, { glob: false })))
const entries = await fs.readdir(path, null).catch(er => [])
return Promise.all(entries.map(f => fs.rm(`${path}/${f}`, { force: true })))
})

await arb.reify(opts)
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/log-file.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const os = require('os')
const path = require('path')
const { format, promisify } = require('util')
const rimraf = promisify(require('rimraf'))
const glob = promisify(require('glob'))
const MiniPass = require('minipass')
const fsMiniPass = require('fs-minipass')
const fs = require('fs/promises')
const log = require('./log-shim')

const padZero = (n, length) => n.toString().padStart(length.toString().length, '0')
Expand Down Expand Up @@ -217,7 +217,7 @@ class LogFiles {

for (const file of files.slice(0, toDelete)) {
try {
await rimraf(file, { glob: false })
await fs.rm(file, { force: true })
} catch (e) {
log.silly('logfile', 'error removing log file', file, e)
}
Expand Down
2 changes: 0 additions & 2 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"read",
"read-package-json",
"read-package-json-fast",
"rimraf",
"semver",
"ssri",
"tar",
Expand Down Expand Up @@ -143,7 +142,6 @@
"read": "~1.0.7",
"read-package-json": "^6.0.0",
"read-package-json-fast": "^3.0.1",
"rimraf": "^3.0.2",
"semver": "^7.3.8",
"ssri": "^10.0.1",
"tar": "^6.1.13",
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"read": "~1.0.7",
"read-package-json": "^6.0.0",
"read-package-json-fast": "^3.0.1",
"rimraf": "^3.0.2",
"semver": "^7.3.8",
"ssri": "^10.0.1",
"tar": "^6.1.13",
Expand Down Expand Up @@ -180,7 +179,6 @@
"read",
"read-package-json",
"read-package-json-fast",
"rimraf",
"semver",
"ssri",
"tar",
Expand Down
6 changes: 2 additions & 4 deletions test/fixtures/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { createHook, executionAsyncId } = require('async_hooks')
const { EventEmitter } = require('events')
const { homedir, tmpdir } = require('os')
const { dirname, join } = require('path')
const { promisify } = require('util')
const { mkdir } = require('fs/promises')
const rimraf = promisify(require('rimraf'))
const { mkdir, rm } = require('fs/promises')
const mockLogs = require('./mock-logs')
const pkg = require('../../package.json')

Expand Down Expand Up @@ -201,7 +199,7 @@ class Sandbox extends EventEmitter {
if (this[_npm]) {
this[_npm].unload()
}
return rimraf(this[_dirs].temp).catch(() => null)
return rm(this[_dirs].temp, { recursive: true, force: true }).catch(() => null)
}

// proxy get handler
Expand Down
15 changes: 8 additions & 7 deletions test/lib/utils/log-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const fs = _fs.promises
const path = require('path')
const os = require('os')
const fsMiniPass = require('fs-minipass')
const rimraf = require('rimraf')
const LogFile = require('../../../lib/utils/log-file.js')
const { cleanCwd, cleanDate } = require('../../fixtures/clean-snapshot')

Expand Down Expand Up @@ -275,12 +274,14 @@ t.test('rimraf error', async t => {
logsMax,
testdir: makeOldLogs(oldLogs),
mocks: {
rimraf: (...args) => {
if (count >= 3) {
throw new Error('bad rimraf')
}
count++
return rimraf(...args)
'fs/promises': {
rm: async (...args) => {
if (count >= 3) {
throw new Error('bad rimraf')
}
count++
return fs.rm(...args)
},
},
},
})
Expand Down

0 comments on commit 28ec922

Please sign in to comment.