Skip to content

Commit 70b8278

Browse files
authored
chore: lighter transformation (#65)
* test(cli): add failing integration test * fix: determine git root correctly from sub directories * chore: make transformation lighter * chore: unify babel config in babel-preset-commitlint * fix: make this work * fix: sudo make this work * fix: sudo make this work * fix(babel-preset-commitlint): use correct imports * fix: remove usage of [].includes * docs: clarify lowest node version
1 parent a077d8d commit 70b8278

File tree

14 files changed

+161
-143
lines changed

14 files changed

+161
-143
lines changed

Diff for: @commitlint/cli/cli.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path';
22
import test from 'ava';
33
import execa from 'execa';
4+
import {includes} from 'lodash';
45
import {sync as bin} from 'resolve-bin';
56
import * as sander from 'sander';
67
import stream from 'string-to-stream';
@@ -44,7 +45,7 @@ test('should throw when called without [input]', t => {
4445

4546
test('should reprint input from stdin', async t => {
4647
const actual = await cli([], {cwd: EMPTY})('foo: bar');
47-
t.true(actual.stdout.includes('foo: bar'));
48+
t.true(includes(actual.stdout, 'foo: bar'));
4849
});
4950

5051
test('should produce no success output with --quiet flag', async t => {
@@ -66,15 +67,15 @@ test('should succeed for input from stdin without rules', async t => {
6667

6768
test('should fail for input from stdin with rule from rc', async t => {
6869
const actual = await t.throws(cli([], {cwd: SIMPLE})('foo: bar'));
69-
t.true(actual.stdout.includes('type must not be one of [foo]'));
70+
t.true(includes(actual.stdout, 'type must not be one of [foo]'));
7071
t.is(actual.code, 1);
7172
});
7273

7374
test('should fail for input from stdin with rule from js', async t => {
7475
const actual = await t.throws(
7576
cli(['--extends', './extended'], {cwd: EXTENDS_ROOT})('foo: bar')
7677
);
77-
t.true(actual.stdout.includes('type must not be one of [foo]'));
78+
t.true(includes(actual.stdout, 'type must not be one of [foo]'));
7879
t.is(actual.code, 1);
7980
});
8081

Diff for: @commitlint/core/package.json

+5-55
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"pretest": "dep-check",
88
"test": "ava -c 4",
9-
"build": "cross-env NODE_ENV=production babel src --out-dir lib",
9+
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
10+
"watch": "babel src --out-dir lib --watch --source-maps",
1011
"clean": "rimraf lib",
1112
"prepublish": "npm run build"
1213
},
@@ -21,53 +22,11 @@
2122
],
2223
"babel": "inherit",
2324
"require": [
24-
"babel-register",
25-
"babel-polyfill"
25+
"babel-register"
2626
]
2727
},
2828
"babel": {
29-
"env": {
30-
"development": {
31-
"sourceMaps": "inline",
32-
"plugins": [
33-
"add-module-exports",
34-
"istanbul",
35-
[
36-
"transform-runtime",
37-
{
38-
"polyfill": false,
39-
"regenerator": true
40-
}
41-
]
42-
]
43-
},
44-
"production": {
45-
"ignore": [
46-
"**/*.test.js"
47-
]
48-
}
49-
},
50-
"presets": [
51-
[
52-
"env",
53-
{
54-
"targets": {
55-
"node": 4
56-
}
57-
}
58-
],
59-
"stage-0"
60-
],
61-
"plugins": [
62-
"add-module-exports",
63-
[
64-
"transform-runtime",
65-
{
66-
"polyfill": false,
67-
"regenerator": true
68-
}
69-
]
70-
]
29+
"presets": ["babel-preset-commitlint"]
7130
},
7231
"xo": false,
7332
"nyc": {
@@ -105,20 +64,11 @@
10564
"ansi-styles": "3.1.0",
10665
"ava": "0.18.2",
10766
"babel-cli": "^6.18.0",
108-
"babel-plugin-add-module-exports": "0.2.1",
109-
"babel-plugin-istanbul": "4.1.3",
110-
"babel-plugin-transform-runtime": "6.23.0",
111-
"babel-polyfill": "^6.20.0",
112-
"babel-preset-env": "^1.2.1",
113-
"babel-preset-stage-0": "^6.16.0",
67+
"babel-preset-commitlint": "^3.1.3",
11468
"babel-register": "6.24.1",
115-
"conventional-changelog-cli": "1.2.0",
116-
"conventional-recommended-bump": "0.3.0",
11769
"cross-env": "^5.0.1",
118-
"cz-conventional-changelog-lint": "0.1.3",
11970
"denodeify": "1.2.1",
12071
"dependency-check": "2.7.0",
121-
"eslint-plugin-flow-check": "1.1.1",
12272
"execa": "0.6.3",
12373
"globby": "6.1.0",
12474
"has-ansi": "3.0.0",

Diff for: @commitlint/core/src/format.test.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import test from 'ava';
22
import hasAnsi from 'has-ansi';
33
import chalk from 'chalk';
44
import {yellow, red, magenta, blue} from 'ansi-styles';
5+
import {includes} from 'lodash';
56
import format from './format';
67

78
const ok = chalk.bold(`${chalk.green('✔')} found 0 problems, 0 warnings`);
@@ -43,9 +44,9 @@ test('returns a correct of empty .errors and .warnings', t => {
4344
]
4445
});
4546

46-
t.true(err.includes('There was an error'));
47-
t.true(prob.includes('There was a problem'));
48-
t.true(msg.includes('1 problems, 1 warnings'));
47+
t.true(includes(err, 'There was an error'));
48+
t.true(includes(prob, 'There was a problem'));
49+
t.true(includes(msg, '1 problems, 1 warnings'));
4950
});
5051

5152
test('colors messages by default', t => {
@@ -79,8 +80,8 @@ test('uses appropriate signs by default', t => {
7980
]
8081
});
8182

82-
t.true(err.includes('✖'));
83-
t.true(warn.includes('⚠'));
83+
t.true(includes(err, '✖'));
84+
t.true(includes(warn, '⚠'));
8485
});
8586

8687
test('uses signs as configured', t => {
@@ -106,8 +107,8 @@ test('uses signs as configured', t => {
106107
}
107108
);
108109

109-
t.true(err.includes('ERR'));
110-
t.true(warn.includes('WRN'));
110+
t.true(includes(err, 'ERR'));
111+
t.true(includes(warn, 'WRN'));
111112
});
112113

113114
test('uses appropriate colors by default', t => {
@@ -128,8 +129,8 @@ test('uses appropriate colors by default', t => {
128129
]
129130
});
130131

131-
t.true(err.includes(red.open));
132-
t.true(warn.includes(yellow.open));
132+
t.true(includes(err, red.open));
133+
t.true(includes(warn, yellow.open));
133134
});
134135

135136
if (process.platform !== 'win32') {
@@ -156,7 +157,7 @@ if (process.platform !== 'win32') {
156157
}
157158
);
158159

159-
t.true(err.includes(blue.open));
160-
t.true(warn.includes(magenta.open));
160+
t.true(includes(err, blue.open));
161+
t.true(includes(warn, magenta.open));
161162
});
162163
}

Diff for: @commitlint/core/src/library/ensure-language.test.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,63 @@
11
import test from 'ava';
2+
import {includes} from 'lodash';
23
import ensure from './ensure-language';
34

45
test('true for no params', t => {
56
const actual = ensure();
67
t.is(actual.matches, true);
7-
t.is(actual.detected.includes('und'), true);
8+
t.is(includes(actual.detected, 'und'), true);
89
});
910

1011
test.failing('true for chinese on chi', t => {
1112
const actual = ensure('這是一個嚴重的問題', 'chi');
1213
t.is(actual.matches, true);
13-
t.is(actual.detected.includes('chi'), true);
14+
t.is(includes(actual.detected, 'chi'), true);
1415
});
1516

1617
test('true for spanish on spa', t => {
1718
const actual = ensure('Este es un asunto serio', 'spa');
1819
t.is(actual.matches, true);
19-
t.is(actual.detected.includes('spa'), true);
20+
t.is(includes(actual.detected, 'spa'), true);
2021
});
2122

2223
test('true for english on eng', t => {
2324
const actual = ensure('This is a serious subject', 'eng');
2425
t.is(actual.matches, true);
25-
t.is(actual.detected.includes('eng'), true);
26+
t.is(includes(actual.detected, 'eng'), true);
2627
});
2728

2829
test('true for hindi on hin', t => {
2930
const actual = ensure('यह एक गंभीर मुद्दा है', 'hin');
3031
t.is(actual.matches, true);
31-
t.is(actual.detected.includes('hin'), true);
32+
t.is(includes(actual.detected, 'hin'), true);
3233
});
3334

3435
test('true for portugese on por', t => {
3536
const actual = ensure('Este é um assunto sério', 'por');
3637
t.is(actual.matches, true);
37-
t.is(actual.detected.includes('por'), true);
38+
t.is(includes(actual.detected, 'por'), true);
3839
});
3940

4041
test.failing('false for chinese on eng', t => {
4142
const actual = ensure('這是一個嚴重的問題', 'eng');
4243
t.is(actual.matches, false);
43-
t.is(actual.detected.includes('chi'), true);
44+
t.is(includes(actual.detected, 'chi'), true);
4445
});
4546

4647
test('false for spanish on eng', t => {
4748
const actual = ensure('Este es un asunto serio', 'eng');
4849
t.is(actual.matches, false);
49-
t.is(actual.detected.includes('spa'), true);
50+
t.is(includes(actual.detected, 'spa'), true);
5051
});
5152

5253
test('false for hindi on eng', t => {
5354
const actual = ensure('यह एक गंभीर मुद्दा है', 'eng');
5455
t.is(actual.matches, false);
55-
t.is(actual.detected.includes('hin'), true);
56+
t.is(includes(actual.detected, 'hin'), true);
5657
});
5758

5859
test('false for portugese on eng', t => {
5960
const actual = ensure('Este é um assunto sério', 'eng');
6061
t.is(actual.matches, false);
61-
t.is(actual.detected.includes('por'), true);
62+
t.is(includes(actual.detected, 'por'), true);
6263
});

Diff for: @commitlint/core/src/load.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ export default async (seed = {}) => {
4141
key,
4242
executedValue.reduce((registry, item) => {
4343
const [key, value] = item;
44-
return {
45-
...registry,
46-
[key]: value
47-
};
44+
registry[key] = value;
45+
return registry;
4846
}, {})
4947
];
5048
})
@@ -53,10 +51,8 @@ export default async (seed = {}) => {
5351
// Merge executed config keys into preset
5452
return executed.reduce((registry, item) => {
5553
const [key, value] = item;
56-
return {
57-
...registry,
58-
[key]: value
59-
};
54+
registry[key] = value;
55+
return registry;
6056
}, preset);
6157
};
6258

Diff for: @commitlint/prompt/package.json

+4-47
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "commitizen prompt using commitlint.config.js",
55
"main": "./lib/index.js",
66
"scripts": {
7-
"build": "cross-env NODE_ENV=production babel src --out-dir lib",
7+
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
8+
"watch": "babel src --out-dir lib --watch --source-maps",
89
"clean": "rimraf lib",
910
"commit": "git-cz",
1011
"pretest": "dep-check",
@@ -24,47 +25,7 @@
2425
]
2526
},
2627
"babel": {
27-
"env": {
28-
"development": {
29-
"sourceMaps": "inline",
30-
"plugins": [
31-
"add-module-exports",
32-
[
33-
"transform-runtime",
34-
{
35-
"polyfill": false,
36-
"regenerator": true
37-
}
38-
]
39-
]
40-
},
41-
"production": {
42-
"ignore": [
43-
"**/*.test.js"
44-
]
45-
}
46-
},
47-
"presets": [
48-
[
49-
"env",
50-
{
51-
"targets": {
52-
"node": 4
53-
}
54-
}
55-
],
56-
"stage-0"
57-
],
58-
"plugins": [
59-
"add-module-exports",
60-
[
61-
"transform-runtime",
62-
{
63-
"polyfill": false,
64-
"regenerator": true
65-
}
66-
]
67-
]
28+
"presets": ["commitlint"]
6829
},
6930
"config": {
7031
"commitizen": {
@@ -93,18 +54,14 @@
9354
"@commitlint/utils": "^3.1.1",
9455
"ava": "^0.20.0",
9556
"babel-cli": "^6.24.1",
96-
"babel-plugin-add-module-exports": "^0.2.1",
97-
"babel-plugin-transform-runtime": "^6.23.0",
98-
"babel-preset-env": "^1.6.0",
99-
"babel-preset-stage-0": "^6.24.1",
57+
"babel-preset-commitlint": "3.1.3",
10058
"babel-register": "^6.24.1",
10159
"commitizen": "^2.9.6",
10260
"cross-env": "^5.0.1",
10361
"throat": "^4.1.0"
10462
},
10563
"dependencies": {
10664
"@commitlint/core": "^3.1.3",
107-
"babel-polyfill": "^6.23.0",
10865
"babel-runtime": "^6.23.0",
10966
"chalk": "^1.1.1",
11067
"lodash": "^4.17.4",

Diff for: @commitlint/prompt/src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable import/no-unassigned-import, import/prefer-default-export */
2-
import 'babel-polyfill';
32
import vorpal from 'vorpal';
43
import input from './input';
54

Diff for: @commitlint/prompt/src/library/format.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ function format(input, debug = false) {
1313
const results = debug
1414
? entries(input).reduce((registry, item) => {
1515
const [name, value] = item;
16-
return {
17-
...registry,
18-
[name]: value === null ? chalk.grey(`<${name}>`) : chalk.bold(value)
19-
};
16+
registry[name] = value === null ? chalk.grey(`<${name}>`) : chalk.bold(value)
17+
return registry;
2018
}, {})
2119
: input;
2220

0 commit comments

Comments
 (0)