Fix module loading issues with require extension compatibility

- Added robust module loading in server.js with multiple fallback paths
- Created bidirectional symlinks for modules with different naming styles
- Added extension-less symlinks for Node.js CommonJS compatibility
- Updated file copying logic to create all necessary symlinks
- Added symlink creation script that runs on startup
- Improved module error reporting with detailed path information

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-07 10:15:47 +00:00
parent 852de32907
commit 16c73bca70
4 changed files with 144 additions and 20 deletions

View File

@@ -1824,25 +1824,58 @@ function copy_module_files() {
echo "Copying module: $module_name"
cp "$js_file" "$INSTALL_DIR/modules/$module_name"
# Create symlinks for alternative module names that might be referenced
base_name=$(basename "$module_name" .js)
case "$base_name" in
"rss-feed-manager")
ln -sf "$INSTALL_DIR/modules/$module_name" "$INSTALL_DIR/modules/rssFeedManager.js"
;;
"post-processor")
ln -sf "$INSTALL_DIR/modules/$module_name" "$INSTALL_DIR/modules/postProcessor.js"
;;
"transmission-client")
ln -sf "$INSTALL_DIR/modules/$module_name" "$INSTALL_DIR/modules/transmissionClient.js"
;;
esac
# Set permissions
chown "$USER:$USER" "$INSTALL_DIR/modules/$module_name"
chmod 644 "$INSTALL_DIR/modules/$module_name"
fi
done
log "INFO" "Copied JavaScript modules to $INSTALL_DIR/modules/"
# Function to create bidirectional symlinks for module compatibility
create_bidirectional_links() {
local hyphenated="$1"
local camelCase="$2"
# Check if hyphenated version exists
if [ -f "$INSTALL_DIR/modules/$hyphenated.js" ]; then
# Create camelCase symlink
ln -sf "$hyphenated.js" "$INSTALL_DIR/modules/$camelCase.js"
log "INFO" "Created symlink: $camelCase.js -> $hyphenated.js"
# Create symlinks without extension
ln -sf "$hyphenated.js" "$INSTALL_DIR/modules/$hyphenated"
ln -sf "$hyphenated.js" "$INSTALL_DIR/modules/$camelCase"
log "INFO" "Created extension-less symlinks: $hyphenated, $camelCase -> $hyphenated.js"
# Check if camelCase version exists
elif [ -f "$INSTALL_DIR/modules/$camelCase.js" ]; then
# Create hyphenated symlink
ln -sf "$camelCase.js" "$INSTALL_DIR/modules/$hyphenated.js"
log "INFO" "Created symlink: $hyphenated.js -> $camelCase.js"
# Create symlinks without extension
ln -sf "$camelCase.js" "$INSTALL_DIR/modules/$hyphenated"
ln -sf "$camelCase.js" "$INSTALL_DIR/modules/$camelCase"
log "INFO" "Created extension-less symlinks: $hyphenated, $camelCase -> $camelCase.js"
else
log "WARN" "Neither $hyphenated.js nor $camelCase.js exists in $INSTALL_DIR/modules"
fi
# Set permissions for all symlinks
chmod 644 "$INSTALL_DIR/modules/$hyphenated.js" 2>/dev/null || true
chmod 644 "$INSTALL_DIR/modules/$camelCase.js" 2>/dev/null || true
chmod 644 "$INSTALL_DIR/modules/$hyphenated" 2>/dev/null || true
chmod 644 "$INSTALL_DIR/modules/$camelCase" 2>/dev/null || true
# Set ownership for all symlinks
chown "$USER:$USER" "$INSTALL_DIR/modules/$hyphenated.js" 2>/dev/null || true
chown "$USER:$USER" "$INSTALL_DIR/modules/$camelCase.js" 2>/dev/null || true
chown "$USER:$USER" "$INSTALL_DIR/modules/$hyphenated" 2>/dev/null || true
chown "$USER:$USER" "$INSTALL_DIR/modules/$camelCase" 2>/dev/null || true
}
# Create bidirectional symlinks for all modules
create_bidirectional_links "rss-feed-manager" "rssFeedManager"
create_bidirectional_links "transmission-client" "transmissionClient"
create_bidirectional_links "post-processor" "postProcessor"
log "INFO" "Copied JavaScript modules and created compatibility symlinks in $INSTALL_DIR/modules/"
}