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