Skip to content

Commit

Permalink
Merge branch 'master' into refactor/load
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Jan 11, 2021
2 parents 0a131f7 + c2c257d commit f6aab6b
Show file tree
Hide file tree
Showing 32 changed files with 671 additions and 1,232 deletions.
11 changes: 6 additions & 5 deletions .eslintrc.js
Expand Up @@ -27,12 +27,13 @@ module.exports = {
// Forbid a module from importing itself
'import/no-self-import': 'error',

// Enable after https://github.com/benmosher/eslint-plugin-import/issues/1650 is fixed
// Forbid the use of extraneous packages
// 'import/no-extraneous-dependencies': [
// 'error',
// {devDependencies: ['**/*.test.js']}
// ]
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/*.test.js', '**/*.test.ts'],
},
],
},
overrides: [
{
Expand Down
6 changes: 4 additions & 2 deletions @alias/commitlint/package.json
Expand Up @@ -34,11 +34,13 @@
},
"license": "MIT",
"dependencies": {
"@commitlint/cli": "^11.0.0"
"@commitlint/cli": "^11.0.0",
"@commitlint/types": "^11.0.0"
},
"devDependencies": {
"@commitlint/test": "^11.0.0",
"@commitlint/utils": "^11.0.0"
"@commitlint/utils": "^11.0.0",
"execa": "^5.0.0"
},
"gitHead": "cb565dfcca3128380b9b3dc274aedbcae34ce5ca"
}
1 change: 1 addition & 0 deletions @commitlint/cli/package.json
Expand Up @@ -47,6 +47,7 @@
"@commitlint/lint": "^11.0.0",
"@commitlint/load": "^11.0.0",
"@commitlint/read": "^11.0.0",
"@commitlint/types": "^11.0.0",
"get-stdin": "8.0.0",
"lodash": "^4.17.19",
"resolve-from": "5.0.0",
Expand Down
22 changes: 22 additions & 0 deletions @commitlint/cli/src/cli.test.ts
Expand Up @@ -446,6 +446,7 @@ test('should print help', async () => {
Options:
-c, --color toggle colored output [boolean] [default: true]
-g, --config path to the config file [string]
--print-config print resolved config [boolean] [default: false]
-d, --cwd directory to execute in
[string] [default: (Working Directory)]
-e, --edit read last commit message from the specified file or
Expand Down Expand Up @@ -475,6 +476,27 @@ test('should print version', async () => {
expect(actual.stdout).toMatch('@commitlint/cli@');
});

test('should print config', async () => {
const cwd = await gitBootstrap('fixtures/default');
const actual = await cli(['--print-config', '--no-color'], {cwd})();
const stdout = actual.stdout
.replace(/^{[^\n]/g, '{\n ')
.replace(/[^\n]}$/g, '\n}')
.replace(/(helpUrl:)\n[ ]+/, '$1 ');
expect(stdout).toMatchInlineSnapshot(`
"{
extends: [],
formatter: '@commitlint/format',
parserPreset: undefined,
ignores: undefined,
defaultIgnores: undefined,
plugins: {},
rules: { 'type-enum': [ 2, 'never', [ 'foo' ] ] },
helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
}"
`);
});

async function writePkg(payload: unknown, options: TestOptions) {
const pkgPath = path.join(options.cwd, 'package.json');
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));
Expand Down
22 changes: 20 additions & 2 deletions @commitlint/cli/src/cli.ts
Expand Up @@ -6,6 +6,7 @@ import stdin from 'get-stdin';
import resolveFrom from 'resolve-from';
import resolveGlobal from 'resolve-global';
import yargs from 'yargs';
import util from 'util';

import {CliFlags, Seed} from './types';
import {
Expand Down Expand Up @@ -33,6 +34,11 @@ const cli = yargs
description: 'path to the config file',
type: 'string',
},
'print-config': {
type: 'boolean',
default: false,
description: 'print resolved config',
},
cwd: {
alias: 'd',
default: process.cwd(),
Expand Down Expand Up @@ -123,6 +129,16 @@ main({edit: false, ...cli.argv}).catch((err) => {
async function main(options: CliFlags) {
const raw = options._;
const flags = normalizeFlags(options);

if (flags['print-config']) {
const loaded = await load(getSeed(flags), {
cwd: flags.cwd,
file: flags.config,
});
console.log(util.inspect(loaded, false, null, options.color));
return;
}

const fromStdin = checkFromStdin(raw, flags);

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

const loadOpts = {cwd: flags.cwd, file: flags.config};
const loaded = await load(getSeed(flags), loadOpts);
const loaded = await load(getSeed(flags), {
cwd: flags.cwd,
file: flags.config,
});
const parserOpts = selectParserOpts(loaded.parserPreset);
const opts: LintOptions & {parserOpts: ParserOptions} = {
parserOpts: {},
Expand Down
1 change: 1 addition & 0 deletions @commitlint/cli/src/types.ts
Expand Up @@ -14,6 +14,7 @@ export interface CliFlags {
to?: string;
version?: boolean;
verbose?: boolean;
'print-config'?: boolean;
_: string[];
$0: string;
}
Expand Down
@@ -0,0 +1,4 @@
{
"name": "@packages/a",
"version": "1.0.0"
}
@@ -0,0 +1,4 @@
{
"name": "@packages/b",
"version": "1.0.0"
}
10 changes: 10 additions & 0 deletions @commitlint/config-lerna-scopes/fixtures/yarn/package.json
@@ -0,0 +1,10 @@
{
"name": "yarn",
"version": "1.0.0",
"devDependencies": {
"lerna": "^3.0.0"
},
"workspaces": [
"@packages/*"
]
}
16 changes: 15 additions & 1 deletion @commitlint/config-lerna-scopes/index.js
@@ -1,6 +1,7 @@
const Path = require('path');
const importFrom = require('import-from');
const resolvePkg = require('resolve-pkg');
const Globby = require('globby');
const semver = require('semver');

module.exports = {
Expand All @@ -16,8 +17,21 @@ function getPackages(context) {
.then(() => {
const ctx = context || {};
const cwd = ctx.cwd || process.cwd();
const lernaVersion = getLernaVersion(cwd);

const {workspaces} = require(Path.join(cwd, 'package.json'));
if (Array.isArray(workspaces) && workspaces.length) {
// use yarn workspaces
return Globby(
workspaces.map((ws) => {
return Path.posix.join(ws, 'package.json');
}),
{cwd}
).then((pJsons = []) => {
return pJsons.map((pJson) => require(Path.join(cwd, pJson)));
});
}

const lernaVersion = getLernaVersion(cwd);
if (semver.lt(lernaVersion, '3.0.0')) {
const Repository = importFrom(cwd, 'lerna/lib/Repository');
const PackageUtilities = importFrom(cwd, 'lerna/lib/PackageUtilities');
Expand Down
8 changes: 8 additions & 0 deletions @commitlint/config-lerna-scopes/index.test.js
@@ -1,3 +1,4 @@
import Path from 'path';
import {lerna} from '@commitlint/test';
import config from '.';

Expand Down Expand Up @@ -66,3 +67,10 @@ test('returns expected value for scoped lerna repository', async () => {
const [, , value] = await fn({cwd});
expect(value).toEqual(['a', 'b']);
});

test('returns expected value for yarn workspaces', async () => {
const {'scope-enum': fn} = config.rules;
const cwd = Path.join(__dirname, 'fixtures', 'yarn');
const [, , value] = await fn({cwd});
expect(value.sort()).toEqual(['a', 'b']);
});
3 changes: 2 additions & 1 deletion @commitlint/config-lerna-scopes/package.json
@@ -1,7 +1,7 @@
{
"name": "@commitlint/config-lerna-scopes",
"version": "11.0.0",
"description": "Shareable commitlint config enforcing lerna package names as scopes",
"description": "Shareable commitlint config enforcing lerna package and workspace names as scopes",
"files": [
"index.js"
],
Expand Down Expand Up @@ -32,6 +32,7 @@
"node": ">=v10"
},
"dependencies": {
"globby": "^11.0.1",
"import-from": "3.0.0",
"resolve-pkg": "2.0.0",
"semver": "7.3.4"
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/config-lerna-scopes/readme.md
Expand Up @@ -2,7 +2,7 @@
# @commitlint/config-lerna-scopes

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

## Getting started
Expand Down
4 changes: 0 additions & 4 deletions @commitlint/ensure/jest.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions @commitlint/execute-rule/jest.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions @commitlint/format/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion @commitlint/load/package.json
Expand Up @@ -43,7 +43,7 @@
"@commitlint/execute-rule": "^11.0.0",
"@commitlint/resolve-extends": "^11.0.0",
"@commitlint/types": "^11.0.0",
"chalk": "4.1.0",
"chalk": "^4.0.0",
"cosmiconfig": "^7.0.0",
"lodash": "^4.17.19",
"resolve-from": "^5.0.0"
Expand Down
1 change: 1 addition & 0 deletions @commitlint/parse/package.json
Expand Up @@ -38,6 +38,7 @@
"@commitlint/utils": "^11.0.0"
},
"dependencies": {
"@commitlint/types": "^11.0.0",
"conventional-changelog-angular": "^5.0.11",
"conventional-commits-parser": "^3.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions @commitlint/prompt/package.json
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"@commitlint/load": "^11.0.0",
"@commitlint/types": "^11.0.0",
"chalk": "^4.0.0",
"lodash": "^4.17.19",
"throat": "^5.0.0",
Expand Down
4 changes: 3 additions & 1 deletion @commitlint/read/package.json
Expand Up @@ -37,10 +37,12 @@
"@commitlint/test": "^11.0.0",
"@commitlint/utils": "^11.0.0",
"@types/fs-extra": "^9.0.1",
"@types/git-raw-commits": "^2.0.0"
"@types/git-raw-commits": "^2.0.0",
"execa": "^5.0.0"
},
"dependencies": {
"@commitlint/top-level": "^11.0.0",
"@commitlint/types": "^11.0.0",
"fs-extra": "^9.0.0",
"git-raw-commits": "^2.0.0"
},
Expand Down
4 changes: 0 additions & 4 deletions @commitlint/resolve-extends/jest.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions @commitlint/to-lines/jest.config.js

This file was deleted.

3 changes: 3 additions & 0 deletions @commitlint/types/package.json
Expand Up @@ -26,6 +26,9 @@
"email": "hello@herebecode.com"
},
"license": "MIT",
"dependencies": {
"chalk": "^4.0.0"
},
"devDependencies": {
"@commitlint/utils": "^11.0.0"
},
Expand Down

0 comments on commit f6aab6b

Please sign in to comment.