Skip to content

Respect runtime version written in package json #2594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ export const ItunesConnectApplicationTypes = new ItunesConnectApplicationTypesCl
export const ANGULAR_NAME = "angular";
export const TYPESCRIPT_NAME = "typescript";
export const BUILD_OUTPUT_EVENT_NAME = "buildOutput";
export const VERSION_STRING = "version";
4 changes: 4 additions & 0 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}

let platformData = this.$platformsData.getPlatformData(platform, projectData);
let currentPlatformData: any = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.$projectDataService.getNSValue can return null can you add check if it is null before you try to access currentPlatformData[constants.VERSION_STRING]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check on the line below, nice catch 🎣

if (currentPlatformData && currentPlatformData[constants.VERSION_STRING]) {
version = currentPlatformData[constants.VERSION_STRING];
}

// Copy platform specific files in platforms dir
let platformProjectService = platformData.platformProjectService;
Expand Down
42 changes: 41 additions & 1 deletion test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as yok from "../lib/common/yok";
import * as stubs from "./stubs";
import * as PlatformServiceLib from "../lib/services/platform-service";
import * as StaticConfigLib from "../lib/config";
import { VERSION_STRING } from "../lib/constants";
import * as fsLib from "../lib/common/file-system";
import * as optionsLib from "../lib/options";
import * as hostInfoLib from "../lib/common/host-info";
Expand Down Expand Up @@ -129,6 +130,45 @@ describe('Platform Service Tests', () => {
assert.equal(errorMessage, err.message);
}
});
it("should respect platform version in package.json's nativescript key", async () => {
const versionString = "2.5.0";
let fs = testInjector.resolve("fs");
fs.exists = () => false;

let nsValueObject: any = {};
nsValueObject[VERSION_STRING] = versionString;
let projectDataService = testInjector.resolve("projectDataService");
projectDataService.getNSValue = () => nsValueObject;

let npmInstallationManager = testInjector.resolve("npmInstallationManager");
npmInstallationManager.install = (packageName: string, packageDir: string, options: INpmInstallOptions) => {
assert.deepEqual(options.version, versionString);
return "";
};

let projectData: IProjectData = testInjector.resolve("projectData");

await platformService.addPlatforms(["android"], "", projectData, null);
await platformService.addPlatforms(["ios"], "", projectData, null);
});
it("should install latest platform if no information found in package.json's nativescript key", async () => {
let fs = testInjector.resolve("fs");
fs.exists = () => false;

let projectDataService = testInjector.resolve("projectDataService");
projectDataService.getNSValue = (): any => null;

let npmInstallationManager = testInjector.resolve("npmInstallationManager");
npmInstallationManager.install = (packageName: string, packageDir: string, options: INpmInstallOptions) => {
assert.deepEqual(options.version, undefined);
return "";
};

let projectData: IProjectData = testInjector.resolve("projectData");

await platformService.addPlatforms(["android"], "", projectData, null);
await platformService.addPlatforms(["ios"], "", projectData, null);
});
});
describe("#add platform(ios)", () => {
it("should call validate method", async () => {
Expand Down Expand Up @@ -173,7 +213,7 @@ describe('Platform Service Tests', () => {
});

describe("remove platform unit tests", () => {
it("should fail when platforms are not added", async () => {
it("should fail when platforms are not added", async () => {
const ExpectedErrorsCaught = 2;
let errorsCaught = 0;
let projectData: IProjectData = testInjector.resolve("projectData");
Expand Down