Skip to content

Commit f5acaeb

Browse files
committed
fix: do not reject platform update on different pbxproj files as they are always different (outdated check from NativeScript 1.3)
1 parent 3a76542 commit f5acaeb

File tree

7 files changed

+12
-66
lines changed

7 files changed

+12
-66
lines changed

lib/declarations.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,6 @@ interface IDeployPlatformOptions extends IAndroidReleaseOptions, IRelease, IClea
600600
interface IUpdatePlatformOptions {
601601
currentVersion: string;
602602
newVersion: string;
603-
canUpdate: boolean;
604603
}
605604

606605
interface IInfoService {

lib/helpers/platform-command-helper.ts

+8-13
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,16 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
155155
const cachedPackageData = this.$fs.readJson(path.join(installedModuleDir, "package.json"));
156156
newVersion = (cachedPackageData && cachedPackageData.version) || newVersion;
157157

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

164-
if (!semver.gt(currentVersion, newVersion)) {
165-
await this.updatePlatformCore(platformData, { currentVersion, newVersion, canUpdate }, projectData);
166-
} else if (semver.eq(currentVersion, newVersion)) {
167-
this.$errors.fail("Current and new version are the same.");
168-
} else {
169-
this.$errors.fail(`Your current version: ${currentVersion} is higher than the one you're trying to install ${newVersion}.`);
170-
}
162+
if (!semver.gt(currentVersion, newVersion)) {
163+
await this.updatePlatformCore(platformData, { currentVersion, newVersion }, projectData);
164+
} else if (semver.eq(currentVersion, newVersion)) {
165+
this.$errors.fail("Current and new version are the same.");
171166
} else {
172-
this.$errors.fail("Native Platform cannot be updated.");
167+
this.$errors.fail(`Your current version: ${currentVersion} is higher than the one you're trying to install ${newVersion}.`);
173168
}
174169
}
175170

lib/services/android-project-service.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
135135
}
136136

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

@@ -217,10 +217,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
217217
return null;
218218
}
219219

220-
public canUpdatePlatform(newInstalledModuleDir: string, projectData: IProjectData): boolean {
221-
return true;
222-
}
223-
224220
public async updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean, projectData: IProjectData, addPlatform?: Function, removePlatforms?: (platforms: string[]) => Promise<void>): Promise<boolean> {
225221
if (semver.eq(newVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
226222
const platformLowercase = this.getPlatformData(projectData).normalizedPlatformName.toLowerCase();

lib/services/ios-project-service.ts

+2-27
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
235235
const frameworkBinaryPath = path.join(bundlePath, frameworkName);
236236

237237
const fileResult = (await this.$childProcess.spawnFromEvent("file", [frameworkBinaryPath], "close")).stdout;
238-
const isDynamicallyLinked = _.includes(fileResult, "dynamically linked");
238+
const isDynamicallyLinked = _.includes(fileResult, "dynamically linked");
239239
return isDynamicallyLinked;
240240
};
241241

@@ -289,23 +289,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
289289
this.savePbxProj(project, projectData);
290290
}
291291

292-
public canUpdatePlatform(installedModuleDir: string, projectData: IProjectData): boolean {
293-
const currentXcodeProjectFile = this.buildPathToCurrentXcodeProjectFile(projectData);
294-
const currentXcodeProjectFileContent = this.$fs.readFile(currentXcodeProjectFile);
295-
296-
const newXcodeProjectFile = this.buildPathToNewXcodeProjectFile(installedModuleDir);
297-
this.replaceFileContent(newXcodeProjectFile, projectData);
298-
const newXcodeProjectFileContent = this.$fs.readFile(newXcodeProjectFile);
299-
300-
const contentIsTheSame = currentXcodeProjectFileContent.toString() === newXcodeProjectFileContent.toString();
301-
302-
if (!contentIsTheSame) {
303-
this.$logger.warn(`The content of the current project file: ${currentXcodeProjectFile} and the new project file: ${newXcodeProjectFile} is different.`);
304-
}
305-
306-
return contentIsTheSame;
307-
}
308-
309292
public async prepareProject(projectData: IProjectData, prepareData: IOSPrepareData): Promise<void> {
310293
const projectRoot = path.join(projectData.platformsDir, "ios");
311294
const platformData = this.getPlatformData(projectData);
@@ -620,18 +603,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
620603
private getAllLibsForPluginWithFileExtension(pluginData: IPluginData, fileExtension: string | string[]): string[] {
621604
const fileExtensions = _.isArray(fileExtension) ? fileExtension : [fileExtension];
622605
const filterCallback = (fileName: string, pluginPlatformsFolderPath: string) =>
623-
fileExtensions.indexOf(path.extname(fileName)) !== -1;
606+
fileExtensions.indexOf(path.extname(fileName)) !== -1;
624607
return this.getAllNativeLibrariesForPlugin(pluginData, IOSProjectService.IOS_PLATFORM_NAME, filterCallback);
625608
}
626609

627-
private buildPathToCurrentXcodeProjectFile(projectData: IProjectData): string {
628-
return path.join(projectData.platformsDir, "ios", `${projectData.projectName}.xcodeproj`, "project.pbxproj");
629-
}
630-
631-
private buildPathToNewXcodeProjectFile(newModulesDir: string): string {
632-
return path.join(newModulesDir, constants.PROJECT_FRAMEWORK_FOLDER_NAME, `${IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER}.xcodeproj`, "project.pbxproj");
633-
}
634-
635610
private validateFramework(libraryPath: string): void {
636611
const infoPlistPath = path.join(libraryPath, constants.INFO_PLIST_FILE_NAME);
637612
if (!this.$fs.exists(infoPlistPath)) {

lib/services/webpack/webpack.d.ts

-8
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ declare global {
8787
*/
8888
isPlatformPrepared(projectRoot: string, projectData: IProjectData): boolean;
8989

90-
/**
91-
* Checks if current platform can be updated to a newer versions.
92-
* @param {string} newInstalledModuleDir Path to the native project.
93-
* @param {IProjectData} projectData DTO with information about the project.
94-
* @return {boolean} True if platform can be updated. false otherwise.
95-
*/
96-
canUpdatePlatform(newInstalledModuleDir: string, projectData: IProjectData): boolean;
97-
9890
preparePluginNativeCode(pluginData: IPluginData, options?: any): Promise<void>;
9991

10092
/**

test/helpers/platform-command-helper.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe("PlatformCommandHelper", () => {
7373
describe("clean platforms unit tests", () => {
7474
_.each(["ios", "anroid"], platform => {
7575
it(`should preserve the specified in the project nativescript version for ${platform}`, async () => {
76-
let versionData = { version: "5.3.1" };
76+
let versionData = { version: "5.3.1" };
7777

7878
const projectDataService = injector.resolve("projectDataService");
7979
projectDataService.getNSValue = () => versionData;
@@ -85,12 +85,4 @@ describe("PlatformCommandHelper", () => {
8585
});
8686
});
8787
});
88-
describe("update platforms unit tests", () => {
89-
it("should fail when tha native platform cannot be updated", async () => {
90-
const packageInstallationManager: IPackageInstallationManager = injector.resolve("packageInstallationManager");
91-
packageInstallationManager.getLatestVersion = async () => "0.2.0";
92-
93-
await assert.isRejected(platformCommandHelper.updatePlatforms(["android"], projectData), "Native Platform cannot be updated.");
94-
});
95-
});
9688
});

test/stubs.ts

-3
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,6 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
434434
isPlatformPrepared(projectRoot: string): boolean {
435435
return false;
436436
}
437-
canUpdatePlatform(installedModulePath: string): boolean {
438-
return false;
439-
}
440437
async updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): Promise<boolean> {
441438
return Promise.resolve(true);
442439
}

0 commit comments

Comments
 (0)