Skip to content

Commit 1cfef29

Browse files
committed
feat(deps)!: update commitlint monorepo to v19
BREAKING CHANGE: Drop support for @commitlint v9 up to and indlucing v18 BREAKING CHANGE: Require Node.js 20 minimum
1 parent 897039e commit 1cfef29

File tree

7 files changed

+682
-6112
lines changed

7 files changed

+682
-6112
lines changed

package-lock.json

Lines changed: 626 additions & 6005 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@
1919
"license": "GPL-3.0-or-later",
2020
"author": "Jeroen de Bruijn",
2121
"type": "module",
22-
"exports": {
23-
".": {
24-
"import": "./dist/config.js",
25-
"require": "./dist/index.cjs"
26-
}
27-
},
22+
"exports": "./dist/index.js",
2823
"files": [
2924
"./dist/**/!(*.test).{js,d.ts,cjs}"
3025
],
3126
"scripts": {
32-
"build": "npm run build:esm && npm run build:cjs",
33-
"build:cjs": "esbuild src/index.ts --bundle --target=ES2022 --platform=node --outfile=dist/index.cjs",
34-
"build:esm": "tsc",
27+
"build": "tsc",
3528
"format": "prettier --ignore-path .gitignore --write \"**/*.{vue,css,less,scss,html,htm,json,md,markdown,yml,yaml}\" --log-level warn",
3629
"format:check": "prettier --ignore-path .gitignore --check \"**/*.{vue,css,less,scss,html,htm,json,md,markdown,yml,yaml}\" --log-level warn",
3730
"lint": "npm run format:check && xo",
@@ -192,37 +185,20 @@
192185
]
193186
},
194187
"dependencies": {
195-
"@commitlint/config-conventional": "18.5.0",
196-
"commitlint-plugin-function-rules": "3.1.0"
188+
"@commitlint/config-conventional": "19.1.0",
189+
"commitlint-plugin-function-rules": "4.0.0-beta.1"
197190
},
198191
"devDependencies": {
199192
"@ava/typescript": "4.1.0",
200-
"@commitlint/cli": "18.5.0",
201-
"@commitlint/lint-10.x": "npm:@commitlint/lint@10.0.0",
202-
"@commitlint/lint-11.x": "npm:@commitlint/lint@11.0.0",
203-
"@commitlint/lint-12.x": "npm:@commitlint/lint@12.1.4",
204-
"@commitlint/lint-13.x": "npm:@commitlint/lint@13.2.0",
205-
"@commitlint/lint-14.x": "npm:@commitlint/lint@14.1.0",
206-
"@commitlint/lint-15.x": "npm:@commitlint/lint@15.0.0",
207-
"@commitlint/lint-16.x": "npm:@commitlint/lint@16.2.4",
208-
"@commitlint/lint-17.x": "npm:@commitlint/lint@18.5.0",
209-
"@commitlint/lint-9.x": "npm:@commitlint/lint@9.1.2",
210-
"@commitlint/load-10.x": "npm:@commitlint/load@10.0.0",
211-
"@commitlint/load-11.x": "npm:@commitlint/load@11.0.0",
212-
"@commitlint/load-12.x": "npm:@commitlint/load@12.1.4",
213-
"@commitlint/load-13.x": "npm:@commitlint/load@13.2.1",
214-
"@commitlint/load-14.x": "npm:@commitlint/load@14.1.0",
215-
"@commitlint/load-15.x": "npm:@commitlint/load@15.0.0",
216-
"@commitlint/load-16.x": "npm:@commitlint/load@16.3.0",
217-
"@commitlint/load-17.x": "npm:@commitlint/load@18.5.0",
218-
"@commitlint/load-9.x": "npm:@commitlint/load@9.1.2",
219-
"@commitlint/types": "18.4.4",
193+
"@commitlint/cli": "19.2.0",
194+
"@commitlint/lint-19.x": "npm:@commitlint/lint@19.1.0",
195+
"@commitlint/load-19.x": "npm:@commitlint/load@19.1.0",
196+
"@commitlint/types": "19.0.3",
220197
"@semantic-release/changelog": "6.0.3",
221198
"@semantic-release/exec": "6.0.3",
222199
"@semantic-release/git": "10.0.1",
223200
"ava": "6.1.2",
224201
"c8": "9.1.0",
225-
"esbuild": "0.20.1",
226202
"husky": "9.0.11",
227203
"lint-staged": "15.2.2",
228204
"prettier": "3.2.5",
@@ -231,6 +207,6 @@
231207
"xo": "0.58.0"
232208
},
233209
"engines": {
234-
"node": ">=18"
210+
"node": ">=20"
235211
}
236212
}

src/config.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import test from 'ava';
2-
import type commitlintLoad from '@commitlint/load-17.x';
3-
import type commitlintLint from '@commitlint/lint-17.x';
2+
import load19x from '@commitlint/load-19.x';
3+
import lint19x from '@commitlint/lint-19.x';
44
import {type LoadOptions} from '@commitlint/types';
5-
import {config} from './config.js';
65
import {headerMaxLength} from './rules/index.js';
6+
import config from './index.js';
7+
8+
/* eslint-disable @typescript-eslint/naming-convention */
9+
const versions = {
10+
'19.x': {load: load19x, lint: lint19x},
11+
} as const;
12+
/* eslint-enable @typescript-eslint/naming-convention */
713

814
test('extends the "@commitlint/config-conventional" config', (t) => {
915
t.deepEqual(config.extends, ['@commitlint/config-conventional']);
@@ -34,43 +40,24 @@ test(disables, 'header-max-length');
3440
* configuration.
3541
*/
3642
const loadOptions: LoadOptions = {file: 'package.json'} as const;
37-
const loadConfig = test.macro<[string]>({
43+
const loadConfig = test.macro<[keyof typeof versions]>({
3844
async exec(t, version) {
39-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
40-
const module = await import(`@commitlint/load-${version}`);
41-
const load = module.default.default as typeof commitlintLoad.default;
42-
43-
await t.notThrowsAsync(load(config, loadOptions));
45+
await t.notThrowsAsync(versions[version].load(config, loadOptions));
4446
},
4547
title: (_, version) =>
4648
`@commitlint/load@${version} can load the configuration`,
4749
});
48-
test(loadConfig, '9.x');
49-
test(loadConfig, '10.x');
50-
test(loadConfig, '11.x');
51-
test(loadConfig, '12.x');
52-
test(loadConfig, '13.x');
53-
test(loadConfig, '14.x');
54-
test(loadConfig, '15.x');
55-
test(loadConfig, '16.x');
56-
test(loadConfig, '17.x');
50+
test(loadConfig, '19.x');
5751

58-
const lintUsingConfiguration = test.macro<[string]>({
52+
const lintUsingConfiguration = test.macro<[keyof typeof versions]>({
5953
async exec(t, version) {
60-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
61-
const loadModule = await import(`@commitlint/load-${version}`);
62-
const load = loadModule.default.default as typeof commitlintLoad.default;
63-
const qualifiedConfig = await load(config, loadOptions);
64-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
65-
const module = await import(`@commitlint/lint-${version}`);
66-
const lint = module.default.default as typeof commitlintLint.default;
67-
54+
const qualifiedConfig = await versions[version].load(config, loadOptions);
6855
const input = [
6956
'chore(deps): we are told to remember the idea, not the man. Because a',
7057
'man can fail. He can be caught, he can be killed and forgotten. But 400',
7158
'years later, an idea can still change the world - A. Moore',
7259
].join(' ');
73-
const outcome = await lint(input, qualifiedConfig.rules, {
60+
const outcome = await versions[version].lint(input, qualifiedConfig.rules, {
7461
plugins: qualifiedConfig.plugins,
7562
});
7663

@@ -79,12 +66,4 @@ const lintUsingConfiguration = test.macro<[string]>({
7966
title: (_, version) =>
8067
`@commitlint/lint@${version} can use the configuration`,
8168
});
82-
test(lintUsingConfiguration, '9.x');
83-
test(lintUsingConfiguration, '10.x');
84-
test(lintUsingConfiguration, '11.x');
85-
test(lintUsingConfiguration, '12.x');
86-
test(lintUsingConfiguration, '13.x');
87-
test(lintUsingConfiguration, '14.x');
88-
test(lintUsingConfiguration, '15.x');
89-
test(lintUsingConfiguration, '16.x');
90-
test(lintUsingConfiguration, '17.x');
69+
test(lintUsingConfiguration, '19.x');

src/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import {config} from './config.js';
1+
import {type UserConfig} from '@commitlint/types';
2+
import {headerMaxLength} from './rules/index.js';
23

3-
/**
4-
* Export single object, according to the CommonJS model. The CommonJS module is
5-
* explicitly used here as that's the kind of module commitlint requires for
6-
* shareable configurations. This project is an ES module for ease of
7-
* development, and thus requires the error for an export assignment to be
8-
* disabled.
9-
*/
10-
// @ts-expect-error TS1203
11-
export = config;
4+
const config: UserConfig = {
5+
extends: ['@commitlint/config-conventional'],
6+
plugins: ['function-rules'],
7+
rules: {
8+
'body-max-line-length': [0],
9+
'footer-max-line-length': [0],
10+
'header-max-length': [0],
11+
'function-rules/header-max-length': [2, 'always', headerMaxLength],
12+
},
13+
};
14+
15+
export default config;

src/rules/header-max-length.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import test from 'ava';
2-
import {type Commit} from '@commitlint/types';
3-
import {config, failedMessage, headerMaxLength} from './header-max-length.js';
2+
import {
3+
type Commit,
4+
config,
5+
failedMessage,
6+
headerMaxLength,
7+
} from './header-max-length.js';
48

59
function commit(
610
type: string,
@@ -25,7 +29,7 @@ function commit(
2529
references: [],
2630
revert: null,
2731
merge: null,
28-
};
32+
} as unknown as Commit;
2933
}
3034

3135
const outcome = test.macro<

src/rules/header-max-length.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {type Commit, type RuleOutcome} from '@commitlint/types';
1+
import {type Rule, type RuleOutcome} from '@commitlint/types';
2+
3+
type Commit = Parameters<Rule>[0];
24

35
const config = {
46
maxLength: 100,
@@ -34,25 +36,24 @@ function failedMessage(dependency: boolean, length: number): string {
3436
}
3537

3638
function headerMaxLength(parsed: Commit): RuleOutcome {
37-
if (parsed.header.length <= config.maxLength) {
39+
const headerLength = parsed.header?.length ?? 0;
40+
if (headerLength <= config.maxLength) {
3841
return [true];
3942
}
4043

4144
const isDependencyCommit = config.dependency.commitStyle.some(
4245
(commitStyle) =>
43-
parsed.type !== null &&
44-
commitStyle.type.test(parsed.type) &&
45-
parsed.scope !== null &&
46-
commitStyle.scope.test(parsed.scope),
46+
commitStyle.type.test(parsed.type ?? '') &&
47+
commitStyle.scope.test(parsed.scope ?? ''),
4748
);
4849
const maxLength = isDependencyCommit
4950
? config.dependency.maxLength
5051
: config.maxLength;
51-
if (parsed.header.length > maxLength) {
52-
return [false, failedMessage(isDependencyCommit, parsed.header.length)];
52+
if (headerLength > maxLength) {
53+
return [false, failedMessage(isDependencyCommit, headerLength)];
5354
}
5455

5556
return [true];
5657
}
5758

58-
export {config, failedMessage, headerMaxLength};
59+
export {type Commit, config, failedMessage, headerMaxLength};

0 commit comments

Comments
 (0)