Skip to content

Commit

Permalink
fix: pinned dependency only adds when modified (#11894) (#11899)
Browse files Browse the repository at this point in the history
Do not mark pin if no version is actually
added or changed.
With this npm install will not always be
executed on reload and the copied
modules will not disappear.

Fixes #11888

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
  • Loading branch information
vaadin-bot and caalador committed Sep 21, 2021
1 parent 2e0e72d commit 8934075
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,19 @@ private boolean pinPlatformDependency(JsonObject packageJson,
final JsonObject vaadinDeps = packageJson.getObject(VAADIN_DEP_KEY)
.getObject(DEPENDENCIES);
final JsonObject packageJsonDeps = packageJson.getObject(DEPENDENCIES);
assert vaadinDeps != null; // exists at this point
assert packageJsonDeps != null;
packageJsonDeps.put(pkg, platformPinnedVersion.getFullVersion());
vaadinDeps.put(pkg, platformPinnedVersion.getFullVersion());
return true;
// packages exist at this point
assert vaadinDeps != null : "vaadin{ dependencies { } } should exist";
assert packageJsonDeps != null : "dependencies { } should exist";
if (!packageJsonDeps.hasKey(pkg) || !vaadinDeps.hasKey(pkg)
|| !platformPinnedVersion.equals(
new FrontendVersion(packageJsonDeps.getString(pkg)))
|| !platformPinnedVersion.equals(
new FrontendVersion(vaadinDeps.getString(pkg)))) {
packageJsonDeps.put(pkg, platformPinnedVersion.getFullVersion());
vaadinDeps.put(pkg, platformPinnedVersion.getFullVersion());
return true;
}
return false;
}

private int updateFlowFrontendDependencies(JsonObject dependenciesObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,34 @@ private boolean isSorted(String[] array) {
return true;
}

// #11888
@Test
public void npmIsInUse_versionsJsonContainsSameVersions_nothingIsModified()
throws IOException {
String versionJsonString = //@formatter:off
"{ \"core\": {"
+ "\"vaadin-element-mixin\": {\n"
+ " \"jsVersion\": \"" + PLATFORM_DIALOG_VERSION + "\",\n"
+ " \"npmName\": \"" + VAADIN_DIALOG
+ "\"\n"
+ "},\n"
+ "}}},\n";//@formatter:on
FileUtils.write(versionJsonFile, versionJsonString,
StandardCharsets.UTF_8);

TaskUpdatePackages task = createTask(createApplicationDependencies());
task.execute();
Assert.assertTrue(
"Creation of package.json should be marked with modified",
task.modified);

// Rewriting with the same packages should not mark as modified
task = createTask(createApplicationDependencies());
task.execute();
Assert.assertFalse("PackageJson modified without changes.",
task.modified);
}

private void createBasicVaadinVersionsJson() {
createVaadinVersionsJson(PLATFORM_DIALOG_VERSION,
PLATFORM_ELEMENT_MIXIN_VERSION, PLATFORM_OVERLAY_VERSION);
Expand Down

0 comments on commit 8934075

Please sign in to comment.