Skip to content

Commit aa1ab49

Browse files
Install latest available version if no matching version is found
In case CLI is version 1.4.x, on platform add we are trying to install latest available 1.4.x runtime. In case there's no 1.4.x version, the code fails. Instead we should install latest availabe version in this case.
1 parent 33e09a0 commit aa1ab49

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/npm-installation-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
8484
.sortBy(verData => verData.patch)
8585
.value();
8686

87-
let result = _.last(compatibleVersions);
87+
let result = _.last(compatibleVersions) || this.getVersionData(latestVersion);
8888

8989
let latestCompatibleVersion = `${result.major}.${result.minor}.${result.patch}`;
9090
return latestCompatibleVersion;

test/npm-installation-manager.ts

+20
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe("Npm installation manager tests", () => {
7272
let expectedLatestCompatibleVersion = "1.4.0";
7373
assert.equal(actualLatestCompatibleVersion, expectedLatestCompatibleVersion);
7474
});
75+
7576
it("returns correct latest compatible version", () => {
7677
let testInjector = createTestInjector();
7778

@@ -92,4 +93,23 @@ describe("Npm installation manager tests", () => {
9293
let expectedLatestCompatibleVersion = "1.3.3";
9394
assert.equal(actualLatestCompatibleVersion, expectedLatestCompatibleVersion);
9495
});
96+
97+
it("returns correct latest compatible version", () => {
98+
let testInjector = createTestInjector();
99+
100+
let versions = ["1.2.0", "1.3.0", "1.3.1", "1.3.2", "1.3.3", "1.4.0"];
101+
let latestVersion = _.last(versions);
102+
mockNpm(testInjector, versions, latestVersion);
103+
104+
// Mock staticConfig.version
105+
let staticConfig = testInjector.resolve("staticConfig");
106+
staticConfig.version = "1.5.0";
107+
108+
// Mock npmInstallationManager.getLatestVersion
109+
let npmInstallationManager = testInjector.resolve("npmInstallationManager");
110+
npmInstallationManager.getLatestVersion = (packageName: string) => Future.fromResult(latestVersion);
111+
112+
let actualLatestCompatibleVersion = npmInstallationManager.getLatestCompatibleVersion("").wait();
113+
assert.equal(actualLatestCompatibleVersion, latestVersion);
114+
});
95115
});

0 commit comments

Comments
 (0)