Skip to content
Myr

Merge pull request #823 from jbergstroem/feature/prefer-xz

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Support `xz` tarballs if available (on io.js >= 2.3.2 and node >= 4)

authored by Jordan Harband · committed by Jordan Harband · parents cb033ad, b8e4917 · Browse files · 3 files+69 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+69 added−12 removed

  • tests:+37 added−1 removed
  • other:+32 added−11 removed

3 files+69 added−12 removed

added:test/fast/Unit tests/nvm_supports_xz+36 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh67OLDPATH=$PATH8TEST_PATH=../../xz-test910mkdir $TEST_PATH11touch ../../xz-test/xz12chmod +x ../../xz-test/xz1314export PATH=$TEST_PATH:$PATH1516$(nvm_supports_xz "v2.3.2") || \17 die "expected 'nvm_supports_xz v2.3.2' to exit with 0"1819$(nvm_supports_xz "v0.12.7") && \20 die "expected 'nvm_supports_xz v0.12.7' to exit with 1"212223# set up for a failure by having a minimal toolset available24# but remove xz25ln -s /usr/bin/which $TEST_PATH/which26ln -s /usr/bin/command $TEST_PATH/command27ln -s /usr/bin/awk $TEST_PATH/awk28ln -s $(which rm) $TEST_PATH/rm2930export PATH=$TEST_PATH31rm $TEST_PATH/xz3233$(nvm_supports_xz "v2.3.2") && \34 die "expected 'nvm_supports_xz v2.3.2' with a missing xz binary to exit with 1"3536export PATH=$OLDPATH
modified:test/fast/teardown+1 added-1 removed
4 unmodified lines
5 cd ../..67 type setopt >/dev/null 2>&1 && setopt NULL_GLOB8 type shopt >/dev/null 2>&1 && shopt -s nullglob9 rm -fR v* src alias9 rm -fR v* src alias test/test-xz10)
modified:nvm.sh+32 added-11 removed
997 unmodified lines
998 local t999 local url1000 local sum1001 local NODE_PREFIX1002 local compression1003 compression="gz"1004 local tar_compression_flag1005 tar_compression_flag="x"1006 if nvm_supports_xz "$VERSION"; then1007 compression="xz"1008 tar_compression_flag="J"1009 fi1010 NODE_PREFIX="$(nvm_node_prefix)"10111012 if [ -n "$NVM_OS" ]; then1013 t="$VERSION-$NVM_OS-$(nvm_get_arch)"1006 url="$MIRROR/$VERSION/$NODE_PREFIX-${t}.tar.gz"1007 sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $NODE_PREFIX-${t}.tar.gz | command awk '{print $1}')"1014 url="$MIRROR/$VERSION/$NODE_PREFIX-${t}.tar.${compression}"1015 sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $NODE_PREFIX-${t}.tar.${compression} | command awk '{print $1}')"1016 local tmpdir1017 tmpdir="$NVM_DIR/bin/node-${t}"1018 local tmptarball1011 tmptarball="$tmpdir/node-${t}.tar.gz"1019 tmptarball="$tmpdir/node-${t}.tar.${compression}"1020 local NVM_INSTALL_ERRORED1021 command mkdir -p "$tmpdir" && \1022 echo "Downloading $url..." && \1023 nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
5 unmodified lines
1029 if (1030 [ "$NVM_INSTALL_ERRORED" != true ] && \1031 echo "WARNING: checksums are currently disabled for node.js v4.0 and later" >&2 && \1032 # nvm_checksum "$tmptarball" $sum && \1025 command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \1033 command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \1034 command rm -f "$tmptarball" && \1035 command mkdir -p "$VERSION_PATH" && \1036 command mv "$tmpdir"/* "$VERSION_PATH"1037 ); then
35 unmodified lines
1073 NVM_OS="$(nvm_get_os)"1074 local t1075 local url1076 local sum1077 local compression1078 compression="gz"1079 local tar_compression_flag1080 tar_compression_flag="x"1081 if nvm_supports_xz "$VERSION"; then1082 compression="xz"1083 tar_compression_flag="J"1084 fi10851086 if [ -n "$NVM_OS" ]; then1087 if nvm_binary_available "$VERSION"; then1088 t="$VERSION-$NVM_OS-$(nvm_get_arch)"1073 url="$MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.gz"1074 sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.gz | command awk '{print $1}')"1089 url="$MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.${compression}"1090 sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.${compression} | command awk '{print $1}')"1091 local tmpdir1092 tmpdir="$NVM_DIR/bin/iojs-${t}"1093 local tmptarball1078 tmptarball="$tmpdir/iojs-${t}.tar.gz"1094 tmptarball="$tmpdir/iojs-${t}.tar.${compression}"1095 local NVM_INSTALL_ERRORED1096 command mkdir -p "$tmpdir" && \1097 echo "Downloading $url..." && \1098 nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
5 unmodified lines
1104 if (1105 [ "$NVM_INSTALL_ERRORED" != true ] && \1106 echo "WARNING: checksums are currently disabled for io.js" >&2 && \1107 # nvm_checksum "$tmptarball" $sum && \1092 command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \1108 command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \1109 command rm -f "$tmptarball" && \1110 command mkdir -p "$VERSION_PATH" && \1111 command mv "$tmpdir"/* "$VERSION_PATH"1112 ); then
564 unmodified lines
1677 NVM_SUCCESS_MSG="Uninstalled node $VERSION"1678 fi1679 # Delete all files related to target version.1680 command rm -rf "$NVM_DIR/src/$NVM_PREFIX-$VERSION" \1665 "$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.gz" \1681 "$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.*" \1682 "$NVM_DIR/bin/$NVM_PREFIX-${t}" \1667 "$NVM_DIR/bin/$NVM_PREFIX-${t}.tar.gz" \1683 "$NVM_DIR/bin/$NVM_PREFIX-${t}.tar.*" \1684 "$VERSION_PATH" 2>/dev/null1685 echo "$NVM_SUCCESS_MSG"16861687 # rm any aliases that point to uninstalled version.
527 unmodified lines
2215 nvm_version_greater nvm_version_greater_than_or_equal_to \2216 nvm_print_npm_version nvm_npm_global_modules \2217 nvm_has_system_node nvm_has_system_iojs \2218 nvm_download nvm_get_latest nvm_has nvm_get_latest \2203 nvm_supports_source_options > /dev/null 2>&12219 nvm_supports_source_options nvm_supports_xz > /dev/null 2>&12220 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&12221 ;;2222 * )2223 >&2 nvm help
5 unmodified lines
2229nvm_supports_source_options() {2230 [ "_$(echo 'echo $1' | . /dev/stdin yes 2> /dev/null)" = "_yes" ]2231}22322233nvm_supports_xz() {2234 command which xz 2>&1 >/dev/null && \2235 nvm_version_greater_than_or_equal_to "$1" "2.3.2" 2236}22372238NVM_VERSION="$(nvm_alias default 2>/dev/null || echo)"2239if nvm_supports_source_options && [ "_$1" = "_--install" ]; then2240 if [ -n "$NVM_VERSION" ]; then2241 nvm install "$NVM_VERSION" >/dev/null
10 unmodified lines