Skip to content

Plugin remove works with --path option #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ interface INodePackageManager {
getCache(): string;
load(config?: any): IFuture<void>;
install(packageName: string, pathToSave: string, config?: any): IFuture<any>;
uninstall(packageName: string, config?: any): IFuture<any>;
uninstall(packageName: string, config?: any, path?: string): IFuture<any>;
cache(packageName: string, version: string, cache?: any): IFuture<IDependencyData>;
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
view(packageName: string, propertyName: string): IFuture<any>;
Expand Down
3 changes: 2 additions & 1 deletion lib/definitions/npm.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
27 changes: 22 additions & 5 deletions lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down Expand Up @@ -33,8 +39,8 @@ export class NodePackageManager implements INodePackageManager {
return this.loadAndExecute("install", [pathToSave, packageName], { config: config });
}

public uninstall(packageName: string, config?: any): IFuture<any> {
return this.loadAndExecute("uninstall", [[packageName]], { config: config });
public uninstall(packageName: string, config?: any, path?: string): IFuture<any> {
return this.loadAndExecute("uninstall", [[packageName]], { config, path});
}

public cache(packageName: string, version: string, config?: any): IFuture<IDependencyData> {
Expand All @@ -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<any> {
private loadAndExecute(commandName: string, args: any[], opts?: INpmOpts): IFuture<any> {
return (() => {
opts = opts || {};
this.load(opts.config).wait();
return this.executeCore(commandName, args, opts.subCommandName).wait();
return this.executeCore(commandName, args, opts).wait();
}).future<any>()();
}

private executeCore(commandName: string, args: any[], subCommandName?: string): IFuture<any> {
private executeCore(commandName: string, args: any[], opts?: INpmOpts): IFuture<any> {
let future = new Future<any>();
let oldNpmPath: string = undefined;
let callback = (err: Error, data: any) => {
if (oldNpmPath) {
npm.prefix = oldNpmPath;
}

if(err) {
future.throw(err);
} else {
Expand All @@ -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);

Expand Down
19 changes: 13 additions & 6 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -259,12 +258,20 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService

public removePluginNativeCode(pluginData: IPluginData): IFuture<void> {
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<void>()();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down