Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tools): nvm support added so node is correctly resolved #535

Merged
merged 8 commits into from Jun 16, 2020

Conversation

drochetti
Copy link
Contributor

@drochetti drochetti commented Jun 9, 2020

Issue # #488

Description of changes: When NVM is installed it needs to be manually initialized inside the Xcode script runtime, otherwise a different NodeJS will be used.

ps: also did some formatting on the file (actually VSCode did).

Diff excluding the formatting changes: 0b4f9bc


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@drochetti drochetti added the build Issues related to build and CI/CD label Jun 10, 2020
@drochetti drochetti requested review from wooj2 and palpatim June 10, 2020 22:18
@drochetti drochetti added this to the 1.0.2 milestone Jun 11, 2020
NVM_PATH=~/.nvm/nvm.sh
if [ -f "${NVM_PATH}" ]; then
echo "NVM found, initializing it..."
source $NVM_PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If we want to support directories with spaces, this needs to be:
NVM_PATH="${HOME}/.nvm/nvm.sh"

(note that ~ can not be used in a string)

  1. Then if we assume there is a space in the path, we should change the source command on line 19 to have quotes like:
source "${NVM_PATH}"
  1. Btw, what does nvm.sh expect to have? i'm guessing it updates some path variables?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand what is inside nvm.sh, but going to assume it is the right thing to do..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me neither, it's a fairly long file (~3500 lines) that handles both NVM and NodeJS version initialization. Based on my research, that safe to call and there are NVM+Xcode issues out there that suggest the same thing to fix it.

I was able to repro the issue, Xcode - for some reason - doesn't pick my default NodeJS version, which is controlled by NVM. That results in the wrong version of amplify CLI being used by our script, so even when I do npm -g install @aws-amplify/cli in my terminal Xcode still picks the wrong version. By forcing the NVM initialization inside the Xcode Build Phase the problem is gone.

@drochetti drochetti requested a review from wooj2 June 16, 2020 00:38
Comment on lines +23 to +24
set -e

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have caught this before....

set -e should probably come before export PATH=$PATH:$(npm bin -g) in case npm bin fails.

@drochetti drochetti merged commit 2b6972b into master Jun 16, 2020
@drochetti drochetti deleted the fix/amplify-tools-nvm branch June 16, 2020 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues related to build and CI/CD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants