UNPKG

@rushstack/heft

Version:

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

75 lines 2.96 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.LoggingManager = void 0; const ScopedLogger_1 = require("./ScopedLogger"); const node_core_library_1 = require("@rushstack/node-core-library"); class LoggingManager { get errorsHaveBeenEmitted() { return this._hasAnyErrors; } get warningsHaveBeenEmitted() { return this._hasAnyWarnings; } constructor(options) { this._scopedLoggers = new Map(); this._shouldPrintStacks = false; this._hasAnyWarnings = false; this._hasAnyErrors = false; this._options = options; } enablePrintStacks() { this._shouldPrintStacks = true; } resetScopedLoggerErrorsAndWarnings() { this._hasAnyErrors = false; this._hasAnyWarnings = false; for (const scopedLogger of this._scopedLoggers.values()) { scopedLogger.resetErrorsAndWarnings(); } } requestScopedLogger(loggerName) { const existingScopedLogger = this._scopedLoggers.get(loggerName); if (existingScopedLogger) { throw new Error(`A named logger with name ${JSON.stringify(loggerName)} has already been requested.`); } else { const scopedLogger = new ScopedLogger_1.ScopedLogger({ loggerName, terminalProvider: this._options.terminalProvider, getShouldPrintStacks: () => this._shouldPrintStacks, errorHasBeenEmittedCallback: () => (this._hasAnyErrors = true), warningHasBeenEmittedCallback: () => (this._hasAnyWarnings = true) }); this._scopedLoggers.set(loggerName, scopedLogger); return scopedLogger; } } getErrorStrings(fileLocationStyle) { const result = []; for (const scopedLogger of this._scopedLoggers.values()) { result.push(...scopedLogger.errors.map((error) => `[${scopedLogger.loggerName}] ` + LoggingManager.getErrorMessage(error, { format: fileLocationStyle }))); } return result; } getWarningStrings(fileErrorFormat) { const result = []; for (const scopedLogger of this._scopedLoggers.values()) { result.push(...scopedLogger.warnings.map((warning) => `[${scopedLogger.loggerName}] ` + LoggingManager.getErrorMessage(warning, { format: fileErrorFormat }))); } return result; } static getErrorMessage(error, options) { if (error instanceof node_core_library_1.FileError) { return error.getFormattedErrorMessage(options); } else { return error.message; } } } exports.LoggingManager = LoggingManager; //# sourceMappingURL=LoggingManager.js.map