diff --git a/changelog.md b/changelog.md index e9d2561..70b5893 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## 2025-03-26 - 2.6.4 - fix(setup) +Improve installation process in setup script by cleaning up package files and ensuring a minimal net-snmp dependency installation. + +- Remove existing package-lock.json along with node_modules to prevent stale artifacts. +- Back up the original package.json before modifying it. +- Create a minimal package.json with only the net-snmp dependency based on the backed-up version. +- Use a clean install to guarantee that only net-snmp is installed. +- Restore the original package.json if the installation fails. + ## 2025-03-26 - 2.6.3 - fix(setup) Update setup script to install only net-snmp dependency and create a minimal package-lock.json for better dependency control. diff --git a/setup.sh b/setup.sh index 3ddb31c..e25f991 100644 --- a/setup.sh +++ b/setup.sh @@ -244,48 +244,61 @@ NODE_BIN_DIR="$SCRIPT_DIR/vendor/$NODE_DIR/bin" OLD_PATH="$PATH" export PATH="$NODE_BIN_DIR:$PATH" -# Remove existing node_modules directory -echo "Removing existing node_modules directory..." +# Remove existing node_modules directory and package files +echo "Cleaning up existing installation..." rm -rf "$SCRIPT_DIR/node_modules" +rm -f "$SCRIPT_DIR/package-lock.json" -# Install ONLY the net-snmp production dependency -echo "Installing ONLY net-snmp production dependency..." +# Back up existing package.json if it exists +if [ -f "$SCRIPT_DIR/package.json" ]; then + echo "Backing up existing package.json..." + cp "$SCRIPT_DIR/package.json" "$SCRIPT_DIR/package.json.bak" +fi + +# Create a clean minimal package.json with ONLY net-snmp dependency +echo "Creating minimal package.json with only net-snmp dependency..." +VERSION=$(grep -o '"version": "[^"]*"' "$SCRIPT_DIR/package.json.bak" | head -1 | cut -d'"' -f4 || echo "2.6.3") +echo '{ + "name": "@serve.zone/nupst", + "version": "'$VERSION'", + "description": "Node.js UPS Shutdown Tool for SNMP-enabled UPS devices", + "main": "dist_ts/index.js", + "type": "module", + "bin": { + "nupst": "bin/nupst" + }, + "dependencies": { + "net-snmp": "3.20.0" + }, + "engines": { + "node": ">=16.0.0" + }, + "private": true +}' > "$SCRIPT_DIR/package.json" + +# Install ONLY net-snmp +echo "Installing ONLY net-snmp dependency..." echo "Using Node.js binary from: $NODE_BIN_DIR" echo "Node version: $(node --version)" echo "NPM version: $(npm --version)" -# Install just net-snmp directly, don't rely on package.json -npm --prefix "$SCRIPT_DIR" install --no-save net-snmp@3.20.0 --no-audit --no-fund - -# Verify only net-snmp is installed -echo "Verifying only net-snmp is installed in node_modules..." -find "$SCRIPT_DIR/node_modules" -maxdepth 1 -type d | sort +# Use clean install to ensure only net-snmp is installed +npm --prefix "$SCRIPT_DIR" install --no-audit --no-fund INSTALL_STATUS=$? if [ $INSTALL_STATUS -ne 0 ]; then echo "Error: Failed to install net-snmp dependency. NUPST may not function correctly." - echo "You can try to install dependencies manually by running:" - echo "cd $SCRIPT_DIR && npm install net-snmp@3.20.0" + echo "Restoring original package.json..." + mv "$SCRIPT_DIR/package.json.bak" "$SCRIPT_DIR/package.json" + exit 1 else echo "net-snmp dependency installed successfully." + # Show what's actually installed + echo "Installed modules:" + find "$SCRIPT_DIR/node_modules" -maxdepth 1 -type d | grep -v "^$SCRIPT_DIR/node_modules$" | sort - # Create minimal package-lock.json if it doesn't exist - if [ ! -f "$SCRIPT_DIR/package-lock.json" ]; then - echo "Creating minimal package-lock.json..." - echo '{ - "name": "@serve.zone/nupst", - "version": "2.6.2", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "dependencies": { - "net-snmp": "3.20.0" - } - } - } -}' > "$SCRIPT_DIR/package-lock.json" - fi + # Remove backup if successful + rm -f "$SCRIPT_DIR/package.json.bak" fi # Restore the original PATH diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index a16e6bf..6f16b2e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/nupst', - version: '2.6.3', + version: '2.6.4', description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices' }