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:
parent
852de32907
commit
16c73bca70
@ -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/"
|
||||
}
|
49
scripts/create-module-links.sh
Executable file
49
scripts/create-module-links.sh
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
# Create bi-directional symlinks for module compatibility
|
||||
|
||||
MODULES_DIR="$(dirname "$(dirname "$0")")/modules"
|
||||
|
||||
echo "Creating module symlinks in $MODULES_DIR..."
|
||||
|
||||
# Check if modules directory exists
|
||||
if [ ! -d "$MODULES_DIR" ]; then
|
||||
echo "Error: Modules directory not found: $MODULES_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create bidirectional symlinks
|
||||
create_bidirectional_links() {
|
||||
local hyphenated="$1"
|
||||
local camelCase="$2"
|
||||
|
||||
# Check if hyphenated version exists
|
||||
if [ -f "$MODULES_DIR/$hyphenated.js" ]; then
|
||||
# Create camelCase symlink
|
||||
ln -sf "$hyphenated.js" "$MODULES_DIR/$camelCase.js"
|
||||
echo "Created symlink: $camelCase.js -> $hyphenated.js"
|
||||
|
||||
# Create symlinks without extension
|
||||
ln -sf "$hyphenated.js" "$MODULES_DIR/$hyphenated"
|
||||
ln -sf "$hyphenated.js" "$MODULES_DIR/$camelCase"
|
||||
echo "Created extension-less symlinks: $hyphenated, $camelCase -> $hyphenated.js"
|
||||
# Check if camelCase version exists
|
||||
elif [ -f "$MODULES_DIR/$camelCase.js" ]; then
|
||||
# Create hyphenated symlink
|
||||
ln -sf "$camelCase.js" "$MODULES_DIR/$hyphenated.js"
|
||||
echo "Created symlink: $hyphenated.js -> $camelCase.js"
|
||||
|
||||
# Create symlinks without extension
|
||||
ln -sf "$camelCase.js" "$MODULES_DIR/$hyphenated"
|
||||
ln -sf "$camelCase.js" "$MODULES_DIR/$camelCase"
|
||||
echo "Created extension-less symlinks: $hyphenated, $camelCase -> $camelCase.js"
|
||||
else
|
||||
echo "Warning: Neither $hyphenated.js nor $camelCase.js exists in $MODULES_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
# Create symlinks for all modules
|
||||
create_bidirectional_links "rss-feed-manager" "rssFeedManager"
|
||||
create_bidirectional_links "transmission-client" "transmissionClient"
|
||||
create_bidirectional_links "post-processor" "postProcessor"
|
||||
|
||||
echo "Module symlinks created successfully."
|
@ -56,6 +56,14 @@ if [ -z "$NODE_PATH" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create module symlinks to ensure compatibility
|
||||
if [ -f "$APP_DIR/scripts/create-module-links.sh" ]; then
|
||||
echo "Creating module symlinks for compatibility..."
|
||||
bash "$APP_DIR/scripts/create-module-links.sh"
|
||||
else
|
||||
echo "Warning: Module symlink script not found"
|
||||
fi
|
||||
|
||||
# Start the application
|
||||
cd "$APP_DIR" || { echo "Failed to change to application directory"; exit 1; }
|
||||
echo "Starting node.js application with: $NODE_PATH $APP_DIR/server.js"
|
||||
|
44
server.js
44
server.js
@ -19,26 +19,60 @@ const execAsync = util.promisify(exec);
|
||||
const semver = require('semver'); // For semantic version comparison
|
||||
|
||||
// Import custom modules
|
||||
// Try to import with .js extension first, then fallback to no extension for better compatibility
|
||||
let RssFeedManager, TransmissionClient, PostProcessor;
|
||||
|
||||
// Always use explicit .js extension when importing our own modules
|
||||
// Helper function to try multiple module paths
|
||||
function tryRequire(modulePaths) {
|
||||
let lastError = null;
|
||||
for (const modulePath of modulePaths) {
|
||||
try {
|
||||
return require(modulePath);
|
||||
} catch (err) {
|
||||
console.log(`Attempted to load module from ${modulePath}, but got error: ${err.message}`);
|
||||
lastError = err;
|
||||
}
|
||||
}
|
||||
throw lastError;
|
||||
}
|
||||
|
||||
// Try loading modules with various namings (with and without .js extension, with hyphens or camelCase)
|
||||
try {
|
||||
RssFeedManager = require('./modules/rss-feed-manager.js');
|
||||
const rssPaths = [
|
||||
'./modules/rss-feed-manager.js',
|
||||
'./modules/rssFeedManager.js',
|
||||
'./modules/rss-feed-manager',
|
||||
'./modules/rssFeedManager'
|
||||
];
|
||||
RssFeedManager = tryRequire(rssPaths);
|
||||
console.log('Successfully loaded RssFeedManager module');
|
||||
} catch (err) {
|
||||
console.error('Failed to load RssFeedManager module:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
TransmissionClient = require('./modules/transmission-client.js');
|
||||
const transmissionPaths = [
|
||||
'./modules/transmission-client.js',
|
||||
'./modules/transmissionClient.js',
|
||||
'./modules/transmission-client',
|
||||
'./modules/transmissionClient'
|
||||
];
|
||||
TransmissionClient = tryRequire(transmissionPaths);
|
||||
console.log('Successfully loaded TransmissionClient module');
|
||||
} catch (err) {
|
||||
console.error('Failed to load TransmissionClient module:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
PostProcessor = require('./modules/post-processor.js');
|
||||
const processorPaths = [
|
||||
'./modules/post-processor.js',
|
||||
'./modules/postProcessor.js',
|
||||
'./modules/post-processor',
|
||||
'./modules/postProcessor'
|
||||
];
|
||||
PostProcessor = tryRequire(processorPaths);
|
||||
console.log('Successfully loaded PostProcessor module');
|
||||
} catch (err) {
|
||||
console.error('Failed to load PostProcessor module:', err);
|
||||
process.exit(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user