diff --git a/src/prettier/install.sh b/src/prettier/install.sh index 5e83ad280..134c03401 100755 --- a/src/prettier/install.sh +++ b/src/prettier/install.sh @@ -21,21 +21,30 @@ $nanolayer_location \ PRETTIER_PLUGINS=${PLUGINS:-""} +setup_npm() { + export NVM_DIR=/usr/local/share/nvm + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" +} + +install_prettier_plugin() { + echo "Installing prettier plugin - $1" + if ! npm list $1 >/dev/null; then + npm install --save-dev prettier $1 + fi +} + # Prettier plugins are expected to be installed locally, not globally # In particular, VSCode + extensions tend to have issues with this if [ -n "${PRETTIER_PLUGINS}" ]; then + if ! type npm >/dev/null 2>&1; then + setup_npm + fi + OIFS=$IFS IFS=',' - for plugin in $PRETTIER_PLUGINS; do - echo "Installing ${plugin}" - echo "DEBUG: whoami - $(whoami)" - echo "DEBUG: npm - $(ls /usr/local/share/nvm)" - if ! npm list ${plugin} > /dev/null; then - npm install --save-dev prettier ${plugin} - fi + install_prettier_plugin $plugin done - IFS=$OIFS fi