From 1e628a1f215fd5ba679a82a8d02c462486159c07 Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Fri, 14 Mar 2025 11:04:50 +0100 Subject: [PATCH 1/2] fix: try online install after ERESOLVE (#2448) --- .../com/diffplug/spotless/npm/NodeApp.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java index 932a148626..19eb584c57 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java @@ -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. @@ -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 @", 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"); } } From b6bf416dda59d7db56c2074caf5fd85d5808eaba Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Fri, 14 Mar 2025 11:08:03 +0100 Subject: [PATCH 2/2] docs: document ERESOLVE fix --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9c7f3e0d39..7d16300cce 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 59b829359f..b40b63b4c8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -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 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index addbe10424..483258c36a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -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))