Skip to content

Commit 96e81a5

Browse files
authored
refactor: simplify commitlint alias package (#965)
1 parent b27ab08 commit 96e81a5

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

@alias/commitlint/cli.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
#!/usr/bin/env node
2-
const path = require('path');
3-
const resolvePkg = require('resolve-pkg');
4-
const readPkg = require('read-pkg');
5-
6-
const pkgDir = resolvePkg('@commitlint/cli', {cwd: __dirname});
7-
const manifest = readPkg.sync({cwd: pkgDir});
8-
const bin = path.join(pkgDir, manifest.bin.commitlint);
9-
10-
require(bin);
2+
const pkgDir = require('@commitlint/cli');
3+
require(pkgDir);

@alias/commitlint/cli.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import execa from 'execa';
2+
import {fix} from '@commitlint/test';
3+
4+
const bin = require.resolve('./cli.js');
5+
6+
function cli(args, options, input) {
7+
const c = execa(bin, args, {
8+
cwd: options.cwd,
9+
env: options.env,
10+
input: input
11+
});
12+
return c.catch(err => err);
13+
}
14+
15+
const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname);
16+
17+
test('should reprint input from stdin', async () => {
18+
const cwd = await fixBootstrap('fixtures/default');
19+
const actual = await cli([], {cwd}, 'foo: bar');
20+
expect(actual.stdout).toContain('foo: bar');
21+
});
22+
23+
test('should produce success output with --verbose flag', async () => {
24+
const cwd = await fixBootstrap('fixtures/default');
25+
const actual = await cli(['--verbose'], {cwd}, 'type: bar');
26+
expect(actual.stdout).toContain('0 problems, 0 warnings');
27+
expect(actual.stderr).toEqual('');
28+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'type-enum': [2, 'never', ['foo']]
4+
}
5+
};

@alias/commitlint/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@
3434
},
3535
"license": "MIT",
3636
"dependencies": {
37-
"@commitlint/cli": "^8.3.5",
38-
"read-pkg": "5.2.0",
39-
"resolve-pkg": "2.0.0"
37+
"@commitlint/cli": "^8.3.5"
4038
},
4139
"devDependencies": {
42-
"@commitlint/utils": "^8.3.4"
40+
"@commitlint/utils": "^8.3.4",
41+
"@commitlint/test": "8.2.0"
4342
}
4443
}

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
testMatch: [
66
'**/*.test.ts?(x)',
77
'**/@commitlint/{lint,read,travis-cli,cli,load,prompt}/src/**/*.test.js?(x)',
8-
'**/@commitlint/{prompt-cli,config-lerna-scopes}/*.test.js?(x)'
8+
'**/@commitlint/{prompt-cli,config-lerna-scopes}/*.test.js?(x)',
9+
'**/@alias/commitlint/*.test.js?(x)'
910
]
1011
};

0 commit comments

Comments
 (0)