// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'node:path';
import { ApprovedPackagesConfiguration } from './ApprovedPackagesConfiguration';
import { RushConstants } from '../logic/RushConstants';
/**
 * This is a helper object for RushConfiguration.
 * It exposes the "approvedPackagesPolicy" feature from rush.json.
 * @public
 */
export class ApprovedPackagesPolicy {
    /** @internal */
    constructor(rushConfiguration, rushConfigurationJson) {
        const approvedPackagesPolicy = rushConfigurationJson.approvedPackagesPolicy || {};
        this.enabled = !!rushConfigurationJson.approvedPackagesPolicy;
        this.ignoredNpmScopes = new Set(approvedPackagesPolicy.ignoredNpmScopes);
        this.reviewCategories = new Set(approvedPackagesPolicy.reviewCategories);
        if (this.enabled) {
            if (!this.reviewCategories.size) {
                throw new Error(`The "approvedPackagesPolicy" feature is enabled ${RushConstants.rushJsonFilename}, but the reviewCategories` +
                    ` list is not configured.`);
            }
        }
        // Load browser-approved-packages.json
        const browserApprovedPackagesPath = path.join(rushConfiguration.commonRushConfigFolder, RushConstants.browserApprovedPackagesFilename);
        this.browserApprovedPackages = new ApprovedPackagesConfiguration(browserApprovedPackagesPath);
        this.browserApprovedPackages.tryLoadFromFile(this.enabled);
        // Load nonbrowser-approved-packages.json
        const nonbrowserApprovedPackagesPath = path.join(rushConfiguration.commonRushConfigFolder, RushConstants.nonbrowserApprovedPackagesFilename);
        this.nonbrowserApprovedPackages = new ApprovedPackagesConfiguration(nonbrowserApprovedPackagesPath);
        this.nonbrowserApprovedPackages.tryLoadFromFile(this.enabled);
    }
}
//# sourceMappingURL=ApprovedPackagesPolicy.js.map