diff --git a/scripts/alpine-setup.sh b/scripts/alpine-setup.sh index 90e8102..ac54a97 100755 --- a/scripts/alpine-setup.sh +++ b/scripts/alpine-setup.sh @@ -1,28 +1,43 @@ #!/bin/sh # Alpine Linux setup script -# Removes onnxruntime-node to prevent glibc dependency errors -# The transformers library will fall back to onnxruntime-web (WASM) +# Patches @xenova/transformers to use onnxruntime-web instead of onnxruntime-node +# This is required for Alpine Linux (musl libc) compatibility -echo "Removing onnxruntime-node for Alpine Linux compatibility..." +echo "Configuring Transformers.js for Alpine Linux (WASM backend)..." -# Remove the onnxruntime-node directory -rm -rf node_modules/onnxruntime-node +# Patch the ONNX backend selector to always use onnxruntime-web +ONNX_BACKEND_FILE="node_modules/@xenova/transformers/src/backends/onnx.js" -# Create a stub module so imports don't fail -mkdir -p node_modules/onnxruntime-node -cat > node_modules/onnxruntime-node/package.json << 'EOF' -{ - "name": "onnxruntime-node", - "version": "0.0.0-stub", - "main": "index.js", - "type": "module" -} +if [ -f "$ONNX_BACKEND_FILE" ]; then + # Backup original file + cp "$ONNX_BACKEND_FILE" "$ONNX_BACKEND_FILE.bak" + + # Replace the backend selection logic to always use ONNX_WEB + cat > "$ONNX_BACKEND_FILE" << 'EOF' +/** + * @file Handler file for choosing the correct version of ONNX Runtime, based on the environment. + * PATCHED FOR ALPINE LINUX: Always uses onnxruntime-web (WASM backend) + * @module backends/onnx + */ + +// Only import onnxruntime-web for Alpine Linux compatibility +import * as ONNX_WEB from 'onnxruntime-web'; + +/** @type {import('onnxruntime-web')} The ONNX runtime module. */ +export let ONNX; + +export const executionProviders = [ + 'wasm' +]; + +// Always use ONNX_WEB (WASM backend) on Alpine Linux +ONNX = ONNX_WEB.default ?? ONNX_WEB; EOF -cat > node_modules/onnxruntime-node/index.js << 'EOF' -// Stub module for Alpine Linux -// @xenova/transformers will use onnxruntime-web instead -export default {}; -EOF + echo "✓ Patched @xenova/transformers backend to use WASM" +else + echo "✗ Could not find $ONNX_BACKEND_FILE" + exit 1 +fi echo "✓ Alpine Linux setup complete - WASM backend will be used"