Skip to content

Instantly share code, notes, and snippets.

@bit4bit
Last active May 13, 2021 09:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bit4bit/899fd0f6336b569e925e43eabf3d1ec9 to your computer and use it in GitHub Desktop.
Save bit4bit/899fd0f6336b569e925e43eabf3d1ec9 to your computer and use it in GitHub Desktop.
GUIXSD HANDLING NPM GLOBAL PACKAGES

GUIXSD HANDLING NPM GLOBAL PACKAGES

Install package

# guix package -i node

Enable user handle global packages (npm)

$ mkdir /home/<user>/.vnode
$ npm config set prefix "/home/<user>/.vnode"

Append to $PATH bins (npm)

$ echo PATH=/home/<user>/.vnode/bin:$PATH

Install npm

$ npm install npm

Now put on /home/<user>/.vnode/lib/node_modules/.hooks/preinstall

#/run/current-system/profile/bin/bash
pkg_path=$PWD

function patch_shebang() {
 file=$1
 python_bin=`type -p python`
 python_bin=`type -p ruby`
 env_bin=`type -p env`
 bash_bin=`type -p bash`

 if [ -n "$env_bin" ]; then
    sed -i -uE "s|^#!.+/env|#!${env_bin}|" $file
 elif [ -n "$bash_bin" ]; then
    sed -i -uE "s|^#!.+/bash|#!${bash_bin}|" $file
 elif [ -n "$python_bin" ]; then
    sed -i -uE "s|^#!.+/bash|#!${python_bin}|" $file
 elif [ -n "$ruby_bin" ]; then
    sed -i -uE "s|^#!.+/bash|#!${ruby_bin}|" $file
 fi
}

files=`find $pkg_path -type f -exec grep -lE '^#!(.+ )' {} \;`
for file in $files; do
 patch_shebang $file
done

Allow run

$ chmod a+rx /home/<user>/.vnode/node_modules/.hooks/preinstall

If everything it's ok, now run npm install -g and see this work's.

For local packages just copy the hook myproject/node_modules/.hooks/preinstall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment