Skip to content

Commit 26edcad

Browse files
teobugslayerFatme Havaluova
authored and
Fatme Havaluova
committed
Plugin remove works with --path option
See #575
1 parent 6f40e15 commit 26edcad

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

lib/declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interface INodePackageManager {
22
getCache(): string;
33
load(config?: any): IFuture<void>;
44
install(packageName: string, pathToSave: string, config?: any): IFuture<any>;
5-
uninstall(packageName: string, config?: any): IFuture<any>;
5+
uninstall(packageName: string, config?: any, path?: string): IFuture<any>;
66
cache(packageName: string, version: string, cache?: any): IFuture<IDependencyData>;
77
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
88
view(packageName: string, propertyName: string): IFuture<any>;

lib/definitions/npm.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
declare module "npm" {
1+
declare module "npm" {
22
var cache: any;
33
var commands: { [index: string]: any };
4+
var prefix: string;
45
function load(config: Object, callback: (err: any, data: any) => void): void;
56
}

lib/node-package-manager.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
import Future = require("fibers/future");
55
import * as npm from "npm";
66

7+
interface INpmOpts {
8+
config?: any;
9+
subCommandName?: string;
10+
path?: string;
11+
}
12+
713
export class NodePackageManager implements INodePackageManager {
814
constructor(private $childProcess: IChildProcess,
915
private $options: IOptions) { }
@@ -33,8 +39,8 @@ export class NodePackageManager implements INodePackageManager {
3339
return this.loadAndExecute("install", [pathToSave, packageName], { config: config });
3440
}
3541

36-
public uninstall(packageName: string, config?: any): IFuture<any> {
37-
return this.loadAndExecute("uninstall", [[packageName]], { config: config });
42+
public uninstall(packageName: string, config?: any, path?: string): IFuture<any> {
43+
return this.loadAndExecute("uninstall", [[packageName]], { config, path});
3844
}
3945

4046
public cache(packageName: string, version: string, config?: any): IFuture<IDependencyData> {
@@ -55,17 +61,22 @@ export class NodePackageManager implements INodePackageManager {
5561
return this.$childProcess.exec(npmCommandName, { cwd: currentWorkingDirectory });
5662
}
5763

58-
private loadAndExecute(commandName: string, args: any[], opts?: { config?: any, subCommandName?: string }): IFuture<any> {
64+
private loadAndExecute(commandName: string, args: any[], opts?: INpmOpts): IFuture<any> {
5965
return (() => {
6066
opts = opts || {};
6167
this.load(opts.config).wait();
62-
return this.executeCore(commandName, args, opts.subCommandName).wait();
68+
return this.executeCore(commandName, args, opts).wait();
6369
}).future<any>()();
6470
}
6571

66-
private executeCore(commandName: string, args: any[], subCommandName?: string): IFuture<any> {
72+
private executeCore(commandName: string, args: any[], opts?: INpmOpts): IFuture<any> {
6773
let future = new Future<any>();
74+
let oldNpmPath: string = undefined;
6875
let callback = (err: Error, data: any) => {
76+
if (oldNpmPath) {
77+
npm.prefix = oldNpmPath;
78+
}
79+
6980
if(err) {
7081
future.throw(err);
7182
} else {
@@ -74,6 +85,12 @@ export class NodePackageManager implements INodePackageManager {
7485
};
7586
args.push(callback);
7687

88+
if (opts && opts.path) {
89+
oldNpmPath = npm.prefix;
90+
npm.prefix = opts.path;
91+
}
92+
93+
let subCommandName: string = opts.subCommandName;
7794
let command = subCommandName ? npm.commands[commandName][subCommandName] : npm.commands[commandName];
7895
command.apply(this, args);
7996

lib/services/android-project-service.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
2323
private $errors: IErrors,
2424
$fs: IFileSystem,
2525
private $hostInfo: IHostInfo,
26-
private $injector: IInjector,
2726
private $logger: ILogger,
2827
private $options: IOptions,
2928
private $projectData: IProjectData,
@@ -264,12 +263,20 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
264263

265264
public removePluginNativeCode(pluginData: IPluginData): IFuture<void> {
266265
return (() => {
267-
let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
268-
let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME);
266+
try {
267+
let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
268+
let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME);
269269

270-
if(this.$fs.exists(libsFolderPath).wait()) {
271-
let pluginJars = this.$fs.enumerateFilesInDirectorySync(libsFolderPath);
272-
_.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait());
270+
if(this.$fs.exists(libsFolderPath).wait()) {
271+
let pluginJars = this.$fs.enumerateFilesInDirectorySync(libsFolderPath);
272+
_.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait());
273+
}
274+
} catch(e) {
275+
if (e.code === "ENOENT") {
276+
this.$logger.debug("No native code jars found: " + e.message);
277+
} else {
278+
throw e;
279+
}
273280
}
274281
}).future<void>()();
275282
}

lib/services/plugins-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class PluginsService implements IPluginsService {
232232
if(npmCommandName === PluginsService.INSTALL_COMMAND_NAME) {
233233
result = this.$npm.install(npmCommandArguments, this.$projectData.projectDir, PluginsService.NPM_CONFIG).wait();
234234
} else if(npmCommandName === PluginsService.UNINSTALL_COMMAND_NAME) {
235-
result = this.$npm.uninstall(npmCommandArguments, PluginsService.NPM_CONFIG).wait();
235+
result = this.$npm.uninstall(npmCommandArguments, PluginsService.NPM_CONFIG, this.$projectData.projectDir).wait();
236236
}
237237

238238
return this.parseNpmCommandResult(result);

0 commit comments

Comments
 (0)