Skip to content

Commit b184cdf

Browse files
authored
Merge pull request #4796 from NativeScript/fatme/validate-webpack-version
feat: validate the version of nativescript-dev-webpack plugin on every command
2 parents 8856a3c + 5c2e869 commit b184cdf

File tree

9 files changed

+17
-30
lines changed

9 files changed

+17
-30
lines changed

lib/commands/build.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
99
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1010
protected $buildController: IBuildController,
1111
$platformValidationService: IPlatformValidationService,
12-
private $bundleValidatorHelper: IBundleValidatorHelper,
1312
private $buildDataService: IBuildDataService,
1413
protected $logger: ILogger) {
1514
super($options, $platformsDataService, $platformValidationService, $projectData);
@@ -33,8 +32,6 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
3332
if (!this.$platformValidationService.isPlatformSupportedForOS(platform, this.$projectData)) {
3433
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
3534
}
36-
37-
this.$bundleValidatorHelper.validate(this.$projectData);
3835
}
3936

4037
protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
@@ -65,10 +62,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
6562
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
6663
$buildController: IBuildController,
6764
$platformValidationService: IPlatformValidationService,
68-
$bundleValidatorHelper: IBundleValidatorHelper,
6965
$logger: ILogger,
7066
$buildDataService: IBuildDataService) {
71-
super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $bundleValidatorHelper, $buildDataService, $logger);
67+
super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
7268
}
7369

7470
public async execute(args: string[]): Promise<void> {
@@ -101,11 +97,10 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
10197
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
10298
$buildController: IBuildController,
10399
$platformValidationService: IPlatformValidationService,
104-
$bundleValidatorHelper: IBundleValidatorHelper,
105100
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
106101
$buildDataService: IBuildDataService,
107102
protected $logger: ILogger) {
108-
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $bundleValidatorHelper, $buildDataService, $logger);
103+
super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger);
109104
}
110105

111106
public async execute(args: string[]): Promise<void> {
@@ -122,7 +117,6 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
122117

123118
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
124119
const platform = this.$devicePlatformsConstants.Android;
125-
super.validatePlatform(platform);
126120
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
127121
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
128122
if (result.canExecute) {

lib/commands/debug.ts

-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { cache } from "../common/decorators";
22
import { ValidatePlatformCommandBase } from "./command-base";
3-
import { LiveSyncCommandHelper } from "../helpers/livesync-command-helper";
43

54
export class DebugPlatformCommand extends ValidatePlatformCommandBase implements ICommand {
65
public allowedParameters: ICommandParameter[] = [];
76

87
constructor(private platform: string,
9-
private $bundleValidatorHelper: IBundleValidatorHelper,
108
protected $devicesService: Mobile.IDevicesService,
119
$platformValidationService: IPlatformValidationService,
1210
$projectData: IProjectData,
@@ -64,9 +62,6 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
6462
this.$errors.fail("--release flag is not applicable to this command");
6563
}
6664

67-
const minSupportedWebpackVersion = this.$options.hmr ? LiveSyncCommandHelper.MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR : null;
68-
this.$bundleValidatorHelper.validate(this.$projectData, minSupportedWebpackVersion);
69-
7065
const result = await super.canExecuteCommandBase(this.platform, { validateOptions: true, notConfiguredEnvOptions: { hideCloudBuildOption: true, hideSyncToPreviewAppOption: true } });
7166
return result;
7267
}

lib/commands/deploy.ts

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
1717
private $errors: IErrors,
1818
private $mobileHelper: Mobile.IMobileHelper,
1919
$platformsDataService: IPlatformsDataService,
20-
private $bundleValidatorHelper: IBundleValidatorHelper,
2120
private $deployCommandHelper: DeployCommandHelper,
2221
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
2322
super($options, $platformsDataService, $platformValidationService, $projectData);
@@ -31,7 +30,6 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
3130

3231
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
3332
this.$androidBundleValidatorHelper.validateNoAab();
34-
this.$bundleValidatorHelper.validate(this.$projectData);
3533
if (!args || !args.length || args.length > 1) {
3634
return false;
3735
}

lib/commands/preview.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { DEVICE_LOG_EVENT_NAME } from "../common/constants";
22

33
export class PreviewCommand implements ICommand {
44
public allowedParameters: ICommandParameter[] = [];
5-
private static MIN_SUPPORTED_WEBPACK_VERSION = "0.17.0";
65

76
constructor(private $analyticsService: IAnalyticsService,
87
private $bundleValidatorHelper: IBundleValidatorHelper,
@@ -43,7 +42,7 @@ export class PreviewCommand implements ICommand {
4342
}
4443

4544
await this.$networkConnectivityValidator.validate();
46-
this.$bundleValidatorHelper.validate(this.$projectData, PreviewCommand.MIN_SUPPORTED_WEBPACK_VERSION);
45+
this.$bundleValidatorHelper.validate(this.$projectData, "1.0.0");
4746
return true;
4847
}
4948
}

lib/common/mobile/mobile-core/devices-service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
444444
}
445445
} catch (err) {
446446
err.deviceIdentifier = device.deviceInfo.identifier;
447+
this.$logger.trace(`Error while executing action on device ${device.deviceInfo.identifier}. The error is ${err}`);
447448
errors.push(err);
448449
}
449450
}
@@ -454,9 +455,9 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
454455
preErrorMsg = "Multiple errors were thrown:" + EOL;
455456
}
456457

457-
const singleError = <Mobile.IDevicesOperationError>(new Error(`${preErrorMsg}${errors.map(e => e.message || e).join(EOL)}`));
458-
singleError.allErrors = errors;
459-
throw singleError;
458+
const errorMessage = `${preErrorMsg}${errors.map(e => e.message || e).join(EOL)}`;
459+
const suppressCommandHelp = _.some(errors, (e: any) => e.suppressCommandHelp);
460+
this.$errors.fail({ formatStr: errorMessage, suppressCommandHelp });
460461
}
461462

462463
return result;

lib/controllers/prepare-controller.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class PrepareController extends EventEmitter {
1616
private persistedData: IFilesChangeEventData[] = [];
1717

1818
constructor(
19+
private $bundleValidatorHelper: IBundleValidatorHelper,
1920
private $platformController: IPlatformController,
2021
public $hooksService: IHooksService,
2122
private $logger: ILogger,
@@ -31,12 +32,14 @@ export class PrepareController extends EventEmitter {
3132
@performanceLog()
3233
@hook("prepare")
3334
public async prepare(prepareData: IPrepareData): Promise<IPrepareResultData> {
35+
const projectData = this.$projectDataService.getProjectData(prepareData.projectDir);
36+
this.$bundleValidatorHelper.validate(projectData, "1.0.0");
37+
3438
await this.$platformController.addPlatformIfNeeded(prepareData);
3539

3640
this.$logger.info("Preparing project...");
3741
let result = null;
3842

39-
const projectData = this.$projectDataService.getProjectData(prepareData.projectDir);
4043
const platformData = this.$platformsDataService.getPlatformData(prepareData.platform, projectData);
4144

4245
if (prepareData.watch) {

lib/helpers/livesync-command-helper.ts

-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { RunOnDeviceEvents } from "../constants";
22
import { DeployController } from "../controllers/deploy-controller";
33

44
export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
5-
public static MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR = "0.17.0";
6-
75
constructor(
86
private $buildDataService: IBuildDataService,
97
private $projectData: IProjectData,
@@ -15,7 +13,6 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
1513
private $injector: IInjector,
1614
private $buildController: IBuildController,
1715
private $analyticsService: IAnalyticsService,
18-
private $bundleValidatorHelper: IBundleValidatorHelper,
1916
private $errors: IErrors,
2017
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
2118
private $cleanupService: ICleanupService,
@@ -133,9 +130,6 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
133130
result[availablePlatform.toLowerCase()] = validateOutput;
134131
}
135132

136-
const minSupportedWebpackVersion = this.$options.hmr ? LiveSyncCommandHelper.MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR : null;
137-
this.$bundleValidatorHelper.validate(this.$projectData, minSupportedWebpackVersion);
138-
139133
return result;
140134
}
141135

lib/services/project-changes-service.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from "path";
22
import { NativePlatformStatus, PACKAGE_JSON_FILE_NAME, APP_GRADLE_FILE_NAME, BUILD_XCCONFIG_FILE_NAME, PLATFORMS_DIR_NAME } from "../constants";
33
import { getHash, hook } from "../common/helpers";
4-
import { PrepareData } from "../data/prepare-data";
54

65
const prepareInfoFileName = ".nsprepareinfo";
76

@@ -51,7 +50,7 @@ export class ProjectChangesService implements IProjectChangesService {
5150
}
5251

5352
@hook("checkForChanges")
54-
public async checkForChanges(platformData: IPlatformData, projectData: IProjectData, prepareData: PrepareData): Promise<IProjectChangesInfo> {
53+
public async checkForChanges(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<IProjectChangesInfo> {
5554
this._changesInfo = new ProjectChangesInfo();
5655
const isNewPrepareInfo = await this.ensurePrepareInfo(platformData, projectData, prepareData);
5756
if (!isNewPrepareInfo) {
@@ -158,7 +157,7 @@ export class ProjectChangesService implements IProjectChangesService {
158157
await this.savePrepareInfo(platformData, projectData, null);
159158
}
160159

161-
private async ensurePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: PrepareData): Promise<boolean> {
160+
private async ensurePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<boolean> {
162161
this._prepareInfo = this.getPrepareInfo(platformData);
163162
if (this._prepareInfo) {
164163
const prepareInfoFile = path.join(platformData.projectRoot, prepareInfoFileName);

test/controllers/prepare-controller.ts

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector {
5454
isFileInIgnoreList: () => false
5555
});
5656

57+
injector.register("bundleValidatorHelper", {
58+
validate: () => ({})
59+
});
60+
5761
const prepareController: PrepareController = injector.resolve("prepareController");
5862
prepareController.emit = (eventName: string, eventData: any) => {
5963
emittedEventNames.push(eventName);

0 commit comments

Comments
 (0)