Skip to content

Commit

Permalink
feat(resolve-extends): accept short scoped package names in extends
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Mar 20, 2019
1 parent 3e0d824 commit ba82634
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
7 changes: 6 additions & 1 deletion @commitlint/resolve-extends/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
12 changes: 12 additions & 0 deletions @commitlint/resolve-extends/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']};

Expand Down
29 changes: 24 additions & 5 deletions docs/concepts-shareable-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 `<scope>/commitlint-config`.
```js
// commitlint.config.js
module.exports = {
extends: ['./example'] // => ./example.js
}
extends: ['@peakfijn'] // => peakfijn/commitlint-config
};
```

If you don't use the exact `<scope>/commitlint-config` pattern, you have to provide the full name of the package.

0 comments on commit ba82634

Please sign in to comment.