Skip to content

Commit c2d844d

Browse files
authored
Fix prepare for android when building with webpack (#2852)
When switching between release, debug and bundle builds, the android build artifacts should be cleaned. fixes NativeScript/android#759
1 parent 756af30 commit c2d844d

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

lib/services/platform-service.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,9 @@ export class PlatformService extends EventEmitter implements IPlatformService {
239239
this.$logger.trace("Changes info in prepare platform:", changesInfo);
240240

241241
if (changesInfo.hasChanges) {
242-
// android build artifacts need to be cleaned up when switching from release to debug builds
243-
if (platform.toLowerCase() === "android") {
244-
let previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
245-
// clean up prepared plugins when not building for release
246-
if (previousPrepareInfo && previousPrepareInfo.release !== appFilesUpdaterOptions.release) {
247-
await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData);
248-
}
249-
}
250-
242+
await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData);
251243
await this.preparePlatformCore(platform, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, filesToSync);
244+
252245
this.$projectChangesService.savePrepareInfo(platform, projectData);
253246
} else {
254247
this.$logger.out("Skipping prepare.");
@@ -275,6 +268,25 @@ export class PlatformService extends EventEmitter implements IPlatformService {
275268
}
276269
}
277270

271+
private async cleanProject(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformData: IPlatformData, projectData: IProjectData): Promise<void> {
272+
// android build artifacts need to be cleaned up
273+
// when switching between debug, release and webpack builds
274+
if (platform.toLowerCase() !== "android") {
275+
return;
276+
}
277+
278+
const previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
279+
if (!previousPrepareInfo) {
280+
return;
281+
}
282+
283+
const { release: previousWasRelease, bundle: previousWasBundle } = previousPrepareInfo;
284+
const { release: currentIsRelease, bundle: currentIsBundle } = appFilesUpdaterOptions;
285+
if ((previousWasRelease !== currentIsRelease) || (previousWasBundle !== currentIsBundle)) {
286+
await platformData.platformProjectService.cleanProject(platformData.projectRoot, projectData);
287+
}
288+
}
289+
278290
/* Hooks are expected to use "filesToSync" parameter, as to give plugin authors additional information about the sync process.*/
279291
@helpers.hook('prepare')
280292
private async preparePlatformCore(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array<String>): Promise<void> {

test/npm-support.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ async function setupProject(dependencies?: any): Promise<any> {
159159
ensureConfigurationFileInAppResources: (): any => null,
160160
interpolateConfigurationFile: (): void => undefined,
161161
isPlatformPrepared: (projectRoot: string) => false,
162-
validatePlugins: (projectData: IProjectData) => Promise.resolve()
162+
validatePlugins: (projectData: IProjectData) => Promise.resolve(),
163+
cleanProject: () => Promise.resolve(),
163164
}
164165
};
165166
};
@@ -316,7 +317,7 @@ describe("Flatten npm modules tests", () => {
316317
let gulpJshint = path.join(tnsModulesFolderPath, "gulp-jshint");
317318
assert.isFalse(fs.exists(gulpJshint));
318319

319-
// Get all gulp dependencies
320+
// Get all gulp dependencies
320321
let gulpJsonContent = fs.readJson(path.join(projectFolder, nodeModulesFolderName, "gulp", packageJsonName));
321322
_.each(_.keys(gulpJsonContent.dependencies), dependency => {
322323
assert.isFalse(fs.exists(path.join(tnsModulesFolderPath, dependency)));

0 commit comments

Comments
 (0)