Skip to content

Commit cae0822

Browse files
author
Charlike Mike Reagent
authored
major: next major, resolves #69 (#70)
Monorepo support. Part of standard-release/cli#1 and standard-release/app#25 resolves #69.
1 parent 249f9a9 commit cae0822

File tree

10 files changed

+1221
-664
lines changed

10 files changed

+1221
-664
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
command: yarn run build || echo "No build step."
108108
- run:
109109
name: Releasing and publishing
110-
command: yarn run release || (yarn global add @tunnckocore/release-cli && yarn run release)
110+
command: yarn run release || (yarn global add new-release@4 && yarn run release)
111111

112112
workflows:
113113
version: 2

.eslintrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
'use strict';
22

3-
module.exports = require('@tunnckocore/config/eslint');
3+
module.exports = {
4+
extends: 'tunnckocore',
5+
rules: {
6+
'jest/expect-expect': 'off',
7+
},
8+
};

.nycrc.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"extends": "./node_modules/@tunnckocore/config/nyc.json",
3-
"exclude": [
4-
"test",
5-
"src/semver-inc/**/*"
6-
]
2+
"statements": 0,
3+
"branches": 0,
4+
"functions": 0,
5+
"lines": 0,
6+
"cache": true,
7+
"check-coverage": true,
8+
"reporter": ["lcov", "text"],
9+
"include": ["src/**/*.js"],
10+
"exclude": ["test", "src/semver-inc/**/*"]
711
}

.prettierrc.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
'use strict';
22

3-
module.exports = require('@tunnckocore/config/prettier');
3+
module.exports = {
4+
printWidth: 80,
5+
6+
// That actually is enforced by AirBnB Style anyway.
7+
// Enforce 2 spaces, because JavaScript is always different
8+
// then the rest of the languages.
9+
tabWidth: 2,
10+
11+
// That actually is enforced by AirBnB Style anyway.
12+
// Explicitness is the most important thing:
13+
// - Always is visible that this is function (because the parens).
14+
// - If you first write single param and decide to add new one,
15+
// then you should also add a parens around the both - that's mess.
16+
arrowParens: 'always',
17+
18+
// Enforce single-quotes, because industry standard.
19+
singleQuote: true,
20+
21+
// That actually is enforced by AirBnB Style anyway.
22+
// Always useful. And guaranteed that you won't see boring errors,
23+
// that eats your time, because of nothing real.
24+
trailingComma: 'all',
25+
26+
// That actually is enforced by AirBnB Style anyway.
27+
// Enforce more clear object literals.
28+
// As seen in this example https://github.com/airbnb/javascript#objects--rest-spread
29+
bracketSpacing: true,
30+
31+
// That actually is enforced by AirBnB Style anyway.
32+
// Enforcing bracket on the next line makes differentiate
33+
// where ends the tag and its properties and where starts the content of the tag.
34+
// https://prettier.io/docs/en/options.html#jsx-brackets
35+
jsxBracketSameLine: false,
36+
};

.verb.md

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,56 @@ _We highly recommend to use Yarn when you think to contribute to this project._
5151
$ yarn add {%= name %}
5252
```
5353

54+
## Monorepo support
55+
56+
For making it work on monorepo setups, you should pass `options.packages` - an array
57+
of package names that are changes and a `options.cwd` - the root of the monorepo.
58+
Usually this can be extracted from commit message or the response of `lerna changed`.
59+
60+
```js
61+
import detectNextVersion from 'detect-next-version';
62+
63+
async function main() {
64+
// e.g. /home/charlike/develop/some-monorepo
65+
const cwd = process.cwd();
66+
67+
// try using `git-commits-since` for getting all commits
68+
// it returns an object with `rawCommits` property
69+
const commits = ['feat: foo bar', 'chore(ok): qux okey'];
70+
const packages = ['@tunnckocore/qq5', 'foo-bar-baz-qux'];
71+
72+
const results = await detectNextVersion(commits, { packages, cwd });
73+
console.log(results);
74+
75+
const [itemOne, itemTwo] = results;
76+
console.log(itemOne.name); // => '@tunnckocore/qq5'
77+
console.log(itemOne.path); // => '@tunnckocore/qq5'
78+
console.log(itemOne.increment); // => 'minor'
79+
console.log(itemOne.lastVersion); // => '0.1.0'
80+
console.log(itemOne.nextVersion); // => '0.2.0'
81+
console.log(itemOne.cwd); // => /home/charlike/develop/some-monorepo
82+
83+
console.log(itemTwo.name); // => 'foo-bar-baz-qux'
84+
console.log(itemTwo.path); // => 'packages/foo-bar-baz-qux'
85+
console.log(itemTwo.increment); // => 'minor'
86+
console.log(itemTwo.lastVersion); // => '1.0.4'
87+
console.log(itemTwo.nextVersion); // => '1.1.0'
88+
console.log(itemTwo.cwd); // => /home/charlike/develop/some-monorepo
89+
}
90+
91+
main().catch(console.error);
92+
```
93+
5494
## API
5595

5696
<!-- docks-start -->
97+
5798
_Generated using [docks](http://npm.im/docks)._
5899

59100
### [src/index.js](/src/index.js)
60101

61-
#### [detectNextVersion](/src/index.js#L72)
102+
#### [detectNextVersion](/src/index.js#L75)
103+
62104
Calculates next version of given package with `name`,
63105
based given `commitMessages` which should follow
64106
the [Conventional Commits Specification](https://www.conventionalcommits.org/).
@@ -73,16 +115,18 @@ returned result won't have `nextVersion` and `increment` will be `false`.
73115
ProTip: See [parse-commit-message types](https://github.com/tunnckoCoreLabs/parse-commit-message#type-definitions) documentation!
74116

75117
**Params**
76-
- `name` **{string}** a package name which you looking to update
118+
77119
- `commits` **{string|}** directly passed to [recommended-bump][]
78-
May be one of `string`, `Array<string>` or `Array<Commit>`
120+
May be one of `string`, `Array<string>` or `Array<Commit>`
79121
- `[options]` **{object}** optional, passed to above mentioned packages.
80122

81123
**Returns**
82-
- `object` an object which is basically the return of [recommended-bump][]
83-
plus `{ pkg, lastVersion, nextVersion? }`.
124+
125+
- `Array<object>` an array of objects where each is basically the return of [recommended-bump][]
126+
plus `{ pkg, name, cwd, path, lastVersion, nextVersion? }`.
84127

85128
**Examples**
129+
86130
```ts
87131
type Commit = {
88132
header: Header;
@@ -93,14 +137,15 @@ type Commit = {
93137
mentions?: Array<Mention>;
94138
};
95139
```
140+
96141
```javascript
97142
import detector from 'detect-next-version';
98143

99144
async function main() {
100145
const commits = ['chore(ci): some build tweaks', 'fix(cli): foo bar'];
101146

102147
// consider `my-npm-package` is version 0.1.0
103-
const result = await detector('my-npm-package', commits);
148+
const [result] = await detector(commits, { name: 'my-npm-package' });
104149
console.log(result.increment); // => 'patch'
105150
console.log(result.pkg); // => package's latest package.json metadata
106151
console.log(result.lastVersion); // => '0.1.0'
@@ -113,6 +158,7 @@ async function main() {
113158

114159
main().catch(console.error);
115160
```
161+
116162
```javascript
117163
import { parse } from 'parse-commit-message';
118164
import detector from 'detect-next-version';
@@ -121,7 +167,11 @@ async function main() {
121167
const commitOne = parse('fix: foo bar');
122168
const commitTwo = parse('feat: some feature subject');
123169

124-
const result = await detector('@my-org/my-awesomepkg', [commitOne, commitTwo]);
170+
// always an array, but we can destruct it here,
171+
// because we know that it has only one item
172+
const [result] = await detector([commitOne, commitTwo], {
173+
name: '@my-org/my-awesomepkg',
174+
});
125175
console.log(result.increment); // => 'minor'
126176
}
127177

@@ -198,24 +248,20 @@ Released under the [Apache-2.0 License][license-url].
198248

199249
[ghrelease-url]: https://github.com/tunnckoCoreLabs/detect-next-version/releases/latest
200250
[ghrelease-img]: https://badgen.net/github/release/tunnckoCoreLabs/detect-next-version?icon=github
201-
202251
[license-url]: https://github.com/tunnckoCoreLabs/detect-next-version/blob/master/LICENSE
252+
203253
[license-img]: https://badgen.net/npm/license/{%= name %}
204254

205255
<!-- Front line badges -->
206256

207257
[codestyle-url]: https://github.com/airbnb/javascript
208258
[codestyle-img]: https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb
209-
210259
[linuxbuild-url]: https://circleci.com/gh/tunnckoCoreLabs/detect-next-version/tree/master
211260
[linuxbuild-img]: https://badgen.net/circleci/github/tunnckoCoreLabs/detect-next-version/master?label=build&icon=circleci
212-
213261
[codecoverage-url]: https://codecov.io/gh/tunnckoCoreLabs/detect-next-version
214262
[codecoverage-img]: https://badgen.net/codecov/c/github/tunnckoCoreLabs/detect-next-version?icon=codecov
215-
216263
[dependencies-url]: https://david-dm.org/tunnckoCoreLabs/detect-next-version
217264
[dependencies-img]: https://badgen.net/david/dep/tunnckoCoreLabs/detect-next-version?label=deps
218-
219265
[ccommits-url]: https://conventionalcommits.org/
220266
[ccommits-img]: https://badgen.net/badge/conventional%20commits/v1.0.0/dfb317
221267
[new-release-url]: https://ghub.io/new-release
@@ -234,7 +280,6 @@ Released under the [Apache-2.0 License][license-url].
234280
[patreon-url]: https://www.patreon.com/bePatron?u=5579781
235281
[patreon-img]: https://badgen.net/badge/patreon/tunnckoCore/F96854?icon=patreon
236282
[patreon-sponsor-img]: https://badgen.net/badge/become/a%20sponsor/F96854?icon=patreon
237-
238283
[shareu]: https://twitter.com/intent/tweet?text=https://github.com/tunnckoCoreLabs/detect-next-version&via=tunnckoCore
239284
[shareb]: https://badgen.net/badge/twitter/share/1da1f2?icon=twitter
240285
[open-issue-url]: https://github.com/tunnckoCoreLabs/detect-next-version/issues/new

0 commit comments

Comments
 (0)