Skip to content

Commit 1d5a187

Browse files
author
Robert Jackson
authored
Merge pull request #53 from felipecrs/npm
2 parents ee98e4e + 170d5b2 commit 1d5a187

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

.github/workflows/CI.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ jobs:
7373

7474
- run: tests/log-info.sh
7575
- run: tests/check-version.sh 'volta' 'current'
76-
76+
7777
- run: tests/check-version.sh 'node' 'v12.16.1'
78+
- run: tests/check-version.sh 'npm' '7.5.2'
7879
- run: tests/check-version.sh 'yarn' '1.19.1'
7980

80-
test-specified-node-yarn-overrides-pinned-versions:
81+
test-specified-node-npm-yarn-overrides-pinned-versions:
8182
runs-on: "${{ matrix.os }}-latest"
8283

8384
defaults:
@@ -103,13 +104,15 @@ jobs:
103104
- uses: ./action
104105
with:
105106
node-version: 12.14.0
107+
npm-version: 7.5.2
106108
yarn-version: 1.22.0
107109

108110
- run: tests/log-info.sh
109111
- run: tests/check-version.sh 'node' 'v12.14.0'
112+
- run: tests/check-version.sh 'npm' '7.5.2'
110113
- run: tests/check-version.sh 'yarn' '1.22.0'
111114

112-
test-specific-volta-node-yarn:
115+
test-specific-volta-node-npm-yarn:
113116
runs-on: "${{ matrix.os }}-latest"
114117

115118
strategy:
@@ -123,11 +126,13 @@ jobs:
123126
- run: npm run build
124127
- uses: ./
125128
with:
126-
volta-version: 0.8.7
129+
volta-version: 1.0.1
127130
node-version: 12.0.0
131+
npm-version: 7.5.2
128132
yarn-version: 1.22.0
129133

130134
- run: tests/log-info.sh
131-
- run: tests/check-version.sh 'volta' '0.8.7'
135+
- run: tests/check-version.sh 'volta' '1.0.1'
132136
- run: tests/check-version.sh 'node' 'v12.0.0'
137+
- run: tests/check-version.sh 'npm' '7.5.2'
133138
- run: tests/check-version.sh 'yarn' '1.22.0'

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ steps:
5454
- run: npm test
5555
```
5656

57+
You can also specify the version of npm:
58+
59+
```yaml
60+
strategy:
61+
matrix:
62+
node-version: ['^8.12', '10', '12']
63+
64+
steps:
65+
- uses: actions/checkout@v1
66+
- uses: volta-cli/action@v1
67+
with:
68+
node-version: ${{ matrix.node-version }}
69+
npm-version: '7'
70+
71+
- run: npm install
72+
- run: npm test
73+
```
74+
5775
# License
5876

5977
The scripts and documentation in this project are released under the [MIT License](LICENSE)

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
node-version:
99
description: 'Version Spec of the node version to use. Examples: 10.6.x, 10.15.1, >=10.15.0'
1010
default: ''
11+
npm-version:
12+
description: 'Version Spec of the npm version to use. Examples: 7.5.x, 7.5.3, >=7.5.3'
13+
default: ''
1114
yarn-version:
1215
description: 'Version Spec of the yarn version to use. Examples: 1.6.x, 10.15.1, >=10.15.0'
1316
default: ''

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ async function run(): Promise<void> {
2020
}
2121
}
2222

23+
const npmVersion = core.getInput('npm-version', { required: false });
24+
if (npmVersion !== '') {
25+
core.info(`installing NPM ${npmVersion === 'true' ? '' : npmVersion}`);
26+
await installer.installNpm(npmVersion);
27+
28+
// cannot pin `npm` when `node` is not pinned as well
29+
if (nodeVersion !== '' && hasPackageJSON) {
30+
await installer.pinNpm(npmVersion);
31+
}
32+
}
33+
2334
const yarnVersion = core.getInput('yarn-version', { required: false });
2435
if (yarnVersion !== '') {
2536
core.info(`installing Yarn ${yarnVersion === 'true' ? '' : yarnVersion}`);

src/installer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ export async function installNode(version: string): Promise<void> {
168168
await execVolta(['install', `node${version === 'true' ? '' : `@${version}`}`]);
169169
}
170170

171+
export async function installNpm(version: string): Promise<void> {
172+
await execVolta(['install', `npm${version === 'true' ? '' : `@${version}`}`]);
173+
}
174+
171175
export async function installYarn(version: string): Promise<void> {
172176
await execVolta(['install', `yarn${version === 'true' ? '' : `@${version}`}`]);
173177
}
@@ -176,6 +180,10 @@ export async function pinNode(version: string): Promise<void> {
176180
await execVolta(['pin', `node${version === 'true' ? '' : `@${version}`}`]);
177181
}
178182

183+
export async function pinNpm(version: string): Promise<void> {
184+
await execVolta(['pin', `npm${version === 'true' ? '' : `@${version}`}`]);
185+
}
186+
179187
export async function pinYarn(version: string): Promise<void> {
180188
await execVolta(['pin', `yarn${version === 'true' ? '' : `@${version}`}`]);
181189
}

0 commit comments

Comments
 (0)