2026-10-07 16:03:37 +08:00
|
|
|
import { analyzeJavaScriptApplication } from "../application/javascript/JavaScriptApplicationService.js";
|
2026-10-08 03:19:37 +08:00
|
|
|
import { createProgressReporter } from "../application/ProgressReporter.js";
|
2026-10-06 05:57:38 +08:00
|
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
2026-07-21 23:42:28 +08:00
|
|
|
import type { JsonValue } from "../domain/jsonValue.js";
|
2026-10-08 03:44:51 +08:00
|
|
|
import type { CliCommandOutput } from "./streamedJsonOutput.js";
|
2026-07-21 23:42:28 +08:00
|
|
|
|
|
|
|
|
/** Execute the shared one-shot CLI boundary for static JavaScript analysis. */
|
|
|
|
|
export const runCliJavaScriptApplicationAnalysis = async (
|
|
|
|
|
input: unknown,
|
2026-10-08 03:44:51 +08:00
|
|
|
output?: CliCommandOutput,
|
2026-10-09 01:15:50 +08:00
|
|
|
signal?: AbortSignal,
|
2026-10-08 03:44:51 +08:00
|
|
|
): Promise<JsonValue | undefined> => {
|
|
|
|
|
const started = performance.now();
|
2026-10-08 03:19:37 +08:00
|
|
|
const progress = createProgressReporter(
|
|
|
|
|
async (update) => {
|
|
|
|
|
process.stderr.write(`${JSON.stringify({ rea_progress: update })}\n`);
|
|
|
|
|
},
|
|
|
|
|
{ minimumIntervalMs: 0 },
|
|
|
|
|
);
|
2026-10-09 01:15:50 +08:00
|
|
|
const result = await analyzeJavaScriptApplication(input, {
|
|
|
|
|
progress,
|
|
|
|
|
...(signal === undefined ? {} : { signal }),
|
|
|
|
|
});
|
2026-10-08 03:44:51 +08:00
|
|
|
const value = result.ok ? result.value : cliError(result.error);
|
|
|
|
|
if (
|
|
|
|
|
output !== undefined &&
|
|
|
|
|
(await output.output.write(value, {
|
|
|
|
|
command: output.command,
|
|
|
|
|
format: output.format,
|
|
|
|
|
duration: `${Math.round(performance.now() - started)}ms`,
|
|
|
|
|
}))
|
|
|
|
|
)
|
2026-10-09 01:15:50 +08:00
|
|
|
// Keep failures visible to command logging after the stream has handled stdout.
|
|
|
|
|
return result.ok ? undefined : value;
|
2026-10-08 03:44:51 +08:00
|
|
|
return value;
|
2026-07-21 23:42:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const cliError = (
|
|
|
|
|
error: Parameters<typeof projectAnalysisError>[0],
|
|
|
|
|
): JsonValue => ({
|
|
|
|
|
error: "JavaScript application analysis failed",
|
|
|
|
|
...projectAnalysisError(error),
|
|
|
|
|
});
|