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

devonfw / IDEasy / 18597783582

17 Oct 2025 03:45PM UTC coverage: 68.522% (+0.09%) from 68.437%
18597783582

Pull #1467

github

web-flow
Merge 4e5b40da9 into 46d29352c
Pull Request #1467: #907 Add yarn and corepack

3467 of 5539 branches covered (62.59%)

Branch coverage included in aggregate %.

9054 of 12734 relevant lines covered (71.1%)

3.13 hits per line

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

31.43
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.node.NodeBasedCommandlet;
15
import com.devonfw.tools.ide.tool.repository.ToolRepository;
16
import com.devonfw.tools.ide.version.VersionIdentifier;
17

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

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

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

35
  @Override
36
  public ToolRepository getToolRepository() {
37

38
    return this.context.getNpmRepository();
4✔
39
  }
40

41
  @Override
42
  protected boolean isIgnoreMissingSoftwareVersionFile() {
43

44
    return true;
×
45
  }
46

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

52
  protected VersionIdentifier runPackageManagerGetInstalledVersion(String npmPackage) {
53
    if (!Files.isDirectory(this.context.getSoftwarePath().resolve("node"))) {
9!
54
      this.context.trace("Since node is not installed, also package {} for tool {} cannot be installed.", npmPackage, this.tool);
15✔
55
      return null;
2✔
56
    }
57
    ProcessResult result = runPackageManager(ProcessMode.DEFAULT_CAPTURE, ProcessErrorHandling.NONE, "list", "-g", npmPackage, "--depth=0");
×
58
    if (result.isSuccessful()) {
×
59
      List<String> versions = result.getOut();
×
60
      String parsedVersion = null;
×
61
      for (String version : versions) {
×
62
        if (version.contains(npmPackage)) {
×
63
          parsedVersion = version.replaceAll(".*" + npmPackage + "@", "");
×
64
          break;
×
65
        }
66
      }
×
67
      if (parsedVersion != null) {
×
68
        return VersionIdentifier.of(parsedVersion);
×
69
      }
70
    } else {
×
71
      this.context.debug("The npm package {} for tool {} is not installed.", npmPackage, this.tool);
×
72
    }
73
    return null;
×
74
  }
75

76
  @Override
77
  protected ProcessResult runPackageManager(ProcessMode processMode, ProcessErrorHandling errorHandling, String... args) {
78

79
    ProcessContext pc = this.context.newProcess().errorHandling(errorHandling);
6✔
80
    Npm npm = this.context.getCommandletManager().getCommandlet(Npm.class);
7✔
81

82
    return npm.runTool(processMode, null, pc, args);
7✔
83
  }
84

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

© 2025 Coveralls, Inc