11cb0ef41Sopenharmony_ci'use strict' 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst fs = require('graceful-fs').promises 41cb0ef41Sopenharmony_ciconst path = require('path') 51cb0ef41Sopenharmony_ciconst log = require('./log') 61cb0ef41Sopenharmony_ciconst semver = require('semver') 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciasync function remove (gyp, argv) { 91cb0ef41Sopenharmony_ci const devDir = gyp.devDir 101cb0ef41Sopenharmony_ci log.verbose('remove', 'using node-gyp dir:', devDir) 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci // get the user-specified version to remove 131cb0ef41Sopenharmony_ci let version = argv[0] || gyp.opts.target 141cb0ef41Sopenharmony_ci log.verbose('remove', 'removing target version:', version) 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci if (!version) { 171cb0ef41Sopenharmony_ci throw new Error('You must specify a version number to remove. Ex: "' + process.version + '"') 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci const versionSemver = semver.parse(version) 211cb0ef41Sopenharmony_ci if (versionSemver) { 221cb0ef41Sopenharmony_ci // flatten the version Array into a String 231cb0ef41Sopenharmony_ci version = versionSemver.version 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci const versionPath = path.resolve(gyp.devDir, version) 271cb0ef41Sopenharmony_ci log.verbose('remove', 'removing development files for version:', version) 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci // first check if its even installed 301cb0ef41Sopenharmony_ci try { 311cb0ef41Sopenharmony_ci await fs.stat(versionPath) 321cb0ef41Sopenharmony_ci } catch (err) { 331cb0ef41Sopenharmony_ci if (err.code === 'ENOENT') { 341cb0ef41Sopenharmony_ci return 'version was already uninstalled: ' + version 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci throw err 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci await fs.rm(versionPath, { recursive: true, force: true }) 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_cimodule.exports = remove 431cb0ef41Sopenharmony_cimodule.exports.usage = 'Removes the node development files for the specified version' 44