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

devonfw / IDEasy / 21174441650

20 Jan 2026 02:06PM UTC coverage: 70.447% (-0.02%) from 70.471%
21174441650

push

github

web-flow
#1679: fix determine version if npm list has exit code 1 (#1681)

4031 of 6308 branches covered (63.9%)

Branch coverage included in aggregate %.

10479 of 14289 relevant lines covered (73.34%)

3.18 hits per line

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

83.78
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 com.devonfw.tools.ide.common.Tag;
8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.process.ProcessContext;
10
import com.devonfw.tools.ide.process.ProcessErrorHandling;
11
import com.devonfw.tools.ide.process.ProcessMode;
12
import com.devonfw.tools.ide.process.ProcessResult;
13
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
14
import com.devonfw.tools.ide.tool.PackageManagerRequest;
15
import com.devonfw.tools.ide.tool.node.NodeBasedCommandlet;
16
import com.devonfw.tools.ide.tool.repository.ToolRepository;
17
import com.devonfw.tools.ide.version.VersionIdentifier;
18

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

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

33
    super(context, tool, tags);
5✔
34
  }
1✔
35

36
  @Override
37
  protected Class<Npm> getPackageManagerClass() {
38

39
    return Npm.class;
2✔
40
  }
41

42
  @Override
43
  public ToolRepository getToolRepository() {
44

45
    return this.context.getNpmRepository();
4✔
46
  }
47

48
  @Override
49
  protected VersionIdentifier computeInstalledVersion() {
50
    return runPackageManagerGetInstalledVersion(getPackageName());
5✔
51
  }
52

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

82
}
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