@@ -19,37 +19,59 @@ cache:
19
19
directories :
20
20
- node_modules
21
21
before_install :
22
+ - |
23
+ # Setup utility functions
24
+ function node_version_lt () {
25
+ [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]]
26
+ }
27
+ function npm_module_installed () {
28
+ npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@"
29
+ }
30
+ function npm_remove_module_re () {
31
+ node -e '
32
+ fs = require("fs");
33
+ p = JSON.parse(fs.readFileSync("package.json", "utf8"));
34
+ r = RegExp(process.argv[1]);
35
+ for (k in p.devDependencies) {
36
+ if (r.test(k)) delete p.devDependencies[k];
37
+ }
38
+ fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n");
39
+ ' "$@"
40
+ }
41
+ function npm_use_module () {
42
+ node -e '
43
+ fs = require("fs");
44
+ p = JSON.parse(fs.readFileSync("package.json", "utf8"));
45
+ p.devDependencies[process.argv[1]] = process.argv[2];
46
+ fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n");
47
+ ' "$@"
48
+ }
49
+ function v () {
50
+ tr '.' '\n' <<< "${1}" \
51
+ | awk '{ printf "%03d", $0 }' \
52
+ | sed 's/^0*//'
53
+ }
22
54
# Configure npm
23
55
- |
24
56
# Skip updating shrinkwrap / lock
25
57
npm config set shrinkwrap false
26
58
# Remove all non-test dependencies
27
59
- |
28
60
# Remove benchmark dependencies
29
- npm rm --save-dev beautify- benchmark benchmark
61
+ npm_remove_module_re '(^|-) benchmark$'
30
62
# Setup Node.js version-specific dependencies
31
63
- |
32
- # mocha for testing
33
- # - use 2.x for Node.js < 0.10
34
- # - use 3.x for Node.js < 6
35
- if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then
36
- npm install --save-dev [email protected]
37
- elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then
38
- npm install --save-dev [email protected]
64
+ # Configure istanbul for coverage
65
+ if node_version_lt '0.10'; then npm_remove_module_re '^istanbul$'
39
66
fi
40
67
- |
41
- # istanbul for coverage
42
- # - remove for Node.js < 0.10
43
- if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then
44
- npm rm --silent --save-dev istanbul
68
+ # Configure eslint for linting
69
+ if node_version_lt '6.0'; then npm_remove_module_re '^eslint(-|$)'
45
70
fi
46
71
- |
47
- # eslint for linting
48
- # - remove on Node.js < 6
49
- if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then
50
- node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \
51
- grep -E '^eslint(-|$)' | \
52
- xargs npm rm --save-dev
72
+ # Configure mocha for testing
73
+ if node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3'
74
+ elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3'
53
75
fi
54
76
# Update Node.js modules
55
77
- |
@@ -58,18 +80,19 @@ before_install:
58
80
npm prune
59
81
npm rebuild
60
82
fi
83
+ before_scrpt :
84
+ - |
85
+ # Contents of node_modules
86
+ npm -s ls ||:
61
87
script :
62
- # Run test script
63
88
- |
64
- if npm -ps ls istanbul | grep -q istanbul; then
65
- npm run test-travis
66
- else
67
- npm test
89
+ # Run test script, depending on istanbul install
90
+ if npm_module_installed 'istanbul'; then npm run-script test-travis
91
+ else npm test
68
92
fi
69
- # Run linting
70
93
- |
71
- if npm -ps ls eslint | grep -q eslint; then
72
- npm run lint
94
+ # Run linting, if eslint exists
95
+ if npm_module_installed 'eslint'; then npm run-script lint
73
96
fi
74
97
after_script :
75
98
- |
0 commit comments