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

devonfw / IDEasy / 18597984553

17 Oct 2025 03:54PM UTC coverage: 68.527% (+0.09%) from 68.437%
18597984553

push

github

web-flow
#907 Add yarn and corepack (#1467)

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

3466 of 5537 branches covered (62.6%)

Branch coverage included in aggregate %.

9049 of 12726 relevant lines covered (71.11%)

3.13 hits per line

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

75.86
cli/src/main/java/com/devonfw/tools/ide/tool/node/NodeBasedCommandlet.java
1
package com.devonfw.tools.ide.tool.node;
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.cache.CachedValue;
8
import com.devonfw.tools.ide.common.Tag;
9
import com.devonfw.tools.ide.context.IdeContext;
10
import com.devonfw.tools.ide.process.ProcessContext;
11
import com.devonfw.tools.ide.process.ProcessErrorHandling;
12
import com.devonfw.tools.ide.process.ProcessMode;
13
import com.devonfw.tools.ide.process.ProcessResult;
14
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
15
import com.devonfw.tools.ide.tool.corepack.Corepack;
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 NodeBasedCommandlet extends LocalToolCommandlet {
23

24
  private final CachedValue<VersionIdentifier> installedVersion;
25

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

35
    super(context, tool, tags);
5✔
36
    this.installedVersion = new CachedValue<>(this::computeInstalledVersion);
7✔
37
  }
1✔
38

39
  /**
40
   * @return the computed value of the {@link #getInstalledVersion() installed version}.
41
   */
42
  protected abstract VersionIdentifier computeInstalledVersion();
43

44
  @Override
45
  protected boolean isIgnoreSoftwareRepo() {
46

47
    // node and node.js are messy - see https://github.com/devonfw/IDEasy/issues/352
48
    return true;
2✔
49
  }
50

51
  /**
52
   * @return the package of this tool from the NPM registry.
53
   */
54
  public String getPackageName() {
55

56
    return this.tool;
3✔
57
  }
58

59
  @Override
60
  public Path getToolPath() {
61

62
    return this.context.getSoftwarePath().resolve("node");
6✔
63
  }
64

65
  @Override
66
  public VersionIdentifier getInstalledVersion() {
67

68
    return this.installedVersion.get();
5✔
69
  }
70

71
  @Override
72
  public String getInstalledEdition() {
73

74
    if (getInstalledVersion() != null) {
3!
75
      return this.tool;
×
76
    }
77
    return null;
2✔
78
  }
79

80
  @Override
81
  protected void performToolInstallation(ToolRepository toolRepository, VersionIdentifier resolvedVersion, Path installationPath, String edition,
82
      ProcessContext processContext) {
83

84
    runPackageInstall(getPackageName() + "@" + resolvedVersion);
7✔
85
    this.installedVersion.invalidate();
3✔
86
  }
1✔
87

88
  @Override
89
  protected void performUninstall(Path toolPath) {
90

91
    runPackageUninstall(getPackageName());
4✔
92
    this.installedVersion.invalidate();
3✔
93
  }
1✔
94

95
  /**
96
   * Checks if a provided binary can be found within node.
97
   *
98
   * @param binary name of the binary.
99
   * @return {@code true} if a binary was found in the node installation, {@code false} if not.
100
   */
101
  protected boolean hasNodeBinary(String binary) {
102

103
    return Files.exists(getToolBinPath().resolve(binary));
8✔
104
  }
105

106
  /**
107
   * Runs uninstall using the package manager.
108
   *
109
   * @param npmPackage the npm package to uninstall.
110
   */
111
  protected void runPackageUninstall(String npmPackage) {
112
    
113
    runPackageManager("uninstall", "-g", npmPackage).failOnError();
17✔
114
  }
1✔
115

116
  /**
117
   * Runs install using the package manager.
118
   *
119
   * @param npmPackage the npm package to install.
120
   */
121
  protected void runPackageInstall(String npmPackage) {
122

123
    runPackageManager("install", "-g", npmPackage).failOnError();
17✔
124
  }
1✔
125

126
  /**
127
   * @param args the arguments for the package manager.
128
   * @return the {@link ProcessResult}.
129
   */
130
  protected ProcessResult runPackageManager(String... args) {
131

132
    return runPackageManager(ProcessMode.DEFAULT, ProcessErrorHandling.THROW_CLI, args);
6✔
133
  }
134

135
  /**
136
   * @param args the arguments for {@link com.devonfw.tools.ide.tool.corepack.Corepack}.
137
   * @return the {@link ProcessResult}.
138
   */
139
  protected ProcessResult runCorepack(String... args) {
140

141
    return runCorepack(ProcessMode.DEFAULT, ProcessErrorHandling.THROW_CLI, args);
×
142
  }
143

144
  /**
145
   * @param processMode the {@link ProcessMode}.
146
   * @param errorHandling the {@link ProcessErrorHandling}.
147
   * @param args the arguments for the package manager.
148
   * @return the {@link ProcessResult}.
149
   */
150
  protected abstract ProcessResult runPackageManager(ProcessMode processMode, ProcessErrorHandling errorHandling, String... args);
151

152
  /**
153
   * @param processMode the {@link ProcessMode}.
154
   * @param errorHandling the {@link ProcessErrorHandling}.
155
   * @param args the arguments for {@link com.devonfw.tools.ide.tool.corepack.Corepack}.
156
   * @return the {@link ProcessResult}.
157
   */
158
  protected ProcessResult runCorepack(ProcessMode processMode, ProcessErrorHandling errorHandling, String... args) {
159
    ProcessContext pc = this.context.newProcess().errorHandling(errorHandling);
×
160
    Corepack corepack = this.context.getCommandletManager().getCommandlet(Corepack.class);
×
161
    return corepack.runTool(processMode, null, pc, args);
×
162
  }
163

164

165
  @Override
166
  public String getToolHelpArguments() {
167

168
    return "--help";
×
169
  }
170
}
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