#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PATH="$SCRIPT_DIR:$PATH"

# Force npm to use its builtin node-gyp
unset npm_config_node_gyp

export ATOM_APM_ORIGINAL_PYTHON="${PYTHON:-}"

# Assumption: env iterates through environment variables in the same order that
# process.env iterates through properties within npm. So, we take the last match.
for var in $(env | grep -i ^npm_config_python=)
do
  ATOM_APM_ORIGINAL_PYTHON="${var#*=}"
done
if [ -z "${ATOM_APM_ORIGINAL_PYTHON}" ] && [ -n "${PYTHON:-}" ]
then
  ATOM_APM_ORIGINAL_PYTHON="${PYTHON}"
fi

export npm_config_python="${SCRIPT_DIR}/python-interceptor.sh"

"$SCRIPT_DIR"/../node_modules/.bin/npm $@
