Skip to content

Commit 981d19c

Browse files
Make fs.readJson and config.loadConfig sync
1 parent 822969b commit 981d19c

23 files changed

+201
-203
lines changed

lib/commands/plugin/list-plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class ListPluginsCommand implements ICommand {
88

99
public execute(args: string[]): IFuture<void> {
1010
return (() => {
11-
let installedPlugins: IPackageJsonDepedenciesResult = this.$pluginsService.getDependenciesFromPackageJson().wait();
11+
let installedPlugins: IPackageJsonDepedenciesResult = this.$pluginsService.getDependenciesFromPackageJson();
1212

1313
let headers: string[] = ["Plugin", "Version"];
1414
let dependenciesData: string[][] = this.createTableCells(installedPlugins.dependencies);

lib/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class Configuration extends ConfigBase implements IConfiguration { // Use
1414
/*don't require logger and everything that has logger as dependency in config.js due to cyclic dependency*/
1515
constructor(protected $fs: IFileSystem) {
1616
super($fs);
17-
_.extend(this, this.loadConfig("config").wait());
17+
_.extend(this, this.loadConfig("config"));
1818
}
1919
}
2020
$injector.register("config", Configuration);

lib/declarations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,16 @@ interface IXmlValidator {
257257
/**
258258
* Checks the passed xml files for errors and if such exists, print them on the stdout.
259259
* @param {string[]} sourceFiles Files to be checked. Only the ones that ends with .xml are filtered.
260-
* @return {IFuture<boolean>} true in case there are no errors in specified files and false in case there's at least one error.
260+
* @return {boolean} true in case there are no errors in specified files and false in case there's at least one error.
261261
*/
262-
validateXmlFiles(sourceFiles: string[]): IFuture<boolean>;
262+
validateXmlFiles(sourceFiles: string[]): boolean;
263263

264264
/**
265265
* Checks the passed xml file for errors and returns them as a result.
266266
* @param {string} sourceFile File to be checked.
267-
* @return {IFuture<string>} The errors detected (as a single string) or null in case there are no errors.
267+
* @return {string} The errors detected (as a single string) or null in case there are no errors.
268268
*/
269-
getXmlFileErrors(sourceFile: string): IFuture<string>;
269+
getXmlFileErrors(sourceFile: string): string;
270270
}
271271

272272
/**

lib/definitions/plugins.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ interface IPluginsService {
55
prepare(pluginData: IDependencyData, platform: string): IFuture<void>;
66
getAllInstalledPlugins(): IFuture<IPluginData[]>;
77
ensureAllDependenciesAreInstalled(): IFuture<void>;
8-
getDependenciesFromPackageJson(): IFuture<IPackageJsonDepedenciesResult>
8+
9+
/**
10+
* Returns all dependencies and devDependencies from pacakge.json file.
11+
* @returns {IPackageJsonDepedenciesResult}
12+
*/
13+
getDependenciesFromPackageJson(): IPackageJsonDepedenciesResult;
914
}
1015

1116
interface IPackageJsonDepedenciesResult {

lib/node-package-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class NodePackageManager implements INodePackageManager {
2424
config["ignore-scripts"] = true;
2525
}
2626

27-
let jsonContentBefore = this.$fs.readJson(path.join(pathToSave, "package.json")).wait();
27+
let jsonContentBefore = this.$fs.readJson(path.join(pathToSave, "package.json"));
2828
let dependenciesBefore = _.keys(jsonContentBefore.dependencies).concat(_.keys(jsonContentBefore.devDependencies));
2929

3030
let flags = this.getFlagsString(config, true);
@@ -58,7 +58,7 @@ export class NodePackageManager implements INodePackageManager {
5858
}
5959
}
6060

61-
let jsonContentAfter = this.$fs.readJson(path.join(pathToSave, "package.json")).wait();
61+
let jsonContentAfter = this.$fs.readJson(path.join(pathToSave, "package.json"));
6262
let dependenciesAfter = _.keys(jsonContentAfter.dependencies).concat(_.keys(jsonContentAfter.devDependencies));
6363

6464
/** This diff is done in case the installed pakcage is a URL address, a path to local directory or a .tgz file

lib/npm-installation-manager.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
1515
}
1616

1717
public getLatestVersion(packageName: string): IFuture<string> {
18-
return(() => {
18+
return (() => {
1919
return this.getVersion(packageName, constants.PackageVersion.LATEST).wait();
2020
}).future<string>()();
2121
}
@@ -31,10 +31,10 @@ export class NpmInstallationManager implements INpmInstallationManager {
3131

3232
let cliVersionRange = `~${this.$staticConfig.version}`;
3333
let latestVersion = this.getLatestVersion(packageName).wait();
34-
if(semver.satisfies(latestVersion, cliVersionRange)) {
34+
if (semver.satisfies(latestVersion, cliVersionRange)) {
3535
return latestVersion;
3636
}
37-
let data = this.$npm.view(packageName, {json: true, "versions": true}).wait();
37+
let data = this.$npm.view(packageName, { json: true, "versions": true }).wait();
3838

3939
return semver.maxSatisfying(data, cliVersionRange) || latestVersion;
4040
}).future<string>()();
@@ -50,26 +50,26 @@ export class NpmInstallationManager implements INpmInstallationManager {
5050
let dependencyType = (opts && opts.dependencyType) || null;
5151

5252
return this.installCore(packageToInstall, pathToSave, version, dependencyType).wait();
53-
} catch(error) {
53+
} catch (error) {
5454
this.$logger.debug(error);
5555
this.$errors.fail("%s. Error: %s", NpmInstallationManager.NPM_LOAD_FAILED, error);
5656
}
5757

5858
}).future<string>()();
5959
}
6060

61-
public getInspectorFromCache(inspectorNpmPackageName: string, projectDir: string) : IFuture<string> {
61+
public getInspectorFromCache(inspectorNpmPackageName: string, projectDir: string): IFuture<string> {
6262
return (() => {
6363
let inspectorPath = path.join(projectDir, "node_modules", inspectorNpmPackageName);
6464

6565
// local installation takes precedence over cache
66-
if(!this.inspectorAlreadyInstalled(inspectorPath)) {
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)) {
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();
@@ -83,30 +83,30 @@ export class NpmInstallationManager implements INpmInstallationManager {
8383
}
8484

8585
private inspectorAlreadyInstalled(pathToInspector: string): Boolean {
86-
if(this.$fs.exists(pathToInspector)) {
86+
if (this.$fs.exists(pathToInspector)) {
8787
return true;
8888
}
8989
return false;
9090
}
9191

9292
private installCore(packageName: string, pathToSave: string, version: string, dependencyType: string): IFuture<string> {
9393
return (() => {
94-
const possiblePackageName= path.resolve(packageName);
95-
if(this.$fs.exists(possiblePackageName)) {
94+
const possiblePackageName = path.resolve(packageName);
95+
if (this.$fs.exists(possiblePackageName)) {
9696
packageName = possiblePackageName;
9797
}
98-
if(packageName.indexOf(".tgz") >= 0) {
98+
if (packageName.indexOf(".tgz") >= 0) {
9999
version = null;
100100
}
101101
// check if the packageName is url or local file and if it is, let npm install deal with the version
102-
if(this.isURL(packageName) || this.$fs.exists(packageName)) {
102+
if (this.isURL(packageName) || this.$fs.exists(packageName)) {
103103
version = null;
104104
} else {
105105
version = version || this.getLatestCompatibleVersion(packageName).wait();
106106
}
107107

108108
let installedModuleNames = this.npmInstall(packageName, pathToSave, version, dependencyType).wait();
109-
let installedPackageName = installedModuleNames[0];
109+
let installedPackageName = installedModuleNames[0];
110110

111111
let pathToInstalledPackage = path.join(pathToSave, "node_modules", installedPackageName);
112112
return pathToInstalledPackage;
@@ -120,18 +120,18 @@ export class NpmInstallationManager implements INpmInstallationManager {
120120
}
121121

122122
private npmInstall(packageName: string, pathToSave: string, version: string, dependencyType: string): IFuture<any> {
123-
return(() => {
123+
return (() => {
124124
this.$logger.out("Installing ", packageName);
125125

126126
packageName = packageName + (version ? `@${version}` : "");
127127

128-
let npmOptions: any = {silent: true};
128+
let npmOptions: any = { silent: true };
129129

130-
if(dependencyType) {
130+
if (dependencyType) {
131131
npmOptions[dependencyType] = true;
132132
}
133133

134-
return this.$npm.install(packageName , pathToSave, npmOptions).wait();
134+
return this.$npm.install(packageName, pathToSave, npmOptions).wait();
135135
}).future<any>()();
136136
}
137137

@@ -141,7 +141,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
141141
*/
142142
private getVersion(packageName: string, version: string): IFuture<string> {
143143
return (() => {
144-
let data:any = this.$npm.view(packageName, {json: true, "dist-tags": true}).wait();
144+
let data: any = this.$npm.view(packageName, { json: true, "dist-tags": true }).wait();
145145
this.$logger.trace("Using version %s. ", data[version]);
146146

147147
return data[version];

lib/project-data.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as constants from "./constants";
22
import * as path from "path";
3-
import {EOL} from "os";
3+
import { EOL } from "os";
44

55
export class ProjectData implements IProjectData {
66
private static OLD_PROJECT_FILE_NAME = ".tnsproject";
@@ -24,27 +24,29 @@ export class ProjectData implements IProjectData {
2424
}
2525

2626
private initializeProjectData(): IFuture<void> {
27-
return(() => {
27+
return (() => {
2828
let projectDir = this.$projectHelper.projectDir;
2929
// If no project found, projectDir should be null
30-
if(projectDir) {
30+
if (projectDir) {
3131
this.initializeProjectDataCore(projectDir);
3232
let data: any = null;
3333

3434
if (this.$fs.exists(this.projectFilePath)) {
3535
let fileContent: any = null;
3636
try {
37-
fileContent = this.$fs.readJson(this.projectFilePath).wait();
37+
fileContent = this.$fs.readJson(this.projectFilePath);
3838
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
3939
} catch (err) {
40-
this.$errors.fail({formatStr: "The project file %s is corrupted." + EOL +
40+
this.$errors.fail({
41+
formatStr: "The project file %s is corrupted." + EOL +
4142
"Consider restoring an earlier version from your source control or backup." + EOL +
4243
"Additional technical info: %s",
43-
suppressCommandHelp: true},
44+
suppressCommandHelp: true
45+
},
4446
this.projectFilePath, err.toString());
4547
}
4648

47-
if(data) {
49+
if (data) {
4850
this.projectId = data.id;
4951
this.dependencies = fileContent.dependencies;
5052
} else { // This is the case when we have package.json file but nativescipt key is not presented in it
@@ -65,7 +67,7 @@ export class ProjectData implements IProjectData {
6567
return (() => {
6668
let projectDir = this.projectDir || path.resolve(this.$options.path || ".");
6769
let oldProjectFilePath = path.join(projectDir, ProjectData.OLD_PROJECT_FILE_NAME);
68-
if(this.$fs.exists(oldProjectFilePath)) {
70+
if (this.$fs.exists(oldProjectFilePath)) {
6971
this.upgrade(projectDir, oldProjectFilePath).wait();
7072
} else {
7173
this.throwNoProjectFoundError();
@@ -76,16 +78,16 @@ export class ProjectData implements IProjectData {
7678
private upgrade(projectDir: string, oldProjectFilePath: string): IFuture<void> {
7779
return (() => {
7880
try {
79-
let oldProjectData = this.$fs.readJson(oldProjectFilePath).wait();
81+
let oldProjectData = this.$fs.readJson(oldProjectFilePath);
8082

8183
let newProjectFilePath = this.projectFilePath || path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
82-
let newProjectData = this.$fs.exists(newProjectFilePath) ? this.$fs.readJson(newProjectFilePath).wait() : {};
84+
let newProjectData = this.$fs.exists(newProjectFilePath) ? this.$fs.readJson(newProjectFilePath) : {};
8385
newProjectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE] = oldProjectData;
8486
this.$fs.writeJson(newProjectFilePath, newProjectData).wait();
8587
this.projectId = newProjectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE].id;
8688

8789
this.$fs.deleteFile(oldProjectFilePath);
88-
} catch(err) {
90+
} catch (err) {
8991
this.$logger.out("An error occurred while upgrading your project.");
9092
throw err;
9193
}

lib/services/android-project-service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import Future = require("fibers/future");
44
import * as constants from "../constants";
55
import * as semver from "semver";
66
import * as projectServiceBaseLib from "./platform-project-service-base";
7-
import {DeviceAndroidDebugBridge} from "../common/mobile/android/device-android-debug-bridge";
8-
import {AndroidDeviceHashService} from "../common/mobile/android/android-device-hash-service";
9-
import {EOL} from "os";
7+
import { DeviceAndroidDebugBridge } from "../common/mobile/android/device-android-debug-bridge";
8+
import { AndroidDeviceHashService } from "../common/mobile/android/android-device-hash-service";
9+
import { EOL } from "os";
1010

1111
export class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
1212
private static VALUES_DIRNAME = "values";
@@ -134,7 +134,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
134134
"silent": true
135135
};
136136

137-
let projectPackageJson: any = this.$fs.readJson(this.$projectData.projectFilePath).wait();
137+
let projectPackageJson: any = this.$fs.readJson(this.$projectData.projectFilePath);
138138

139139
_.each(AndroidProjectService.REQUIRED_DEV_DEPENDENCIES, (dependency: any) => {
140140
let dependencyVersionInProject = (projectPackageJson.dependencies && projectPackageJson.dependencies[dependency.name]) ||
@@ -148,7 +148,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
148148
// The plugin version is not valid. Check node_modules for the valid version.
149149
if (!cleanedVerson) {
150150
let pathToPluginPackageJson = path.join(this.$projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME, dependency.name, constants.PACKAGE_JSON_FILE_NAME);
151-
dependencyVersionInProject = this.$fs.exists(pathToPluginPackageJson) && this.$fs.readJson(pathToPluginPackageJson).wait().version;
151+
dependencyVersionInProject = this.$fs.exists(pathToPluginPackageJson) && this.$fs.readJson(pathToPluginPackageJson).version;
152152
}
153153

154154
if (!semver.satisfies(dependencyVersionInProject || cleanedVerson, dependency.version)) {
@@ -312,7 +312,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
312312
let originalAndroidManifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName);
313313

314314
let manifestExists = this.$fs.exists(originalAndroidManifestFilePath);
315-
if(!manifestExists) {
315+
if (!manifestExists) {
316316
this.$logger.warn('No manifest found in ' + originalAndroidManifestFilePath);
317317
return;
318318
}

lib/services/init-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class InitService implements IInitService {
2929
let projectData: any = {};
3030

3131
if (this.$fs.exists(this.projectFilePath)) {
32-
projectData = this.$fs.readJson(this.projectFilePath).wait();
32+
projectData = this.$fs.readJson(this.projectFilePath);
3333
}
3434

3535
let projectDataBackup = _.extend({}, projectData);

lib/services/platform-service.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as shell from "shelljs";
33
import * as constants from "../constants";
44
import * as helpers from "../common/helpers";
55
import * as semver from "semver";
6-
import {AppFilesUpdater} from "./app-files-updater";
6+
import { AppFilesUpdater } from "./app-files-updater";
77
import * as temp from "temp";
8-
import {ProjectChangesInfo, IPrepareInfo} from "./project-changes-info";
8+
import { ProjectChangesInfo, IPrepareInfo } from "./project-changes-info";
99
import Future = require("fibers/future");
1010
temp.track();
1111
let clui = require("clui");
@@ -99,7 +99,7 @@ export class PlatformService implements IPlatformService {
9999
frameworkDir = path.resolve(frameworkDir);
100100

101101
let coreModuleName = this.addPlatformCore(platformData, frameworkDir).wait();
102-
this.$npm.uninstall(coreModuleName, {save: true}, this.$projectData.projectDir).wait();
102+
this.$npm.uninstall(coreModuleName, { save: true }, this.$projectData.projectDir).wait();
103103
} catch (err) {
104104
this.$fs.deleteDirectory(platformPath);
105105
throw err;
@@ -114,7 +114,7 @@ export class PlatformService implements IPlatformService {
114114

115115
private addPlatformCore(platformData: IPlatformData, frameworkDir: string): IFuture<string> {
116116
return (() => {
117-
let coreModuleData = this.$fs.readJson(path.join(frameworkDir, "../", "package.json")).wait();
117+
let coreModuleData = this.$fs.readJson(path.join(frameworkDir, "../", "package.json"));
118118
let installedVersion = coreModuleData.version;
119119
let coreModuleName = coreModuleData.name;
120120

@@ -216,7 +216,7 @@ export class PlatformService implements IPlatformService {
216216

217217
this.ensurePlatformInstalled(platform).wait();
218218

219-
let changeInfo:ProjectChangesInfo = new ProjectChangesInfo(platform, force, skipModulesAndResources, this.$platformsData, this.$projectData, this.$devicePlatformsConstants, this.$options, this.$fs);
219+
let changeInfo: ProjectChangesInfo = new ProjectChangesInfo(platform, force, skipModulesAndResources, this.$platformsData, this.$projectData, this.$devicePlatformsConstants, this.$options, this.$fs);
220220
this._prepareInfo = changeInfo.prepareInfo;
221221
if (!this.isPlatformPrepared(platform) || changeInfo.hasChanges) {
222222
this.preparePlatformCore(platform, changeInfo).wait();
@@ -227,7 +227,7 @@ export class PlatformService implements IPlatformService {
227227
}
228228

229229
@helpers.hook('prepare')
230-
private preparePlatformCore(platform: string, changeInfo:ProjectChangesInfo): IFuture<void> {
230+
private preparePlatformCore(platform: string, changeInfo: ProjectChangesInfo): IFuture<void> {
231231
return (() => {
232232

233233
let platformData = this.$platformsData.getPlatformData(platform);
@@ -257,7 +257,7 @@ export class PlatformService implements IPlatformService {
257257

258258
platformData.platformProjectService.interpolateConfigurationFile().wait();
259259

260-
this.$logger.out("Project successfully prepared ("+platform+")");
260+
this.$logger.out("Project successfully prepared (" + platform + ")");
261261
}).future<void>()();
262262
}
263263

@@ -273,7 +273,7 @@ export class PlatformService implements IPlatformService {
273273

274274
const appUpdater = new AppFilesUpdater(appSourceDirectoryPath, appDestinationDirectoryPath, this.$options, this.$fs);
275275
appUpdater.updateApp(sourceFiles => {
276-
this.$xmlValidator.validateXmlFiles(sourceFiles).wait();
276+
this.$xmlValidator.validateXmlFiles(sourceFiles);
277277
});
278278
}).future<void>()();
279279
}
@@ -607,12 +607,12 @@ export class PlatformService implements IPlatformService {
607607
let newVersion = version === constants.PackageVersion.NEXT ?
608608
this.$npmInstallationManager.getNextVersion(platformData.frameworkPackageName).wait() :
609609
version || this.$npmInstallationManager.getLatestCompatibleVersion(platformData.frameworkPackageName).wait();
610-
let installedModuleDir = this.$npmInstallationManager.install(platformData.frameworkPackageName, this.$projectData.projectDir, {version: newVersion, dependencyType: "save"}).wait();
611-
let cachedPackageData = this.$fs.readJson(path.join(installedModuleDir, "package.json")).wait();
610+
let installedModuleDir = this.$npmInstallationManager.install(platformData.frameworkPackageName, this.$projectData.projectDir, { version: newVersion, dependencyType: "save" }).wait();
611+
let cachedPackageData = this.$fs.readJson(path.join(installedModuleDir, "package.json"));
612612
newVersion = (cachedPackageData && cachedPackageData.version) || newVersion;
613613

614614
let canUpdate = platformData.platformProjectService.canUpdatePlatform(installedModuleDir).wait();
615-
this.$npm.uninstall(platformData.frameworkPackageName, {save: true}, this.$projectData.projectDir).wait();
615+
this.$npm.uninstall(platformData.frameworkPackageName, { save: true }, this.$projectData.projectDir).wait();
616616
if (canUpdate) {
617617
if (!semver.valid(newVersion)) {
618618
this.$errors.fail("The version %s is not valid. The version should consists from 3 parts separated by dot.", newVersion);

0 commit comments

Comments
 (0)