mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-09-04 19:49:36 +00:00
Compare commits
406 Commits
v0.35.2
...
28cb7eb035
Author | SHA1 | Date | |
---|---|---|---|
![]() |
28cb7eb035 | ||
![]() |
9602f4f959 | ||
![]() |
c3d674f8f9 | ||
![]() |
0215ef8203 | ||
![]() |
1aab8b2d5a | ||
![]() |
977563e97d | ||
![]() |
99352a64d2 | ||
![]() |
ffec9fec72 | ||
![]() |
df9ac58f8b | ||
![]() |
8dbc22f0e9 | ||
![]() |
5c12680a62 | ||
![]() |
f0f8ed12f8 | ||
![]() |
759f70f196 | ||
![]() |
06a9179309 | ||
![]() |
74eb396099 | ||
![]() |
c04530396e | ||
![]() |
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 | ||
![]() |
8debf39f24 | ||
![]() |
c7ca08d575 | ||
![]() |
6110d31969 | ||
![]() |
68d2f47c0a | ||
![]() |
6e0562ac6d | ||
![]() |
68d331a816 | ||
![]() |
22e07cc0c1 | ||
![]() |
cf92956e5d | ||
![]() |
1d88ecfce5 | ||
![]() |
035bf9e28e | ||
![]() |
f7fbad2bd6 | ||
![]() |
19c55b9936 | ||
![]() |
9dc6f3e4a5 | ||
![]() |
1c00753fd9 | ||
![]() |
b1200c659b | ||
![]() |
16b75b7333 | ||
![]() |
1bf567bd0b | ||
![]() |
a01deb11dc | ||
![]() |
a5aec107df | ||
![]() |
18c6f98acc | ||
![]() |
424aeb38b4 | ||
![]() |
abfe0a5891 | ||
![]() |
3561bbc54a | ||
![]() |
83043c4d3a | ||
![]() |
55eafcd814 | ||
![]() |
06c3bf6a8f | ||
![]() |
4b1100e515 | ||
![]() |
f6d11bae41 | ||
![]() |
d2d232ea2b | ||
![]() |
7b3af45cf7 | ||
![]() |
bac5393e12 | ||
![]() |
2d4e877b61 | ||
![]() |
6575b6b052 | ||
![]() |
33fa27dabe | ||
![]() |
91a55dd91a | ||
![]() |
7aba64a2d5 | ||
![]() |
dcc8059ef8 | ||
![]() |
8e1e5df059 | ||
![]() |
e0ed1eacfd | ||
![]() |
73438e339e | ||
![]() |
b02617028f | ||
![]() |
f607f2f783 | ||
![]() |
258938ef66 | ||
![]() |
096ba0d8c3 | ||
![]() |
4626d1aae6 | ||
![]() |
c372ff03e0 | ||
![]() |
30cd9c5dc8 | ||
![]() |
b9536327ae | ||
![]() |
e609091a55 | ||
![]() |
8093dbeacd | ||
![]() |
4cd6b4822c | ||
![]() |
6c560b12b6 | ||
![]() |
f4eddb2c9c | ||
![]() |
a1ad32e9cb | ||
![]() |
d8785da988 | ||
![]() |
4ff9084e99 | ||
![]() |
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 |
@@ -8,6 +8,7 @@ test/bak
|
||||
.urchin.log
|
||||
.urchin_stdout
|
||||
test/**/test_output
|
||||
test/**/.nvmrc
|
||||
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
|
@@ -12,11 +12,24 @@ trim_trailing_whitespace = true
|
||||
[*.txt]
|
||||
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
|
||||
|
||||
[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
|
||||
|
||||
[test/fast/Unit tests/mocks/**]
|
||||
insert_final_newline = off
|
||||
|
||||
[test/**/.urchin*]
|
||||
insert_final_newline = off
|
||||
|
||||
[Makefile]
|
||||
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
|
||||
|
117
.github/INCIDENT_RESPONSE_PLAN.md
vendored
Normal file
117
.github/INCIDENT_RESPONSE_PLAN.md
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
# Incident Response Process for **nvm**
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
We take the security of **nvm** very seriously. If you believe you’ve found a security vulnerability, please inform us responsibly through coordinated disclosure.
|
||||
|
||||
### How to Report
|
||||
|
||||
> **Do not** report security vulnerabilities through public GitHub issues, discussions, or social media.
|
||||
|
||||
Instead, please use one of these secure channels:
|
||||
|
||||
1. **GitHub Security Advisories**
|
||||
Use the **Report a vulnerability** button in the Security tab of the [nvm-sh/nvm repository](https://github.com/nvm-sh/nvm).
|
||||
|
||||
2. **Email**
|
||||
Follow the posted [Security Policy](https://github.com/nvm-sh/nvm/security/policy).
|
||||
|
||||
### What to Include
|
||||
|
||||
**Required Information:**
|
||||
- Brief description of the vulnerability type
|
||||
- Affected version(s) and components
|
||||
- Steps to reproduce the issue
|
||||
- Impact assessment (what an attacker could achieve)
|
||||
|
||||
**Helpful Additional Details:**
|
||||
- Full paths of affected scripts or files
|
||||
- Specific commit or branch where the issue exists
|
||||
- Required configuration to reproduce
|
||||
- Proof-of-concept code (if available)
|
||||
- Suggested mitigation or fix
|
||||
|
||||
## Our Response Process
|
||||
|
||||
**Timeline Commitments:**
|
||||
- **Initial acknowledgment**: Within 24 hours
|
||||
- **Detailed response**: Within 3 business days
|
||||
- **Status updates**: Every 7 days until resolved
|
||||
- **Resolution target**: 90 days for most issues
|
||||
|
||||
**What We’ll Do:**
|
||||
1. Acknowledge your report and assign a tracking ID
|
||||
2. Assess the vulnerability and determine severity
|
||||
3. Develop and test a fix
|
||||
4. Coordinate disclosure timeline with you
|
||||
5. Release a security update and publish an advisory and CVE
|
||||
6. Credit you in our security advisory (if desired)
|
||||
|
||||
## Disclosure Policy
|
||||
|
||||
- **Coordinated disclosure**: We’ll work with you on timing
|
||||
- **Typical timeline**: 90 days from report to public disclosure
|
||||
- **Early disclosure**: If actively exploited
|
||||
- **Delayed disclosure**: For complex issues
|
||||
|
||||
## Scope
|
||||
|
||||
**In Scope:**
|
||||
- **nvm** project (all supported versions)
|
||||
- Installation and update scripts (`install.sh`, `nvm.sh`)
|
||||
- Official documentation and CI/CD integrations
|
||||
- Dependencies with direct security implications
|
||||
|
||||
**Out of Scope:**
|
||||
- Third-party forks or mirrors
|
||||
- Platform-specific installs outside core scripts
|
||||
- Social engineering or physical attacks
|
||||
- Theoretical vulnerabilities without practical exploitation
|
||||
|
||||
## Security Measures
|
||||
|
||||
**Our Commitments:**
|
||||
- Regular vulnerability scanning via GitHub Actions
|
||||
- Automated security checks in CI/CD pipelines
|
||||
- Secure scripting practices and mandatory code review
|
||||
- Prompt patch releases for critical issues
|
||||
|
||||
**User Responsibilities:**
|
||||
- Keep **nvm** updated
|
||||
- Verify script downloads via PGP signatures
|
||||
- Follow secure configuration guidelines for shell environments
|
||||
|
||||
## Legal Safe Harbor
|
||||
|
||||
**We will NOT:**
|
||||
- Initiate legal action
|
||||
- Contact law enforcement
|
||||
- Suspend or terminate your access
|
||||
|
||||
**You must:**
|
||||
- Only test against your own installations
|
||||
- Not access, modify, or delete user data
|
||||
- Not degrade service availability
|
||||
- Not publicly disclose before coordinated disclosure
|
||||
- Act in good faith
|
||||
|
||||
## Recognition
|
||||
|
||||
- **Advisory Credits**: Credit in GitHub Security Advisories (unless anonymous)
|
||||
|
||||
## Security Updates
|
||||
|
||||
**Stay Informed:**
|
||||
- Subscribe to GitHub releases for **nvm**
|
||||
- Enable GitHub Security Advisory notifications
|
||||
|
||||
**Update Process:**
|
||||
- Patch releases (e.g., v0.40.3 → v0.40.4)
|
||||
- Out-of-band releases for critical issues
|
||||
- Advisories via GitHub Security Advisories
|
||||
|
||||
## Contact Information
|
||||
|
||||
- **Security reports**: Security tab of [nvm-sh/nvm](https://github.com/nvm-sh/nvm/security)
|
||||
- **General inquiries**: GitHub Discussions or Issues
|
||||
|
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! -->
|
||||
|
28
.github/SECURITY.md
vendored
Normal file
28
.github/SECURITY.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# Security
|
||||
|
||||
Please file a private vulnerability report via GitHub, 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 100% of the “silver” criteria.
|
||||
|
||||
### Gold
|
||||
We meet 78% of the “gold” criteria. The gaps are as follows:
|
||||
- because we only have one maintainer, the project has no way to continue if that maintainer stops being active.
|
||||
- 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](.github/THREAT_MODEL.md).
|
||||
|
||||
## Incident Response Plan
|
||||
|
||||
Please see our [Incident Response Plan](.github/INCIDENT_RESPONSE_PLAN.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.
|
427
.github/copilot-instructions.md
vendored
Normal file
427
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,427 @@
|
||||
# nvm Copilot Instructions
|
||||
|
||||
This document provides guidance for GitHub Copilot when working with the Node Version Manager (nvm) codebase.
|
||||
|
||||
## Overview
|
||||
|
||||
nvm is a version manager for Node.js, implemented as a POSIX-compliant function that works across multiple shells (sh, dash, bash, ksh, zsh). The codebase is primarily written in shell script and emphasizes portability and compatibility.
|
||||
|
||||
### Core Architecture
|
||||
|
||||
- **Main script**: `nvm.sh` - Contains all core functionality and the main `nvm()` function
|
||||
- **Installation script**: `install.sh` - Handles downloading and installing nvm itself
|
||||
- **Execution wrapper**: `nvm-exec` - Allows running commands with specific Node.js versions
|
||||
- **Bash completion**: `bash_completion` - Provides tab completion for bash users
|
||||
- **Tests**: Comprehensive test suite in `test/` directory using the [urchin](https://www.npmjs.com/package/urchin) test framework
|
||||
|
||||
## Key Files and Their Purposes
|
||||
|
||||
### `nvm.sh`
|
||||
The core functionality file containing:
|
||||
- Main `nvm()` function (starts around line 3000)
|
||||
- All internal helper functions (prefixed with `nvm_`)
|
||||
- Command implementations for install, use, ls, etc.
|
||||
- Shell compatibility logic
|
||||
- POSIX compliance utilities
|
||||
|
||||
### `install.sh`
|
||||
Handles nvm installation via curl/wget/git:
|
||||
- Downloads nvm from GitHub
|
||||
- Sets up directory structure
|
||||
- Configures shell integration
|
||||
- Supports both git clone and script download methods
|
||||
|
||||
### `nvm-exec`
|
||||
Simple wrapper script that:
|
||||
- Sources nvm.sh with `--no-use` flag
|
||||
- Switches to specified Node version via `NODE_VERSION` env var or `.nvmrc`
|
||||
- Executes the provided command with that Node version
|
||||
|
||||
## Top-Level nvm Commands and Internal Functions
|
||||
|
||||
### Core Commands
|
||||
|
||||
#### `nvm install [version]`
|
||||
- **Internal functions**: `nvm_install_binary()`, `nvm_install_source()`, `nvm_download_artifact()`
|
||||
- Downloads and installs specified Node.js version
|
||||
- Automatically `nvm use`s that version after installation
|
||||
- Supports LTS versions, version ranges, and built-in aliases (like `node`, `stable`) and user-defined aliases
|
||||
- Can install from binary or compile from source
|
||||
- When compiling from source, accepts additional arguments that are passed to the compilation task
|
||||
|
||||
#### `nvm use [version]`
|
||||
- **Internal functions**: `nvm_resolve_alias()`, `nvm_version_path()`, `nvm_change_path()`
|
||||
- Switches current shell to use specified Node.js version
|
||||
- Updates PATH environment variable
|
||||
- Supports `.nvmrc` file integration
|
||||
|
||||
#### `nvm ls [pattern]`
|
||||
- **Internal functions**: `nvm_ls()`, `nvm_tree_contains_path()`
|
||||
- Lists installed Node.js versions
|
||||
- Supports pattern matching and filtering
|
||||
- Shows current version and aliases
|
||||
|
||||
#### `nvm ls-remote [pattern]`
|
||||
- **Internal functions**: `nvm_ls_remote()`, `nvm_download()`, `nvm_ls_remote_index_tab()`
|
||||
- Lists available Node.js versions from nodejs.org and iojs.org, or the env-var-configured mirrors
|
||||
- Supports LTS filtering and pattern matching
|
||||
- Downloads version index on-demand
|
||||
|
||||
#### `nvm alias [name] [version]`
|
||||
- **Internal functions**: `nvm_alias()`, `nvm_alias_path()`
|
||||
- Creates text files containing the mapped version, named as the alias name
|
||||
- Special aliases: `default`, `node`, `iojs`, `stable`, `unstable` (note: `stable` and `unstable` are deprecated, from node's pre-v1 release plan)
|
||||
- Stored in `$NVM_DIR/alias/` directory
|
||||
|
||||
#### `nvm current`
|
||||
- **Internal functions**: `nvm_ls_current()`
|
||||
- Shows currently active Node.js version
|
||||
- Returns "system" if using system Node.js
|
||||
|
||||
#### `nvm which [version]`
|
||||
- **Internal functions**: `nvm_version_path()`, `nvm_resolve_alias()`
|
||||
- Shows path to specified Node.js version
|
||||
- Resolves aliases and version strings
|
||||
|
||||
### Utility Commands
|
||||
|
||||
#### `nvm cache clear|dir`
|
||||
- Cache management for downloaded binaries and source code
|
||||
- Clears or shows cache directory path
|
||||
|
||||
#### `nvm debug`
|
||||
- Diagnostic information for troubleshooting
|
||||
- Shows environment, tool versions, and paths
|
||||
|
||||
#### `nvm deactivate`
|
||||
- Removes nvm modifications from current shell
|
||||
- Restores original PATH
|
||||
|
||||
#### `nvm unload`
|
||||
- Completely removes nvm from shell environment
|
||||
- Unsets all nvm functions and variables
|
||||
|
||||
### Internal Function Categories
|
||||
|
||||
#### Version Resolution
|
||||
- `nvm_resolve_alias()` - Resolves aliases to version numbers
|
||||
- `nvm_version()` - Finds best matching local version
|
||||
- `nvm_remote_version()` - Finds best matching remote version
|
||||
- `nvm_normalize_version()` - Standardizes version strings
|
||||
- `nvm_version_greater()` - Compares version numbers
|
||||
- `nvm_version_greater_than_or_equal_to()` - Version comparison with equality
|
||||
- `nvm_get_latest()` - Gets latest version from a list
|
||||
|
||||
#### Installation Helpers
|
||||
- `nvm_install_binary()` - Downloads and installs precompiled binaries
|
||||
- `nvm_install_source()` - Compiles Node.js from source
|
||||
- `nvm_download_artifact()` - Downloads tarballs or binaries
|
||||
- `nvm_compute_checksum()` - Verifies download integrity
|
||||
- `nvm_checksum()` - Checksum verification wrapper
|
||||
- `nvm_get_mirror()` - Gets appropriate download mirror
|
||||
- `nvm_get_arch()` - Determines system architecture
|
||||
|
||||
#### Path Management
|
||||
- `nvm_change_path()` - Updates PATH for version switching
|
||||
- `nvm_strip_path()` - Removes nvm paths from PATH
|
||||
- `nvm_version_path()` - Gets installation path for version
|
||||
- `nvm_version_dir()` - Gets version directory name
|
||||
- `nvm_prepend_path()` - Safely prepends to PATH
|
||||
|
||||
#### Shell Detection and Compatibility
|
||||
- `nvm_is_zsh()` - Shell detection for zsh
|
||||
- `nvm_is_iojs_version()` - Checks if version is io.js
|
||||
- `nvm_get_os()` - Operating system detection
|
||||
- `nvm_supports_source_options()` - Checks if shell supports source options
|
||||
|
||||
#### Network and Remote Operations
|
||||
- `nvm_download()` - Generic download function
|
||||
- `nvm_ls_remote()` - Lists remote versions
|
||||
- `nvm_ls_remote_iojs()` - Lists remote io.js versions
|
||||
- `nvm_ls_remote_index_tab()` - Parses remote version index
|
||||
|
||||
#### Utility Functions
|
||||
- `nvm_echo()`, `nvm_err()` - Output functions
|
||||
- `nvm_has()` - Checks if command exists
|
||||
- `nvm_sanitize_path()` - Cleans sensitive data from paths
|
||||
- `nvm_die_on_prefix()` - Validates npm prefix settings
|
||||
- `nvm_ensure_default_set()` - Ensures default alias is set
|
||||
- `nvm_auto()` - Automatic version switching from .nvmrc
|
||||
|
||||
#### Alias Management
|
||||
- `nvm_alias()` - Creates or lists aliases
|
||||
- `nvm_alias_path()` - Gets path to alias file
|
||||
- `nvm_unalias()` - Removes aliases
|
||||
- `nvm_resolve_local_alias()` - Resolves local aliases
|
||||
|
||||
#### Listing and Display
|
||||
- `nvm_ls()` - Lists local versions
|
||||
- `nvm_ls_current()` - Shows current version
|
||||
- `nvm_tree_contains_path()` - Checks if path is in nvm tree
|
||||
- `nvm_format_version()` - Formats version display
|
||||
|
||||
## Running Tests
|
||||
|
||||
### Test Framework
|
||||
nvm uses the [urchin](https://www.npmjs.com/package/urchin) test framework for shell script testing.
|
||||
|
||||
### Test Structure
|
||||
```
|
||||
test/
|
||||
├── fast/ # Quick unit tests
|
||||
├── slow/ # Integration tests
|
||||
├── sourcing/ # Shell sourcing tests
|
||||
├── install_script/ # Installation script tests
|
||||
├── installation_node/ # Node installation tests
|
||||
├── installation_iojs/ # io.js installation tests
|
||||
└── common.sh # Shared test utilities
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
#### Install Dependencies
|
||||
```bash
|
||||
npm install # Installs urchin, semver, and replace tools
|
||||
```
|
||||
|
||||
#### Run All Tests
|
||||
```bash
|
||||
npm test # Runs tests in current shell (sh, bash, dash, zsh, ksh)
|
||||
make test # Runs tests in all supported shells (sh, bash, dash, zsh, ksh)
|
||||
make test-sh # Runs tests only in sh
|
||||
make test-bash # Runs tests only in bash
|
||||
make test-dash # Runs tests only in dash
|
||||
make test-zsh # Runs tests only in zsh
|
||||
make test-ksh # Runs tests only in ksh
|
||||
```
|
||||
|
||||
#### Run Specific Test Suites
|
||||
```bash
|
||||
make TEST_SUITE=fast test # Only fast tests
|
||||
make TEST_SUITE=slow test # Only slow tests
|
||||
make SHELLS=bash test # Only bash shell
|
||||
```
|
||||
|
||||
#### Individual Test Execution
|
||||
```bash
|
||||
./test/fast/Unit\ tests/nvm_get_arch # Run single test (WARNING: This will exit/terminate your current shell session)
|
||||
./node_modules/.bin/urchin test/fast/ # Run fast test suite
|
||||
./node_modules/.bin/urchin 'test/fast/Unit tests/nvm_get_arch' # Run single test safely without shell termination
|
||||
./node_modules/.bin/urchin test/slow/ # Run slow test suite
|
||||
./node_modules/.bin/urchin test/sourcing/ # Run sourcing test suite
|
||||
```
|
||||
|
||||
### Test Writing Guidelines
|
||||
- Tests should work across all supported shells (sh, bash, dash, zsh, ksh)
|
||||
- Define and use a `die()` function for test failures
|
||||
- Clean up after tests in cleanup functions
|
||||
- Mock external dependencies when needed
|
||||
- Place mocks in `test/mocks/` directory
|
||||
- Mock files should only be updated by the existing `update_test_mocks.sh` script, and any new mocks must be added to this script
|
||||
|
||||
## Shell Environment Setup
|
||||
|
||||
### Supported Shells
|
||||
- **bash** - Full feature support
|
||||
- **zsh** - Full feature support
|
||||
- **dash** - Basic POSIX support
|
||||
- **sh** - Basic POSIX support
|
||||
- **ksh** - Limited support (experimental)
|
||||
|
||||
### Installing Shell Environments
|
||||
|
||||
#### Ubuntu/Debian
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install bash zsh dash ksh
|
||||
# sh is typically provided by dash or bash and is available by default
|
||||
```
|
||||
|
||||
#### macOS
|
||||
```bash
|
||||
# bash and zsh are available by default, bash is not the default shell for new user accounts
|
||||
# Install other shells via Homebrew
|
||||
brew install dash ksh
|
||||
# For actual POSIX sh (not bash), install mksh which provides a true POSIX sh
|
||||
brew install mksh
|
||||
```
|
||||
|
||||
#### Manual Shell Testing
|
||||
```bash
|
||||
# Test in specific shell
|
||||
bash -c "source nvm.sh && nvm --version"
|
||||
zsh -c "source nvm.sh && nvm --version"
|
||||
dash -c ". nvm.sh && nvm --version"
|
||||
sh -c ". nvm.sh && nvm --version" # On macOS: mksh -c ". nvm.sh && nvm --version"
|
||||
ksh -c ". nvm.sh && nvm --version"
|
||||
```
|
||||
|
||||
### Shell-Specific Considerations
|
||||
- **zsh**: Requires basically any non-default zsh option to be temporarily unset to restore POSIX compliance
|
||||
- **dash**: Limited feature set, avoid bash-specific syntax
|
||||
- **ksh**: Some features may not work, primarily for compatibility testing
|
||||
|
||||
## CI Environment Details
|
||||
|
||||
### GitHub Actions Workflows
|
||||
|
||||
#### `.github/workflows/tests.yml`
|
||||
- Runs test suite across multiple shells and test suites
|
||||
- Uses `script` command for proper TTY simulation
|
||||
- Matrix strategy covers shell × test suite combinations
|
||||
- Excludes install_script tests from non-bash shells
|
||||
|
||||
#### `.github/workflows/shellcheck.yml`
|
||||
- Lints all shell scripts using shellcheck
|
||||
- Tests against multiple shell targets (bash, sh, dash, ksh)
|
||||
- Note: zsh is not included due to [shellcheck limitations](https://github.com/koalaman/shellcheck/issues/809)
|
||||
- Uses Homebrew to install latest shellcheck version
|
||||
|
||||
#### `.github/workflows/lint.yml`
|
||||
- Runs additional linting and formatting checks
|
||||
- Validates documentation and code style
|
||||
|
||||
### Travis CI (Legacy)
|
||||
- Configured in `.travis.yml`
|
||||
- Tests on multiple Ubuntu versions
|
||||
- Installs shell environments via apt packages
|
||||
|
||||
### CI Test Execution
|
||||
```bash
|
||||
# Simulate CI environment locally
|
||||
unset TRAVIS_BUILD_DIR # Disable Travis-specific logic
|
||||
unset GITHUB_ACTIONS # Disable GitHub Actions logic
|
||||
make test
|
||||
```
|
||||
|
||||
## Setting Up shellcheck Locally
|
||||
|
||||
### Installation
|
||||
|
||||
#### macOS (Homebrew)
|
||||
```bash
|
||||
brew install shellcheck
|
||||
```
|
||||
|
||||
#### Ubuntu/Debian
|
||||
```bash
|
||||
sudo apt-get install shellcheck
|
||||
```
|
||||
|
||||
#### From Source
|
||||
```bash
|
||||
# Download from https://github.com/koalaman/shellcheck/releases
|
||||
wget https://github.com/koalaman/shellcheck/releases/download/latest/shellcheck-latest.linux.x86_64.tar.xz
|
||||
tar -xf shellcheck-latest.linux.x86_64.tar.xz
|
||||
sudo cp shellcheck-latest/shellcheck /usr/local/bin/
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
#### Lint Main Files
|
||||
```bash
|
||||
shellcheck -s bash nvm.sh
|
||||
shellcheck -s bash install.sh
|
||||
shellcheck -s bash nvm-exec
|
||||
shellcheck -s bash bash_completion
|
||||
```
|
||||
|
||||
#### Lint Across Shell Types
|
||||
```bash
|
||||
shellcheck -s sh nvm.sh # POSIX sh
|
||||
shellcheck -s bash nvm.sh # Bash extensions
|
||||
shellcheck -s dash nvm.sh # Dash compatibility
|
||||
shellcheck -s ksh nvm.sh # Ksh compatibility
|
||||
```
|
||||
|
||||
#### Common shellcheck Directives in nvm
|
||||
- `# shellcheck disable=SC2039` - Allow bash extensions in POSIX mode
|
||||
- `# shellcheck disable=SC2016` - Allow literal `$` in single quotes
|
||||
- `# shellcheck disable=SC2001` - Allow sed usage instead of parameter expansion
|
||||
- `# shellcheck disable=SC3043` - Allow `local` keyword (bash extension)
|
||||
|
||||
### Fixing shellcheck Issues
|
||||
1. **Quoting**: Always quote variables: `"${VAR}"` instead of `$VAR`
|
||||
2. **POSIX compliance**: Avoid bash-specific features in portable sections
|
||||
3. **Array usage**: Use `set --` for positional parameters instead of arrays, which are not supported in POSIX
|
||||
4. **Local variables**: Declared with `local FOO` and then initialized on the next line (the latter is for ksh support)
|
||||
|
||||
## Development Best Practices
|
||||
|
||||
### Code Style
|
||||
- Use 2-space indentation
|
||||
- Follow POSIX shell guidelines for portability
|
||||
- Prefix internal functions with `nvm_`
|
||||
- Use `nvm_echo` instead of `echo` for output
|
||||
- Use `nvm_err` for error messages
|
||||
|
||||
### Compatibility
|
||||
- Test changes across all supported shells
|
||||
- Avoid bash-specific features in core functionality
|
||||
- Use `nvm_is_zsh` to check when zsh-specific behavior is needed
|
||||
- Mock external dependencies in tests
|
||||
|
||||
### Performance
|
||||
- Cache expensive operations (like remote version lists)
|
||||
- Use local variables to avoid scope pollution
|
||||
- Minimize subprocess calls where possible
|
||||
- Implement lazy loading for optional features
|
||||
|
||||
### Debugging
|
||||
- Use `nvm debug` command for environment information
|
||||
- Enable verbose output with `set -x` during development
|
||||
- Test with `NVM_DEBUG=1` environment variable
|
||||
- Check `$NVM_DIR/.cache` for cached data issues
|
||||
|
||||
## Common Gotchas
|
||||
|
||||
1. **PATH modification**: nvm modifies PATH extensively; be careful with restoration
|
||||
2. **Shell sourcing**: nvm must be sourced, not executed as a script
|
||||
3. **Version resolution**: Aliases, partial versions, and special keywords interact complexly
|
||||
4. **Platform differences**: Handle differences between Linux, macOS, and other Unix systems
|
||||
5. **Network dependencies**: Many operations require internet access for version lists
|
||||
6. **Concurrent access**: Multiple shells can conflict when installing versions simultaneously
|
||||
|
||||
## Windows Support
|
||||
|
||||
nvm works on Windows via several compatibility layers:
|
||||
|
||||
### WSL2 (Windows Subsystem for Linux)
|
||||
- Full nvm functionality available
|
||||
- **Important**: Ensure you're using WSL2, not WSL1 - see [Microsoft's WSL2 installation guide](https://docs.microsoft.com/en-us/windows/wsl/install) for up-to-date instructions
|
||||
- Install Ubuntu or other Linux distribution from Microsoft Store
|
||||
- Follow Linux installation instructions within WSL2
|
||||
|
||||
### Cygwin
|
||||
- POSIX-compatible environment for Windows
|
||||
- Download Cygwin from [cygwin.com](https://www.cygwin.com/install.html) and run the installer
|
||||
- During installation, include these packages: bash, curl, git, tar, and wget
|
||||
- May require additional PATH configuration
|
||||
|
||||
### Git Bash (MSYS2)
|
||||
- Comes with Git for Windows
|
||||
- Limited functionality compared to full Linux environment
|
||||
- Some features may not work due to path translation issues, including:
|
||||
- Binary extraction paths may be incorrectly translated
|
||||
- Symlink creation may fail
|
||||
- Some shell-specific features may behave differently
|
||||
- File permissions handling differs from Unix systems
|
||||
|
||||
### Setup Instructions for Windows
|
||||
|
||||
#### WSL2 (recommended)
|
||||
1. Install WSL2 using the official Microsoft guide: https://docs.microsoft.com/en-us/windows/wsl/install
|
||||
2. Install Ubuntu or preferred Linux distribution from Microsoft Store
|
||||
3. Follow standard Linux installation within WSL2
|
||||
|
||||
#### Git Bash
|
||||
1. Install Git for Windows (includes Git Bash) from https://git-scm.com/download/win
|
||||
2. Open Git Bash terminal
|
||||
3. Run nvm installation script
|
||||
|
||||
#### Cygwin
|
||||
1. Download and install Cygwin from https://www.cygwin.com/install.html
|
||||
2. Include bash, curl, git, tar, and wget packages during installation
|
||||
3. Run nvm installation in Cygwin terminal
|
||||
|
||||
This guide should help GitHub Copilot understand the nvm codebase structure, testing procedures, and development environment setup requirements.
|
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
|
26
.github/workflows/rebase.yml
vendored
Normal file
26
.github/workflows/rebase.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: Automatic Rebase
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
_:
|
||||
permissions:
|
||||
contents: write
|
||||
name: "Automatic Rebase"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- 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
|
||||
env:
|
||||
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
|
41
.github/workflows/toc.yml
vendored
Normal file
41
.github/workflows/toc.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
name: update readme TOC
|
||||
|
||||
on: [push]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
_:
|
||||
permissions:
|
||||
contents: write
|
||||
name: "update readme TOC"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- 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:
|
||||
# https://github.com/actions/checkout/issues/217#issue-599945005
|
||||
# pulls all commits (needed for lerna / semantic release to correctly version)
|
||||
fetch-depth: "0"
|
||||
|
||||
# pulls all tags (needed for lerna / semantic release to correctly version)
|
||||
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
- run: npm install
|
||||
- run: npm run doctoc
|
||||
- name: commit changes
|
||||
uses: ljharb/actions-js-build/commit@v3+amendpush
|
||||
with:
|
||||
amend: true
|
||||
force: true
|
196
.github/workflows/windows-npm.yml
vendored
Normal file
196
.github/workflows/windows-npm.yml
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
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"
|
||||
export HOME="$(cygpath -u "$USERPROFILE")"
|
||||
|
||||
echo "HOME is $HOME"
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||
ls -l $HOME/.nvm
|
||||
. "$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_stdout
|
||||
test/**/test_output
|
||||
test/**/.nvmrc
|
||||
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
@@ -21,3 +22,5 @@ current
|
||||
npm-shrinkwrap.json
|
||||
package-lock.json
|
||||
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
|
||||
dist: xenial
|
||||
sudo: required
|
||||
dist: focal
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@@ -9,31 +8,72 @@ addons:
|
||||
# - gcc-4.8
|
||||
# - g++-4.8
|
||||
|
||||
# https://gist.github.com/iedemam/9830045
|
||||
git:
|
||||
submodules: false
|
||||
|
||||
cache:
|
||||
ccache: true
|
||||
directories:
|
||||
- $HOME/.npm
|
||||
- $TRAVIS_BUILD_DIR/.cache
|
||||
- $TRAVIS_BUILD_DIR/node_modules
|
||||
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
|
||||
- curl --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:
|
||||
- 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'
|
||||
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 "${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
|
||||
- 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
|
||||
before_cache:
|
||||
- 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:
|
||||
global:
|
||||
- CXX=g++
|
||||
@@ -42,56 +82,13 @@ env:
|
||||
- PATH="/usr/lib/ccache/:$PATH"
|
||||
- NVM_DIR="${TRAVIS_BUILD_DIR}"
|
||||
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=dash TEST_SUITE=fast
|
||||
- SHELL=bash TEST_SUITE=fast
|
||||
- SHELL=zsh 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=ksh TEST_SUITE=fast
|
||||
- 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=bash TEST_SUITE=installation_iojs
|
||||
- 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=ksh TEST_SUITE=installation_iojs
|
||||
# - 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"
|
||||
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||
|
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.
|
||||
|
||||
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:
|
||||
|
||||
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.
|
||||
- Please give us as much detail as possible about your environment, so we can more easily confirm the problem.
|
||||
There are lots of ways to get involved. Here are some suggestions of things we'd love some help with.
|
||||
|
||||
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 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.
|
||||
- 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.
|
||||
|
||||
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.
|
||||
|
44
Dockerfile
44
Dockerfile
@@ -6,9 +6,7 @@
|
||||
# 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.
|
||||
|
||||
# Use Ubuntu Trusty Tahr as base image as we're using on Travis CI
|
||||
# I also tested with Ubuntu 16.04, should be good with it!
|
||||
FROM ubuntu:14.04
|
||||
FROM ubuntu:22.04
|
||||
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
|
||||
LABEL name="nvm-dev-env"
|
||||
LABEL version="latest"
|
||||
@@ -20,15 +18,12 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
# ShellCheck version
|
||||
ENV SHELLCHECK_VERSION=0.6.0
|
||||
ENV SHELLCHECK_VERSION=0.7.0
|
||||
|
||||
# Pick a Ubuntu apt mirror site for better speed
|
||||
# ref: https://launchpad.net/ubuntu/+archivemirrors
|
||||
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
|
||||
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
|
||||
@@ -43,6 +38,7 @@ RUN apt update && \
|
||||
file \
|
||||
openssl \
|
||||
libssl-dev \
|
||||
locales \
|
||||
ca-certificates \
|
||||
ssh \
|
||||
wget \
|
||||
@@ -55,24 +51,20 @@ RUN apt update && \
|
||||
curl \
|
||||
git \
|
||||
jq \
|
||||
realpath \
|
||||
zsh \
|
||||
ksh \
|
||||
gcc-4.8 \
|
||||
g++-4.8 \
|
||||
gcc \
|
||||
g++ \
|
||||
xz-utils \
|
||||
build-essential \
|
||||
bash-completion && \
|
||||
apt-get clean
|
||||
|
||||
# ShellCheck with Ubuntu 14.04 container workaround
|
||||
RUN wget https://storage.googleapis.com/shellcheck/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 && \
|
||||
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
|
||||
rmdir shellcheck-v$SHELLCHECK_VERSION && \
|
||||
touch /tmp/libc.so.6 && \
|
||||
echo "alias shellcheck='LD_LIBRARY_PATH=/tmp /bin/shellcheck'" >> /etc/bash.bashrc
|
||||
RUN LD_LIBRARY_PATH=/tmp shellcheck -V
|
||||
rmdir shellcheck-v$SHELLCHECK_VERSION
|
||||
RUN shellcheck -V
|
||||
|
||||
# Set locale
|
||||
RUN locale-gen en_US.UTF-8
|
||||
@@ -91,7 +83,7 @@ RUN useradd -ms /bin/bash nvm
|
||||
|
||||
# Copy and set permission for nvm directory
|
||||
COPY . /home/nvm/.nvm/
|
||||
RUN chown nvm:nvm -R "home/nvm/.nvm"
|
||||
RUN chown nvm:nvm -R "/home/nvm/.nvm"
|
||||
|
||||
# Set sudoer for "nvm"
|
||||
RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
||||
@@ -99,16 +91,20 @@ RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
||||
# Switch to user "nvm" from now
|
||||
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
|
||||
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$HOME/.bashrc"
|
||||
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$HOME/.bashrc"
|
||||
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$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' >> "$BASH_ENV"
|
||||
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$BASH_ENV"
|
||||
|
||||
# nodejs and tools
|
||||
RUN bash -c 'source $HOME/.nvm/nvm.sh && \
|
||||
nvm install node && \
|
||||
npm install -g doctoc urchin eclint dockerfile_lint && \
|
||||
npm install --prefix "$HOME/.nvm/"'
|
||||
RUN nvm install node
|
||||
RUN npm install -g doctoc urchin eclint dockerfile_lint
|
||||
RUN npm install --prefix "$HOME/.nvm/"
|
||||
|
||||
# Set WORKDIR to nvm directory
|
||||
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).
|
||||
.PHONY: $(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"; \
|
||||
[ -z "$$TRAVIS_BUILD_DIR" ] && 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
|
||||
[ -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 \
|
||||
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).
|
||||
.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; } \
|
||||
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; }; \
|
||||
replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \
|
||||
replace "$$old_ver" "$$new_ver" $(VERSIONED_FILES) && \
|
||||
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
|
||||
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
|
@@ -58,7 +58,7 @@ __nvm_aliases() {
|
||||
declare aliases
|
||||
aliases=""
|
||||
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
|
||||
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
|
||||
# ZSH, load and run bashcompinit before calling the complete function.
|
||||
if [[ -n ${ZSH_VERSION-} ]]; then
|
||||
autoload -U +X bashcompinit && bashcompinit
|
||||
autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
|
||||
compinit -u
|
||||
else
|
||||
compinit
|
||||
# First calling compinit (only if not called yet!)
|
||||
# and then bashcompinit as mentioned by zsh man page.
|
||||
if ! command -v compinit > /dev/null; then
|
||||
autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
|
||||
compinit -u
|
||||
else
|
||||
compinit
|
||||
fi
|
||||
fi
|
||||
autoload -U +X bashcompinit && bashcompinit
|
||||
fi
|
||||
|
||||
complete -o default -F __nvm nvm
|
||||
|
244
install.sh
244
install.sh
@@ -6,6 +6,20 @@ nvm_has() {
|
||||
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() {
|
||||
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
|
||||
}
|
||||
@@ -19,14 +33,14 @@ nvm_install_dir() {
|
||||
}
|
||||
|
||||
nvm_latest_version() {
|
||||
echo "v0.35.2"
|
||||
nvm_echo "v0.40.3"
|
||||
}
|
||||
|
||||
nvm_profile_is_bash_or_zsh() {
|
||||
local TEST_PROFILE
|
||||
TEST_PROFILE="${1-}"
|
||||
case "${TEST_PROFILE-}" in
|
||||
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
|
||||
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")
|
||||
return
|
||||
;;
|
||||
*)
|
||||
@@ -38,48 +52,70 @@ nvm_profile_is_bash_or_zsh() {
|
||||
#
|
||||
# Outputs the location to NVM depending on:
|
||||
# * The availability of $NVM_SOURCE
|
||||
# * The presence of $NVM_INSTALL_GITHUB_REPO
|
||||
# * 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() {
|
||||
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
|
||||
NVM_METHOD="$1"
|
||||
local NVM_SOURCE_URL
|
||||
NVM_SOURCE_URL="$NVM_SOURCE"
|
||||
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
|
||||
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
|
||||
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
|
||||
NVM_SOURCE_URL="https://github.com/nvm-sh/nvm.git"
|
||||
NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git"
|
||||
else
|
||||
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
|
||||
nvm_echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
echo "$NVM_SOURCE_URL"
|
||||
nvm_echo "$NVM_SOURCE_URL"
|
||||
}
|
||||
|
||||
#
|
||||
# Node.js version to install
|
||||
#
|
||||
nvm_node_version() {
|
||||
echo "$NODE_VERSION"
|
||||
nvm_echo "$NODE_VERSION"
|
||||
}
|
||||
|
||||
nvm_download() {
|
||||
if nvm_has "curl"; then
|
||||
curl --compressed -q "$@"
|
||||
curl --fail --compressed -q "$@"
|
||||
elif nvm_has "wget"; then
|
||||
# Emulate curl with wget
|
||||
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||
-e 's/-L //' \
|
||||
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||
-e 's/--compressed //' \
|
||||
-e 's/--fail //' \
|
||||
-e 's/-L //' \
|
||||
-e 's/-I /--server-response /' \
|
||||
-e 's/-s /-q /' \
|
||||
-e 's/-sS /-nv /' \
|
||||
-e 's/-o /-O /' \
|
||||
-e 's/-C - /-c /')
|
||||
# shellcheck disable=SC2086
|
||||
@@ -90,56 +126,76 @@ nvm_download() {
|
||||
install_nvm_from_git() {
|
||||
local INSTALL_DIR
|
||||
INSTALL_DIR="$(nvm_install_dir)"
|
||||
|
||||
if [ -d "$INSTALL_DIR/.git" ]; then
|
||||
echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
|
||||
command printf '\r=> '
|
||||
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$(nvm_latest_version)" --depth=1 2> /dev/null || {
|
||||
echo >&2 "Failed to update nvm, run 'git fetch' in $INSTALL_DIR yourself."
|
||||
local NVM_VERSION
|
||||
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
|
||||
if [ -n "${NVM_INSTALL_VERSION:-}" ]; then
|
||||
# Check if version is an existing ref
|
||||
if command git ls-remote "$(nvm_source "git")" "$NVM_VERSION" | nvm_grep -q "$NVM_VERSION" ; then
|
||||
:
|
||||
# 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
|
||||
}
|
||||
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
|
||||
# Cloning to $INSTALL_DIR
|
||||
echo "=> Downloading nvm from git to '$INSTALL_DIR'"
|
||||
fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!"
|
||||
nvm_echo "=> Downloading nvm from git to '$INSTALL_DIR'"
|
||||
command printf '\r=> '
|
||||
mkdir -p "${INSTALL_DIR}"
|
||||
if [ "$(ls -A "${INSTALL_DIR}")" ]; then
|
||||
# Initializing repo
|
||||
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
|
||||
}
|
||||
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)" || {
|
||||
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!'
|
||||
nvm_echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
|
||||
exit 2
|
||||
}
|
||||
else
|
||||
command git -c advice.detachedHead=false clone "$(nvm_source)" -b "$(nvm_latest_version)" --depth=1 "${INSTALL_DIR}" || {
|
||||
echo >&2 'Failed to clone nvm repo. Please report this!'
|
||||
# Cloning repo
|
||||
command git clone "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || {
|
||||
nvm_echo >&2 'Failed to clone nvm repo. Please report this!'
|
||||
exit 2
|
||||
}
|
||||
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 command git --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
|
||||
if command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
|
||||
command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
|
||||
else
|
||||
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
|
||||
nvm_echo >&2 "Your version of git is out of date. Please update it!"
|
||||
command git --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch -D master >/dev/null 2>&1
|
||||
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
|
||||
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
|
||||
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
|
||||
return
|
||||
}
|
||||
@@ -155,15 +211,15 @@ nvm_install_node() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
|
||||
nvm_echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
|
||||
nvm install "$NODE_VERSION_LOCAL"
|
||||
local CURRENT_NVM_NODE
|
||||
|
||||
CURRENT_NVM_NODE="$(nvm_version current)"
|
||||
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
|
||||
echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
|
||||
nvm_echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -180,20 +236,20 @@ install_nvm_as_script() {
|
||||
# Downloading to $INSTALL_DIR
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
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
|
||||
echo "=> Downloading nvm as script to '$INSTALL_DIR'"
|
||||
nvm_echo "=> Downloading nvm as script to '$INSTALL_DIR'"
|
||||
fi
|
||||
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
|
||||
} &
|
||||
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
|
||||
} &
|
||||
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
|
||||
} &
|
||||
for job in $(jobs -p | command sort)
|
||||
@@ -201,7 +257,7 @@ install_nvm_as_script() {
|
||||
wait "$job" || return $?
|
||||
done
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -210,7 +266,7 @@ nvm_try_profile() {
|
||||
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
|
||||
return 1
|
||||
fi
|
||||
echo "${1}"
|
||||
nvm_echo "${1}"
|
||||
}
|
||||
|
||||
#
|
||||
@@ -226,34 +282,38 @@ nvm_detect_profile() {
|
||||
fi
|
||||
|
||||
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
|
||||
echo "${PROFILE}"
|
||||
nvm_echo "${PROFILE}"
|
||||
return
|
||||
fi
|
||||
|
||||
local DETECTED_PROFILE
|
||||
DETECTED_PROFILE=''
|
||||
|
||||
if [ -n "${BASH_VERSION-}" ]; then
|
||||
if [ "${SHELL#*bash}" != "$SHELL" ]; then
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
DETECTED_PROFILE="$HOME/.bashrc"
|
||||
elif [ -f "$HOME/.bash_profile" ]; then
|
||||
DETECTED_PROFILE="$HOME/.bash_profile"
|
||||
fi
|
||||
elif [ -n "${ZSH_VERSION-}" ]; then
|
||||
DETECTED_PROFILE="$HOME/.zshrc"
|
||||
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
|
||||
if [ -f "${ZDOTDIR:-${HOME}}/.zshrc" ]; then
|
||||
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zshrc"
|
||||
elif [ -f "${ZDOTDIR:-${HOME}}/.zprofile" ]; then
|
||||
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zprofile"
|
||||
fi
|
||||
fi
|
||||
|
||||
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
|
||||
if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
|
||||
if DETECTED_PROFILE="$(nvm_try_profile "${ZDOTDIR:-${HOME}}/${EACH_PROFILE}")"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "$DETECTED_PROFILE" ]; then
|
||||
echo "$DETECTED_PROFILE"
|
||||
nvm_echo "$DETECTED_PROFILE"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -262,7 +322,9 @@ nvm_detect_profile() {
|
||||
# Node, and warn them if so.
|
||||
#
|
||||
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
|
||||
NPM_VERSION="$(npm --version)"
|
||||
@@ -284,68 +346,76 @@ nvm_check_global_modules() {
|
||||
|
||||
if [ "${MODULE_COUNT}" != '0' ]; then
|
||||
# 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
|
||||
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
|
||||
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
|
||||
echo '=> override the binaries of modules installed with `nvm`:'
|
||||
echo
|
||||
nvm_echo '=> override the binaries of modules installed with `nvm`:'
|
||||
nvm_echo
|
||||
|
||||
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
|
||||
echo '=> `nvm` Nodes), you can remove them from the system Node as follows:'
|
||||
echo
|
||||
echo ' $ nvm use system'
|
||||
echo ' $ npm uninstall -g a_module'
|
||||
echo
|
||||
nvm_echo '=> `nvm` node installs), you can remove them from the system Node as follows:'
|
||||
nvm_echo
|
||||
nvm_echo ' $ nvm use system'
|
||||
nvm_echo ' $ npm uninstall -g a_module'
|
||||
nvm_echo
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_do_install() {
|
||||
if [ -n "${NVM_DIR-}" ] && ! [ -d "${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
|
||||
fi
|
||||
|
||||
if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then
|
||||
mkdir "${NVM_DIR}"
|
||||
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
|
||||
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
|
||||
# Autodetect install method
|
||||
if nvm_has git; then
|
||||
install_nvm_from_git
|
||||
elif nvm_has nvm_download; then
|
||||
elif nvm_has curl || nvm_has wget; then
|
||||
install_nvm_as_script
|
||||
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
|
||||
fi
|
||||
elif [ "${METHOD}" = '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
|
||||
fi
|
||||
install_nvm_from_git
|
||||
elif [ "${METHOD}" = 'script' ]; then
|
||||
if ! nvm_has nvm_download; then
|
||||
echo >&2 "You need curl or wget to install nvm"
|
||||
if ! nvm_has curl && ! nvm_has wget; then
|
||||
nvm_echo >&2 "You need curl or wget to install nvm"
|
||||
exit 1
|
||||
fi
|
||||
install_nvm_as_script
|
||||
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
|
||||
fi
|
||||
|
||||
echo
|
||||
nvm_echo
|
||||
|
||||
local NVM_PROFILE
|
||||
NVM_PROFILE="$(nvm_detect_profile)"
|
||||
@@ -363,32 +433,32 @@ nvm_do_install() {
|
||||
if [ -n "${PROFILE}" ]; then
|
||||
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
|
||||
fi
|
||||
echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
|
||||
echo "=> Create one of them and run this script again"
|
||||
echo " OR"
|
||||
echo "=> Append the following lines to the correct file yourself:"
|
||||
nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zprofile, ~/.zshrc, and ~/.profile."
|
||||
nvm_echo "=> Create one of them and run this script again"
|
||||
nvm_echo " OR"
|
||||
nvm_echo "=> Append the following lines to the correct file yourself:"
|
||||
command printf "${SOURCE_STR}"
|
||||
echo
|
||||
nvm_echo
|
||||
else
|
||||
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
|
||||
BASH_OR_ZSH=true
|
||||
fi
|
||||
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"
|
||||
else
|
||||
echo "=> nvm source string already in ${NVM_PROFILE}"
|
||||
nvm_echo "=> nvm source string already in ${NVM_PROFILE}"
|
||||
fi
|
||||
# shellcheck disable=SC2016
|
||||
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"
|
||||
else
|
||||
echo "=> bash_completion source string already in ${NVM_PROFILE}"
|
||||
nvm_echo "=> bash_completion source string already in ${NVM_PROFILE}"
|
||||
fi
|
||||
fi
|
||||
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}"
|
||||
fi
|
||||
|
||||
@@ -402,7 +472,7 @@ nvm_do_install() {
|
||||
|
||||
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}"
|
||||
if ${BASH_OR_ZSH} ; then
|
||||
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 \
|
||||
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 \
|
||||
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
|
||||
|
4
nvm-exec
4
nvm-exec
@@ -2,7 +2,9 @@
|
||||
|
||||
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
unset NVM_CD_FLAGS
|
||||
|
||||
# shellcheck disable=SC1090,SC1091
|
||||
\. "$DIR/nvm.sh" --no-use
|
||||
|
||||
if [ -n "$NODE_VERSION" ]; then
|
||||
|
25
package.json
25
package.json
@@ -1,22 +1,28 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.35.2",
|
||||
"version": "0.40.3",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"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/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/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/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",
|
||||
"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)",
|
||||
"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": {
|
||||
"type": "git",
|
||||
@@ -36,11 +42,12 @@
|
||||
},
|
||||
"homepage": "https://github.com/nvm-sh/nvm",
|
||||
"devDependencies": {
|
||||
"dockerfile_lint": "^0.3.2",
|
||||
"eclint": "^2.6.0",
|
||||
"replace": "^0.3.0",
|
||||
"semver": "^5.0.1",
|
||||
"urchin": "^0.0.5",
|
||||
"doctoc": "^1.2.0"
|
||||
"dockerfile_lint": "^0.3.4",
|
||||
"doctoc": "^2.2.1",
|
||||
"eclint": "^2.8.1",
|
||||
"markdown-link-check": "^3.13.7",
|
||||
"replace": "^1.2.2",
|
||||
"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;
|
||||
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; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
export NVM_DIR="$(cd ../../.. && pwd)"
|
||||
|
||||
\. "${NVM_DIR}/nvm.sh"
|
||||
|
||||
EXIT_CODE=$(nvm_resolve_alias ; echo $?)
|
||||
[ $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" = "_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
|
||||
|
||||
export NVM_DIR="$(cd ../../.. && pwd)"
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
|
@@ -15,3 +15,5 @@ rm -f "../../../alias/unstable"
|
||||
rm -f "../../../alias/node"
|
||||
rm -f "../../../alias/iojs"
|
||||
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
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
nvm alias test v0.1.2
|
@@ -4,6 +4,8 @@ set -ex
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
nvm deactivate 2>&1
|
@@ -4,6 +4,8 @@ set -ex
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
\. ../../nvm.sh
|
||||
\. ../common.sh
|
||||
|
@@ -7,6 +7,8 @@ cleanup () {
|
||||
rm -rf "${NVM_DIR}/v0.10.4"
|
||||
}
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
\. ../../nvm.sh
|
||||
\. ../common.sh
|
||||
|
@@ -4,6 +4,8 @@ set -ex
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
set +ex # needed for stderr
|
@@ -9,6 +9,7 @@ cleanup () { rm -f "${BEFORE}" "${AFTER}"; }
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}"
|
||||
env | grep -v PATH= | grep -v IFS= | grep -v NVM_ | grep -v TRAVIS_ | sort >> "${BEFORE}"
|
||||
|
||||
set +e # TODO: fix
|
||||
\. ../../nvm.sh
|
||||
@@ -19,10 +20,11 @@ type nvm > /dev/null 2>&1 || die "nvm not loaded"
|
||||
nvm unload
|
||||
|
||||
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${AFTER}"
|
||||
env | grep -v PATH= | grep -v IFS= | grep -v TRAVIS_ | sort >> "${AFTER}"
|
||||
|
||||
! type nvm > /dev/null 2>&1 || die "nvm not unloaded"
|
||||
|
||||
DIFF="$(diff "${BEFORE}" "${AFTER}" ||:)"
|
||||
[ -z "${DIFF}" ] || die "function pollution found: ${DIFF}"
|
||||
[ -z "${DIFF}" ] || die "function pollution found: >${DIFF}<"
|
||||
|
||||
cleanup
|
@@ -27,7 +27,9 @@ EXPECTED_OUTPUT="$(nvm_add_iojs_prefix ${VERSION})"
|
||||
|
||||
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}"
|
||||
|
||||
[ "${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
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user