Skip to content
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

refactor: port config-conventional to ts #3881

Merged
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
2 changes: 1 addition & 1 deletion @commitlint/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ async function main(args: MainArgs): Promise<void> {
message: [
'Please add rules to your `commitlint.config.js`',
' - Getting started guide: https://commitlint.js.org/#/?id=getting-started',
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js',
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts',
].join('\n'),
},
],
Expand Down
4 changes: 3 additions & 1 deletion @commitlint/config-conventional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "@commitlint/config-conventional",
"version": "18.6.0",
"description": "Shareable commitlint config enforcing conventional commits",
"main": "lib/index.js",
Copy link

@jerome-benoit jerome-benoit Feb 13, 2024

Choose a reason for hiding this comment

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

@escapedcat, @Mersho: That change breaks ESM and CommonJS usage of '@commitlint/config-conventional':

  • the generated file is ESM, but the documentation is using CommonJS syntax
  • repo defaulting to ESM can't import: no properly filled exports field in package.json

Replacing it by:

"exports": {
    ".": {
      "types": "./lib/index.d.ts",
      "require": "./lib/index.js",
      "import": "./lib/index.js"
    }
  }

makes things better for ESM but still breaks CommonJS: the dependency code expected syntax is in CommonJS and its default syntax for exported files is ESM ...

Please generate exported files according to the default syntax chosen, CommonJS, and then wrap to ESM, and then use exports field only in package.json.

Copy link

@nwrkbiz nwrkbiz Feb 13, 2024

Choose a reason for hiding this comment

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

Breaking change for converntional-commits cli: #3909

Copy link
Contributor

Choose a reason for hiding this comment

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

@jerome-benoit can I ask you for a review on #3911? 🙏

"files": [
"index.js"
"lib/"
],
"scripts": {
"deps": "dep-check",
Expand Down Expand Up @@ -37,6 +38,7 @@
"@commitlint/utils": "^18.4.4"
},
"dependencies": {
"@commitlint/types": "^18.6.0",
"conventional-changelog-conventionalcommits": "^7.0.2"
},
"gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import lint from '@commitlint/lint';
import {rules, parserPreset} from '.';
import {config} from '.';

const commitLint = async (message) => {
const preset = await require(parserPreset)();
return lint(message, rules, {...preset});
const preset = await require(config.parserPreset)();
return lint(message, config.rules, {...preset});
};

const messages = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
module.exports = {
import {
RuleConfigCondition,
RuleConfigSeverity,
TargetCaseType,
} from '@commitlint/types';

export const config = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'body-leading-blank': [1, 'always'],
'body-max-line-length': [2, 'always', 100],
'footer-leading-blank': [1, 'always'],
'footer-max-line-length': [2, 'always', 100],
'header-max-length': [2, 'always', 100],
'header-trim': [2, 'always'],
'body-leading-blank': [RuleConfigSeverity.Warning, 'always'] as const,
'body-max-line-length': [RuleConfigSeverity.Error, 'always', 100] as const,
'footer-leading-blank': [RuleConfigSeverity.Warning, 'always'] as const,
'footer-max-line-length': [
RuleConfigSeverity.Error,
'always',
100,
] as const,
'header-max-length': [RuleConfigSeverity.Error, 'always', 100] as const,
'header-trim': [RuleConfigSeverity.Error, 'always'] as const,
'subject-case': [
2,
RuleConfigSeverity.Error,
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
] as [RuleConfigSeverity, RuleConfigCondition, TargetCaseType[]],
'subject-empty': [RuleConfigSeverity.Error, 'never'] as const,
'subject-full-stop': [RuleConfigSeverity.Error, 'never', '.'] as const,
'type-case': [RuleConfigSeverity.Error, 'always', 'lower-case'] as const,
'type-empty': [RuleConfigSeverity.Error, 'never'] as const,
'type-enum': [
2,
RuleConfigSeverity.Error,
'always',
[
'build',
Expand All @@ -32,7 +42,7 @@ module.exports = {
'style',
'test',
],
],
] as [RuleConfigSeverity, RuleConfigCondition, string[]],
},
prompt: {
questions: {
Expand Down
4 changes: 2 additions & 2 deletions @commitlint/config-conventional/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"rootDir": "./src",
"outDir": "./lib"
},
"include": ["./**/*.ts"],
"exclude": ["./**/*.test.ts"]
"include": ["./src"],
"exclude": ["./src/**/*.test.ts", "./lib/**/*"]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ These can be modified by [your own configuration](#config).
- `commitlint` field in `package.json`
- Packages: [cli](./@commitlint/cli), [core](./@commitlint/core)
- See [Rules](./docs/reference-rules.md) for a complete list of possible rules
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/index.js)
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/src/index.ts)

## Shared configuration

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{"path": "@commitlint/cli"},
{"path": "@commitlint/travis-cli"},
{"path": "@commitlint/prompt"},
{"path": "@commitlint/cz-commitlint"}
{"path": "@commitlint/cz-commitlint"},
{"path": "@commitlint/config-conventional"}
]
}