@rushstack/terminal 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@rushstack/terminal",
3
3
  "entries": [
4
+ {
5
+ "version": "0.18.0",
6
+ "tag": "@rushstack/terminal_v0.18.0",
7
+ "date": "Tue, 30 Sep 2025 23:57:45 GMT",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "comment": "Add ProblemCollector.onProblem notification callback"
12
+ },
13
+ {
14
+ "comment": "Update API contract for `SplitterTransform` to support adding and removing destinations after creation."
15
+ }
16
+ ],
17
+ "dependency": [
18
+ {
19
+ "comment": "Updating dependency \"@rushstack/node-core-library\" to `5.15.1`"
20
+ },
21
+ {
22
+ "comment": "Updating dependency \"@rushstack/problem-matcher\" to `0.1.1`"
23
+ }
24
+ ]
25
+ }
26
+ },
4
27
  {
5
28
  "version": "0.17.0",
6
29
  "tag": "@rushstack/terminal_v0.17.0",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Change Log - @rushstack/terminal
2
2
 
3
- This log was last generated on Tue, 30 Sep 2025 20:33:51 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 30 Sep 2025 23:57:45 GMT and should not be manually modified.
4
+
5
+ ## 0.18.0
6
+ Tue, 30 Sep 2025 23:57:45 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Add ProblemCollector.onProblem notification callback
11
+ - Update API contract for `SplitterTransform` to support adding and removing destinations after creation.
4
12
 
5
13
  ## 0.17.0
6
14
  Tue, 30 Sep 2025 20:33:51 GMT
@@ -315,6 +315,10 @@ export declare interface IProblemCollectorOptions extends ITerminalWritableOptio
315
315
  * {@link @rushstack/problem-matcher#IProblemMatcher | IProblemMatcher} definitions.
316
316
  */
317
317
  matcherJson?: IProblemMatcherJson[];
318
+ /**
319
+ * Optional callback invoked immediately whenever a problem is produced.
320
+ */
321
+ onProblem?: (problem: IProblem) => void;
318
322
  }
319
323
 
320
324
  /**
@@ -324,9 +328,9 @@ export declare interface IProblemCollectorOptions extends ITerminalWritableOptio
324
328
  */
325
329
  export declare interface ISplitterTransformOptions extends ITerminalWritableOptions {
326
330
  /**
327
- * Each input chunk will be passed to each destination in the array.
331
+ * Each input chunk will be passed to each destination in the iterable.
328
332
  */
329
- destinations: TerminalWritable[];
333
+ destinations: Iterable<TerminalWritable>;
330
334
  }
331
335
 
332
336
  /**
@@ -779,6 +783,7 @@ export declare class PrintUtilities {
779
783
  export declare class ProblemCollector extends TerminalWritable implements IProblemCollector {
780
784
  private readonly _matchers;
781
785
  private readonly _problems;
786
+ private readonly _onProblem;
782
787
  constructor(options: IProblemCollectorOptions);
783
788
  /**
784
789
  * {@inheritdoc IProblemCollector}
@@ -823,8 +828,25 @@ export declare class RemoveColorsTextRewriter extends TextRewriter {
823
828
  * @public
824
829
  */
825
830
  export declare class SplitterTransform extends TerminalWritable {
826
- readonly destinations: ReadonlyArray<TerminalWritable>;
831
+ private readonly _destinations;
827
832
  constructor(options: ISplitterTransformOptions);
833
+ get destinations(): ReadonlySet<TerminalWritable>;
834
+ /**
835
+ * Adds a destination to the set of destinations. Duplicates are ignored.
836
+ * Only new chunks received after the destination is added will be sent to it.
837
+ * @param destination - The destination to add.
838
+ */
839
+ addDestination(destination: TerminalWritable): void;
840
+ /**
841
+ * Removes a destination from the set of destinations. It will no longer receive chunks, and will be closed, unless
842
+ * `destination.preventAutoclose` is set to `true`.
843
+ * @param destination - The destination to remove.
844
+ * @param close - If `true` (default), the destination will be closed when removed, unless `destination.preventAutoclose` is set to `true`.
845
+ * @returns `true` if the destination was removed, `false` if it was not found.
846
+ * @remarks
847
+ * If the destination is not found, it will not be closed.
848
+ */
849
+ removeDestination(destination: TerminalWritable, close?: boolean): boolean;
828
850
  protected onWriteChunk(chunk: ITerminalChunk): void;
829
851
  protected onClose(): void;
830
852
  }
@@ -16,6 +16,10 @@ export interface IProblemCollectorOptions extends ITerminalWritableOptions {
16
16
  * {@link @rushstack/problem-matcher#IProblemMatcher | IProblemMatcher} definitions.
17
17
  */
18
18
  matcherJson?: IProblemMatcherJson[];
19
+ /**
20
+ * Optional callback invoked immediately whenever a problem is produced.
21
+ */
22
+ onProblem?: (problem: IProblem) => void;
19
23
  }
20
24
  /**
21
25
  * A {@link TerminalWritable} that consumes line-oriented terminal output and extracts structured
@@ -31,6 +35,7 @@ export interface IProblemCollectorOptions extends ITerminalWritableOptions {
31
35
  export declare class ProblemCollector extends TerminalWritable implements IProblemCollector {
32
36
  private readonly _matchers;
33
37
  private readonly _problems;
38
+ private readonly _onProblem;
34
39
  constructor(options: IProblemCollectorOptions);
35
40
  /**
36
41
  * {@inheritdoc IProblemCollector}
@@ -1 +1 @@
1
- {"version":3,"file":"ProblemCollector.d.ts","sourceRoot":"","sources":["../src/ProblemCollector.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,KAAK,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;GAGG;AACH,MAAM,WAAW,wBAAyB,SAAQ,wBAAwB;IACxE;;OAEG;IACH,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,gBAAiB,SAAQ,gBAAiB,YAAW,iBAAiB;IACjF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4B;gBAEnC,OAAO,EAAE,wBAAwB;IAoBpD;;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I;CAiB1B"}
@@ -32,6 +32,7 @@ class ProblemCollector extends TerminalWritable_1.TerminalWritable {
32
32
  if (this._matchers.length === 0) {
33
33
  throw new Error('ProblemCollector requires at least one problem matcher.');
34
34
  }
35
+ this._onProblem = options.onProblem;
35
36
  }
36
37
  /**
37
38
  * {@inheritdoc IProblemCollector}
@@ -43,6 +44,7 @@ class ProblemCollector extends TerminalWritable_1.TerminalWritable {
43
44
  * {@inheritdoc TerminalWritable}
44
45
  */
45
46
  onWriteChunk(chunk) {
47
+ var _a;
46
48
  const text = chunk.text;
47
49
  if (text.length === 0 || text[text.length - 1] !== '\n') {
48
50
  throw new Error('ProblemCollector expects chunks that were split into newline terminated lines. ' +
@@ -57,6 +59,7 @@ class ProblemCollector extends TerminalWritable_1.TerminalWritable {
57
59
  matcherName: matcher.name
58
60
  };
59
61
  this._problems.add(finalized);
62
+ (_a = this._onProblem) === null || _a === void 0 ? void 0 : _a.call(this, finalized);
60
63
  }
61
64
  }
62
65
  }
@@ -64,6 +67,7 @@ class ProblemCollector extends TerminalWritable_1.TerminalWritable {
64
67
  * {@inheritdoc TerminalWritable}
65
68
  */
66
69
  onClose() {
70
+ var _a;
67
71
  for (const matcher of this._matchers) {
68
72
  if (matcher.flush) {
69
73
  const flushed = matcher.flush();
@@ -74,6 +78,7 @@ class ProblemCollector extends TerminalWritable_1.TerminalWritable {
74
78
  matcherName: matcher.name
75
79
  };
76
80
  this._problems.add(finalized);
81
+ (_a = this._onProblem) === null || _a === void 0 ? void 0 : _a.call(this, finalized);
77
82
  }
78
83
  }
79
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProblemCollector.js","sourceRoot":"","sources":["../src/ProblemCollector.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,gEAAsE;AAItE,yDAAqF;AAmBrF;;;;;;;;;;GAUG;AACH,MAAa,gBAAiB,SAAQ,mCAAgB;IAIpD,YAAmB,OAAiC;QAClD,KAAK,CAAC,OAAO,C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,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,SAAS,GAAa;oBAC1B,GAAG,OAAO;oBACV,WAAW,EAAE,OAAO,CAAC,IAAI;iBAC1B,CAAC;gBACF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACO,OAAO;QACf,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAClB,MAAM,OAAO,GAAe,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC5C,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAClC,KAAK,MAAM,OAAO,IAAI,OAAO,EAAE,CAAC;wBAC9B,MAAM,SAAS,GAAa;4BAC1B,GAAG,OAAO;4BACV,WAAW,EAAE,OAAO,CAAC,IAAI;yBAC1B,CAAC;wBACF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAChC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA3ED,4CA2EC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { parseProblemMatchersJson } from '@rushstack/problem-matcher';\nimport type { IProblemMatcher, IProblemMatcherJson, IProblem } from '@rushstack/problem-matcher';\n\nimport type { ITerminalChunk } from './ITerminalChunk';\nimport { type ITerminalWritableOptions, TerminalWritable } from './TerminalWritable';\nimport type { IProblemCollector } from './IProblemCollector';\n\n/**\n * Constructor options for {@link ProblemCollector}.\n * @beta\n */\nexport interface IProblemCollectorOptions extends ITerminalWritableOptions {\n /**\n * The set of matchers that will be applied to each incoming line. Must contain at least one item.\n */\n matchers?: IProblemMatcher[];\n /**\n * VS Code style problem matcher definitions. These will be converted to\n * {@link @rushstack/problem-matcher#IProblemMatcher | IProblemMatcher} definitions.\n */\n matcherJson?: IProblemMatcherJson[];\n}\n\n/**\n * A {@link TerminalWritable} that consumes line-oriented terminal output and extracts structured\n * problems using one or more {@link @rushstack/problem-matcher#IProblemMatcher | IProblemMatcher} instances.\n *\n * @remarks\n * This collector expects that each incoming {@link ITerminalChunk} represents a single line terminated\n * by a `\"\\n\"` character (for example when preceded by {@link StderrLineTransform} / `StdioLineTransform`).\n * If a chunk does not end with a newline an error is thrown to surface incorrect pipeline wiring early.\n *\n * @beta\n */\nexport class ProblemCollector extends TerminalWritable implements IProblemCollector {\n private readonly _matchers: IProblemMatcher[];\n private readonly _problems: Set<IProblem> = new Set();\n\n public constructor(options: IProblemCollectorOptions) {\n super(options);\n\n if (\n !options ||\n ((!options.matchers || options.matchers.length === 0) &&\n (!options.matcherJson || options.matcherJson.length === 0))\n ) {\n throw new Error('ProblemCollector requires at least one problem matcher.');\n }\n\n const fromJson: IProblemMatcher[] = options.matcherJson\n ? parseProblemMatchersJson(options.matcherJson)\n : [];\n this._matchers = [...(options.matchers || []), ...fromJson];\n if (this._matchers.length === 0) {\n throw new Error('ProblemCollector requires at least one problem matcher.');\n }\n }\n\n /**\n * {@inheritdoc IProblemCollector}\n */\n public get problems(): ReadonlySet<IProblem> {\n return this._problems;\n }\n\n /**\n * {@inheritdoc TerminalWritable}\n */\n protected onWriteChunk(chunk: ITerminalChunk): void {\n const text: string = chunk.text;\n if (text.length === 0 || text[text.length - 1] !== '\\n') {\n throw new Error(\n 'ProblemCollector expects chunks that were split into newline terminated lines. ' +\n 'Invalid input: ' +\n JSON.stringify(text)\n );\n }\n\n for (const matcher of this._matchers) {\n const problem: IProblem | false = matcher.exec(text);\n if (problem) {\n const finalized: IProblem = {\n ...problem,\n matcherName: matcher.name\n };\n this._problems.add(finalized);\n }\n }\n }\n\n /**\n * {@inheritdoc TerminalWritable}\n */\n protected onClose(): void {\n for (const matcher of this._matchers) {\n if (matcher.flush) {\n const flushed: IProblem[] = matcher.flush();\n if (flushed && flushed.length > 0) {\n for (const problem of flushed) {\n const finalized: IProblem = {\n ...problem,\n matcherName: matcher.name\n };\n this._problems.add(finalized);\n }\n }\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ProblemCollector.js","sourceRoot":"","sources":["../src/ProblemCollector.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,gEAAsE;AAItE,yDAAqF;AAuBrF;;;;;;;;;;GAUG;AACH,MAAa,gBAAiB,SAAQ,mCAAgB;IAKpD,YAAmB,OAAiC;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJA,cAAS,GAAkB,IAAI,GAAG,EAAE,CAAC;QAMpD,IACE,CAAC,OAAO;YACR,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;gBACnD,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,EAC7D,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,QAAQ,GAAsB,OAAO,CAAC,WAAW;YACrD,CAAC,CAAC,IAAA,0CAAwB,EAAC,OAAO,CAAC,WAAW,CAAC;YAC/C,CAAC,CAAC,EAAE,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;QAC5D,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC7E,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,IA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AAS,CAAC,CAAC;wBAC9B,MAAA,IAAI,CAAC,UAAU,qDAAG,SAAS,CAAC,CAAC;oBAC/B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA/ED,4CA+EC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { parseProblemMatchersJson } from '@rushstack/problem-matcher';\nimport type { IProblemMatcher, IProblemMatcherJson, IProblem } from '@rushstack/problem-matcher';\n\nimport type { ITerminalChunk } from './ITerminalChunk';\nimport { type ITerminalWritableOptions, TerminalWritable } from './TerminalWritable';\nimport type { IProblemCollector } from './IProblemCollector';\n\n/**\n * Constructor options for {@link ProblemCollector}.\n * @beta\n */\nexport interface IProblemCollectorOptions extends ITerminalWritableOptions {\n /**\n * The set of matchers that will be applied to each incoming line. Must contain at least one item.\n */\n matchers?: IProblemMatcher[];\n /**\n * VS Code style problem matcher definitions. These will be converted to\n * {@link @rushstack/problem-matcher#IProblemMatcher | IProblemMatcher} definitions.\n */\n matcherJson?: IProblemMatcherJson[];\n /**\n * Optional callback invoked immediately whenever a problem is produced.\n */\n onProblem?: (problem: IProblem) => void;\n}\n\n/**\n * A {@link TerminalWritable} that consumes line-oriented terminal output and extracts structured\n * problems using one or more {@link @rushstack/problem-matcher#IProblemMatcher | IProblemMatcher} instances.\n *\n * @remarks\n * This collector expects that each incoming {@link ITerminalChunk} represents a single line terminated\n * by a `\"\\n\"` character (for example when preceded by {@link StderrLineTransform} / `StdioLineTransform`).\n * If a chunk does not end with a newline an error is thrown to surface incorrect pipeline wiring early.\n *\n * @beta\n */\nexport class ProblemCollector extends TerminalWritable implements IProblemCollector {\n private readonly _matchers: IProblemMatcher[];\n private readonly _problems: Set<IProblem> = new Set();\n private readonly _onProblem: ((problem: IProblem) => void) | undefined;\n\n public constructor(options: IProblemCollectorOptions) {\n super(options);\n\n if (\n !options ||\n ((!options.matchers || options.matchers.length === 0) &&\n (!options.matcherJson || options.matcherJson.length === 0))\n ) {\n throw new Error('ProblemCollector requires at least one problem matcher.');\n }\n\n const fromJson: IProblemMatcher[] = options.matcherJson\n ? parseProblemMatchersJson(options.matcherJson)\n : [];\n this._matchers = [...(options.matchers || []), ...fromJson];\n if (this._matchers.length === 0) {\n throw new Error('ProblemCollector requires at least one problem matcher.');\n }\n this._onProblem = options.onProblem;\n }\n\n /**\n * {@inheritdoc IProblemCollector}\n */\n public get problems(): ReadonlySet<IProblem> {\n return this._problems;\n }\n\n /**\n * {@inheritdoc TerminalWritable}\n */\n protected onWriteChunk(chunk: ITerminalChunk): void {\n const text: string = chunk.text;\n if (text.length === 0 || text[text.length - 1] !== '\\n') {\n throw new Error(\n 'ProblemCollector expects chunks that were split into newline terminated lines. ' +\n 'Invalid input: ' +\n JSON.stringify(text)\n );\n }\n\n for (const matcher of this._matchers) {\n const problem: IProblem | false = matcher.exec(text);\n if (problem) {\n const finalized: IProblem = {\n ...problem,\n matcherName: matcher.name\n };\n this._problems.add(finalized);\n this._onProblem?.(finalized);\n }\n }\n }\n\n /**\n * {@inheritdoc TerminalWritable}\n */\n protected onClose(): void {\n for (const matcher of this._matchers) {\n if (matcher.flush) {\n const flushed: IProblem[] = matcher.flush();\n if (flushed && flushed.length > 0) {\n for (const problem of flushed) {\n const finalized: IProblem = {\n ...problem,\n matcherName: matcher.name\n };\n this._problems.add(finalized);\n this._onProblem?.(finalized);\n }\n }\n }\n }\n }\n}\n"]}
@@ -7,9 +7,9 @@ import type { ITerminalChunk } from './ITerminalChunk';
7
7
  */
8
8
  export interface ISplitterTransformOptions extends ITerminalWritableOptions {
9
9
  /**
10
- * Each input chunk will be passed to each destination in the array.
10
+ * Each input chunk will be passed to each destination in the iterable.
11
11
  */
12
- destinations: TerminalWritable[];
12
+ destinations: Iterable<TerminalWritable>;
13
13
  }
14
14
  /**
15
15
  * Use this instead of {@link TerminalTransform} if you need to output `ITerminalChunk`
@@ -24,8 +24,25 @@ export interface ISplitterTransformOptions extends ITerminalWritableOptions {
24
24
  * @public
25
25
  */
26
26
  export declare class SplitterTransform extends TerminalWritable {
27
- readonly destinations: ReadonlyArray<TerminalWritable>;
27
+ private readonly _destinations;
28
28
  constructor(options: ISplitterTransformOptions);
29
+ get destinations(): ReadonlySet<TerminalWritable>;
30
+ /**
31
+ * Adds a destination to the set of destinations. Duplicates are ignored.
32
+ * Only new chunks received after the destination is added will be sent to it.
33
+ * @param destination - The destination to add.
34
+ */
35
+ addDestination(destination: TerminalWritable): void;
36
+ /**
37
+ * Removes a destination from the set of destinations. It will no longer receive chunks, and will be closed, unless
38
+ * `destination.preventAutoclose` is set to `true`.
39
+ * @param destination - The destination to remove.
40
+ * @param close - If `true` (default), the destination will be closed when removed, unless `destination.preventAutoclose` is set to `true`.
41
+ * @returns `true` if the destination was removed, `false` if it was not found.
42
+ * @remarks
43
+ * If the destination is not found, it will not be closed.
44
+ */
45
+ removeDestination(destination: TerminalWritable, close?: boolean): boolean;
29
46
  protected onWriteChunk(chunk: ITerminalChunk): void;
30
47
  protected onClose(): void;
31
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SplitterTransform.d.ts","sourceRoot":"","sources":["../src/SplitterTransform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;IACzE;;OAEG;IACH,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,iBAAkB,SAAQ,gBAAgB;IACrD,SAAgB,YAAY,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;gBAE3C,OAAO,EAAE,yBAAyB;IAKrD,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAMnD,SAAS,CAAC,OAAO,IAAI,IAAI;CAkB1B"}
1
+ {"version":3,"file":"SplitterTransform.d.ts","sourceRoot":"","sources":["../src/SplitterTransform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;IACzE;;OAEG;IACH,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,iBAAkB,SAAQ,gBAAgB;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAwB;gBAEnC,OAAO,EAAE,yBAAyB;IAKrD,IAAW,YAAY,IAAI,WAAW,CAAC,gBAAgB,CAAC,CAEvD;IAED;;;;OAIG;IACI,cAAc,CAAC,WAAW,EAAE,gBAAgB,GAAG,IAAI;IAI1D;;;;;;;;OAQG;IACI,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,EAAE,KAAK,GAAE,OAAc,GAAG,OAAO;IAUvF,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAMnD,SAAS,CAAC,OAAO,IAAI,IAAI;CAoB1B"}
@@ -19,17 +19,46 @@ const TerminalWritable_1 = require("./TerminalWritable");
19
19
  class SplitterTransform extends TerminalWritable_1.TerminalWritable {
20
20
  constructor(options) {
21
21
  super();
22
- this.destinations = [...options.destinations];
22
+ this._destinations = new Set(options.destinations);
23
+ }
24
+ get destinations() {
25
+ return this._destinations;
26
+ }
27
+ /**
28
+ * Adds a destination to the set of destinations. Duplicates are ignored.
29
+ * Only new chunks received after the destination is added will be sent to it.
30
+ * @param destination - The destination to add.
31
+ */
32
+ addDestination(destination) {
33
+ this._destinations.add(destination);
34
+ }
35
+ /**
36
+ * Removes a destination from the set of destinations. It will no longer receive chunks, and will be closed, unless
37
+ * `destination.preventAutoclose` is set to `true`.
38
+ * @param destination - The destination to remove.
39
+ * @param close - If `true` (default), the destination will be closed when removed, unless `destination.preventAutoclose` is set to `true`.
40
+ * @returns `true` if the destination was removed, `false` if it was not found.
41
+ * @remarks
42
+ * If the destination is not found, it will not be closed.
43
+ */
44
+ removeDestination(destination, close = true) {
45
+ if (this._destinations.delete(destination)) {
46
+ if (close && !destination.preventAutoclose) {
47
+ destination.close();
48
+ }
49
+ return true;
50
+ }
51
+ return false;
23
52
  }
24
53
  onWriteChunk(chunk) {
25
- for (const destination of this.destinations) {
54
+ for (const destination of this._destinations) {
26
55
  destination.writeChunk(chunk);
27
56
  }
28
57
  }
29
58
  onClose() {
30
59
  const errors = [];
31
60
  // If an exception is thrown, try to ensure that the other destinations get closed properly
32
- for (const destination of this.destinations) {
61
+ for (const destination of this._destinations) {
33
62
  if (!destination.preventAutoclose) {
34
63
  try {
35
64
  destination.close();
@@ -39,6 +68,7 @@ class SplitterTransform extends TerminalWritable_1.TerminalWritable {
39
68
  }
40
69
  }
41
70
  }
71
+ this._destinations.clear();
42
72
  if (errors.length > 0) {
43
73
  throw errors[0];
44
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SplitterTransform.js","sourceRoot":"","sources":["../src/SplitterTransform.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,yDAAqF;AAerF;;;;;;;;;;;GAWG;AACH,MAAa,iBAAkB,SAAQ,mCAAgB;IAGrD,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,YAAY,GAAG,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IAES,YAAY,CAAC,KAAqB;QAC1C,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC5C,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAES,OAAO;QACf,MAAM,MAAM,GAAY,EAAE,CAAC;QAE3B,2FAA2F;QAC3F,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC5C,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC;gBAClC,IAAI,CAAC;oBACH,WAAW,CAAC,KAAK,EAAE,CAAC;gBACtB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,CAAC,IAAI,CAAC,KAAc,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AAhCD,8CAgCC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { TerminalWritable, type ITerminalWritableOptions } from './TerminalWritable';\nimport type { ITerminalChunk } from './ITerminalChunk';\n\n/**\n * Constructor options for {@link SplitterTransform}.\n *\n * @public\n */\nexport interface ISplitterTransformOptions extends ITerminalWritableOptions {\n /**\n * Each input chunk will be passed to each destination in the array.\n */\n destinations: TerminalWritable[];\n}\n\n/**\n * Use this instead of {@link TerminalTransform} if you need to output `ITerminalChunk`\n * data to more than one destination.\n *\n * @remarks\n *\n * Splitting streams complicates the pipeline topology and can make debugging more difficult.\n * For this reason, it is modeled as an explicit `SplitterTransform` node, rather than\n * as a built-in feature of `TerminalTransform`.\n *\n * @public\n */\nexport class SplitterTransform extends TerminalWritable {\n public readonly destinations: ReadonlyArray<TerminalWritable>;\n\n public constructor(options: ISplitterTransformOptions) {\n super();\n this.destinations = [...options.destinations];\n }\n\n protected onWriteChunk(chunk: ITerminalChunk): void {\n for (const destination of this.destinations) {\n destination.writeChunk(chunk);\n }\n }\n\n protected onClose(): void {\n const errors: Error[] = [];\n\n // If an exception is thrown, try to ensure that the other destinations get closed properly\n for (const destination of this.destinations) {\n if (!destination.preventAutoclose) {\n try {\n destination.close();\n } catch (error) {\n errors.push(error as Error);\n }\n }\n }\n\n if (errors.length > 0) {\n throw errors[0];\n }\n }\n}\n"]}
1
+ {"version":3,"file":"SplitterTransform.js","sourceRoot":"","sources":["../src/SplitterTransform.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,yDAAqF;AAerF;;;;;;;;;;;GAWG;AACH,MAAa,iBAAkB,SAAQ,mCAAgB;IAGrD,YAAmB,OAAkC;QACnD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACrD,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,WAA6B;QACjD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACI,iBAAiB,CAAC,WAA6B,EAAE,QAAiB,IAAI;QAC3E,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3C,IAAI,KAAK,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC;gBAC3C,WAAW,CAAC,KAAK,EAAE,CAAC;YACtB,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAES,YAAY,CAAC,KAAqB;QAC1C,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC7C,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAES,OAAO;QACf,MAAM,MAAM,GAAY,EAAE,CAAC;QAE3B,2FAA2F;QAC3F,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC7C,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC;gBAClC,IAAI,CAAC;oBACH,WAAW,CAAC,KAAK,EAAE,CAAC;gBACtB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,CAAC,IAAI,CAAC,KAAc,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAE3B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AAlED,8CAkEC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { TerminalWritable, type ITerminalWritableOptions } from './TerminalWritable';\nimport type { ITerminalChunk } from './ITerminalChunk';\n\n/**\n * Constructor options for {@link SplitterTransform}.\n *\n * @public\n */\nexport interface ISplitterTransformOptions extends ITerminalWritableOptions {\n /**\n * Each input chunk will be passed to each destination in the iterable.\n */\n destinations: Iterable<TerminalWritable>;\n}\n\n/**\n * Use this instead of {@link TerminalTransform} if you need to output `ITerminalChunk`\n * data to more than one destination.\n *\n * @remarks\n *\n * Splitting streams complicates the pipeline topology and can make debugging more difficult.\n * For this reason, it is modeled as an explicit `SplitterTransform` node, rather than\n * as a built-in feature of `TerminalTransform`.\n *\n * @public\n */\nexport class SplitterTransform extends TerminalWritable {\n private readonly _destinations: Set<TerminalWritable>;\n\n public constructor(options: ISplitterTransformOptions) {\n super();\n this._destinations = new Set(options.destinations);\n }\n\n public get destinations(): ReadonlySet<TerminalWritable> {\n return this._destinations;\n }\n\n /**\n * Adds a destination to the set of destinations. Duplicates are ignored.\n * Only new chunks received after the destination is added will be sent to it.\n * @param destination - The destination to add.\n */\n public addDestination(destination: TerminalWritable): void {\n this._destinations.add(destination);\n }\n\n /**\n * Removes a destination from the set of destinations. It will no longer receive chunks, and will be closed, unless\n * `destination.preventAutoclose` is set to `true`.\n * @param destination - The destination to remove.\n * @param close - If `true` (default), the destination will be closed when removed, unless `destination.preventAutoclose` is set to `true`.\n * @returns `true` if the destination was removed, `false` if it was not found.\n * @remarks\n * If the destination is not found, it will not be closed.\n */\n public removeDestination(destination: TerminalWritable, close: boolean = true): boolean {\n if (this._destinations.delete(destination)) {\n if (close && !destination.preventAutoclose) {\n destination.close();\n }\n return true;\n }\n return false;\n }\n\n protected onWriteChunk(chunk: ITerminalChunk): void {\n for (const destination of this._destinations) {\n destination.writeChunk(chunk);\n }\n }\n\n protected onClose(): void {\n const errors: Error[] = [];\n\n // If an exception is thrown, try to ensure that the other destinations get closed properly\n for (const destination of this._destinations) {\n if (!destination.preventAutoclose) {\n try {\n destination.close();\n } catch (error) {\n errors.push(error as Error);\n }\n }\n }\n\n this._destinations.clear();\n\n if (errors.length > 0) {\n throw errors[0];\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/terminal",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "User interface primitives for console applications",
5
5
  "main": "lib/index.js",
6
6
  "typings": "dist/terminal.d.ts",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "supports-color": "~8.1.1",
15
- "@rushstack/node-core-library": "5.15.0",
16
- "@rushstack/problem-matcher": "0.1.0"
15
+ "@rushstack/problem-matcher": "0.1.1",
16
+ "@rushstack/node-core-library": "5.15.1"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@rushstack/heft": "0.74.3",