Skip to content

Commit

Permalink
feat: drop rimraf dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Dec 15, 2022
1 parent 6b2de32 commit 6b5651c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
10 changes: 6 additions & 4 deletions lib/clean.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use strict'

const rm = require('rimraf')
const fs = require('fs')
const log = require('./log')

function clean (gyp, argv, callback) {
async function clean (gyp, argv) {
// Remove the 'build' dir
const buildDir = 'build'

log.verbose('clean', 'removing "%s" directory', buildDir)
rm(buildDir, callback)
await fs.promises.rm(buildDir, { recursive: true, force: true })
}

module.exports = clean
module.exports = function (gyp, argv, callback) {
clean(gyp, argv).then(callback.bind(undefined, null), callback)
}
module.exports.usage = 'Removes any generated build files and the "out" dir'
31 changes: 15 additions & 16 deletions lib/remove.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict'

const fs = require('fs')
const rm = require('rimraf')
const fs = require('fs').promises
const path = require('path')
const log = require('./log')
const semver = require('semver')

function remove (gyp, argv, callback) {
async function remove (gyp, argv) {
const devDir = gyp.devDir
log.verbose('remove', 'using node-gyp dir:', devDir)

Expand All @@ -15,7 +14,7 @@ function remove (gyp, argv, callback) {
log.verbose('remove', 'removing target version:', version)

if (!version) {
return callback(new Error('You must specify a version number to remove. Ex: "' + process.version + '"'))
throw new Error('You must specify a version number to remove. Ex: "' + process.version + '"')
}

const versionSemver = semver.parse(version)
Expand All @@ -28,19 +27,19 @@ function remove (gyp, argv, callback) {
log.verbose('remove', 'removing development files for version:', version)

// first check if its even installed
fs.stat(versionPath, function (err) {
if (err) {
if (err.code === 'ENOENT') {
callback(null, 'version was already uninstalled: ' + version)
} else {
callback(err)
}
return
try {
await fs.stat(versionPath)
} catch (err) {
if (err.code === 'ENOENT') {
return 'version was already uninstalled: ' + version
}
// Go ahead and delete the dir
rm(versionPath, callback)
})
throw err
}

await fs.rm(versionPath, { recursive: true, force: true })
}

module.exports = exports = remove
module.exports = function (gyp, argv, callback) {
remove(gyp, argv).then(callback.bind(undefined, null), callback)
}
module.exports.usage = 'Removes the node development files for the specified version'
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"make-fetch-happen": "^11.0.2",
"nopt": "^7.0.0",
"proc-log": "^3.0.0",
"rimraf": "^3.0.2",
"semver": "^7.3.5",
"tar": "^6.1.2",
"which": "^3.0.0"
Expand Down
3 changes: 1 addition & 2 deletions test/test-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const https = require('https')
const install = require('../lib/install')
const semver = require('semver')
const devDir = require('./fixtures/common').devDir()
const rimraf = require('rimraf')
const gyp = require('../lib/node-gyp')
const log = require('../lib/log')
const certs = require('./fixtures/certs')
Expand Down Expand Up @@ -179,7 +178,7 @@ test('download headers (actual)', async (t) => {
t.plan(12)

const expectedDir = path.join(devDir, process.version.replace(/^v/, ''))
await util.promisify(rimraf)(expectedDir)
await fs.promises.rm(expectedDir, { recursive: true, force: true })

const prog = gyp()
prog.parseArgv([])
Expand Down

0 comments on commit 6b5651c

Please sign in to comment.