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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Changed
* Use palantir-java-format 2.57.0 on Java 21. ([#2447](https://github.com/diffplug/spotless/pull/2447))
* Re-try `npm install` with `--prefer-online` after `ERESOLVE` error. ([#2448](https://github.com/diffplug/spotless/pull/2448))

## [3.1.0] - 2025-02-20
### Added
Expand Down
18 changes: 14 additions & 4 deletions lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 DiffPlug
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -98,18 +98,28 @@ private void optimizedNpmInstall() {
if (!offlineInstallFailed(e.getResult())) {
throw e; // pass through
}
// if the npm install fails with message "No matching version found for <package>@<version>", we try again without the offline flag
// if the npm install fails in a way that might be caused by missing dependency information, we try again without the offline flag
npmProcessFactory.createNpmInstallProcess(nodeServerLayout, formatterStepLocations, PREFER_ONLINE).waitFor();
}
}

private boolean offlineInstallFailed(ProcessRunner.Result result) {
private static boolean offlineInstallFailed(ProcessRunner.Result result) {
if (result == null) {
return false; // no result, something else must have happened
}
if (result.exitCode() == 0) {
return false; // all is well
}
return result.stdOutUtf8().contains("code ETARGET") && result.stdOutUtf8().contains("No matching version found for"); // offline install failed, needs online install
var installOutput = result.stdOutUtf8();
// offline install failed, needs online install
return isNoMatchingVersionFound(installOutput) || isCannotResolveDependencyTree(installOutput);
}

private static boolean isNoMatchingVersionFound(String installOutput) {
return installOutput.contains("code ETARGET") && installOutput.contains("No matching version found for");
}

private static boolean isCannotResolveDependencyTree(String installOutput) {
return installOutput.contains("code ERESOLVE") && installOutput.contains("unable to resolve dependency tree");
}
}
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Changed
* Use palantir-java-format 2.57.0 on Java 21. ([#2447](https://github.com/diffplug/spotless/pull/2447))
* Re-try `npm install` with `--prefer-online` after `ERESOLVE` error. ([#2448](https://github.com/diffplug/spotless/pull/2448))

## [7.0.2] - 2025-01-14
### Fixed
Expand Down
1 change: 1 addition & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Changed
* Use palantir-java-format 2.57.0 on Java 21. ([#2447](https://github.com/diffplug/spotless/pull/2447))
* Re-try `npm install` with `--prefer-online` after `ERESOLVE` error. ([#2448](https://github.com/diffplug/spotless/pull/2448))

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