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

devonfw / IDEasy / 18099133632

29 Sep 2025 01:44PM UTC coverage: 68.468% (+0.02%) from 68.447%
18099133632

push

github

web-flow
#1511: Fixed npm commands (#1513)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

3438 of 5499 branches covered (62.52%)

Branch coverage included in aggregate %.

8989 of 12651 relevant lines covered (71.05%)

3.12 hits per line

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

36.11
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.util.StringUtil;
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 {
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
  public ToolRepository getToolRepository() {
38

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

42
  @Override
43
  protected boolean isIgnoreMissingSoftwareVersionFile() {
44

45
    return true;
2✔
46
  }
47

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

53
  protected 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
    ProcessResult result = runPackageManager(ProcessMode.DEFAULT_CAPTURE, ProcessErrorHandling.NONE, "list", "-g", npmPackage, "--depth=0");
×
59
    if (result.isSuccessful()) {
×
60
      List<String> versions = result.getOut();
×
61
      String parsedVersion = null;
×
62
      for (String version : versions) {
×
63
        if (version.contains(npmPackage)) {
×
64
          parsedVersion = version.replaceAll(".*" + npmPackage + "@", "");
×
65
          break;
×
66
        }
67
      }
×
68
      if (parsedVersion != null) {
×
69
        return VersionIdentifier.of(parsedVersion);
×
70
      }
71
    } else {
×
72
      this.context.debug("The npm package {} for tool {} is not installed.", npmPackage, this.tool);
×
73
    }
74
    return null;
×
75
  }
76

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

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

83
    return npm.runTool(processMode, null, pc,
18✔
84
        StringUtil.extendArray(args, false, "--prefix", this.context.getSoftwarePath().resolve("node").toAbsolutePath().toString()));
7✔
85
  }
86

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