Skip to content

Commit 1e628a1

Browse files
committed
fix: try online install after ERESOLVE (#2448)
1 parent f6da1c4 commit 1e628a1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 DiffPlug
2+
* Copyright 2023-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,18 +98,28 @@ private void optimizedNpmInstall() {
9898
if (!offlineInstallFailed(e.getResult())) {
9999
throw e; // pass through
100100
}
101-
// if the npm install fails with message "No matching version found for <package>@<version>", we try again without the offline flag
101+
// if the npm install fails in a way that might be caused by missing dependency information, we try again without the offline flag
102102
npmProcessFactory.createNpmInstallProcess(nodeServerLayout, formatterStepLocations, PREFER_ONLINE).waitFor();
103103
}
104104
}
105105

106-
private boolean offlineInstallFailed(ProcessRunner.Result result) {
106+
private static boolean offlineInstallFailed(ProcessRunner.Result result) {
107107
if (result == null) {
108108
return false; // no result, something else must have happened
109109
}
110110
if (result.exitCode() == 0) {
111111
return false; // all is well
112112
}
113-
return result.stdOutUtf8().contains("code ETARGET") && result.stdOutUtf8().contains("No matching version found for"); // offline install failed, needs online install
113+
var installOutput = result.stdOutUtf8();
114+
// offline install failed, needs online install
115+
return isNoMatchingVersionFound(installOutput) || isCannotResolveDependencyTree(installOutput);
116+
}
117+
118+
private static boolean isNoMatchingVersionFound(String installOutput) {
119+
return installOutput.contains("code ETARGET") && installOutput.contains("No matching version found for");
120+
}
121+
122+
private static boolean isCannotResolveDependencyTree(String installOutput) {
123+
return installOutput.contains("code ERESOLVE") && installOutput.contains("unable to resolve dependency tree");
114124
}
115125
}

0 commit comments

Comments
 (0)