From 1a033ff4d6eec07bd52097d4b23b947efaf4a0c3 Mon Sep 17 00:00:00 2001 From: Vaadin Bot Date: Tue, 14 Sep 2021 18:58:20 +0300 Subject: [PATCH] fix: Only write package.json if something actually changed (#11848) (#11851) Flag update of vaadin version as an addition also and only write the package.json if thee was an actual change in content. Fixes #11259 Co-authored-by: caalador --- .../java/com/vaadin/flow/server/frontend/NodeUpdater.java | 4 ++++ .../vaadin/flow/server/frontend/TaskCreatePackageJson.java | 4 +++- .../flow/server/frontend/AbstractNodeUpdatePackagesTest.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeUpdater.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeUpdater.java index 0f95e48ecd0..52d51225759 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeUpdater.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeUpdater.java @@ -385,6 +385,10 @@ private int handleExistingVaadinDep(JsonObject json, String pkg, if (added) { log().debug("Added \"{}\": \"{}\" line.", pkg, version); + } else { + // we made a change to the package json vaadin defaults + // even if we didn't add to the dependencies. + added = !vaadinVersion.isEqualTo(newVersion); } return added ? 1 : 0; } diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCreatePackageJson.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCreatePackageJson.java index 1c434ccc5a6..6044145ddb5 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCreatePackageJson.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCreatePackageJson.java @@ -48,7 +48,9 @@ public void execute() { modified = false; JsonObject mainContent = getPackageJson(); modified = updateDefaultDependencies(mainContent); - writePackageFile(mainContent); + if(modified) { + writePackageFile(mainContent); + } } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/AbstractNodeUpdatePackagesTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/AbstractNodeUpdatePackagesTest.java index 75691b7e93a..a5adc1c4c2d 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/AbstractNodeUpdatePackagesTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/AbstractNodeUpdatePackagesTest.java @@ -293,7 +293,7 @@ public void oldVaadinDevDependency_missmatchWithDevDependency_vaadinDependencyIs final String version = packageUpdater.getDefaultDevDependencies() .get(key); json.getObject(VAADIN_DEP_KEY).getObject(DEV_DEPENDENCIES) - .put(key, "4.42.0"); + .put(key, "3.42.0"); json.getObject(DEV_DEPENDENCIES).put(key, version); Files.write(packageJson.toPath(),