Commit Graph

16 Commits

Author SHA1 Message Date
Matt Saladna
ad4fa37deb
Add test for NVM_DIR outside nvm.sh
Fix symlink traversal
2023-12-09 19:26:17 -05:00
Matt Saladna
d956279e5a
shellcheck warnings 2023-12-09 19:26:17 -05:00
Matt Saladna
c18cbf4d25
Allow nvm-exec to be linked into individual .nvm directories for system-wide installs with a localized Nodes.
Let's say we have nvm installed in a separate mount, /.socket. NVM_DIR is $HOME/.nvm in /etc/profile.d/nvm.sh. With this setup, users can install Node versions to their home directories without each installing nvm.

nvm install --lts

This works fine as does nvm use --lts. When nvm exec is used though, it fails because it looks for nvm-exec in $NVM_DIR. First fix is to look for nvm-exec in $NVM_DIR. If NVM_DIR does not contain nvm-exec, check $BASH_SOURCE[0]. The second fix is to follow nvm-exec if a symbolic link to determine the proper location of nvm's home. Alternatively we could use a second environment variable, NVM_HOME in exec instead of relying on the directory name of nvm-exec.
2023-12-09 19:25:43 -05:00
Spike Grobstein
70aa611abc
[Fix] nvm exec: no longer error with '-q: invalid option' for zsh users
the `nvm.sh` file assigns and exports an `NVM_CD_FLAGS` variable if it
was sourced from a zsh shell. the fact that it's exported means that
it'll be assigned in all child processes, including the `nvm-exec`
script, which uses bash as the interpreter.

Bash's `cd` command doesn't have a `-q` flag, so if the `NVM_CD_FLAGS`
is assigned `-q`, the script will error out and incorrectly claim that
the node version isn't installed.

this also manifests itself in the `nvm exec` command.

Example:

```console
$ nvm exec 16.14.0 npm --version
Running node v16.14.0 (npm v8.3.1)
/Users/<ME>/.nvm/nvm.sh: line 28: cd: -q: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]
both the tree and the node path are required
N/A: version "v16.14.0 -> N/A" is not yet installed.

You need to run "nvm install v16.14.0" to install it before using it.
```

To address this, we unset the `NVM_CD_FLAGS` at the start of the
`nvm-exec` script, before loading `nvm.sh`.
2023-04-21 20:40:01 -07:00
Jordan Harband
ad24e96fda
[shellcheck] disable additional -x warning from v0.7.2 2021-05-03 14:26:45 -07:00
Peter Dave Hello
ac63638469
[Fix] add missing quotes for $NODE_VERSION in nvm-exec 2016-11-24 13:44:39 +08:00
Qiangjun Ran
cadbbced20
[Tests] Replace all dots with backslash dots 2016-11-03 23:44:59 -07:00
Thomas Levine
0eaa7e0bde use env bash in nvm-exec and install.sh 2016-02-14 19:34:19 +00:00
Jordan Harband
77e0449c89 [Fix] nvm-exec: properly exit when failing; improve error messages, suppress nvm use --help output
Fixes #997.
2016-02-04 11:19:34 -08:00
Jordan Harband
4fcf37fa29 [New] support --no-use on sourcing, in supported shells.
Fixes #972.
2016-01-20 12:50:45 -08:00
Keiichiro Ui
b76d43e9f8 Fix nvm-exec for the commands includes white-spaces 2015-12-24 19:48:35 +09:00
Jordan Harband
d68f667464 When no arguments are passed to nvm run X, use nvm exec to open a REPL.
Fixes #625. Tests will be in #717.
2015-04-05 15:13:35 -07:00
Koen Punt
b16bf303ca Suppress output of nvm use
+redirect errors to stdout
2014-06-18 08:54:14 +02:00
Jordan Harband
0871131dfd Make sure nvm-exec can use .nvmrc logic. Fixes #402, obviates #403. 2014-04-25 10:38:21 -07:00
Jordan Harband
3a21485050 Files should end in trailing newlines 2014-03-15 11:41:50 -07:00
Koen Punt
f3d1770e3e nvm exec wrapper to execute commands with a specific node version 2014-03-15 15:58:32 +01:00