Skip to content

Commit 3a532c9

Browse files
committed
Plugin remove works with --path option
See #575
1 parent 2b6f0b0 commit 3a532c9

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

.idea/misc.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
2424
private $childProcess: IChildProcess,
2525
private $errors: IErrors,
2626
private $hostInfo: IHostInfo,
27-
private $injector: IInjector,
2827
private $logger: ILogger,
2928
private $options: IOptions,
3029
private $projectData: IProjectData,
@@ -249,11 +248,20 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
249248

250249
public removePluginNativeCode(pluginData: IPluginData): IFuture<void> {
251250
return (() => {
252-
let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
253-
let pluginJars = this.$fs.enumerateFilesInDirectorySync(path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME));
251+
try {
252+
let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
253+
let pluginJars = this.$fs.enumerateFilesInDirectorySync(path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME));
254+
255+
let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME);
256+
_.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait());
257+
} catch(e) {
258+
if (e.code === "ENOENT") {
259+
this.$logger.debug("No native code jars found: " + e.message);
260+
} else {
261+
throw e;
262+
}
263+
}
254264

255-
let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME);
256-
_.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait());
257265
}).future<void>()();
258266
}
259267

lib/services/plugins-service.ts

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

235235
return this.parseNpmCommandResult(result);

0 commit comments

Comments
 (0)