Skip to content

Self-improving AI Employees for everyone

Fix npm install output visibility and Windows build

trohitg37792fbbd4df
diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml
index b06588b2..cb29e79b 100644
--- a/.github/workflows/build-binaries.yml
+++ b/.github/workflows/build-binaries.yml
@@ -47,14 +47,19 @@ jobs:
go-version: '1.24'
cache-dependency-path: server/whatsapp-rpc/go.sum
- - name: Install GCC (Windows)
+ - name: Setup MSYS2 (Windows)
if: matrix.os == 'windows-latest'
- run: choco install mingw -y
+ uses: msys2/setup-msys2@v2
+ with:
+ msystem: MINGW64
+ update: false
+ install: mingw-w64-x86_64-gcc
- name: Build WhatsApp RPC Server
working-directory: server/whatsapp-rpc
env:
CGO_ENABLED: 1
+ CC: ${{ matrix.os == 'windows-latest' && 'C:/msys64/mingw64/bin/gcc.exe' || 'gcc' }}
run: go build -ldflags="-s -w" -o whatsapp-rpc-server-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }} ./src/go/cmd/server
- name: Upload artifact
diff --git a/scripts/build.js b/scripts/build.js
index eb361ee2..415a668a 100644
--- a/scripts/build.js
+++ b/scripts/build.js
@@ -26,17 +26,20 @@ const isMac = process.platform === 'darwin';
const isPostInstall = process.env.npm_lifecycle_event === 'postinstall';
const isCI = process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true';
+// Ensure Python UTF-8 encoding
+process.env.PYTHONUTF8 = '1';
+
+// Use stderr for all output so npm shows it during postinstall
+const print = (msg) => process.stderr.write(msg + '\n');
+
// Skip build entirely in CI (workflows handle this)
if (isCI && isPostInstall) {
- console.log('CI environment detected, skipping postinstall build.');
+ print('CI environment detected, skipping postinstall build.');
process.exit(0);
}
-// Ensure Python UTF-8 encoding
-process.env.PYTHONUTF8 = '1';
-
function run(cmd, cwd = ROOT) {
- execSync(cmd, { cwd, stdio: 'inherit', shell: true });
+ execSync(cmd, { cwd, stdio: ['inherit', process.stderr, process.stderr], shell: true });
}
function runSilent(cmd) {
@@ -57,13 +60,13 @@ function getVersion(cmd) {
}
function log(step, msg) {
- console.log(`[${step}] ${msg}`);
+ print(`[${step}] ${msg}`);
}
function npmInstall(cwd = ROOT) {
- // Use npm install directly with visible output
+ // Use npm install directly with visible output via stderr
// npm ci requires package-lock.json which may not exist in all directories
- execSync('npm install', { cwd, stdio: 'inherit', shell: true });
+ execSync('npm install', { cwd, stdio: ['inherit', process.stderr, process.stderr], shell: true });
}
// ============================================================================
@@ -71,7 +74,7 @@ function npmInstall(cwd = ROOT) {
// ============================================================================
function installPython() {
- console.log(' Installing Python 3.11+...');
+ print(' Installing Python 3.11+...');
if (isWindows) {
// Try winget first, then choco
if (runSilent('winget --version')) {
@@ -79,15 +82,15 @@ function installPython() {
} else if (runSilent('choco --version')) {
run('choco install python312 -y');
} else {
- console.error(' Error: Please install Python manually from https://python.org/');
- console.error(' Or install winget/chocolatey first.');
+ print(' Error: Please install Python manually from https://python.org/');
+ print(' Or install winget/chocolatey first.');
process.exit(1);
}
} else if (isMac) {
if (runSilent('brew --version')) {
run('brew install [email protected]');
} else {
- console.error(' Error: Please install Homebrew first: https://brew.sh/');
+ print(' Error: Please install Homebrew first: https://brew.sh/');
process.exit(1);
}
} else {
@@ -99,14 +102,14 @@ function installPython() {
} else if (runSilent('pacman --version')) {
run('sudo pacman -S --noconfirm python');
} else {
- console.error(' Error: Please install Python manually from https://python.org/');
+ print(' Error: Please install Python manually from https://python.org/');
process.exit(1);
}
}
}
function installUv() {
- console.log(' Installing uv...');
+ print(' Installing uv...');
if (isWindows) {
run('powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"');
} else {
@@ -121,21 +124,21 @@ function installUv() {
}
function installGo() {
- console.log(' Installing Go...');
+ print(' Installing Go...');
if (isWindows) {
if (runSilent('winget --version')) {
run('winget install GoLang.Go --accept-package-agreements --accept-source-agreements');
} else if (runSilent('choco --version')) {
run('choco install golang -y');
} else {
- console.error(' Error: Please install Go manually from https://go.dev/dl/');
+ print(' Error: Please install Go manually from https://go.dev/dl/');
process.exit(1);
}
} else if (isMac) {
if (runSilent('brew --version')) {
run('brew install go');
} else {
- console.error(' Error: Please install Homebrew first: https://brew.sh/');
+ print(' Error: Please install Homebrew first: https://brew.sh/');
process.exit(1);
}
} else {
@@ -146,7 +149,7 @@ function installGo() {
} else if (runSilent('pacman --version')) {
run('sudo pacman -S --noconfirm go');
} else {
- console.error(' Error: Please install Go manually from https://go.dev/dl/');
+ print(' Error: Please install Go manually from https://go.dev/dl/');
process.exit(1);
}
}
@@ -156,14 +159,14 @@ function installGo() {
// Check and Install Dependencies
// ============================================================================
-console.log('Checking dependencies...\n');
+print('Checking dependencies...\n');
// Node.js (must already be installed to run this script)
const nodeVersion = getVersion('node --version');
-console.log(` Node.js: ${nodeVersion}`);
+print(` Node.js: ${nodeVersion}`);
const npmVersion = getVersion('npm --version');
-console.log(` npm: ${npmVersion}`);
+print(` npm: ${npmVersion}`);
// Python
let pyCmd = null;
@@ -179,9 +182,9 @@ if (pyCmd) {
if (match) {
const [, major, minor] = match.map(Number);
if (major >= 3 && minor >= 11) {
- console.log(` ${pyVersion}`);
+ print(` ${pyVersion}`);
} else {
- console.log(` ${pyVersion} (too old, need 3.11+)`);
+ print(` ${pyVersion} (too old, need 3.11+)`);
installPython();
}
}
@@ -189,21 +192,21 @@ if (pyCmd) {
installPython();
// Re-check
pyCmd = runSilent('python --version') ? 'python' : 'python3';
- console.log(` ${getVersion(`${pyCmd} --version`)}`);
+ print(` ${getVersion(`${pyCmd} --version`)}`);
}
// uv
let uvVersion = getVersion('uv --version');
if (uvVersion) {
- console.log(` uv: ${uvVersion}`);
+ print(` uv: ${uvVersion}`);
} else {
installUv();
uvVersion = getVersion('uv --version');
if (uvVersion) {
- console.log(` uv: ${uvVersion}`);
+ print(` uv: ${uvVersion}`);
} else {
- console.error(' Error: Failed to install uv. Please install manually.');
- console.error(' https://docs.astral.sh/uv/getting-started/installation/');
+ print(' Error: Failed to install uv. Please install manually.');
+ print(' https://docs.astral.sh/uv/getting-started/installation/');
process.exit(1);
}
}
@@ -212,21 +215,21 @@ if (uvVersion) {
let goVersionFull = getVersion('go version');
if (goVersionFull) {
const goVersion = goVersionFull.match(/go\d+\.\d+(\.\d+)?/)?.[0] || 'go';
- console.log(` Go: ${goVersion}`);
+ print(` Go: ${goVersion}`);
} else {
installGo();
goVersionFull = getVersion('go version');
if (goVersionFull) {
const goVersion = goVersionFull.match(/go\d+\.\d+(\.\d+)?/)?.[0] || 'go';
- console.log(` Go: ${goVersion}`);
+ print(` Go: ${goVersion}`);
} else {
- console.error(' Error: Failed to install Go. Please install manually.');
- console.error(' https://go.dev/dl/');
+ print(' Error: Failed to install Go. Please install manually.');
+ print(' https://go.dev/dl/');
process.exit(1);
}
}
-console.log('\nAll dependencies ready.\n');
+print('\nAll dependencies ready.\n');
// ============================================================================
// Build
@@ -272,9 +275,9 @@ try {
log('6/6', 'Building WhatsApp server...');
run('npm run build', whatsappDir);
- console.log('\nBuild complete.');
+ print('\nBuild complete.');
} catch (err) {
- console.error('\nBuild failed:', err.message);
+ print(`\nBuild failed: ${err.message}`);
process.exit(1);
}
diff --git a/scripts/postinstall.js b/scripts/postinstall.js
index 761bfa6e..3d4a521a 100644
--- a/scripts/postinstall.js
+++ b/scripts/postinstall.js
@@ -37,15 +37,19 @@ print(' MachinaOS - Installing...');
print('========================================');
print('');
-// Run a script and pipe output to stderr
+// Run a script and pipe all output to stderr (npm shows stderr during install)
function runScript(scriptPath) {
return new Promise((resolve, reject) => {
const child = spawn(process.execPath, [scriptPath], {
cwd: ROOT,
- stdio: ['inherit', process.stderr, 'inherit'],
+ stdio: ['inherit', 'pipe', 'pipe'],
env: { ...process.env, FORCE_COLOR: '1' }
});
+ // Pipe stdout to stderr so npm shows it
+ child.stdout.on('data', (data) => process.stderr.write(data));
+ child.stderr.on('data', (data) => process.stderr.write(data));
+
child.on('error', reject);
child.on('close', (code) => {
if (code === 0) {