Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
uninstall.js55 linesDownload Raw Back to commands
1const { resolve } = require('node:path')
2const pkgJson = require('@npmcli/package-json')
3const reifyFinish = require('../utils/reify-finish.js')
4const completion = require('../utils/installed-shallow.js')
5const ArboristWorkspaceCmd = require('../arborist-cmd.js')
6
7class Uninstall extends ArboristWorkspaceCmd {
8  static description = 'Remove a package'
9  static name = 'uninstall'
10  static params = ['save', 'global', ...super.params]
11  static usage = ['[<@scope>/]<pkg>...']
12  static ignoreImplicitWorkspace = false
13
14  static async completion (opts, npm) {
15    return completion(npm, opts)
16  }
17
18  async exec (args) {
19    if (!args.length) {
20      if (!this.npm.global) {
21        throw new Error('Must provide a package name to remove')
22      } else {
23        try {
24          const { content: pkg } = await pkgJson.normalize(this.npm.localPrefix)
25          args.push(pkg.name)
26        } catch (er) {
27          if (er.code !== 'ENOENT' && er.code !== 'ENOTDIR') {
28            throw er
29          } else {
30            throw this.usageError()
31          }
32        }
33      }
34    }
35
36    // the /path/to/node_modules/..
37    const path = this.npm.global
38      ? resolve(this.npm.globalDir, '..')
39      : this.npm.localPrefix
40
41    const Arborist = require('@npmcli/arborist')
42    const opts = {
43      ...this.npm.flatOptions,
44      path,
45      rm: args,
46      workspaces: this.workspaceNames,
47    }
48    const arb = new Arborist(opts)
49    await arb.reify(opts)
50    await reifyFinish(this.npm, arb)
51  }
52}
53
54module.exports = Uninstall
55 
codekingpro/portable-devtools · Team Ai