Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 17a506a

Browse files
Merge pull request #865 from telerik/all/remove-fibers
Remove fibers and use async/await
2 parents 4225f59 + d36d30c commit 17a506a

File tree

161 files changed

+6151
-6914
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+6151
-6914
lines changed

Gruntfile.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var now = new Date().toISOString();
55

66
function shallowCopy(obj) {
77
var result = {};
8-
Object.keys(obj).forEach(function(key) {
8+
Object.keys(obj).forEach(function (key) {
99
result[key] = obj[key];
1010
});
1111
return result;
@@ -20,7 +20,7 @@ function getBuildVersion(version) {
2020
return buildVersion;
2121
}
2222

23-
module.exports = function(grunt) {
23+
module.exports = function (grunt) {
2424

2525
// Windows cmd does not accept paths with / and unix shell does not accept paths with \\ and we need to execute from a sub-dir.
2626
// To circumvent the issue, hack our environment's PATH and let the OS deal with it, which in practice works
@@ -60,14 +60,14 @@ module.exports = function(grunt) {
6060

6161
tslint: {
6262
build: {
63-
files: {
64-
src: ["**/*.ts", "!node_modules/**/*.ts", "!messages/**/*.ts", "!**/*.d.ts"]
65-
},
66-
options: {
67-
configuration: grunt.file.readJSON("./tslint.json")
68-
}
69-
}
70-
},
63+
files: {
64+
src: ["**/*.ts", "!node_modules/**/*.ts", "!messages/**/*.ts", "!**/*.d.ts"]
65+
},
66+
options: {
67+
configuration: grunt.file.readJSON("./tslint.json")
68+
}
69+
}
70+
},
7171

7272
watch: {
7373
devall: {
@@ -90,7 +90,7 @@ module.exports = function(grunt) {
9090
command: "npm test",
9191
options: {
9292
execOptions: {
93-
env: (function() {
93+
env: (function () {
9494
var env = shallowCopy(process.env);
9595
env["XUNIT_FILE"] = "test-reports.xml";
9696
env["LOG_XUNIT"] = "true";
@@ -104,7 +104,7 @@ module.exports = function(grunt) {
104104
command: "npm pack",
105105
options: {
106106
execOptions: {
107-
env: (function() {
107+
env: (function () {
108108
var env = shallowCopy(process.env);
109109
env["COMMON_LIB_SKIP_POSTINSTALL_TASKS"] = "1";
110110
return env;
@@ -134,7 +134,7 @@ module.exports = function(grunt) {
134134
grunt.loadNpmTasks("grunt-ts");
135135
grunt.loadNpmTasks("grunt-tslint");
136136

137-
grunt.registerTask("set_package_version", function(version) {
137+
grunt.registerTask("set_package_version", function (version) {
138138
var buildVersion = getBuildVersion(version);
139139
var packageJson = grunt.file.readJSON("package.json");
140140
packageJson.buildVersion = buildVersion;
@@ -147,7 +147,7 @@ module.exports = function(grunt) {
147147
var buildVersion = getBuildVersion(version);
148148
var packageJson = grunt.file.readJSON("package.json");
149149
var oldFileName = packageJson.name + "-" + packageJson.version + fileExtension;
150-
if(buildVersion) {
150+
if (buildVersion) {
151151
var newFileName = oldFileName + "-" + buildVersion + fileExtension;
152152
fs.renameSync(oldFileName, newFileName);
153153
console.log("Renamed " + oldFileName + " to " + newFileName);
@@ -156,11 +156,11 @@ module.exports = function(grunt) {
156156
}
157157
});
158158

159-
grunt.registerTask("delete_coverage_dir", function() {
159+
grunt.registerTask("delete_coverage_dir", function () {
160160
var done = this.async();
161161
var rimraf = require("rimraf");
162-
rimraf("coverage", function(err) {
163-
if(err) {
162+
rimraf("coverage", function (err) {
163+
if (err) {
164164
console.log("Error while deleting coverage directory from the package.");
165165
done(false);
166166
}

appbuilder/declarations.d.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface ILiveSyncDeviceAppData extends Mobile.IDeviceAppData {
55
}
66

77
interface IDeployHelper {
8-
deploy(platform?: string): IFuture<void>;
8+
deploy(platform?: string): Promise<void>;
99
}
1010

1111
declare module Project {
@@ -110,14 +110,9 @@ declare module Project {
110110
/**
111111
* Gets the app identifier which is going to be used to build the application.
112112
* @parameter Optional parameter the platform for which the app identifier will be returned.
113-
* @return {IFuture<string>} the app identifier which will be used to build the application.
113+
* @return {string} the app identifier which will be used to build the application.
114114
*/
115-
getAppIdentifierForPlatform(platform?: string): IFuture<string>;
116-
117-
/**
118-
* Checks if the app identifier is valid and if it is not - this method will throw an exception.
119-
*/
120-
validateAppIdentifier(platform?: string): IFuture<void>;
115+
getAppIdentifierForPlatform(platform?: string): string;
121116
}
122117

123118
/**
@@ -164,7 +159,7 @@ interface IProtonLiveSyncService {
164159
* @param {string[]} filePaths Passed only in cases when only some of the files must be synced.
165160
* @return {IDeviceLiveSyncResult[]} Information about each LiveSync operation.
166161
*/
167-
livesync(deviceDescriptors: IDeviceLiveSyncInfo[], projectDir: string, filePaths?: string[]): IFuture<IDeviceLiveSyncResult>[];
162+
livesync(deviceDescriptors: IDeviceLiveSyncInfo[], projectDir: string, filePaths?: string[]): Promise<IDeviceLiveSyncResult>[];
168163
}
169164

170165
/**
@@ -322,37 +317,37 @@ interface INpmService {
322317
* The method will remove them from package.json and from node_modules dir.
323318
* @param {string} projectDir Directory of the project, where package.json is located.
324319
* @param {string} dependency The name of the dependency that has to be removed.
325-
* @return {IFuture<void>}
320+
* @return {Promise<void>}
326321
*/
327-
uninstall(projectDir: string, dependency: string): IFuture<void>;
322+
uninstall(projectDir: string, dependency: string): Promise<void>;
328323

329324
/**
330325
* Installs everything from package.json or specified dependency.
331326
* In case there's information which dependency to install, the method will check it and install only this dependency and possibly its @types.
332327
* @param {string} projectDir Directory of the project, where package.json is located.
333328
* @param @optional {INpmDependency} dependency Description of the dependency that has to be installed.
334-
* @return {IFuture<INpmInstallResult>} Returns object that will have error in case something fails.
329+
* @return {Promise<INpmInstallResult>} Returns object that will have error in case something fails.
335330
* In case there's no specific dependency that has to be installed and everything is installed successfully, the result will be empty object.
336331
* In case there's dependency that has to be installed, the result object will contain information for the successfull installation of the dependency and the @types reference.
337332
*/
338-
install(projectDir: string, dependencyToInstall?: INpmDependency): IFuture<INpmInstallResult>;
333+
install(projectDir: string, dependencyToInstall?: INpmDependency): Promise<INpmInstallResult>;
339334

340335
/**
341336
* Searches for plugins in npm.
342337
* @param {string} projectDir The project directory.
343338
* @param {string[]} keywords The keywords for the search.
344339
* @param @optional {string[]} args Additional flags for the npm search command.
345-
* @return {IFuture<IBasicPluginInformation[]>} Array of basic plugin information for the search results.
340+
* @return {Promise<IBasicPluginInformation[]>} Array of basic plugin information for the search results.
346341
*/
347-
search(projectDir: string, keywords: string[], args?: string[]): IFuture<IBasicPluginInformation[]>;
342+
search(projectDir: string, keywords: string[], args?: string[]): Promise<IBasicPluginInformation[]>;
348343

349344
/**
350345
* Gets package.json of a specific dependency from registry.npmjs.org.
351346
* @param {string} packageName The name of the dependency.
352347
* @param {string} version The version that has to be taken from registry. "latest" will be used in case there's no version passed.
353348
* @return {any} package.json of a dependency or null in case such dependency or version does not exist.
354349
*/
355-
getPackageJsonFromNpmRegistry(packageName: string, version?: string): IFuture<any>;
350+
getPackageJsonFromNpmRegistry(packageName: string, version?: string): Promise<any>;
356351

357352
/**
358353
* Checks if dependency is scoped.
@@ -379,16 +374,16 @@ interface INpmPluginsService {
379374
* @param {string} projectDir The directory of the project.
380375
* @param {string[]} keywords The keywords for the search.
381376
* @param @optional {(keywords: string[]) => string[]} modifySearchQuery Function which will be used to modify the search query when using the npm binary.
382-
* @return {IFuture<IPluginsSource>} The plugins source which can be used to get the result.
377+
* @return {Promise<IPluginsSource>} The plugins source which can be used to get the result.
383378
*/
384-
search(projectDir: string, keywords: string[], modifySearchQuery?: (keywords: string[]) => string[]): IFuture<IPluginsSource>;
379+
search(projectDir: string, keywords: string[], modifySearchQuery?: (keywords: string[]) => string[]): Promise<IPluginsSource>;
385380

386381
/**
387382
* Searches for plugin in http://registry.npmjs.org plugins and if plugin is not found will continue the search in http://npmjs.org and the npm binary.
388383
* @param {string} projectDir The directory of the project.
389384
* @param {string[]} keywords The keywords for the search.
390385
* @param @optional {(keywords: string[]) => string[]} modifySearchQuery Function which will be used to modify the search query when using the npm binary.
391-
* @return {IFuture<IPluginsSource>} The plugins source which can be used to get the result.
386+
* @return {Promise<IPluginsSource>} The plugins source which can be used to get the result.
392387
*/
393-
optimizedSearch(projectDir: string, keywords: string[], modifySearchQuery?: (keywords: string[]) => string[]): IFuture<IPluginsSource>;
388+
optimizedSearch(projectDir: string, keywords: string[], modifySearchQuery?: (keywords: string[]) => string[]): Promise<IPluginsSource>;
394389
}

appbuilder/device-emitter.ts

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export class DeviceEmitter extends EventEmitter {
77
private $devicesService: Mobile.IDevicesService,
88
private $deviceLogProvider: EventEmitter,
99
private $companionAppsService: ICompanionAppsService,
10-
private $projectConstants: Project.IConstants,
1110
private $logger: ILogger) {
1211
super();
1312
}
@@ -21,50 +20,49 @@ export class DeviceEmitter extends EventEmitter {
2120
return this._companionAppIdentifiers;
2221
}
2322

24-
public initialize(): IFuture<void> {
25-
return (() => {
26-
try {
27-
this.$androidDeviceDiscovery.ensureAdbServerStarted().wait();
28-
} catch(err) {
29-
this.$logger.warn(`Unable to start adb server. Error message is: ${err.message}`);
30-
}
23+
public async initialize(): Promise<void> {
24+
try {
25+
await this.$androidDeviceDiscovery.ensureAdbServerStarted();
26+
} catch (err) {
27+
this.$logger.warn(`Unable to start adb server. Error message is: ${err.message}`);
28+
}
29+
30+
this.$androidDeviceDiscovery.on("deviceFound", (device: Mobile.IDevice) => {
31+
this.emit("deviceFound", device.deviceInfo);
32+
this.attachApplicationChangedHandlers(device);
33+
// await: Do not await as this will require to mark the lambda with async keyword, but there's no way to await the lambda itself.
34+
device.openDeviceLogStream();
35+
});
36+
37+
this.$androidDeviceDiscovery.on("deviceLost", (device: Mobile.IDevice) => {
38+
this.emit("deviceLost", device.deviceInfo);
39+
});
40+
41+
this.$iOSDeviceDiscovery.on("deviceFound", (device: Mobile.IDevice) => {
42+
this.emit("deviceFound", device.deviceInfo);
43+
this.attachApplicationChangedHandlers(device);
44+
device.openDeviceLogStream();
45+
});
3146

32-
this.$androidDeviceDiscovery.on("deviceFound", (device: Mobile.IDevice) => {
33-
this.emit("deviceFound", device.deviceInfo);
34-
this.attachApplicationChangedHandlers(device);
35-
device.openDeviceLogStream();
36-
});
37-
38-
this.$androidDeviceDiscovery.on("deviceLost", (device: Mobile.IDevice) => {
39-
this.emit("deviceLost", device.deviceInfo);
40-
});
41-
42-
this.$iOSDeviceDiscovery.on("deviceFound", (device: Mobile.IDevice) => {
43-
this.emit("deviceFound", device.deviceInfo);
44-
this.attachApplicationChangedHandlers(device);
45-
device.openDeviceLogStream();
46-
});
47-
48-
this.$iOSDeviceDiscovery.on("deviceLost", (device: Mobile.IDevice) => {
49-
this.emit("deviceLost", device.deviceInfo);
50-
});
51-
52-
this.$iOSSimulatorDiscovery.on("deviceFound", (device: Mobile.IDevice) => {
53-
this.emit("deviceFound", device.deviceInfo);
54-
device.openDeviceLogStream();
55-
this.attachApplicationChangedHandlers(device);
56-
});
57-
58-
this.$iOSSimulatorDiscovery.on("deviceLost", (device: Mobile.IDevice) => {
59-
this.emit("deviceLost", device.deviceInfo);
60-
});
61-
62-
this.$devicesService.initialize({ skipInferPlatform: true }).wait();
63-
64-
this.$deviceLogProvider.on("data", (identifier: string, data: any) => {
65-
this.emit('deviceLogData', identifier, data.toString());
66-
});
67-
}).future<void>()();
47+
this.$iOSDeviceDiscovery.on("deviceLost", (device: Mobile.IDevice) => {
48+
this.emit("deviceLost", device.deviceInfo);
49+
});
50+
51+
this.$iOSSimulatorDiscovery.on("deviceFound", (device: Mobile.IDevice) => {
52+
this.emit("deviceFound", device.deviceInfo);
53+
device.openDeviceLogStream();
54+
this.attachApplicationChangedHandlers(device);
55+
});
56+
57+
this.$iOSSimulatorDiscovery.on("deviceLost", (device: Mobile.IDevice) => {
58+
this.emit("deviceLost", device.deviceInfo);
59+
});
60+
61+
await this.$devicesService.initialize({ skipInferPlatform: true });
62+
63+
this.$deviceLogProvider.on("data", (identifier: string, data: any) => {
64+
this.emit('deviceLogData', identifier, data.toString());
65+
});
6866
}
6967

7068
private attachApplicationChangedHandlers(device: Mobile.IDevice): void {

appbuilder/device-log-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class DeviceLogProvider extends DeviceLogProviderBase {
2424
this.$logFilter.loggingLevel = logLevel.toUpperCase();
2525

2626
_.keys(this.devicesLogOptions).forEach(deviceId => {
27-
this.devicesLogOptions[deviceId] = this.devicesLogOptions[deviceId] || <Mobile.IDeviceLogOptions> { };
27+
this.devicesLogOptions[deviceId] = this.devicesLogOptions[deviceId] || <Mobile.IDeviceLogOptions>{};
2828
this.devicesLogOptions[deviceId].logLevel = this.$logFilter.loggingLevel;
2929
});
3030
}

appbuilder/mobile-platforms-capabilities.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
export class MobilePlatformsCapabilities implements Mobile.IPlatformsCapabilities {
22
private platformCapabilities: IDictionary<Mobile.IPlatformCapabilities>;
33

4-
constructor(private $errors: IErrors) { }
5-
6-
public getPlatformNames(): string[]{
4+
public getPlatformNames(): string[] {
75
return _.keys(this.getAllCapabilities());
86
}
97

appbuilder/mobile/appbuilder-companion-device-app-data-base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {AppBuilderDeviceAppDataBase} from "./appbuilder-device-app-data-base";
1+
import { AppBuilderDeviceAppDataBase } from "./appbuilder-device-app-data-base";
22

33
export abstract class AppBuilderCompanionDeviceAppDataBase extends AppBuilderDeviceAppDataBase {
4-
public isLiveSyncSupported(): IFuture<boolean> {
4+
public isLiveSyncSupported(): Promise<boolean> {
55
return this.device.applicationManager.isApplicationInstalled(this.appIdentifier);
66
}
77

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import * as querystring from "querystring";
2-
import {DeviceAppDataBase} from "./../../mobile/device-app-data/device-app-data-base";
2+
import { DeviceAppDataBase } from "./../../mobile/device-app-data/device-app-data-base";
33

44
export class AppBuilderDeviceAppDataBase extends DeviceAppDataBase implements ILiveSyncDeviceAppData {
5-
public deviceProjectRootPath: string;
6-
75
constructor(_appIdentifier: string,
86
public device: Mobile.IDevice,
97
public platform: string,
10-
private $deployHelper: IDeployHelper,
11-
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) {
8+
private $deployHelper: IDeployHelper) {
129
super(_appIdentifier);
1310
}
1411

12+
public getDeviceProjectRootPath(): Promise<string> {
13+
return Promise.resolve("");
14+
}
15+
1516
public get liveSyncFormat(): string {
1617
return null;
1718
}
@@ -24,17 +25,15 @@ export class AppBuilderDeviceAppDataBase extends DeviceAppDataBase implements IL
2425
return `You can't LiveSync on device with id ${this.device.deviceInfo.identifier}! Deploy the app with LiveSync enabled and wait for the initial start up before LiveSyncing.`;
2526
}
2627

27-
public isLiveSyncSupported(): IFuture<boolean> {
28-
return (() => {
29-
let isApplicationInstalled = this.device.applicationManager.isApplicationInstalled(this.appIdentifier).wait();
28+
public async isLiveSyncSupported(): Promise<boolean> {
29+
let isApplicationInstalled = await this.device.applicationManager.isApplicationInstalled(this.appIdentifier);
3030

31-
if (!isApplicationInstalled) {
32-
this.$deployHelper.deploy(this.platform.toString()).wait();
33-
// Update cache of installed apps
34-
this.device.applicationManager.checkForApplicationUpdates().wait();
35-
}
31+
if (!isApplicationInstalled) {
32+
await this.$deployHelper.deploy(this.platform.toString());
33+
// Update cache of installed apps
34+
await this.device.applicationManager.checkForApplicationUpdates();
35+
}
3636

37-
return this.device.applicationManager.isLiveSyncSupported(this.appIdentifier).wait();
38-
}).future<boolean>()();
37+
return await this.device.applicationManager.isLiveSyncSupported(this.appIdentifier);
3938
}
4039
}

0 commit comments

Comments
 (0)