"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const modulesController_1 = require("../fs/modulesController");
const errorTypes_1 = require("../errorTypes");
class UnexpectedStoreError extends errorTypes_1.PnpmError {
    constructor(opts) {
        super('UNEXPECTED_STORE', 'Unexpected store used for installation');
        this.expectedStorePath = opts.expectedStorePath;
        this.actualStorePath = opts.actualStorePath;
    }
}
class BreakingChangeError extends errorTypes_1.PnpmError {
    constructor(opts) {
        super(opts.code, opts.message);
        this.relatedIssue = opts.relatedIssue;
        this.relatedPR = opts.relatedPR;
        this.additionalInformation = opts.additionalInformation;
    }
}
class ModulesBreakingChangeError extends BreakingChangeError {
    constructor(opts) {
        super({
            code: 'MODULES_BREAKING_CHANGE',
            message: `The node_modules structure at ${opts.modulesPath} was changed. Try running the same command with the --force parameter.`,
            additionalInformation: opts.additionalInformation,
            relatedIssue: opts.relatedIssue,
            relatedPR: opts.relatedPR,
        });
        this.modulesPath = opts.modulesPath;
    }
}
function checkCompatibility(modules, opts) {
    if (modules.storePath !== opts.storePath) {
        throw new UnexpectedStoreError({
            expectedStorePath: modules.storePath,
            actualStorePath: opts.storePath,
        });
    }
    if (!modules.layoutVersion || modules.layoutVersion !== modulesController_1.LAYOUT_VERSION) {
        throw new ModulesBreakingChangeError({
            modulesPath: opts.modulesPath,
            additionalInformation: 'The change was needed to make `independent-leafs` not the default installation layout',
            relatedIssue: 821,
        });
    }
}
exports.default = checkCompatibility;
//# sourceMappingURL=checkCompatibility.js.map