git-semver-tags 6.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +5 -5
  2. package/cli.mjs +3 -8
  3. package/index.js +48 -43
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -16,12 +16,12 @@ $ npm install --save git-semver-tags
16
16
  ```js
17
17
  var gitSemverTags = require('git-semver-tags');
18
18
 
19
- // gitSemverTags([options,] callback)
19
+ // gitSemverTags([options])
20
20
 
21
- gitSemverTags(function(err, tags) {
22
- console.log(tags);
23
- //=> [ 'v2.0.0', 'v1.0.0' ]
24
- });
21
+ const tags = await gitSemverTags();
22
+
23
+ console.log(tags);
24
+ //=> [ 'v2.0.0', 'v1.0.0' ]
25
25
  ```
26
26
 
27
27
  ```sh
package/cli.mjs CHANGED
@@ -33,16 +33,11 @@ const args = meow(`
33
33
  }
34
34
  })
35
35
 
36
- gitSemverTags({
36
+ const tags = await gitSemverTags({
37
37
  lernaTags: args.flags.lerna,
38
38
  package: args.flags.package,
39
39
  tagPrefix: args.flags.tagPrefix,
40
40
  skipUnstable: args.flags.skipUnstable
41
- }, (err, tags) => {
42
- if (err) {
43
- console.error(err.toString())
44
- process.exit(1)
45
- }
46
-
47
- console.log(tags.join('\n'))
48
41
  })
42
+
43
+ console.log(tags.join('\n'))
package/index.js CHANGED
@@ -1,66 +1,71 @@
1
- 'use strict'
1
+ const { exec } = require('child_process')
2
+ const { valid: semverValid } = require('semver')
2
3
 
3
- const proc = require('process')
4
- const exec = require('child_process').exec
5
- const semverValid = require('semver').valid
6
4
  const regex = /tag:\s*(.+?)[,)]/gi
7
- const cmd = 'git log --decorate --no-color'
5
+ const cmd = 'git log --decorate --no-color --date-order'
8
6
  const unstableTagTest = /.+-\w+\.\d+$/
9
7
 
10
8
  function lernaTag (tag, pkg) {
11
- if (pkg && !(new RegExp('^' + pkg + '@')).test(tag)) {
9
+ if (pkg && !tag.startsWith(`${pkg}@`)) {
12
10
  return false
13
- } else {
14
- return /^.+@[0-9]+\.[0-9]+\.[0-9]+(-.+)?$/.test(tag)
15
11
  }
16
- }
17
12
 
18
- module.exports = function gitSemverTags (opts, callback) {
19
- if (typeof opts === 'function') {
20
- callback = opts
21
- opts = {}
22
- }
23
- const options = Object.assign({ maxBuffer: Infinity, cwd: proc.cwd() }, opts)
13
+ return /^.+@[0-9]+\.[0-9]+\.[0-9]+(-.+)?$/.test(tag)
14
+ }
24
15
 
25
- if (options.package && !options.lernaTags) {
26
- callback(new Error('opts.package should only be used when running in lerna mode'))
27
- return
28
- }
16
+ function gitSemverTags (opts = {}) {
17
+ return new Promise((resolve, reject) => {
18
+ const options = {
19
+ maxBuffer: Infinity,
20
+ cwd: process.cwd(),
21
+ ...opts
22
+ }
29
23
 
30
- exec(cmd, options, function (err, data) {
31
- if (err) {
32
- callback(err)
33
- return
24
+ if (options.package && !options.lernaTags) {
25
+ throw new Error('opts.package should only be used when running in lerna mode')
34
26
  }
35
27
 
36
- const tags = []
37
- data.split('\n').forEach(function (decorations) {
28
+ exec(cmd, options, (err, data) => {
29
+ if (err) {
30
+ reject(err)
31
+ return
32
+ }
33
+
34
+ const tags = []
38
35
  let match
39
- while ((match = regex.exec(decorations))) {
40
- const tag = match[1]
36
+ let tag
37
+ let unprefixedTag
41
38
 
42
- if (options.skipUnstable && unstableTagTest.test(tag)) {
43
- // skip unstable tag
44
- continue
45
- }
39
+ data.split('\n').forEach((decorations) => {
40
+ while ((match = regex.exec(decorations))) {
41
+ tag = match[1]
46
42
 
47
- if (options.lernaTags) {
48
- if (lernaTag(tag, options.package)) {
49
- tags.push(tag)
43
+ if (options.skipUnstable && unstableTagTest.test(tag)) {
44
+ // skip unstable tag
45
+ continue
50
46
  }
51
- } else if (options.tagPrefix) {
52
- if (tag.startsWith(options.tagPrefix)) {
53
- const unprefixedTag = tag.replace(options.tagPrefix, '')
54
- if (semverValid(unprefixedTag)) {
47
+
48
+ if (options.lernaTags) {
49
+ if (lernaTag(tag, options.package)) {
55
50
  tags.push(tag)
56
51
  }
52
+ } else if (options.tagPrefix) {
53
+ if (tag.startsWith(options.tagPrefix)) {
54
+ unprefixedTag = tag.replace(options.tagPrefix, '')
55
+
56
+ if (semverValid(unprefixedTag)) {
57
+ tags.push(tag)
58
+ }
59
+ }
60
+ } else if (semverValid(tag)) {
61
+ tags.push(tag)
57
62
  }
58
- } else if (semverValid(tag)) {
59
- tags.push(tag)
60
63
  }
61
- }
62
- })
64
+ })
63
65
 
64
- callback(null, tags)
66
+ resolve(tags)
67
+ })
65
68
  })
66
69
  }
70
+
71
+ module.exports = gitSemverTags
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-semver-tags",
3
- "version": "6.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Get all git semver tags of your repository in reverse chronological order",
5
5
  "bugs": {
6
6
  "url": "https://github.com/conventional-changelog/conventional-changelog/issues"