@atlasng/commitlint-config 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +60 -2
- package/index.d.ts +89 -0
- package/index.js +82 -0
- package/package.json +33 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cyberinfrastructure for Network Science Center at Indiana University
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @atlasng/commitlint-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared [commitlint](https://commitlint.js.org/) configuration for AtlasNG and other Nx workspaces. It enforces [Conventional Commits](https://www.conventionalcommits.org/) and only accepts scopes that are Nx project names.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @commitlint/cli @atlasng/commitlint-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Extend the configuration from `commitlint.config.mjs`:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
export default {
|
|
17
|
+
extends: ['@atlasng'],
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The configuration:
|
|
22
|
+
|
|
23
|
+
- extends `@commitlint/config-conventional`
|
|
24
|
+
- restricts `scope-enum` to the workspace's Nx project names (`@org/name` becomes `name`), or allows no scopes when the directory has no `nx.json`
|
|
25
|
+
- ignores commits created by Nx Cloud self-healing CI reruns
|
|
26
|
+
|
|
27
|
+
### Additional scopes
|
|
28
|
+
|
|
29
|
+
No scopes beyond the project names are allowed by default. Use `utils.getProjects` to add your own, for example a `release` scope for `nx release` commits:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import atlasng from '@atlasng/commitlint-config';
|
|
33
|
+
|
|
34
|
+
export default {
|
|
35
|
+
extends: ['@atlasng'],
|
|
36
|
+
rules: {
|
|
37
|
+
'scope-enum': async (ctx) => [2, 'always', [...atlasng.utils.getProjects(ctx), 'release']],
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Selecting projects
|
|
43
|
+
|
|
44
|
+
`utils.getProjects(ctx, selector)` accepts an optional selector that receives each project's `name`, `projectType` and `tags`:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import atlasng from '@atlasng/commitlint-config';
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
extends: ['@atlasng'],
|
|
51
|
+
rules: {
|
|
52
|
+
'scope-enum': async (ctx) => [
|
|
53
|
+
2,
|
|
54
|
+
'always',
|
|
55
|
+
atlasng.utils.getProjects(ctx, ({ tags }) => !tags?.includes('internal')),
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`utils.isNxSelfHealingCommit(message)` is also exported for configurations that replace `ignores`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export default config;
|
|
2
|
+
/**
|
|
3
|
+
* Commitlint context passed to configuration rule functions.
|
|
4
|
+
*/
|
|
5
|
+
export type CommitlintContext = {
|
|
6
|
+
/**
|
|
7
|
+
* Directory commitlint runs in. Defaults to `process.cwd()`.
|
|
8
|
+
*/
|
|
9
|
+
cwd?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Subset of an Nx project configuration that project selectors receive.
|
|
13
|
+
*/
|
|
14
|
+
export type ProjectSummary = {
|
|
15
|
+
/**
|
|
16
|
+
* Project name.
|
|
17
|
+
*/
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* Either `application` or `library` when declared.
|
|
21
|
+
*/
|
|
22
|
+
projectType?: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Tags declared on the project.
|
|
25
|
+
*/
|
|
26
|
+
tags?: string[] | undefined;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Predicate that decides whether a project contributes a commit scope.
|
|
30
|
+
*/
|
|
31
|
+
export type ProjectSelector = (project: ProjectSummary) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Commitlint rule configuration tuple for `scope-enum`. The severity `2` is an error.
|
|
34
|
+
*/
|
|
35
|
+
export type ScopeEnumRuleConfig = [2, "always", string[]];
|
|
36
|
+
/**
|
|
37
|
+
* Helpers exposed for consumers that extend the shared configuration.
|
|
38
|
+
*/
|
|
39
|
+
export type CommitlintConfigUtils = {
|
|
40
|
+
/**
|
|
41
|
+
* Lists Nx project names usable as commit scopes.
|
|
42
|
+
*/
|
|
43
|
+
getProjects: typeof getProjects;
|
|
44
|
+
/**
|
|
45
|
+
* Detects Nx Cloud self-healing CI commits.
|
|
46
|
+
*/
|
|
47
|
+
isNxSelfHealingCommit: typeof isNxSelfHealingCommit;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Shared commitlint configuration.
|
|
51
|
+
*/
|
|
52
|
+
export type CommitlintConfig = {
|
|
53
|
+
/**
|
|
54
|
+
* Configurations this configuration builds on.
|
|
55
|
+
*/
|
|
56
|
+
extends: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Predicates for commit messages commitlint skips.
|
|
59
|
+
*/
|
|
60
|
+
ignores: ((message: string) => boolean)[];
|
|
61
|
+
/**
|
|
62
|
+
* Rule overrides.
|
|
63
|
+
*/
|
|
64
|
+
rules: {
|
|
65
|
+
"scope-enum": (ctx?: CommitlintContext) => Promise<ScopeEnumRuleConfig>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Helpers for extending the configuration.
|
|
69
|
+
*/
|
|
70
|
+
utils: CommitlintConfigUtils;
|
|
71
|
+
};
|
|
72
|
+
/** @type {CommitlintConfig} */
|
|
73
|
+
declare const config: CommitlintConfig;
|
|
74
|
+
/**
|
|
75
|
+
* Lists the Nx project names in the workspace, for use as commit scopes. Scoped names such as
|
|
76
|
+
* `@org/name` are reduced to `name`.
|
|
77
|
+
*
|
|
78
|
+
* @param {CommitlintContext} [ctx] Commitlint context; its `cwd` locates the workspace.
|
|
79
|
+
* @param {ProjectSelector} [selector] Optional filter applied to each project.
|
|
80
|
+
* @returns {string[]} Matching project names, or an empty list when `cwd` has no `nx.json`.
|
|
81
|
+
*/
|
|
82
|
+
declare function getProjects(ctx?: CommitlintContext, selector?: ProjectSelector): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Checks whether a commit was produced by Nx Cloud's self-healing CI.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} message The complete commit message.
|
|
87
|
+
* @returns {boolean} Whether commitlint should ignore the message.
|
|
88
|
+
*/
|
|
89
|
+
declare function isNxSelfHealingCommit(message: string): boolean;
|
package/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import nxScopes from '@commitlint/config-nx-scopes';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
/**
|
|
6
|
+
* Commitlint context passed to configuration rule functions.
|
|
7
|
+
*
|
|
8
|
+
* @typedef {object} CommitlintContext
|
|
9
|
+
* @property {string} [cwd] Directory commitlint runs in. Defaults to `process.cwd()`.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Subset of an Nx project configuration that project selectors receive.
|
|
13
|
+
*
|
|
14
|
+
* @typedef {object} ProjectSummary
|
|
15
|
+
* @property {string} name Project name.
|
|
16
|
+
* @property {string} [projectType] Either `application` or `library` when declared.
|
|
17
|
+
* @property {string[]} [tags] Tags declared on the project.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Predicate that decides whether a project contributes a commit scope.
|
|
21
|
+
*
|
|
22
|
+
* @callback ProjectSelector
|
|
23
|
+
* @param {ProjectSummary} project Project to test.
|
|
24
|
+
* @returns {boolean} Whether the project name is an allowed scope.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Commitlint rule configuration tuple for `scope-enum`. The severity `2` is an error.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {[2, 'always', string[]]} ScopeEnumRuleConfig
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Helpers exposed for consumers that extend the shared configuration.
|
|
33
|
+
*
|
|
34
|
+
* @typedef {object} CommitlintConfigUtils
|
|
35
|
+
* @property {typeof getProjects} getProjects Lists Nx project names usable as commit scopes.
|
|
36
|
+
* @property {typeof isNxSelfHealingCommit} isNxSelfHealingCommit Detects Nx Cloud self-healing CI commits.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Shared commitlint configuration.
|
|
40
|
+
*
|
|
41
|
+
* @typedef {object} CommitlintConfig
|
|
42
|
+
* @property {string[]} extends Configurations this configuration builds on.
|
|
43
|
+
* @property {((message: string) => boolean)[]} ignores Predicates for commit messages commitlint skips.
|
|
44
|
+
* @property {{ 'scope-enum': (ctx?: CommitlintContext) => Promise<ScopeEnumRuleConfig> }} rules Rule overrides.
|
|
45
|
+
* @property {CommitlintConfigUtils} utils Helpers for extending the configuration.
|
|
46
|
+
*/
|
|
47
|
+
/** Matches the marker Nx Cloud adds to commits created by self-healing CI reruns. */
|
|
48
|
+
const NX_SELF_HEALING_RERUN_PATTERN = /\[Self-Healing CI Rerun\]/iu;
|
|
49
|
+
/**
|
|
50
|
+
* Checks whether a commit was produced by Nx Cloud's self-healing CI.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} message The complete commit message.
|
|
53
|
+
* @returns {boolean} Whether commitlint should ignore the message.
|
|
54
|
+
*/
|
|
55
|
+
function isNxSelfHealingCommit(message) {
|
|
56
|
+
return NX_SELF_HEALING_RERUN_PATTERN.test(message);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lists the Nx project names in the workspace, for use as commit scopes. Scoped names such as
|
|
60
|
+
* `@org/name` are reduced to `name`.
|
|
61
|
+
*
|
|
62
|
+
* @param {CommitlintContext} [ctx] Commitlint context; its `cwd` locates the workspace.
|
|
63
|
+
* @param {ProjectSelector} [selector] Optional filter applied to each project.
|
|
64
|
+
* @returns {string[]} Matching project names, or an empty list when `cwd` has no `nx.json`.
|
|
65
|
+
*/
|
|
66
|
+
function getProjects(ctx, selector) {
|
|
67
|
+
const cwd = ctx?.cwd || process.cwd();
|
|
68
|
+
if (!fs.existsSync(path.join(cwd, 'nx.json'))) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
return nxScopes.utils.getProjects({ ...ctx, cwd }, selector);
|
|
72
|
+
}
|
|
73
|
+
/** @type {CommitlintConfig} */
|
|
74
|
+
const config = {
|
|
75
|
+
extends: ['@commitlint/config-conventional'],
|
|
76
|
+
ignores: [isNxSelfHealingCommit],
|
|
77
|
+
rules: {
|
|
78
|
+
'scope-enum': async (ctx) => [2, 'always', getProjects(ctx)],
|
|
79
|
+
},
|
|
80
|
+
utils: { getProjects, isNxSelfHealingCommit },
|
|
81
|
+
};
|
|
82
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlasng/commitlint-config",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Shared commitlint configuration with Nx project scopes for AtlasNG and related Nx workspaces",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/cns-iu/AtlasNG",
|
|
9
|
+
"directory": "libs/tooling/commitlint-config"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/cns-iu/AtlasNG/tree/main/libs/tooling/commitlint-config",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/cns-iu/AtlasNG/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"default": "./index.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@commitlint/config-conventional": "^21.2.2",
|
|
28
|
+
"@commitlint/config-nx-scopes": "^21.2.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@commitlint/cli": "^21.0.0"
|
|
32
|
+
},
|
|
33
|
+
"types": "./index.d.ts",
|
|
34
|
+
"module": "./index.js",
|
|
35
|
+
"main": "./index.js"
|
|
6
36
|
}
|