Skip to content

Commit a3c3fa3

Browse files
Use sync version of fs.exists
We use fs.exists, which is deprecated. Change the code to use fs.existsSync instead. This makes the `$fs.exists` method to return boolean instead of `IFuture<boolean>`. Several methods were declared as `IFuture<T>` as in their body they are calling `$fs.exists(...).wait()`. As now the `$fs.exists` method is sync, change all methods that are async only because of `$fs.exists().wait()` sync.
1 parent 8fe2f37 commit a3c3fa3

35 files changed

+181
-171
lines changed

lib/android-tools-info.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
4242
this.showWarningsAsErrors = options.showWarningsAsErrors;
4343
}
4444
if (!this.pathToAndroidExecutable) {
45-
if (this.validateAndroidHomeEnvVariable(this.androidHome).wait()) {
45+
if (this.validateAndroidHomeEnvVariable(this.androidHome)) {
4646
let androidPath = path.join(this.androidHome, "tools", this.androidExecutableName);
4747
if (!this.trySetAndroidPath(androidPath).wait() && !this.trySetAndroidPath(this.androidExecutableName).wait()) {
4848
this.printMessage(`Unable to find "${this.androidExecutableName}" executable file. Make sure you have set ANDROID_HOME environment variable correctly.`);
@@ -100,7 +100,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
100100
let detectedErrors = false;
101101
this.showWarningsAsErrors = options && options.showWarningsAsErrors;
102102
let toolsInfoData = this.getToolsInfo().wait();
103-
let isAndroidHomeValid = this.validateAndroidHomeEnvVariable(toolsInfoData.androidHomeEnvVar).wait();
103+
let isAndroidHomeValid = this.validateAndroidHomeEnvVariable(toolsInfoData.androidHomeEnvVar);
104104
if (!toolsInfoData.compileSdkVersion) {
105105
this.printMessage(`Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK ${AndroidToolsInfo.MIN_REQUIRED_COMPILE_TARGET} or later.`,
106106
"Run `$ android` to manage your Android SDK versions.");
@@ -261,7 +261,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
261261
private getMatchingDir(pathToDir: string, versionRange: string): IFuture<string> {
262262
return ((): string => {
263263
let selectedVersion: string;
264-
if (this.$fs.exists(pathToDir).wait()) {
264+
if (this.$fs.exists(pathToDir)) {
265265
let subDirs = this.$fs.readDirectory(pathToDir).wait();
266266
this.$logger.trace(`Directories found in ${pathToDir} are ${subDirs.join(", ")}`);
267267

@@ -366,25 +366,23 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
366366
}
367367

368368
private _cachedAndroidHomeValidationResult: boolean = null;
369-
private validateAndroidHomeEnvVariable(androidHomeEnvVar: string): IFuture<boolean> {
370-
return ((): boolean => {
371-
if (this._cachedAndroidHomeValidationResult === null) {
372-
this._cachedAndroidHomeValidationResult = true;
373-
let expectedDirectoriesInAndroidHome = ["build-tools", "tools", "platform-tools", "extras"];
374-
if (!androidHomeEnvVar || !this.$fs.exists(androidHomeEnvVar).wait()) {
375-
this.printMessage("The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.",
376-
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.");
377-
this._cachedAndroidHomeValidationResult = false;
378-
} else if (!_.some(expectedDirectoriesInAndroidHome.map(dir => this.$fs.exists(path.join(androidHomeEnvVar, dir)).wait()))) {
379-
this.printMessage("The ANDROID_HOME environment variable points to incorrect directory. You will not be able to perform any build-related operations for Android.",
380-
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory, " +
381-
"where you will find `tools` and `platform-tools` directories.");
382-
this._cachedAndroidHomeValidationResult = false;
383-
}
369+
private validateAndroidHomeEnvVariable(androidHomeEnvVar: string): boolean {
370+
if (this._cachedAndroidHomeValidationResult === null) {
371+
this._cachedAndroidHomeValidationResult = true;
372+
let expectedDirectoriesInAndroidHome = ["build-tools", "tools", "platform-tools", "extras"];
373+
if (!androidHomeEnvVar || !this.$fs.exists(androidHomeEnvVar)) {
374+
this.printMessage("The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android.",
375+
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory.");
376+
this._cachedAndroidHomeValidationResult = false;
377+
} else if (!_.some(expectedDirectoriesInAndroidHome.map(dir => this.$fs.exists(path.join(androidHomeEnvVar, dir))))) {
378+
this.printMessage("The ANDROID_HOME environment variable points to incorrect directory. You will not be able to perform any build-related operations for Android.",
379+
"To be able to perform Android build-related operations, set the `ANDROID_HOME` variable to point to the root of your Android SDK installation directory, " +
380+
"where you will find `tools` and `platform-tools` directories.");
381+
this._cachedAndroidHomeValidationResult = false;
384382
}
383+
}
385384

386-
return this._cachedAndroidHomeValidationResult;
387-
}).future<boolean>()();
385+
return this._cachedAndroidHomeValidationResult;
388386
}
389387
}
390388
$injector.register("androidToolsInfo", AndroidToolsInfo);

lib/commands/install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class InstallCommand implements ICommand {
4949
let projectDir = this.$projectData.projectDir;
5050

5151
let devPrefix = 'nativescript-dev-';
52-
if (!this.$fs.exists(moduleName).wait() && moduleName.indexOf(devPrefix) !== 0) {
52+
if (!this.$fs.exists(moduleName) && moduleName.indexOf(devPrefix) !== 0) {
5353
moduleName = devPrefix + moduleName;
5454
}
5555

lib/commands/list-platforms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class ListPlatformsCommand implements ICommand {
99
let installedPlatforms = this.$platformService.getInstalledPlatforms().wait();
1010

1111
if(installedPlatforms.length > 0) {
12-
let preparedPlatforms = this.$platformService.getPreparedPlatforms().wait();
12+
let preparedPlatforms = this.$platformService.getPreparedPlatforms();
1313
if(preparedPlatforms.length > 0) {
1414
this.$logger.out("The project is prepared for: ", helpers.formatListOfNames(preparedPlatforms, "and"));
1515
} else {

lib/commands/test-init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TestInitCommand implements ICommand {
4141

4242
let testsDir = path.join(projectDir, 'app/tests');
4343
let shouldCreateSampleTests = true;
44-
if (this.$fs.exists(testsDir).wait()) {
44+
if (this.$fs.exists(testsDir)) {
4545
this.$logger.info('app/tests/ directory already exists, will not create an example test project.');
4646
shouldCreateSampleTests = false;
4747
}
@@ -59,7 +59,7 @@ class TestInitCommand implements ICommand {
5959

6060
let exampleFilePath = this.$resources.resolvePath(`test/example.${frameworkToInstall}.js`);
6161

62-
if (shouldCreateSampleTests && this.$fs.exists(exampleFilePath).wait()) {
62+
if (shouldCreateSampleTests && this.$fs.exists(exampleFilePath)) {
6363
this.$fs.copyFile(exampleFilePath, path.join(testsDir, 'example.js')).wait();
6464
this.$logger.info('\nExample test file created in app/tests/'.yellow);
6565
} else {

lib/common

Submodule common updated 50 files

lib/definitions/platform.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ interface IPlatformService {
22
addPlatforms(platforms: string[]): IFuture<void>;
33
getInstalledPlatforms(): IFuture<string[]>;
44
getAvailablePlatforms(): IFuture<string[]>;
5-
getPreparedPlatforms(): IFuture<string[]>;
5+
6+
/**
7+
* Returns a list of all currently prepared platforms.
8+
* @returns {string[]} List of all prepared platforms.
9+
*/
10+
getPreparedPlatforms(): string[];
11+
612
removePlatforms(platforms: string[]): IFuture<void>;
713
updatePlatforms(platforms: string[]): IFuture<void>;
814
preparePlatform(platform: string, force?: boolean, skipModulesAndResources?: boolean): IFuture<boolean>;

lib/definitions/project.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ interface IPlatformProjectService {
7474
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
7575
prepareProject(): IFuture<void>;
7676
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void>;
77-
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
77+
78+
/**
79+
* Defines if current platform is prepared (i.e. if <project dir>/platforms/<platform> dir exists).
80+
* @param {string} projectRoot The project directory (path where root's package.json is located).
81+
* @returns {boolean} True in case platform is prepare (i.e. if <project dir>/platforms/<platform> dir exists), false otherwise.
82+
*/
83+
isPlatformPrepared(projectRoot: string): boolean;
84+
7885
canUpdatePlatform(newInstalledModuleDir: string): IFuture<boolean>;
7986
preparePluginNativeCode(pluginData: IPluginData, options?: any): IFuture<void>;
8087
removePluginNativeCode(pluginData: IPluginData): IFuture<void>;

lib/dynamic-help-provider.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import * as constants from './constants';
2-
import Future = require("fibers/future");
32

43
export class DynamicHelpProvider implements IDynamicHelpProvider {
5-
public isProjectType(args: string[]): IFuture<boolean> {
6-
return Future.fromResult(true);
4+
public isProjectType(args: string[]): boolean {
5+
return true;
76
}
87

9-
public getLocalVariables(options: { isHtml: boolean }): IFuture<IDictionary<any>> {
8+
public getLocalVariables(options: { isHtml: boolean }): IDictionary<any> {
109
let localVariables: IDictionary<any> = {
1110
constants: constants
1211
};
13-
return Future.fromResult(localVariables);
12+
return localVariables;
1413
}
1514
}
1615
$injector.register("dynamicHelpProvider", DynamicHelpProvider);

lib/node-package-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class NodePackageManager implements INodePackageManager {
3939
let relativePathFromCwdToSource = "";
4040
if(this.$options.frameworkPath) {
4141
relativePathFromCwdToSource = path.relative(this.$options.frameworkPath, pathToSave);
42-
if(this.$fs.exists(relativePathFromCwdToSource).wait()) {
42+
if(this.$fs.exists(relativePathFromCwdToSource)) {
4343
packageName = relativePathFromCwdToSource;
4444
}
4545
}

lib/npm-installation-manager.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ export class NpmInstallationManager implements INpmInstallationManager {
6363
let inspectorPath = path.join(projectDir, "node_modules", inspectorNpmPackageName);
6464

6565
// local installation takes precedence over cache
66-
if(!this.inspectorAlreadyInstalled(inspectorPath).wait()) {
66+
if(!this.inspectorAlreadyInstalled(inspectorPath)) {
6767
let cachepath = this.$childProcess.exec("npm get cache").wait().trim();
6868
let version = this.getLatestCompatibleVersion(inspectorNpmPackageName).wait();
6969
let pathToPackageInCache = path.join(cachepath, inspectorNpmPackageName, version);
7070
let pathToUnzippedInspector = path.join(pathToPackageInCache, "package");
7171

72-
if(!this.$fs.exists(pathToPackageInCache).wait()) {
72+
if(!this.$fs.exists(pathToPackageInCache)) {
7373
this.$childProcess.exec(`npm cache add ${inspectorNpmPackageName}@${version}`).wait();
7474
let inspectorTgzPathInCache = path.join(pathToPackageInCache, "package.tgz");
7575
this.$childProcess.exec(`tar -xf ${inspectorTgzPathInCache} -C ${pathToPackageInCache}`).wait();
@@ -82,26 +82,24 @@ export class NpmInstallationManager implements INpmInstallationManager {
8282
}).future<string>()();
8383
}
8484

85-
private inspectorAlreadyInstalled(pathToInspector: string): IFuture<Boolean> {
86-
return (() => {
87-
if(this.$fs.exists(pathToInspector).wait()) {
88-
return true;
89-
}
90-
return false;
91-
}).future<Boolean>()();
85+
private inspectorAlreadyInstalled(pathToInspector: string): Boolean {
86+
if(this.$fs.exists(pathToInspector)) {
87+
return true;
88+
}
89+
return false;
9290
}
9391

9492
private installCore(packageName: string, pathToSave: string, version: string, dependencyType: string): IFuture<string> {
9593
return (() => {
9694
const possiblePackageName= path.resolve(packageName);
97-
if(this.$fs.exists(possiblePackageName).wait()) {
95+
if(this.$fs.exists(possiblePackageName)) {
9896
packageName = possiblePackageName;
9997
}
10098
if(packageName.indexOf(".tgz") >= 0) {
10199
version = null;
102100
}
103101
// check if the packageName is url or local file and if it is, let npm install deal with the version
104-
if(this.isURL(packageName) || this.$fs.exists(packageName).wait()) {
102+
if(this.isURL(packageName) || this.$fs.exists(packageName)) {
105103
version = null;
106104
} else {
107105
version = version || this.getLatestCompatibleVersion(packageName).wait();

0 commit comments

Comments
 (0)