mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:15:53 +08:00 
			
		
		
		
	Adding nvm exec command.
				
					
				
			This commit is contained in:
		| @@ -38,7 +38,7 @@ Often I also put in a line to use a specific version of node. | |||||||
| ## Usage | ## Usage | ||||||
|  |  | ||||||
| You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory). | You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory). | ||||||
| `nvm use`, `nvm install`, and `nvm run` will all respect an `.nvmrc` file. | `nvm use`, `nvm install`, `nvm exec`, and `nvm run` will all respect an `.nvmrc` file. | ||||||
|  |  | ||||||
| To download, compile, and install the latest v0.10.x release of node, do this: | To download, compile, and install the latest v0.10.x release of node, do this: | ||||||
|  |  | ||||||
| @@ -52,6 +52,10 @@ Or you can just run it: | |||||||
|  |  | ||||||
|     nvm run 0.10 --version |     nvm run 0.10 --version | ||||||
|  |  | ||||||
|  | Or, you can run any arbitrary command in the node environment: | ||||||
|  |  | ||||||
|  |     nvm exec 0.10 node --version | ||||||
|  |  | ||||||
| If you want to see what versions are installed: | If you want to see what versions are installed: | ||||||
|  |  | ||||||
|     nvm ls |     nvm ls | ||||||
|   | |||||||
							
								
								
									
										23
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -639,6 +639,29 @@ nvm() { | |||||||
|       echo "Running node $VERSION" |       echo "Running node $VERSION" | ||||||
|       NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" |       NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" | ||||||
|     ;; |     ;; | ||||||
|  |     "exec" ) | ||||||
|  |       shift | ||||||
|  |  | ||||||
|  |       local provided_version | ||||||
|  |       provided_version=$1 | ||||||
|  |       if [ -n "$provided_version" ]; then | ||||||
|  |         VERSION=`nvm_version $provided_version` | ||||||
|  |         if [ $VERSION = "N/A" ]; then | ||||||
|  |           provided_version='' | ||||||
|  |           nvm_rc_version | ||||||
|  |           VERSION=`nvm_version $NVM_RC_VERSION` | ||||||
|  |         else | ||||||
|  |           shift | ||||||
|  |         fi | ||||||
|  |       fi | ||||||
|  |  | ||||||
|  |       if [ ! -d "$NVM_DIR/$VERSION" ]; then | ||||||
|  |         echo "$VERSION version is not installed yet" >&2 | ||||||
|  |         return 1 | ||||||
|  |       fi | ||||||
|  |       echo "Running node $VERSION" | ||||||
|  |       NODE_VERSION=$VERSION $NVM_DIR/nvm-exec "$@" | ||||||
|  |     ;; | ||||||
|     "ls" | "list" ) |     "ls" | "list" ) | ||||||
|       local NVM_LS_OUTPUT |       local NVM_LS_OUTPUT | ||||||
|       local NVM_LS_EXIT_CODE |       local NVM_LS_EXIT_CODE | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user