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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rage-against-the-pixel/unity-cli",
"version": "1.3.1",
"version": "1.3.2",
"description": "A command line utility for the Unity Game Engine.",
"author": "RageAgainstThePixel",
"license": "MIT",
Expand Down
25 changes: 10 additions & 15 deletions src/android-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ async function getAndroidSdkPath(rootEditorPath: string, androidTargetSdk: numbe
}

async function execSdkManager(sdkManagerPath: string, javaPath: string, args: string[]): Promise<void> {
const acceptBuffer = Buffer.from(Array(10).fill('y').join('\n'), 'utf8');
let output = '';
let exitCode = 0;

Expand All @@ -127,7 +126,10 @@ async function execSdkManager(sdkManagerPath: string, javaPath: string, args: st
exitCode = await new Promise<number>((resolve, reject) => {
const child = spawn(sdkManagerPath, args, {
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, JAVA_HOME: javaPath }
env: {
...process.env,
JAVA_HOME: process.platform === 'win32' ? `"${javaPath}"` : javaPath
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding quotes around the JAVA_HOME path on Windows can cause issues. Environment variable values should not include quotes - the operating system handles paths with spaces correctly without them. This could break Java execution if the JDK tools don't expect quoted paths.

Suggested change
JAVA_HOME: process.platform === 'win32' ? `"${javaPath}"` : javaPath
JAVA_HOME: javaPath

Copilot uses AI. Check for mistakes.
}
});
const sigintHandler = () => child.kill('SIGINT');
const sigtermHandler = () => child.kill('SIGTERM');
Expand All @@ -142,22 +144,15 @@ async function execSdkManager(sdkManagerPath: string, javaPath: string, args: st
process.removeListener('SIGTERM', sigtermHandler);
}

child.stdout.on('data', (data: Buffer) => {
const chunk = data.toString();
output += chunk;

if (output.includes('Accept? (y/N):')) {
child.stdin?.write(acceptBuffer);
output = '';
}

process.stdout.write(chunk);
});
child.stderr.on('data', (data: Buffer) => {
function handleDataStream(data: Buffer) {
const chunk = data.toString();
output += chunk;
process.stderr.write(chunk);
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handleDataStream function writes all output to stderr, but it's being used for both stdout and stderr streams (lines 154-155). Output from child.stdout should be written to process.stdout, not process.stderr.

Copilot uses AI. Check for mistakes.
});
}
const acceptBuffer = Buffer.from(Array(10).fill('y').join(os.EOL), 'utf8');
child.stdin.write(acceptBuffer);
child.stdout.on('data', (data: Buffer) => handleDataStream(data));
child.stderr.on('data', (data: Buffer) => handleDataStream(data));
Comment on lines +152 to +155
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing all license acceptances to stdin immediately before the SDK manager prompts may cause issues. The previous implementation waited for the 'Accept? (y/N):' prompt before responding. Pre-writing responses could lead to the input being consumed before prompts appear or cause the SDK manager to behave unexpectedly if it doesn't buffer stdin properly.

Suggested change
const acceptBuffer = Buffer.from(Array(10).fill('y').join(os.EOL), 'utf8');
child.stdin.write(acceptBuffer);
child.stdout.on('data', (data: Buffer) => handleDataStream(data));
child.stderr.on('data', (data: Buffer) => handleDataStream(data));
// Respond to license prompts only when detected in output
const licensePromptRegex = /Accept\?\s*\(y\/N\):/i;
let stdoutBuffer = '';
let stderrBuffer = '';
function checkAndRespond(buffer: string) {
if (licensePromptRegex.test(buffer)) {
child.stdin.write('y' + os.EOL);
}
}
child.stdout.on('data', (data: Buffer) => {
const chunk = data.toString();
stdoutBuffer += chunk;
handleDataStream(data);
checkAndRespond(stdoutBuffer);
// Keep buffer from growing indefinitely
if (stdoutBuffer.length > 1000) stdoutBuffer = stdoutBuffer.slice(-1000);
});
child.stderr.on('data', (data: Buffer) => {
const chunk = data.toString();
stderrBuffer += chunk;
handleDataStream(data);
checkAndRespond(stderrBuffer);
if (stderrBuffer.length > 1000) stderrBuffer = stderrBuffer.slice(-1000);
});

Copilot uses AI. Check for mistakes.
child.on('error', (error) => {
removeListeners();
reject(error);
Expand Down
Loading