XuqmGroup-H5SDK/node_modules/@rushstack/terminal/lib-esm/ProblemCollector.js
徐勤民 e34fa2052a feat(private): add private deployment SDK module
Adds @xuqm/h5-sdk/private entry point with JSON-based initialization,
feature gating, and error codes for private deployment scenarios.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 21:08:08 +08:00

79 行
3.0 KiB
JavaScript

// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { parseProblemMatchersJson } from '@rushstack/problem-matcher';
import { TerminalWritable } from './TerminalWritable';
/**
* A {@link TerminalWritable} that consumes line-oriented terminal output and extracts structured
* problems using one or more {@link @rushstack/problem-matcher#IProblemMatcher | IProblemMatcher} instances.
*
* @remarks
* This collector expects that each incoming {@link ITerminalChunk} represents a single line terminated
* by a `"\n"` character (for example when preceded by {@link StderrLineTransform} / `StdioLineTransform`).
* If a chunk does not end with a newline an error is thrown to surface incorrect pipeline wiring early.
*
* @beta
*/
export class ProblemCollector extends TerminalWritable {
constructor(options) {
super(options);
this._problems = new Set();
const { matchers = [], matcherJson = [], onProblem } = options;
const fromJson = matcherJson.length !== 0 ? parseProblemMatchersJson(matcherJson) : [];
this._matchers = [...matchers, ...fromJson];
if (this._matchers.length === 0) {
throw new Error('ProblemCollector requires at least one problem matcher.');
}
this._onProblem = onProblem;
}
/**
* {@inheritdoc IProblemCollector}
*/
get problems() {
return this._problems;
}
/**
* {@inheritdoc TerminalWritable}
*/
onWriteChunk(chunk) {
var _a;
const text = chunk.text;
if (text.length === 0 || text[text.length - 1] !== '\n') {
throw new Error('ProblemCollector expects chunks that were split into newline terminated lines. ' +
'Invalid input: ' +
JSON.stringify(text));
}
for (const matcher of this._matchers) {
const problem = matcher.exec(text);
if (problem) {
const finalized = {
...problem,
matcherName: matcher.name
};
this._problems.add(finalized);
(_a = this._onProblem) === null || _a === void 0 ? void 0 : _a.call(this, finalized);
}
}
}
/**
* {@inheritdoc TerminalWritable}
*/
onClose() {
var _a;
for (const matcher of this._matchers) {
if (matcher.flush) {
const flushed = matcher.flush();
if (flushed && flushed.length > 0) {
for (const problem of flushed) {
const finalized = {
...problem,
matcherName: matcher.name
};
this._problems.add(finalized);
(_a = this._onProblem) === null || _a === void 0 ? void 0 : _a.call(this, finalized);
}
}
}
}
}
}
//# sourceMappingURL=ProblemCollector.js.map