• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 26214126503

21 May 2026 08:16AM UTC coverage: 70.981% (+0.03%) from 70.953%
26214126503

Pull #1900

github

web-flow
Merge f048669be into 5cf051aec
Pull Request #1900: #1886: fix npm based commandlet shows wrong tool version

4446 of 6934 branches covered (64.12%)

Branch coverage included in aggregate %.

11490 of 15517 relevant lines covered (74.05%)

3.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
cli/src/main/java/com/devonfw/tools/ide/tool/npm/NpmBasedCommandlet.java
1
package com.devonfw.tools.ide.tool.npm;
2

3
import java.nio.file.Files;
4
import java.util.List;
5
import java.util.Set;
6

7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import com.devonfw.tools.ide.common.Tag;
11
import com.devonfw.tools.ide.context.IdeContext;
12
import com.devonfw.tools.ide.process.ProcessContext;
13
import com.devonfw.tools.ide.process.ProcessErrorHandling;
14
import com.devonfw.tools.ide.process.ProcessMode;
15
import com.devonfw.tools.ide.process.ProcessResult;
16
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
17
import com.devonfw.tools.ide.tool.PackageManagerRequest;
18
import com.devonfw.tools.ide.tool.node.NodeBasedCommandlet;
19
import com.devonfw.tools.ide.tool.repository.ToolRepository;
20
import com.devonfw.tools.ide.version.VersionIdentifier;
21

22
/**
23
 * {@link LocalToolCommandlet} for tools based on <a href="https://www.npmjs.com/">npm</a>.
24
 */
25
public abstract class NpmBasedCommandlet extends NodeBasedCommandlet<Npm> {
26

27
  private static final Logger LOG = LoggerFactory.getLogger(NpmBasedCommandlet.class);
4✔
28

29
  /**
30
   * The constructor.
31
   *
32
   * @param context the {@link IdeContext}.
33
   * @param tool the {@link #getName() tool name}.
34
   * @param tags the {@link #getTags() tags} classifying the tool. Should be created via {@link Set#of(Object) Set.of} method.
35
   */
36
  public NpmBasedCommandlet(IdeContext context, String tool, Set<Tag> tags) {
37

38
    super(context, tool, tags);
5✔
39
  }
1✔
40

41
  @Override
42
  protected Class<Npm> getPackageManagerClass() {
43

44
    return Npm.class;
2✔
45
  }
46

47
  @Override
48
  public ToolRepository getToolRepository() {
49

50
    return this.context.getNpmRepository();
4✔
51
  }
52

53

54
  @Override
55
  protected VersionIdentifier computeInstalledVersion() {
56
    return runPackageManagerGetInstalledVersion(getPackageName());
5✔
57
  }
58

59
  private VersionIdentifier runPackageManagerGetInstalledVersion(String npmPackage) {
60
    if (!Files.isDirectory(this.context.getSoftwarePath().resolve("node"))) {
9✔
61
      LOG.trace("Since node is not installed, also package {} for tool {} cannot be installed.", npmPackage, this.tool);
6✔
62
      return null;
2✔
63
    }
64
    PackageManagerRequest request = new PackageManagerRequest("list", npmPackage).addArg("list").addArg("-g").addArg(npmPackage).addArg("--depth=0")
14✔
65
        .setProcessMode(ProcessMode.DEFAULT_CAPTURE);
2✔
66
    ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.THROW_CLI)
6✔
67
        .withExitCodeAcceptor(rc -> true); // if the tool is not installed npm list will end with exit code 1
4✔
68
    request.setProcessContext(pc);
4✔
69
    ProcessResult result = runPackageManager(request);
4✔
70
    if (result.isSuccessful()) {
3!
71
      List<String> versions = result.getOut();
3✔
72
      String parsedVersion = null;
2✔
73
      for (String version : versions) {
10!
74
        if (version.contains(npmPackage)) {
4✔
75
          parsedVersion = version.replaceAll(".*" + npmPackage + "@", "");
6✔
76
          break;
1✔
77
        }
78
      }
1✔
79
      if (parsedVersion != null) {
2!
80
        return VersionIdentifier.of(parsedVersion);
3✔
81
      }
82
    } else {
×
83
      LOG.debug("The npm package {} for tool {} is not installed.", npmPackage, this.tool);
×
84
    }
85
    return null;
×
86
  }
87

88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc