Skip to content

Commit

Permalink
Make ddev nvm work right again, fixes ddev#4499 (ddev#4620)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay authored Feb 9, 2023
1 parent 969de43 commit a9b53ba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/ddev/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ func TestGetActiveAppRoot(t *testing.T) {

// And we should be able to stop it and find it as well
app, err := ddevapp.GetActiveApp("")
require.NoError(t, err)
err = app.Stop(false, true)
assert.NoError(err)
require.NoError(t, err)

t.Cleanup(func() {
err = os.Chdir(origDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ if ! shopt -oq posix; then
fi

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && source "$NVM_DIR/bash_completion"

for f in /etc/bashrc/*.bashrc; do
source $f;
Expand Down
1 change: 1 addition & 0 deletions pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ func (app *DdevApp) RenderComposeYAML() (string, error) {
}

extraWebContent := "\nRUN mkdir -p /home/$username && chown $username /home/$username && chmod 600 /home/$username/.pgpass"
extraWebContent = extraWebContent + "\nENV NVM_DIR=/home/$username/.nvm"
if app.NodeJSVersion != nodeps.NodeJSDefault {
extraWebContent = extraWebContent + "\nRUN (apt-get remove -y nodejs || true) && (apt purge nodejs || true)"
// Download of setup_*.sh seems to fail a LOT, probably a problem on their end. So try it twice
Expand Down
12 changes: 11 additions & 1 deletion pkg/ddevapp/nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ func TestNodeJSVersions(t *testing.T) {
assert.Contains(out, "Now using node v6")

out, err = exec.RunHostCommand(DdevBin, "nvm", "install", "8")
require.NoError(t, err)
require.NoError(t, err, "output=%v", out)
assert.Contains(out, "Now using node v8")
out, err = exec.RunHostCommand(DdevBin, "nvm", "use", "8")
require.NoError(t, err, "output=%v", out)
out, err = exec.RunHostCommand(DdevBin, "nvm", "alias", "default", "8")
require.NoError(t, err, "output=%v", out)

out, err = exec.RunHostCommand(DdevBin, "exec", "node", "--version")
require.NoError(t, err)

assert.Contains(out, "v8.17")

}
2 changes: 1 addition & 1 deletion pkg/versionconstants/versionconstants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var SegmentKey = ""
var WebImg = "drud/ddev-webserver"

// WebTag defines the default web image tag
var WebTag = "20230128_xdebug_build_time" // Note that this can be overridden by make
var WebTag = "20230207_fix_nvm" // Note that this can be overridden by make

// DBImg defines the default db image used for applications.
var DBImg = "drud/ddev-dbserver"
Expand Down

0 comments on commit a9b53ba

Please sign in to comment.