Skip to content

Commit 2a68d08

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

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
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.$logger.error("Processing tns core modules failed.");
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ export class ProjectService implements IProjectService {
116116
let tnsModulesVersion: string = this.$options.tnsModulesVersion;
117117
let packageName: string = 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)