-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-pnpm-scopes): implement config-pnpm-scopes (#3427)
shareable config enforcing pnpm workspaces names as scopes
- Loading branch information
Showing
16 changed files
with
2,503 additions
and
59 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,6 @@ | ||
{ | ||
"name": "basic", | ||
"version": "1.0.0", | ||
"private": true, | ||
"devDependencies": {} | ||
} |
4 changes: 4 additions & 0 deletions
4
@commitlint/config-pnpm-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-pnpm-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" | ||
} |
2 changes: 2 additions & 0 deletions
2
@commitlint/config-pnpm-scopes/fixtures/basic/pnpm-workspace.yaml
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,2 @@ | ||
packages: | ||
- 'packages/*' |
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,6 @@ | ||
{ | ||
"name": "empty", | ||
"version": "1.0.0", | ||
"private": true, | ||
"devDependencies": {} | ||
} |
2 changes: 2 additions & 0 deletions
2
@commitlint/config-pnpm-scopes/fixtures/empty/pnpm-workspace.yaml
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,2 @@ | ||
packages: | ||
- 'packages/*' |
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,6 @@ | ||
{ | ||
"name": "basic", | ||
"version": "1.0.0", | ||
"private": true, | ||
"devDependencies": {} | ||
} |
4 changes: 4 additions & 0 deletions
4
@commitlint/config-pnpm-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": "@scope/a", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
@commitlint/config-pnpm-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": "@scope/b", | ||
"version": "1.0.0" | ||
} |
2 changes: 2 additions & 0 deletions
2
@commitlint/config-pnpm-scopes/fixtures/scoped/pnpm-workspace.yaml
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,2 @@ | ||
packages: | ||
- 'packages/*' |
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,26 @@ | ||
const {findWorkspacePackages} = require('@pnpm/find-workspace-packages'); | ||
|
||
module.exports = { | ||
utils: {getProjects}, | ||
rules: { | ||
'scope-enum': (ctx) => | ||
getProjects(ctx).then((packages) => [2, 'always', packages]), | ||
}, | ||
}; | ||
|
||
function getProjects(context) { | ||
const ctx = context || {}; | ||
const cwd = ctx.cwd || process.cwd(); | ||
|
||
return findWorkspacePackages(cwd).then((projects) => { | ||
return projects.reduce((projects, project) => { | ||
const name = project.manifest.name; | ||
|
||
if (name && project.dir !== cwd) { | ||
projects.push(name.charAt(0) === '@' ? name.split('/')[1] : name); | ||
} | ||
|
||
return 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,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 pnpm 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 pnpm 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 pnpm 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) 2022 - present Dan Onoshko | ||
|
||
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,50 @@ | ||
{ | ||
"name": "@commitlint/config-pnpm-scopes", | ||
"version": "17.2.0", | ||
"description": "Shareable commitlint config enforcing pnpm workspaces 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-pnpm-scopes" | ||
}, | ||
"keywords": [ | ||
"conventional-changelog", | ||
"commitlint", | ||
"commitlint-config", | ||
"pnpm" | ||
], | ||
"author": "Dan Onoshko <danon0404@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/conventional-changelog/commitlint/issues" | ||
}, | ||
"homepage": "https://commitlint.js.org/", | ||
"peerDependencies": { | ||
"@pnpm/find-workspace-packages": "^5.0.0", | ||
"@pnpm/logger": "^5.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@pnpm/find-workspace-packages": { | ||
"optional": true | ||
}, | ||
"@pnpm/logger": { | ||
"optional": true | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=v14" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/test": "^17.2.0", | ||
"@commitlint/utils": "^17.0.0", | ||
"@pnpm/find-workspace-packages": "^5.0.0", | ||
"@pnpm/logger": "^5.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 pnpm workspaces project commits | ||
# @commitlint/config-pnpm-scopes | ||
|
||
Shareable `commitlint` config enforcing pnpm workspaces names as scopes. | ||
Use with [@commitlint/cli](../cli) and [@commitlint/prompt-cli](../prompt-cli). | ||
|
||
## Getting started | ||
|
||
``` | ||
npm install --save-dev @commitlint/config-pnpm-scopes @commitlint/cli | ||
echo "module.exports = {extends: ['@commitlint/config-pnpm-scopes']};" > commitlint.config.js | ||
``` | ||
|
||
## Examples | ||
|
||
``` | ||
β― cat commitlint.config.js | ||
{ | ||
extends: ['@commitlint/config-pnpm-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. |
Oops, something went wrong.