UNPKG

@rushstack/heft

Version:

Build all your JavaScript projects the same way: A way that works.

111 lines 5.28 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.InternalHeftSession = void 0; const node_core_library_1 = require("@rushstack/node-core-library"); const Constants_1 = require("../utilities/Constants"); const HeftLifecycle_1 = require("./HeftLifecycle"); const HeftPhaseSession_1 = require("./HeftPhaseSession"); const HeftPhase_1 = require("./HeftPhase"); const CoreConfigFiles_1 = require("../utilities/CoreConfigFiles"); function* getAllTasks(phases) { for (const phase of phases) { yield* phase.tasks; } } class InternalHeftSession { constructor(heftConfigurationJson, options) { this._phaseSessionsByPhase = new Map(); this.heftConfiguration = options.heftConfiguration; this.loggingManager = options.loggingManager; this.metricsCollector = options.metricsCollector; this.debug = options.debug; this._heftConfigurationJson = heftConfigurationJson; } static async initializeAsync(options) { // Initialize the rig. Must be done before the HeftConfiguration.rigConfig is used. await options.heftConfiguration._checkForRigAsync(); const heftConfigurationJson = await CoreConfigFiles_1.CoreConfigFiles.loadHeftConfigurationFileForProjectAsync(options.heftConfiguration.globalTerminal, options.heftConfiguration.buildFolderPath, options.heftConfiguration.rigConfig); const internalHeftSession = new InternalHeftSession(heftConfigurationJson, options); // Initialize the lifecycle and the tasks. This will ensure that we throw an error if a plugin is improperly // specified, or if the options provided to a plugin are invalid. We will avoid loading the actual plugins // until they are needed. await internalHeftSession.lifecycle.ensureInitializedAsync(); const tasks = getAllTasks(internalHeftSession.phases); await node_core_library_1.Async.forEachAsync(tasks, async (task) => { await task.ensureInitializedAsync(); }, { concurrency: Constants_1.Constants.maxParallelism }); function* getAllPluginDefinitions() { yield* internalHeftSession.lifecycle.pluginDefinitions; for (const task of getAllTasks(internalHeftSession.phases)) { yield task.pluginDefinition; } } const loadedPluginPathsByName = new Map(); for (const { pluginName, entryPoint } of getAllPluginDefinitions()) { let existingPluginPaths = loadedPluginPathsByName.get(pluginName); if (!existingPluginPaths) { existingPluginPaths = new Set(); loadedPluginPathsByName.set(pluginName, existingPluginPaths); } existingPluginPaths.add(entryPoint); } for (const [pluginName, pluginPaths] of loadedPluginPathsByName) { if (pluginPaths.size > 1) { throw new Error(`Multiple plugins named ${JSON.stringify(pluginName)} were loaded from different paths: ` + `${Array.from(pluginPaths, (x) => JSON.stringify(x)).join(', ')}. Plugins must have unique names.`); } } return internalHeftSession; } get parameterManager() { if (!this._parameterManager) { throw new node_core_library_1.InternalError('A parameter manager for the session has not been provided.'); } return this._parameterManager; } set parameterManager(value) { this._parameterManager = value; } get actionReferencesByAlias() { if (!this._actionReferencesByAlias) { this._actionReferencesByAlias = new Map(Object.entries(this._heftConfigurationJson.aliasesByName || {})); } return this._actionReferencesByAlias; } get lifecycle() { if (!this._lifecycle) { this._lifecycle = new HeftLifecycle_1.HeftLifecycle(this, this._heftConfigurationJson.heftPlugins || []); } return this._lifecycle; } get phases() { this._ensurePhases(); return this._phases; } get phasesByName() { this._ensurePhases(); return this._phasesByName; } getSessionForPhase(phase) { let phaseSession = this._phaseSessionsByPhase.get(phase); if (!phaseSession) { phaseSession = new HeftPhaseSession_1.HeftPhaseSession({ internalHeftSession: this, phase }); this._phaseSessionsByPhase.set(phase, phaseSession); } return phaseSession; } _ensurePhases() { if (!this._phases || !this._phasesByName) { this._phasesByName = new Map(); for (const [phaseName, phaseSpecifier] of Object.entries(this._heftConfigurationJson.phasesByName || {})) { const phase = new HeftPhase_1.HeftPhase(this, phaseName, phaseSpecifier); this._phasesByName.set(phaseName, phase); } this._phases = new Set(this._phasesByName.values()); } } } exports.InternalHeftSession = InternalHeftSession; //# sourceMappingURL=InternalHeftSession.js.map