Skip to content

Commit d906519

Browse files
committed
Fix coding style. Improve implmentation. Add try-catch block for prepareNodeModules.
1 parent ac715c3 commit d906519

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

lib/node-package-manager.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ export class NodePackageManager implements INodePackageManager {
5656
}
5757

5858
public executeNpmCommand(npmCommandName: string, currentWorkingDirectory: string): IFuture<any> {
59-
return (() => {
60-
return this.$childProcess.exec(npmCommandName, { cwd: currentWorkingDirectory }).wait();
61-
}).future<any>()();
59+
return this.$childProcess.exec(npmCommandName, { cwd: currentWorkingDirectory });
6260
}
6361

6462
private loadAndExecute(commandName: string, args: any[], opts?: { config?: any, subCommandName?: string }): IFuture<any> {

lib/services/platform-service.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,16 @@ export class PlatformService implements IPlatformService {
175175
platformData.platformProjectService.prepareProject().wait();
176176

177177
// Process node_modules folder
178-
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
179-
let tnsModulesDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, PlatformService.TNS_MODULES_FOLDER_NAME);
180-
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, this.$projectData.projectDir, platform, lastModifiedTime).wait();
181-
178+
try {
179+
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
180+
let tnsModulesDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, PlatformService.TNS_MODULES_FOLDER_NAME);
181+
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, this.$projectData.projectDir, platform, lastModifiedTime).wait();
182+
} catch(error) {
183+
this.$logger.debug(error);
184+
this.$errors.fail(`Processing node_modules failed. Error:${error}`);
185+
shell.rm("-rf", appResourcesDirectoryPath);
186+
}
187+
182188
// Process platform specific files
183189
let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
184190
let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME];

lib/services/project-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ export class ProjectService implements IProjectService {
113113
this.$projectDataService.initialize(projectDir);
114114
this.$projectDataService.setValue("id", projectId).wait();
115115

116-
let tnsModulesVersion: string = this.$options.tnsModulesVersion;
117-
let packageName: string = constants.TNS_CORE_MODULES_NAME;
116+
let tnsModulesVersion = this.$options.tnsModulesVersion;
117+
let packageName = constants.TNS_CORE_MODULES_NAME;
118118
if (tnsModulesVersion) {
119-
packageName = packageName.concat("@" + tnsModulesVersion);
119+
packageName = `${packageName}@${tnsModulesVersion}`;
120120
}
121121

122-
this.$npm.executeNpmCommand("npm install " + packageName + " --save --save-exact", projectDir).wait();
122+
this.$npm.executeNpmCommand(`npm install ${packageName} --save --save-exact`, projectDir).wait();
123123
}).future<void>()();
124124
}
125125

test/project-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"use strict";
33

44
import yok = require('../lib/common/yok');
5-
import ChildProcessLib = require("../lib/common/child-process");
65
import stubs = require('./stubs');
7-
import constants = require("./../lib/constants");
6+
import * as constants from "./../lib/constants";
7+
import * as ChildProcessLib from "../lib/common/child-process";
88

99
import ProjectServiceLib = require("../lib/services/project-service");
1010
import ProjectDataServiceLib = require("../lib/services/project-data-service");
@@ -88,7 +88,7 @@ class ProjectIntegrationTest {
8888
assert.equal(actualAppId, expectedAppId);
8989

9090
let tnsCoreModulesRecord = fs.readJson(tnsProjectFilePath).wait()["dependencies"][constants.TNS_CORE_MODULES_NAME];
91-
assert.isTrue(tnsCoreModulesRecord != null);
91+
assert.isTrue(tnsCoreModulesRecord !== null);
9292

9393
var actualFiles = fs.enumerateFilesInDirectorySync(options.copyFrom);
9494
var expectedFiles = fs.enumerateFilesInDirectorySync(appDirectoryPath);

0 commit comments

Comments
 (0)