UNPKG

@rushstack/heft

Version:

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

103 lines 4.5 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.HeftTask = void 0; const node_core_library_1 = require("@rushstack/node-core-library"); const HeftPluginConfiguration_1 = require("../configuration/HeftPluginConfiguration"); const RESERVED_TASK_NAMES = new Set(['clean']); /** * @internal */ class HeftTask { get parentPhase() { return this._parentPhase; } get taskName() { return this._taskName; } get consumingTasks() { if (!this._consumingTasks) { // Force initialize all dependency relationships // This needs to operate on every phase in the set because the relationships are only specified // in the consuming phase. const { tasks } = this._parentPhase; for (const task of tasks) { task._consumingTasks = new Set(); } for (const task of tasks) { for (const dependency of task.dependencyTasks) { dependency._consumingTasks.add(task); } } } return this._consumingTasks; } get pluginDefinition() { if (!this._taskPluginDefinition) { throw new node_core_library_1.InternalError('HeftTask.ensureInitializedAsync() must be called before accessing HeftTask.pluginDefinition.'); } return this._taskPluginDefinition; } get pluginOptions() { return this._taskSpecifier.taskPlugin.options; } get dependencyTasks() { if (!this._dependencyTasks) { this._dependencyTasks = new Set(); const dependencyNamesSet = new Set(this._taskSpecifier.taskDependencies || []); for (const dependencyName of dependencyNamesSet) { // Skip if we can't find the dependency const dependencyTask = this._parentPhase.tasksByName.get(dependencyName); if (!dependencyTask) { throw new Error(`Could not find dependency task ${JSON.stringify(dependencyName)} within phase ` + `${JSON.stringify(this._parentPhase.phaseName)}.`); } this._dependencyTasks.add(dependencyTask); } } return this._dependencyTasks; } constructor(parentPhase, taskName, taskSpecifier) { this._parentPhase = parentPhase; this._taskName = taskName; this._taskSpecifier = taskSpecifier; this._validate(); } async ensureInitializedAsync() { if (!this._taskPluginDefinition) { this._taskPluginDefinition = await this._loadTaskPluginDefinitionAsync(); this.pluginDefinition.validateOptions(this.pluginOptions); } } async getPluginAsync(logger) { await this.ensureInitializedAsync(); if (!this._taskPlugin) { this._taskPlugin = await this._taskPluginDefinition.loadPluginAsync(logger); } return this._taskPlugin; } async _loadTaskPluginDefinitionAsync() { // taskPlugin.pluginPackage should already be resolved to the package root. // See CoreConfigFiles.heftConfigFileLoader const pluginSpecifier = this._taskSpecifier.taskPlugin; const pluginConfiguration = await HeftPluginConfiguration_1.HeftPluginConfiguration.loadFromPackageAsync(pluginSpecifier.pluginPackageRoot, pluginSpecifier.pluginPackage); const pluginDefinition = pluginConfiguration.getPluginDefinitionBySpecifier(pluginSpecifier); const isTaskPluginDefinition = pluginConfiguration.isTaskPluginDefinition(pluginDefinition); if (!isTaskPluginDefinition) { throw new Error(`Plugin ${JSON.stringify(pluginSpecifier.pluginName)} specified by task ` + `${JSON.stringify(this._taskName)} is not a task plugin.`); } return pluginDefinition; } _validate() { if (RESERVED_TASK_NAMES.has(this.taskName)) { throw new Error(`Task name ${JSON.stringify(this.taskName)} is reserved and cannot be used as a task name.`); } if (!this._taskSpecifier.taskPlugin) { throw new Error(`Task ${JSON.stringify(this.taskName)} has no specified task plugin.`); } } } exports.HeftTask = HeftTask; //# sourceMappingURL=HeftTask.js.map