From ba90e8e3461736d4a0b92b16c6fd2c03f446458f Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Thu, 21 Mar 2019 03:04:54 +0100 Subject: [PATCH] feat(resolve-extends): accept short scoped package names in extends (#597) --- @commitlint/resolve-extends/src/index.js | 7 ++++- @commitlint/resolve-extends/src/index.test.js | 12 ++++++++ docs/concepts-shareable-config.md | 29 +++++++++++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/@commitlint/resolve-extends/src/index.js b/@commitlint/resolve-extends/src/index.js index e8750545fd..a202512001 100644 --- a/@commitlint/resolve-extends/src/index.js +++ b/@commitlint/resolve-extends/src/index.js @@ -72,7 +72,12 @@ function getId(raw = '', prefix = '') { const first = raw.charAt(0); const scoped = first === '@'; const relative = first === '.'; - return scoped || relative ? raw : [prefix, raw].filter(String).join('-'); + + if (scoped) { + return raw.includes('/') ? raw : [raw, prefix].filter(String).join('/'); + } + + return relative ? raw : [prefix, raw].filter(String).join('-'); } function resolveConfig(raw, context = {}) { diff --git a/@commitlint/resolve-extends/src/index.test.js b/@commitlint/resolve-extends/src/index.test.js index fe4af27701..504e7a1082 100644 --- a/@commitlint/resolve-extends/src/index.test.js +++ b/@commitlint/resolve-extends/src/index.test.js @@ -96,6 +96,18 @@ test('ignores prefix for scoped extends', t => { }); }); +test('adds prefix as suffix for scopes only', t => { + const input = {extends: ['@scope']}; + + resolveExtends(input, { + prefix: 'prefix', + resolve: id, + require(id) { + t.is(id, '@scope/prefix'); + } + }); +}); + test('ignores prefix for relative extends', t => { const input = {extends: ['./extender']}; diff --git a/docs/concepts-shareable-config.md b/docs/concepts-shareable-config.md index 527f3eab33..87fccba4f8 100644 --- a/docs/concepts-shareable-config.md +++ b/docs/concepts-shareable-config.md @@ -20,9 +20,24 @@ The rules found in `commitlint-config-example` are merged with the rules in `com This works recursively, enabling shareable configuration to extend on an indefinite chain of other shareable configurations. -## Special cases +## Relative config -Scoped npm packages are not prefixed. +You can also load local configuration by using a relative path to the file. + +> This must always start with a `.` (dot). + +```js +// commitlint.config.js +module.exports = { + extends: ['./example'] // => ./example.js +} +``` + +## Scoped packages + +When using scoped packages you have two options. + +You can provide the full path of the package like: ```js // commitlint.config.js @@ -31,11 +46,15 @@ module.exports = { }; ``` -The same is true for relative imports +Or just the scope/owner of the package. + +> Just like "normal" extends listed above, this will add `/commitlint-config`. ```js // commitlint.config.js module.exports = { - extends: ['./example'] // => ./example.js -} + extends: ['@coolcompany'] // => coolcompany/commitlint-config +}; ``` + +If you don't use the exact `/commitlint-config` pattern, you have to provide the full name of the package.