Skip to content

Commit 6975cda

Browse files
committed
feat: add nodes from env matrix
1 parent 6023b14 commit 6975cda

File tree

6 files changed

+195
-7
lines changed

6 files changed

+195
-7
lines changed

lib/index.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ const Path = require('path');
55
const Yaml = require('js-yaml');
66

77

8+
const internals = {};
9+
10+
internals.detectFromTravisYaml = (travisYaml) => {
11+
12+
const raw = new Set();
13+
14+
if (travisYaml.node_js) {
15+
const versions = Array.isArray(travisYaml.node_js) ? travisYaml.node_js : [travisYaml.node_js];
16+
17+
versions.forEach((v) => raw.add(v));
18+
}
19+
20+
if (travisYaml.env) {
21+
22+
for (const env of travisYaml.env.matrix) {
23+
24+
const matches = env.match(/(?:NODEJS_VER|TRAVIS_NODE_VERSION)="?(node\/)?(?<version>[\w./*]+)"?/); /* hack syntax highlighter 🤦‍♂️ */
25+
26+
raw.add(matches.groups.version);
27+
}
28+
}
29+
30+
return { raw: [...raw] };
31+
};
32+
33+
834
module.exports.detect = ({ path }) => {
935

1036
const packageJson = require(Path.join(path, 'package.json'));
@@ -16,8 +42,6 @@ module.exports.detect = ({ path }) => {
1642
return {
1743
name,
1844
version,
19-
travis: {
20-
raw: travisYaml.node_js
21-
}
45+
travis: internals.detectFromTravisYaml(travisYaml)
2246
};
2347
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "List the Node.js versions supported by the package/repository",
55
"main": "lib/index.js",
66
"scripts": {
7-
"test": "lab -a @hapi/code -L -t 100"
7+
"test": "lab -a @hapi/code -L -p 1 -t 100"
88
},
99
"repository": {
1010
"type": "git",
@@ -20,7 +20,8 @@
2020
"@hapi/code": "^7.0.0",
2121
"@hapi/lab": "^21.0.0",
2222
"allow-scripts": "^1.5.2",
23-
"semantic-release": "^15.14.0"
23+
"semantic-release": "^15.14.0",
24+
"tmp": "^0.1.0"
2425
},
2526
"dependencies": {
2627
"js-yaml": "^3.13.1"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Source: https://github.com/kangax/html-minifier/blob/51ce10f4daedb1de483ffbcccecc41be1c873da2/.travis.yml
2+
3+
addons:
4+
apt:
5+
sources:
6+
- ubuntu-toolchain-r-test
7+
packages:
8+
- libstdc++-4.9-dev
9+
10+
language: generic
11+
12+
matrix:
13+
fast_finish: true
14+
15+
env:
16+
matrix:
17+
- NODEJS_VER=node/6
18+
- NODEJS_VER=node/8
19+
- NODEJS_VER=node/10
20+
- NODEJS_VER=node/latest
21+
22+
before_install:
23+
- git clone --branch v1.4.2 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
24+
- . ~/.nvs/nvs.sh
25+
- nvs --version
26+
27+
install:
28+
- nvs add $NODEJS_VER
29+
- nvs use $NODEJS_VER
30+
- node --version
31+
- npm --version --no-update-notifier
32+
- npm install --no-optional --no-save --no-update-notifier
33+
34+
script:
35+
- npm test --no-update-notifier
36+
37+
notifications:
38+
email: false

test/fixtures/nodejs-nan.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
os:
2+
- linux
3+
- osx
4+
language: cpp
5+
addons:
6+
apt:
7+
sources:
8+
- ubuntu-toolchain-r-test
9+
packages:
10+
- bc
11+
- g++-4.8
12+
env:
13+
matrix:
14+
- TRAVIS_NODE_VERSION="0.10"
15+
- TRAVIS_NODE_VERSION="0.12"
16+
- TRAVIS_NODE_VERSION="4"
17+
- TRAVIS_NODE_VERSION="5"
18+
- TRAVIS_NODE_VERSION="6"
19+
- TRAVIS_NODE_VERSION="7"
20+
- TRAVIS_NODE_VERSION="8"
21+
- TRAVIS_NODE_VERSION="9"
22+
- TRAVIS_NODE_VERSION="10"
23+
- TRAVIS_NODE_VERSION="11"
24+
- TRAVIS_NODE_VERSION="12"
25+
- TRAVIS_NODE_VERSION="13"
26+
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="2.0.18"
27+
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="3.1.13"
28+
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="4.2.12"
29+
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="5.0.11"
30+
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="6.1.2"
31+
- TRAVIS_NODE_VERSION="lts/*" ELECTRON_VERSION="7.0.0"
32+
matrix:
33+
exclude:
34+
- os: osx
35+
env: TRAVIS_NODE_VERSION="0.12"
36+
install:
37+
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
38+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
39+
- $CXX --version
40+
- if [[ $TRAVIS_NODE_VERSION == "0.8" ]]; then npm config set strict-ssl false; fi
41+
- if [[ -z "$ELECTRON_VERSION" && $(echo "$TRAVIS_NODE_VERSION < 4" | bc -l) == "1" ]]; then npm install npm@2 && mv node_modules npm && npm/.bin/npm --version && npm/.bin/npm install; else npm --version && npm install; fi
42+
- if [[ -z "$ELECTRON_VERSION" ]]; then node_modules/.bin/node-gyp rebuild --directory test; else node_modules/.bin/node-gyp rebuild --target=v$ELECTRON_VERSION --dist-url=https://atom.io/download/electron --directory test; fi
43+
script:
44+
- if [[ -z "$ELECTRON_VERSION" ]]; then node_modules/.bin/tap --gc test/js/*-test.js; fi

test/fixtures/single-version.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: node_js
2+
node_js: "10"

test/index.js

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
11
'use strict';
22

3+
const Fs = require('fs');
34
const Path = require('path');
5+
const Tmp = require('tmp');
46

57
const NodeSupport = require('..');
68

79

8-
const { describe, it } = exports.lab = require('@hapi/lab').script();
10+
const { describe, it, afterEach } = exports.lab = require('@hapi/lab').script();
911
const { expect } = require('@hapi/code');
1012

13+
14+
const internals = {
15+
tmpObjects: []
16+
};
17+
18+
internals.prepareFixture = (travisYml) => {
19+
20+
const tmpObj = Tmp.dirSync({ unsafeCleanup: true });
21+
22+
internals.tmpObjects.push(tmpObj);
23+
24+
Fs.copyFileSync(Path.join(__dirname, 'fixtures', travisYml), Path.join(tmpObj.name, '.travis.yml'));
25+
26+
Fs.writeFileSync(Path.join(tmpObj.name, 'package.json'), JSON.stringify({
27+
name: 'test-module',
28+
version: '0.0.0-development'
29+
}));
30+
31+
return tmpObj.name;
32+
};
33+
34+
1135
describe('node-support', () => {
1236

37+
afterEach(() => {
38+
39+
internals.tmpObjects.forEach((tmpObj) => {
40+
41+
tmpObj.removeCallback();
42+
});
43+
44+
internals.tmpObjects = [];
45+
});
46+
1347
describe('detect()', () => {
1448

1549
describe('path', () => {
1650

17-
it('returns node versions from .travis.yml at the path', async () => {
51+
it('returns node versions from iamitcs-nodejs-nan.yml at the path', async () => {
1852

1953
const path = Path.join(__dirname, '..');
2054

@@ -28,6 +62,51 @@ describe('node-support', () => {
2862
}
2963
});
3064
});
65+
66+
it('returns the single node version', async () => {
67+
68+
const path = internals.prepareFixture('single-version.yml');
69+
70+
const result = await NodeSupport.detect({ path });
71+
72+
expect(result).to.equal({
73+
name: 'test-module',
74+
version: '0.0.0-development',
75+
travis: {
76+
raw: ['10']
77+
}
78+
});
79+
});
80+
81+
it('returns node versions from matrix env vars (NODEJS_VER)', async () => {
82+
83+
const path = internals.prepareFixture('kangax-html-minifier.yml');
84+
85+
const result = await NodeSupport.detect({ path });
86+
87+
expect(result).to.equal({
88+
name: 'test-module',
89+
version: '0.0.0-development',
90+
travis: {
91+
raw: ['6', '8', '10', 'latest']
92+
}
93+
});
94+
});
95+
96+
it('returns node versions from matrix env vars (TRAVIS_NODE_VERSION)', async () => {
97+
98+
const path = internals.prepareFixture('nodejs-nan.yml');
99+
100+
const result = await NodeSupport.detect({ path });
101+
102+
expect(result).to.equal({
103+
name: 'test-module',
104+
version: '0.0.0-development',
105+
travis: {
106+
raw: ['0.10', '0.12', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', 'lts/*']
107+
}
108+
});
109+
});
31110
});
32111
});
33112
});

0 commit comments

Comments
 (0)