mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-21 13:55:54 +00:00
Work on custom node installer
This commit is contained in:
parent
f1288417b1
commit
932beff906
2 changed files with 87 additions and 23 deletions
|
|
@ -107,7 +107,33 @@ BUILD_CONFIG="${CONFIGURATION:-Debug}"
|
|||
echo "Build configuration: $BUILD_CONFIG"
|
||||
|
||||
# Check for custom Node.js build
|
||||
CUSTOM_NODE_PATH=$(find "${WEB_DIR}/.node-builds" -name "node-v*-minimal" -type d 2>/dev/null | sort -V | tail -n1)/out/Release/node
|
||||
echo "Searching for custom Node.js builds..."
|
||||
|
||||
# Find all Node build directories
|
||||
ALL_NODE_DIRS=$(find "${WEB_DIR}/.node-builds" -name "node-v*-minimal" -type d 2>/dev/null | sort -V)
|
||||
if [ -n "$ALL_NODE_DIRS" ]; then
|
||||
echo "Found Node.js build directories:"
|
||||
echo "$ALL_NODE_DIRS" | while read -r dir; do
|
||||
if [ -f "$dir/out/Release/node" ]; then
|
||||
VERSION=$(basename "$dir" | sed 's/node-v\(.*\)-minimal/\1/')
|
||||
echo " ✓ $VERSION (complete build)"
|
||||
else
|
||||
VERSION=$(basename "$dir" | sed 's/node-v\(.*\)-minimal/\1/')
|
||||
echo " ✗ $VERSION (incomplete build - missing binary)"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Find directories with complete builds (containing the actual node binary)
|
||||
CUSTOM_NODE_DIR=$(find "${WEB_DIR}/.node-builds" -name "node-v*-minimal" -type d -exec test -f {}/out/Release/node \; -print 2>/dev/null | sort -V | tail -n1)
|
||||
CUSTOM_NODE_PATH="${CUSTOM_NODE_DIR}/out/Release/node"
|
||||
|
||||
if [ -n "$CUSTOM_NODE_DIR" ]; then
|
||||
SELECTED_VERSION=$(basename "$CUSTOM_NODE_DIR" | sed 's/node-v\(.*\)-minimal/\1/')
|
||||
echo "Selected custom Node.js v$SELECTED_VERSION"
|
||||
else
|
||||
echo "No complete custom Node.js builds found"
|
||||
fi
|
||||
|
||||
# Build the web frontend
|
||||
if [ "$BUILD_CONFIG" = "Release" ]; then
|
||||
|
|
@ -117,7 +143,8 @@ if [ "$BUILD_CONFIG" = "Release" ]; then
|
|||
echo "Custom Node.js not found, building it for optimal size..."
|
||||
echo "This will take 10-20 minutes on first run but will be cached."
|
||||
node build-custom-node.js --latest
|
||||
CUSTOM_NODE_PATH=$(find "${WEB_DIR}/.node-builds" -name "node-v*-minimal" -type d 2>/dev/null | sort -V | tail -n1)/out/Release/node
|
||||
CUSTOM_NODE_DIR=$(find "${WEB_DIR}/.node-builds" -name "node-v*-minimal" -type d -exec test -f {}/out/Release/node \; -print 2>/dev/null | sort -V | tail -n1)
|
||||
CUSTOM_NODE_PATH="${CUSTOM_NODE_DIR}/out/Release/node"
|
||||
fi
|
||||
|
||||
if [ -f "$CUSTOM_NODE_PATH" ]; then
|
||||
|
|
@ -232,14 +259,19 @@ if [ ${#MISSING_FILES[@]} -gt 0 ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Optional: Verify the executable works
|
||||
# Verify the executable works
|
||||
echo "Verifying vibetunnel executable..."
|
||||
if "${APP_RESOURCES}/vibetunnel" --version &>/dev/null; then
|
||||
VERSION_OUTPUT=$("${APP_RESOURCES}/vibetunnel" --version 2>&1 | head -1)
|
||||
echo "Full path: ${APP_RESOURCES}/vibetunnel"
|
||||
if "${APP_RESOURCES}/vibetunnel" version &>/dev/null; then
|
||||
VERSION_OUTPUT=$("${APP_RESOURCES}/vibetunnel" version 2>&1 | head -1)
|
||||
echo "✓ VibeTunnel executable verified: $VERSION_OUTPUT"
|
||||
else
|
||||
echo "error: VibeTunnel executable failed verification (--version test failed)"
|
||||
echo "This might indicate a corrupted or incompatible binary"
|
||||
echo "error: VibeTunnel executable failed verification (version command failed)"
|
||||
echo "Full executable path: ${APP_RESOURCES}/vibetunnel"
|
||||
echo "Checking if file exists and is executable:"
|
||||
ls -la "${APP_RESOURCES}/vibetunnel" || echo "File not found!"
|
||||
echo "Attempting to run with error output:"
|
||||
"${APP_RESOURCES}/vibetunnel" version 2>&1 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -124,9 +124,9 @@ function patchNodePty() {
|
|||
execSync('rm -rf node_modules/@homebridge/node-pty-prebuilt-multiarch', { stdio: 'inherit' });
|
||||
execSync('npm install @homebridge/node-pty-prebuilt-multiarch --silent --no-fund --no-audit', { stdio: 'inherit' });
|
||||
|
||||
// If using custom Node.js, check if we need to rebuild
|
||||
// If using custom Node.js, rebuild native modules
|
||||
if (customNodePath) {
|
||||
console.log('Custom Node.js detected - checking native module compatibility...');
|
||||
console.log('Custom Node.js detected - rebuilding native modules...');
|
||||
|
||||
// Get versions
|
||||
const customVersion = execSync(`"${customNodePath}" --version`, { encoding: 'utf8' }).trim();
|
||||
|
|
@ -135,15 +135,47 @@ function patchNodePty() {
|
|||
console.log(`Custom Node.js: ${customVersion}`);
|
||||
console.log(`System Node.js: ${systemVersion}`);
|
||||
|
||||
// Extract major versions
|
||||
const customMajor = parseInt(customVersion.substring(1).split('.')[0]);
|
||||
const systemMajor = parseInt(systemVersion.substring(1).split('.')[0]);
|
||||
// Rebuild node-pty with the custom Node using npm rebuild
|
||||
console.log('Rebuilding @homebridge/node-pty-prebuilt-multiarch with custom Node.js...');
|
||||
|
||||
if (customMajor !== systemMajor) {
|
||||
console.warn(`WARNING: Major version mismatch (${customMajor} vs ${systemMajor})`);
|
||||
console.warn('Native modules may not be compatible. Consider rebuilding.');
|
||||
} else {
|
||||
console.log('Major versions match - native modules should be compatible.');
|
||||
try {
|
||||
// Use the custom Node to rebuild native modules
|
||||
execSync(`"${customNodePath}" "$(which npm)" rebuild @homebridge/node-pty-prebuilt-multiarch`, {
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
...process.env,
|
||||
npm_config_runtime: 'node',
|
||||
npm_config_target: customVersion.substring(1), // Remove 'v' prefix
|
||||
npm_config_arch: process.arch,
|
||||
npm_config_target_arch: process.arch,
|
||||
npm_config_disturl: 'https://nodejs.org/dist',
|
||||
npm_config_build_from_source: 'true'
|
||||
}
|
||||
});
|
||||
console.log('Native module rebuilt successfully with custom Node.js');
|
||||
} catch (error) {
|
||||
console.error('Failed to rebuild native module:', error.message);
|
||||
console.error('Trying alternative rebuild method...');
|
||||
|
||||
// Alternative: Force rebuild from source
|
||||
try {
|
||||
execSync(`rm -rf node_modules/@homebridge/node-pty-prebuilt-multiarch/build`, { stdio: 'inherit' });
|
||||
execSync(`"${customNodePath}" "$(which npm)" install @homebridge/node-pty-prebuilt-multiarch --build-from-source`, {
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
...process.env,
|
||||
npm_config_runtime: 'node',
|
||||
npm_config_target: customVersion.substring(1),
|
||||
npm_config_arch: process.arch,
|
||||
npm_config_target_arch: process.arch,
|
||||
npm_config_disturl: 'https://nodejs.org/dist'
|
||||
}
|
||||
});
|
||||
console.log('Native module rebuilt from source successfully');
|
||||
} catch (error2) {
|
||||
console.error('Alternative rebuild also failed:', error2.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -405,12 +437,7 @@ async function main() {
|
|||
console.log(`Final executable size: ${(finalStats.size / 1024 / 1024).toFixed(2)} MB`);
|
||||
console.log(`Size reduction: ${((nodeStats.size - finalStats.size) / 1024 / 1024).toFixed(2)} MB`);
|
||||
|
||||
// 8. Restore original node-pty
|
||||
console.log('Restoring original node-pty...');
|
||||
execSync('rm -rf node_modules/@homebridge/node-pty-prebuilt-multiarch', { stdio: 'inherit' });
|
||||
execSync('npm install @homebridge/node-pty-prebuilt-multiarch --silent --no-fund --no-audit', { stdio: 'inherit' });
|
||||
|
||||
// 9. Copy only necessary native files
|
||||
// 8. Copy native modules BEFORE restoring (to preserve custom-built versions)
|
||||
console.log('Copying native modules...');
|
||||
const nativeModulesDir = 'node_modules/@homebridge/node-pty-prebuilt-multiarch/build/Release';
|
||||
|
||||
|
|
@ -442,6 +469,11 @@ async function main() {
|
|||
console.log(' - Copied spawn-helper');
|
||||
}
|
||||
|
||||
// 9. Restore original node-pty (AFTER copying the custom-built version)
|
||||
console.log('\nRestoring original node-pty for development...');
|
||||
execSync('rm -rf node_modules/@homebridge/node-pty-prebuilt-multiarch', { stdio: 'inherit' });
|
||||
execSync('npm install @homebridge/node-pty-prebuilt-multiarch --silent --no-fund --no-audit', { stdio: 'inherit' });
|
||||
|
||||
console.log('\n✅ Build complete!');
|
||||
console.log(`\nPortable executable created in native/ directory:`);
|
||||
console.log(` - vibetunnel (executable)`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue