mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 22:31:51 +00:00
Compare commits
344 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
977563e97d | ||
![]() |
99352a64d2 | ||
![]() |
ffec9fec72 | ||
![]() |
df9ac58f8b | ||
![]() |
8dbc22f0e9 | ||
![]() |
5c12680a62 | ||
![]() |
f0f8ed12f8 | ||
![]() |
759f70f196 | ||
![]() |
06a9179309 | ||
![]() |
74eb396099 | ||
![]() |
9f520c97db | ||
![]() |
e5521cfd3c | ||
![]() |
247ed8a186 | ||
![]() |
14507f807f | ||
![]() |
6135555b40 | ||
![]() |
d90a7910db | ||
![]() |
8c30ac633b | ||
![]() |
ecdc865a5a | ||
![]() |
9bcbbef4eb | ||
![]() |
b77fcec399 | ||
![]() |
287d535f2c | ||
![]() |
572c757f6d | ||
![]() |
1d39e35bd3 | ||
![]() |
19f452ba0f | ||
![]() |
b9b0ea8020 | ||
![]() |
dae1427f7e | ||
![]() |
0641363102 | ||
![]() |
9659af6c16 | ||
![]() |
abd02e5aae | ||
![]() |
3de0b15810 | ||
![]() |
cd22c84026 | ||
![]() |
d648a3b1ba | ||
![]() |
ccf6d16017 | ||
![]() |
ba98270442 | ||
![]() |
1be4257e96 | ||
![]() |
9c9ff4bac0 | ||
![]() |
51ea809d63 | ||
![]() |
6b70c40f15 | ||
![]() |
5dc31ac51b | ||
![]() |
da2720a429 | ||
![]() |
9fb9dec710 | ||
![]() |
9a28dbd394 | ||
![]() |
179d45050b | ||
![]() |
ff7634577b | ||
![]() |
0ce8f5a52f | ||
![]() |
863bd63cfa | ||
![]() |
0d53381666 | ||
![]() |
df70535248 | ||
![]() |
c31a867c46 | ||
![]() |
a8c418558a | ||
![]() |
d5e2c92a25 | ||
![]() |
81f18bc445 | ||
![]() |
4beab63631 | ||
![]() |
14acd3dcdd | ||
![]() |
271720ebfc | ||
![]() |
423ee82b4c | ||
![]() |
deac4e0932 | ||
![]() |
b5118ac365 | ||
![]() |
24deac7ac5 | ||
![]() |
ff1257e8e3 | ||
![]() |
87a709741f | ||
![]() |
f439acda4a | ||
![]() |
dd89af53f5 | ||
![]() |
bd090ef7f8 | ||
![]() |
4c7d899447 | ||
![]() |
80cb39d712 | ||
![]() |
93277112ae | ||
![]() |
762f9ef9d1 | ||
![]() |
e597bb208e | ||
![]() |
aa427ad396 | ||
![]() |
c20db2ab86 | ||
![]() |
29dce5edfd | ||
![]() |
95081f0bc2 | ||
![]() |
1750b8d327 | ||
![]() |
97093dc1b3 | ||
![]() |
811c039e2b | ||
![]() |
294ff9e3aa | ||
![]() |
c24c3134a7 | ||
![]() |
c82e7a6f62 | ||
![]() |
4e2a71ba9b | ||
![]() |
6c9cd2f2d1 | ||
![]() |
bab86d5de5 | ||
![]() |
d86f270438 | ||
![]() |
c73009f503 | ||
![]() |
7aee54b76c | ||
![]() |
6262b5a666 | ||
![]() |
925cff2c78 | ||
![]() |
b1fa143dd8 | ||
![]() |
cc765cc000 | ||
![]() |
99646ee600 | ||
![]() |
b356fab4b4 | ||
![]() |
064f2597d1 | ||
![]() |
6b15796f66 | ||
![]() |
3e51872b98 | ||
![]() |
4bdd57ba0f | ||
![]() |
d02ddcac2c | ||
![]() |
ef7fc2f2c0 | ||
![]() |
b64e5474ea | ||
![]() |
1f970ccb7a | ||
![]() |
6743aef70c | ||
![]() |
10cdda081f | ||
![]() |
8241287349 | ||
![]() |
6aeab3349c | ||
![]() |
bfce5889f7 | ||
![]() |
fd412645ca | ||
![]() |
2426a0c4b2 | ||
![]() |
8a83b36688 | ||
![]() |
414e8d426f | ||
![]() |
1b102ab9a6 | ||
![]() |
d4a733e4d8 | ||
![]() |
1de3333651 | ||
![]() |
1eaaada499 | ||
![]() |
c92adb3c47 | ||
![]() |
15eba7b7e6 | ||
![]() |
a1601eddb8 | ||
![]() |
324b81a722 | ||
![]() |
55075db96d | ||
![]() |
4618ce0aa1 | ||
![]() |
3afdce0a2c | ||
![]() |
8fbf8ab694 | ||
![]() |
4fc91d408c | ||
![]() |
f86847fdd2 | ||
![]() |
9a769630d7 | ||
![]() |
c26422a03e | ||
![]() |
7c3cd81ad9 | ||
![]() |
0ebda7eea3 | ||
![]() |
5410ae57ba | ||
![]() |
70aa611abc | ||
![]() |
c08b38a2a4 | ||
![]() |
a07cd41af1 | ||
![]() |
d1a22a63bd | ||
![]() |
0d9b5c2a00 | ||
![]() |
44e1d9c911 | ||
![]() |
b1331c20b0 | ||
![]() |
766341fca1 | ||
![]() |
946da2e743 | ||
![]() |
dde04f9392 | ||
![]() |
ffcb5213e2 | ||
![]() |
ea3b65f02e | ||
![]() |
ee6f766712 | ||
![]() |
edacf8275e | ||
![]() |
f36516b472 | ||
![]() |
dc691121b8 | ||
![]() |
ce35311657 | ||
![]() |
fe06825a96 | ||
![]() |
a60ac08a80 | ||
![]() |
552db40622 | ||
![]() |
788c0a425e | ||
![]() |
333c52ec04 | ||
![]() |
59f448d595 | ||
![]() |
d0bc227127 | ||
![]() |
bf438742a7 | ||
![]() |
447940acb3 | ||
![]() |
0ec2ca979c | ||
![]() |
b86c91efe3 | ||
![]() |
ac357c59ef | ||
![]() |
abe5e30a9d | ||
![]() |
4c4b0d64ed | ||
![]() |
e6fa80cb61 | ||
![]() |
1f4bb91ae6 | ||
![]() |
924d77cc90 | ||
![]() |
095a4ca655 | ||
![]() |
9721791563 | ||
![]() |
89d6cdd6cf | ||
![]() |
df84c77a81 | ||
![]() |
fe6268c021 | ||
![]() |
df01d81128 | ||
![]() |
0ccd099bff | ||
![]() |
f062cca179 | ||
![]() |
0698ede92d | ||
![]() |
71a73b17cf | ||
![]() |
0ae8409f4f | ||
![]() |
5e9791c4f8 | ||
![]() |
7c929f8742 | ||
![]() |
c6269e0ac2 | ||
![]() |
28b3b0e324 | ||
![]() |
b133f6619d | ||
![]() |
4893128c61 | ||
![]() |
8fd948001e | ||
![]() |
5a4e9184f1 | ||
![]() |
95269ff055 | ||
![]() |
2cfced740a | ||
![]() |
35758b75ed | ||
![]() |
d451e261ed | ||
![]() |
a82edf40ba | ||
![]() |
ef3b20c21e | ||
![]() |
01886b4243 | ||
![]() |
bd083ff367 | ||
![]() |
9e884b8d7b | ||
![]() |
7d86701067 | ||
![]() |
c367d7daa0 | ||
![]() |
d157cac689 | ||
![]() |
39d9a42c35 | ||
![]() |
2c0c34f10e | ||
![]() |
c2f740ab38 | ||
![]() |
6cfaede5a0 | ||
![]() |
1875fe8b40 | ||
![]() |
81f0f3ec19 | ||
![]() |
fb4538b360 | ||
![]() |
d004c6b064 | ||
![]() |
79ad72d116 | ||
![]() |
ccd442d833 | ||
![]() |
9600617c52 | ||
![]() |
5cc74a6736 | ||
![]() |
aa57406ede | ||
![]() |
0f62be6fdd | ||
![]() |
c4c7690dec | ||
![]() |
aed1d732d7 | ||
![]() |
0b4cd8df6c | ||
![]() |
430860a8be | ||
![]() |
2459d17741 | ||
![]() |
6cc90a4b8d | ||
![]() |
81fc05684d | ||
![]() |
328dd5004e | ||
![]() |
4856407d26 | ||
![]() |
275001b066 | ||
![]() |
89379176ac | ||
![]() |
30486b9bd9 | ||
![]() |
e9b26938b9 | ||
![]() |
ccd98f7fcb | ||
![]() |
2f40eeef2e | ||
![]() |
c9e7bb2da1 | ||
![]() |
a284af9228 | ||
![]() |
5b3d188b83 | ||
![]() |
e8f485bb63 | ||
![]() |
055af09d24 | ||
![]() |
93e0070a44 | ||
![]() |
10189bf4cb | ||
![]() |
da5baa005b | ||
![]() |
ebbd30eb7f | ||
![]() |
2bda9fd97e | ||
![]() |
7b530edd3a | ||
![]() |
1afd4f3566 | ||
![]() |
53f9ba8336 | ||
![]() |
07c02d43fe | ||
![]() |
59b0b3942c | ||
![]() |
7bbc57355d | ||
![]() |
47f0b32155 | ||
![]() |
91bd22aa57 | ||
![]() |
ca897ac6d5 | ||
![]() |
11d71ab24b | ||
![]() |
4471b6beb6 | ||
![]() |
cc6915e216 | ||
![]() |
b6b6e685a3 | ||
![]() |
d91087c333 | ||
![]() |
59532c74c6 | ||
![]() |
2dad0455ec | ||
![]() |
f03f69508e | ||
![]() |
fa63399991 | ||
![]() |
291c7c4c47 | ||
![]() |
c169d622ff | ||
![]() |
5b77f7d023 | ||
![]() |
fd78c0101e | ||
![]() |
678a827978 | ||
![]() |
62d45af17e | ||
![]() |
e0df5e92e3 | ||
![]() |
e98e9d9e4b | ||
![]() |
812d6e4ab4 | ||
![]() |
7f2ccd51d4 | ||
![]() |
7ba49f8f71 | ||
![]() |
eed0d0e85c | ||
![]() |
ad24e96fda | ||
![]() |
b5165ecbe4 | ||
![]() |
fc87226b23 | ||
![]() |
f3caa06420 | ||
![]() |
1527ac9d21 | ||
![]() |
bd0ac1e96d | ||
![]() |
117486d4a7 | ||
![]() |
07253ecd51 | ||
![]() |
f2582275f6 | ||
![]() |
d118be8fd4 | ||
![]() |
5fcec573eb | ||
![]() |
779a34e6a9 | ||
![]() |
2b5e53fcd5 | ||
![]() |
f534fde760 | ||
![]() |
3fea5493a4 | ||
![]() |
cfc7edac65 | ||
![]() |
c26bd935c0 | ||
![]() |
621ccc5d13 | ||
![]() |
b19d8dbbba | ||
![]() |
0579718308 | ||
![]() |
8884fd32f6 | ||
![]() |
25d2ebf2f8 | ||
![]() |
9cb6a2b614 | ||
![]() |
216ccd62f7 | ||
![]() |
4da7f101a2 | ||
![]() |
641f86879f | ||
![]() |
1081ed161b | ||
![]() |
52f67b3677 | ||
![]() |
4fdef427e4 | ||
![]() |
d9b11ba208 | ||
![]() |
87f37909f2 | ||
![]() |
7f6c0c053a | ||
![]() |
d396181ffb | ||
![]() |
a5742d4e9e | ||
![]() |
d5c1441a83 | ||
![]() |
0fad5ec575 | ||
![]() |
0d14d7f6b7 | ||
![]() |
4c11ab1ac6 | ||
![]() |
49e806c77a | ||
![]() |
3243f7a082 | ||
![]() |
015623ee6d | ||
![]() |
502089ae30 | ||
![]() |
589c2377fb | ||
![]() |
60e78d3ec1 | ||
![]() |
9f3397afa4 | ||
![]() |
436cda247e | ||
![]() |
9849bf494d | ||
![]() |
4e9df33cb7 | ||
![]() |
f3fa157456 | ||
![]() |
6982dee071 | ||
![]() |
31c5c5c45a | ||
![]() |
2fea55fdb5 | ||
![]() |
10399ed1bd | ||
![]() |
3c079f16c7 | ||
![]() |
e76b2945c5 | ||
![]() |
e48cb858a6 | ||
![]() |
86708833c9 | ||
![]() |
d4eba354b5 | ||
![]() |
ed321f1df0 | ||
![]() |
4b947ec92d | ||
![]() |
3b57dfec8d | ||
![]() |
661a702cdd | ||
![]() |
510b2fd44c | ||
![]() |
80a4e06af9 | ||
![]() |
22902f04a3 | ||
![]() |
6848c16d53 | ||
![]() |
3abb98124e | ||
![]() |
21c0c05130 | ||
![]() |
00af6341f7 | ||
![]() |
11a9d22607 | ||
![]() |
bbe032fa7e | ||
![]() |
4054bd70ce | ||
![]() |
499d303746 | ||
![]() |
31bc0a13c2 | ||
![]() |
c72f2c6f21 | ||
![]() |
f2c5ce459a | ||
![]() |
0f0d5e8270 | ||
![]() |
e77ed07ccc | ||
![]() |
e01060fa2c | ||
![]() |
96069da0d5 | ||
![]() |
4436638816 | ||
![]() |
344cc32ac3 | ||
![]() |
7929190e6e |
@ -8,6 +8,7 @@ test/bak
|
|||||||
.urchin.log
|
.urchin.log
|
||||||
.urchin_stdout
|
.urchin_stdout
|
||||||
test/**/test_output
|
test/**/test_output
|
||||||
|
test/**/.nvmrc
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
@ -12,10 +12,10 @@ trim_trailing_whitespace = true
|
|||||||
[*.txt]
|
[*.txt]
|
||||||
indent_size = false
|
indent_size = false
|
||||||
|
|
||||||
[test/fast/Listing versions/Running "nvm ls" calls into nvm_alias]
|
[test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias]
|
||||||
indent_size = false
|
indent_size = false
|
||||||
|
|
||||||
[test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]
|
[test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias]
|
||||||
indent_size = false
|
indent_size = false
|
||||||
|
|
||||||
[test/fast/Unit tests/mocks/**]
|
[test/fast/Unit tests/mocks/**]
|
||||||
@ -26,3 +26,10 @@ insert_final_newline = off
|
|||||||
|
|
||||||
[Makefile]
|
[Makefile]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
|
||||||
|
[test/fixtures/nvmrc/**]
|
||||||
|
indent_style = off
|
||||||
|
insert_final_newline = off
|
||||||
|
|
||||||
|
[test/fixtures/actual/alias/empty]
|
||||||
|
insert_final_newline = off
|
||||||
|
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1 +1 @@
|
|||||||
* eol=lf
|
* text=auto eol=lf
|
||||||
|
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: false
|
@ -1,3 +1,11 @@
|
|||||||
|
---
|
||||||
|
name: File an issue…
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
<!-- Thank you for being interested in nvm! Please help us by filling out the following form if you‘re having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! -->
|
<!-- Thank you for being interested in nvm! Please help us by filling out the following form if you‘re having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! -->
|
||||||
|
|
27
.github/SECURITY.md
vendored
Normal file
27
.github/SECURITY.md
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Security
|
||||||
|
|
||||||
|
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
||||||
|
|
||||||
|
## OpenSSF CII Best Practices
|
||||||
|
|
||||||
|
[](https://bestpractices.coreinfrastructure.org/projects/684)
|
||||||
|
|
||||||
|
There are three “tiers”: passing, silver, and gold.
|
||||||
|
|
||||||
|
### Passing
|
||||||
|
We meet 100% of the “passing” criteria.
|
||||||
|
|
||||||
|
### Silver
|
||||||
|
We meet 95% of the “silver” criteria. The gaps are as follows:
|
||||||
|
- we do not have a DCO or a CLA process for contributions.
|
||||||
|
- because we only have one maintainer, the project has no way to continue if that maintainer stops being active.
|
||||||
|
- we do not currently document “what the user can and cannot expect in terms of security” for our project. This is planned to be completed in 2023.
|
||||||
|
|
||||||
|
### Gold
|
||||||
|
We meet 65% of the “gold” criteria. The gaps are as follows:
|
||||||
|
- we do not yet have the “silver” badge; see all the gaps above.
|
||||||
|
- We do not include a copyright or license statement in each source file. Efforts are underway to change this archaic practice into a suggestion instead of a hard requirement.
|
||||||
|
|
||||||
|
## Threat Model
|
||||||
|
|
||||||
|
See [THREAT_MODEL.md](./THREAT_MODEL.md).
|
109
.github/THREAT_MODEL.md
vendored
Normal file
109
.github/THREAT_MODEL.md
vendored
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
# `nvm` Threat Model
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
|
||||||
|
Threat model analysis assists organizations to proactively identify potential security threats and vulnerabilities, enabling them to develop effective strategies to mitigate these risks before they are exploited by attackers.
|
||||||
|
Furthermore, this often helps to improve the overall security and resilience of a system or application.
|
||||||
|
|
||||||
|
The aim of this section is to facilitate the identification of potential security threats and vulnerabilities that may be exploited by adversaries, along with possible outcomes and appropriate mitigations.
|
||||||
|
|
||||||
|
## Relevant assets and threat actors
|
||||||
|
|
||||||
|
The following assets are considered important for the `nvm` project:
|
||||||
|
- `nvm` source code and project documentation
|
||||||
|
- Underlying `nvm` dependencies
|
||||||
|
- `nvm` development infrastructure
|
||||||
|
- `nvm` installed devices including servers
|
||||||
|
|
||||||
|
The following threat actors are considered relevant to the `nvm` application:
|
||||||
|
- External malicious attackers
|
||||||
|
- Internal malicious attackers
|
||||||
|
- Services
|
||||||
|
- Malicious insider actors
|
||||||
|
- Third-party libraries
|
||||||
|
|
||||||
|
## Attack surface for external/internal attackers and services
|
||||||
|
|
||||||
|
In threat modeling, an attack surface refers to any possible point of entry that an attacker might use to exploit a system or application.
|
||||||
|
This includes all the paths and interfaces that an attacker may use to access, manipulate or extract sensitive data from a system.
|
||||||
|
By understanding the attack surface, organizations are typically able to identify potential attack vectors and implement appropriate countermeasures to mitigate risks.
|
||||||
|
|
||||||
|
In the following diagrams, _External Malicious Attacker_ applies to threat actors who do not yet have direct access to the `nvm` application and the underlying operating system, while the _Internal Malicious Attacker_ applies to an attacker with access to the device (computer, server), potentially after successfully exploiting a threat from the _External Malicious Attacker_ scenario.
|
||||||
|
**Please note that some of the external threats may be also exploitable from internal threats and vice versa.**
|
||||||
|
|
||||||
|
<img src="./external-threat-actor.png" alt="Fig.: Possible attacks from internal and external threat actors and services" />
|
||||||
|
Fig.: Possible attacks from internal and external threat actors and services
|
||||||
|
|
||||||
|
## Identified threats
|
||||||
|
|
||||||
|
The identified threats against the `nvm` application are as follows:
|
||||||
|
|
||||||
|
### Threat ID 1: `nvm` commands
|
||||||
|
|
||||||
|
Overview: The `nvm` commands and subcommands take user input for handling and executing appropriate functions from the project directory (or any parent directory).
|
||||||
|
When user-controlled inputs are not adequately validated and later passed to the `nvm` functions as a part of a command, an attacker might be able to execute operating system commands triggered by any parsing functionality.
|
||||||
|
|
||||||
|
Possible Outcome: Attacks against `nvm` commands could lead to unauthorized access to user data or unauthorized access to the device (i.e. laptop or server, depending on where `nvm` is installed), resulting in loss of user private data stored on the device, among other possibilities.
|
||||||
|
|
||||||
|
Recommendation: Input validation should be implemented to prevent attackers from requesting operating system commands.
|
||||||
|
Similarly, secure coding practices ought to be in place to minimize the risk of buffer overflow vulnerabilities.
|
||||||
|
|
||||||
|
### Threat ID 2: URI scheme
|
||||||
|
|
||||||
|
Overview: `nvm` commands heavily use the [Secure HyperText Transfer](https://datatracker.ietf.org/doc/html/rfc2660) protocol for `nvm` related actions.
|
||||||
|
Missing [scheme](https://datatracker.ietf.org/doc/html/rfc3986#section-3.1) validation for any `nvm` command might result in file retrieval, enumeration, file overwrite, or [path traversal](https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/05-Authorization_Testing/01-Testing_Directory_Traversal_File_Include) attacks.
|
||||||
|
An example of this could be path validation for [`nvm_download`](https://github.com/nvm-sh/nvm/blob/ef7fc2f2c06ad75fe7fbabf28d427561ae7b007d/nvm.sh#L118), among many other possibilities.
|
||||||
|
|
||||||
|
Possible Outcome: Security misconfiguration flaws for URI scheme may lead to unauthorized access to user data, as well as data integrity compromises.
|
||||||
|
|
||||||
|
Recommendation: Adequate input validation should be implemented to prevent attackers from enumerating, retrieving and writing to application files and paths.
|
||||||
|
|
||||||
|
### Threat ID 3: Communication channel
|
||||||
|
|
||||||
|
Overview: The `nvm` commands and its subcommands use network protocol to communicate with external services.
|
||||||
|
Insecure communication may allow malicious attackers to perform [_Man-in-the-Middle_](https://owasp.org/www-community/attacks/Manipulator-in-the-middle_attack) attacks in order to manipulate the data sent during the users’ active connection.
|
||||||
|
|
||||||
|
Possible Outcome: Usage of plaintext communication protocols, like HTTP could lead to data sniffing and modification through insecure communications channels.
|
||||||
|
|
||||||
|
Recommendation: Mitigation countermeasures such as data encryption should be in place to prevent data manipulation via insecure communication channels.
|
||||||
|
|
||||||
|
### Threat ID 4: Environment variables
|
||||||
|
|
||||||
|
Overview: Each `nvm` installation defines its environment variables, which should be secured from internal malicious attackers, preventing access control attack vectors.
|
||||||
|
Missing stringent restrictions on setting variables, might allow attackers to prepare various targeted attacks against other local users, who use `nvm` in their user space.
|
||||||
|
For example, [_Privilege Escalation_](https://owasp.org/Top10/A01_2021-Broken_Access_Control/), [_Command Injection_](https://cwe.mitre.org/data/definitions/77.html), as well as many other parser-related attacks.
|
||||||
|
|
||||||
|
Possible Outcome: Attacks against environment variables could lead to unauthorized access to the user space, resulting in the loss of user private data and disruptions in service availability.
|
||||||
|
|
||||||
|
Recommendation: Adequate hardening of configuration file permissions should be in place for all relevant configuration files, as this provides protection against attackers able to manipulate variables and inject malicious code.
|
||||||
|
|
||||||
|
## Attack surface for malicious insider actors and third-party libraries
|
||||||
|
|
||||||
|
The following diagram summarizes the main possible threats against the `nvm` project from malicious insider actors and third-party libraries:
|
||||||
|
|
||||||
|
<img src="./insider-threat-actor-and-libs.png" alt="Fig.: Possible attacks from insider threat actors and third-party libraries" />
|
||||||
|
Fig.: Possible attacks from insider threat actors and third-party libraries
|
||||||
|
|
||||||
|
The identified threats against the `nvm` project are as follows:
|
||||||
|
|
||||||
|
### Threat ID 1: Insider threat actor
|
||||||
|
|
||||||
|
**Overview**: An insider threat actor, such as an `nvm` project contributor or employee with access to the code base, might abuse their role in the organization to modify the `nvm` application source code.
|
||||||
|
For example, intentionally adding malicious code snippets, clearing logs after being written and/or modifying specific sections of the documentation.
|
||||||
|
|
||||||
|
**Possible Outcome**: Reputation damage, financial losses.
|
||||||
|
|
||||||
|
**Recommendation**: Secure coding practices, code reviews, automated code scanning and separation of duties (i.e. requiring at least two developers to approve any code change) are potentially useful security controls to identify and mitigate vulnerabilities that may be introduced by an insider threat actor.
|
||||||
|
|
||||||
|
### Threat ID 2: Third-party libraries
|
||||||
|
|
||||||
|
**Overview**: Please note that while `nvm` does not currently make use of any third-party libraries, this might become an attack vector if that changes in the future.
|
||||||
|
Third-party libraries may introduce potential risks related to maintaining security requirements by third-party vendors.
|
||||||
|
As a result, third-party libraries used by the `nvm` project, might contain vulnerabilities, such as [_Buffer Overflows_](https://owasp.org/www-community/vulnerabilities/Buffer_Overflow), [_Format String Vulnerabilities_](https://owasp.org/www-community/attacks/Format_string_attack), as well as many other types of weaknesses that, in a worst-case scenario may lead to _Remote Code Execution_ (_RCE_).
|
||||||
|
Additionally, the maintainer of a third-party dependency might introduce a vulnerability on purpose, or be compromised by an attacker that subsequently introduces vulnerable code.
|
||||||
|
|
||||||
|
**Possible Outcome**: Code vulnerabilities may lead to unauthorized access to user data, loss of user private data, service disruptions and reputation damage.
|
||||||
|
|
||||||
|
**Recommendation**: Third-party libraries should be kept up-to-date, applying patches to address publicly known vulnerabilities in a timely fashion.
|
||||||
|
Monitoring and logging capabilities should also be in place to detect and respond to potential attacks.
|
||||||
|
SLSA compliance may also be considered for further supply chain security hardening.
|
BIN
.github/external-threat-actor.png
vendored
Normal file
BIN
.github/external-threat-actor.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
BIN
.github/insider-threat-actor-and-libs.png
vendored
Normal file
BIN
.github/insider-threat-actor-and-libs.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
86
.github/workflows/latest-npm.yml
vendored
Normal file
86
.github/workflows/latest-npm.yml
vendored
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
name: 'Tests: `nvm install-latest-npm`'
|
||||||
|
|
||||||
|
on: [pull_request, push]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
matrix:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
latest: ${{ steps.set-matrix.outputs.requireds }}
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
iojs.org:443
|
||||||
|
nodejs.org:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
- uses: ljharb/actions/node/matrix@main
|
||||||
|
id: set-matrix
|
||||||
|
with:
|
||||||
|
versionsAsRoot: true
|
||||||
|
type: majors
|
||||||
|
preset: '>=1'
|
||||||
|
|
||||||
|
nodes:
|
||||||
|
needs: [matrix]
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
name: 'nvm install-latest-npm'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
|
||||||
|
include:
|
||||||
|
- node-version: "21"
|
||||||
|
- node-version: "20.5"
|
||||||
|
- node-version: "20.4"
|
||||||
|
- node-version: "14.17"
|
||||||
|
- node-version: "14.16"
|
||||||
|
- node-version: "9.2"
|
||||||
|
- node-version: "9.1"
|
||||||
|
- node-version: "9.0"
|
||||||
|
- node-version: "6.1"
|
||||||
|
- node-version: "5.9"
|
||||||
|
- node-version: "4.6"
|
||||||
|
- node-version: "4.5"
|
||||||
|
- node-version: "4.4"
|
||||||
|
- node-version: "0.12"
|
||||||
|
- node-version: "0.10"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
github.com:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
iojs.org:443
|
||||||
|
nodejs.org:443
|
||||||
|
registry.npmjs.org:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ljharb/actions/node/install@main
|
||||||
|
name: 'install node'
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
skip-ls-check: true
|
||||||
|
skip-install: true
|
||||||
|
skip-latest-npm: true
|
||||||
|
- run: npm --version
|
||||||
|
- run: '. ./nvm.sh ; nvm install-latest-npm'
|
||||||
|
name: 'nvm install-latest-npm'
|
||||||
|
- run: npm --version
|
||||||
|
|
||||||
|
node:
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
name: 'nvm install-latest-npm'
|
||||||
|
needs: [nodes]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: true
|
72
.github/workflows/lint.yml
vendored
Normal file
72
.github/workflows/lint.yml
vendored
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
name: 'Tests: linting'
|
||||||
|
|
||||||
|
on: [pull_request, push]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
eclint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
github.com:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
nodejs.org:443
|
||||||
|
registry.npmjs.org:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ljharb/actions/node/install@main
|
||||||
|
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||||
|
with:
|
||||||
|
node-version: 'lts/*'
|
||||||
|
- run: npm run eclint
|
||||||
|
|
||||||
|
dockerfile_lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
ghcr.io:443
|
||||||
|
github.com:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
pkg-containers.githubusercontent.com:443
|
||||||
|
nodejs.org:443
|
||||||
|
registry.npmjs.org:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ljharb/actions/node/install@main
|
||||||
|
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||||
|
with:
|
||||||
|
node-version: 'lts/*'
|
||||||
|
- run: npm run dockerfile_lint
|
||||||
|
|
||||||
|
doctoc:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
github.com:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
nodejs.org:443
|
||||||
|
registry.npmjs.org:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ljharb/actions/node/install@main
|
||||||
|
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||||
|
with:
|
||||||
|
node-version: 'lts/*'
|
||||||
|
- run: npm run doctoc:check
|
||||||
|
|
||||||
|
test_naming:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
github.com:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: check tests filenames
|
||||||
|
run: ./rename_test.sh --check
|
104
.github/workflows/nvm-install-test.yml
vendored
Normal file
104
.github/workflows/nvm-install-test.yml
vendored
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
name: 'Tests: nvm install with set -e'
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
ref:
|
||||||
|
description: 'git ref to use'
|
||||||
|
required: false
|
||||||
|
default: 'HEAD'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
matrix:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.matrix.outputs.matrix }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- id: matrix
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.ref }}" ]; then
|
||||||
|
echo "matrix=\"[\"${{ github.event.inputs.ref }}\"]\"" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
TAGS="$((echo "HEAD" && git tag --sort=-v:refname --merged HEAD --format='%(refname:strip=2) %(creatordate:short)' | grep '^v' | while read tag date; do
|
||||||
|
if [ "$(uname)" == "Darwin" ]; then
|
||||||
|
timestamp=$(date -j -f "%Y-%m-%d" "$date" +%s)
|
||||||
|
threshold=$(date -j -v-4y +%s)
|
||||||
|
else
|
||||||
|
timestamp=$(date -d "$date" +%s)
|
||||||
|
threshold=$(date -d "4 years ago" +%s)
|
||||||
|
fi
|
||||||
|
if [ $timestamp -ge $threshold ]; then echo "$tag"; fi
|
||||||
|
done) | xargs)"
|
||||||
|
echo $TAGS
|
||||||
|
TAGS_JSON=$(printf "%s\n" $TAGS | jq -R . | jq -sc .)
|
||||||
|
echo "matrix=${TAGS_JSON}" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
test:
|
||||||
|
needs: [matrix]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: ${{ matrix.ref == 'v0.40.0' }} # https://github.com/nvm-sh/nvm/issues/3405
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
ref: ${{ fromJson(needs.matrix.outputs.matrix) }}
|
||||||
|
has-nvmrc:
|
||||||
|
- 'no nvmrc'
|
||||||
|
- 'nvmrc'
|
||||||
|
shell-level:
|
||||||
|
- 1 shlvl
|
||||||
|
- 2 shlvls
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: resolve HEAD to sha
|
||||||
|
run: |
|
||||||
|
if [ '${{ matrix.ref }}' = 'HEAD' ]; then
|
||||||
|
REF="$(git rev-parse HEAD)"
|
||||||
|
else
|
||||||
|
REF="${{ matrix.ref }}"
|
||||||
|
fi
|
||||||
|
echo "resolved ref: ${REF}"
|
||||||
|
echo "ref="$REF"" >> $GITHUB_ENV
|
||||||
|
- run: echo $- # which options are set
|
||||||
|
- run: echo node > .nvmrc
|
||||||
|
if: ${{ matrix.has-nvmrc == 'nvmrc' }}
|
||||||
|
- run: curl -I --compressed -v https://nodejs.org/dist/
|
||||||
|
- name: 'install nvm'
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
export NVM_INSTALL_VERSION="${ref}"
|
||||||
|
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${ref}/install.sh" | bash
|
||||||
|
- name: nvm --version
|
||||||
|
run: |
|
||||||
|
set +e
|
||||||
|
. $NVM_DIR/nvm.sh && nvm --version
|
||||||
|
- name: nvm install in 1 shell level, ${{ matrix.has-nvmrc }}
|
||||||
|
if: ${{ matrix.shell-level == '1 shlvl' }}
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
. $NVM_DIR/nvm.sh
|
||||||
|
echo nvm.sh sourced
|
||||||
|
nvm --version
|
||||||
|
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
|
||||||
|
nvm install
|
||||||
|
fi
|
||||||
|
- name: nvm install in 2 shell levels, ${{ matrix.has-nvmrc }}
|
||||||
|
if: ${{ matrix.shell-level == '2 shlvls' }}
|
||||||
|
run: |
|
||||||
|
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
|
||||||
|
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version && nvm install"
|
||||||
|
else
|
||||||
|
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version"
|
||||||
|
fi
|
||||||
|
|
||||||
|
finisher:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [test]
|
||||||
|
steps:
|
||||||
|
- run: true
|
15
.github/workflows/rebase.yml
vendored
15
.github/workflows/rebase.yml
vendored
@ -1,15 +1,26 @@
|
|||||||
name: Automatic Rebase
|
name: Automatic Rebase
|
||||||
|
|
||||||
on: [pull_request]
|
on: [pull_request_target]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
_:
|
_:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
name: "Automatic Rebase"
|
name: "Automatic Rebase"
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
api.github.com:443
|
||||||
|
github.com:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
- uses: ljharb/rebase@master
|
- uses: ljharb/rebase@master
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
38
.github/workflows/release.yml
vendored
Normal file
38
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
name: 'Tests: release process'
|
||||||
|
|
||||||
|
on: [pull_request, push]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
github.com:443
|
||||||
|
api.github.com:443
|
||||||
|
objects.githubusercontent.com:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
registry.npmjs.org:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-tags: true
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "14"
|
||||||
|
- run: npm install
|
||||||
|
- name: Configure git
|
||||||
|
run: |
|
||||||
|
git config user.name github-actions
|
||||||
|
git config user.email github-actions@github.com
|
||||||
|
git fetch --unshallow --tags -f || git fetch --tags -f
|
||||||
|
- name: Attempt `make release` process
|
||||||
|
run: echo proceed | make TAG=99.99.99 release
|
||||||
|
env:
|
||||||
|
GIT_EDITOR: "sed -i '1 s/^/99.99.99 make release test/'"
|
||||||
|
- name: Ensure tag is created
|
||||||
|
run: git tag | grep v99.99.99
|
24
.github/workflows/require-allow-edits.yml
vendored
Normal file
24
.github/workflows/require-allow-edits.yml
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
name: Require “Allow Edits”
|
||||||
|
|
||||||
|
on: [pull_request_target]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
_:
|
||||||
|
permissions:
|
||||||
|
pull-requests: read
|
||||||
|
name: "Require “Allow Edits”"
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
api.github.com:443
|
||||||
|
- uses: ljharb/require-allow-edits@main
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
56
.github/workflows/shellcheck.yml
vendored
Normal file
56
.github/workflows/shellcheck.yml
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
name: 'Tests: shellcheck'
|
||||||
|
|
||||||
|
on: [pull_request, push]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
shellcheck_matrix:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
shell:
|
||||||
|
- bash
|
||||||
|
- sh
|
||||||
|
- dash
|
||||||
|
- ksh
|
||||||
|
file:
|
||||||
|
- nvm.sh
|
||||||
|
include:
|
||||||
|
- shell: bash
|
||||||
|
file: install.sh # only supported on bash
|
||||||
|
- shell: bash
|
||||||
|
file: bash_completion # only needed in bash/zsh
|
||||||
|
- shell: bash
|
||||||
|
file: nvm-exec # only runs in bash
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
ghcr.io:443
|
||||||
|
github.com:443
|
||||||
|
pkg-containers.githubusercontent.com:443
|
||||||
|
formulae.brew.sh:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up Homebrew
|
||||||
|
uses: Homebrew/actions/setup-homebrew@master
|
||||||
|
- name: Install latest shellcheck
|
||||||
|
run: brew install shellcheck
|
||||||
|
env:
|
||||||
|
HOMEBREW_NO_ANALYTICS: 1
|
||||||
|
- run: which shellcheck
|
||||||
|
- run: shellcheck --version
|
||||||
|
- name: Run shellcheck on ${{ matrix.file }}
|
||||||
|
run: shellcheck -s ${{ matrix.shell }} ${{ matrix.file }}
|
||||||
|
|
||||||
|
shellcheck:
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
needs: [shellcheck_matrix]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: true
|
80
.github/workflows/tests.yml
vendored
Normal file
80
.github/workflows/tests.yml
vendored
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
name: urchin tests
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
name: "tests"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: 'script -q -e -c "${{ matrix.shell }} {0}"'
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
exclude:
|
||||||
|
- shell: sh
|
||||||
|
suite: install_script
|
||||||
|
- shell: dash
|
||||||
|
suite: install_script
|
||||||
|
- shell: zsh
|
||||||
|
suite: install_script
|
||||||
|
- shell: ksh
|
||||||
|
suite: install_script
|
||||||
|
suite:
|
||||||
|
- install_script
|
||||||
|
- sourcing
|
||||||
|
- slow
|
||||||
|
- installation_iojs
|
||||||
|
shell:
|
||||||
|
- sh
|
||||||
|
- bash
|
||||||
|
- dash
|
||||||
|
- zsh
|
||||||
|
# - ksh
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
github.com:443
|
||||||
|
registry.npmjs.org:443
|
||||||
|
raw.githubusercontent.com:443
|
||||||
|
nodejs.org:443
|
||||||
|
iojs.org:443
|
||||||
|
azure.archive.ubuntu.com:80
|
||||||
|
packages.microsoft.com:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: sudo apt-get update; sudo apt-get install ${{ matrix.shell }}
|
||||||
|
if: matrix.shell == 'zsh' || matrix.shell == 'ksh'
|
||||||
|
# zsh (https://github.com/actions/runner-images/issues/264) and ksh are not in the ubuntu image
|
||||||
|
shell: bash
|
||||||
|
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
|
||||||
|
- run: curl --version
|
||||||
|
- run: wget --version
|
||||||
|
- uses: ljharb/actions/node/install@main
|
||||||
|
name: 'npm install && version checks'
|
||||||
|
with:
|
||||||
|
node-version: 'lts/*'
|
||||||
|
skip-ls-check: true
|
||||||
|
- run: npm ls urchin
|
||||||
|
- run: npx which urchin
|
||||||
|
- run: env
|
||||||
|
- run: make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }}
|
||||||
|
|
||||||
|
nvm:
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
name: 'all test suites, all shells'
|
||||||
|
needs: [tests]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: true
|
18
.github/workflows/toc.yml
vendored
18
.github/workflows/toc.yml
vendored
@ -2,14 +2,26 @@ name: update readme TOC
|
|||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
_:
|
_:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
name: "update readme TOC"
|
name: "update readme TOC"
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Harden Runner
|
||||||
|
uses: step-security/harden-runner@v2
|
||||||
|
with:
|
||||||
|
allowed-endpoints:
|
||||||
|
github.com:443
|
||||||
|
registry.npmjs.org:443
|
||||||
|
api.github.com:443
|
||||||
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# https://github.com/actions/checkout/issues/217#issue-599945005
|
# https://github.com/actions/checkout/issues/217#issue-599945005
|
||||||
# pulls all commits (needed for lerna / semantic release to correctly version)
|
# pulls all commits (needed for lerna / semantic release to correctly version)
|
||||||
@ -17,9 +29,9 @@ jobs:
|
|||||||
|
|
||||||
# pulls all tags (needed for lerna / semantic release to correctly version)
|
# pulls all tags (needed for lerna / semantic release to correctly version)
|
||||||
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
||||||
- uses: actions/setup-node@v1
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '12.x'
|
node-version: 'lts/*'
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run doctoc
|
- run: npm run doctoc
|
||||||
- name: commit changes
|
- name: commit changes
|
||||||
|
193
.github/workflows/windows-npm.yml
vendored
Normal file
193
.github/workflows/windows-npm.yml
vendored
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
name: 'Tests on Windows: `nvm install`'
|
||||||
|
|
||||||
|
on: [pull_request, push]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
env:
|
||||||
|
NVM_INSTALL_GITHUB_REPO: ${{ github.repository }}
|
||||||
|
NVM_INSTALL_VERSION: ${{ github.sha }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
msys_fail_install:
|
||||||
|
# Default installation does not work due to npm_config_prefix set to C:\npm\prefix
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
name: 'MSYS fail prefix nvm install'
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: Retrieve nvm
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
! nvm install --lts
|
||||||
|
|
||||||
|
msys_matrix:
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
name: 'MSYS nvm install'
|
||||||
|
runs-on: windows-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
npm-node-version:
|
||||||
|
- '--lts'
|
||||||
|
- '--default 12'
|
||||||
|
- '--no-progress 10'
|
||||||
|
steps:
|
||||||
|
- name: Retrieve nvm
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
unset npm_config_prefix
|
||||||
|
if [ "${{ matrix.npm-node-version }}" = "--lts" ]; then
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||||
|
else
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
|
||||||
|
fi
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
nvm install ${{ matrix.npm-node-version }}
|
||||||
|
|
||||||
|
cygwin_matrix:
|
||||||
|
continue-on-error: true
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
name: 'Cygwin nvm install'
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: Install Cygwin
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
export SITE='https://mirror.clarkson.edu/cygwin/' # see https://archlinux.org/mirrors/clarkson.edu/1603/ for uptime status
|
||||||
|
export SITE='https://mirrors.kernel.org/sourceware/cygwin/'
|
||||||
|
export LOCALDIR="$(pwd)"
|
||||||
|
export ROOTDIR="$USERPROFILE\\cygwin"
|
||||||
|
export PACKAGES='bash,git,curl'
|
||||||
|
|
||||||
|
curl -fsSLo setup-x86_64.exe 'https://cygwin.com/setup-x86_64.exe'
|
||||||
|
./setup-x86_64.exe --disable-buggy-antivirus -q -s "$SITE" -l "$LOCALDIR" -R "$ROOTDIR" -P "$PACKAGES"
|
||||||
|
|
||||||
|
cat >~/setup.sh <<EOM
|
||||||
|
unset npm_config_prefix
|
||||||
|
export NVM_INSTALL_GITHUB_REPO="$NVM_INSTALL_GITHUB_REPO"
|
||||||
|
export NVM_INSTALL_VERSION="$NVM_INSTALL_VERSION"
|
||||||
|
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
nvm install --lts
|
||||||
|
|
||||||
|
nvm deactivate
|
||||||
|
rm -rf "$HOME/.nvm/nvm.sh"
|
||||||
|
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
nvm install 9
|
||||||
|
EOM
|
||||||
|
- name: Retrieve nvm
|
||||||
|
shell: cmd
|
||||||
|
run: |
|
||||||
|
cd %USERPROFILE%\cygwin\bin
|
||||||
|
bash.exe "%USERPROFILE%\setup.sh"
|
||||||
|
|
||||||
|
wsl_matrix:
|
||||||
|
continue-on-error: true
|
||||||
|
name: 'WSL nvm install'
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: wsl-bash {0}
|
||||||
|
runs-on: windows-latest
|
||||||
|
env:
|
||||||
|
WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
wsl-distrib:
|
||||||
|
- Debian
|
||||||
|
# - Alpine # fails
|
||||||
|
- Ubuntu-20.04
|
||||||
|
- Ubuntu-18.04
|
||||||
|
npm-node-version:
|
||||||
|
- '--lts'
|
||||||
|
- '21'
|
||||||
|
- '18'
|
||||||
|
- '16'
|
||||||
|
- '14'
|
||||||
|
- '12'
|
||||||
|
- '10'
|
||||||
|
exclude:
|
||||||
|
- wsl-distrib: Ubuntu-18.04
|
||||||
|
npm-node-version: '--lts'
|
||||||
|
- wsl-distrib: Ubuntu-18.04
|
||||||
|
npm-node-version: '21'
|
||||||
|
- wsl-distrib: Ubuntu-18.04
|
||||||
|
npm-node-version: '18'
|
||||||
|
method:
|
||||||
|
- ''
|
||||||
|
- 'script'
|
||||||
|
steps:
|
||||||
|
- uses: Vampire/setup-wsl@v3
|
||||||
|
with:
|
||||||
|
distribution: ${{ matrix.wsl-distrib }}
|
||||||
|
additional-packages: bash git curl ca-certificates wget
|
||||||
|
- name: Retrieve nvm on WSL
|
||||||
|
run: |
|
||||||
|
if [ -z "${{ matrix.method }}" ]; then
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||||
|
else
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD="${{matrix.method}}" bash
|
||||||
|
fi
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
nvm install ${{ matrix.npm-node-version }}
|
||||||
|
node -v
|
||||||
|
|
||||||
|
wsl_matrix_unofficial:
|
||||||
|
continue-on-error: true
|
||||||
|
name: 'WSL nvm install'
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: wsl-bash {0}
|
||||||
|
runs-on: windows-latest
|
||||||
|
env:
|
||||||
|
WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p
|
||||||
|
NVM_NODEJS_ORG_MIRROR: https://unofficial-builds.nodejs.org/download/release
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
wsl-distrib:
|
||||||
|
- Alpine
|
||||||
|
npm-node-version:
|
||||||
|
- '--lts'
|
||||||
|
- '21'
|
||||||
|
- '18'
|
||||||
|
- '16'
|
||||||
|
- '14'
|
||||||
|
- '12'
|
||||||
|
- '11'
|
||||||
|
- '10'
|
||||||
|
method:
|
||||||
|
- ''
|
||||||
|
- 'script'
|
||||||
|
steps:
|
||||||
|
- uses: Vampire/setup-wsl@v3
|
||||||
|
with:
|
||||||
|
distribution: ${{ matrix.wsl-distrib }}
|
||||||
|
additional-packages: bash git curl ca-certificates wget
|
||||||
|
- name: Retrieve nvm on WSL
|
||||||
|
run: |
|
||||||
|
if [ -z "${{ matrix.method }}" ]; then
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||||
|
else
|
||||||
|
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD="${{matrix.method}}" bash
|
||||||
|
fi
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
NVM_NODEJS_ORG_MIRROR=${{ env.NVM_NODEJS_ORG_MIRROR }} nvm install ${{ matrix.npm-node-version }}
|
||||||
|
|
||||||
|
nvm_windows:
|
||||||
|
name: 'tests, on windows'
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
|
needs: [wsl_matrix, wsl_matrix_unofficial, cygwin_matrix, msys_matrix, msys_fail_install]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: true
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,6 +9,7 @@ test/bak
|
|||||||
.urchin.log
|
.urchin.log
|
||||||
.urchin_stdout
|
.urchin_stdout
|
||||||
test/**/test_output
|
test/**/test_output
|
||||||
|
test/**/.nvmrc
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
@ -21,3 +22,5 @@ current
|
|||||||
npm-shrinkwrap.json
|
npm-shrinkwrap.json
|
||||||
package-lock.json
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
|
||||||
|
target/
|
||||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "test/fixtures/nvmrc"]
|
||||||
|
path = test/fixtures/nvmrc
|
||||||
|
url = git@github.com:nvm-sh/nvmrc.git
|
113
.travis.yml
113
.travis.yml
@ -1,6 +1,5 @@
|
|||||||
language: generic
|
language: generic
|
||||||
dist: xenial
|
dist: focal
|
||||||
sudo: required
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
@ -9,31 +8,72 @@ addons:
|
|||||||
# - gcc-4.8
|
# - gcc-4.8
|
||||||
# - g++-4.8
|
# - g++-4.8
|
||||||
|
|
||||||
|
# https://gist.github.com/iedemam/9830045
|
||||||
|
git:
|
||||||
|
submodules: false
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
ccache: true
|
ccache: true
|
||||||
directories:
|
directories:
|
||||||
- $HOME/.npm
|
|
||||||
- $TRAVIS_BUILD_DIR/.cache
|
- $TRAVIS_BUILD_DIR/.cache
|
||||||
- $TRAVIS_BUILD_DIR/node_modules
|
- $TRAVIS_BUILD_DIR/node_modules
|
||||||
before_install:
|
before_install:
|
||||||
|
- sudo sed -i 's/mozilla\/DST_Root_CA_X3.crt/!mozilla\/DST_Root_CA_X3.crt/g' /etc/ca-certificates.conf
|
||||||
|
- sudo update-ca-certificates -f
|
||||||
|
|
||||||
|
# https://gist.github.com/iedemam/9830045
|
||||||
|
- sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
|
||||||
|
- git submodule update --init --recursive
|
||||||
|
|
||||||
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
|
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
|
||||||
- curl --version
|
- curl --version
|
||||||
- wget --version
|
- wget --version
|
||||||
- shellcheck --version
|
- bash --version | head
|
||||||
|
- zsh --version
|
||||||
|
- dpkg -s dash | grep ^Version | awk '{print $2}'
|
||||||
|
# install python
|
||||||
|
- pyenv local 2.7.18 || pyenv install 2.7.18
|
||||||
|
- pyenv local 2.7.18 || echo 'pyenv failed'
|
||||||
|
- python -V
|
||||||
install:
|
install:
|
||||||
- if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi
|
- if [ -z "${SHELLCHECK-}" ]; then nvm install 16 && nvm unalias default && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi
|
||||||
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
|
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
|
||||||
script:
|
script:
|
||||||
- if [ -n "${MAKE_RELEASE-}" ]; then export GIT_EDITOR="sed -i '1 s/^/99.99.99 make release test/'" && git fetch --unshallow --tags && echo proceed | make TAG=99.99.99 release ; fi
|
- if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ] || [ "${TEST_SUITE}" = 'xenial' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi
|
||||||
- if [ -n "${DOCTOCCHECK-}" ]; then cp README.md README.md.orig && npm run doctoc && diff -q README.md README.md.orig ; fi
|
|
||||||
- if [ -n "${ECLINT-}" ]; then npm run eclint ; fi
|
|
||||||
- if [ -n "${DOCKERFILE_LINT-}" ]; then npm run dockerfile_lint ; fi
|
|
||||||
- if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash nvm.sh && shellcheck -s sh nvm.sh && shellcheck -s dash nvm.sh && shellcheck -s ksh nvm.sh ; fi
|
|
||||||
- if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash install.sh bash_completion nvm-exec ; fi
|
|
||||||
- if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi
|
|
||||||
before_cache:
|
before_cache:
|
||||||
- if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi
|
- if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi
|
||||||
- if [ -n "${NODE-}" ]; then . nvm.sh && set -ex && nvm install --latest-npm "${NODE}" && npm --version; fi
|
jobs:
|
||||||
|
include:
|
||||||
|
- env: SHELL=bash TEST_SUITE=installation_node
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=sh TEST_SUITE=installation_node
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=dash TEST_SUITE=installation_node
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=dash TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=zsh TEST_SUITE=installation_node
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
|
dist: xenial
|
||||||
|
#- env: SHELL=ksh TEST_SUITE=installation_node
|
||||||
|
# dist: xenial
|
||||||
|
#- env: SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
|
# dist: xenial
|
||||||
|
- env: SHELL=bash TEST_SUITE=xenial
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=sh TEST_SUITE=xenial
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=dash TEST_SUITE=xenial
|
||||||
|
dist: xenial
|
||||||
|
- env: SHELL=zsh TEST_SUITE=xenial
|
||||||
|
dist: xenial
|
||||||
|
#- env: SHELL=ksh TEST_SUITE=xenial
|
||||||
|
# dist: xenial
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- CXX=g++
|
- CXX=g++
|
||||||
@ -42,56 +82,13 @@ env:
|
|||||||
- PATH="/usr/lib/ccache/:$PATH"
|
- PATH="/usr/lib/ccache/:$PATH"
|
||||||
- NVM_DIR="${TRAVIS_BUILD_DIR}"
|
- NVM_DIR="${TRAVIS_BUILD_DIR}"
|
||||||
matrix:
|
matrix:
|
||||||
- MAKE_RELEASE=true
|
|
||||||
- DOCTOCCHECK=true
|
|
||||||
- SHELLCHECK=true
|
|
||||||
- ECLINT=true
|
|
||||||
- DOCKERFILE_LINT=true
|
|
||||||
- SHELL=bash TEST_SUITE=install_script
|
|
||||||
- SHELL=sh TEST_SUITE=fast
|
- SHELL=sh TEST_SUITE=fast
|
||||||
- SHELL=dash TEST_SUITE=fast
|
- SHELL=dash TEST_SUITE=fast
|
||||||
- SHELL=bash TEST_SUITE=fast
|
- SHELL=bash TEST_SUITE=fast
|
||||||
- SHELL=zsh TEST_SUITE=fast
|
- SHELL=zsh TEST_SUITE=fast
|
||||||
# - SHELL=ksh TEST_SUITE=fast
|
# - SHELL=ksh TEST_SUITE=fast
|
||||||
- SHELL=sh TEST_SUITE=sourcing
|
|
||||||
- SHELL=dash TEST_SUITE=sourcing
|
|
||||||
- SHELL=bash TEST_SUITE=sourcing
|
|
||||||
- SHELL=zsh TEST_SUITE=sourcing
|
|
||||||
# - SHELL=ksh TEST_SUITE=sourcing
|
|
||||||
- SHELL=sh TEST_SUITE=slow
|
|
||||||
- SHELL=dash TEST_SUITE=slow
|
|
||||||
- SHELL=bash TEST_SUITE=slow
|
|
||||||
- SHELL=zsh TEST_SUITE=slow
|
|
||||||
# - SHELL=ksh TEST_SUITE=slow
|
|
||||||
- SHELL=sh TEST_SUITE=installation_node
|
|
||||||
- SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
|
|
||||||
- SHELL=dash TEST_SUITE=installation_node
|
|
||||||
- SHELL=dash TEST_SUITE=installation_node WITHOUT_CURL=1
|
|
||||||
- SHELL=bash TEST_SUITE=installation_node
|
|
||||||
- SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
|
|
||||||
- SHELL=zsh TEST_SUITE=installation_node
|
|
||||||
- SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
|
|
||||||
# - SHELL=ksh TEST_SUITE=installation_node
|
|
||||||
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
|
|
||||||
- SHELL=sh TEST_SUITE=installation_iojs
|
|
||||||
- SHELL=sh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
- SHELL=sh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
- SHELL=dash TEST_SUITE=installation_iojs
|
|
||||||
- SHELL=dash TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
- SHELL=dash TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
- SHELL=bash TEST_SUITE=installation_iojs
|
|
||||||
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
- SHELL=zsh TEST_SUITE=installation_iojs
|
|
||||||
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
# - SHELL=ksh TEST_SUITE=installation_iojs
|
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
|
||||||
- NODE=10 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=9 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=8 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=7 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=6 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=5 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=5.9 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=4 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=4.6 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=4.5 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=4.4 TEST="nvm install-latest-npm"
|
|
||||||
- NODE=2 TEST="nvm install-latest-npm"
|
|
||||||
|
125
CODE_OF_CONDUCT.md
Normal file
125
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
# Code of Conduct
|
||||||
|
|
||||||
|
`nvm`, as a member project of the OpenJS Foundation, uses [Contributor Covenant v2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) as their code of conduct. The full text is included [below](#contributor-covenant-code-of-conduct) in English, and translations are available from the Contributor Covenant organisation:
|
||||||
|
|
||||||
|
- [contributor-covenant.org/translations](https://www.contributor-covenant.org/translations)
|
||||||
|
- [github.com/ContributorCovenant](https://github.com/ContributorCovenant/contributor_covenant/tree/release/content/version/2/1)
|
||||||
|
|
||||||
|
Refer to the sections on reporting and escalation in this document for the specific emails that can be used to report and escalate issues.
|
||||||
|
|
||||||
|
## Reporting
|
||||||
|
|
||||||
|
### Project Spaces
|
||||||
|
|
||||||
|
For reporting issues in spaces related to `nvm` please use the email `ljharb@gmail.com`. `nvm` handles CoC issues related to the spaces that it maintains. Projects maintainers commit to:
|
||||||
|
|
||||||
|
- maintain the confidentiality with regard to the reporter of an incident
|
||||||
|
- to participate in the path for escalation as outlined in the section on Escalation when required.
|
||||||
|
|
||||||
|
### Foundation Spaces
|
||||||
|
|
||||||
|
For reporting issues in spaces managed by the OpenJS Foundation, for example, repositories within the OpenJS organization, use the email `report@lists.openjsf.org`.
|
||||||
|
The Cross Project Council (CPC) is responsible for managing these reports and commits to:
|
||||||
|
|
||||||
|
- maintain the confidentiality with regard to the reporter of an incident
|
||||||
|
- to participate in the path for escalation as outlined in the section on Escalation when required.
|
||||||
|
|
||||||
|
## Escalation
|
||||||
|
|
||||||
|
The OpenJS Foundation maintains a Code of Conduct Panel (CoCP).
|
||||||
|
This is a foundation-wide team established to manage escalation when a reporter believes that a report to a member project or the CPC has not been properly handled.
|
||||||
|
In order to escalate to the CoCP send an email to `coc-escalation@lists.openjsf.org`.
|
||||||
|
|
||||||
|
For more information, refer to the full [Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/blob/HEAD/CODE_OF_CONDUCT.md).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [@ljharb](ljharb@gmail.com).
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at
|
||||||
|
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by
|
||||||
|
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
|
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
||||||
|
[https://www.contributor-covenant.org/translations][translations].
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||||
|
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||||
|
[FAQ]: https://www.contributor-covenant.org/faq
|
||||||
|
[translations]: https://www.contributor-covenant.org/translations
|
116
CONTRIBUTING.md
116
CONTRIBUTING.md
@ -1,21 +1,123 @@
|
|||||||
Thanks for contributing to `nvm`!
|
# Contributing
|
||||||
|
|
||||||
|
:+1::tada: First off, thanks for taking the time to contribute to `nvm`! :tada::+1:
|
||||||
|
|
||||||
We love pull requests and issues, they're our favorite.
|
We love pull requests and issues, they're our favorite.
|
||||||
|
|
||||||
|
The following is a set of guidelines for contributing to `nvm` managed by [@LJHarb](https://github.com/ljharb), which is hosted on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
|
||||||
|
|
||||||
However, before submitting, please review the following:
|
However, before submitting, please review the following:
|
||||||
|
|
||||||
For bug reports:
|
# How Can I Contribute?
|
||||||
|
|
||||||
- Please make sure the bug is reproducible, and give us the steps to reproduce it, so that we can dig into the problem.
|
There are lots of ways to get involved. Here are some suggestions of things we'd love some help with.
|
||||||
- Please give us as much detail as possible about your environment, so we can more easily confirm the problem.
|
|
||||||
|
|
||||||
For pull requests:
|
## Resolving existing issues
|
||||||
|
|
||||||
|
You can consider helping out with issues already requiring attention - look for a "help wanted" label.
|
||||||
|
|
||||||
|
### How Do I Submit a (Good) Bug Report? :bug:
|
||||||
|
|
||||||
|
Explain the problem and include additional details to help maintainers reproduce the problem:
|
||||||
|
|
||||||
|
* **Use a clear and descriptive title** for the issue to identify the problem.
|
||||||
|
|
||||||
|
* **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining which command exactly you used in the terminal. When listing steps, **don't just say what you did, but explain how you did it**. For example, if you moved the cursor to the end of a line, explain if you used the mouse, or a keyboard shortcut or a command, and if so which one?
|
||||||
|
* **Provide specific examples to demonstrate the steps**. Include links to files or Github projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines).
|
||||||
|
* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
|
||||||
|
* **Explain which behavior you expected to see instead and why.**
|
||||||
|
* **Provide as much context as possible** in order to help others verify and ultimately fix the issue. This includes giving us as much details as possible about your environment, so we can more easily confirm the problem.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
We are happy to welcome contributions from anyone willing to improve documentation by adding missing information or making it more consistent and coherent.
|
||||||
|
|
||||||
|
# Dev Environment
|
||||||
|
|
||||||
|
Please refer to the [README](README.md) for complete instructions how to install, update, as well as troubleshoot `nvm` in your environment depending on your Operating System.
|
||||||
|
|
||||||
|
# Style Guide / Coding conventions
|
||||||
|
|
||||||
|
### Pull requests
|
||||||
|
|
||||||
|
#### Before creating a pull request
|
||||||
|
|
||||||
- Please include tests. Changes with tests will be merged very quickly.
|
- Please include tests. Changes with tests will be merged very quickly.
|
||||||
- Please manually confirm that your changes work in `bash`, `sh`/`dash`, `ksh`, and `zsh`. Fast tests do run in these shells, but it's nice to manually verify also.
|
- Please manually confirm that your changes work in `bash`, `sh`/`dash`, `ksh`, and `zsh`. Fast tests do run in these shells, but it's nice to manually verify also.
|
||||||
- Please maintain consistent whitespace - 2-space indentation, trailing newlines in all files, etc.
|
- Please maintain consistent whitespace - 2-space indentation, trailing newlines in all files, etc.
|
||||||
- Any time you make a change to your PR, please rebase freshly on top of master. Nobody likes merge commits.
|
- Any time you make a change to your PR, please rebase freshly on top of the default branch. Nobody likes merge commits.
|
||||||
|
|
||||||
Even if you don't have all of these items covered, please still feel free to submit a PR/issue! Someone else may be inspired and volunteer to complete it for you.
|
Even if you don't have all of these items covered, please still feel free to submit a PR/issue! Someone else may be inspired and volunteer to complete it for you.
|
||||||
|
|
||||||
Thanks again!
|
#### How to create a pull request
|
||||||
|
|
||||||
|
Create a new branch
|
||||||
|
|
||||||
|
```
|
||||||
|
git checkout -b issue1234
|
||||||
|
```
|
||||||
|
|
||||||
|
Commit the changes to your branch, including a coherent commit message that follows our [standards](#commit-messages)
|
||||||
|
|
||||||
|
```
|
||||||
|
git commit -a
|
||||||
|
```
|
||||||
|
|
||||||
|
Before sending the pull request, make sure your code is running on the latest available code by rebasing onto the upstream source
|
||||||
|
|
||||||
|
```
|
||||||
|
git fetch upstream
|
||||||
|
git rebase upstream/main
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify your changes
|
||||||
|
|
||||||
|
```
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
Push your changes
|
||||||
|
|
||||||
|
```
|
||||||
|
git push origin issue1234
|
||||||
|
```
|
||||||
|
|
||||||
|
Send the [pull request](https://docs.github.com/en/pull-requests), make requested changes, and get merged.
|
||||||
|
|
||||||
|
### Commit Messages
|
||||||
|
|
||||||
|
* Limit the first line of the commit message (message summary) to 72 characters or less.
|
||||||
|
* Use the present tense ("Add feature" not "Added feature") and imperative mood ("Move cursor to..." not "Moves cursor to...") when providing a description of what you did.
|
||||||
|
* If your PR addresses an issue, reference it in the body of the commit message.
|
||||||
|
* See the rest of the conventions [here](https://gist.github.com/ljharb/772b0334387a4bee89af24183114b3c7)
|
||||||
|
|
||||||
|
#### Commit message example
|
||||||
|
|
||||||
|
```
|
||||||
|
[Tag]: Short description of what you did
|
||||||
|
|
||||||
|
Longer description here if necessary
|
||||||
|
|
||||||
|
Fixes #1234
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** Add co-authors to your commit message for commits with multiple authors
|
||||||
|
|
||||||
|
```
|
||||||
|
Co-authored-by: Name Here <email@here>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# Code of Conduct
|
||||||
|
[Code of Conduct](https://github.com/nvm-sh/nvm/blob/HEAD/CODE_OF_CONDUCT.md)
|
||||||
|
|
||||||
|
# Where can I ask for help?
|
||||||
|
If you have any questions, please contact [@LJHarb](mailto:ljharb@gmail.com).
|
||||||
|
|
||||||
|
# Developer's Certificate of Origin 1.1
|
||||||
|
|
||||||
|
By making a contribution to this project, I certify that:
|
||||||
|
- The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
|
||||||
|
- The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
|
||||||
|
- The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
|
||||||
|
- I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
|
||||||
|
33
Dockerfile
33
Dockerfile
@ -6,9 +6,7 @@
|
|||||||
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
|
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
|
||||||
# build this image, it depends on your hardware.
|
# build this image, it depends on your hardware.
|
||||||
|
|
||||||
# Use Ubuntu Trusty Tahr as base image as we're using on Travis CI
|
FROM ubuntu:22.04
|
||||||
# I also tested with Ubuntu 16.04, should be good with it!
|
|
||||||
FROM ubuntu:16.04
|
|
||||||
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
|
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
|
||||||
LABEL name="nvm-dev-env"
|
LABEL name="nvm-dev-env"
|
||||||
LABEL version="latest"
|
LABEL version="latest"
|
||||||
@ -26,9 +24,6 @@ ENV SHELLCHECK_VERSION=0.7.0
|
|||||||
# ref: https://launchpad.net/ubuntu/+archivemirrors
|
# ref: https://launchpad.net/ubuntu/+archivemirrors
|
||||||
ENV UBUNTU_APT_SITE ubuntu.cs.utah.edu
|
ENV UBUNTU_APT_SITE ubuntu.cs.utah.edu
|
||||||
|
|
||||||
# Disable src package source
|
|
||||||
RUN sed -i 's/^deb-src\ /\#deb-src\ /g' /etc/apt/sources.list
|
|
||||||
|
|
||||||
# Replace origin apt package site with the mirror site
|
# Replace origin apt package site with the mirror site
|
||||||
RUN sed -E -i "s/([a-z]+.)?archive.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
|
RUN sed -E -i "s/([a-z]+.)?archive.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
|
||||||
RUN sed -i "s/security.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
|
RUN sed -i "s/security.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
|
||||||
@ -56,17 +51,15 @@ RUN apt update && \
|
|||||||
curl \
|
curl \
|
||||||
git \
|
git \
|
||||||
jq \
|
jq \
|
||||||
realpath \
|
|
||||||
zsh \
|
zsh \
|
||||||
ksh \
|
ksh \
|
||||||
gcc-4.8 \
|
gcc \
|
||||||
g++-4.8 \
|
g++ \
|
||||||
xz-utils \
|
xz-utils \
|
||||||
build-essential \
|
build-essential \
|
||||||
bash-completion && \
|
bash-completion && \
|
||||||
apt-get clean
|
apt-get clean
|
||||||
|
|
||||||
# ShellCheck with Ubuntu 14.04 container workaround
|
|
||||||
RUN wget https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK_VERSION/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \
|
RUN wget https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK_VERSION/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \
|
||||||
tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \
|
tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \
|
||||||
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
|
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
|
||||||
@ -90,7 +83,7 @@ RUN useradd -ms /bin/bash nvm
|
|||||||
|
|
||||||
# Copy and set permission for nvm directory
|
# Copy and set permission for nvm directory
|
||||||
COPY . /home/nvm/.nvm/
|
COPY . /home/nvm/.nvm/
|
||||||
RUN chown nvm:nvm -R "home/nvm/.nvm"
|
RUN chown nvm:nvm -R "/home/nvm/.nvm"
|
||||||
|
|
||||||
# Set sudoer for "nvm"
|
# Set sudoer for "nvm"
|
||||||
RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
||||||
@ -98,16 +91,20 @@ RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
|||||||
# Switch to user "nvm" from now
|
# Switch to user "nvm" from now
|
||||||
USER nvm
|
USER nvm
|
||||||
|
|
||||||
|
# Create a script file sourced by both interactive and non-interactive bash shells
|
||||||
|
ENV BASH_ENV /home/nvm/.bash_env
|
||||||
|
RUN touch "$BASH_ENV"
|
||||||
|
RUN echo '. "$BASH_ENV"' >> "$HOME/.bashrc"
|
||||||
|
|
||||||
# nvm
|
# nvm
|
||||||
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$HOME/.bashrc"
|
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$BASH_ENV"
|
||||||
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$HOME/.bashrc"
|
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$BASH_ENV"
|
||||||
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$HOME/.bashrc"
|
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$BASH_ENV"
|
||||||
|
|
||||||
# nodejs and tools
|
# nodejs and tools
|
||||||
RUN bash -c 'source $HOME/.nvm/nvm.sh && \
|
RUN nvm install node
|
||||||
nvm install node && \
|
RUN npm install -g doctoc urchin eclint dockerfile_lint
|
||||||
npm install -g doctoc urchin eclint dockerfile_lint && \
|
RUN npm install --prefix "$HOME/.nvm/"
|
||||||
npm install --prefix "$HOME/.nvm/"'
|
|
||||||
|
|
||||||
# Set WORKDIR to nvm directory
|
# Set WORKDIR to nvm directory
|
||||||
WORKDIR /home/nvm/.nvm
|
WORKDIR /home/nvm/.nvm
|
||||||
|
10
GOVERNANCE.md
Normal file
10
GOVERNANCE.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# `nvm` Project Governance
|
||||||
|
|
||||||
|
## Maintainers
|
||||||
|
- [@ljharb](https://github.com/ljharb)
|
||||||
|
|
||||||
|
Maintainers are responsible for issue/PR triage, feature additions, maintenance, bugfixes, security fixes, releases, promoting existing contributors to maintainers, managing repo and CI configuration, etc.
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
Anyone who contributes code or content or time, via issues or pull requests or otherwise. Contributors do not have any additional permissions on the project.
|
12
Makefile
12
Makefile
@ -40,10 +40,14 @@ list:
|
|||||||
# Note that preexisting NVM_* variables are unset to avoid interfering with tests, except when running the Travis tests (where NVM_DIR must be passed in and the env. is assumed to be pristine).
|
# Note that preexisting NVM_* variables are unset to avoid interfering with tests, except when running the Travis tests (where NVM_DIR must be passed in and the env. is assumed to be pristine).
|
||||||
.PHONY: $(SHELL_TARGETS)
|
.PHONY: $(SHELL_TARGETS)
|
||||||
$(SHELL_TARGETS):
|
$(SHELL_TARGETS):
|
||||||
@shell='$@'; shell=$${shell##*-}; which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
|
@shell='$@'; shell=$${shell##*-}; \
|
||||||
|
which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
|
||||||
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
|
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
|
||||||
[ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
|
[ -z "$$TRAVIS_BUILD_DIR" ] && [ -z "$$GITHUB_ACTIONS" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
|
||||||
for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done
|
for suite in $(TEST_SUITE); do \
|
||||||
|
echo "Running test suite: $$suite"; \
|
||||||
|
$(URCHIN) -f -s $$shell test/$$suite || exit; \
|
||||||
|
done
|
||||||
|
|
||||||
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
|
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
@ -80,6 +84,6 @@ release: _ensure-tag _ensure-clean _ensure-current-version
|
|||||||
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
|
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
|
||||||
fi; \
|
fi; \
|
||||||
printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \
|
printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \
|
||||||
replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \
|
replace "$$old_ver" "$$new_ver" $(VERSIONED_FILES) && \
|
||||||
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
|
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
|
||||||
git tag -a "v$$new_ver"
|
git tag -a "v$$new_ver"
|
||||||
|
49
PROJECT_CHARTER.md
Normal file
49
PROJECT_CHARTER.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# `nvm` Charter
|
||||||
|
|
||||||
|
nvm is a version manager for Node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and Windows WSL.
|
||||||
|
|
||||||
|
## Section 0: Guiding Principles
|
||||||
|
|
||||||
|
The `nvm` project is part of the [OpenJS Foundation][openjs foundation], which operates transparently, openly, collaboratively, and ethically. Project proposals, timelines, and status must not merely be open, but also easily visible to outsiders.
|
||||||
|
|
||||||
|
## Section 1: Scope
|
||||||
|
|
||||||
|
`nvm` is a node version manager, focused on making it easy to install and manage multiple Node.js versions. Any features related to managing the installation and removal of Node.js on any node-supported platform are potentially in scope.
|
||||||
|
|
||||||
|
## Section 2: Relationship with OpenJS Foundation CPC.
|
||||||
|
|
||||||
|
Technical leadership for the projects within the [OpenJS Foundation][openjs foundation] is delegated to the projects through their project charters by the [OpenJS Foundation Cross-Project Council](https://openjsf.org/about/governance/) (CPC). In the case of the `nvm` project, it is delegated to the [`nvm` Maintainers](README.md#maintainers) (the “Maintainers”). The OpenJS Foundation's business leadership is the Board of Directors (the “Board”).
|
||||||
|
|
||||||
|
This `nvm` Charter reflects a carefully constructed balanced role for the Maintainers and the CPC in the governance of the OpenJS Foundation. The charter amendment process is for the Maintainers to propose changes using simple majority of the full Maintainers, the proposed changes being subject to review and approval by the CPC. The CPC may additionally make amendments to the project charter at any time, though the CPC will not interfere with day-to-day discussions, votes or meetings of the Maintainers.
|
||||||
|
|
||||||
|
### 2.1 Other Formal Project Relationships
|
||||||
|
|
||||||
|
Section Intentionally Left Blank
|
||||||
|
|
||||||
|
## Section 3: `nvm`'s Maintainers Governing Body
|
||||||
|
|
||||||
|
`nvm` is governed by its [maintainers](README.md#maintainers).
|
||||||
|
|
||||||
|
## Section 4: Roles & Responsibilities
|
||||||
|
|
||||||
|
The roles and responsibilities of `nvm`'s Maintainers are described in [GOVERNANCE.md](./GOVERNANCE.md).
|
||||||
|
|
||||||
|
### Section 4.1 Project Operations & Management
|
||||||
|
|
||||||
|
Section Intentionally Left Blank
|
||||||
|
|
||||||
|
### Section 4.2: Decision-making, Voting, and/or Elections
|
||||||
|
|
||||||
|
Section Intentionally Left Blank
|
||||||
|
|
||||||
|
### Section 4.3: Other Project Roles
|
||||||
|
|
||||||
|
Section Intentionally Left Blank
|
||||||
|
|
||||||
|
## Section 5: Definitions
|
||||||
|
|
||||||
|
- *Contributors*: contribute code or other artifacts, but do not have the right to commit to the codebase. Contributors work with the project’s maintainers to have code committed to the code base. A Contributor may be promoted to a Maintainer by the Maintainers. Contributors should rarely be encumbered by the Maintainers and never by the CPC or OpenJS Foundation Board.
|
||||||
|
|
||||||
|
- *Maintainers*: Contributors with any kind of decision-making authority in the project.
|
||||||
|
|
||||||
|
[openjs foundation]: https://openjsf.org
|
579
README.md
579
README.md
@ -1,14 +1,25 @@
|
|||||||
# Node Version Manager [][3] [][4] [](https://bestpractices.coreinfrastructure.org/projects/684)
|
<a href="https://github.com/nvm-sh/logos">
|
||||||
|
<picture>
|
||||||
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nvm-sh/logos/HEAD/nvm-logo-white.svg" />
|
||||||
|
<img src="https://raw.githubusercontent.com/nvm-sh/logos/HEAD/nvm-logo-color.svg" height="50" alt="nvm project logo" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
# Node Version Manager [][3] [][4] [](https://bestpractices.dev/projects/684)
|
||||||
|
|
||||||
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
|
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
|
||||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
|
- [Intro](#intro)
|
||||||
- [About](#about)
|
- [About](#about)
|
||||||
- [Installing and Updating](#installing-and-updating)
|
- [Installing and Updating](#installing-and-updating)
|
||||||
- [Install & Update Script](#install--update-script)
|
- [Install & Update Script](#install--update-script)
|
||||||
- [Additional Notes](#additional-notes)
|
- [Additional Notes](#additional-notes)
|
||||||
|
- [Installing in Docker](#installing-in-docker)
|
||||||
|
- [Installing in Docker for CICD-Jobs](#installing-in-docker-for-cicd-jobs)
|
||||||
- [Troubleshooting on Linux](#troubleshooting-on-linux)
|
- [Troubleshooting on Linux](#troubleshooting-on-linux)
|
||||||
- [Troubleshooting on macOS](#troubleshooting-on-macos)
|
- [Troubleshooting on macOS](#troubleshooting-on-macos)
|
||||||
- [Ansible](#ansible)
|
- [Ansible](#ansible)
|
||||||
@ -24,32 +35,66 @@
|
|||||||
- [io.js](#iojs)
|
- [io.js](#iojs)
|
||||||
- [System Version of Node](#system-version-of-node)
|
- [System Version of Node](#system-version-of-node)
|
||||||
- [Listing Versions](#listing-versions)
|
- [Listing Versions](#listing-versions)
|
||||||
|
- [Setting Custom Colors](#setting-custom-colors)
|
||||||
|
- [Persisting custom colors](#persisting-custom-colors)
|
||||||
- [Suppressing colorized output](#suppressing-colorized-output)
|
- [Suppressing colorized output](#suppressing-colorized-output)
|
||||||
|
- [Restoring PATH](#restoring-path)
|
||||||
|
- [Set default node version](#set-default-node-version)
|
||||||
|
- [Use a mirror of node binaries](#use-a-mirror-of-node-binaries)
|
||||||
|
- [Pass Authorization header to mirror](#pass-authorization-header-to-mirror)
|
||||||
- [.nvmrc](#nvmrc)
|
- [.nvmrc](#nvmrc)
|
||||||
- [Deeper Shell Integration](#deeper-shell-integration)
|
- [Deeper Shell Integration](#deeper-shell-integration)
|
||||||
- [bash](#bash)
|
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
|
||||||
- [Automatically call `nvm use`](#automatically-call-nvm-use)
|
- [bash](#bash)
|
||||||
- [zsh](#zsh)
|
- [zsh](#zsh)
|
||||||
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
|
- [fish](#fish)
|
||||||
- [fish](#fish)
|
|
||||||
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file-1)
|
|
||||||
- [License](#license)
|
|
||||||
- [Running Tests](#running-tests)
|
- [Running Tests](#running-tests)
|
||||||
- [Environment variables](#environment-variables)
|
- [Environment variables](#environment-variables)
|
||||||
- [Bash Completion](#bash-completion)
|
- [Bash Completion](#bash-completion)
|
||||||
- [Usage](#usage-1)
|
- [Usage](#usage-1)
|
||||||
- [Compatibility Issues](#compatibility-issues)
|
- [Compatibility Issues](#compatibility-issues)
|
||||||
- [Installing nvm on Alpine Linux](#installing-nvm-on-alpine-linux)
|
- [Installing nvm on Alpine Linux](#installing-nvm-on-alpine-linux)
|
||||||
|
- [Alpine Linux 3.13+](#alpine-linux-313)
|
||||||
|
- [Alpine Linux 3.5 - 3.12](#alpine-linux-35---312)
|
||||||
- [Uninstalling / Removal](#uninstalling--removal)
|
- [Uninstalling / Removal](#uninstalling--removal)
|
||||||
- [Manual Uninstall](#manual-uninstall)
|
- [Manual Uninstall](#manual-uninstall)
|
||||||
- [Docker For Development Environment](#docker-for-development-environment)
|
- [Docker For Development Environment](#docker-for-development-environment)
|
||||||
- [Problems](#problems)
|
- [Problems](#problems)
|
||||||
- [macOS Troubleshooting](#macos-troubleshooting)
|
- [macOS Troubleshooting](#macos-troubleshooting)
|
||||||
|
- [WSL Troubleshooting](#wsl-troubleshooting)
|
||||||
|
- [Maintainers](#maintainers)
|
||||||
|
- [Project Support](#project-support)
|
||||||
|
- [Enterprise Support](#enterprise-support)
|
||||||
|
- [License](#license)
|
||||||
|
- [Copyright notice](#copyright-notice)
|
||||||
|
|
||||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
`nvm` allows you to quickly install and use different versions of node via the command line.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
```sh
|
||||||
|
$ nvm use 16
|
||||||
|
Now using node v16.9.1 (npm v7.21.1)
|
||||||
|
$ node -v
|
||||||
|
v16.9.1
|
||||||
|
$ nvm use 14
|
||||||
|
Now using node v14.18.0 (npm v6.14.15)
|
||||||
|
$ node -v
|
||||||
|
v14.18.0
|
||||||
|
$ nvm install 12
|
||||||
|
Now using node v12.22.6 (npm v6.14.5)
|
||||||
|
$ node -v
|
||||||
|
v12.22.6
|
||||||
|
```
|
||||||
|
|
||||||
|
Simple as that!
|
||||||
|
|
||||||
|
|
||||||
## About
|
## About
|
||||||
nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be installed per-user, and invoked per-shell. `nvm` works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
|
nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be installed per-user, and invoked per-shell. `nvm` works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and [windows WSL](https://github.com/nvm-sh/nvm#important-notes).
|
||||||
|
|
||||||
<a id="installation-and-update"></a>
|
<a id="installation-and-update"></a>
|
||||||
<a id="install-script"></a>
|
<a id="install-script"></a>
|
||||||
@ -59,13 +104,13 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i
|
|||||||
|
|
||||||
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
|
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
|
||||||
```sh
|
```sh
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||||
```
|
```
|
||||||
```sh
|
```sh
|
||||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bashrc`, `~/.bash_profile`, `~/.zshrc`, or `~/.profile`). If you find the install script is updating the wrong profile file, set the `$PROFILE` env var to the profile file’s path, and then rerun the installation script.
|
||||||
|
|
||||||
<a id="profile_snippet"></a>
|
<a id="profile_snippet"></a>
|
||||||
```sh
|
```sh
|
||||||
@ -77,16 +122,107 @@ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || pr
|
|||||||
|
|
||||||
- If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub>
|
- If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub>
|
||||||
|
|
||||||
- You can add `--no-use` to the end of the above script (...`nvm.sh --no-use`) to postpone using `nvm` until you manually [`use`](#usage) it.
|
- You can add `--no-use` to the end of the above script to postpone using `nvm` until you manually [`use`](#usage) it:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm, without auto-using the default version
|
||||||
|
```
|
||||||
|
|
||||||
- You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables.
|
- You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables.
|
||||||
Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not contain a trailing slash.
|
Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not contain a trailing slash.
|
||||||
|
|
||||||
- The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available.
|
- The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available.
|
||||||
|
|
||||||
|
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash'`
|
||||||
|
|
||||||
|
#### Installing in Docker
|
||||||
|
|
||||||
|
When invoking bash as a non-interactive shell, like in a Docker container, none of the regular profile files are sourced. In order to use `nvm`, `node`, and `npm` like normal, you can instead specify the special `BASH_ENV` variable, which bash sources when invoked non-interactively.
|
||||||
|
|
||||||
|
```Dockerfile
|
||||||
|
# Use bash for the shell
|
||||||
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
|
||||||
|
# Create a script file sourced by both interactive and non-interactive bash shells
|
||||||
|
ENV BASH_ENV /home/user/.bash_env
|
||||||
|
RUN touch "${BASH_ENV}"
|
||||||
|
RUN echo '. "${BASH_ENV}"' >> ~/.bashrc
|
||||||
|
|
||||||
|
# Download and install nvm
|
||||||
|
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | PROFILE="${BASH_ENV}" bash
|
||||||
|
RUN echo node > .nvmrc
|
||||||
|
RUN nvm install
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Installing in Docker for CICD-Jobs
|
||||||
|
|
||||||
|
More robust, works in CI/CD-Jobs. Can be run in interactive and non-interactive containers.
|
||||||
|
See https://github.com/nvm-sh/nvm/issues/3531.
|
||||||
|
|
||||||
|
```Dockerfile
|
||||||
|
FROM ubuntu:latest
|
||||||
|
ARG NODE_VERSION=20
|
||||||
|
|
||||||
|
# install curl
|
||||||
|
RUN apt update && apt install curl -y
|
||||||
|
|
||||||
|
# install nvm
|
||||||
|
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||||
|
|
||||||
|
# set env
|
||||||
|
ENV NVM_DIR=/root/.nvm
|
||||||
|
|
||||||
|
# install node
|
||||||
|
RUN bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION"
|
||||||
|
|
||||||
|
# set ENTRYPOINT for reloading nvm-environment
|
||||||
|
ENTRYPOINT ["bash", "-c", "source $NVM_DIR/nvm.sh && exec \"$@\"", "--"]
|
||||||
|
|
||||||
|
# set cmd to bash
|
||||||
|
CMD ["/bin/bash"]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
This example defaults to installation of nodejs version 20.x.y. Optionally you can easily override the version with docker build args like:
|
||||||
|
```
|
||||||
|
docker build -t nvmimage --build-arg NODE_VERSION=19 .
|
||||||
|
```
|
||||||
|
|
||||||
|
After creation of the image you can start container interactively and run commands, for example:
|
||||||
|
```
|
||||||
|
docker run --rm -it nvmimage
|
||||||
|
|
||||||
|
root@0a6b5a237c14:/# nvm -v
|
||||||
|
0.40.3
|
||||||
|
|
||||||
|
root@0a6b5a237c14:/# node -v
|
||||||
|
v19.9.0
|
||||||
|
|
||||||
|
root@0a6b5a237c14:/# npm -v
|
||||||
|
9.6.3
|
||||||
|
```
|
||||||
|
|
||||||
|
Noninteractive example:
|
||||||
|
```
|
||||||
|
user@host:/tmp/test $ docker run --rm -it nvmimage node -v
|
||||||
|
v19.9.0
|
||||||
|
user@host:/tmp/test $ docker run --rm -it nvmimage npm -v
|
||||||
|
9.6.3
|
||||||
|
```
|
||||||
|
|
||||||
#### Troubleshooting on Linux
|
#### Troubleshooting on Linux
|
||||||
|
|
||||||
On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again.
|
On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again.
|
||||||
|
Alternatively, you can run the following commands for the different shells on the command line:
|
||||||
|
|
||||||
|
*bash*: `source ~/.bashrc`
|
||||||
|
|
||||||
|
*zsh*: `source ~/.zshrc`
|
||||||
|
|
||||||
|
*ksh*: `. ~/.profile`
|
||||||
|
|
||||||
|
These should pick up the `nvm` command.
|
||||||
|
|
||||||
#### Troubleshooting on macOS
|
#### Troubleshooting on macOS
|
||||||
|
|
||||||
@ -96,26 +232,32 @@ If you get `nvm: command not found` after running the install script, one of the
|
|||||||
|
|
||||||
- Since macOS 10.15, the default shell is `zsh` and nvm will look for `.zshrc` to update, none is installed by default. Create one with `touch ~/.zshrc` and run the install script again.
|
- Since macOS 10.15, the default shell is `zsh` and nvm will look for `.zshrc` to update, none is installed by default. Create one with `touch ~/.zshrc` and run the install script again.
|
||||||
|
|
||||||
- If you use bash, the previous default shell, run `touch ~/.bash_profile` to create the necessary profile file if it does not exist.
|
- If you use bash, the previous default shell, your system may not have `.bash_profile` or `.bashrc` files where the command is set up. Create one of them with `touch ~/.bash_profile` or `touch ~/.bashrc` and run the install script again. Then, run `. ~/.bash_profile` or `. ~/.bashrc` to pick up the `nvm` command.
|
||||||
|
|
||||||
|
- You have previously used `bash`, but you have `zsh` installed. You need to manually add [these lines](#manual-install) to `~/.zshrc` and run `. ~/.zshrc`.
|
||||||
|
|
||||||
- You might need to restart your terminal instance or run `. ~/.nvm/nvm.sh`. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.
|
- You might need to restart your terminal instance or run `. ~/.nvm/nvm.sh`. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.
|
||||||
|
|
||||||
|
- If the above didn't help, you might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.
|
||||||
|
|
||||||
If the above doesn't fix the problem, you may try the following:
|
If the above doesn't fix the problem, you may try the following:
|
||||||
|
|
||||||
- If you use bash, it may be that your `.bash_profile` (or `~/.profile`) does not source your `~/.bashrc` properly. You could fix this by adding `source ~/<your_profile_file>` to it or follow the next step below.
|
- If you use bash, it may be that your `.bash_profile` (or `~/.profile`) does not source your `~/.bashrc` properly. You could fix this by adding `source ~/<your_profile_file>` to it or following the next step below.
|
||||||
|
|
||||||
- Try adding [the snippet from the install section](#profile_snippet), that finds the correct nvm directory and loads nvm, to your usual profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
- Try adding [the snippet from the install section](#profile_snippet), that finds the correct nvm directory and loads nvm, to your usual profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
||||||
|
|
||||||
- For more information about this issue and possible workarounds, please [refer here](https://github.com/nvm-sh/nvm/issues/576)
|
- For more information about this issue and possible workarounds, please [refer here](https://github.com/nvm-sh/nvm/issues/576)
|
||||||
|
|
||||||
|
**Note** For Macs with the Apple Silicon chip, node started offering **arm64** arch Darwin packages since v16.0.0 and experimental **arm64** support when compiling from source since v14.17.0. If you are facing issues installing node using `nvm`, you may want to update to one of those versions or later.
|
||||||
|
|
||||||
#### Ansible
|
#### Ansible
|
||||||
|
|
||||||
You can use a task:
|
You can use a task:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: nvm
|
- name: Install nvm
|
||||||
shell: >
|
ansible.builtin.shell: >
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||||
args:
|
args:
|
||||||
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
||||||
```
|
```
|
||||||
@ -130,31 +272,34 @@ command -v nvm
|
|||||||
|
|
||||||
which should output `nvm` if the installation was successful. Please note that `which nvm` will not work, since `nvm` is a sourced shell function, not an executable binary.
|
which should output `nvm` if the installation was successful. Please note that `which nvm` will not work, since `nvm` is a sourced shell function, not an executable binary.
|
||||||
|
|
||||||
|
**Note:** On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again.
|
||||||
|
|
||||||
### Important Notes
|
### Important Notes
|
||||||
|
|
||||||
If you're running a system without prepackaged binary available, which means you're going to install nodejs or io.js from its source code, you need to make sure your system has a C++ compiler. For OS X, Xcode will work, for Debian/Ubuntu based GNU/Linux, the `build-essential` and `libssl-dev` packages work.
|
If you're running a system without prepackaged binary available, which means you're going to install node or io.js from its source code, you need to make sure your system has a C++ compiler. For OS X, Xcode will work, for Debian/Ubuntu based GNU/Linux, the `build-essential` and `libssl-dev` packages work.
|
||||||
|
|
||||||
**Note:** `nvm` does not support Windows (see [#284](https://github.com/nvm-sh/nvm/issues/284)), but may work in WSL (Windows Subsystem for Linux) depending on the version of WSL. For Windows, two alternatives exist, which are neither supported nor developed by us:
|
**Note:** `nvm` also supports Windows in some cases. It should work through WSL (Windows Subsystem for Linux) depending on the version of WSL. It should also work with [GitBash](https://gitforwindows.org/) (MSYS) or [Cygwin](https://cygwin.com). Otherwise, for Windows, a few alternatives exist, which are neither supported nor developed by us:
|
||||||
|
|
||||||
- [nvm-windows](https://github.com/coreybutler/nvm-windows)
|
- [nvm-windows](https://github.com/coreybutler/nvm-windows)
|
||||||
- [nodist](https://github.com/marcelklehr/nodist)
|
- [nodist](https://github.com/marcelklehr/nodist)
|
||||||
|
- [nvs](https://github.com/jasongin/nvs)
|
||||||
|
|
||||||
**Note:** `nvm` does not support [Fish] either (see [#303](https://github.com/nvm-sh/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us:
|
**Note:** `nvm` does not support [Fish] either (see [#303](https://github.com/nvm-sh/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us:
|
||||||
|
|
||||||
- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
|
- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
|
||||||
- [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup
|
- [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup
|
||||||
- [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell
|
- [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell
|
||||||
- [fnm](https://github.com/fisherman/fnm) - [fisherman](https://github.com/fisherman/fisherman)-based version manager for fish
|
- [nvm.fish](https://github.com/jorgebucaran/nvm.fish) - The Node.js version manager you'll adore, crafted just for Fish
|
||||||
- [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used.
|
- [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used.
|
||||||
|
|
||||||
**Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket:
|
**Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket:
|
||||||
|
|
||||||
- [[#900] [Bug] nodejs on FreeBSD may need to be patched](https://github.com/nvm-sh/nvm/issues/900)
|
- [[#900] [Bug] node on FreeBSD may need to be patched](https://github.com/nvm-sh/nvm/issues/900)
|
||||||
- [nodejs/node#3716](https://github.com/nodejs/node/issues/3716)
|
- [nodejs/node#3716](https://github.com/nodejs/node/issues/3716)
|
||||||
|
|
||||||
**Note:** On OS X, if you do not have Xcode installed and you do not wish to download the ~4.3GB file, you can install the `Command Line Tools`. You can check out this blog post on how to just that:
|
**Note:** On OS X, if you do not have Xcode installed and you do not wish to download the ~4.3GB file, you can install the `Command Line Tools`. You can check out this blog post on how to just that:
|
||||||
|
|
||||||
- [How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode)](http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/)
|
- [How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode)](https://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/)
|
||||||
|
|
||||||
**Note:** On OS X, if you have/had a "system" node installed and want to install modules globally, keep in mind that:
|
**Note:** On OS X, if you have/had a "system" node installed and want to install modules globally, keep in mind that:
|
||||||
|
|
||||||
@ -164,7 +309,7 @@ If you're running a system without prepackaged binary available, which means you
|
|||||||
|
|
||||||
Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue.
|
Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue.
|
||||||
|
|
||||||
**Note:** If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm upgrade` to upgrade.
|
**Note:** If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm upgrade` to upgrade ([you can set](https://github.com/lukechilds/zsh-nvm#auto-use) `NVM_AUTO_USE=true` to have it automatically detect and use `.nvmrc` files).
|
||||||
|
|
||||||
**Note:** Git versions before v1.7 may face a problem of cloning `nvm` source from GitHub via https protocol, and there is also different behavior of git before v1.6, and git prior to [v1.17.10](https://github.com/git/git/commit/5a7d5b683f869d3e3884a89775241afa515da9e7) can not clone tags, so the minimum required git version is v1.7.10. If you are interested in the problem we mentioned here, please refer to GitHub's [HTTPS cloning errors](https://help.github.com/articles/https-cloning-errors/) article.
|
**Note:** Git versions before v1.7 may face a problem of cloning `nvm` source from GitHub via https protocol, and there is also different behavior of git before v1.6, and git prior to [v1.17.10](https://github.com/git/git/commit/5a7d5b683f869d3e3884a89775241afa515da9e7) can not clone tags, so the minimum required git version is v1.7.10. If you are interested in the problem we mentioned here, please refer to GitHub's [HTTPS cloning errors](https://help.github.com/articles/https-cloning-errors/) article.
|
||||||
|
|
||||||
@ -173,9 +318,9 @@ Homebrew installation is not supported. If you have issues with homebrew-install
|
|||||||
If you have `git` installed (requires git v1.7.10+):
|
If you have `git` installed (requires git v1.7.10+):
|
||||||
|
|
||||||
1. clone this repo in the root of your user profile
|
1. clone this repo in the root of your user profile
|
||||||
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
|
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
|
||||||
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.36.0`
|
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.3`
|
||||||
1. activate `nvm` by sourcing it from your shell: `. nvm.sh`
|
1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh`
|
||||||
|
|
||||||
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
|
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
|
||||||
(you may have to add to more than one of the above files)
|
(you may have to add to more than one of the above files)
|
||||||
@ -204,6 +349,7 @@ Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to hav
|
|||||||
```sh
|
```sh
|
||||||
export NVM_DIR="$HOME/.nvm"
|
export NVM_DIR="$HOME/.nvm"
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||||||
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
||||||
```
|
```
|
||||||
|
|
||||||
### Manual Upgrade
|
### Manual Upgrade
|
||||||
@ -234,9 +380,16 @@ nvm install node # "node" is an alias for the latest version
|
|||||||
To install a specific version of node:
|
To install a specific version of node:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
|
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To set an alias:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nvm alias my_alias v14.4.0
|
||||||
|
```
|
||||||
|
Make sure that your alias does not contain any spaces or slashes.
|
||||||
|
|
||||||
The first version installed becomes the default. New shells will start with the default version of node (e.g., `nvm alias default`).
|
The first version installed becomes the default. New shells will start with the default version of node (e.g., `nvm alias default`).
|
||||||
|
|
||||||
You can list available versions using `ls-remote`:
|
You can list available versions using `ls-remote`:
|
||||||
@ -266,10 +419,10 @@ nvm exec 4.2 node --version
|
|||||||
You can also get the path to the executable to where it was installed:
|
You can also get the path to the executable to where it was installed:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm which 5.0
|
nvm which 12.22
|
||||||
```
|
```
|
||||||
|
|
||||||
In place of a version pointer like "0.10" or "5.0" or "4.2.1", you can use the following special default aliases with `nvm install`, `nvm use`, `nvm run`, `nvm exec`, `nvm which`, etc:
|
In place of a version pointer like "14.7" or "16.3" or "12.22.1", you can use the following special default aliases with `nvm install`, `nvm use`, `nvm run`, `nvm exec`, `nvm which`, etc:
|
||||||
|
|
||||||
- `node`: this installs the latest version of [`node`](https://nodejs.org/en/)
|
- `node`: this installs the latest version of [`node`](https://nodejs.org/en/)
|
||||||
- `iojs`: this installs the latest version of [`io.js`](https://iojs.org/en/)
|
- `iojs`: this installs the latest version of [`io.js`](https://iojs.org/en/)
|
||||||
@ -293,7 +446,7 @@ Any time your local copy of `nvm` connects to https://nodejs.org, it will re-cre
|
|||||||
To get the latest LTS version of node and migrate your existing installed packages, use
|
To get the latest LTS version of node and migrate your existing installed packages, use
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm install 'lts/*' --reinstall-packages-from=current
|
nvm install --reinstall-packages-from=current 'lts/*'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Migrating Global Packages While Installing
|
### Migrating Global Packages While Installing
|
||||||
@ -301,7 +454,7 @@ nvm install 'lts/*' --reinstall-packages-from=current
|
|||||||
If you want to install a new version of Node.js and migrate npm packages from a previous version:
|
If you want to install a new version of Node.js and migrate npm packages from a previous version:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm install node --reinstall-packages-from=node
|
nvm install --reinstall-packages-from=node node
|
||||||
```
|
```
|
||||||
|
|
||||||
This will first use "nvm version node" to identify the current version you're migrating packages from. Then it resolves the new version to install from the remote server and installs it. Lastly, it runs "nvm reinstall-packages" to reinstall the npm packages from your prior version of Node to the new one.
|
This will first use "nvm version node" to identify the current version you're migrating packages from. Then it resolves the new version to install from the remote server and installs it. Lastly, it runs "nvm reinstall-packages" to reinstall the npm packages from your prior version of Node to the new one.
|
||||||
@ -309,8 +462,8 @@ This will first use "nvm version node" to identify the current version you're mi
|
|||||||
You can also install and migrate npm packages from specific versions of Node like this:
|
You can also install and migrate npm packages from specific versions of Node like this:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm install 6 --reinstall-packages-from=5
|
nvm install --reinstall-packages-from=5 6
|
||||||
nvm install v4.2 --reinstall-packages-from=iojs
|
nvm install --reinstall-packages-from=iojs v4.2
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that reinstalling packages _explicitly does not update the npm version_ — this is to ensure that npm isn't accidentally upgraded to a broken version for the new node version.
|
Note that reinstalling packages _explicitly does not update the npm version_ — this is to ensure that npm isn't accidentally upgraded to a broken version for the new node version.
|
||||||
@ -318,7 +471,7 @@ Note that reinstalling packages _explicitly does not update the npm version_ —
|
|||||||
To update npm at the same time add the `--latest-npm` flag, like this:
|
To update npm at the same time add the `--latest-npm` flag, like this:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm install lts/* --reinstall-packages-from=default --latest-npm
|
nvm install --reinstall-packages-from=default --latest-npm 'lts/*'
|
||||||
```
|
```
|
||||||
|
|
||||||
or, you can at any time run the following command to get the latest supported npm version on the current node version:
|
or, you can at any time run the following command to get the latest supported npm version on the current node version:
|
||||||
@ -326,7 +479,7 @@ or, you can at any time run the following command to get the latest supported np
|
|||||||
nvm install-latest-npm
|
nvm install-latest-npm
|
||||||
```
|
```
|
||||||
|
|
||||||
If you've already gotten an error to the effect of "npm does not support Node.js", you'll need to (1) revert to a previous node version (`nvm ls` & `nvm use <your latest _working_ version from the ls>`, (2) delete the newly created node version (`nvm uninstall <your _broken_ version of node from the ls>`), then (3) rerun your `nvm install` with the `--latest-npm` flag.
|
If you've already gotten an error to the effect of "npm does not support Node.js", you'll need to (1) revert to a previous node version (`nvm ls` & `nvm use <your latest _working_ version from the ls>`), (2) delete the newly created node version (`nvm uninstall <your _broken_ version of node from the ls>`), then (3) rerun your `nvm install` with the `--latest-npm` flag.
|
||||||
|
|
||||||
|
|
||||||
### Default Global Packages From File While Installing
|
### Default Global Packages From File While Installing
|
||||||
@ -352,7 +505,7 @@ nvm install iojs
|
|||||||
If you want to install a new version of io.js and migrate npm packages from a previous version:
|
If you want to install a new version of io.js and migrate npm packages from a previous version:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm install iojs --reinstall-packages-from=iojs
|
nvm install --reinstall-packages-from=iojs iojs
|
||||||
```
|
```
|
||||||
|
|
||||||
The same guidelines mentioned for migrating npm packages in node are applicable to io.js.
|
The same guidelines mentioned for migrating npm packages in node are applicable to io.js.
|
||||||
@ -380,27 +533,68 @@ If you want to see what versions are available to install:
|
|||||||
nvm ls-remote
|
nvm ls-remote
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Setting Custom Colors
|
||||||
|
|
||||||
|
You can set five colors that will be used to display version and alias information. These colors replace the default colors.
|
||||||
|
Initial colors are: g b y r e
|
||||||
|
|
||||||
|
Color codes:
|
||||||
|
|
||||||
|
r/R = red / bold red
|
||||||
|
|
||||||
|
g/G = green / bold green
|
||||||
|
|
||||||
|
b/B = blue / bold blue
|
||||||
|
|
||||||
|
c/C = cyan / bold cyan
|
||||||
|
|
||||||
|
m/M = magenta / bold magenta
|
||||||
|
|
||||||
|
y/Y = yellow / bold yellow
|
||||||
|
|
||||||
|
k/K = black / bold black
|
||||||
|
|
||||||
|
e/W = light grey / white
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nvm set-colors rgBcm
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Persisting custom colors
|
||||||
|
|
||||||
|
If you want the custom colors to persist after terminating the shell, export the `NVM_COLORS` variable in your shell profile. For example, if you want to use cyan, magenta, green, bold red and bold yellow, add the following line:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
export NVM_COLORS='cmgRY'
|
||||||
|
```
|
||||||
|
|
||||||
#### Suppressing colorized output
|
#### Suppressing colorized output
|
||||||
|
|
||||||
`nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
|
`nvm help (or -h or --help)`, `nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm ls --no-colors
|
nvm ls --no-colors
|
||||||
|
nvm help --no-colors
|
||||||
TERM=dumb nvm ls
|
TERM=dumb nvm ls
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Restoring PATH
|
||||||
To restore your PATH, you can deactivate it:
|
To restore your PATH, you can deactivate it:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm deactivate
|
nvm deactivate
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Set default node version
|
||||||
To set a default Node version to be used in any new shell, use the alias 'default':
|
To set a default Node version to be used in any new shell, use the alias 'default':
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nvm alias default node
|
nvm alias default node # this refers to the latest installed version of node
|
||||||
|
nvm alias default 18 # this refers to the latest installed v18.x version of node
|
||||||
|
nvm alias default 18.12 # this refers to the latest installed v18.12.x version of node
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Use a mirror of node binaries
|
||||||
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
|
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@ -421,6 +615,13 @@ NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
|
|||||||
|
|
||||||
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions.
|
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions.
|
||||||
|
|
||||||
|
#### Pass Authorization header to mirror
|
||||||
|
To pass an Authorization header through to the mirror url, set `$NVM_AUTH_HEADER`
|
||||||
|
|
||||||
|
```sh
|
||||||
|
NVM_AUTH_HEADER="Bearer secret-token" nvm install node
|
||||||
|
```
|
||||||
|
|
||||||
### .nvmrc
|
### .nvmrc
|
||||||
|
|
||||||
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
|
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
|
||||||
@ -438,7 +639,7 @@ $ echo "node" > .nvmrc # to default to the latest version
|
|||||||
|
|
||||||
[NB these examples assume a POSIX-compliant shell version of `echo`. If you use a Windows `cmd` development environment, eg the `.nvmrc` file is used to configure a remote Linux deployment, then keep in mind the `"`s will be copied leading to an invalid file. Remove them.]
|
[NB these examples assume a POSIX-compliant shell version of `echo`. If you use a Windows `cmd` development environment, eg the `.nvmrc` file is used to configure a remote Linux deployment, then keep in mind the `"`s will be copied leading to an invalid file. Remove them.]
|
||||||
|
|
||||||
Then when you run nvm:
|
Then when you run nvm use:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ nvm use
|
$ nvm use
|
||||||
@ -446,81 +647,93 @@ Found '/path/to/project/.nvmrc' with version <5.9>
|
|||||||
Now using node v5.9.1 (npm v3.7.3)
|
Now using node v5.9.1 (npm v3.7.3)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Running nvm install will also switch over to the correct version, but if the correct node version isn't already installed, it will install it for you.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ nvm install
|
||||||
|
Found '/path/to/project/.nvmrc' with version <5.9>
|
||||||
|
Downloading and installing node v5.9.1...
|
||||||
|
Downloading https://nodejs.org/dist/v5.9.1/node-v5.9.1-linux-x64.tar.xz...
|
||||||
|
#################################################################################### 100.0%
|
||||||
|
Computing checksum with sha256sum
|
||||||
|
Checksums matched!
|
||||||
|
Now using node v5.9.1 (npm v3.7.3)
|
||||||
|
```
|
||||||
|
|
||||||
`nvm use` et. al. will traverse directory structure upwards from the current directory looking for the `.nvmrc` file. In other words, running `nvm use` et. al. in any subdirectory of a directory with an `.nvmrc` will result in that `.nvmrc` being utilized.
|
`nvm use` et. al. will traverse directory structure upwards from the current directory looking for the `.nvmrc` file. In other words, running `nvm use` et. al. in any subdirectory of a directory with an `.nvmrc` will result in that `.nvmrc` being utilized.
|
||||||
|
|
||||||
The contents of a `.nvmrc` file **must** be the `<version>` (as described by `nvm --help`) followed by a newline. No trailing spaces are allowed, and the trailing newline is required.
|
The contents of a `.nvmrc` file **must** contain precisely one `<version>` (as described by `nvm --help`) followed by a newline. `.nvmrc` files may also have comments. The comment delimiter is `#`, and it and any text after it, as well as blank lines, and leading and trailing white space, will be ignored when parsing.
|
||||||
|
|
||||||
|
Key/value pairs using `=` are also allowed and ignored, but are reserved for future use, and may cause validation errors in the future.
|
||||||
|
|
||||||
|
Run [`npx nvmrc`](https://npmjs.com/nvmrc) to validate an `.nvmrc` file. If that tool’s results do not agree with nvm, one or the other has a bug - please file an issue.
|
||||||
|
|
||||||
### Deeper Shell Integration
|
### Deeper Shell Integration
|
||||||
|
|
||||||
You can use [`avn`](https://github.com/wbyoung/avn) to deeply integrate into your shell and automatically invoke `nvm` when changing directories. `avn` is **not** supported by the `nvm` development team. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/issues/new).
|
You can use [`nvshim`](https://github.com/iamogbz/nvshim) to shim the `node`, `npm`, and `npx` bins to automatically use the `nvm` config in the current directory. `nvshim` is **not** supported by the `nvm` maintainers. Please [report issues to the `nvshim` team](https://github.com/iamogbz/nvshim/issues/new).
|
||||||
|
|
||||||
If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` development team. We are, however, accepting pull requests for more examples.
|
If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` maintainers. We are, however, accepting pull requests for more examples.
|
||||||
|
|
||||||
#### bash
|
#### Calling `nvm use` automatically in a directory with a `.nvmrc` file
|
||||||
|
|
||||||
##### Automatically call `nvm use`
|
In your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`), add the following to `nvm use` whenever you enter a new directory:
|
||||||
|
|
||||||
|
##### bash
|
||||||
|
|
||||||
Put the following at the end of your `$HOME/.bashrc`:
|
Put the following at the end of your `$HOME/.bashrc`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
find-up () {
|
cdnvm() {
|
||||||
path=$(pwd)
|
command cd "$@" || return $?
|
||||||
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
|
nvm_path="$(nvm_find_up .nvmrc | command tr -d '\n')"
|
||||||
path=${path%/*}
|
|
||||||
done
|
|
||||||
echo "$path"
|
|
||||||
}
|
|
||||||
|
|
||||||
cdnvm(){
|
|
||||||
cd "$@";
|
|
||||||
nvm_path=$(find-up .nvmrc | tr -d '\n')
|
|
||||||
|
|
||||||
# If there are no .nvmrc file, use the default nvm version
|
# If there are no .nvmrc file, use the default nvm version
|
||||||
if [[ ! $nvm_path = *[^[:space:]]* ]]; then
|
if [[ ! $nvm_path = *[^[:space:]]* ]]; then
|
||||||
|
|
||||||
declare default_version;
|
declare default_version
|
||||||
default_version=$(nvm version default);
|
default_version="$(nvm version default)"
|
||||||
|
|
||||||
# If there is no default version, set it to `node`
|
# If there is no default version, set it to `node`
|
||||||
# This will use the latest version on your machine
|
# This will use the latest version on your machine
|
||||||
if [[ $default_version == "N/A" ]]; then
|
if [ $default_version = 'N/A' ]; then
|
||||||
nvm alias default node;
|
nvm alias default node
|
||||||
default_version=$(nvm version default);
|
default_version=$(nvm version default)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If the current version is not the default version, set it to use the default version
|
# If the current version is not the default version, set it to use the default version
|
||||||
if [[ $(nvm current) != "$default_version" ]]; then
|
if [ "$(nvm current)" != "${default_version}" ]; then
|
||||||
nvm use default;
|
nvm use default
|
||||||
fi
|
fi
|
||||||
|
elif [[ -s "${nvm_path}/.nvmrc" && -r "${nvm_path}/.nvmrc" ]]; then
|
||||||
elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then
|
|
||||||
declare nvm_version
|
declare nvm_version
|
||||||
nvm_version=$(<"$nvm_path"/.nvmrc)
|
nvm_version=$(<"${nvm_path}"/.nvmrc)
|
||||||
|
|
||||||
declare locally_resolved_nvm_version
|
declare locally_resolved_nvm_version
|
||||||
# `nvm ls` will check all locally-available versions
|
# `nvm ls` will check all locally-available versions
|
||||||
# If there are multiple matching versions, take the latest one
|
# If there are multiple matching versions, take the latest one
|
||||||
# Remove the `->` and `*` characters and spaces
|
# Remove the `->` and `*` characters and spaces
|
||||||
# `locally_resolved_nvm_version` will be `N/A` if no local versions are found
|
# `locally_resolved_nvm_version` will be `N/A` if no local versions are found
|
||||||
locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]')
|
locally_resolved_nvm_version=$(nvm ls --no-colors "${nvm_version}" | command tail -1 | command tr -d '\->*' | command tr -d '[:space:]')
|
||||||
|
|
||||||
# If it is not already installed, install it
|
# If it is not already installed, install it
|
||||||
# `nvm install` will implicitly use the newly-installed version
|
# `nvm install` will implicitly use the newly-installed version
|
||||||
if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
|
if [ "${locally_resolved_nvm_version}" = 'N/A' ]; then
|
||||||
nvm install "$nvm_version";
|
nvm install "${nvm_version}";
|
||||||
elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
|
elif [ "$(nvm current)" != "${locally_resolved_nvm_version}" ]; then
|
||||||
nvm use "$nvm_version";
|
nvm use "${nvm_version}";
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
alias cd='cdnvm'
|
alias cd='cdnvm'
|
||||||
|
cdnvm "$PWD" || exit
|
||||||
```
|
```
|
||||||
|
|
||||||
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
|
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
|
||||||
|
|
||||||
#### zsh
|
##### zsh
|
||||||
|
|
||||||
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
|
This shell function will install (if needed) and `nvm use` the specified Node version when an `.nvmrc` is found, and `nvm use default` otherwise.
|
||||||
|
|
||||||
Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you enter a directory that contains an
|
Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you enter a directory that contains an
|
||||||
`.nvmrc` file with a string telling nvm which node to `use`:
|
`.nvmrc` file with a string telling nvm which node to `use`:
|
||||||
@ -528,30 +741,34 @@ Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you e
|
|||||||
```zsh
|
```zsh
|
||||||
# place this after nvm initialization!
|
# place this after nvm initialization!
|
||||||
autoload -U add-zsh-hook
|
autoload -U add-zsh-hook
|
||||||
|
|
||||||
load-nvmrc() {
|
load-nvmrc() {
|
||||||
local node_version="$(nvm version)"
|
local nvmrc_path
|
||||||
local nvmrc_path="$(nvm_find_nvmrc)"
|
nvmrc_path="$(nvm_find_nvmrc)"
|
||||||
|
|
||||||
if [ -n "$nvmrc_path" ]; then
|
if [ -n "$nvmrc_path" ]; then
|
||||||
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
|
local nvmrc_node_version
|
||||||
|
nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
|
||||||
|
|
||||||
if [ "$nvmrc_node_version" = "N/A" ]; then
|
if [ "$nvmrc_node_version" = "N/A" ]; then
|
||||||
nvm install
|
nvm install
|
||||||
elif [ "$nvmrc_node_version" != "$node_version" ]; then
|
elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then
|
||||||
nvm use
|
nvm use
|
||||||
fi
|
fi
|
||||||
elif [ "$node_version" != "$(nvm version default)" ]; then
|
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
|
||||||
echo "Reverting to nvm default version"
|
echo "Reverting to nvm default version"
|
||||||
nvm use default
|
nvm use default
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
add-zsh-hook chpwd load-nvmrc
|
add-zsh-hook chpwd load-nvmrc
|
||||||
load-nvmrc
|
load-nvmrc
|
||||||
```
|
```
|
||||||
|
|
||||||
#### fish
|
After saving the file, run `source ~/.zshrc` to reload the configuration with the latest changes made.
|
||||||
|
|
||||||
|
##### fish
|
||||||
|
|
||||||
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
|
|
||||||
This requires that you have [bass](https://github.com/edc/bass) installed.
|
This requires that you have [bass](https://github.com/edc/bass) installed.
|
||||||
```fish
|
```fish
|
||||||
# ~/.config/fish/functions/nvm.fish
|
# ~/.config/fish/functions/nvm.fish
|
||||||
@ -573,7 +790,7 @@ function load_nvm --on-variable="PWD"
|
|||||||
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
|
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
|
||||||
if test "$nvmrc_node_version" = "N/A"
|
if test "$nvmrc_node_version" = "N/A"
|
||||||
nvm install (cat $nvmrc_path)
|
nvm install (cat $nvmrc_path)
|
||||||
else if test nvmrc_node_version != node_version
|
else if test "$nvmrc_node_version" != "$node_version"
|
||||||
nvm use $nvmrc_node_version
|
nvm use $nvmrc_node_version
|
||||||
end
|
end
|
||||||
else if test "$node_version" != "$default_node_version"
|
else if test "$node_version" != "$default_node_version"
|
||||||
@ -584,23 +801,9 @@ end
|
|||||||
|
|
||||||
# ~/.config/fish/config.fish
|
# ~/.config/fish/config.fish
|
||||||
# You must call it on initialization or listening to directory switching won't work
|
# You must call it on initialization or listening to directory switching won't work
|
||||||
load_nvm
|
load_nvm > /dev/stderr
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
nvm is released under the MIT license.
|
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2010 Tim Caswell and Jordan Harband
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
## Running Tests
|
## Running Tests
|
||||||
|
|
||||||
Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
|
Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
|
||||||
@ -650,36 +853,36 @@ Put the above sourcing line just below the sourcing line for nvm in your profile
|
|||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
nvm:
|
nvm:
|
||||||
> $ nvm <kbd>Tab</kbd>
|
|
||||||
|
|
||||||
```
|
> `$ nvm` <kbd>Tab</kbd>
|
||||||
|
```sh
|
||||||
alias deactivate install list-remote reinstall-packages uninstall version
|
alias deactivate install list-remote reinstall-packages uninstall version
|
||||||
cache exec install-latest-npm ls run unload version-remote
|
cache exec install-latest-npm ls run unload version-remote
|
||||||
current help list ls-remote unalias use which
|
current help list ls-remote unalias use which
|
||||||
```
|
```
|
||||||
|
|
||||||
nvm alias:
|
nvm alias:
|
||||||
> $ nvm alias <kbd>Tab</kbd>
|
|
||||||
|
|
||||||
```
|
> `$ nvm alias` <kbd>Tab</kbd>
|
||||||
|
```sh
|
||||||
default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable
|
default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable
|
||||||
```
|
```
|
||||||
|
|
||||||
> $ nvm alias my_alias <kbd>Tab</kbd>
|
|
||||||
|
|
||||||
```
|
> `$ nvm alias my_alias` <kbd>Tab</kbd>
|
||||||
|
```sh
|
||||||
v10.22.0 v12.18.3 v14.8.0
|
v10.22.0 v12.18.3 v14.8.0
|
||||||
```
|
```
|
||||||
|
|
||||||
nvm use:
|
nvm use:
|
||||||
> $ nvm use <kbd>Tab</kbd>
|
> `$ nvm use` <kbd>Tab</kbd>
|
||||||
|
|
||||||
```
|
```
|
||||||
my_alias default v10.22.0 v12.18.3 v14.8.0
|
my_alias default v10.22.0 v12.18.3 v14.8.0
|
||||||
```
|
```
|
||||||
|
|
||||||
nvm uninstall:
|
nvm uninstall:
|
||||||
> $ nvm uninstall <kbd>Tab</kbd>
|
> `$ nvm uninstall` <kbd>Tab</kbd>
|
||||||
|
|
||||||
```
|
```
|
||||||
my_alias default v10.22.0 v12.18.3 v14.8.0
|
my_alias default v10.22.0 v12.18.3 v14.8.0
|
||||||
@ -687,7 +890,7 @@ my_alias default v10.22.0 v12.18.3 v14.8.0
|
|||||||
|
|
||||||
## Compatibility Issues
|
## Compatibility Issues
|
||||||
|
|
||||||
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](/../../issues/606))
|
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](https://github.com/nvm-sh/nvm/issues/606))
|
||||||
The following are known to cause issues:
|
The following are known to cause issues:
|
||||||
|
|
||||||
Inside `~/.npmrc`:
|
Inside `~/.npmrc`:
|
||||||
@ -711,19 +914,28 @@ set -e
|
|||||||
|
|
||||||
## Installing nvm on Alpine Linux
|
## Installing nvm on Alpine Linux
|
||||||
|
|
||||||
In order to provide the best performance (and other optimisations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS, RedHat et al).
|
In order to provide the best performance (and other optimizations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS, RedHat et al).
|
||||||
|
|
||||||
Alpine Linux, unlike mainstream/traditional Linux distributions, is based on [BusyBox](https://www.busybox.net/), a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - [musl](https://www.musl-libc.org/). This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply `nvm install X` on Alpine Linux and expect the downloaded binary to run correctly - you'll likely see "...does not exist" errors if you try that.
|
Alpine Linux, unlike mainstream/traditional Linux distributions, is based on [BusyBox](https://www.busybox.net/), a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - [musl](https://www.musl-libc.org/). This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply `nvm install X` on Alpine Linux and expect the downloaded binary to run correctly - you'll likely see "...does not exist" errors if you try that.
|
||||||
|
|
||||||
There is a `-s` flag for `nvm install` which requests nvm download Node source and compile it locally.
|
There is a `-s` flag for `nvm install` which requests nvm download Node source and compile it locally.
|
||||||
|
|
||||||
If installing nvm on Alpine Linux *is* still what you want or need to do, you should be able to achieve this by running the following from you Alpine Linux shell:
|
If installing nvm on Alpine Linux *is* still what you want or need to do, you should be able to achieve this by running the following from you Alpine Linux shell, depending on which version you are using:
|
||||||
|
|
||||||
|
### Alpine Linux 3.13+
|
||||||
|
```sh
|
||||||
|
apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
||||||
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
### Alpine Linux 3.5 - 3.12
|
||||||
```sh
|
```sh
|
||||||
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
_Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package `python2` to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._
|
||||||
|
|
||||||
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
|
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
|
||||||
|
|
||||||
As a potential alternative, @mhart (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node).
|
As a potential alternative, @mhart (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node).
|
||||||
@ -735,8 +947,12 @@ As a potential alternative, @mhart (a Node contributor) has some [Docker images
|
|||||||
|
|
||||||
To remove `nvm` manually, execute the following:
|
To remove `nvm` manually, execute the following:
|
||||||
|
|
||||||
|
First, use `nvm unload` to remove the nvm command from your terminal session and delete the installation directory:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ rm -rf "$NVM_DIR"
|
$ nvm_dir="${NVM_DIR:-~/.nvm}"
|
||||||
|
$ nvm unload
|
||||||
|
$ rm -rf "$nvm_dir"
|
||||||
```
|
```
|
||||||
|
|
||||||
Edit `~/.bashrc` (or other shell resource config) and remove the lines below:
|
Edit `~/.bashrc` (or other shell resource config) and remove the lines below:
|
||||||
@ -749,7 +965,7 @@ export NVM_DIR="$HOME/.nvm"
|
|||||||
|
|
||||||
## Docker For Development Environment
|
## Docker For Development Environment
|
||||||
|
|
||||||
To make the development and testing work easier, we have a Dockerfile for development usage, which is based on Ubuntu 14.04 base image, prepared with essential and useful tools for `nvm` development, to build the docker image of the environment, run the docker command at the root of `nvm` repository:
|
To make the development and testing work easier, we have a Dockerfile for development usage, which is based on Ubuntu 18.04 base image, prepared with essential and useful tools for `nvm` development, to build the docker image of the environment, run the docker command at the root of `nvm` repository:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ docker build -t nvm-dev .
|
$ docker build -t nvm-dev .
|
||||||
@ -818,8 +1034,141 @@ You have to make sure that the user directory name in `$HOME` and the user direc
|
|||||||
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
|
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
|
||||||
|
|
||||||
[1]: https://github.com/nvm-sh/nvm.git
|
[1]: https://github.com/nvm-sh/nvm.git
|
||||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.36.0/install.sh
|
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.3/install.sh
|
||||||
[3]: https://travis-ci.org/nvm-sh/nvm
|
[3]: https://app.travis-ci.com/nvm-sh/nvm
|
||||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.36.0
|
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.3
|
||||||
[Urchin]: https://github.com/scraperwiki/urchin
|
[Urchin]: https://git.sdf.org/tlevine/urchin
|
||||||
[Fish]: http://fishshell.com
|
[Fish]: https://fishshell.com
|
||||||
|
|
||||||
|
**Homebrew makes zsh directories unsecure**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
zsh compinit: insecure directories, run compaudit for list.
|
||||||
|
Ignore insecure directories and continue [y] or abort compinit [n]? y
|
||||||
|
```
|
||||||
|
|
||||||
|
Homebrew causes insecure directories like `/usr/local/share/zsh/site-functions` and `/usr/local/share/zsh`. This is **not** an `nvm` problem - it is a homebrew problem. Refer [here](https://github.com/zsh-users/zsh-completions/issues/680) for some solutions related to the issue.
|
||||||
|
|
||||||
|
**Macs with Apple Silicon chips**
|
||||||
|
|
||||||
|
Experimental support for the Apple Silicon chip architecture was added in node.js v15.3 and full support was added in v16.0.
|
||||||
|
Because of this, if you try to install older versions of node as usual, you will probably experience either compilation errors when installing node or out-of-memory errors while running your code.
|
||||||
|
|
||||||
|
So, if you want to run a version prior to v16.0 on an Apple Silicon Mac, it may be best to compile node targeting the `x86_64` Intel architecture so that Rosetta 2 can translate the `x86_64` processor instructions to ARM-based Apple Silicon instructions.
|
||||||
|
Here's what you will need to do:
|
||||||
|
|
||||||
|
- Install Rosetta, if you haven't already done so
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ softwareupdate --install-rosetta
|
||||||
|
```
|
||||||
|
|
||||||
|
You might wonder, "how will my Apple Silicon Mac know to use Rosetta for a version of node compiled for an Intel chip?".
|
||||||
|
If an executable contains only Intel instructions, macOS will automatically use Rosetta to translate the instructions.
|
||||||
|
|
||||||
|
- Open a shell that's running using Rosetta
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ arch -x86_64 zsh
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: This same thing can also be accomplished by finding the Terminal or iTerm App in Finder, right clicking, selecting "Get Info", and then checking the box labeled "Open using Rosetta".
|
||||||
|
|
||||||
|
Note: This terminal session is now running in `zsh`.
|
||||||
|
If `zsh` is not the shell you typically use, `nvm` may not be `source`'d automatically like it probably is for your usual shell through your dotfiles.
|
||||||
|
If that's the case, make sure to source `nvm`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ source "${NVM_DIR}/nvm.sh"
|
||||||
|
```
|
||||||
|
|
||||||
|
- Install whatever older version of node you are interested in. Let's use 12.22.1 as an example.
|
||||||
|
This will fetch the node source code and compile it, which will take several minutes.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ nvm install v12.22.1 --shared-zlib
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: You're probably curious why `--shared-zlib` is included.
|
||||||
|
There's a bug in recent versions of Apple's system `clang` compiler.
|
||||||
|
If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the `--shared-zlib` flag.
|
||||||
|
However, later, when you attempt to `npm install` something using your old version of node.js, you will see `incorrect data check` errors.
|
||||||
|
If you want to avoid the possible hassle of dealing with this, include that flag.
|
||||||
|
For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.376)
|
||||||
|
|
||||||
|
- Exit back to your native shell.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ exit
|
||||||
|
$ arch
|
||||||
|
arm64
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: If you selected the box labeled "Open using Rosetta" rather than running the CLI command in the second step, you will see `i386` here.
|
||||||
|
Unless you have another reason to have that box selected, you can deselect it now.
|
||||||
|
|
||||||
|
- Check to make sure the architecture is correct. `x64` is the abbreviation for `x86_64`, which is what you want to see.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ node -p process.arch
|
||||||
|
x64
|
||||||
|
```
|
||||||
|
|
||||||
|
Now you should be able to use node as usual.
|
||||||
|
|
||||||
|
## WSL Troubleshooting
|
||||||
|
|
||||||
|
If you've encountered this error on WSL-2:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||||
|
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||||
|
Dload Upload Total Spent Left Speed
|
||||||
|
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com
|
||||||
|
```
|
||||||
|
|
||||||
|
It may be due to your antivirus, VPN, or other reasons.
|
||||||
|
|
||||||
|
Where you can `ping 8.8.8.8` while you can't `ping google.com`
|
||||||
|
|
||||||
|
|
||||||
|
This could simply be solved by running this in your root directory:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo rm /etc/resolv.conf
|
||||||
|
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
|
||||||
|
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
|
||||||
|
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
|
||||||
|
sudo chattr +i /etc/resolv.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
This deletes your `resolv.conf` file that is automatically generated when you run WSL, creates a new file and puts `nameserver 8.8.8.8`, then creates a `wsl.conf` file and adds `[network]` and `generateResolveConf = false` to prevent auto-generation of that file.
|
||||||
|
|
||||||
|
You can check the contents of the file by running:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cat /etc/resolv.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
## Maintainers
|
||||||
|
|
||||||
|
Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more maintainers are quite welcome, and we hope to add folks to the team over time. [Governance](./GOVERNANCE.md) will be re-evaluated as the project evolves.
|
||||||
|
|
||||||
|
## Project Support
|
||||||
|
|
||||||
|
Only the latest version (v0.40.3 at this time) is supported.
|
||||||
|
|
||||||
|
## Enterprise Support
|
||||||
|
|
||||||
|
If you are unable to update to the latest version of `nvm`, our [partners](https://openjsf.org/ecosystem-sustainability-program) provide commercial security fixes for all unsupported versions:
|
||||||
|
|
||||||
|
- [HeroDevs Never-Ending Support](https://www.herodevs.com/support?utm_source=OpenJS&utm_medium=Link&utm_campaign=nvm_openjs)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
See [LICENSE.md](./LICENSE.md).
|
||||||
|
|
||||||
|
## Copyright notice
|
||||||
|
|
||||||
|
Copyright [OpenJS Foundation](https://openjsf.org) and `nvm` contributors. All rights reserved. The [OpenJS Foundation](https://openjsf.org) has registered trademarks and uses trademarks. For a list of trademarks of the [OpenJS Foundation](https://openjsf.org), please see our [Trademark Policy](https://trademark-policy.openjsf.org/) and [Trademark List](https://trademark-list.openjsf.org/). Trademarks and logos not indicated on the [list of OpenJS Foundation trademarks](https://trademark-list.openjsf.org) are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
|
||||||
|
[The OpenJS Foundation](https://openjsf.org/) | [Terms of Use](https://terms-of-use.openjsf.org/) | [Privacy Policy](https://privacy-policy.openjsf.org/) | [Bylaws](https://bylaws.openjsf.org/) | [Code of Conduct](https://code-of-conduct.openjsf.org) | [Trademark Policy](https://trademark-policy.openjsf.org/) | [Trademark List](https://trademark-list.openjsf.org/) | [Cookie Policy](https://www.linuxfoundation.org/cookies/)
|
||||||
|
@ -58,7 +58,7 @@ __nvm_aliases() {
|
|||||||
declare aliases
|
declare aliases
|
||||||
aliases=""
|
aliases=""
|
||||||
if [ -d "${NVM_DIR}/alias" ]; then
|
if [ -d "${NVM_DIR}/alias" ]; then
|
||||||
aliases="$(cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"
|
aliases="$(command cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"
|
||||||
fi
|
fi
|
||||||
echo "${aliases} node stable unstable iojs"
|
echo "${aliases} node stable unstable iojs"
|
||||||
}
|
}
|
||||||
@ -84,12 +84,16 @@ __nvm() {
|
|||||||
# called bashcompinit that will create a complete in ZSH. If the user is in
|
# called bashcompinit that will create a complete in ZSH. If the user is in
|
||||||
# ZSH, load and run bashcompinit before calling the complete function.
|
# ZSH, load and run bashcompinit before calling the complete function.
|
||||||
if [[ -n ${ZSH_VERSION-} ]]; then
|
if [[ -n ${ZSH_VERSION-} ]]; then
|
||||||
autoload -U +X bashcompinit && bashcompinit
|
# First calling compinit (only if not called yet!)
|
||||||
autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
|
# and then bashcompinit as mentioned by zsh man page.
|
||||||
compinit -u
|
if ! command -v compinit > /dev/null; then
|
||||||
else
|
autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
|
||||||
compinit
|
compinit -u
|
||||||
|
else
|
||||||
|
compinit
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
autoload -U +X bashcompinit && bashcompinit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
complete -o default -F __nvm nvm
|
complete -o default -F __nvm nvm
|
||||||
|
244
install.sh
244
install.sh
@ -6,6 +6,20 @@ nvm_has() {
|
|||||||
type "$1" > /dev/null 2>&1
|
type "$1" > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_echo() {
|
||||||
|
command printf %s\\n "$*" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z "${BASH_VERSION}" ] || [ -n "${ZSH_VERSION}" ]; then
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
nvm_echo >&2 'Error: the install instructions explicitly say to pipe the install script to `bash`; please follow them'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
nvm_grep() {
|
||||||
|
GREP_OPTIONS='' command grep "$@"
|
||||||
|
}
|
||||||
|
|
||||||
nvm_default_install_dir() {
|
nvm_default_install_dir() {
|
||||||
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
|
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
|
||||||
}
|
}
|
||||||
@ -19,14 +33,14 @@ nvm_install_dir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nvm_latest_version() {
|
nvm_latest_version() {
|
||||||
echo "v0.36.0"
|
nvm_echo "v0.40.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_profile_is_bash_or_zsh() {
|
nvm_profile_is_bash_or_zsh() {
|
||||||
local TEST_PROFILE
|
local TEST_PROFILE
|
||||||
TEST_PROFILE="${1-}"
|
TEST_PROFILE="${1-}"
|
||||||
case "${TEST_PROFILE-}" in
|
case "${TEST_PROFILE-}" in
|
||||||
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
|
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -38,48 +52,70 @@ nvm_profile_is_bash_or_zsh() {
|
|||||||
#
|
#
|
||||||
# Outputs the location to NVM depending on:
|
# Outputs the location to NVM depending on:
|
||||||
# * The availability of $NVM_SOURCE
|
# * The availability of $NVM_SOURCE
|
||||||
|
# * The presence of $NVM_INSTALL_GITHUB_REPO
|
||||||
# * The method used ("script" or "git" in the script, defaults to "git")
|
# * The method used ("script" or "git" in the script, defaults to "git")
|
||||||
# NVM_SOURCE always takes precedence unless the method is "script-nvm-exec"
|
# NVM_SOURCE always takes precedence unless the method is "script-nvm-exec"
|
||||||
#
|
#
|
||||||
nvm_source() {
|
nvm_source() {
|
||||||
|
local NVM_GITHUB_REPO
|
||||||
|
NVM_GITHUB_REPO="${NVM_INSTALL_GITHUB_REPO:-nvm-sh/nvm}"
|
||||||
|
if [ "${NVM_GITHUB_REPO}" != 'nvm-sh/nvm' ]; then
|
||||||
|
{ nvm_echo >&2 "$(cat)" ; } << EOF
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@ WARNING: REMOTE REPO IDENTIFICATION HAS CHANGED! @
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
|
||||||
|
|
||||||
|
The default repository for this install is \`nvm-sh/nvm\`,
|
||||||
|
but the environment variables \`\$NVM_INSTALL_GITHUB_REPO\` is
|
||||||
|
currently set to \`${NVM_GITHUB_REPO}\`.
|
||||||
|
|
||||||
|
If this is not intentional, interrupt this installation and
|
||||||
|
verify your environment variables.
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
local NVM_VERSION
|
||||||
|
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
|
||||||
local NVM_METHOD
|
local NVM_METHOD
|
||||||
NVM_METHOD="$1"
|
NVM_METHOD="$1"
|
||||||
local NVM_SOURCE_URL
|
local NVM_SOURCE_URL
|
||||||
NVM_SOURCE_URL="$NVM_SOURCE"
|
NVM_SOURCE_URL="$NVM_SOURCE"
|
||||||
if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
|
if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
|
||||||
NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm-exec"
|
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm-exec"
|
||||||
elif [ "_$NVM_METHOD" = "_script-nvm-bash-completion" ]; then
|
elif [ "_$NVM_METHOD" = "_script-nvm-bash-completion" ]; then
|
||||||
NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/bash_completion"
|
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/bash_completion"
|
||||||
elif [ -z "$NVM_SOURCE_URL" ]; then
|
elif [ -z "$NVM_SOURCE_URL" ]; then
|
||||||
if [ "_$NVM_METHOD" = "_script" ]; then
|
if [ "_$NVM_METHOD" = "_script" ]; then
|
||||||
NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm.sh"
|
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm.sh"
|
||||||
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
|
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
|
||||||
NVM_SOURCE_URL="https://github.com/nvm-sh/nvm.git"
|
NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git"
|
||||||
else
|
else
|
||||||
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
|
nvm_echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "$NVM_SOURCE_URL"
|
nvm_echo "$NVM_SOURCE_URL"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Node.js version to install
|
# Node.js version to install
|
||||||
#
|
#
|
||||||
nvm_node_version() {
|
nvm_node_version() {
|
||||||
echo "$NODE_VERSION"
|
nvm_echo "$NODE_VERSION"
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_download() {
|
nvm_download() {
|
||||||
if nvm_has "curl"; then
|
if nvm_has "curl"; then
|
||||||
curl --compressed -q "$@"
|
curl --fail --compressed -q "$@"
|
||||||
elif nvm_has "wget"; then
|
elif nvm_has "wget"; then
|
||||||
# Emulate curl with wget
|
# Emulate curl with wget
|
||||||
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
|
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||||
-e 's/-L //' \
|
|
||||||
-e 's/--compressed //' \
|
-e 's/--compressed //' \
|
||||||
|
-e 's/--fail //' \
|
||||||
|
-e 's/-L //' \
|
||||||
-e 's/-I /--server-response /' \
|
-e 's/-I /--server-response /' \
|
||||||
-e 's/-s /-q /' \
|
-e 's/-s /-q /' \
|
||||||
|
-e 's/-sS /-nv /' \
|
||||||
-e 's/-o /-O /' \
|
-e 's/-o /-O /' \
|
||||||
-e 's/-C - /-c /')
|
-e 's/-C - /-c /')
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
@ -90,56 +126,76 @@ nvm_download() {
|
|||||||
install_nvm_from_git() {
|
install_nvm_from_git() {
|
||||||
local INSTALL_DIR
|
local INSTALL_DIR
|
||||||
INSTALL_DIR="$(nvm_install_dir)"
|
INSTALL_DIR="$(nvm_install_dir)"
|
||||||
|
local NVM_VERSION
|
||||||
if [ -d "$INSTALL_DIR/.git" ]; then
|
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
|
||||||
echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
|
if [ -n "${NVM_INSTALL_VERSION:-}" ]; then
|
||||||
command printf '\r=> '
|
# Check if version is an existing ref
|
||||||
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$(nvm_latest_version)" --depth=1 2> /dev/null || {
|
if command git ls-remote "$(nvm_source "git")" "$NVM_VERSION" | nvm_grep -q "$NVM_VERSION" ; then
|
||||||
echo >&2 "Failed to update nvm, run 'git fetch' in $INSTALL_DIR yourself."
|
:
|
||||||
|
# Check if version is an existing changeset
|
||||||
|
elif ! nvm_download -o /dev/null "$(nvm_source "script-nvm-exec")"; then
|
||||||
|
nvm_echo >&2 "Failed to find '$NVM_VERSION' version."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
local fetch_error
|
||||||
|
if [ -d "$INSTALL_DIR/.git" ]; then
|
||||||
|
# Updating repo
|
||||||
|
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
|
||||||
|
command printf '\r=> '
|
||||||
|
fetch_error="Failed to update nvm with $NVM_VERSION, run 'git fetch' in $INSTALL_DIR yourself."
|
||||||
else
|
else
|
||||||
# Cloning to $INSTALL_DIR
|
fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!"
|
||||||
echo "=> Downloading nvm from git to '$INSTALL_DIR'"
|
nvm_echo "=> Downloading nvm from git to '$INSTALL_DIR'"
|
||||||
command printf '\r=> '
|
command printf '\r=> '
|
||||||
mkdir -p "${INSTALL_DIR}"
|
mkdir -p "${INSTALL_DIR}"
|
||||||
if [ "$(ls -A "${INSTALL_DIR}")" ]; then
|
if [ "$(ls -A "${INSTALL_DIR}")" ]; then
|
||||||
|
# Initializing repo
|
||||||
command git init "${INSTALL_DIR}" || {
|
command git init "${INSTALL_DIR}" || {
|
||||||
echo >&2 'Failed to initialize nvm repo. Please report this!'
|
nvm_echo >&2 'Failed to initialize nvm repo. Please report this!'
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
command git --git-dir="${INSTALL_DIR}/.git" remote add origin "$(nvm_source)" 2> /dev/null \
|
command git --git-dir="${INSTALL_DIR}/.git" remote add origin "$(nvm_source)" 2> /dev/null \
|
||||||
|| command git --git-dir="${INSTALL_DIR}/.git" remote set-url origin "$(nvm_source)" || {
|
|| command git --git-dir="${INSTALL_DIR}/.git" remote set-url origin "$(nvm_source)" || {
|
||||||
echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
|
nvm_echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
|
||||||
exit 2
|
|
||||||
}
|
|
||||||
command git --git-dir="${INSTALL_DIR}/.git" fetch origin tag "$(nvm_latest_version)" --depth=1 || {
|
|
||||||
echo >&2 'Failed to fetch origin with tags. Please report this!'
|
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
command git -c advice.detachedHead=false clone "$(nvm_source)" -b "$(nvm_latest_version)" --depth=1 "${INSTALL_DIR}" || {
|
# Cloning repo
|
||||||
echo >&2 'Failed to clone nvm repo. Please report this!'
|
command git clone "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || {
|
||||||
|
nvm_echo >&2 'Failed to clone nvm repo. Please report this!'
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet "$(nvm_latest_version)"
|
# Try to fetch tag
|
||||||
|
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$NVM_VERSION" --depth=1 2>/dev/null; then
|
||||||
|
:
|
||||||
|
# Fetch given version
|
||||||
|
elif ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin "$NVM_VERSION" --depth=1; then
|
||||||
|
nvm_echo >&2 "$fetch_error"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet FETCH_HEAD || {
|
||||||
|
nvm_echo >&2 "Failed to checkout the given version $NVM_VERSION. Please report this!"
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
if [ -n "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then
|
if [ -n "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then
|
||||||
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
|
if command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
|
||||||
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
|
command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
|
||||||
else
|
else
|
||||||
echo >&2 "Your version of git is out of date. Please update it!"
|
nvm_echo >&2 "Your version of git is out of date. Please update it!"
|
||||||
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch -D master >/dev/null 2>&1
|
command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch -D master >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "=> Compressing and cleaning up git repository"
|
nvm_echo "=> Compressing and cleaning up git repository"
|
||||||
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" reflog expire --expire=now --all; then
|
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" reflog expire --expire=now --all; then
|
||||||
echo >&2 "Your version of git is out of date. Please update it!"
|
nvm_echo >&2 "Your version of git is out of date. Please update it!"
|
||||||
fi
|
fi
|
||||||
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" gc --auto --aggressive --prune=now ; then
|
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" gc --auto --aggressive --prune=now ; then
|
||||||
echo >&2 "Your version of git is out of date. Please update it!"
|
nvm_echo >&2 "Your version of git is out of date. Please update it!"
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -155,15 +211,15 @@ nvm_install_node() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
|
nvm_echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
|
||||||
nvm install "$NODE_VERSION_LOCAL"
|
nvm install "$NODE_VERSION_LOCAL"
|
||||||
local CURRENT_NVM_NODE
|
local CURRENT_NVM_NODE
|
||||||
|
|
||||||
CURRENT_NVM_NODE="$(nvm_version current)"
|
CURRENT_NVM_NODE="$(nvm_version current)"
|
||||||
if [ "$(nvm_version "$NODE_VERSION_LOCAL")" == "$CURRENT_NVM_NODE" ]; then
|
if [ "$(nvm_version "$NODE_VERSION_LOCAL")" == "$CURRENT_NVM_NODE" ]; then
|
||||||
echo "=> Node.js version $NODE_VERSION_LOCAL has been successfully installed"
|
nvm_echo "=> Node.js version $NODE_VERSION_LOCAL has been successfully installed"
|
||||||
else
|
else
|
||||||
echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
|
nvm_echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,20 +236,20 @@ install_nvm_as_script() {
|
|||||||
# Downloading to $INSTALL_DIR
|
# Downloading to $INSTALL_DIR
|
||||||
mkdir -p "$INSTALL_DIR"
|
mkdir -p "$INSTALL_DIR"
|
||||||
if [ -f "$INSTALL_DIR/nvm.sh" ]; then
|
if [ -f "$INSTALL_DIR/nvm.sh" ]; then
|
||||||
echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script"
|
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script"
|
||||||
else
|
else
|
||||||
echo "=> Downloading nvm as script to '$INSTALL_DIR'"
|
nvm_echo "=> Downloading nvm as script to '$INSTALL_DIR'"
|
||||||
fi
|
fi
|
||||||
nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || {
|
nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || {
|
||||||
echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"
|
nvm_echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"
|
||||||
return 1
|
return 1
|
||||||
} &
|
} &
|
||||||
nvm_download -s "$NVM_EXEC_SOURCE" -o "$INSTALL_DIR/nvm-exec" || {
|
nvm_download -s "$NVM_EXEC_SOURCE" -o "$INSTALL_DIR/nvm-exec" || {
|
||||||
echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
|
nvm_echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
|
||||||
return 2
|
return 2
|
||||||
} &
|
} &
|
||||||
nvm_download -s "$NVM_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || {
|
nvm_download -s "$NVM_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || {
|
||||||
echo >&2 "Failed to download '$NVM_BASH_COMPLETION_SOURCE'"
|
nvm_echo >&2 "Failed to download '$NVM_BASH_COMPLETION_SOURCE'"
|
||||||
return 2
|
return 2
|
||||||
} &
|
} &
|
||||||
for job in $(jobs -p | command sort)
|
for job in $(jobs -p | command sort)
|
||||||
@ -201,7 +257,7 @@ install_nvm_as_script() {
|
|||||||
wait "$job" || return $?
|
wait "$job" || return $?
|
||||||
done
|
done
|
||||||
chmod a+x "$INSTALL_DIR/nvm-exec" || {
|
chmod a+x "$INSTALL_DIR/nvm-exec" || {
|
||||||
echo >&2 "Failed to mark '$INSTALL_DIR/nvm-exec' as executable"
|
nvm_echo >&2 "Failed to mark '$INSTALL_DIR/nvm-exec' as executable"
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +266,7 @@ nvm_try_profile() {
|
|||||||
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
|
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo "${1}"
|
nvm_echo "${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -226,34 +282,38 @@ nvm_detect_profile() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
|
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
|
||||||
echo "${PROFILE}"
|
nvm_echo "${PROFILE}"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local DETECTED_PROFILE
|
local DETECTED_PROFILE
|
||||||
DETECTED_PROFILE=''
|
DETECTED_PROFILE=''
|
||||||
|
|
||||||
if [ -n "${BASH_VERSION-}" ]; then
|
if [ "${SHELL#*bash}" != "$SHELL" ]; then
|
||||||
if [ -f "$HOME/.bashrc" ]; then
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
DETECTED_PROFILE="$HOME/.bashrc"
|
DETECTED_PROFILE="$HOME/.bashrc"
|
||||||
elif [ -f "$HOME/.bash_profile" ]; then
|
elif [ -f "$HOME/.bash_profile" ]; then
|
||||||
DETECTED_PROFILE="$HOME/.bash_profile"
|
DETECTED_PROFILE="$HOME/.bash_profile"
|
||||||
fi
|
fi
|
||||||
elif [ -n "${ZSH_VERSION-}" ]; then
|
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
|
||||||
DETECTED_PROFILE="$HOME/.zshrc"
|
if [ -f "${ZDOTDIR:-${HOME}}/.zshrc" ]; then
|
||||||
|
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zshrc"
|
||||||
|
elif [ -f "${ZDOTDIR:-${HOME}}/.zprofile" ]; then
|
||||||
|
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zprofile"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$DETECTED_PROFILE" ]; then
|
if [ -z "$DETECTED_PROFILE" ]; then
|
||||||
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
|
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc"
|
||||||
do
|
do
|
||||||
if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
|
if DETECTED_PROFILE="$(nvm_try_profile "${ZDOTDIR:-${HOME}}/${EACH_PROFILE}")"; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$DETECTED_PROFILE" ]; then
|
if [ -n "$DETECTED_PROFILE" ]; then
|
||||||
echo "$DETECTED_PROFILE"
|
nvm_echo "$DETECTED_PROFILE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +322,9 @@ nvm_detect_profile() {
|
|||||||
# Node, and warn them if so.
|
# Node, and warn them if so.
|
||||||
#
|
#
|
||||||
nvm_check_global_modules() {
|
nvm_check_global_modules() {
|
||||||
command -v npm >/dev/null 2>&1 || return 0
|
local NPM_COMMAND
|
||||||
|
NPM_COMMAND="$(command -v npm 2>/dev/null)" || return 0
|
||||||
|
[ -n "${NVM_DIR}" ] && [ -z "${NPM_COMMAND%%"$NVM_DIR"/*}" ] && return 0
|
||||||
|
|
||||||
local NPM_VERSION
|
local NPM_VERSION
|
||||||
NPM_VERSION="$(npm --version)"
|
NPM_VERSION="$(npm --version)"
|
||||||
@ -284,68 +346,76 @@ nvm_check_global_modules() {
|
|||||||
|
|
||||||
if [ "${MODULE_COUNT}" != '0' ]; then
|
if [ "${MODULE_COUNT}" != '0' ]; then
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
echo '=> You currently have modules installed globally with `npm`. These will no'
|
nvm_echo '=> You currently have modules installed globally with `npm`. These will no'
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
echo '=> longer be linked to the active version of Node when you install a new node'
|
nvm_echo '=> longer be linked to the active version of Node when you install a new node'
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
echo '=> with `nvm`; and they may (depending on how you construct your `$PATH`)'
|
nvm_echo '=> with `nvm`; and they may (depending on how you construct your `$PATH`)'
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
echo '=> override the binaries of modules installed with `nvm`:'
|
nvm_echo '=> override the binaries of modules installed with `nvm`:'
|
||||||
echo
|
nvm_echo
|
||||||
|
|
||||||
command printf %s\\n "$NPM_GLOBAL_MODULES"
|
command printf %s\\n "$NPM_GLOBAL_MODULES"
|
||||||
echo '=> If you wish to uninstall them at a later point (or re-install them under your'
|
nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your'
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
echo '=> `nvm` Nodes), you can remove them from the system Node as follows:'
|
nvm_echo '=> `nvm` node installs), you can remove them from the system Node as follows:'
|
||||||
echo
|
nvm_echo
|
||||||
echo ' $ nvm use system'
|
nvm_echo ' $ nvm use system'
|
||||||
echo ' $ npm uninstall -g a_module'
|
nvm_echo ' $ npm uninstall -g a_module'
|
||||||
echo
|
nvm_echo
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_do_install() {
|
nvm_do_install() {
|
||||||
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then
|
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then
|
||||||
if [ -e "${NVM_DIR}" ]; then
|
if [ -e "${NVM_DIR}" ]; then
|
||||||
echo >&2 "File \"${NVM_DIR}\" has the same name as installation directory."
|
nvm_echo >&2 "File \"${NVM_DIR}\" has the same name as installation directory."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then
|
if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then
|
||||||
mkdir "${NVM_DIR}"
|
mkdir "${NVM_DIR}"
|
||||||
else
|
else
|
||||||
echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment."
|
nvm_echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
# Disable the optional which check, https://www.shellcheck.net/wiki/SC2230
|
||||||
|
# shellcheck disable=SC2230
|
||||||
|
if nvm_has xcode-select && [ "$(xcode-select -p >/dev/null 2>/dev/null ; echo $?)" = '2' ] && [ "$(which git)" = '/usr/bin/git' ] && [ "$(which curl)" = '/usr/bin/curl' ]; then
|
||||||
|
nvm_echo >&2 'You may be on a Mac, and need to install the Xcode Command Line Developer Tools.'
|
||||||
|
# shellcheck disable=SC2016
|
||||||
|
nvm_echo >&2 'If so, run `xcode-select --install` and try again. If not, please report this!'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
if [ -z "${METHOD}" ]; then
|
if [ -z "${METHOD}" ]; then
|
||||||
# Autodetect install method
|
# Autodetect install method
|
||||||
if nvm_has git; then
|
if nvm_has git; then
|
||||||
install_nvm_from_git
|
install_nvm_from_git
|
||||||
elif nvm_has nvm_download; then
|
elif nvm_has curl || nvm_has wget; then
|
||||||
install_nvm_as_script
|
install_nvm_as_script
|
||||||
else
|
else
|
||||||
echo >&2 'You need git, curl, or wget to install nvm'
|
nvm_echo >&2 'You need git, curl, or wget to install nvm'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif [ "${METHOD}" = 'git' ]; then
|
elif [ "${METHOD}" = 'git' ]; then
|
||||||
if ! nvm_has git; then
|
if ! nvm_has git; then
|
||||||
echo >&2 "You need git to install nvm"
|
nvm_echo >&2 "You need git to install nvm"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
install_nvm_from_git
|
install_nvm_from_git
|
||||||
elif [ "${METHOD}" = 'script' ]; then
|
elif [ "${METHOD}" = 'script' ]; then
|
||||||
if ! nvm_has nvm_download; then
|
if ! nvm_has curl && ! nvm_has wget; then
|
||||||
echo >&2 "You need curl or wget to install nvm"
|
nvm_echo >&2 "You need curl or wget to install nvm"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
install_nvm_as_script
|
install_nvm_as_script
|
||||||
else
|
else
|
||||||
echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method."
|
nvm_echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
nvm_echo
|
||||||
|
|
||||||
local NVM_PROFILE
|
local NVM_PROFILE
|
||||||
NVM_PROFILE="$(nvm_detect_profile)"
|
NVM_PROFILE="$(nvm_detect_profile)"
|
||||||
@ -363,32 +433,32 @@ nvm_do_install() {
|
|||||||
if [ -n "${PROFILE}" ]; then
|
if [ -n "${PROFILE}" ]; then
|
||||||
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
|
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
|
||||||
fi
|
fi
|
||||||
echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
|
nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zprofile, ~/.zshrc, and ~/.profile."
|
||||||
echo "=> Create one of them and run this script again"
|
nvm_echo "=> Create one of them and run this script again"
|
||||||
echo " OR"
|
nvm_echo " OR"
|
||||||
echo "=> Append the following lines to the correct file yourself:"
|
nvm_echo "=> Append the following lines to the correct file yourself:"
|
||||||
command printf "${SOURCE_STR}"
|
command printf "${SOURCE_STR}"
|
||||||
echo
|
nvm_echo
|
||||||
else
|
else
|
||||||
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
|
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
|
||||||
BASH_OR_ZSH=true
|
BASH_OR_ZSH=true
|
||||||
fi
|
fi
|
||||||
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
|
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
|
||||||
echo "=> Appending nvm source string to $NVM_PROFILE"
|
nvm_echo "=> Appending nvm source string to $NVM_PROFILE"
|
||||||
command printf "${SOURCE_STR}" >> "$NVM_PROFILE"
|
command printf "${SOURCE_STR}" >> "$NVM_PROFILE"
|
||||||
else
|
else
|
||||||
echo "=> nvm source string already in ${NVM_PROFILE}"
|
nvm_echo "=> nvm source string already in ${NVM_PROFILE}"
|
||||||
fi
|
fi
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
|
if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
|
||||||
echo "=> Appending bash_completion source string to $NVM_PROFILE"
|
nvm_echo "=> Appending bash_completion source string to $NVM_PROFILE"
|
||||||
command printf "$COMPLETION_STR" >> "$NVM_PROFILE"
|
command printf "$COMPLETION_STR" >> "$NVM_PROFILE"
|
||||||
else
|
else
|
||||||
echo "=> bash_completion source string already in ${NVM_PROFILE}"
|
nvm_echo "=> bash_completion source string already in ${NVM_PROFILE}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
|
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
|
||||||
echo "=> Please also append the following lines to the if you are using bash/zsh shell:"
|
nvm_echo "=> Please also append the following lines to the if you are using bash/zsh shell:"
|
||||||
command printf "${COMPLETION_STR}"
|
command printf "${COMPLETION_STR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -402,7 +472,7 @@ nvm_do_install() {
|
|||||||
|
|
||||||
nvm_reset
|
nvm_reset
|
||||||
|
|
||||||
echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"
|
nvm_echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"
|
||||||
command printf "${SOURCE_STR}"
|
command printf "${SOURCE_STR}"
|
||||||
if ${BASH_OR_ZSH} ; then
|
if ${BASH_OR_ZSH} ; then
|
||||||
command printf "${COMPLETION_STR}"
|
command printf "${COMPLETION_STR}"
|
||||||
@ -417,7 +487,7 @@ nvm_reset() {
|
|||||||
unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \
|
unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \
|
||||||
nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \
|
nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \
|
||||||
install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \
|
install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \
|
||||||
nvm_do_install nvm_reset nvm_default_install_dir
|
nvm_do_install nvm_reset nvm_default_install_dir nvm_grep
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install
|
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install
|
||||||
|
4
nvm-exec
4
nvm-exec
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
unset NVM_CD_FLAGS
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090,SC1091
|
||||||
\. "$DIR/nvm.sh" --no-use
|
\. "$DIR/nvm.sh" --no-use
|
||||||
|
|
||||||
if [ -n "$NODE_VERSION" ]; then
|
if [ -n "$NODE_VERSION" ]; then
|
||||||
|
25
package.json
25
package.json
@ -1,22 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "nvm",
|
"name": "nvm",
|
||||||
"version": "0.36.0",
|
"version": "0.40.3",
|
||||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
|
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
|
||||||
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=fast test-$shell",
|
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); env -i TERM=\"$TERM\" bash -lc \"make TEST_SUITE=fast test-$shell\"",
|
||||||
"test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
|
"test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
|
||||||
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
|
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
|
||||||
"test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs",
|
"test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs",
|
||||||
"test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell",
|
"test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell",
|
||||||
"test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",
|
"test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",
|
||||||
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",
|
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",
|
||||||
|
"test:check-exec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ ! -x \"$file\" ] && [[ \"$file\" != *.* ]] && [[ \"$file\" != test/fixtures/* ]]; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
|
||||||
|
"test:check-nonexec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ -x \"$file\" ] && [ ! -d \"$file\" ] && { [[ \"$file\" =~ '\\.(json|txt|sh|js|log)$' ]] || [[ \"$file\" =~ '^test/(mocks|fixtures)/.*' ]]; }; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
|
||||||
"doctoc": "doctoc --title='## Table of Contents' --github README.md",
|
"doctoc": "doctoc --title='## Table of Contents' --github README.md",
|
||||||
|
"predoctoc:check": "cp README.md v-README.md.orig && npm run doctoc",
|
||||||
|
"doctoc:check": "diff -q README.md v-README.md.orig",
|
||||||
|
"postdoctoc:check": "mv v-README.md.orig README.md",
|
||||||
"eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)",
|
"eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)",
|
||||||
"dockerfile_lint": "dockerfile_lint"
|
"dockerfile_lint": "dockerfile_lint",
|
||||||
|
"markdown-link-check": "git ls-files | command grep -E '\\.md$' | xargs -n 1 markdown-link-check -p"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -36,11 +42,12 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/nvm-sh/nvm",
|
"homepage": "https://github.com/nvm-sh/nvm",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dockerfile_lint": "^0.3.2",
|
"dockerfile_lint": "^0.3.4",
|
||||||
"eclint": "^2.6.0",
|
"doctoc": "^2.2.1",
|
||||||
"replace": "^0.3.0",
|
"eclint": "^2.8.1",
|
||||||
"semver": "^5.0.1",
|
"markdown-link-check": "^3.13.7",
|
||||||
"urchin": "^0.0.5",
|
"replace": "^1.2.2",
|
||||||
"doctoc": "^1.2.0"
|
"semver": "^7.7.1",
|
||||||
|
"urchin": "^0.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
rename_test.sh
Executable file
52
rename_test.sh
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
find_name(){
|
||||||
|
find test -name "*[\\/:\*\?\"<>\|]*" -o -name "*."
|
||||||
|
}
|
||||||
|
|
||||||
|
check_name() {
|
||||||
|
if [ "$(find_name | wc -l)" != "0" ]; then
|
||||||
|
printf '%s\n\n' "The following filenames contain unwanted characters:"
|
||||||
|
find_name
|
||||||
|
printf '\n%s\n%s\n' "Please run ./rename_test.sh" "If the problem persist, please open an issue."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Ok"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
rename_test() {
|
||||||
|
local filename
|
||||||
|
local new_filename
|
||||||
|
while read -r filename; do
|
||||||
|
# Even though it looks < and > are replaced by the same < and >, the latters are not ASCII code
|
||||||
|
# If you check with 'cat -v rename_test.sh' you would see 's/</M-KM-^B/g' and 's/>/M-KM-^C/g'
|
||||||
|
# M-KM-^B -> U+02C2
|
||||||
|
# M-KM-^C -> U+02C3
|
||||||
|
new_filename=$(echo "$filename" | sed -r \
|
||||||
|
-e "s/\"/'/g" \
|
||||||
|
-e 's/</˂/g' \
|
||||||
|
-e 's/>/˃/g' \
|
||||||
|
-e 's/^(.*)\.$/\1/'
|
||||||
|
)
|
||||||
|
printf '%s\n%s\n\n' "$filename" "$new_filename"
|
||||||
|
[ "$filename" != "$new_filename" ] && git mv "$filename" "$new_filename"
|
||||||
|
done < <(find_name)
|
||||||
|
|
||||||
|
if [ "$(find_name | wc -l)" != "0" ]; then
|
||||||
|
echo "Still some files to treat:"
|
||||||
|
find_name
|
||||||
|
else
|
||||||
|
echo "Done"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
if [ "$1" = "--check" ]; then
|
||||||
|
check_name
|
||||||
|
else
|
||||||
|
rename_test
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
144
test/common.sh
144
test/common.sh
@ -101,3 +101,147 @@ watch() {
|
|||||||
kill %2;
|
kill %2;
|
||||||
return $EXIT_CODE
|
return $EXIT_CODE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# JSON parsing from https://gist.github.com/assaf/ee377a186371e2e269a7
|
||||||
|
nvm_json_throw() {
|
||||||
|
nvm_err "$*"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_json_awk_egrep() {
|
||||||
|
local pattern_string
|
||||||
|
pattern_string="${1}"
|
||||||
|
|
||||||
|
awk '{
|
||||||
|
while ($0) {
|
||||||
|
start=match($0, pattern);
|
||||||
|
token=substr($0, start, RLENGTH);
|
||||||
|
print token;
|
||||||
|
$0=substr($0, start+RLENGTH);
|
||||||
|
}
|
||||||
|
}' "pattern=${pattern_string}"
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_json_tokenize() {
|
||||||
|
local GREP
|
||||||
|
GREP='grep -Eao'
|
||||||
|
|
||||||
|
local ESCAPE
|
||||||
|
local CHAR
|
||||||
|
|
||||||
|
# if echo "test string" | grep -Eo "test" > /dev/null 2>&1; then
|
||||||
|
# ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
|
||||||
|
# CHAR='[^[:cntrl:]"\\]'
|
||||||
|
# else
|
||||||
|
GREP=nvm_json_awk_egrep
|
||||||
|
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
|
||||||
|
CHAR='[^[:cntrl:]"\\\\]'
|
||||||
|
# fi
|
||||||
|
|
||||||
|
local STRING
|
||||||
|
STRING="\"${CHAR}*(${ESCAPE}${CHAR}*)*\""
|
||||||
|
local NUMBER
|
||||||
|
NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
|
||||||
|
local KEYWORD
|
||||||
|
KEYWORD='null|false|true'
|
||||||
|
local SPACE
|
||||||
|
SPACE='[[:space:]]+'
|
||||||
|
|
||||||
|
$GREP "${STRING}|${NUMBER}|${KEYWORD}|${SPACE}|." | TERM=dumb grep -Ev "^${SPACE}$"
|
||||||
|
}
|
||||||
|
|
||||||
|
_json_parse_array() {
|
||||||
|
local index=0
|
||||||
|
local ary=''
|
||||||
|
read -r token
|
||||||
|
case "$token" in
|
||||||
|
']') ;;
|
||||||
|
*)
|
||||||
|
while :; do
|
||||||
|
_json_parse_value "${1}" "${index}"
|
||||||
|
index=$((index+1))
|
||||||
|
ary="${ary}${value}"
|
||||||
|
read -r token
|
||||||
|
case "${token}" in
|
||||||
|
']') break ;;
|
||||||
|
',') ary="${ary}," ;;
|
||||||
|
*) nvm_json_throw "EXPECTED , or ] GOT ${token:-EOF}" ;;
|
||||||
|
esac
|
||||||
|
read -r token
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
_json_parse_object() {
|
||||||
|
local key
|
||||||
|
local obj=''
|
||||||
|
read -r token
|
||||||
|
case "$token" in
|
||||||
|
'}') ;;
|
||||||
|
*)
|
||||||
|
while :; do
|
||||||
|
case "${token}" in
|
||||||
|
'"'*'"') key="${token}" ;;
|
||||||
|
*) nvm_json_throw "EXPECTED string GOT ${token:-EOF}" ;;
|
||||||
|
esac
|
||||||
|
read -r token
|
||||||
|
case "${token}" in
|
||||||
|
':') ;;
|
||||||
|
*) nvm_json_throw "EXPECTED : GOT ${token:-EOF}" ;;
|
||||||
|
esac
|
||||||
|
read -r token
|
||||||
|
_json_parse_value "${1}" "${key}"
|
||||||
|
obj="${obj}${key}:${value}"
|
||||||
|
read -r token
|
||||||
|
case "${token}" in
|
||||||
|
'}') break ;;
|
||||||
|
',') obj="${obj}," ;;
|
||||||
|
*) nvm_json_throw "EXPECTED , or } GOT ${token:-EOF}" ;;
|
||||||
|
esac
|
||||||
|
read -r token
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
_json_parse_value() {
|
||||||
|
local jpath="${1:+$1,}$2"
|
||||||
|
local isleaf=0
|
||||||
|
local isempty=0
|
||||||
|
local print=0
|
||||||
|
|
||||||
|
case "$token" in
|
||||||
|
'{') _json_parse_object "${jpath}" ;;
|
||||||
|
'[') _json_parse_array "${jpath}" ;;
|
||||||
|
# At this point, the only valid single-character tokens are digits.
|
||||||
|
''|[!0-9]) nvm_json_throw "EXPECTED value GOT >${token:-EOF}<" ;;
|
||||||
|
*)
|
||||||
|
value=$token
|
||||||
|
isleaf=1
|
||||||
|
[ "${value}" = '""' ] && isempty=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
[ "${value}" = '' ] && return
|
||||||
|
[ "${isleaf}" -eq 1 ] && [ $isempty -eq 0 ] && print=1
|
||||||
|
[ "${print}" -eq 1 ] && printf "[%s]\t%s\n" "${jpath}" "${value}"
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
|
_json_parse() {
|
||||||
|
read -r token
|
||||||
|
_json_parse_value
|
||||||
|
read -r token
|
||||||
|
case "${token}" in
|
||||||
|
'') ;;
|
||||||
|
*) nvm_json_throw "EXPECTED EOF GOT >${token}<" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_json_extract() {
|
||||||
|
nvm_json_tokenize | _json_parse | grep -e "${1}" | awk '{print $2 $3}'
|
||||||
|
}
|
||||||
|
20
test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file
Executable file
20
test/fast/Aliases/'nvm alias' should ignore leading blank lines in the file
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die() { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../../.. && pwd)"
|
||||||
|
|
||||||
|
\. "${NVM_DIR}/nvm.sh"
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
echo "
|
||||||
|
|
||||||
|
v0.0.1
|
||||||
|
" > ../../../alias/test-blank-lines
|
||||||
|
|
||||||
|
EXPECTED='v0.0.1'
|
||||||
|
ACTUAL="$(nvm_alias test-blank-lines)"
|
||||||
|
EXIT_CODE="$(nvm_alias test-blank-lines 2>&1 >/dev/null; echo $?)"
|
||||||
|
|
||||||
|
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
|
||||||
|
[ "${EXIT_CODE}" = '0' ] || die "expected exit code 0, got ${EXIT_CODE}"
|
26
test/fast/Aliases/'nvm alias' should not accept aliases with a hash
Executable file
26
test/fast/Aliases/'nvm alias' should not accept aliases with a hash
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
OUTPUT="$(nvm alias foo#bar baz 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases with a comment delimiter (#) are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias with a hash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm alias foo#bar baz >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias with a hash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm alias foo# baz 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases with a comment delimiter (#) are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias ending with a hash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm alias foo# baz >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias ending with a hash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm alias \#bar baz 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases with a comment delimiter (#) are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias starting with a hash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm alias \#bar baz >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias starting with a hash should fail with code 1, got '$EXIT_CODE'"
|
22
test/fast/Aliases/nvm_list_aliases calls nvm_get_colors
Executable file
22
test/fast/Aliases/nvm_list_aliases calls nvm_get_colors
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
nvm_get_colors(){
|
||||||
|
echo "0;95m"
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_alias_path() {
|
||||||
|
nvm_echo "../../../alias"
|
||||||
|
}
|
||||||
|
|
||||||
|
OUTPUT=$(command printf %b $(nvm_list_aliases test-stable-1) | awk '{ print substr($0, 1, 19); }')
|
||||||
|
|
||||||
|
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1" | awk '{ print substr($0, 1, 19); }')
|
||||||
|
echo "\033[0m"
|
||||||
|
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
31
test/fast/Aliases/nvm_list_aliases works with LTS aliases
Executable file
31
test/fast/Aliases/nvm_list_aliases works with LTS aliases
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
MOCKS_DIR="../Unit tests/mocks"
|
||||||
|
|
||||||
|
# sample output at the time the test was written
|
||||||
|
TAB_PATH="$MOCKS_DIR/nodejs.org-dist-index.tab"
|
||||||
|
nvm_download() {
|
||||||
|
cat "$TAB_PATH"
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_alias_path() {
|
||||||
|
nvm_echo "../../../alias"
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm ls-remote >/dev/null || die 'nvm ls-remote (to populate LTS aliases) failed'
|
||||||
|
|
||||||
|
EXPECTED_OUTPUT="$(cat "$MOCKS_DIR/lts-star.txt")"
|
||||||
|
STDOUT_OUTPUT="$(nvm_list_aliases "lts/*")"
|
||||||
|
STDERR_OUTPUT="$(nvm_list_aliases "lts/*" 2>&1 >/dev/null)"
|
||||||
|
|
||||||
|
[ -z "${STDERR_OUTPUT}" ] || die "expected no stderr output, got >${STDERR_OUTPUT}<"
|
||||||
|
[ "${STDOUT_OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected ${EXPECTED_OUTPUT}, got >${STDOUT_OUTPUT}<"
|
21
test/fast/Aliases/nvm_list_aliases works with no LTS aliases present
Executable file
21
test/fast/Aliases/nvm_list_aliases works with no LTS aliases present
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () {
|
||||||
|
mv "$(nvm_alias_path)/_lts.bak" "$(nvm_alias_path)/lts"
|
||||||
|
echo "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
nvm_alias_path() {
|
||||||
|
nvm_echo "../../../alias"
|
||||||
|
}
|
||||||
|
|
||||||
|
mv "$(nvm_alias_path)/lts" "$(nvm_alias_path)/_lts.bak"
|
||||||
|
|
||||||
|
STDERR_OUTPUT="$(nvm_list_aliases 2>&1 >/dev/null)"
|
||||||
|
|
||||||
|
[ -z "${STDERR_OUTPUT}" ] || die "expected no stderr output, got >${STDERR_OUTPUT}<"
|
28
test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors
Executable file
28
test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () {
|
||||||
|
# echo "$@" ;
|
||||||
|
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
nvm_get_colors(){
|
||||||
|
echo "0;95m"
|
||||||
|
}
|
||||||
|
|
||||||
|
# nvm_print_alias_path call nvm_print_formatted_alias which calls nvm_get-colors
|
||||||
|
# the output of nvm_print_alias_path uses the color code returned by nvm_get_colors (redefined above)
|
||||||
|
NVM_ALIAS_DIR='../../../alias'
|
||||||
|
|
||||||
|
OUTPUT=$(command printf %b $(nvm_print_alias_path "$NVM_ALIAS_DIR" "$NVM_ALIAS_DIR"/test-stable-1) | awk '{ print substr($0, 1, 24); }')
|
||||||
|
|
||||||
|
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1\033[0m")
|
||||||
|
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||||
|
|
||||||
|
|
||||||
|
set +e
|
21
test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors
Executable file
21
test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
# # # expecting in red and two grays:
|
||||||
|
OUTPUT=$(echo $(nvm_print_formatted_alias fakealias fakedest) | awk '{ print substr($0, 1, 21); }')
|
||||||
|
EXPECTED_OUTPUT="$(command printf %b "\033[0;31mfakealias\033[0m ")"
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||||
|
|
||||||
|
# expecting in bold yellow and two grays:
|
||||||
|
nvm set-colors bbbYb
|
||||||
|
OUTPUT=$(echo $(nvm_print_formatted_alias fakealias fakedest) | awk '{ print substr($0, 1, 21); }')
|
||||||
|
EXPECTED_OUTPUT="$(command printf %b "\033[1;33mfakealias\033[0m ")"
|
||||||
|
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
die () { echo "$@" ; exit 1; }
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
export NVM_DIR="$(cd ../../.. && pwd)"
|
||||||
|
|
||||||
|
\. "${NVM_DIR}/nvm.sh"
|
||||||
|
|
||||||
EXIT_CODE=$(nvm_resolve_alias ; echo $?)
|
EXIT_CODE=$(nvm_resolve_alias ; echo $?)
|
||||||
[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE"
|
[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE"
|
||||||
@ -31,3 +33,17 @@ UNSTABLE="$(nvm_resolve_alias unstable)"
|
|||||||
|
|
||||||
IOJS="$(nvm_resolve_alias iojs)"
|
IOJS="$(nvm_resolve_alias iojs)"
|
||||||
[ "_$IOJS" = "_iojs-v0.2" ] || die "'nvm_resolve_alias iojs' was not iojs-v0.2; got $IOJS"
|
[ "_$IOJS" = "_iojs-v0.2" ] || die "'nvm_resolve_alias iojs' was not iojs-v0.2; got $IOJS"
|
||||||
|
|
||||||
|
echo "
|
||||||
|
|
||||||
|
v0.0.1
|
||||||
|
v0.0.2
|
||||||
|
v0.0.3
|
||||||
|
" > ../../../alias/test-multi-lines
|
||||||
|
|
||||||
|
EXPECTED='v0.0.1'
|
||||||
|
ACTUAL="$(nvm_resolve_alias test-multi-lines)"
|
||||||
|
EXIT_CODE="$(nvm_resolve_alias test-multi-lines 2>&1 >/dev/null; echo $?)"
|
||||||
|
|
||||||
|
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
|
||||||
|
[ "${EXIT_CODE}" = '0' ] || die "expected exit code 0, got ${EXIT_CODE}"
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../../.. && pwd)"
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
\. ../../common.sh
|
\. ../../common.sh
|
||||||
|
|
||||||
|
@ -15,3 +15,5 @@ rm -f "../../../alias/unstable"
|
|||||||
rm -f "../../../alias/node"
|
rm -f "../../../alias/node"
|
||||||
rm -f "../../../alias/iojs"
|
rm -f "../../../alias/iojs"
|
||||||
rm -f "../../../alias/default"
|
rm -f "../../../alias/default"
|
||||||
|
rm -f "../../../alias/test-blank-lines"
|
||||||
|
rm -f "../../../alias/test-multi-lines"
|
||||||
|
42
test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash
Executable file
42
test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../../.. && pwd)"
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
if type setopt >/dev/null 2>&1; then setopt local_options markdirs; fi
|
||||||
|
|
||||||
|
die () {
|
||||||
|
if type unsetopt >/dev/null 2>&1; then unsetopt local_options markdirs; fi
|
||||||
|
echo "$@";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
make_fake_node v0.0.1
|
||||||
|
make_fake_node v0.0.3
|
||||||
|
make_fake_node v0.0.9
|
||||||
|
make_fake_node v0.3.1
|
||||||
|
make_fake_node v0.3.3
|
||||||
|
make_fake_node v0.3.9
|
||||||
|
make_fake_node v0.12.87
|
||||||
|
make_fake_node v0.12.9
|
||||||
|
make_fake_iojs v0.1.2
|
||||||
|
make_fake_iojs v0.10.2
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_ls)"
|
||||||
|
EXPECTED_OUTPUT="v0.0.1
|
||||||
|
v0.0.3
|
||||||
|
v0.0.9
|
||||||
|
iojs-v0.1.2
|
||||||
|
v0.3.1
|
||||||
|
v0.3.3
|
||||||
|
v0.3.9
|
||||||
|
iojs-v0.10.2
|
||||||
|
v0.12.9
|
||||||
|
v0.12.87"
|
||||||
|
if nvm_has_system_node || nvm_has_system_iojs; then
|
||||||
|
EXPECTED_OUTPUT="${EXPECTED_OUTPUT}
|
||||||
|
system"
|
||||||
|
fi
|
||||||
|
[ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../.. && pwd)"
|
||||||
|
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
|
|
||||||
nvm alias test v0.1.2
|
nvm alias test v0.1.2
|
@ -4,6 +4,8 @@ set -ex
|
|||||||
|
|
||||||
die () { echo "$@" ; exit 1; }
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../.. && pwd)"
|
||||||
|
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
|
|
||||||
nvm deactivate 2>&1
|
nvm deactivate 2>&1
|
@ -4,6 +4,8 @@ set -ex
|
|||||||
|
|
||||||
die () { echo "$@" ; exit 1; }
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../.. && pwd)"
|
||||||
|
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
\. ../common.sh
|
\. ../common.sh
|
||||||
|
|
@ -7,6 +7,8 @@ cleanup () {
|
|||||||
rm -rf "${NVM_DIR}/v0.10.4"
|
rm -rf "${NVM_DIR}/v0.10.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../.. && pwd)"
|
||||||
|
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
\. ../common.sh
|
\. ../common.sh
|
||||||
|
|
@ -4,6 +4,8 @@ set -ex
|
|||||||
|
|
||||||
die () { echo "$@" ; exit 1; }
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
export NVM_DIR="$(cd ../.. && pwd)"
|
||||||
|
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
|
|
||||||
set +ex # needed for stderr
|
set +ex # needed for stderr
|
@ -5,11 +5,11 @@ set -ex
|
|||||||
BEFORE="./before.tmp"
|
BEFORE="./before.tmp"
|
||||||
AFTER="./after.tmp"
|
AFTER="./after.tmp"
|
||||||
|
|
||||||
cleanup () { echo rm -f "${BEFORE}" "${AFTER}"; }
|
cleanup () { rm -f "${BEFORE}" "${AFTER}"; }
|
||||||
die () { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}"
|
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}"
|
||||||
env | grep -v PATH= | grep -v IFS= | grep -v NVM_ | sort >> "${BEFORE}"
|
env | grep -v PATH= | grep -v IFS= | grep -v NVM_ | grep -v TRAVIS_ | sort >> "${BEFORE}"
|
||||||
|
|
||||||
set +e # TODO: fix
|
set +e # TODO: fix
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
@ -20,11 +20,11 @@ type nvm > /dev/null 2>&1 || die "nvm not loaded"
|
|||||||
nvm unload
|
nvm unload
|
||||||
|
|
||||||
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${AFTER}"
|
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${AFTER}"
|
||||||
env | grep -v PATH= | grep -v IFS= | sort >> "${AFTER}"
|
env | grep -v PATH= | grep -v IFS= | grep -v TRAVIS_ | sort >> "${AFTER}"
|
||||||
|
|
||||||
! type nvm > /dev/null 2>&1 || die "nvm not unloaded"
|
! type nvm > /dev/null 2>&1 || die "nvm not unloaded"
|
||||||
|
|
||||||
DIFF="$(diff "${BEFORE}" "${AFTER}" ||:)"
|
DIFF="$(diff "${BEFORE}" "${AFTER}" ||:)"
|
||||||
[ -z "${DIFF}" ] || die "function pollution found: ${DIFF}"
|
[ -z "${DIFF}" ] || die "function pollution found: >${DIFF}<"
|
||||||
|
|
||||||
cleanup
|
cleanup
|
@ -27,7 +27,9 @@ EXPECTED_OUTPUT="$(nvm_add_iojs_prefix ${VERSION})"
|
|||||||
|
|
||||||
nvm use --delete-prefix iojs || die '`nvm use iojs` failed'
|
nvm use --delete-prefix iojs || die '`nvm use iojs` failed'
|
||||||
|
|
||||||
CURRENT="$(nvm current)"
|
# Remove node_modules/.bin from the path so that the system version `which` is
|
||||||
|
# used in nvm_ls_current
|
||||||
|
PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "node_modules/.bin" | tr "\n" ":") CURRENT="$(nvm current)"
|
||||||
echo "current: ${CURRENT}"
|
echo "current: ${CURRENT}"
|
||||||
|
|
||||||
[ "${CURRENT}" = "${IOJS_VERSION}" ] || die "expected >${IOJS_VERSION}<; got >${CURRENT}<"
|
[ "${CURRENT}" = "${IOJS_VERSION}" ] || die "expected >${IOJS_VERSION}<; got >${CURRENT}<"
|
21
test/fast/Set Colors/nvm_echo_with_colors
Executable file
21
test/fast/Set Colors/nvm_echo_with_colors
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
echo "Tested nvm_echo_with_colors"
|
||||||
|
}
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_echo_with_colors "\033[0;36mCyan-colored text")"
|
||||||
|
EXPECTED_OUTPUT=$(printf "\033[0;36mCyan-colored text")
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die
|
||||||
|
|
||||||
|
cleanup
|
19
test/fast/Set Colors/nvm_err_with_colors
Executable file
19
test/fast/Set Colors/nvm_err_with_colors
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
echo "Tested nvm_err_with_colors"
|
||||||
|
}
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
set +ex
|
||||||
|
OUTPUT="$(nvm_err_with_colors "\033[0;35mMagenta-colored text" 2>&1)"
|
||||||
|
set -ex
|
||||||
|
EXPECTED_OUTPUT=$(printf "\033[0;35mMagenta-colored text")
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die
|
||||||
|
|
||||||
|
cleanup
|
24
test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors
Executable file
24
test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () {
|
||||||
|
# echo "$@" ;
|
||||||
|
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
nvm_get_colors(){
|
||||||
|
echo "0;95m"
|
||||||
|
}
|
||||||
|
|
||||||
|
# nvm_print_default_alias call nvm_print_formatted_alias which calls nvm_get-colors
|
||||||
|
# the output of nvm_print_default_alias uses the color code returned by nvm_get_colors (redefined above)
|
||||||
|
OUTPUT=$(command printf %b $(nvm_print_default_alias node ./alias v14.7.0) | awk '{ print substr($0, 1, 11); }')
|
||||||
|
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mnode")
|
||||||
|
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||||
|
|
||||||
|
set +e
|
52
test/fast/Set Colors/nvm_print_versions calls nvm_get_colors
Executable file
52
test/fast/Set Colors/nvm_print_versions calls nvm_get_colors
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
die () {
|
||||||
|
# echo "$@" ;
|
||||||
|
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
cleanup() {
|
||||||
|
if [ -n TEMP_NVM_COLORS ]; then
|
||||||
|
export NVM_COLORS=TEMP_NVM_COLORS
|
||||||
|
fi
|
||||||
|
unset TEMP_NVM_COLORS
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n ${NVM_COLORS} ]; then
|
||||||
|
export TEMP_NVM_COLORS=NVM_COLORS
|
||||||
|
unset NVM_COLORS
|
||||||
|
fi
|
||||||
|
|
||||||
|
# default system color
|
||||||
|
nvm use system
|
||||||
|
OUTPUT=$(nvm_print_versions system)
|
||||||
|
FORMAT="\033[0;32m-> %12s\033[0m"
|
||||||
|
VERSION='system'
|
||||||
|
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
|
||||||
|
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||||
|
|
||||||
|
nvm_ls_current() { echo "current";}
|
||||||
|
|
||||||
|
# default current color
|
||||||
|
OUTPUT=$(nvm_print_versions current)
|
||||||
|
FORMAT="\033[0;32m-> %12s\033[0m"
|
||||||
|
VERSION="current"
|
||||||
|
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
|
||||||
|
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||||
|
|
||||||
|
# custom current color
|
||||||
|
nvm set-colors YCMGR
|
||||||
|
OUTPUT=$(nvm_print_versions current)
|
||||||
|
FORMAT="\033[1;35m-> %12s\033[0m"
|
||||||
|
VERSION="current"
|
||||||
|
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
|
||||||
|
|
||||||
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||||
|
|
||||||
|
cleanup
|
61
test/fast/Unit tests/Running 'nvm install --save' works as expected'
Executable file
61
test/fast/Unit tests/Running 'nvm install --save' works as expected'
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TEST_VERSION='v0.2.4'
|
||||||
|
|
||||||
|
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
nvm cache clear
|
||||||
|
nvm deactivate
|
||||||
|
nvm unalias default
|
||||||
|
rm -rf "${NVM_DIR}/v0.2.4" .nvmrc
|
||||||
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
||||||
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
|
}
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$@"
|
||||||
|
cleanup
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
||||||
|
nvm_ls_remote() {
|
||||||
|
if [ -n "${PATTERN}" ]; then
|
||||||
|
cat "${REMOTE}" | \grep "${PATTERN}"
|
||||||
|
else
|
||||||
|
cat "${REMOTE}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
local PATTERN
|
||||||
|
PATTERN="${1-}"
|
||||||
|
if [ -n "${PATTERN}" ]; then
|
||||||
|
cat "${REMOTE_IOJS}" | \grep "${PATTERN}"
|
||||||
|
else
|
||||||
|
cat "${REMOTE_IOJS}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
make_fake_node "${TEST_VERSION}"
|
||||||
|
|
||||||
|
nvm install -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"
|
||||||
|
OUTPUT="$(cat .nvmrc)"
|
||||||
|
|
||||||
|
nvm_is_valid_version "${OUTPUT}" \
|
||||||
|
|| die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
||||||
|
|
||||||
|
rm .nvmrc || die 'removing of .nvmrc failed'
|
||||||
|
|
||||||
|
nvm install --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"
|
||||||
|
OUTPUT="$(cat .nvmrc)"
|
||||||
|
|
||||||
|
nvm_is_valid_version "${OUTPUT}" \
|
||||||
|
|| die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
||||||
|
|
||||||
|
cleanup
|
61
test/fast/Unit tests/Running 'nvm use --save' works as expected'
Executable file
61
test/fast/Unit tests/Running 'nvm use --save' works as expected'
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TEST_VERSION='v0.2.4'
|
||||||
|
|
||||||
|
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
nvm cache clear
|
||||||
|
nvm deactivate
|
||||||
|
nvm unalias default
|
||||||
|
rm -rf "${NVM_DIR}/v0.2.4" .nvmrc
|
||||||
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
||||||
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
|
}
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$@"
|
||||||
|
cleanup
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
||||||
|
nvm_ls_remote() {
|
||||||
|
if [ -n "${PATTERN}" ]; then
|
||||||
|
cat "${REMOTE}" | \grep "${PATTERN}"
|
||||||
|
else
|
||||||
|
cat "${REMOTE}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
local PATTERN
|
||||||
|
PATTERN="${1-}"
|
||||||
|
if [ -n "${PATTERN}" ]; then
|
||||||
|
cat "${REMOTE_IOJS}" | \grep "${PATTERN}"
|
||||||
|
else
|
||||||
|
cat "${REMOTE_IOJS}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
make_fake_node "${TEST_VERSION}"
|
||||||
|
|
||||||
|
nvm use -w "${TEST_VERSION}" || die "\`nvm install -w ${TEST_VERSION}\` failed"
|
||||||
|
OUTPUT="$(cat .nvmrc)"
|
||||||
|
|
||||||
|
nvm_is_valid_version "${OUTPUT}" \
|
||||||
|
|| die "\`nvm install -w ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
||||||
|
|
||||||
|
rm .nvmrc || die 'removing of .nvmrc failed'
|
||||||
|
|
||||||
|
nvm use --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"
|
||||||
|
OUTPUT="$(cat .nvmrc)"
|
||||||
|
|
||||||
|
nvm_is_valid_version "${OUTPUT}" \
|
||||||
|
|| die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|
||||||
|
|
||||||
|
cleanup
|
@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TEST_VERSION="v0.2.4"
|
||||||
|
|
||||||
|
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
||||||
|
if [ -f ../.nvmrc ]; then mv ../.nvmrc ../.nvmrc.orig; fi
|
||||||
|
|
||||||
|
del_nvmrc () {
|
||||||
|
rm -f .nvmrc ../.nvmrc
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup () {
|
||||||
|
del_nvmrc
|
||||||
|
nvm cache clear
|
||||||
|
nvm deactivate
|
||||||
|
nvm unalias default
|
||||||
|
rm -rf ${NVM_DIR}/v*
|
||||||
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
||||||
|
if [ -f ../.nvmrc.orig ]; then mv ../.nvmrc.orig ../.nvmrc; fi
|
||||||
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo "$@"
|
||||||
|
cleanup
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
REMOTE="$PWD/mocks/nvm_ls_remote.txt"
|
||||||
|
nvm_ls_remote() {
|
||||||
|
cat "$REMOTE"
|
||||||
|
}
|
||||||
|
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
cat "$REMOTE_IOJS"
|
||||||
|
}
|
||||||
|
|
||||||
|
del_nvmrc
|
||||||
|
make_fake_node "$TEST_VERSION"
|
||||||
|
|
||||||
|
(cd ..
|
||||||
|
nvm use --save "$TEST_VERSION" || die "\`nvm use --save $TEST_VERSION\` failed in the parent dir")
|
||||||
|
nvm use --save || die "\`nvm use --save\` failed"
|
||||||
|
|
||||||
|
[ -f ../.nvmrc ] && [ -f .nvmrc ] || die "expected two .nvmrc files to be generated"
|
||||||
|
|
||||||
|
OUTPUT=$(cat .nvmrc)
|
||||||
|
EXPECTED_OUTPUT="$(cat ../.nvmrc)"
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|
|| die "invalid \`nvm use --save \` output: expected '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
|
cleanup
|
@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
TEST_VERSION="v0.2.4"
|
||||||
|
|
||||||
|
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
||||||
|
|
||||||
|
cleanup () {
|
||||||
|
nvm cache clear
|
||||||
|
nvm deactivate
|
||||||
|
nvm unalias default
|
||||||
|
rm -rf "${NVM_DIR}/${TEST_VERSION:?}" .nvmrc
|
||||||
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
||||||
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo "$@"
|
||||||
|
cleanup
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
||||||
|
nvm_ls_remote() {
|
||||||
|
cat "${REMOTE}"
|
||||||
|
}
|
||||||
|
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
cat "${REMOTE_IOJS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_fake_node "${TEST_VERSION}"
|
||||||
|
|
||||||
|
OUTPUT=$(nvm use --save --silent "${TEST_VERSION}" || die "\`nvm use --save --silent ${TEST_VERSION}\` failed")
|
||||||
|
EXPECTED_OUTPUT=''
|
||||||
|
|
||||||
|
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|
||||||
|
|| die "\`nvm use --save --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"
|
||||||
|
|
||||||
|
rm .nvmrc || die 'removing of .nvmrc failed'
|
||||||
|
|
||||||
|
OUTPUT=$(nvm use -w --silent "${TEST_VERSION}" || die "\`nvm use -w --silent ${TEST_VERSION}\` failed")
|
||||||
|
EXPECTED_OUTPUT=''
|
||||||
|
|
||||||
|
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|
||||||
|
|| die "\`nvm use -w --silent ${TEST_VERSION}\` output was not silenced to '${EXPECTED_OUTPUT}'; got '${OUTPUT}'"
|
||||||
|
|
||||||
|
cleanup
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user