Code coverage report for lib/node-package-manager.js

Statements: 87.3% (55 / 63)      Branches: 68.18% (15 / 22)      Functions: 93.75% (15 / 16)      Lines: 87.1% (54 / 62)      Ignored: none     

All files » lib/ » node-package-manager.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93    1 1 1 1 16 16   1 6   1 26 25 25 25 15   25     1 1 1       1     1     1 9       9   1     1 8   1 3   1 3   1 2   1 23 23 23 23 23     1 23 23 23 23     23       23     23 23       23 23 23 23   1   1 1  
///<reference path=".d.ts"/>
"use strict";
var Future = require("fibers/future");
var npm = require("npm");
var NodePackageManager = (function () {
    function NodePackageManager($childProcess, $options) {
        this.$childProcess = $childProcess;
        this.$options = $options;
    }
    NodePackageManager.prototype.getCache = function () {
        return npm.cache;
    };
    NodePackageManager.prototype.load = function (config) {
        if (npm.config.loaded) {
            var data = npm.config.sources.cli.data;
            Object.keys(data).forEach(function (k) { return delete data[k]; });
            if (config) {
                _.assign(data, config);
            }
            return Future.fromResult();
        }
        else {
            var future = new Future();
            npm.load(config, function (err) {
                Iif (err) {
                    future.throw(err);
                }
                else {
                    future.return();
                }
            });
            return future;
        }
    };
    NodePackageManager.prototype.install = function (packageName, pathToSave, config) {
        Iif (this.$options.ignoreScripts) {
            config = config || {};
            config["ignore-scripts"] = true;
        }
        return this.loadAndExecute("install", [pathToSave, packageName], { config: config });
    };
    NodePackageManager.prototype.uninstall = function (packageName, config, path) {
        return this.loadAndExecute("uninstall", [[packageName]], { config: config, path: path });
    };
    NodePackageManager.prototype.cache = function (packageName, version, config) {
        return this.loadAndExecute("cache", [packageName, version, undefined, false], { subCommandName: "add", config: config });
    };
    NodePackageManager.prototype.cacheUnpack = function (packageName, version, unpackTarget) {
        return this.loadAndExecute("cache", [packageName, version, unpackTarget, null, null, null, null], { subCommandName: "unpack" });
    };
    NodePackageManager.prototype.view = function (packageName, propertyName) {
        return this.loadAndExecute("view", [[packageName, propertyName], [false]]);
    };
    NodePackageManager.prototype.executeNpmCommand = function (npmCommandName, currentWorkingDirectory) {
        return this.$childProcess.exec(npmCommandName, { cwd: currentWorkingDirectory });
    };
    NodePackageManager.prototype.loadAndExecute = function (commandName, args, opts) {
        var _this = this;
        return (function () {
            opts = opts || {};
            _this.load(opts.config).wait();
            return _this.executeCore(commandName, args, opts).wait();
        }).future()();
    };
    NodePackageManager.prototype.executeCore = function (commandName, args, opts) {
        var future = new Future();
        var oldNpmPath = undefined;
        var callback = function (err, data) {
            Iif (oldNpmPath) {
                npm.prefix = oldNpmPath;
            }
            Iif (err) {
                future.throw(err);
            }
            else {
                future.return(data);
            }
        };
        args.push(callback);
        Iif (opts && opts.path) {
            oldNpmPath = npm.prefix;
            npm.prefix = opts.path;
        }
        var subCommandName = opts.subCommandName;
        var command = subCommandName ? npm.commands[commandName][subCommandName] : npm.commands[commandName];
        command.apply(this, args);
        return future;
    };
    return NodePackageManager;
})();
exports.NodePackageManager = NodePackageManager;
$injector.register("npm", NodePackageManager);