Skip to content

Commit

Permalink
fix: pinned dependency only adds when modified (#11893)
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
  • Loading branch information
caalador authored Sep 21, 2021
1 parent 63fed9c commit 6b28d46
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,18 @@ 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;
assert vaadinDeps != null : "vaadin{ dependencies { } } should exist"; // exists at this point
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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,33 @@ public void npmIsInUse_versionsJsonHasVaadinCoreVersionPinned_vaadinCoreVersionI
vaadinDependencies.hasKey(VAADIN_CORE_NPM_PACKAGE));
}

// #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 6b28d46

Please sign in to comment.