Skip to content

Commit 557d983

Browse files
authored
fix: try online install after ERESOLVE (#2449 fixes #2448)
2 parents 43fe591 + b6bf416 commit 557d983

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Changed
1414
* Use palantir-java-format 2.57.0 on Java 21. ([#2447](https://github.com/diffplug/spotless/pull/2447))
15+
* Re-try `npm install` with `--prefer-online` after `ERESOLVE` error. ([#2448](https://github.com/diffplug/spotless/pull/2448))
1516

1617
## [3.1.0] - 2025-02-20
1718
### Added

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
}

plugin-gradle/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
55
## [Unreleased]
66
### Changed
77
* Use palantir-java-format 2.57.0 on Java 21. ([#2447](https://github.com/diffplug/spotless/pull/2447))
8+
* Re-try `npm install` with `--prefer-online` after `ERESOLVE` error. ([#2448](https://github.com/diffplug/spotless/pull/2448))
89

910
## [7.0.2] - 2025-01-14
1011
### Fixed

plugin-maven/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
55
## [Unreleased]
66
### Changed
77
* Use palantir-java-format 2.57.0 on Java 21. ([#2447](https://github.com/diffplug/spotless/pull/2447))
8+
* Re-try `npm install` with `--prefer-online` after `ERESOLVE` error. ([#2448](https://github.com/diffplug/spotless/pull/2448))
89

910
## [2.44.3] - 2025-02-20
1011
* Support for `clang-format` ([#2406](https://github.com/diffplug/spotless/pull/2406))

0 commit comments

Comments
 (0)