diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 1df21befb2..60d81a4894 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -239,16 +239,9 @@ export class PlatformService extends EventEmitter implements IPlatformService { this.$logger.trace("Changes info in prepare platform:", changesInfo); if (changesInfo.hasChanges) { - // android build artifacts need to be cleaned up when switching from release to debug builds - if (platform.toLowerCase() === "android") { - let previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData); - // clean up prepared plugins when not building for release - if (previousPrepareInfo && previousPrepareInfo.release !== appFilesUpdaterOptions.release) { - await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData); - } - } - + await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData); await this.preparePlatformCore(platform, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, filesToSync); + this.$projectChangesService.savePrepareInfo(platform, projectData); } else { this.$logger.out("Skipping prepare."); @@ -275,6 +268,25 @@ export class PlatformService extends EventEmitter implements IPlatformService { } } + private async cleanProject(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformData: IPlatformData, projectData: IProjectData): Promise { + // android build artifacts need to be cleaned up + // when switching between debug, release and webpack builds + if (platform.toLowerCase() !== "android") { + return; + } + + const previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData); + if (!previousPrepareInfo) { + return; + } + + const { release: previousWasRelease, bundle: previousWasBundle } = previousPrepareInfo; + const { release: currentIsRelease, bundle: currentIsBundle } = appFilesUpdaterOptions; + if ((previousWasRelease !== currentIsRelease) || (previousWasBundle !== currentIsBundle)) { + await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData); + } + } + /* Hooks are expected to use "filesToSync" parameter, as to give plugin authors additional information about the sync process.*/ @helpers.hook('prepare') private async preparePlatformCore(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array): Promise { diff --git a/test/npm-support.ts b/test/npm-support.ts index 261cfe9ad0..f345095ca6 100644 --- a/test/npm-support.ts +++ b/test/npm-support.ts @@ -159,7 +159,8 @@ async function setupProject(dependencies?: any): Promise { ensureConfigurationFileInAppResources: (): any => null, interpolateConfigurationFile: (): void => undefined, isPlatformPrepared: (projectRoot: string) => false, - validatePlugins: (projectData: IProjectData) => Promise.resolve() + validatePlugins: (projectData: IProjectData) => Promise.resolve(), + cleanProject: () => Promise.resolve(), } }; }; @@ -316,7 +317,7 @@ describe("Flatten npm modules tests", () => { let gulpJshint = path.join(tnsModulesFolderPath, "gulp-jshint"); assert.isFalse(fs.exists(gulpJshint)); - // Get all gulp dependencies + // Get all gulp dependencies let gulpJsonContent = fs.readJson(path.join(projectFolder, nodeModulesFolderName, "gulp", packageJsonName)); _.each(_.keys(gulpJsonContent.dependencies), dependency => { assert.isFalse(fs.exists(path.join(tnsModulesFolderPath, dependency)));