install_node_modules() {
  local build_dir=${1:-}

  if [ -e $build_dir/package.json ]; then
    cd $build_dir
    echo "Pruning any extraneous modules"
    # npm prune --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
    npm prune --unsafe-perm --userconfig $HOME/.npmrc 2>&1
    if [ -e $build_dir/npm-shrinkwrap.json ]; then
      echo "Installing node modules (package.json + shrinkwrap)"
    else
      echo "Installing node modules (package.json)"
    fi
    # npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
    npm install --unsafe-perm --userconfig $HOME/.npmrc 2>&1
  else
    echo "Skipping (no package.json)"
  fi
}

rebuild_node_modules() {
  local build_dir=${1:-}

  if [ -e $build_dir/package.json ]; then
    cd $build_dir
    # echo "Rebuilding any native modules"
    # npm rebuild 2>&1
    if [ -e $build_dir/npm-shrinkwrap.json ]; then
      echo "Installing any new modules (package.json + shrinkwrap)"
    else
      echo "Installing any new modules (package.json)"
    fi
    # npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
    npm install --unsafe-perm --userconfig $HOME/.npmrc 2>&1
  else
    echo "Skipping (no package.json)"
  fi
}
