From f5acaeb97de923fd265fe46f1359a41d6205e7e1 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Fri, 4 Oct 2019 15:52:42 +0300 Subject: [PATCH] fix: do not reject platform update on different pbxproj files as they are always different (outdated check from NativeScript 1.3) --- lib/declarations.d.ts | 1 - lib/helpers/platform-command-helper.ts | 21 +++++++----------- lib/services/android-project-service.ts | 6 +---- lib/services/ios-project-service.ts | 29 ++----------------------- lib/services/webpack/webpack.d.ts | 8 ------- test/helpers/platform-command-helper.ts | 10 +-------- test/stubs.ts | 3 --- 7 files changed, 12 insertions(+), 66 deletions(-) diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 488c6d728e..4da61c9a4f 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -600,7 +600,6 @@ interface IDeployPlatformOptions extends IAndroidReleaseOptions, IRelease, IClea interface IUpdatePlatformOptions { currentVersion: string; newVersion: string; - canUpdate: boolean; } interface IInfoService { diff --git a/lib/helpers/platform-command-helper.ts b/lib/helpers/platform-command-helper.ts index 0352fca6e8..37094d6fbf 100644 --- a/lib/helpers/platform-command-helper.ts +++ b/lib/helpers/platform-command-helper.ts @@ -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}.`); } } diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 246ce0cf40..04c6a2363b 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -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}'.`); @@ -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): Promise { if (semver.eq(newVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) { const platformLowercase = this.getPlatformData(projectData).normalizedPlatformName.toLowerCase(); diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 784fd90388..6d1f3f1b73 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -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; }; @@ -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 { const projectRoot = path.join(projectData.platformsDir, "ios"); const platformData = this.getPlatformData(projectData); @@ -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)) { diff --git a/lib/services/webpack/webpack.d.ts b/lib/services/webpack/webpack.d.ts index 3c283a3870..601bdcf3ef 100644 --- a/lib/services/webpack/webpack.d.ts +++ b/lib/services/webpack/webpack.d.ts @@ -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; /** diff --git a/test/helpers/platform-command-helper.ts b/test/helpers/platform-command-helper.ts index 0f71c8399b..be769607b8 100644 --- a/test/helpers/platform-command-helper.ts +++ b/test/helpers/platform-command-helper.ts @@ -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; @@ -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."); - }); - }); }); diff --git a/test/stubs.ts b/test/stubs.ts index 300d83f4a3..171c04846e 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -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 { return Promise.resolve(true); }