|
1 | 1 | /*
|
2 |
| - * Copyright 2023 DiffPlug |
| 2 | + * Copyright 2023-2025 DiffPlug |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -98,18 +98,28 @@ private void optimizedNpmInstall() {
|
98 | 98 | if (!offlineInstallFailed(e.getResult())) {
|
99 | 99 | throw e; // pass through
|
100 | 100 | }
|
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 |
102 | 102 | npmProcessFactory.createNpmInstallProcess(nodeServerLayout, formatterStepLocations, PREFER_ONLINE).waitFor();
|
103 | 103 | }
|
104 | 104 | }
|
105 | 105 |
|
106 |
| - private boolean offlineInstallFailed(ProcessRunner.Result result) { |
| 106 | + private static boolean offlineInstallFailed(ProcessRunner.Result result) { |
107 | 107 | if (result == null) {
|
108 | 108 | return false; // no result, something else must have happened
|
109 | 109 | }
|
110 | 110 | if (result.exitCode() == 0) {
|
111 | 111 | return false; // all is well
|
112 | 112 | }
|
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"); |
114 | 124 | }
|
115 | 125 | }
|
0 commit comments