From 8198f9f5fec330a389405194412310d22b3ab785 Mon Sep 17 00:00:00 2001 From: Matheus Costa Date: Fri, 2 May 2025 22:06:47 -0300 Subject: [PATCH 1/4] fix: extended CommandOptions with std events --- src/utils/commandExecutor.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/commandExecutor.ts b/src/utils/commandExecutor.ts index 1950e50..76943fc 100644 --- a/src/utils/commandExecutor.ts +++ b/src/utils/commandExecutor.ts @@ -3,6 +3,8 @@ import { Options, execa } from "execa"; export interface CommandOptions extends Options { reject?: boolean; timeout?: number; + onStdout?: (data: string) => void; + onStderr?: (data: string) => void; env?: Record; cwd?: string; } From f7cf9b886e63df9e7ad2c10ac3351f42a73b9c81 Mon Sep 17 00:00:00 2001 From: Matheus Costa Date: Fri, 2 May 2025 22:26:29 -0300 Subject: [PATCH 2/4] fix(Editor): hotfix import error from UnityEditor security --- src/unityEditor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unityEditor.ts b/src/unityEditor.ts index d36c4fe..05fc2ad 100644 --- a/src/unityEditor.ts +++ b/src/unityEditor.ts @@ -3,7 +3,7 @@ import fs from "fs-extra"; import path from "path"; import { ProjectInfo, TestMode, UnityBuildTarget, UnityEditorInfo } from "./types/unity.js"; import { CommandOptions, CommandResult, executeCommand } from "./utils/commandExecutor.js"; -import { redactSensitiveArgs } from "utils/security.js"; +import { redactSensitiveArgs } from "./utils/security.js"; /** * UnityEditor class provides a comprehensive interface for interacting with the Unity game engine editor From 4348611f96da5fbbed39895ac587a5e6caad1d03 Mon Sep 17 00:00:00 2001 From: Matheus Costa Date: Fri, 2 May 2025 23:45:26 -0300 Subject: [PATCH 3/4] fix: subprocess send streams stdout and stderr --- eslint.config.js | 2 +- src/utils/commandExecutor.ts | 38 ++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 08d5c2f..8d16c0f 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -33,7 +33,7 @@ export default defineConfig([ "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/strict-boolean-expressions": "off", "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/prefer-nullish-coalescing": "error", + "@typescript-eslint/prefer-nullish-coalescing": "warn", "@typescript-eslint/prefer-optional-chain": "error", "@typescript-eslint/no-unnecessary-type-assertion": "error", "@typescript-eslint/no-unnecessary-condition": "warn", diff --git a/src/utils/commandExecutor.ts b/src/utils/commandExecutor.ts index 76943fc..173c6aa 100644 --- a/src/utils/commandExecutor.ts +++ b/src/utils/commandExecutor.ts @@ -22,26 +22,44 @@ export async function executeCommand( options: CommandOptions = {} ): Promise { try { + const streamOutput = options.onStdout || options.onStderr; + const subprocess = execa(executable, args, { reject: options.reject ?? false, timeout: options.timeout, env: options.env, cwd: options.cwd, encoding: "utf8", + buffer: !streamOutput, }); - /* - // Pipe the output to the parent process - // This is commented out to avoid cluttering the output - // Uncomment if you want to see the output in real-time - if (subprocess.stdout) { - subprocess.stdout.pipe(process.stdout); - } + if (streamOutput) { + if (subprocess.stdout) { + subprocess.stdout.on("data", (data: Buffer) => { + const lines = data.toString().split(/\r?\n/); + for (const line of lines) { + if (line.trim()) { + if (options.onStdout) { + options.onStdout(line); + } + } + } + }); + } - if (subprocess.stderr) { - subprocess.stderr.pipe(process.stderr); + if (subprocess.stderr) { + subprocess.stderr.on("data", (data: Buffer) => { + const lines = data.toString().split(/\r?\n/); + for (const line of lines) { + if (line.trim()) { + if (options.onStderr) { + options.onStderr(line); + } + } + } + }); + } } - */ const { stdout, stderr, exitCode } = await subprocess; From ba21b462f3eee168909ae54003936e4c551bcaed Mon Sep 17 00:00:00 2001 From: Matheus Costa Date: Fri, 2 May 2025 23:46:29 -0300 Subject: [PATCH 4/4] fix(Hub): simple stream output feedback close #13 --- src/unityHub.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/unityHub.ts b/src/unityHub.ts index 8d7ced6..75234c4 100644 --- a/src/unityHub.ts +++ b/src/unityHub.ts @@ -234,12 +234,16 @@ class UnityHub { throw new Error("No module IDs provided."); } - const { stdout, stderr } = await this.execUnityHubCommand(args, { + const { stderr } = await this.execUnityHubCommand(args, { reject: false, + onStderr: (data: string) => { + console.warn(`Unity Hub stderr: ${data}`); + }, + onStdout: (data: string) => { + console.debug(`Unity Hub stdout: ${data}`); + }, }); - console.debug(`Add module command output: ${stdout}`); - if (stderr) { console.warn(`Add module command warning/error: ${stderr}`); } @@ -286,6 +290,12 @@ class UnityHub { const { stdout, stderr } = await this.execUnityHubCommand(args, { reject: false, + onStderr: (data: string) => { + console.warn(`Unity Hub stderr: ${data}`); + }, + onStdout: (data: string) => { + console.debug(`Unity Hub stdout: ${data}`); + }, }); if (stderr) {