Skip to content

Commit b3795dc

Browse files
Respect runtime version written in package json (#2594)
* Respect runtime version written in package json Instead of always installing the latest runtime version, respect the one written in `package.json` `nativescript` key. * Add tests
1 parent e80d3d0 commit b3795dc

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ export const ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesCl
6868
export const ANGULAR_NAME = "angular";
6969
export const TYPESCRIPT_NAME = "typescript";
7070
export const BUILD_OUTPUT_EVENT_NAME = "buildOutput";
71+
export const VERSION_STRING = "version";

lib/services/platform-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
6767
}
6868

6969
let platformData = this.$platformsData.getPlatformData(platform, projectData);
70+
let currentPlatformData: any = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
71+
if (currentPlatformData && currentPlatformData[constants.VERSION_STRING]) {
72+
version = currentPlatformData[constants.VERSION_STRING];
73+
}
7074

7175
// Copy platform specific files in platforms dir
7276
let platformProjectService = platformData.platformProjectService;

test/platform-service.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as yok from "../lib/common/yok";
22
import * as stubs from "./stubs";
33
import * as PlatformServiceLib from "../lib/services/platform-service";
44
import * as StaticConfigLib from "../lib/config";
5+
import { VERSION_STRING } from "../lib/constants";
56
import * as fsLib from "../lib/common/file-system";
67
import * as optionsLib from "../lib/options";
78
import * as hostInfoLib from "../lib/common/host-info";
@@ -129,6 +130,45 @@ describe('Platform Service Tests', () => {
129130
assert.equal(errorMessage, err.message);
130131
}
131132
});
133+
it("should respect platform version in package.json's nativescript key", async () => {
134+
const versionString = "2.5.0";
135+
let fs = testInjector.resolve("fs");
136+
fs.exists = () => false;
137+
138+
let nsValueObject: any = {};
139+
nsValueObject[VERSION_STRING] = versionString;
140+
let projectDataService = testInjector.resolve("projectDataService");
141+
projectDataService.getNSValue = () => nsValueObject;
142+
143+
let npmInstallationManager = testInjector.resolve("npmInstallationManager");
144+
npmInstallationManager.install = (packageName: string, packageDir: string, options: INpmInstallOptions) => {
145+
assert.deepEqual(options.version, versionString);
146+
return "";
147+
};
148+
149+
let projectData: IProjectData = testInjector.resolve("projectData");
150+
151+
await platformService.addPlatforms(["android"], "", projectData, null);
152+
await platformService.addPlatforms(["ios"], "", projectData, null);
153+
});
154+
it("should install latest platform if no information found in package.json's nativescript key", async () => {
155+
let fs = testInjector.resolve("fs");
156+
fs.exists = () => false;
157+
158+
let projectDataService = testInjector.resolve("projectDataService");
159+
projectDataService.getNSValue = (): any => null;
160+
161+
let npmInstallationManager = testInjector.resolve("npmInstallationManager");
162+
npmInstallationManager.install = (packageName: string, packageDir: string, options: INpmInstallOptions) => {
163+
assert.deepEqual(options.version, undefined);
164+
return "";
165+
};
166+
167+
let projectData: IProjectData = testInjector.resolve("projectData");
168+
169+
await platformService.addPlatforms(["android"], "", projectData, null);
170+
await platformService.addPlatforms(["ios"], "", projectData, null);
171+
});
132172
});
133173
describe("#add platform(ios)", () => {
134174
it("should call validate method", async () => {
@@ -173,7 +213,7 @@ describe('Platform Service Tests', () => {
173213
});
174214

175215
describe("remove platform unit tests", () => {
176-
it("should fail when platforms are not added", async () => {
216+
it("should fail when platforms are not added", async () => {
177217
const ExpectedErrorsCaught = 2;
178218
let errorsCaught = 0;
179219
let projectData: IProjectData = testInjector.resolve("projectData");

0 commit comments

Comments
 (0)