Skip to content

Commit a5e658a

Browse files
committed
fix: ensure node4 compat
1 parent 94437e8 commit a5e658a

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

@commitlint/cli/cli.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const help = require('./help');
1616
*/
1717
const rules = {
1818
fromStdin: (input, flags) => input.length === 0 &&
19-
flags.from === null &&
20-
flags.to === null &&
19+
typeof flags.from !== 'string' &&
20+
typeof flags.to !== 'string' &&
2121
!flags.edit
2222
};
2323

@@ -62,7 +62,8 @@ const cli = meow({
6262
const load = seed => core.load(seed);
6363

6464
function main(options) {
65-
const {input: raw, flags} = options;
65+
const raw = options.input;
66+
const flags = options.flags;
6667
const fromStdin = rules.fromStdin(raw, flags);
6768

6869
const range = pick(flags, 'edit', 'from', 'to');
@@ -93,8 +94,10 @@ function main(options) {
9394
));
9495
}
9596

96-
function getSeed({extends: e}) {
97-
return e ? {extends: e.split(', ')} : {};
97+
function getSeed(seed) {
98+
const e = Array.isArray(seed.extends) ? seed.extends : [seed.extends];
99+
const n = e.filter(i => typeof i === 'string');
100+
return n.length > 0 ? {extends: n} : {};
98101
}
99102

100103
// Start the engine

@commitlint/cli/help.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = configuration => {
22
const lines = Object.entries(configuration.description)
33
.map(entry => {
4-
const [name, desc] = entry;
4+
const name = entry[0];
5+
const desc = entry[1];
56
const alias = Object.entries(configuration.alias)
67
.find(entry => entry[1] === name)
78
.map(entry => entry[0])[0];
@@ -11,14 +12,16 @@ module.exports = configuration => {
1112

1213
const longest = lines
1314
.map(line => {
14-
const [flags] = line;
15+
const flags = line[0];
1516
return flags.reduce((sum, flag) => sum + flag.length, 0);
1617
})
1718
.sort(Number)[0];
1819

1920
return lines
2021
.map(line => {
21-
const [flags, desc, defaults] = line;
22+
const flags = line[0];
23+
const desc = line[1];
24+
const defaults = line[2];
2225
const fs = flags.map(flag => flag.length > 1 ? `--${flag}` : `-${flag}`);
2326
const ds = defaults ? `, defaults to: ${defaults}` : '';
2427
const length = flags.reduce((sum, flag) => sum + flag.length, 0);

@commitlint/core/src/library/resolve-extends.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import from from 'resolve-from';
3-
import {merge, omit, values} from 'lodash';
3+
import {merge, omit} from 'lodash';
44

55
// Resolve extend configs
66
export default function resolveExtends(config = {}, context = {}) {
@@ -18,8 +18,7 @@ export default function resolveExtends(config = {}, context = {}) {
1818

1919
// (any, string, string, Function) => any[];
2020
function loadExtends(config = {}, context = {}) {
21-
const toExtend = values(config.extends || []);
22-
return toExtend.reduce((configs, raw) => {
21+
return (config.extends || []).reduce((configs, raw) => {
2322
const id = getId(raw, context.prefix);
2423
const resolve = context.resolve || resolveId;
2524
const resolved = resolve(id, context);
@@ -46,7 +45,6 @@ function getId(raw = '', prefix = '') {
4645
return (scoped || relative) ? raw : [prefix, raw].filter(String).join('-');
4746
}
4847

49-
function resolveId(id, context) {
50-
const cwd = context.cwd || process.cwd();
51-
return from(cwd, id);
48+
function resolveId(id, context = {}) {
49+
return from(context.cwd || process.cwd(), id);
5250
}

0 commit comments

Comments
 (0)