From c08335af23e2c3e8e7d2da59b91fa69c3f749c0f Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Tue, 14 Sep 2021 14:11:31 +0300 Subject: [PATCH] fix: Only write package.json if something actually changed 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 --- .../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 12908ed12dd..d17b16ed10b 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 @@ -420,6 +420,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 2328318e709..b85fb341fe2 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 @@ -292,7 +292,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(),