You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -8,41 +8,47 @@ English | [中文简体](README_zh-CN.md)
8
8
9
9
### Introduction
10
10
11
-
Nodapt (/noʊˈdæpt/) is a command-line tool that adapts to multiple NodeJS versions. It will run commands with the appropriate NodeJS version based on the NodeJS version constraints in `packages.json`.
11
+
Nodapt (/noʊˈdæpt/) is a command-line tool designed to work with multiple Node.js versions. It automatically selects and uses the appropriate Node.js version to run commands based on the version constraints specified in the `package.json` file.
12
12
13
13
### Background
14
14
15
-
When developing NodeJS projects, we often need to switch NodeJS versions. For example, project A requires `16.x.y`, while project B uses `20.x.y`.
15
+
When developing Node.js projects, it is common to switch between different Node.js versions. For example, Project A might require `16.x.y`, while Project B uses `20.x.y`.
16
16
17
-
However, global version management tools like nvm cannot meet the requirements. It has the following problems:
17
+
However, traditional global version management tools (e.g., nvm) often fall short in meeting these needs due to the following issues:
18
18
19
-
1.nvm is not cross-platform, and it is not very convenient to use on Windows.
20
-
2.nvm needs to install the specified version in advance to switch, which is not very friendly to the CI/CD environment.
21
-
3.In a Monorepo, there may be a situation where package A requires `16.x.y`, while package B requires `20.x.y`. In this case, nvm cannot solve this problem well.
19
+
1.**Limited cross-platform support**: nvm is not very convenient to use on Windows.
20
+
2.**Pre-installation requirements**: nvm requires pre-installing specific versions, which is not ideal for CI/CD environments.
21
+
3.**Lack of Monorepo support**: In Monorepo setups, different subprojects may require different Node.js versions, which nvm cannot handle effectively.
22
22
23
-
So I developed this tool to solve this problem.
24
-
25
-
It will run the command with the appropriate NodeJS version according to the NodeJS version constraint in `packages.json`.
23
+
To address these challenges, Nodapt was developed. It automatically selects and installs the appropriate Node.js version to run commands based on the version constraints in `package.json`.
26
24
27
25
### Features
28
26
29
27
-[x] Cross-platform support (Mac/Linux/Windows)
30
-
-[x] Automatically select and install the NodeJS version to run the command
31
-
-[x] Specify the NodeJS version to run the command
28
+
-[x] Automatically select and install the appropriate Node.js version to run commands
29
+
-[x] Support for running commands with a specified Node.js version
30
+
-[x] Support for Node.js version constraints in `package.json`
31
+
-[x] Monorepo project support
32
+
-[x] CI/CD environment support
33
+
-[x] Compatibility with other Node.js version managers (e.g., nvm, n, fnm)
34
+
-[x] Support for opening a new shell session with the `nodapt use <version>` command
32
35
33
36
### Usage
34
37
35
38
```bash
36
-
# Automatically select the NodeJS version to run the command
39
+
# Automatically select the appropriate Node.js version to run a command
37
40
$ nodapt node -v
38
41
39
-
#Specify the NodeJS version and run the specified command
42
+
#Run a command with a specified Node.js version
40
43
$ nodapt use ^18 node -v
44
+
45
+
# Specify a version range and open a new shell session
46
+
$ nodapt use 20
41
47
```
42
48
43
-
### Integrate into your NodeJS project
49
+
### Integrating with Your Node.js Project
44
50
45
-
1. Add NodeJS version constraint in `package.json`.
51
+
1. Add Node.js version constraints to your `package.json` file:
46
52
47
53
```diff
48
54
+ "engines": {
@@ -53,99 +59,56 @@ $ nodapt use ^18 node -v
53
59
}
54
60
```
55
61
56
-
2.Run the script with `nodapt` command.
62
+
2.Use the `nodapt` command to run scripts:
57
63
58
64
```diff
59
65
- yarn dev
60
66
+ nodapt yarn dev
61
67
```
62
68
63
-
Run with `--help` to see more options.
64
-
65
-
```
66
-
$ nodapt --help
67
-
nodapt - A virtual node environment for node.js, node version manager for projects.
68
-
69
-
USAGE:
70
-
nodapt [OPTIONS] <ARGS...>
71
-
nodapt [OPTIONS] run <ARGS...>
72
-
nodapt [OPTIONS] use <CONSTRAINT> [ARGS...]
73
-
nodapt [OPTIONS] rm <CONSTRAINT>
74
-
nodapt [OPTIONS] clean
75
-
nodapt [OPTIONS] ls
76
-
nodapt [OPTIONS] ls-remote
77
-
78
-
COMMANDS:
79
-
<ARGS...> Alias for 'run <ARGS...>' but shorter
80
-
run <ARGS...> Automatically select node version to run commands
81
-
use <CONSTRAINT> <ARGS...> Use the specified version of node to run the command
82
-
rm|remove <CONSTRAINT> Remove the specified version of node that installed by nodapt
83
-
clean Remove all the node version that installed by nodapt
84
-
ls|list List all the installed node version
85
-
ls-remote|list-remote List all the available node version
86
-
87
-
OPTIONS:
88
-
--help|-h Print help information
89
-
--version|-v Print version information
90
-
91
-
ENVIRONMENT VARIABLES:
92
-
NODE_MIRROR The mirror of the nodejs download, defaults to: https://nodejs.org/dist/
93
-
Chinese users defaults to: https://registry.npmmirror.com/-/binary/node/
94
-
NODE_ENV_DIR The directory where the nodejs is stored, defaults to: $HOME/.nodapt
95
-
DEBUG Print debug information when set DEBUG=1
96
-
97
-
EXAMPLES:
98
-
nodapt node -v
99
-
nodapt run node -v
100
-
nodapt use v14.17.0 node -v
101
-
102
-
SOURCE CODE:
103
-
https://github.com/axetroy/nodapt
104
-
```
69
+
Run `nodapt --help` to see more options.
105
70
106
71
### Installation
107
72
108
-
1. Install via [Cask](https://github.com/cask-pkg/cask.rs) (Mac/Linux/Windows)
73
+
####Install via [Cask](https://github.com/cask-pkg/cask.rs) (Mac/Linux/Windows)
109
74
110
75
```bash
111
76
$ cask install github.com/axetroy/nodapt
112
77
$ nodapt --help
113
78
```
114
79
115
-
2. Install via npm
80
+
####Install via npm
116
81
117
-
```sh
118
-
$ npm install nodapt -g
82
+
```bash
83
+
$ npm install @axetroy/nodapt -g
119
84
$ nodapt --help
120
85
```
121
86
122
-
### Uninstall
87
+
### Uninstallation
123
88
124
89
```bash
125
90
$ nodapt clean
126
-
#then remove the binary file or uninstall via package manager
91
+
#Then remove the executable file or uninstall it via your package manager
127
92
```
128
93
129
-
### NodeJS version selection algorithm
94
+
### Node.js Version Selection Algorithm
130
95
131
-
This section explains what happens when you run `nodapt` and how it selects the node version.
96
+
This section explains how `nodapt`behaves and selects the appropriate Node.js version when executed:
132
97
133
-
1. Check for the presence of `package.json`.
134
-
2. If `package.json` exists:
135
-
1.If the `engines.node` field is specified, use the indicated version.
136
-
1. If the currently installed version matches `engines.node`, the command is run using the currently installed version.
137
-
2. Otherwise, select the latest matching version from the remote list, install it, and run the command.
138
-
2.Otherwise, run the command directly.
139
-
3.Otherwise, run the command directly.
98
+
1. Check if a `package.json` file exists in the current directory.
99
+
2. If it exists:
100
+
1.Check if the `engines.node` field specifies a version constraint:
101
+
- If the currently installed version satisfies the constraint, use it directly.
102
+
- If not, select the latest matching version from the remote list, install it, and then run the command.
103
+
2.If `engines.node` is not specified, run the command directly.
104
+
3.If `package.json` does not exist, run the command directly.
0 commit comments