-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Nx monorepos via @commitlint/config-nx-scopes (#…
- Loading branch information
Showing
21 changed files
with
525 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# commitlint-config-nx-scopes | ||
|
||
> Alias of [@commitlint/config-nx-scopes](https://www.npmjs.com/package/@commitlint/config-nx-scopes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@commitlint/config-nx-scopes'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2022 - present Florian Guitton | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "commitlint-config-nx-scopes", | ||
"version": "16.0.0", | ||
"description": "Shareable commitlint config enforcing nx project names as scopes", | ||
"files": [ | ||
"index.js" | ||
], | ||
"scripts": { | ||
"deps": "dep-check", | ||
"pkg": "pkg-check" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/conventional-changelog/commitlint.git", | ||
"directory": "@alias/commitlint-config-nx-scopes" | ||
}, | ||
"keywords": [ | ||
"conventional-changelog", | ||
"commitlint", | ||
"commitlint-config", | ||
"nx" | ||
], | ||
"author": "Florian Guitton <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/conventional-changelog/commitlint/issues" | ||
}, | ||
"homepage": "https://commitlint.js.org/", | ||
"engines": { | ||
"node": ">=v12" | ||
}, | ||
"dependencies": { | ||
"@commitlint/config-nx-scopes": "^16.0.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/utils": "^16.0.0" | ||
}, | ||
"gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"extends": "@nrwl/workspace/presets/core.json", | ||
"npmScope": "secretarium", | ||
"affected": { | ||
"defaultBase": "main" | ||
}, | ||
"cli": { | ||
"defaultCollection": "@nrwl/react" | ||
}, | ||
"tasksRunnerOptions": { | ||
"default": { | ||
"runner": "@nrwl/nx-cloud", | ||
"options": { | ||
"cacheableOperations": [ | ||
"build", | ||
"lint", | ||
"test", | ||
"e2e" | ||
] | ||
} | ||
} | ||
}, | ||
"generators": { | ||
"@nrwl/react": { | ||
"application": { | ||
"style": "css", | ||
"linter": "eslint", | ||
"babel": true | ||
}, | ||
"component": { | ||
"style": "css" | ||
}, | ||
"library": { | ||
"style": "css", | ||
"linter": "eslint" | ||
} | ||
} | ||
}, | ||
"defaultProject": "a" | ||
} |
4 changes: 4 additions & 0 deletions
4
@commitlint/config-nx-scopes/fixtures/basic/nx/a/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "a", | ||
"version": "1.0.0" | ||
} |
29 changes: 29 additions & 0 deletions
29
@commitlint/config-nx-scopes/fixtures/basic/nx/a/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"root": "nx/a", | ||
"sourceRoot": "nx/a/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"nx/a/**/*.ts" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": [ | ||
"coverage/nx/a" | ||
], | ||
"options": { | ||
"jestConfig": "nx/a/jest.config.js", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
4 changes: 4 additions & 0 deletions
4
@commitlint/config-nx-scopes/fixtures/basic/nx/b/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "b", | ||
"version": "1.0.0" | ||
} |
29 changes: 29 additions & 0 deletions
29
@commitlint/config-nx-scopes/fixtures/basic/nx/b/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"root": "nx/b", | ||
"sourceRoot": "nx/b/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"nx/b/**/*.ts" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": [ | ||
"coverage/nx/b" | ||
], | ||
"options": { | ||
"jestConfig": "nx/b/jest.config.js", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "basic", | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"@nrwl/tao": "^13.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"version": 2, | ||
"projects": { | ||
"a": "nx/a", | ||
"b": "nx/b" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"npmScope": "empty", | ||
"affected": { | ||
"defaultBase": "main" | ||
}, | ||
"cli": { | ||
"defaultCollection": "@nrwl/workspace" | ||
}, | ||
"implicitDependencies": { | ||
"package.json": { | ||
"dependencies": "*", | ||
"devDependencies": "*" | ||
}, | ||
".eslintrc.json": "*" | ||
}, | ||
"tasksRunnerOptions": { | ||
"default": { | ||
"runner": "@nrwl/workspace/tasks-runners/default", | ||
"options": { | ||
"cacheableOperations": [ | ||
"build", | ||
"lint", | ||
"test", | ||
"e2e" | ||
] | ||
} | ||
} | ||
}, | ||
"targetDependencies": { | ||
"build": [ | ||
{ | ||
"target": "build", | ||
"projects": "dependencies" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "empty", | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"@nrwl/tao": "^13.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"version": 2, | ||
"projects": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const {Workspaces} = require('@nrwl/tao/src/shared/workspace'); | ||
|
||
module.exports = { | ||
utils: {getProjects}, | ||
rules: { | ||
'scope-enum': (ctx) => | ||
getProjects(ctx).then((packages) => [2, 'always', packages]), | ||
}, | ||
}; | ||
|
||
function getProjects(context) { | ||
return Promise.resolve() | ||
.then(() => { | ||
const ctx = context || {}; | ||
const cwd = ctx.cwd || process.cwd(); | ||
const ws = new Workspaces(cwd); | ||
const workspace = ws.readWorkspaceConfiguration(); | ||
return Object.entries(workspace.projects || {}).map( | ||
([name, project]) => ({ | ||
name, | ||
...project, | ||
}) | ||
); | ||
}) | ||
.then((projects) => { | ||
return projects | ||
.filter((project) => project.targets) | ||
.map((project) => project.name) | ||
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {npm} from '@commitlint/test'; | ||
import config from '.'; | ||
|
||
test('exports rules key', () => { | ||
expect(config).toHaveProperty('rules'); | ||
}); | ||
|
||
test('rules hold object', () => { | ||
expect(config).toMatchObject({ | ||
rules: expect.any(Object), | ||
}); | ||
}); | ||
|
||
test('rules contain scope-enum', () => { | ||
expect(config).toMatchObject({ | ||
rules: { | ||
'scope-enum': expect.anything(), | ||
}, | ||
}); | ||
}); | ||
|
||
test('scope-enum is function', () => { | ||
expect(config).toMatchObject({ | ||
rules: { | ||
'scope-enum': expect.any(Function), | ||
}, | ||
}); | ||
}); | ||
|
||
test('scope-enum does not throw for missing context', async () => { | ||
const {'scope-enum': fn} = config.rules; | ||
await expect(fn()).resolves.toBeTruthy(); | ||
}); | ||
|
||
test('scope-enum has expected severity', async () => { | ||
const {'scope-enum': fn} = config.rules; | ||
const [severity] = await fn(); | ||
expect(severity).toBe(2); | ||
}); | ||
|
||
test('scope-enum has expected modifier', async () => { | ||
const {'scope-enum': fn} = config.rules; | ||
const [, modifier] = await fn(); | ||
expect(modifier).toBe('always'); | ||
}); | ||
|
||
test('returns empty value for empty nx repository', async () => { | ||
const {'scope-enum': fn} = config.rules; | ||
const cwd = await npm.bootstrap('fixtures/empty', __dirname); | ||
const [, , value] = await fn({cwd}); | ||
expect(value).toEqual([]); | ||
}); | ||
|
||
test('returns expected value for basic nx repository', async () => { | ||
const {'scope-enum': fn} = config.rules; | ||
const cwd = await npm.bootstrap('fixtures/basic', __dirname); | ||
|
||
const [, , value] = await fn({cwd}); | ||
expect(value).toEqual(['a', 'b']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2022 - present Florian Guitton | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.