git-raw-commits 4.0.0 → 5.0.0

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.
package/README.md CHANGED
@@ -1,101 +1,60 @@
1
- # [![NPM version][npm-image]][npm-url] [![Build Status: Linux][travis-image]][travis-url] [![Build Status: Windows][appveyor-image]][appveyor-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coverage-image]][coverage-url]
1
+ # git-raw-commits
2
2
 
3
- > Get raw git commits out of your repository using git-log(1)
3
+ [![ESM-only package][package]][package-url]
4
+ [![NPM version][npm]][npm-url]
5
+ [![Node version][node]][node-url]
6
+ [![Dependencies status][deps]][deps-url]
7
+ [![Install size][size]][size-url]
8
+ [![Build status][build]][build-url]
9
+ [![Coverage status][coverage]][coverage-url]
4
10
 
11
+ [package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
12
+ [package-url]: https://nodejs.org/api/esm.html
5
13
 
6
- ## Install
7
-
8
- ```sh
9
- $ npm install --save git-raw-commits
10
- ```
11
-
12
-
13
- ## Usage
14
-
15
- ```js
16
- var gitRawCommits = require('git-raw-commits');
17
-
18
- gitRawCommits(options)
19
- .pipe(...);
20
- ```
21
-
22
-
23
- ## API
24
-
25
- ### gitRawCommits(gitOpts, [execOpts])
26
-
27
- Returns a readable stream. Stream is split to break on each commit.
28
-
29
- #### gitOpts
30
-
31
- Type: `object`
32
-
33
- Please check the available options at http://git-scm.com/docs/git-log.
34
- **NOTE:** Single dash arguments are not supported because of https://github.com/sindresorhus/dargs/blob/master/index.js#L5.
35
-
36
- *NOTE*: for `<revision range>` we can also use `<from>..<to>` pattern, and this module has the following extra options for shortcut of this pattern:
37
-
38
- ##### gitOpts.from
39
-
40
- Type: `string` Default: `''`
14
+ [npm]: https://img.shields.io/npm/v/git-raw-commits.svg
15
+ [npm-url]: https://npmjs.com/package/git-raw-commits
41
16
 
42
- ##### gitOpts.to
17
+ [node]: https://img.shields.io/node/v/git-raw-commits.svg
18
+ [node-url]: https://nodejs.org
43
19
 
44
- Type: `string` Default: `'HEAD'`
20
+ [deps]: https://img.shields.io/librariesio/release/npm/git-raw-commits
21
+ [deps-url]: https://libraries.io/npm/git-raw-commits/tree
45
22
 
46
- This module also have the following additions:
23
+ [size]: https://packagephobia.com/badge?p=git-raw-commits
24
+ [size-url]: https://packagephobia.com/result?p=git-raw-commits
47
25
 
48
- ##### gitOpts.format
26
+ [build]: https://img.shields.io/github/actions/workflow/status/conventional-changelog/conventional-changelog/tests.yaml?branch=master
27
+ [build-url]: https://github.com/conventional-changelog/conventional-changelog/actions
49
28
 
50
- Type: `string` Default: `'%B'`
51
-
52
- Please check http://git-scm.com/docs/git-log for format options.
53
-
54
- ##### gitOpts.debug
55
-
56
- Type: `function`
57
-
58
- A function to get debug information.
59
-
60
- ##### gitOpts.path
61
-
62
- Type: `string` or `array`
63
-
64
- Filter commits to the path(s) provided.
65
-
66
- ##### execOpts
67
-
68
- Options to pass to `git` `childProcess`
69
-
70
- Type: `object`
71
-
72
- ##### execOpts.cwd
29
+ [coverage]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
30
+ [coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
73
31
 
74
- Type: `string`
32
+ Get raw git commits out of your repository using git-log(1).
75
33
 
76
- Current working directory to execute git in
34
+ ## Install
77
35
 
36
+ ```bash
37
+ # pnpm
38
+ pnpm add git-raw-commits
39
+ # yarn
40
+ yarn add git-raw-commits
41
+ # npm
42
+ npm i git-raw-commits
43
+ ```
78
44
 
79
45
  ## CLI
80
46
 
81
- ```sh
82
- $ npm install --global git-raw-commits
83
- $ git-raw-commits --help # for more details
47
+ ```bash
48
+ # Example
49
+ git-raw-commits --from HEAD~2 --to HEAD^
50
+ # For more details
51
+ git-raw-commits --help
84
52
  ```
85
53
 
54
+ ## API
55
+
56
+ For JS API see [@conventional-changelog/git-client](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-client).
86
57
 
87
58
  ## License
88
59
 
89
60
  MIT © [Steve Mao](https://github.com/stevemao)
90
-
91
-
92
- [npm-image]: https://badge.fury.io/js/git-raw-commits.svg
93
- [npm-url]: https://npmjs.org/package/git-raw-commits
94
- [travis-image]: https://travis-ci.org/conventional-changelog/git-raw-commits.svg?branch=master
95
- [travis-url]: https://travis-ci.org/conventional-changelog/git-raw-commits
96
- [appveyor-image]: https://ci.appveyor.com/api/projects/status/4qm3bjmg41k3dsbv/branch/master?svg=true
97
- [appveyor-url]: https://ci.appveyor.com/project/stevemao/git-raw-commits/branch/master
98
- [daviddm-image]: https://david-dm.org/conventional-changelog/git-raw-commits.svg?theme=shields.io
99
- [daviddm-url]: https://david-dm.org/conventional-changelog/git-raw-commits
100
- [coverage-image]: https://coveralls.io/repos/github/conventional-changelog/conventional-changelog/badge.svg?branch=master
101
- [coverage-url]: https://coveralls.io/github/conventional-changelog/conventional-changelog?branch=master
package/package.json CHANGED
@@ -1,28 +1,23 @@
1
1
  {
2
2
  "name": "git-raw-commits",
3
- "version": "4.0.0",
4
- "description": "Get raw git commits out of your repository using git-log(1)",
5
- "bugs": {
6
- "url": "https://github.com/conventional-changelog/conventional-changelog/issues"
7
- },
8
- "homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-raw-commits#readme",
3
+ "type": "module",
4
+ "version": "5.0.0",
5
+ "description": "Get raw git commits out of your repository using git-log(1).",
9
6
  "author": {
10
7
  "name": "Steve Mao",
11
8
  "email": "maochenyan@gmail.com",
12
9
  "url": "https://github.com/stevemao"
13
10
  },
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/git-raw-commits#readme",
14
13
  "repository": {
15
14
  "type": "git",
16
- "url": "https://github.com/conventional-changelog/conventional-changelog.git"
15
+ "url": "https://github.com/conventional-changelog/conventional-changelog.git",
16
+ "directory": "packages/git-raw-commits"
17
17
  },
18
- "license": "MIT",
19
- "engines": {
20
- "node": ">=16"
18
+ "bugs": {
19
+ "url": "https://github.com/conventional-changelog/conventional-changelog/issues"
21
20
  },
22
- "files": [
23
- "index.js",
24
- "cli.mjs"
25
- ],
26
21
  "keywords": [
27
22
  "git-raw-commits",
28
23
  "raw",
@@ -32,12 +27,18 @@
32
27
  "log",
33
28
  "git-log"
34
29
  ],
35
- "dependencies": {
36
- "dargs": "^8.0.0",
37
- "meow": "^12.0.1",
38
- "split2": "^4.0.0"
30
+ "engines": {
31
+ "node": ">=18"
39
32
  },
40
33
  "bin": {
41
- "git-raw-commits": "cli.mjs"
34
+ "git-raw-commits": "./src/cli.js"
35
+ },
36
+ "exports": "./src/index.js",
37
+ "files": [
38
+ "src"
39
+ ],
40
+ "dependencies": {
41
+ "meow": "^13.0.0",
42
+ "@conventional-changelog/git-client": "^1.0.0"
42
43
  }
43
44
  }
package/src/cli.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ import { pipeline } from 'stream/promises'
3
+ import meow from 'meow'
4
+ import { getRawCommits } from './index.js'
5
+
6
+ const cli = meow(`
7
+ Usage
8
+ git-raw-commits [<git-log(1)-options>]
9
+
10
+ Example
11
+ git-raw-commits --from HEAD~2 --to HEAD^
12
+ `, {
13
+ importMeta: import.meta,
14
+ flags: {
15
+ ignore: {
16
+ type: 'string'
17
+ },
18
+ path: {
19
+ type: 'string',
20
+ isMultiple: true
21
+ },
22
+ from: {
23
+ type: 'string'
24
+ },
25
+ to: {
26
+ type: 'string'
27
+ },
28
+ format: {
29
+ type: 'string'
30
+ }
31
+ }
32
+ })
33
+
34
+ await pipeline(
35
+ getRawCommits(cli.flags),
36
+ process.stdout
37
+ )
package/src/index.js ADDED
@@ -0,0 +1,59 @@
1
+ import { Readable } from 'stream'
2
+ import { GitClient } from '@conventional-changelog/git-client'
3
+
4
+ function getFinalOptions (options = {}) {
5
+ const finalOptions = {
6
+ cwd: process.cwd(),
7
+ ...options
8
+ }
9
+
10
+ if (options.debug) {
11
+ finalOptions.debug = (args) => {
12
+ options.debug('Your git-log command is:\ngit ' + args.join(' '))
13
+ }
14
+ }
15
+
16
+ return finalOptions
17
+ }
18
+
19
+ /**
20
+ * Get raw commits from git-log.
21
+ * @param {*} options
22
+ * @param {string} [options.cwd=process.cwd()] - Current working directory to run git.
23
+ * @param {false | ((log: string) => void)} [options.debug=false] - A function to get debug information.
24
+ * @param {string | RegExp} [options.ignore] - Ignore commits that match provided string or RegExp.
25
+ * @param {string | string[]} [options.path] - Only commits that are modifying this path.
26
+ * @param {string} [options.from=''] - Starting commit reference or hash.
27
+ * @param {string} [options.to='HEAD'] - Ending commit reference or hash.
28
+ * @param {string} [options.format='%B'] - Format of the commit.
29
+ * @yields {string} - Raw commit.
30
+ */
31
+ export async function * getRawCommits (options) {
32
+ const { cwd, debug, ...finalOptions } = getFinalOptions(options)
33
+ const client = new GitClient(cwd, debug)
34
+ let commit
35
+
36
+ if (typeof finalOptions.ignore === 'string') {
37
+ finalOptions.ignore = new RegExp(finalOptions.ignore)
38
+ }
39
+
40
+ for await (commit of client.getRawCommits(finalOptions)) {
41
+ yield commit
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Get raw commits stream from git-log.
47
+ * @param {*} options
48
+ * @param {string} [options.cwd=process.cwd()] - Current working directory to run git.
49
+ * @param {false | ((log: string) => void)} [options.debug=false] - A function to get debug information.
50
+ * @param {string | RegExp} [options.ignore] - Ignore commits that match provided string or RegExp.
51
+ * @param {string | string[]} [options.path] - Only commits that are modifying this path.
52
+ * @param {string} [options.from=''] - Starting commit reference or hash.
53
+ * @param {string} [options.to='HEAD'] - Ending commit reference or hash.
54
+ * @param {string} [options.format='%B'] - Format of the commit.
55
+ * @returns {Readable} - Raw commits stream.
56
+ */
57
+ export function getRawCommitsStream (options) {
58
+ return Readable.from(getRawCommits(options))
59
+ }
package/cli.mjs DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- import meow from 'meow'
3
- import gitRawCommits from './index.js'
4
-
5
- const cli = meow(`
6
- Usage
7
- git-raw-commits [<git-log(1)-options>]
8
-
9
- Example
10
- git-raw-commits --from HEAD~2 --to HEAD^
11
- `, {
12
- importMeta: import.meta
13
- })
14
-
15
- gitRawCommits(cli.flags)
16
- .on('error', (err) => {
17
- process.stderr.write(err)
18
- process.exit(1)
19
- })
20
- .pipe(process.stdout)
package/index.js DELETED
@@ -1,110 +0,0 @@
1
-
2
- const { Readable, Transform } = require('stream')
3
- const { execFile } = require('child_process')
4
- const split = require('split2')
5
-
6
- const DELIMITER = '------------------------ >8 ------------------------'
7
-
8
- function normalizeExecOpts (execOpts) {
9
- execOpts = execOpts || {}
10
- execOpts.cwd = execOpts.cwd || process.cwd()
11
-
12
- return execOpts
13
- }
14
-
15
- function normalizeGitOpts (gitOpts) {
16
- gitOpts = gitOpts || {}
17
- gitOpts.format = gitOpts.format || '%B'
18
- gitOpts.from = gitOpts.from || ''
19
- gitOpts.to = gitOpts.to || 'HEAD'
20
-
21
- return gitOpts
22
- }
23
-
24
- async function getGitArgs (gitOpts) {
25
- const { default: dargs } = await import('dargs')
26
- const gitFormat = `--format=${gitOpts.format || ''}%n${DELIMITER}`
27
- const gitFromTo = [gitOpts.from, gitOpts.to].filter(Boolean).join('..')
28
- const gitArgs = ['log', gitFormat, gitFromTo]
29
- .concat(dargs(gitOpts, {
30
- excludes: ['debug', 'from', 'to', 'format', 'path', 'ignore']
31
- }))
32
-
33
- // allow commits to focus on specific directories.
34
- // this is useful for monorepos.
35
- if (gitOpts.path) {
36
- gitArgs.push('--', ...Array.isArray(gitOpts.path) ? gitOpts.path : [gitOpts.path])
37
- }
38
-
39
- return gitArgs
40
- }
41
-
42
- function gitRawCommits (rawGitOpts, rawExecOpts) {
43
- const readable = new Readable()
44
- readable._read = () => {}
45
-
46
- const gitOpts = normalizeGitOpts(rawGitOpts)
47
- const execOpts = normalizeExecOpts(rawExecOpts)
48
- let isError = false
49
-
50
- getGitArgs(gitOpts).then((args) => {
51
- if (gitOpts.debug) {
52
- gitOpts.debug('Your git-log command is:\ngit ' + args.join(' '))
53
- }
54
-
55
- const ignoreRegex = typeof gitOpts.ignore === 'string'
56
- ? new RegExp(gitOpts.ignore)
57
- : gitOpts.ignore
58
- const shouldNotIgnore = ignoreRegex
59
- ? chunk => !ignoreRegex.test(chunk.toString())
60
- : () => true
61
-
62
- const child = execFile('git', args, {
63
- cwd: execOpts.cwd,
64
- maxBuffer: Infinity
65
- })
66
-
67
- child.stdout
68
- .pipe(split(DELIMITER + '\n'))
69
- .pipe(
70
- new Transform({
71
- transform (chunk, enc, cb) {
72
- isError = false
73
- setImmediate(() => {
74
- if (shouldNotIgnore(chunk)) {
75
- readable.push(chunk)
76
- }
77
- cb()
78
- })
79
- },
80
- flush (cb) {
81
- setImmediate(() => {
82
- if (!isError) {
83
- readable.push(null)
84
- readable.emit('close')
85
- }
86
-
87
- cb()
88
- })
89
- }
90
- })
91
- )
92
-
93
- child.stderr
94
- .pipe(
95
- new Transform({
96
- objectMode: true,
97
- highWaterMark: 16,
98
- transform (chunk) {
99
- isError = true
100
- readable.emit('error', new Error(chunk))
101
- readable.emit('close')
102
- }
103
- })
104
- )
105
- })
106
-
107
- return readable
108
- }
109
-
110
- module.exports = gitRawCommits