-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-rush-scopes): add config for rush monorepo (#2878)
* feat(config-rush-scopes): add config for rush monorepo * fix(config-rush-scopes): support older NodeJS
- Loading branch information
Showing
14 changed files
with
1,557 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
4 changes: 4 additions & 0 deletions
4
@commitlint/config-rush-scopes/fixtures/basic/packages/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" | ||
} |
4 changes: 4 additions & 0 deletions
4
@commitlint/config-rush-scopes/fixtures/basic/packages/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" | ||
} |
441 changes: 441 additions & 0 deletions
441
@commitlint/config-rush-scopes/fixtures/basic/rush.json
Large diffs are not rendered by default.
Oops, something went wrong.
433 changes: 433 additions & 0 deletions
433
@commitlint/config-rush-scopes/fixtures/empty/rush.json
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
@commitlint/config-rush-scopes/fixtures/scoped/@packages/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": "@packages/a", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
@commitlint/config-rush-scopes/fixtures/scoped/@packages/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": "@packages/b", | ||
"version": "1.0.0" | ||
} |
441 changes: 441 additions & 0 deletions
441
@commitlint/config-rush-scopes/fixtures/scoped/rush.json
Large diffs are not rendered by default.
Oops, something went wrong.
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,33 @@ | ||
const Path = require('path'); | ||
const util = require('util'); | ||
const fs = require('fs'); | ||
const jsonc = require('jsonc'); | ||
|
||
const readFilePromisifed = util.promisify(fs.readFile); | ||
|
||
module.exports = { | ||
utils: {getPackages}, | ||
rules: { | ||
'scope-enum': (ctx) => | ||
getPackages(ctx).then((packages) => [2, 'always', packages]), | ||
}, | ||
}; | ||
|
||
function getPackages(context) { | ||
return Promise.resolve() | ||
.then(() => { | ||
const ctx = context || {}; | ||
const cwd = ctx.cwd || process.cwd(); | ||
|
||
return readFilePromisifed(Path.join(cwd, 'rush.json'), {encoding: 'utf8'}) | ||
.then((content) => jsonc.parse(content)) | ||
.then(({projects}) => projects) | ||
.catch(() => []); | ||
}) | ||
.then((packages) => { | ||
return packages | ||
.map((pkg) => pkg.packageName) | ||
.filter(Boolean) | ||
.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,69 @@ | ||
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 rush 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 rush 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']); | ||
}); | ||
|
||
test('returns expected value for scoped lerna repository', async () => { | ||
const {'scope-enum': fn} = config.rules; | ||
const cwd = await npm.bootstrap('fixtures/scoped', __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) 2016 - present Mario Nebl | ||
|
||
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,42 @@ | ||
{ | ||
"name": "@commitlint/config-rush-scopes", | ||
"version": "15.0.0", | ||
"description": "Shareable commitlint config enforcing rush package and workspace 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": "@commitlint/config-rush-scopes" | ||
}, | ||
"keywords": [ | ||
"conventional-changelog", | ||
"commitlint", | ||
"commitlint-config", | ||
"rush" | ||
], | ||
"author": { | ||
"name": "Alexander Vyzhanov", | ||
"email": "lembdev@gmail.com" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/conventional-changelog/commitlint/issues" | ||
}, | ||
"homepage": "https://commitlint.js.org/", | ||
"engines": { | ||
"node": ">=v12" | ||
}, | ||
"dependencies": { | ||
"jsonc": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/test": "^15.0.0", | ||
"@commitlint/utils": "^15.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,44 @@ | ||
> Lint your rush project commits | ||
# @commitlint/config-rush-scopes | ||
|
||
Shareable `commitlint` config enforcing rush package and workspace names as scopes. | ||
Use with [@commitlint/cli](../cli) and [@commitlint/prompt-cli](../prompt-cli). | ||
|
||
## Getting started | ||
|
||
``` | ||
npm install --save-dev @commitlint/config-rush-scopes @commitlint/cli | ||
echo "module.exports = {extends: ['@commitlint/config-rush-scopes']};" > commitlint.config.js | ||
``` | ||
|
||
## Examples | ||
|
||
``` | ||
β― cat commitlint.config.js | ||
{ | ||
extends: ['@commitlint/config-rush-scopes'] | ||
} | ||
β― tree packages | ||
packages | ||
βββ api | ||
βββ app | ||
βββ web | ||
β― echo "build(api): change something in api's build" | commitlint | ||
β§ input: build(api): change something in api's build | ||
β found 0 problems, 0 warnings | ||
β― echo "test(foo): this won't pass" | commitlint | ||
β§ input: test(foo): this won't pass | ||
β scope must be one of [api, app, web] [scope-enum] | ||
β found 1 problems, 0 warnings | ||
β― echo "ci: do some general maintenance" | commitlint | ||
β§ input: ci: do some general maintenance | ||
β found 0 problems, 0 warnings | ||
``` | ||
|
||
Consult [docs/rules](https://conventional-changelog.github.io/commitlint/#/reference-rules) for a list of available rules. |
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