"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.PLUGINS = void 0;
exports.injectDevelopmentPlugins = injectDevelopmentPlugins;
const CorePlugins = __importStar(require("@servicenow/sdk-build-plugins"));
const external_plugins_1 = require("./external-plugins");
// Order is reversed here to match the order when injecting via FLUENT_INJECT_PLUGINS
const loadedExternalPlugins = external_plugins_1.EXTERNAL_PLUGINS.flatMap((plugin) => (0, external_plugins_1.loadExternalPlugins)(plugin.slug, plugin.packageName).reverse());
exports.PLUGINS = [
    // Graduated external plugins
    ...loadedExternalPlugins,
    CorePlugins.ClaimsPlugin,
    CorePlugins.ApplicationMenuPlugin,
    CorePlugins.BusinessRulePlugin,
    CorePlugins.RolePlugin,
    CorePlugins.AclPlugin,
    CorePlugins.ClientScriptPlugin,
    CorePlugins.CrossScopePrivilegePlugin,
    CorePlugins.PropertyPlugin,
    CorePlugins.NowConfigPlugin,
    CorePlugins.PackageJsonPlugin,
    CorePlugins.ServerModulePlugin,
    CorePlugins.ViewPlugin,
    CorePlugins.UserPreferencePlugin,
    CorePlugins.ChoiceSetPlugin,
    CorePlugins.ColumnPlugin,
    CorePlugins.TablePlugin,
    CorePlugins.ListPlugin,
    CorePlugins.FormPlugin,
    CorePlugins.UiPagePlugin,
    CorePlugins.UiActionPlugin,
    CorePlugins.ScriptIncludePlugin,
    CorePlugins.RestApiPlugin,
    CorePlugins.StaticContentPlugin,
    CorePlugins.ScriptActionPlugin,
    CorePlugins.UiPolicyPlugin,
    CorePlugins.DataPolicyPlugin,
    CorePlugins.TestPlugin,
    CorePlugins.NowAttachPlugin,
    CorePlugins.SLAPlugin,
    CorePlugins.EmailNotificationPlugin,
    CorePlugins.InboundEmailActionPlugin,
    CorePlugins.UxListMenuConfigPlugin,
    CorePlugins.WorkspacePlugin,
    CorePlugins.DashboardPlugin,
    CorePlugins.ApplicabilityPlugin,
    CorePlugins.AiuxPlugin,
    CorePlugins.VariableSetPlugin,
    CorePlugins.CatalogItemRecordProducerPlugin,
    CorePlugins.CatalogItemPlugin,
    CorePlugins.CatalogClientScriptPlugin,
    CorePlugins.CatalogUiPolicyPlugin,
    CorePlugins.ScheduledScriptPlugin,
    CorePlugins.InstanceScanPlugin,
    CorePlugins.RestMessagePlugin,
    CorePlugins.DataLookupPlugin,
    // Alias plugin
    CorePlugins.RetryPolicyPlugin,
    CorePlugins.AliasTemplatePlugin,
    CorePlugins.AliasPlugin,
    // Service Portal plugins
    CorePlugins.ServicePortalPlugin,
    CorePlugins.SPWidgetPlugin,
    CorePlugins.SPWidgetDependencyPlugin,
    CorePlugins.SPAngularProviderPlugin,
    CorePlugins.SPPagePlugin,
    CorePlugins.SPThemePlugin,
    CorePlugins.SPMenuPlugin,
    CorePlugins.SPHeaderFooterPlugin,
    CorePlugins.SPPageRouteMapPlugin,
    // New plugins should usually be added ABOVE this line
    CorePlugins.RecordPlugin,
    CorePlugins.NowIncludePlugin,
    CorePlugins.NowRefPlugin,
    CorePlugins.NowDeletePlugin,
    CorePlugins.NowIdPlugin,
    CorePlugins.NowUnresolvedPlugin,
    CorePlugins.HtmlImportPlugin,
    CorePlugins.JsonPlugin,
    CorePlugins.ArrowFunctionPlugin,
    CorePlugins.DataPlugin,
    CorePlugins.CallExpressionPlugin,
    CorePlugins.BasicSyntaxPlugin,
    CorePlugins.ImportSetPlugin,
];
/**
 * Loads plugins specified by the FLUENT_INJECT_PLUGINS environment variable
 *
 * @example
 * FLUENT_INJECT_PLUGINS=@servicenow/my-plugin
 */
function injectDevelopmentPlugins(plugins, packageJsonPath, logger) {
    if (process && 'env' in process) {
        const injectedPackages = process.env['FLUENT_INJECT_PLUGINS'];
        if (injectedPackages) {
            const { createRequire } = require('node:module');
            const localRequire = createRequire(packageJsonPath);
            for (const injectedPackage of injectedPackages.split(',').map((p) => p.trim())) {
                if (!injectedPackage) {
                    continue;
                }
                // Exported module could be a single plugin or array of plugins
                const moduleExport = localRequire(injectedPackage);
                const moduleDefault = moduleExport?.default ?? moduleExport;
                const injectedPlugins = [moduleDefault].flat();
                for (const plugin of injectedPlugins) {
                    if (plugin &&
                        typeof plugin === 'object' &&
                        !Array.isArray(plugin) &&
                        plugin.constructor.name === 'Plugin') {
                        plugins.prepend(plugin);
                    }
                    else {
                        logger.error(`Value from injected package "${injectedPackage}" is not a plugin: ${plugin} (${typeof plugin})`);
                    }
                }
            }
        }
    }
}
//# sourceMappingURL=plugin-registry.js.map