"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const abstract_node_1 = require("./abstract-node");
const path_1 = require("path");
const fs_1 = require("fs");
const logger_1 = require("../utils/logger");
const logger = logger_1.log('npm');
class NpmNode extends abstract_node_1.AbstractNode {
    constructor(graph, packageName, pkg, nodes) {
        super(graph);
        this._external = true;
        const location = !!pkg.path ? pkg.path : path_1.join(pkg._where, 'node_modules', packageName);
        if (!fs_1.existsSync(location)) {
            logger.error('Package not found on filesystem', pkg);
            throw Error('Package not found on filesystem');
        }
        this._name = packageName;
        this._version = pkg.version;
        this._location = location;
        this._dependencies = [];
        for (const dependencyName of Object.keys(pkg.dependencies)) {
            const dep = pkg.dependencies[packageName];
            const externalNode = new NpmNode(graph, dependencyName, dep, nodes);
            nodes.add(externalNode);
            this._dependencies.push(externalNode);
        }
    }
    equals(node) {
        return (node.isExternal() &&
            this._name === node.getName() &&
            this._version === node.getVersion() &&
            this._version === node.getLocation());
    }
}
exports.NpmNode = NpmNode;
//# sourceMappingURL=npm-node.js.map