Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/unityEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/unityHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down Expand Up @@ -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) {
Expand Down
40 changes: 30 additions & 10 deletions src/utils/commandExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
cwd?: string;
}
Expand All @@ -20,26 +22,44 @@ export async function executeCommand(
options: CommandOptions = {}
): Promise<CommandResult> {
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;

Expand Down