diff --git a/lib/declarations.ts b/lib/declarations.ts index 4bbe0e267f..0c68366626 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -2,7 +2,7 @@ interface INodePackageManager { getCache(): string; load(config?: any): IFuture; install(packageName: string, pathToSave: string, config?: any): IFuture; - uninstall(packageName: string, config?: any): IFuture; + uninstall(packageName: string, config?: any, path?: string): IFuture; cache(packageName: string, version: string, cache?: any): IFuture; cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture; view(packageName: string, propertyName: string): IFuture; diff --git a/lib/definitions/npm.d.ts b/lib/definitions/npm.d.ts index f34a477220..9cb8c86d6b 100644 --- a/lib/definitions/npm.d.ts +++ b/lib/definitions/npm.d.ts @@ -1,5 +1,6 @@ - declare module "npm" { +declare module "npm" { var cache: any; var commands: { [index: string]: any }; + var prefix: string; function load(config: Object, callback: (err: any, data: any) => void): void; } \ No newline at end of file diff --git a/lib/node-package-manager.ts b/lib/node-package-manager.ts index 9e18b9fd99..79ed92e7d2 100644 --- a/lib/node-package-manager.ts +++ b/lib/node-package-manager.ts @@ -4,6 +4,12 @@ import Future = require("fibers/future"); import * as npm from "npm"; +interface INpmOpts { + config?: any; + subCommandName?: string; + path?: string; +} + export class NodePackageManager implements INodePackageManager { constructor(private $childProcess: IChildProcess, private $options: IOptions) { } @@ -33,8 +39,8 @@ export class NodePackageManager implements INodePackageManager { return this.loadAndExecute("install", [pathToSave, packageName], { config: config }); } - public uninstall(packageName: string, config?: any): IFuture { - return this.loadAndExecute("uninstall", [[packageName]], { config: config }); + public uninstall(packageName: string, config?: any, path?: string): IFuture { + return this.loadAndExecute("uninstall", [[packageName]], { config, path}); } public cache(packageName: string, version: string, config?: any): IFuture { @@ -55,17 +61,22 @@ export class NodePackageManager implements INodePackageManager { return this.$childProcess.exec(npmCommandName, { cwd: currentWorkingDirectory }); } - private loadAndExecute(commandName: string, args: any[], opts?: { config?: any, subCommandName?: string }): IFuture { + private loadAndExecute(commandName: string, args: any[], opts?: INpmOpts): IFuture { return (() => { opts = opts || {}; this.load(opts.config).wait(); - return this.executeCore(commandName, args, opts.subCommandName).wait(); + return this.executeCore(commandName, args, opts).wait(); }).future()(); } - private executeCore(commandName: string, args: any[], subCommandName?: string): IFuture { + private executeCore(commandName: string, args: any[], opts?: INpmOpts): IFuture { let future = new Future(); + let oldNpmPath: string = undefined; let callback = (err: Error, data: any) => { + if (oldNpmPath) { + npm.prefix = oldNpmPath; + } + if(err) { future.throw(err); } else { @@ -74,6 +85,12 @@ export class NodePackageManager implements INodePackageManager { }; args.push(callback); + if (opts && opts.path) { + oldNpmPath = npm.prefix; + npm.prefix = opts.path; + } + + let subCommandName: string = opts.subCommandName; let command = subCommandName ? npm.commands[commandName][subCommandName] : npm.commands[commandName]; command.apply(this, args); diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index e2f8af0918..2c7837d7f4 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -24,7 +24,6 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService private $childProcess: IChildProcess, private $errors: IErrors, private $hostInfo: IHostInfo, - private $injector: IInjector, private $logger: ILogger, private $options: IOptions, private $projectData: IProjectData, @@ -259,12 +258,20 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService public removePluginNativeCode(pluginData: IPluginData): IFuture { return (() => { - let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME); - let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME); + try { + let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME); + let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME); - if(this.$fs.exists(libsFolderPath).wait()) { - let pluginJars = this.$fs.enumerateFilesInDirectorySync(libsFolderPath); - _.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait()); + if(this.$fs.exists(libsFolderPath).wait()) { + let pluginJars = this.$fs.enumerateFilesInDirectorySync(libsFolderPath); + _.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait()); + } + } catch(e) { + if (e.code === "ENOENT") { + this.$logger.debug("No native code jars found: " + e.message); + } else { + throw e; + } } }).future()(); } diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 0350486aac..4353855322 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -231,7 +231,7 @@ export class PluginsService implements IPluginsService { if(npmCommandName === PluginsService.INSTALL_COMMAND_NAME) { result = this.$npm.install(npmCommandArguments, this.$projectData.projectDir, PluginsService.NPM_CONFIG).wait(); } else if(npmCommandName === PluginsService.UNINSTALL_COMMAND_NAME) { - result = this.$npm.uninstall(npmCommandArguments, PluginsService.NPM_CONFIG).wait(); + result = this.$npm.uninstall(npmCommandArguments, PluginsService.NPM_CONFIG, this.$projectData.projectDir).wait(); } return this.parseNpmCommandResult(result);