Skip to content

refactor(commitlint): simplify commitlint alias package #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions @alias/commitlint/cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#!/usr/bin/env node
const path = require('path');
const resolvePkg = require('resolve-pkg');
const readPkg = require('read-pkg');

const pkgDir = resolvePkg('@commitlint/cli', {cwd: __dirname});
const manifest = readPkg.sync({cwd: pkgDir});
const bin = path.join(pkgDir, manifest.bin.commitlint);

require(bin);
const pkgDir = require('@commitlint/cli');
require(pkgDir);
Copy link
Contributor Author

@armano2 armano2 Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be even simpler as we can directly import

require('@commitlint/cli/lib/cli');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on the simplification. Let's keep the current solution to maintain a degree of decoupling so we can move around the the commitlint bin file inside of @commitlint/cli if we want to.

28 changes: 28 additions & 0 deletions @alias/commitlint/cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import execa from 'execa';
import {fix} from '@commitlint/test';

const bin = require.resolve('./cli.js');

function cli(args, options, input) {
const c = execa(bin, args, {
cwd: options.cwd,
env: options.env,
input: input
});
return c.catch(err => err);
}

const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname);

test('should reprint input from stdin', async () => {
const cwd = await fixBootstrap('fixtures/default');
const actual = await cli([], {cwd}, 'foo: bar');
expect(actual.stdout).toContain('foo: bar');
});

test('should produce success output with --verbose flag', async () => {
const cwd = await fixBootstrap('fixtures/default');
const actual = await cli(['--verbose'], {cwd}, 'type: bar');
expect(actual.stdout).toContain('0 problems, 0 warnings');
expect(actual.stderr).toEqual('');
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm unsure if we really need tests for this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick smoke tests are in order via #889

5 changes: 5 additions & 0 deletions @alias/commitlint/fixtures/default/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'type-enum': [2, 'never', ['foo']]
}
};
7 changes: 3 additions & 4 deletions @alias/commitlint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
},
"license": "MIT",
"dependencies": {
"@commitlint/cli": "^8.3.5",
"read-pkg": "5.2.0",
"resolve-pkg": "2.0.0"
"@commitlint/cli": "^8.3.5"
},
"devDependencies": {
"@commitlint/utils": "^8.3.4"
"@commitlint/utils": "^8.3.4",
"@commitlint/test": "8.2.0"
}
}
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
testMatch: [
'**/*.test.ts?(x)',
'**/@commitlint/{lint,read,travis-cli,cli,load,prompt}/src/**/*.test.js?(x)',
'**/@commitlint/{prompt-cli,config-lerna-scopes}/*.test.js?(x)'
'**/@commitlint/{prompt-cli,config-lerna-scopes}/*.test.js?(x)',
'**/@alias/commitlint/*.test.js?(x)'
]
};