├── bin ├── exec-env ├── postinstall ├── list-all ├── get-bin-names.js └── install ├── npm-hooks └── postinstall └── README.md /bin/exec-env: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "$NPM_CONFIG_PREFIX" = "" ]; then 4 | export NPM_CONFIG_PREFIX=$ASDF_INSTALL_PATH/.npm 5 | fi 6 | -------------------------------------------------------------------------------- /npm-hooks/postinstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | asdf_nodejs_installs_path=$(dirname $(dirname $(dirname $NODE))) 4 | asdf_nodejs_plugin_path=${asdf_nodejs_installs_path/installs/plugins} 5 | bash $asdf_nodejs_plugin_path/bin/postinstall 6 | -------------------------------------------------------------------------------- /bin/postinstall: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | package_bin_names=$($NODE $(dirname $0)/get-bin-names.js) 4 | IFS=' ' read -a package_bin_names_list <<< "$package_bin_names" 5 | 6 | for package_bin in "${package_bin_names_list[@]}" 7 | do 8 | asdf shim nodejs .npm/bin/${package_bin} 9 | done 10 | -------------------------------------------------------------------------------- /bin/list-all: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | versions_list=( 4 | 5.5.0 5 | 5.4.1 6 | 5.4.0 7 | 5.3.0 8 | 5.2.0 9 | 5.1.1 10 | 5.1.0 11 | 5.0.0 12 | 4.2.3 13 | 4.2.2 14 | 4.2.1 15 | 4.2.0 16 | 4.1.2 17 | 4.1.1 18 | 4.1.0 19 | 4.0.0 20 | 0.12.7 21 | 0.12.3 22 | 0.12.2 23 | ) 24 | 25 | versions="" 26 | 27 | for version in "${versions_list[@]}" 28 | do 29 | versions="${versions} ${version}" 30 | done 31 | 32 | echo $versions 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asdf-nodejs 2 | 3 | Node.js plugin for [asdf](https://github.com/HashNuke/asdf) version manager 4 | 5 | ## Install 6 | 7 | ``` 8 | asdf plugin-add nodejs https://github.com/HashNuke/asdf-nodejs.git 9 | ``` 10 | 11 | ## Use 12 | 13 | Check [asdf](https://github.com/HashNuke/asdf) readme for instructions on how to install & manage versions of Node.js. 14 | 15 | When installing Node.js using `asdf install`, you can pass custom configure options with the following env vars: 16 | 17 | * `NODEJS_CONFIGURE_OPTIONS` - use only your configure options 18 | * `NODEJS_EXTRA_CONFIGURE_OPTIONS` - append these configure options along with ones that this plugin already uses 19 | -------------------------------------------------------------------------------- /bin/get-bin-names.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | 5 | if (process.env['npm_config_global'] != 'true') { 6 | process.exit(); 7 | } 8 | 9 | var package_json_path=process.env['PWD'] + '/package.json'; 10 | var node_modules_occurance = (package_json_path.match(/node_modules/g) || []).length; 11 | 12 | // create shims only for globally installed pkg 13 | if (node_modules_occurance > 1) { 14 | process.exit(); 15 | } 16 | 17 | var package_json = JSON.parse(fs.readFileSync(package_json_path, 'utf8')); 18 | 19 | if (!('bin' in package_json)) { 20 | process.exit(); 21 | } 22 | 23 | if (typeof package_json['bin'] === "object") { 24 | var bin_names = Object.keys(package_json['bin']); 25 | console.log(bin_names.join(" ")); 26 | } 27 | else 28 | { 29 | console.log(package_json["name"]); 30 | } 31 | -------------------------------------------------------------------------------- /bin/install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | install_nodejs() { 4 | local install_type=$1 5 | local version=$2 6 | local install_path=$3 7 | 8 | if [ "$TMPDIR" = "" ]; then 9 | local tmp_download_dir=$(mktemp -d) 10 | else 11 | local tmp_download_dir=$TMPDIR 12 | fi 13 | 14 | local source_path=$(get_download_file_path $install_type $version $tmp_download_dir) 15 | download_source_file $install_type $version $source_path 16 | 17 | # running this in a subshell 18 | # we don't want to disturb current working dir 19 | ( 20 | if [ "$install_type" != "version" ]; then 21 | tar zxf $source_path -C $install_path --strip-components=1 || exit 1 22 | cd $install_path 23 | 24 | local configure_options="$(construct_configure_options $install_path)" 25 | 26 | ./configure $configure_options || exit 1 27 | make 28 | make install 29 | 30 | if [ $? -ne 0 ]; then 31 | rm -rf $install_path 32 | exit 1 33 | fi 34 | else 35 | tar zxf $source_path -C $install_path --strip-components=1 || exit 1 36 | fi 37 | 38 | mkdir -p $install_path/.npm/lib/node_modules/.hooks 39 | cp $(dirname $(dirname $0))/npm-hooks/* $install_path/.npm/lib/node_modules/.hooks/ 40 | chmod +x $install_path/.npm/lib/node_modules/.hooks/* 41 | ) 42 | } 43 | 44 | 45 | construct_configure_options() { 46 | local install_path=$1 47 | 48 | if [ "$NODEJS_CONFIGURE_OPTIONS" = "" ]; then 49 | local configure_options="$(os_based_configure_options) --prefix=$install_path" 50 | 51 | if [ "$NODEJS_EXTRA_CONFIGURE_OPTIONS" != "" ]; then 52 | configure_options="$configure_options $NODEJS_EXTRA_CONFIGURE_OPTIONS" 53 | fi 54 | else 55 | local configure_options="$NODEJS_CONFIGURE_OPTIONS --prefix=$install_path" 56 | fi 57 | 58 | echo "$configure_options" 59 | } 60 | 61 | 62 | os_based_configure_options() { 63 | local operating_system=$(uname -a) 64 | local configure_options="" 65 | 66 | if [[ "$operating_system" =~ "x86_64" ]]; then 67 | local cpu_type="x64" 68 | else 69 | local cpu_type="x86" 70 | fi 71 | 72 | configure_options="$configure_options --dest-cpu=$cpu_type" 73 | echo $configure_options 74 | } 75 | 76 | 77 | download_source_file() { 78 | local install_type=$1 79 | local version=$2 80 | local download_path=$3 81 | local download_url=$(get_download_url $install_type $version) 82 | 83 | curl -Lo $download_path -C - $download_url 84 | } 85 | 86 | 87 | get_download_file_path() { 88 | local install_type=$1 89 | local version=$2 90 | local tmp_download_dir=$3 91 | 92 | 93 | if [ "$install_type" = "version" ]; then 94 | if [[ "$operating_system" =~ "x86_64" ]]; then 95 | local cpu_type="x64" 96 | else 97 | local cpu_type="x86" 98 | fi 99 | 100 | if [[ "$operating_system" =~ "Darwin" ]]; then 101 | local pkg_name="node-v${version}-darwin-${cpu_type}" 102 | else # we'll assume it is linux 103 | local pkg_name="node-v${version}-linux-${cpu_type}" 104 | fi 105 | else 106 | local pkg_name="${version}.tar.gz" 107 | fi 108 | 109 | echo "$tmp_download_dir/$pkg_name" 110 | } 111 | 112 | 113 | get_download_url() { 114 | local install_type=$1 115 | local version=$2 116 | local operating_system=$(uname -a) 117 | 118 | if [ "$install_type" = "version" ]; then 119 | if [[ "$operating_system" =~ "x86_64" ]]; then 120 | local cpu_type="x64" 121 | else 122 | local cpu_type="x86" 123 | fi 124 | 125 | if [[ "$operating_system" =~ "Darwin" ]]; then 126 | echo "http://nodejs.org/dist/v${version}/node-v${version}-darwin-${cpu_type}.tar.gz" 127 | else # we'll assume it is linux 128 | echo "http://nodejs.org/dist/v${version}/node-v${version}-linux-${cpu_type}.tar.gz" 129 | fi 130 | else 131 | echo "https://github.com/nodejs/node/archive/${version}.tar.gz" 132 | fi 133 | } 134 | 135 | 136 | install_nodejs $ASDF_INSTALL_TYPE $ASDF_INSTALL_VERSION $ASDF_INSTALL_PATH 137 | --------------------------------------------------------------------------------