UNPKG

@rushstack/heft

Version:

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

110 lines 3.83 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.HeftPhase = void 0; const HeftTask_1 = require("./HeftTask"); const RESERVED_PHASE_NAMES = new Set(['lifecycle']); /** * @internal */ class HeftPhase { constructor(internalHeftSession, phaseName, phaseSpecifier) { this._internalHeftSession = internalHeftSession; this._phaseName = phaseName; this._phaseSpecifier = phaseSpecifier; this._validate(); } /** * The name of the phase. */ get phaseName() { return this._phaseName; } /** * The description of the phase. */ get phaseDescription() { return this._phaseSpecifier.phaseDescription; } /** * Returns delete operations that are specified on the phase. */ get cleanFiles() { if (!this._cleanFiles) { this._cleanFiles = new Set(this._phaseSpecifier.cleanFiles || []); } return this._cleanFiles; } /** * Returns the set of phases that depend on this phase. */ get consumingPhases() { if (!this._consumingPhases) { // 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 { phases } = this._internalHeftSession; for (const phase of phases) { phase._consumingPhases = new Set(); } for (const phase of phases) { for (const dependency of phase.dependencyPhases) { dependency._consumingPhases.add(phase); } } } return this._consumingPhases; } /** * Returns the set of phases that this phase depends on. */ get dependencyPhases() { let dependencyPhases = this._dependencyPhases; if (!dependencyPhases) { this._dependencyPhases = dependencyPhases = new Set(); const dependencyNamesSet = new Set(this._phaseSpecifier.phaseDependencies || []); for (const dependencyName of dependencyNamesSet) { // Skip if we can't find the dependency const dependencyPhase = this._internalHeftSession.phasesByName.get(dependencyName); if (!dependencyPhase) { throw new Error(`Could not find dependency phase ${JSON.stringify(dependencyName)}.`); } dependencyPhases.add(dependencyPhase); } } return dependencyPhases; } /** * Returns the set of tasks contained by this phase. */ get tasks() { this._ensureTasks(); return this._tasks; } /** * Returns a map of tasks by name. */ get tasksByName() { this._ensureTasks(); return this._tasksByName; } _ensureTasks() { if (!this._tasks || !this._tasksByName) { this._tasks = new Set(); this._tasksByName = new Map(); for (const [taskName, taskSpecifier] of Object.entries(this._phaseSpecifier.tasksByName || {})) { const task = new HeftTask_1.HeftTask(this, taskName, taskSpecifier); this._tasks.add(task); this._tasksByName.set(taskName, task); } } } _validate() { if (RESERVED_PHASE_NAMES.has(this.phaseName)) { throw new Error(`Phase name ${JSON.stringify(this.phaseName)} is reserved and cannot be used as a phase name.`); } } } exports.HeftPhase = HeftPhase; //# sourceMappingURL=HeftPhase.js.map