Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Release with new features and bugfixes:
* https://github.com/devonfw/IDEasy/issues/1602[#1602]: Being offline can block ide startup
* https://github.com/devonfw/IDEasy/issues/1667[#1667]: ide command without arguments triggers download and installation
* https://github.com/devonfw/IDEasy/issues/1677[#1677]: Add release for linux-arm architecture
* https://github.com/devonfw/IDEasy/issues/1679[#1679]: Npm based commandlets fail to determine installed version of npm tool

The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/39?closed=1[milestone 2026.01.001].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void run() {
}
for (int i = 0; i < valueCount; i++) {
ToolCommandlet toolCommandlet = this.tools.getValue(i);
if (toolCommandlet.getInstalledVersion() != null) {
if (toolCommandlet.isInstalled()) {
toolCommandlet.uninstall();
} else {
this.context.warning("Couldn't uninstall " + toolCommandlet.getName() + " because we could not find an installation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private VersionIdentifier runPackageManagerGetInstalledVersion(String npmPackage
this.context.trace("Since node is not installed, also package {} for tool {} cannot be installed.", npmPackage, this.tool);
return null;
}
PackageManagerRequest request = new PackageManagerRequest("list", npmPackage).addArg("-g").addArg(npmPackage).addArg("--depth=0")
PackageManagerRequest request = new PackageManagerRequest("list", npmPackage).addArg("list").addArg("-g").addArg(npmPackage).addArg("--depth=0")
.setProcessMode(ProcessMode.DEFAULT_CAPTURE);
ProcessResult result = runPackageManager(request);
if (result.isSuccessful()) {
Expand Down
37 changes: 28 additions & 9 deletions cli/src/test/java/com/devonfw/tools/ide/tool/yarn/YarnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.tool.node.Node;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;

Expand All @@ -25,15 +26,33 @@ void testYarnInstall(WireMockRuntimeInfo wireMockRuntimeInfo) {

// arrange
IdeTestContext context = newContext(PROJECT_YARN, wireMockRuntimeInfo);
Yarn commandlet = new Yarn(context);
Yarn yarn = context.getCommandletManager().getCommandlet(Yarn.class);

// act
commandlet.install();
yarn.install();

// assert
checkInstallation(context);
}

@Test
void testYarnInstallWhenNpmInstalled(WireMockRuntimeInfo wireMockRuntimeInfo) {

// arrange
IdeTestContext context = newContext(PROJECT_YARN, wireMockRuntimeInfo);
Node node = context.getCommandletManager().getCommandlet(Node.class);
Yarn yarn = context.getCommandletManager().getCommandlet(Yarn.class);

// act
node.install();
yarn.install();

// assert
assertThat(context).logAtDebug()
.hasMessageContaining("npm' using bash with arguments 'list' '-g' 'yarn' '--depth=0'"); // since npm was installed this should be called
checkInstallation(context);
}

/**
* Tests if the {@link Yarn} uninstall works correctly.
*
Expand All @@ -44,16 +63,16 @@ void testYarnUninstall(WireMockRuntimeInfo wireMockRuntimeInfo) {

// arrange
IdeTestContext context = newContext(PROJECT_YARN, wireMockRuntimeInfo);
Yarn commandlet = new Yarn(context);
Yarn yarn = context.getCommandletManager().getCommandlet(Yarn.class);

// act I
commandlet.install();
yarn.install();

// assert I
checkInstallation(context);

// act II
commandlet.uninstall();
yarn.uninstall();

// assert II
assertThat(context).logAtInfo().hasMessageContaining("npm uninstall -g yarn");
Expand All @@ -71,11 +90,11 @@ void testYarnRun(WireMockRuntimeInfo wireMockRuntimeInfo) {

// arrange
IdeTestContext context = newContext(PROJECT_YARN, wireMockRuntimeInfo);
Yarn commandlet = new Yarn(context);
commandlet.arguments.setValue("--version");
Yarn yarn = context.getCommandletManager().getCommandlet(Yarn.class);
yarn.arguments.setValue("--version");

// act
commandlet.run();
yarn.run();

// assert
assertThat(context).logAtInfo().hasMessageContaining("yarn --version");
Expand All @@ -84,7 +103,7 @@ void testYarnRun(WireMockRuntimeInfo wireMockRuntimeInfo) {

private void checkInstallation(IdeTestContext context) {

assertThat(context).logAtInfo().hasMessageContaining("npm install -gf yarn@2.4.3");
assertThat(context).logAtInfo().hasMessage("npm install -gf yarn@2.4.3");
assertThat(context).logAtSuccess().hasMessageContaining("Setting npm config prefix to: " + context.getSoftwarePath().resolve("node") + " was successful");
assertThat(context).logAtSuccess().hasMessageContaining("Successfully installed yarn in version 2.4.3");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash
if [ "${1}" == "--version" ]; then
if [ "$1" = "--version" ]; then
echo "9.9.2"
exit
elif [ "$1" = "list" ] && [ "$2" = "-g" ]; then
echo $IDE_HOME/software/node
echo "-- $3@9.9.2"
exit
fi
echo "npm $*"
if [ "$1" == "install" ]; then
Expand Down