Allow for customization of installers
I've searched open issues for similar requests
- [x] Yes
Is your feature request related to a problem? Please describe.
I don't want to use npm, I like to keep things slim.
Describe the solution you'd like
Allow a configuration option which can change commands for certain installers, like npm, to other, less bloated alternatives. I can do this with a cheeky workaround where I symlink npm to yarn, but I would like a more official solution. I'm not asking you to change from npm, I'm just asking for a customization option there.
Describe potential alternatives you've considered
Symlink npm to yarn (weird and buggy (yarn doesn't like install)) Just use npm (I don't feel like compiling npm into my system, and I use yarn anyways) Use a redirection script (I'll explain) (Too complex for most beginners)
Additional context
No response
For anyone who is looking to replace npm with another package manager, like yarn or pnpm (or even bun), I have written a script that should be placed in /usr/bin/npm that does exactly this. It allows yarn to run instead of npm when called from Mason, so I consider it a success. If you are a less-experienced user, I recommend just symlinking npm to another package manager (not yarn, as it will break) via sudo ln -s /usr/bin/yarn /usr/bin/npm
My "solution" script (located at /usr/bin/npm):
#!/bin/bash
# /usr/bin/npm
# Set this to the executable of your choice
newcmd="yarn" # Default command, you can change this to 'pnpm', 'bun', etc.
# Set this to 'true' to enable debugging logs, or 'false' to disable.
# Some programs don't play nice with the extra debug output
debuglogs="true"
# Capture the arguments passed to this script
args="$*"
# Debug logging function
debug_echo() {
if [ "$debuglogs" = "true" ]; then
echo "$@"
fi
}
# Print the original command (if debugging is enabled)
debug_echo "Original command: npm $args"
# Handle the translation based on the new command
if [ "$newcmd" = "yarn" ]; then
# For yarn, translate 'npm install' to 'yarn add'
if echo "$args" | grep -q '^install'; then
after_install=$(echo "$args" | sed 's/^install //')
output="$newcmd add $after_install"
else
output="$newcmd $args"
fi
else
# For other commands or package managers, replace 'npm' with newcmd
output="$newcmd $args"
fi
# Print the transformed command (if debugging is enabled)
debug_echo "Transformed command: $output"
# Execute the transformed command
eval "$output"
again, this file is located at /usr/bin/npm and you should run sudo chmod +x /usr/bin/npm after adding this to the file. Test the script by opening a new terminal and writing npm -v for my example, yarn, you will see the following output (assuming you are on version 1.22.22):
Original command: npm -v
Transformed command: yarn -v
1.22.22
after which I would set debuglogs = "false" in the script as some programs don't play nice with unexpected output
Of course, this does no cover every installer, so this issue will remain open
I would prefer to automatically find first installed package manager and use that
If anyone is looking for updated instructions, I have made a repo for this script, with installation instructions. I have also implemented feedback from @lorypelli.