Skip to content

fix: store the platform status on platform add in order to avoid another platform add during prepare. #4139

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
Nov 19, 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
14 changes: 7 additions & 7 deletions lib/definitions/project-changes.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
interface IAppFilesHashes {
appFilesHashes: IStringDictionary;
appFilesHashes?: IStringDictionary;
}

interface IPrepareInfo extends IAddedNativePlatform, IAppFilesHashes {
time: string;
bundle: boolean;
release: boolean;
projectFileHash: string;
changesRequireBuild: boolean;
changesRequireBuildTime: string;
time?: string;
bundle?: boolean;
release?: boolean;
projectFileHash?: string;
changesRequireBuild?: boolean;
changesRequireBuildTime?: string;
iOSProvisioningProfileUUID?: string;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
private shouldPersistWebpackFiles(platform: string, projectData: IProjectData, prepareInfo: IPrepareInfo, appFilesUpdaterOptions: IAppFilesUpdaterOptions, nativePrepare: INativePrepare): boolean {
const hasPlatformDirectory = this.hasPlatformDirectory(platform, projectData);
const isWebpackWatcherStarted = this.$usbLiveSyncService.isInitialized;
const hasNativePlatformStatus = !prepareInfo || !prepareInfo.nativePlatformStatus;
const hasNativePlatformStatus = prepareInfo && prepareInfo.nativePlatformStatus;
const requiresPlatformAdd = prepareInfo && prepareInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPlatformAdd;
const shouldAddNativePlatform = !nativePrepare || !nativePrepare.skipNativePrepare;
const shouldAddPlatform = hasNativePlatformStatus || (requiresPlatformAdd && shouldAddNativePlatform);
const shouldAddPlatform = !hasNativePlatformStatus || (requiresPlatformAdd && shouldAddNativePlatform);
const result = appFilesUpdaterOptions.bundle && isWebpackWatcherStarted && hasPlatformDirectory && shouldAddPlatform;
return result;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/services/prepare-platform-native-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class PreparePlatformNativeService extends PreparePlatformService impleme
info.platformData.platformProjectService.ensureConfigurationFileInAppResources(info.projectData);
await info.platformData.platformProjectService.interpolateData(info.projectData, info.config);
info.platformData.platformProjectService.afterCreateProject(info.platformData.projectRoot, info.projectData);
this.$projectChangesService.setNativePlatformStatus(info.platformData.normalizedPlatformName, info.projectData,
{ nativePlatformStatus: constants.NativePlatformStatus.requiresPrepare });
}

public async preparePlatform(config: IPreparePlatformJSInfo): Promise<void> {
Expand Down Expand Up @@ -111,7 +113,7 @@ export class PreparePlatformNativeService extends PreparePlatformService impleme
}

const previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
if (!previousPrepareInfo) {
if (!previousPrepareInfo || previousPrepareInfo.nativePlatformStatus !== constants.NativePlatformStatus.alreadyPrepared) {
return;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/services/project-changes-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,13 @@ export class ProjectChangesService implements IProjectChangesService {
this._prepareInfo = this._prepareInfo || this.getPrepareInfo(platform, projectData);
if (this._prepareInfo) {
this._prepareInfo.nativePlatformStatus = addedPlatform.nativePlatformStatus;
this.savePrepareInfo(platform, projectData);
} else {
this._prepareInfo = {
nativePlatformStatus: addedPlatform.nativePlatformStatus
};
}

this.savePrepareInfo(platform, projectData);
}

private async ensurePrepareInfo(platform: string, projectData: IProjectData, projectChangesOptions: IProjectChangesOptions): Promise<boolean> {
Expand Down
1 change: 1 addition & 0 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ describe('Platform Service Tests', () => {
appResourcesDestinationDirectoryPath: testDirData.appResourcesFolderPath,
normalizedPlatformName: "Android",
projectRoot: testDirData.tempFolder,
configurationFileName: "configFileName",
platformProjectService: {
prepareProject: (): any => null,
prepareAppResources: (): any => null,
Expand Down
12 changes: 12 additions & 0 deletions test/project-changes-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,16 @@ describe("Project Changes Service Tests", () => {
assert.isFalse(!!androidChanges.signingChanged, "Android signingChanged expected to be false");
});
});

describe("setNativePlatformStatus", () => {
it("creates prepare info and sets only the native platform status when there isn't an existing prepare info", () => {
for (const platform of ["ios", "android"]) {
serviceTest.projectChangesService.setNativePlatformStatus(platform, serviceTest.projectData, { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare });

const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(platform, serviceTest.projectData);

assert.deepEqual(actualPrepareInfo, { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare });
}
});
});
});
2 changes: 1 addition & 1 deletion test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export class ProjectDataStub implements IProjectData {
projectDir: string;
projectName: string;
get platformsDir(): string {
return this.plafromsDir;
return this.plafromsDir || (this.projectDir && path.join(this.projectDir, "platforms")) || "";
}
set platformsDir(value) {
this.plafromsDir = value;
Expand Down