@rushstack/heft
Version:
Build all your JavaScript projects the same way: A way that works.
48 lines • 2.77 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { AsyncParallelHook, AsyncSeriesWaterfallHook } from 'tapable';
import { InternalError } from '@rushstack/node-core-library';
export class HeftTaskSession {
get parameters() {
// Delay loading the parameters for the task until they're actually needed
if (!this._parameters) {
const parameterManager = this._options.internalHeftSession.parameterManager;
const task = this._options.task;
this._parameters = parameterManager.getParametersForPlugin(task.pluginDefinition);
}
return this._parameters;
}
get parsedCommandLine() {
return this._parsedCommandLine;
}
constructor(options) {
const { internalHeftSession: { heftConfiguration: { tempFolderPath: tempFolder }, loggingManager, metricsCollector }, phase, task } = options;
if (!options.internalHeftSession.parsedCommandLine) {
// This should not happen
throw new InternalError('Attempt to construct HeftTaskSession before command line has been parsed');
}
this._parsedCommandLine = options.internalHeftSession.parsedCommandLine;
this.logger = loggingManager.requestScopedLogger(`${phase.phaseName}:${task.taskName}`);
this.metricsCollector = metricsCollector;
this.taskName = task.taskName;
this.hooks = {
run: new AsyncParallelHook(['runHookOptions']),
runIncremental: new AsyncParallelHook(['runIncrementalHookOptions']),
registerFileOperations: new AsyncSeriesWaterfallHook(['fileOperations'])
};
// Guaranteed to be unique since phases are uniquely named, tasks are uniquely named within
// phases, and neither can have '/' in their names. We will also use the phase name and
// task name as the folder name (instead of the plugin name) since we want to enable re-use
// of plugins in multiple phases and tasks while maintaining unique temp/cache folders for
// each task.
// Having a parent folder for the phase simplifies interaction with the Rush build cache.
const uniqueTaskFolderName = `${phase.phaseName}/${task.taskName}`;
// <projectFolder>/temp/<phaseName>/<taskName>
this.tempFolderPath = `${tempFolder}/${uniqueTaskFolderName}`;
this._options = options;
}
requestAccessToPluginByName(pluginToAccessPackage, pluginToAccessName, pluginApply) {
this._options.pluginHost.requestAccessToPluginByName(this.taskName, pluginToAccessPackage, pluginToAccessName, pluginApply);
}
}
//# sourceMappingURL=HeftTaskSession.js.map