Last active
October 7, 2016 23:13
-
-
Save mattlubner/8af29ac2d3cce7db92709fa209ef7942 to your computer and use it in GitHub Desktop.
Bash function to npm link packages using symbolic links w/ absolute paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HOWTO: paste the contents of this file into your ~/.bash_profile or ~/.bashrc file | |
nvm_link_abs() { | |
# usage: nvm_link_abs <package_name> | |
if [ ! -d node_modules ]; then | |
echo "nvm_link_abs: you must be within your project's base directory for this script to work!" | |
return 1 | |
fi | |
npm link "$1" | |
local temp_link_target="$(readlink "node_modules/$1")" | |
if [ "/" == "${temp_link_target:0:1}" ]; then | |
# symbolic link target is already an absolute path | |
return 0 | |
else | |
# symbolic link target is a relative path | |
local temp_link_dirname="$(dirname "$temp_link_target")" | |
local temp_path_abs="$(cd "node_modules/${temp_link_dirname##*node_modules/}/$temp_link_target" && pwd)" | |
rm "node_modules/$1" | |
ln -s "$temp_path_abs" "node_modules/$1" | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copyright (c) 2016, Matt Lubner <[email protected]> | |
The "ISC" license: | |
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment