Skip to content

Commit b40c92b

Browse files
Fix npm support tests
Fix the tests by modifying current logic: - stop using ensurePrepareInfo for setting `nativePlatformStatus` property - introduce new method for setting it. The problem with using `ensurePrepareInfo` is that it saves the prepareInfo and calling checkForChanges after that is incorrect in case we modify the `bundle` option. Check test: `Ensures that tns_modules absent when bundling` - the last case was failing because when we call ensurePrepareInfo last time, bundle is false, we overwrite the prepareInfo in the file and checkForChanges says that bundle is currently false and has been false in the previous case. - in case prepareInfo is missing, we should not call addPlatform again - the else in `ensurePlatformInstalled` is not correct in case we execute `tns platform add <platform>` and then try `tns run/build/prepare <platform>` - in this case we do not have prepareInfo, so we try adding platform again. However, due to current implementation, we are sure that when we do not have prepareInfo, we've called platform add from CLI, so the platform is already added correctly. - fix a strange if inside `preparePlatformCoreNative` - we must prepare the node_modules in case `--bundle` is passed or the modulesChanged property of `changesInfo` is true.
1 parent 3caaf09 commit b40c92b

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

lib/definitions/project-changes.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface IProjectChangesService {
3131
getPrepareInfo(platform: string, projectData: IProjectData): IPrepareInfo;
3232
savePrepareInfo(platform: string, projectData: IProjectData): void;
3333
getPrepareInfoFilePath(platform: string, projectData: IProjectData): string;
34-
ensurePrepareInfo(platform: string, projectData: IProjectData, projectChangesOptions: IProjectChangesOptions): boolean;
34+
setNativePlatformStatus(platform: string, projectData: IProjectData, nativePlatformStatus: IAddedNativePlatform): void;
3535
currentChanges: IProjectChangesInfo;
3636
}
3737

lib/services/platform-service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
340340
await platformData.platformProjectService.prepareProject(projectData, platformSpecificData);
341341
}
342342

343-
if (changesInfo && !changesInfo.modulesChanged && appFilesUpdaterOptions.bundle) {
343+
if (!changesInfo || changesInfo.modulesChanged || appFilesUpdaterOptions.bundle) {
344344
let appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
345345
let lastModifiedTime = this.$fs.exists(appDestinationDirectoryPath) ? this.$fs.getFsStats(appDestinationDirectoryPath).mtime : null;
346346

@@ -354,8 +354,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
354354
}
355355

356356
platformData.platformProjectService.interpolateConfigurationFile(projectData, platformSpecificData);
357-
this.$projectChangesService.ensurePrepareInfo(platform, projectData,
358-
{ nativePlatformStatus: constants.NativePlatformStatus.alreadyPrepared, release: appFilesUpdaterOptions.release, bundle: appFilesUpdaterOptions.bundle, provision: platformSpecificData.provision });
357+
this.$projectChangesService.setNativePlatformStatus(platform, projectData,
358+
{ nativePlatformStatus: constants.NativePlatformStatus.alreadyPrepared });
359359
}
360360

361361
private async copyAppFiles(platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData): Promise<void> {
@@ -742,7 +742,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
742742
} else {
743743
const shouldAddNativePlatform = !nativePrepare || !nativePrepare.skip;
744744
const prepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
745-
requiresNativePlatformAdd = !prepareInfo || prepareInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPlatformAdd;
745+
// In case there's no prepare info, it means only platform add had been executed. So we've come from CLI and we do not need to prepare natively.
746+
requiresNativePlatformAdd = prepareInfo && prepareInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPlatformAdd;
746747
if (requiresNativePlatformAdd && shouldAddNativePlatform) {
747748
await this.addPlatform(platform, platformTemplate, projectData, config, "", nativePrepare);
748749
}

lib/services/project-changes-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ export class ProjectChangesService implements IProjectChangesService {
139139
this.$fs.writeJson(prepareInfoFilePath, this._prepareInfo);
140140
}
141141

142+
public setNativePlatformStatus(platform: string, projectData: IProjectData, addedPlatform: IAddedNativePlatform): void {
143+
this._prepareInfo = this._prepareInfo || this.getPrepareInfo(platform, projectData);
144+
if (this._prepareInfo) {
145+
this._prepareInfo.nativePlatformStatus = addedPlatform.nativePlatformStatus;
146+
this.savePrepareInfo(platform, projectData);
147+
}
148+
}
149+
142150
public ensurePrepareInfo(platform: string, projectData: IProjectData, projectChangesOptions: IProjectChangesOptions): boolean {
143151
this._prepareInfo = this.getPrepareInfo(platform, projectData);
144152
if (this._prepareInfo) {
@@ -150,7 +158,6 @@ export class ProjectChangesService implements IProjectChangesService {
150158
let prepareInfoFile = path.join(platformData.projectRoot, prepareInfoFileName);
151159
this._outputProjectMtime = this.$fs.getFsStats(prepareInfoFile).mtime.getTime();
152160
this._outputProjectCTime = this.$fs.getFsStats(prepareInfoFile).ctime.getTime();
153-
this.savePrepareInfo(platform, projectData);
154161
return false;
155162
}
156163

@@ -171,8 +178,6 @@ export class ProjectChangesService implements IProjectChangesService {
171178
this._changesInfo.appResourcesChanged = true;
172179
this._changesInfo.modulesChanged = true;
173180
this._changesInfo.configChanged = true;
174-
175-
this.savePrepareInfo(platform, projectData);
176181
return true;
177182
}
178183

test/stubs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ export class ProjectChangesService implements IProjectChangesService {
575575
return <IProjectChangesInfo>{};
576576
}
577577

578-
public ensurePrepareInfo(platform: string, projectData: IProjectData, projectChangesOptions: IProjectChangesOptions): boolean {
578+
public setNativePlatformStatus(platform: string, projectData: IProjectData, nativePlatformStatus: IAddedNativePlatform): boolean {
579579
return true;
580580
}
581581
}

0 commit comments

Comments
 (0)