Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for customization of installers #1786

Open
1 task done
JarzaClay opened this issue Sep 10, 2024 · 2 comments
Open
1 task done

Allow for customization of installers #1786

JarzaClay opened this issue Sep 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@JarzaClay
Copy link

JarzaClay commented Sep 10, 2024

I've searched open issues for similar requests

  • 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

@JarzaClay JarzaClay added the enhancement New feature or request label Sep 10, 2024
@JarzaClay
Copy link
Author

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

@lorypelli
Copy link

I would prefer to automatically find first installed package manager and use that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants