You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

remove.js 1.3KB

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