@rushstack/heft
Version:
Build all your JavaScript projects the same way: A way that works.
67 lines • 2.89 kB
JavaScript
;
// 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.HeftPhaseSession = void 0;
const HeftTaskSession_1 = require("./HeftTaskSession");
const HeftPluginHost_1 = require("./HeftPluginHost");
class HeftPhaseSession extends HeftPluginHost_1.HeftPluginHost {
constructor(options) {
super();
this._taskSessionsByTask = new Map();
this._options = options;
const loggingManager = options.internalHeftSession.loggingManager;
this.phaseLogger = loggingManager.requestScopedLogger(options.phase.phaseName);
this.cleanLogger = loggingManager.requestScopedLogger(`${options.phase.phaseName}:clean`);
}
/**
* Get a task session for the given task.
*/
getSessionForTask(task) {
let taskSession = this._taskSessionsByTask.get(task);
if (!taskSession) {
taskSession = new HeftTaskSession_1.HeftTaskSession({
...this._options,
task,
pluginHost: this
});
this._taskSessionsByTask.set(task, taskSession);
}
return taskSession;
}
/**
* Apply all task plugins specified by the phase.
*/
async applyPluginsInternalAsync() {
const { internalHeftSession: { heftConfiguration }, phase: { tasks } } = this._options;
// Load up all plugins concurrently
const loadPluginPromises = [];
for (const task of tasks) {
const taskSession = this.getSessionForTask(task);
loadPluginPromises.push(task.getPluginAsync(taskSession.logger));
}
// Promise.all maintains the order of the input array
const plugins = await Promise.all(loadPluginPromises);
// Iterate through and apply the plugins
let pluginIndex = 0;
for (const task of tasks) {
const taskSession = this.getSessionForTask(task);
const taskPlugin = plugins[pluginIndex++];
try {
taskPlugin.apply(taskSession, heftConfiguration, task.pluginOptions);
}
catch (error) {
throw new Error(`Error applying plugin ${JSON.stringify(task.pluginDefinition.pluginName)} from package ` +
`${JSON.stringify(task.pluginDefinition.pluginPackageName)}: ${error}`);
}
}
// Do a second pass to apply the plugin access requests for each plugin
pluginIndex = 0;
for (const task of tasks) {
const taskPlugin = plugins[pluginIndex++];
this.resolvePluginAccessRequests(taskPlugin, task.pluginDefinition);
}
}
}
exports.HeftPhaseSession = HeftPhaseSession;
//# sourceMappingURL=HeftPhaseSession.js.map