Skip to content

Commit 2230f56

Browse files
authored
docs: Update nx project filtering documentation (#4037)
Remove use of `require()` and replace with `import()`
1 parent b2845e7 commit 2230f56

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

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

+49-37
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,64 @@ As an example, the following code demonstrates how to select only applications t
2121
In your .commitlintrc.js file:
2222

2323
```javascript
24-
const {
25-
utils: {getProjects},
26-
} = require('@commitlint/config-nx-scopes');
27-
28-
module.exports = {
29-
rules: {
30-
'scope-enum': async (ctx) => [
31-
2,
32-
'always',
33-
[
34-
...(await getProjects(
35-
ctx,
36-
({name, projectType}) =>
37-
!name.includes('e2e') && projectType == 'application'
38-
)),
24+
async function getConfig() {
25+
const {
26+
default: {
27+
utils: {getProjects},
28+
},
29+
} = await import('@commitlint/config-nx-scopes');
30+
31+
return {
32+
rules: {
33+
'scope-enum': async (ctx) => [
34+
2,
35+
'always',
36+
[
37+
...(await getProjects(
38+
ctx,
39+
({name, projectType}) =>
40+
!name.includes('e2e') && projectType == 'application'
41+
)),
42+
],
3943
],
40-
],
41-
},
42-
// . . .
43-
};
44+
},
45+
// . . .
46+
};
47+
}
48+
49+
module.exports = getConfig();
4450
```
4551

4652
Here is another example where projects tagged with 'stage:end-of-life' are not allowed to be used as the scope for a commit.
4753

4854
In your .commitlintrc.js file:
4955

5056
```javascript
51-
const {
52-
utils: {getProjects},
53-
} = require('@commitlint/config-nx-scopes');
54-
55-
module.exports = {
56-
rules: {
57-
'scope-enum': async (ctx) => [
58-
2,
59-
'always',
60-
[
61-
...(await getProjects(
62-
ctx,
63-
({tags}) => !tags.includes('stage:end-of-life')
64-
)),
57+
async function getConfig() {
58+
const {
59+
default: {
60+
utils: {getProjects},
61+
},
62+
} = await import('@commitlint/config-nx-scopes');
63+
64+
return {
65+
rules: {
66+
'scope-enum': async (ctx) => [
67+
2,
68+
'always',
69+
[
70+
...(await getProjects(
71+
ctx,
72+
({tags}) => !tags.includes('stage:end-of-life')
73+
)),
74+
],
6575
],
66-
],
67-
},
68-
// . . .
69-
};
76+
},
77+
// . . .
78+
};
79+
}
80+
81+
module.exports = getConfig();
7082
```
7183

7284
## Examples

0 commit comments

Comments
 (0)