@rushstack/node-core-library
Advanced tools
Comparing version 3.58.0 to 3.59.0
@@ -40,5 +40,5 @@ /** | ||
export { StringBufferTerminalProvider, IStringBufferOutputOptions } from './Terminal/StringBufferTerminalProvider'; | ||
export { PrefixProxyTerminalProvider, IPrefixProxyTerminalProviderOptions } from './Terminal/PrefixProxyTerminalProvider'; | ||
export { PrefixProxyTerminalProvider, IPrefixProxyTerminalProviderOptions, IDynamicPrefixProxyTerminalProviderOptions, IPrefixProxyTerminalProviderOptionsBase, IStaticPrefixProxyTerminalProviderOptions } from './Terminal/PrefixProxyTerminalProvider'; | ||
export { TerminalWritable, ITerminalWritableOptions } from './Terminal/TerminalWritable'; | ||
export { TypeUuid } from './TypeUuid'; | ||
//# sourceMappingURL=index.d.ts.map |
import type { ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider'; | ||
/** | ||
* Options for {@link PrefixProxyTerminalProvider}. | ||
* | ||
* @beta | ||
*/ | ||
export interface IPrefixProxyTerminalProviderOptions { | ||
export interface IPrefixProxyTerminalProviderOptionsBase { | ||
/** | ||
@@ -12,2 +10,9 @@ * The {@link ITerminalProvider} that will be wrapped. | ||
terminalProvider: ITerminalProvider; | ||
} | ||
/** | ||
* Options for {@link PrefixProxyTerminalProvider}, with a static prefix. | ||
* | ||
* @beta | ||
*/ | ||
export interface IStaticPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase { | ||
/** | ||
@@ -19,2 +24,18 @@ * The prefix that should be added to each line of output. | ||
/** | ||
* Options for {@link PrefixProxyTerminalProvider}. | ||
* | ||
* @beta | ||
*/ | ||
export interface IDynamicPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase { | ||
/** | ||
* A function that returns the prefix that should be added to each line of output. This is useful | ||
* for prefixing each line with a timestamp. | ||
*/ | ||
getPrefix: () => string; | ||
} | ||
/** | ||
* @beta | ||
*/ | ||
export declare type IPrefixProxyTerminalProviderOptions = IStaticPrefixProxyTerminalProviderOptions | IDynamicPrefixProxyTerminalProviderOptions; | ||
/** | ||
* Wraps an existing {@link ITerminalProvider} that prefixes each line of output with a specified | ||
@@ -26,6 +47,6 @@ * prefix string. | ||
export declare class PrefixProxyTerminalProvider implements ITerminalProvider { | ||
private _parentTerminalProvider; | ||
private _prefix; | ||
private _currentPrefix; | ||
private _newlineRegex; | ||
private readonly _parentTerminalProvider; | ||
private readonly _getPrefix; | ||
private readonly _newlineRegex; | ||
private _isOnNewline; | ||
constructor(options: IPrefixProxyTerminalProviderOptions); | ||
@@ -32,0 +53,0 @@ /** @override */ |
@@ -15,6 +15,13 @@ "use strict"; | ||
constructor(options) { | ||
const { terminalProvider, prefix } = options; | ||
const { terminalProvider } = options; | ||
this._parentTerminalProvider = terminalProvider; | ||
this._prefix = prefix; | ||
this._currentPrefix = prefix; | ||
if (options.prefix !== undefined) { | ||
const { prefix } = options; | ||
this._getPrefix = () => prefix; | ||
} | ||
else { | ||
const { getPrefix } = options; | ||
this._getPrefix = getPrefix; | ||
} | ||
this._isOnNewline = true; | ||
// eslint-disable-next-line @rushstack/security/no-unsafe-regexp | ||
@@ -41,7 +48,8 @@ this._newlineRegex = new RegExp(`${Text_1.Text.escapeRegExp(terminalProvider.eolCharacter)}|\\n`, 'g'); | ||
const newIndex = newlineIndex + newlineMatch[0].length; | ||
const dataToWrite = `${this._currentPrefix}${data.substring(currentIndex, newIndex)}`; | ||
const prefix = this._isOnNewline ? this._getPrefix() : ''; | ||
const dataToWrite = `${prefix}${data.substring(currentIndex, newIndex)}`; | ||
this._parentTerminalProvider.write(dataToWrite, severity); | ||
// Update the currentIndex to start the search from the char after the newline | ||
currentIndex = newIndex; | ||
this._currentPrefix = this._prefix; | ||
this._isOnNewline = true; | ||
} | ||
@@ -51,4 +59,5 @@ // The remaining data is not postfixed by a newline, so write out the data and set _isNewline to false | ||
if (remainingData.length) { | ||
this._parentTerminalProvider.write(`${this._currentPrefix}${remainingData}`, severity); | ||
this._currentPrefix = ''; | ||
const prefix = this._isOnNewline ? this._getPrefix() : ''; | ||
this._parentTerminalProvider.write(`${prefix}${remainingData}`, severity); | ||
this._isOnNewline = false; | ||
} | ||
@@ -55,0 +64,0 @@ } |
{ | ||
"name": "@rushstack/node-core-library", | ||
"version": "3.58.0", | ||
"version": "3.59.0", | ||
"description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1095749
14298