Skip to content

fix: do not reject platform update on different pbxproj files as they are always different #5048

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
Oct 4, 2019
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: 0 additions & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ interface IDeployPlatformOptions extends IAndroidReleaseOptions, IRelease, IClea
interface IUpdatePlatformOptions {
currentVersion: string;
newVersion: string;
canUpdate: boolean;
}

interface IInfoService {
Expand Down
21 changes: 8 additions & 13 deletions lib/helpers/platform-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,16 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
const cachedPackageData = this.$fs.readJson(path.join(installedModuleDir, "package.json"));
newVersion = (cachedPackageData && cachedPackageData.version) || newVersion;

const canUpdate = platformData.platformProjectService.canUpdatePlatform(installedModuleDir, projectData);
if (canUpdate) {
if (!semver.valid(newVersion)) {
this.$errors.fail("The version %s is not valid. The version should consists from 3 parts separated by dot.", newVersion);
}
if (!semver.valid(newVersion)) {
this.$errors.fail("The version %s is not valid. The version should consists from 3 parts separated by dot.", newVersion);
}

if (!semver.gt(currentVersion, newVersion)) {
await this.updatePlatformCore(platformData, { currentVersion, newVersion, canUpdate }, projectData);
} else if (semver.eq(currentVersion, newVersion)) {
this.$errors.fail("Current and new version are the same.");
} else {
this.$errors.fail(`Your current version: ${currentVersion} is higher than the one you're trying to install ${newVersion}.`);
}
if (!semver.gt(currentVersion, newVersion)) {
await this.updatePlatformCore(platformData, { currentVersion, newVersion }, projectData);
} else if (semver.eq(currentVersion, newVersion)) {
this.$errors.fail("Current and new version are the same.");
} else {
this.$errors.fail("Native Platform cannot be updated.");
this.$errors.fail(`Your current version: ${currentVersion} is higher than the one you're trying to install ${newVersion}.`);
}
}

Expand Down
6 changes: 1 addition & 5 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}

this.$fs.ensureDirectoryExists(this.getPlatformData(projectData).projectRoot);
const androidToolsInfo = this.$androidToolsInfo.getToolsInfo({ projectDir: projectData.projectDir});
const androidToolsInfo = this.$androidToolsInfo.getToolsInfo({ projectDir: projectData.projectDir });
const targetSdkVersion = androidToolsInfo && androidToolsInfo.targetSdkVersion;
this.$logger.trace(`Using Android SDK '${targetSdkVersion}'.`);

Expand Down Expand Up @@ -217,10 +217,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
return null;
}

public canUpdatePlatform(newInstalledModuleDir: string, projectData: IProjectData): boolean {
return true;
}

public async updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean, projectData: IProjectData, addPlatform?: Function, removePlatforms?: (platforms: string[]) => Promise<void>): Promise<boolean> {
if (semver.eq(newVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
const platformLowercase = this.getPlatformData(projectData).normalizedPlatformName.toLowerCase();
Expand Down
29 changes: 2 additions & 27 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
const frameworkBinaryPath = path.join(bundlePath, frameworkName);

const fileResult = (await this.$childProcess.spawnFromEvent("file", [frameworkBinaryPath], "close")).stdout;
const isDynamicallyLinked = _.includes(fileResult, "dynamically linked");
const isDynamicallyLinked = _.includes(fileResult, "dynamically linked");
return isDynamicallyLinked;
};

Expand Down Expand Up @@ -289,23 +289,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
this.savePbxProj(project, projectData);
}

public canUpdatePlatform(installedModuleDir: string, projectData: IProjectData): boolean {
const currentXcodeProjectFile = this.buildPathToCurrentXcodeProjectFile(projectData);
const currentXcodeProjectFileContent = this.$fs.readFile(currentXcodeProjectFile);

const newXcodeProjectFile = this.buildPathToNewXcodeProjectFile(installedModuleDir);
this.replaceFileContent(newXcodeProjectFile, projectData);
const newXcodeProjectFileContent = this.$fs.readFile(newXcodeProjectFile);

const contentIsTheSame = currentXcodeProjectFileContent.toString() === newXcodeProjectFileContent.toString();

if (!contentIsTheSame) {
this.$logger.warn(`The content of the current project file: ${currentXcodeProjectFile} and the new project file: ${newXcodeProjectFile} is different.`);
}

return contentIsTheSame;
}

public async prepareProject(projectData: IProjectData, prepareData: IOSPrepareData): Promise<void> {
const projectRoot = path.join(projectData.platformsDir, "ios");
const platformData = this.getPlatformData(projectData);
Expand Down Expand Up @@ -620,18 +603,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
private getAllLibsForPluginWithFileExtension(pluginData: IPluginData, fileExtension: string | string[]): string[] {
const fileExtensions = _.isArray(fileExtension) ? fileExtension : [fileExtension];
const filterCallback = (fileName: string, pluginPlatformsFolderPath: string) =>
fileExtensions.indexOf(path.extname(fileName)) !== -1;
fileExtensions.indexOf(path.extname(fileName)) !== -1;
return this.getAllNativeLibrariesForPlugin(pluginData, IOSProjectService.IOS_PLATFORM_NAME, filterCallback);
}

private buildPathToCurrentXcodeProjectFile(projectData: IProjectData): string {
return path.join(projectData.platformsDir, "ios", `${projectData.projectName}.xcodeproj`, "project.pbxproj");
}

private buildPathToNewXcodeProjectFile(newModulesDir: string): string {
return path.join(newModulesDir, constants.PROJECT_FRAMEWORK_FOLDER_NAME, `${IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER}.xcodeproj`, "project.pbxproj");
}

private validateFramework(libraryPath: string): void {
const infoPlistPath = path.join(libraryPath, constants.INFO_PLIST_FILE_NAME);
if (!this.$fs.exists(infoPlistPath)) {
Expand Down
8 changes: 0 additions & 8 deletions lib/services/webpack/webpack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ declare global {
*/
isPlatformPrepared(projectRoot: string, projectData: IProjectData): boolean;

/**
* Checks if current platform can be updated to a newer versions.
* @param {string} newInstalledModuleDir Path to the native project.
* @param {IProjectData} projectData DTO with information about the project.
* @return {boolean} True if platform can be updated. false otherwise.
*/
canUpdatePlatform(newInstalledModuleDir: string, projectData: IProjectData): boolean;

preparePluginNativeCode(pluginData: IPluginData, options?: any): Promise<void>;

/**
Expand Down
10 changes: 1 addition & 9 deletions test/helpers/platform-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("PlatformCommandHelper", () => {
describe("clean platforms unit tests", () => {
_.each(["ios", "anroid"], platform => {
it(`should preserve the specified in the project nativescript version for ${platform}`, async () => {
let versionData = { version: "5.3.1" };
let versionData = { version: "5.3.1" };

const projectDataService = injector.resolve("projectDataService");
projectDataService.getNSValue = () => versionData;
Expand All @@ -85,12 +85,4 @@ describe("PlatformCommandHelper", () => {
});
});
});
describe("update platforms unit tests", () => {
it("should fail when tha native platform cannot be updated", async () => {
const packageInstallationManager: IPackageInstallationManager = injector.resolve("packageInstallationManager");
packageInstallationManager.getLatestVersion = async () => "0.2.0";

await assert.isRejected(platformCommandHelper.updatePlatforms(["android"], projectData), "Native Platform cannot be updated.");
});
});
});
3 changes: 0 additions & 3 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,6 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
isPlatformPrepared(projectRoot: string): boolean {
return false;
}
canUpdatePlatform(installedModulePath: string): boolean {
return false;
}
async updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): Promise<boolean> {
return Promise.resolve(true);
}
Expand Down