Skip to content

Commit

Permalink
Fix getting shrinkwrap version (#6433)
Browse files Browse the repository at this point in the history
Fix getting shrinkwrap version from
package-lock.json

fixes #6151
  • Loading branch information
caalador authored and Denis committed Sep 11, 2019
1 parent e84bf89 commit 98d877a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class NodeUpdater implements FallibleCommand {
private static final String DEP_LICENSE_DEFAULT = "UNLICENSED";
private static final String DEP_NAME_KEY = "name";
private static final String DEP_NAME_DEFAULT = "no-name";
private static final String DEP_NAME_FLOW_DEPS = "@vaadin/flow-deps";
protected static final String DEP_NAME_FLOW_DEPS = "@vaadin/flow-deps";
private static final String DEP_VERSION_KEY = "version";
private static final String DEP_VERSION_DEFAULT = "1.0.0";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
public class TaskUpdatePackages extends NodeUpdater {

static final String APP_PACKAGE_HASH = "vaadinAppPackageHash";
private static final String VALUE = "value";
private static final String VERSION = "version";
private static final String SHRINK_WRAP = "@vaadin/vaadin-shrinkwrap";
private boolean forceCleanUp;

Expand Down Expand Up @@ -207,8 +207,7 @@ private String getCurrentShrinkWrapVersion() throws IOException {
return shrinkWrapVersion;
}

File atVaadin = new File(nodeModulesFolder, "@vaadin");
File flowDeps = new File(atVaadin, "flow-deps");
File flowDeps = new File(nodeModulesFolder, DEP_NAME_FLOW_DEPS);
shrinkWrapVersion = getShrinkWrapVersion(
getPackageJson(new File(flowDeps, Constants.PACKAGE_JSON)));
if (shrinkWrapVersion != null) {
Expand Down Expand Up @@ -237,8 +236,8 @@ private String getPackageLockShrinkWrapVersion() throws IOException {
}

JsonObject shrinkWrap = dependencies.getObject(SHRINK_WRAP);
if (shrinkWrap.hasKey(VALUE)) {
return shrinkWrap.get(VALUE).asString();
if (shrinkWrap.hasKey(VERSION)) {
return shrinkWrap.get(VERSION).asString();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,64 @@ public void versions_doNotMatch_inPackageLock_cleanUp() throws IOException {

assertVersionAndCleanUp();
}
@Test
public void versionsDoNotMatch_inMainJson_cleanUp() throws IOException {
FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);

Map<String, String> packages = new HashMap<>();
packages.put("@polymer/iron-list", "3.0.2");
packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
packages.put("@vaadin/vaadin-checkbox", "2.2.10");
packages.put("@polymer/iron-icon", "3.0.1");
packages.put("@vaadin/vaadin-time-picker", "2.0.2");
packages.put(SHRINKWRAP, "1.2.3");

Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);

packageUpdater = new TaskUpdatePackages(null, frontendDependencies, baseDir,
generatedDir, false);

// Generate package json in a proper format first
packageCreator.execute();

makeNodeModulesAndPackageLock();

JsonObject packageJson = getPackageJson(mainPackageJson);
packageJson.put(SHRINKWRAP, "1.1.1");
Files.write(packageLock.toPath(),
Collections.singletonList(stringify(
packageJson)));

packageUpdater.execute();

assertVersionAndCleanUp();
}

@Test
public void versionsMatch_noCleanUp() throws IOException {
FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);

Map<String, String> packages = new HashMap<>();
packages.put("@polymer/iron-list", "3.0.2");
packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
packages.put("@vaadin/vaadin-checkbox", "2.2.10");
packages.put("@polymer/iron-icon", "3.0.1");
packages.put("@vaadin/vaadin-time-picker", "2.0.2");
packages.put(SHRINKWRAP, "1.1.1");

Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);

packageUpdater = new TaskUpdatePackages(null, frontendDependencies, baseDir,
generatedDir, false);

// Generate package json in a proper format first
packageCreator.execute();
packageUpdater.execute();

makeNodeModulesAndPackageLock();

// run it again with existing generated package.json and matched
// version
Files.write(packageLock.toPath(),
Collections.singletonList(stringify(makePackageLock("1.1.1"))));

packageUpdater.execute();

// nothing is removed
Expand Down

0 comments on commit 98d877a

Please sign in to comment.