Skip to content

Commit 79b2283

Browse files
committed
Merge branch 'master' into refactor/prompt2
2 parents f6c8b7d + c2c257d commit 79b2283

File tree

32 files changed

+675
-1310
lines changed

32 files changed

+675
-1310
lines changed

.eslintrc.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ module.exports = {
2727
// Forbid a module from importing itself
2828
'import/no-self-import': 'error',
2929

30-
// Enable after https://github.com/benmosher/eslint-plugin-import/issues/1650 is fixed
3130
// Forbid the use of extraneous packages
32-
// 'import/no-extraneous-dependencies': [
33-
// 'error',
34-
// {devDependencies: ['**/*.test.js']}
35-
// ]
31+
'import/no-extraneous-dependencies': [
32+
'error',
33+
{
34+
devDependencies: ['**/*.test.js', '**/*.test.ts'],
35+
},
36+
],
3637
},
3738
overrides: [
3839
{

@alias/commitlint/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
},
3535
"license": "MIT",
3636
"dependencies": {
37-
"@commitlint/cli": "^11.0.0"
37+
"@commitlint/cli": "^11.0.0",
38+
"@commitlint/types": "^11.0.0"
3839
},
3940
"devDependencies": {
4041
"@commitlint/test": "^11.0.0",
41-
"@commitlint/utils": "^11.0.0"
42+
"@commitlint/utils": "^11.0.0",
43+
"execa": "^5.0.0"
4244
},
4345
"gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca"
4446
}

@commitlint/cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@commitlint/lint": "^11.0.0",
4848
"@commitlint/load": "^11.0.0",
4949
"@commitlint/read": "^11.0.0",
50+
"@commitlint/types": "^11.0.0",
5051
"get-stdin": "8.0.0",
5152
"lodash": "^4.17.19",
5253
"resolve-from": "5.0.0",

@commitlint/cli/src/cli.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ test('should print help', async () => {
446446
Options:
447447
-c, --color toggle colored output [boolean] [default: true]
448448
-g, --config path to the config file [string]
449+
--print-config print resolved config [boolean] [default: false]
449450
-d, --cwd directory to execute in
450451
[string] [default: (Working Directory)]
451452
-e, --edit read last commit message from the specified file or
@@ -475,6 +476,27 @@ test('should print version', async () => {
475476
expect(actual.stdout).toMatch('@commitlint/cli@');
476477
});
477478

479+
test('should print config', async () => {
480+
const cwd = await gitBootstrap('fixtures/default');
481+
const actual = await cli(['--print-config', '--no-color'], {cwd})();
482+
const stdout = actual.stdout
483+
.replace(/^{[^\n]/g, '{\n ')
484+
.replace(/[^\n]}$/g, '\n}')
485+
.replace(/(helpUrl:)\n[ ]+/, '$1 ');
486+
expect(stdout).toMatchInlineSnapshot(`
487+
"{
488+
extends: [],
489+
formatter: '@commitlint/format',
490+
parserPreset: undefined,
491+
ignores: undefined,
492+
defaultIgnores: undefined,
493+
plugins: {},
494+
rules: { 'type-enum': [ 2, 'never', [ 'foo' ] ] },
495+
helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
496+
}"
497+
`);
498+
});
499+
478500
async function writePkg(payload: unknown, options: TestOptions) {
479501
const pkgPath = path.join(options.cwd, 'package.json');
480502
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));

@commitlint/cli/src/cli.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import stdin from 'get-stdin';
66
import resolveFrom from 'resolve-from';
77
import resolveGlobal from 'resolve-global';
88
import yargs from 'yargs';
9+
import util from 'util';
910

1011
import {CliFlags, Seed} from './types';
1112
import {
@@ -33,6 +34,11 @@ const cli = yargs
3334
description: 'path to the config file',
3435
type: 'string',
3536
},
37+
'print-config': {
38+
type: 'boolean',
39+
default: false,
40+
description: 'print resolved config',
41+
},
3642
cwd: {
3743
alias: 'd',
3844
default: process.cwd(),
@@ -123,6 +129,16 @@ main({edit: false, ...cli.argv}).catch((err) => {
123129
async function main(options: CliFlags) {
124130
const raw = options._;
125131
const flags = normalizeFlags(options);
132+
133+
if (flags['print-config']) {
134+
const loaded = await load(getSeed(flags), {
135+
cwd: flags.cwd,
136+
file: flags.config,
137+
});
138+
console.log(util.inspect(loaded, false, null, options.color));
139+
return;
140+
}
141+
126142
const fromStdin = checkFromStdin(raw, flags);
127143

128144
const input = await (fromStdin
@@ -149,8 +165,10 @@ async function main(options: CliFlags) {
149165
throw err;
150166
}
151167

152-
const loadOpts = {cwd: flags.cwd, file: flags.config};
153-
const loaded = await load(getSeed(flags), loadOpts);
168+
const loaded = await load(getSeed(flags), {
169+
cwd: flags.cwd,
170+
file: flags.config,
171+
});
154172
const parserOpts = selectParserOpts(loaded.parserPreset);
155173
const opts: LintOptions & {parserOpts: ParserOptions} = {
156174
parserOpts: {},

@commitlint/cli/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface CliFlags {
1414
to?: string;
1515
version?: boolean;
1616
verbose?: boolean;
17+
'print-config'?: boolean;
1718
_: string[];
1819
$0: string;
1920
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@packages/a",
3+
"version": "1.0.0"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@packages/b",
3+
"version": "1.0.0"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "yarn",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"lerna": "^3.0.0"
6+
},
7+
"workspaces": [
8+
"@packages/*"
9+
]
10+
}

@commitlint/config-lerna-scopes/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Path = require('path');
22
const importFrom = require('import-from');
33
const resolvePkg = require('resolve-pkg');
4+
const Globby = require('globby');
45
const semver = require('semver');
56

67
module.exports = {
@@ -16,8 +17,21 @@ function getPackages(context) {
1617
.then(() => {
1718
const ctx = context || {};
1819
const cwd = ctx.cwd || process.cwd();
19-
const lernaVersion = getLernaVersion(cwd);
2020

21+
const {workspaces} = require(Path.join(cwd, 'package.json'));
22+
if (Array.isArray(workspaces) && workspaces.length) {
23+
// use yarn workspaces
24+
return Globby(
25+
workspaces.map((ws) => {
26+
return Path.posix.join(ws, 'package.json');
27+
}),
28+
{cwd}
29+
).then((pJsons = []) => {
30+
return pJsons.map((pJson) => require(Path.join(cwd, pJson)));
31+
});
32+
}
33+
34+
const lernaVersion = getLernaVersion(cwd);
2135
if (semver.lt(lernaVersion, '3.0.0')) {
2236
const Repository = importFrom(cwd, 'lerna/lib/Repository');
2337
const PackageUtilities = importFrom(cwd, 'lerna/lib/PackageUtilities');

@commitlint/config-lerna-scopes/index.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Path from 'path';
12
import {lerna} from '@commitlint/test';
23
import config from '.';
34

@@ -66,3 +67,10 @@ test('returns expected value for scoped lerna repository', async () => {
6667
const [, , value] = await fn({cwd});
6768
expect(value).toEqual(['a', 'b']);
6869
});
70+
71+
test('returns expected value for yarn workspaces', async () => {
72+
const {'scope-enum': fn} = config.rules;
73+
const cwd = Path.join(__dirname, 'fixtures', 'yarn');
74+
const [, , value] = await fn({cwd});
75+
expect(value.sort()).toEqual(['a', 'b']);
76+
});

@commitlint/config-lerna-scopes/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@commitlint/config-lerna-scopes",
33
"version": "11.0.0",
4-
"description": "Shareable commitlint config enforcing lerna package names as scopes",
4+
"description": "Shareable commitlint config enforcing lerna package and workspace names as scopes",
55
"files": [
66
"index.js"
77
],
@@ -32,6 +32,7 @@
3232
"node": ">=v10"
3333
},
3434
"dependencies": {
35+
"globby": "^11.0.1",
3536
"import-from": "3.0.0",
3637
"resolve-pkg": "2.0.0",
3738
"semver": "7.3.4"

@commitlint/config-lerna-scopes/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
# @commitlint/config-lerna-scopes
44

5-
Shareable `commitlint` config enforcing lerna package names as scopes.
5+
Shareable `commitlint` config enforcing lerna package and workspace names as scopes.
66
Use with [@commitlint/cli](../cli) and [@commitlint/prompt-cli](../prompt-cli).
77

88
## Getting started

@commitlint/ensure/jest.config.js

-4
This file was deleted.

@commitlint/execute-rule/jest.config.js

-4
This file was deleted.

@commitlint/format/jest.config.js

-4
This file was deleted.

@commitlint/load/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@commitlint/execute-rule": "^11.0.0",
4444
"@commitlint/resolve-extends": "^11.0.0",
4545
"@commitlint/types": "^11.0.0",
46-
"chalk": "4.1.0",
46+
"chalk": "^4.0.0",
4747
"cosmiconfig": "^7.0.0",
4848
"lodash": "^4.17.19",
4949
"resolve-from": "^5.0.0"

@commitlint/parse/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@commitlint/utils": "^11.0.0"
3939
},
4040
"dependencies": {
41+
"@commitlint/types": "^11.0.0",
4142
"conventional-changelog-angular": "^5.0.11",
4243
"conventional-commits-parser": "^3.0.0"
4344
},

@commitlint/prompt/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"dependencies": {
4646
"@commitlint/load": "^11.0.0",
47+
"@commitlint/types": "^11.0.0",
4748
"chalk": "^4.0.0",
4849
"lodash": "^4.17.19"
4950
},

@commitlint/read/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
"@commitlint/test": "^11.0.0",
3838
"@commitlint/utils": "^11.0.0",
3939
"@types/fs-extra": "^9.0.1",
40-
"@types/git-raw-commits": "^2.0.0"
40+
"@types/git-raw-commits": "^2.0.0",
41+
"execa": "^5.0.0"
4142
},
4243
"dependencies": {
4344
"@commitlint/top-level": "^11.0.0",
45+
"@commitlint/types": "^11.0.0",
4446
"fs-extra": "^9.0.0",
4547
"git-raw-commits": "^2.0.0"
4648
},

@commitlint/resolve-extends/jest.config.js

-4
This file was deleted.

@commitlint/to-lines/jest.config.js

-4
This file was deleted.

@commitlint/types/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"email": "[email protected]"
2727
},
2828
"license": "MIT",
29+
"dependencies": {
30+
"chalk": "^4.0.0"
31+
},
2932
"devDependencies": {
3033
"@commitlint/utils": "^11.0.0"
3134
},

0 commit comments

Comments
 (0)