1'use strict' 2 3const fs = require('graceful-fs').promises 4const path = require('path') 5const log = require('./log') 6const semver = require('semver') 7 8async function remove (gyp, argv) { 9 const devDir = gyp.devDir 10 log.verbose('remove', 'using node-gyp dir:', devDir) 11 12 // get the user-specified version to remove 13 let version = argv[0] || gyp.opts.target 14 log.verbose('remove', 'removing target version:', version) 15 16 if (!version) { 17 throw new Error('You must specify a version number to remove. Ex: "' + process.version + '"') 18 } 19 20 const versionSemver = semver.parse(version) 21 if (versionSemver) { 22 // flatten the version Array into a String 23 version = versionSemver.version 24 } 25 26 const versionPath = path.resolve(gyp.devDir, version) 27 log.verbose('remove', 'removing development files for version:', version) 28 29 // first check if its even installed 30 try { 31 await fs.stat(versionPath) 32 } catch (err) { 33 if (err.code === 'ENOENT') { 34 return 'version was already uninstalled: ' + version 35 } 36 throw err 37 } 38 39 await fs.rm(versionPath, { recursive: true, force: true }) 40} 41 42module.exports = remove 43module.exports.usage = 'Removes the node development files for the specified version' 44