fix(setup.sh): Improve setup script to detect and execute npm-cli.js directly using the Node.js binary

This commit is contained in:
2025-03-26 15:53:38 +00:00
parent 4cac599a58
commit 5b756dd223
3 changed files with 30 additions and 12 deletions

View File

@@ -239,20 +239,31 @@ echo "dist_ts directory successfully downloaded from npm registry."
# Make launcher script executable
chmod +x "$SCRIPT_DIR/bin/nupst"
# Set path to our Node.js binaries
# Set up Node.js binary path
NODE_BIN_DIR="$SCRIPT_DIR/vendor/$NODE_DIR/bin"
NODE_BIN="$NODE_BIN_DIR/node"
NPM_BIN="$NODE_BIN_DIR/npm"
NPM_CLI_JS="$NODE_BIN_DIR/../lib/node_modules/npm/bin/npm-cli.js"
# Ensure we have executable permissions
chmod +x "$NODE_BIN" "$NPM_BIN"
chmod +x "$NODE_BIN"
# Save original PATH but don't modify it
# We'll use the full paths to binaries instead
OLD_PATH="$PATH"
# Make sure the npm-cli.js exists
if [ ! -f "$NPM_CLI_JS" ]; then
# Try to find npm-cli.js
NPM_CLI_JS=$(find "$NODE_BIN_DIR/.." -name "npm-cli.js" | head -1)
if [ -z "$NPM_CLI_JS" ]; then
echo "Warning: Could not find npm-cli.js, npm commands may fail"
# Set to a fallback value so code can continue
NPM_CLI_JS="$NODE_BIN_DIR/npm"
else
echo "Found npm-cli.js at: $NPM_CLI_JS"
fi
fi
# Display which binaries we're using
echo "Using Node binary: $NODE_BIN"
echo "Using NPM binary: $NPM_BIN"
echo "Using NPM CLI JS: $NPM_CLI_JS"
# Remove existing node_modules directory and package files
echo "Cleaning up existing installation..."
@@ -289,10 +300,10 @@ echo '{
# Install ONLY net-snmp
echo "Installing ONLY net-snmp dependency..."
echo "Node version: $("$NODE_BIN" --version)"
echo "NPM version: $("$NPM_BIN" --version)"
echo "Executing NPM directly with Node.js"
# Use absolute paths to binaries to ensure we use our Node.js
"$NPM_BIN" --prefix "$SCRIPT_DIR" install --no-audit --no-fund
# Execute npm-cli.js directly with our Node.js binary
"$NODE_BIN" "$NPM_CLI_JS" --prefix "$SCRIPT_DIR" install --no-audit --no-fund
INSTALL_STATUS=$?
if [ $INSTALL_STATUS -ne 0 ]; then
@@ -310,7 +321,7 @@ else
rm -f "$SCRIPT_DIR/package.json.bak"
fi
# We didn't modify PATH, so no need to restore it
# No temporary files to clean up
echo "NUPST setup completed successfully."
echo "You can now run NUPST using: $SCRIPT_DIR/bin/nupst"