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

devonfw / IDEasy / 20003978026

07 Dec 2025 12:09PM UTC coverage: 70.101% (+0.2%) from 69.903%
20003978026

push

github

web-flow
#39: refactoring to extract package-manager logic out of node/npm (#1638)

3892 of 6090 branches covered (63.91%)

Branch coverage included in aggregate %.

9955 of 13663 relevant lines covered (72.86%)

3.15 hits per line

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

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

3
import java.nio.file.Files;
4
import java.nio.file.Path;
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.EnvironmentContext;
10
import com.devonfw.tools.ide.tool.ToolInstallation;
11
import com.devonfw.tools.ide.version.VersionIdentifier;
12

13
/**
14
 * {@link NpmBasedCommandlet} for <a href="https://www.npmjs.com/">npm</a>.
15
 */
16
public class Npm extends NpmBasedCommandlet {
17

18
  private static final String NPM_HOME_FOLDER = "npm";
19

20
  /**
21
   * The constructor.
22
   *
23
   * @param context the {@link IdeContext}.
24
   */
25
  public Npm(IdeContext context) {
26

27
    super(context, "npm", Set.of(Tag.JAVA_SCRIPT, Tag.BUILD));
7✔
28
  }
1✔
29

30
  @Override
31
  protected boolean canBeUninstalled() {
32
    return false;
2✔
33
  }
34

35
  @Override
36
  protected VersionIdentifier computeInstalledVersion() {
37
    if (hasNodeBinary("npm")) {
4✔
38
      return VersionIdentifier.of(this.context.newProcess().runAndGetSingleOutput("npm", "--version"));
13✔
39
    }
40
    return null;
2✔
41
  }
42

43
  @Override
44
  public String getToolHelpArguments() {
45

46
    return "help";
×
47
  }
48

49
  /**
50
   * @return the {@link Path} to the npm user configuration file, creates the folder and configuration file if it was not existing.
51
   */
52
  public Path getOrCreateNpmConfigUserConfig() {
53
    Path confPath = this.context.getConfPath().resolve(NPM_HOME_FOLDER);
6✔
54
    Path npmConfigFile = confPath.resolve(".npmrc");
4✔
55
    if (!Files.isDirectory(confPath)) {
5✔
56
      this.context.getFileAccess().mkdirs(confPath);
5✔
57
      this.context.getFileAccess().touch(npmConfigFile);
5✔
58
    }
59
    return npmConfigFile;
2✔
60
  }
61

62
  @Override
63
  public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean additionalInstallation) {
64
    super.setEnvironment(environmentContext, toolInstallation, additionalInstallation);
5✔
65
    environmentContext.withEnvVar("npm_config_prefix", this.context.getSoftwarePath().resolve("node").toString());
10✔
66
  }
1✔
67
}
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