Skip to content

Commit 227ab62

Browse files
vaadin-botplatosha
andauthored
fix(flow-build-tools): re-enable upgrading override versions (#24137) (CP: 25.1) (#24138)
This PR cherry-picks changes from the original PR #24137 to branch 25.1. --- #### Original PR description > Adjust user opt-out override detection for `package.json` without explicitly stored previous Vaadin overrides to still upgrade old override versions of Vaadin managed dependencies. > > Fixes the build issues for https://github.com/vaadin/patient-portal-demo-flow > Co-authored-by: Anton Platonov <anton@vaadin.com>
1 parent addf74b commit 227ab62

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

flow-build-tools/src/main/java/com/vaadin/flow/server/frontend/TaskUpdatePackages.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ boolean lockVersionForNpm(ObjectNode packageJson) throws IOException {
170170
}
171171
}
172172

173+
final ObjectNode overridesSection = getOverridesSection(packageJson);
174+
173175
// Flatten overrides to simplify diffing
174176
final Map<String, String> flatVaadinOverrides = flattenOverrides(
175177
vaadinOverrides);
@@ -181,7 +183,6 @@ boolean lockVersionForNpm(ObjectNode packageJson) throws IOException {
181183

182184
boolean versionLockingUpdated = false;
183185
// Update overrides based on diff between current and last overrides
184-
final ObjectNode overridesSection = getOverridesSection(packageJson);
185186
for (final Map.Entry<String, String> entryToUpdate : flatVaadinOverrides
186187
.entrySet()) {
187188
final String lastValue = flatLastVaadinOverrides
@@ -200,11 +201,22 @@ boolean lockVersionForNpm(ObjectNode packageJson) throws IOException {
200201
lastUserValue = JacksonUtils.getNestedKey(overridesSection,
201202
keyPath);
202203
}
203-
boolean optOut = !Objects.equals(StringNode.valueOf(lastValue),
204-
lastUserValue);
204+
boolean optOut;
205+
if (lastValue == null) {
206+
// Old-style package.json did not have Vaadin overrides.
207+
// We generally cannot detect opt-out except for one case:
208+
// prevent unpinning with relative version when the user has
209+
// existing non-relative override.
210+
optOut = lastUserValue != null
211+
&& entryToUpdate.getValue().startsWith("$")
212+
&& !lastUserValue.stringValue().startsWith("$");
213+
} else {
214+
// Detect opt-out: the actual override value is different from
215+
// last Vaadin override:
216+
optOut = !StringNode.valueOf(lastValue).equals(lastUserValue);
217+
}
205218
if (optOut) {
206-
// Actual override value is different from last Vaadin override:
207-
// assume user opt-out and skip.
219+
// Skip due to user opt-out using a custom override
208220
continue;
209221
}
210222
versionLockingUpdated = true;

flow-build-tools/src/test/java/com/vaadin/flow/server/frontend/NodeUpdatePackagesNpmVersionLockingTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class NodeUpdatePackagesNpmVersionLockingTest extends NodeUpdateTestUtil {
5656
private static final String OVERRIDES = "overrides";
5757
private static final String PLATFORM_PINNED_DEPENDENCY_VERSION = "3.2.17";
5858
private static final String USER_PINNED_DEPENDENCY_VERSION = "1.0";
59+
private static final String RELATIVE_DEPENDENCY_VERSION = "$@vaadin/vaadin-overlay";
5960

6061
@TempDir
6162
File temporaryFolder;
@@ -136,6 +137,27 @@ void shouldNotUpdatesOverrides_whenHasUserModification()
136137
packageJson.get(OVERRIDES).get(TEST_DEPENDENCY).stringValue());
137138
}
138139

140+
@Test
141+
void shouldUpdatesOverrides_whenNoVaadinOverrides_changingVersion()
142+
throws IOException {
143+
TaskUpdatePackages packageUpdater = createPackageUpdater(false,
144+
JacksonUtils.createObjectNode().put(TEST_DEPENDENCY,
145+
PLATFORM_PINNED_DEPENDENCY_VERSION));
146+
ObjectNode packageJson = packageUpdater.getPackageJson();
147+
ObjectNode overridesSection = JacksonUtils.createObjectNode();
148+
packageJson.set(OVERRIDES, overridesSection);
149+
150+
((ObjectNode) packageJson.get(DEPENDENCIES)).put(TEST_DEPENDENCY,
151+
USER_PINNED_DEPENDENCY_VERSION);
152+
overridesSection.put(TEST_DEPENDENCY, USER_PINNED_DEPENDENCY_VERSION);
153+
154+
packageUpdater.generateVersionsJson(packageJson);
155+
packageUpdater.lockVersionForNpm(packageJson);
156+
157+
assertEquals(PLATFORM_PINNED_DEPENDENCY_VERSION,
158+
packageJson.get(OVERRIDES).get(TEST_DEPENDENCY).stringValue());
159+
}
160+
139161
@Test
140162
void shouldRemoveUnusedLocking() throws IOException {
141163
// Test when there is no vaadin-version-core.json available

0 commit comments

Comments
 (0)