Skip to content

Commit

Permalink
attempt at fixing npx and uvx ( not working yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvadratni committed Feb 6, 2025
1 parent f6e0d7e commit f08f929
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 111 deletions.
18 changes: 13 additions & 5 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,20 @@ make-ui-windows:
mkdir -p ./ui/desktop/src/bin; \
cp -f ./target/x86_64-pc-windows-gnu/release/goosed.exe ./ui/desktop/src/bin/; \
cp -f ./target/x86_64-pc-windows-gnu/release/*.dll ./ui/desktop/src/bin/; \
echo "Setting up Windows tools..."; \
cd ui/desktop && node scripts/setup-windows-tools.js || exit 1; \
echo "Building Windows package..."; \
cd ui/desktop && \
npm run bundle:windows && \
mkdir -p out/Goose-win32-x64/resources/bin && \
cp -f src/bin/goosed.exe out/Goose-win32-x64/resources/bin/ && \
cp -f src/bin/*.dll out/Goose-win32-x64/resources/bin/; \
if [ -f "src/bin/uvx.bat" ] && [ -f "src/bin/npx.bat" ]; then \
npm run bundle:windows && \
mkdir -p out/Goose-win32-x64/resources/bin && \
cp -f src/bin/goosed.exe out/Goose-win32-x64/resources/bin/ && \
cp -f src/bin/*.dll out/Goose-win32-x64/resources/bin/ && \
cp -f src/bin/*.bat out/Goose-win32-x64/resources/bin/ && \
cp -f src/bin/*.cmd out/Goose-win32-x64/resources/bin/; \
else \
echo "Windows tools setup failed - missing required files"; \
exit 1; \
fi \
else \
echo "Windows binary not found."; \
exit 1; \
Expand Down
3 changes: 2 additions & 1 deletion ui/desktop/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.vite/
out
src/bin/goosed
src/bin/goosed
/src/bin/goosed.exe
2 changes: 1 addition & 1 deletion ui/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "goose-app",
"productName": "Goose",
"version": "1.0.61",
"version": "1.0.6",
"description": "Goose App",
"main": ".vite/build/main.js",
"scripts": {
Expand Down
171 changes: 171 additions & 0 deletions ui/desktop/scripts/setup-windows-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// Ensure bin directory exists
const binDir = path.join(__dirname, '..', 'src', 'bin');
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}

try {
console.log('Creating uvx wrapper...');

// Create a simple uvx script that handles the toml command and mcp-server commands
const uvxScript = `#!/usr/bin/env node
const { execSync, spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
// Simple argument parser
const args = process.argv.slice(2);
// Create a temporary directory for npm operations
const getTempDir = () => {
const tempDir = path.join(os.tmpdir(), 'goose-npm-' + Math.random().toString(36).substring(7));
fs.mkdirSync(tempDir, { recursive: true });
return tempDir;
};
// Helper function to run npm install with SSL verification disabled
const npmInstall = (pkg, cwd) => {
const npmCommand = \`npm install \${pkg} --no-save --registry=https://registry.npmjs.org/ --strict-ssl=false\`;
console.log('Running npm install command:', npmCommand);
return execSync(npmCommand, {
cwd,
stdio: 'inherit',
env: {
...process.env,
npm_config_registry: 'https://registry.npmjs.org/',
npm_config_strict_ssl: 'false'
}
});
};
// Helper function to run MCP servers
const runMcpServer = async (serverType) => {
try {
// Create temp directory and install the server
const tempDir = getTempDir();
fs.writeFileSync(path.join(tempDir, 'package.json'), JSON.stringify({
name: 'temp',
version: '1.0.0'
}));
console.log(\`Installing \${serverType}...\`);
const packageName = \`@modelcontextprotocol/server-\${serverType.replace('mcp-server-', '')}\`;
npmInstall(packageName, tempDir);
console.log(\`Starting \${serverType}...\`);
const serverPath = path.join(tempDir, 'node_modules', packageName, 'dist', 'index.js');
// Log the server path and check if it exists
console.log('Server path:', serverPath);
console.log('Server path exists:', fs.existsSync(serverPath));
console.log('Contents of node_modules:', fs.readdirSync(path.join(tempDir, 'node_modules')));
const child = spawn('node', [serverPath], {
stdio: 'inherit',
cwd: tempDir,
env: {
...process.env,
npm_config_registry: 'https://registry.npmjs.org/',
npm_config_strict_ssl: 'false'
}
});
child.on('error', (error) => {
console.error(\`Failed to start \${serverType}:\`, error);
process.exit(1);
});
// Clean up temp directory when process exits
process.on('exit', () => {
try {
fs.rmSync(tempDir, { recursive: true, force: true });
} catch (error) {
console.error('Error cleaning up:', error);
}
});
child.on('exit', (code) => {
process.exit(code);
});
} catch (error) {
console.error(\`Error executing \${serverType}:\`, error);
process.exit(1);
}
};
if (args[0] === '--from' && args[1] === 'toml-cli' && args[2] === 'toml') {
// Handle toml command
const tomlArgs = args.slice(2);
try {
// Create temp directory and install toml-cli
const tempDir = getTempDir();
fs.writeFileSync(path.join(tempDir, 'package.json'), JSON.stringify({
name: 'temp',
version: '1.0.0'
}));
npmInstall('toml-cli', tempDir);
const result = execSync('node ' + path.join('node_modules', '.bin', 'toml') + ' ' + tomlArgs.join(' '), {
cwd: tempDir,
stdio: 'pipe',
encoding: 'utf8'
});
console.log(result.trim());
fs.rmSync(tempDir, { recursive: true, force: true });
} catch (error) {
console.error('Error executing toml command:', error.message);
process.exit(1);
}
} else if (args[0].startsWith('mcp-server-')) {
// Handle any mcp-server command
runMcpServer(args[0]);
} else {
console.error('Unsupported uvx command');
process.exit(1);
}
`;

// Create the uvx script file
fs.writeFileSync(path.join(binDir, 'uvx'), uvxScript);
fs.chmodSync(path.join(binDir, 'uvx'), '755'); // Make executable

// Create uvx.cmd wrapper for Windows
const uvxCmd = `@ECHO off
SET NODE_NO_WARNINGS=1
SET npm_config_registry=https://registry.npmjs.org/
SET npm_config_strict_ssl=false
node "%~dp0\\uvx" %*`;
fs.writeFileSync(path.join(binDir, 'uvx.cmd'), uvxCmd);

// Create uvx.bat for Windows
const uvxBat = `@ECHO off
SET NODE_NO_WARNINGS=1
SET npm_config_registry=https://registry.npmjs.org/
SET npm_config_strict_ssl=false
node "%~dp0\\uvx" %*`;
fs.writeFileSync(path.join(binDir, 'uvx.bat'), uvxBat);

// Verify files exist
const files = ['uvx', 'uvx.cmd', 'uvx.bat'];
const missingFiles = files.filter(file => !fs.existsSync(path.join(binDir, file)));

if (missingFiles.length > 0) {
throw new Error(`Missing files after setup: ${missingFiles.join(', ')}`);
}

console.log('Successfully created Windows tools');
console.log('Files in bin directory:', fs.readdirSync(binDir));
} catch (error) {
console.error('Error creating Windows tools:', error);
process.exit(1);
}
1 change: 1 addition & 0 deletions ui/desktop/scripts/temp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"temp","version":"1.0.0","description":"Temporary package for installing tools"}
Binary file added ui/desktop/src/bin/libgcc_s_seh-1.dll
Binary file not shown.
Binary file added ui/desktop/src/bin/libstdc++-6.dll
Binary file not shown.
Binary file added ui/desktop/src/bin/libwinpthread-1.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions ui/desktop/src/bin/npx.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO off
SET NODE_NO_WARNINGS=1
node "%~dp0\npx.cmd" %*
3 changes: 3 additions & 0 deletions ui/desktop/src/bin/npx.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO off
SET NODE_NO_WARNINGS=1
node "%~dp0\..\node_modules\npm\bin\npx-cli.js" %*
Loading

0 comments on commit f08f929

Please sign in to comment.