Skip to content

fix: Platform add hangs when invalid frameworkPath is passed #3737

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 1 commit into from
Jul 10, 2018
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
4 changes: 4 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,7 @@ export class Hooks {
}

export const PACKAGE_PLACEHOLDER_NAME = "__PACKAGE__";

export class AddPlaformErrors {
public static InvalidFrameworkPathStringFormat = "Invalid frameworkPath: %s. Please ensure the specified frameworkPath exists.";
}
5 changes: 5 additions & 0 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as constants from "../constants";
import { Configurations } from "../common/constants";
import * as helpers from "../common/helpers";
import * as semver from "semver";
import { format } from "util";
import { EventEmitter } from "events";
import { AppFilesUpdater } from "./app-files-updater";
import { attachAwaitDetach } from "../common/helpers";
Expand Down Expand Up @@ -104,6 +105,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
let packageToInstall = "";
if (frameworkPath) {
packageToInstall = path.resolve(frameworkPath);
if (!this.$fs.exists(packageToInstall)) {
const errorMessage = format(constants.AddPlaformErrors.InvalidFrameworkPathStringFormat, frameworkPath);
this.$errors.fail(errorMessage);
}
} else {
if (!version) {
version = this.getCurrentPlatformVersion(platform, projectData) ||
Expand Down
13 changes: 12 additions & 1 deletion test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ 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, PACKAGE_JSON_FILE_NAME } from "../lib/constants";
import { VERSION_STRING, PACKAGE_JSON_FILE_NAME, AddPlaformErrors } 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";
import * as ProjectFilesManagerLib from "../lib/common/services/project-files-manager";
import * as path from "path";
import { format } from "util";
import { assert } from "chai";
import { DeviceAppDataFactory } from "../lib/common/mobile/device-app-data/device-app-data-factory";
import { LocalToDevicePathDataFactory } from "../lib/common/mobile/local-to-device-path-data-factory";
Expand Down Expand Up @@ -232,6 +233,16 @@ describe('Platform Service Tests', () => {
await assert.isRejected(platformService.addPlatforms(["android"], "", projectData, config), errorMessage);
});

it("fails when path passed to frameworkPath does not exist", async () => {
const fs = testInjector.resolve("fs");
fs.exists = () => false;

const projectData: IProjectData = testInjector.resolve("projectData");
const frameworkPath = "invalidPath";
const errorMessage = format(AddPlaformErrors.InvalidFrameworkPathStringFormat, frameworkPath);
await assert.isRejected(platformService.addPlatforms(["android"], "", projectData, config, frameworkPath), errorMessage);
});

const assertCorrectDataIsPassedToPacoteService = async (versionString: string): Promise<void> => {
const fs = testInjector.resolve("fs");
fs.exists = () => false;
Expand Down