git-raw-commits
Advanced tools
Comparing version 3.0.0 to 4.0.0
114
index.js
@@ -1,7 +0,5 @@ | ||
'use strict' | ||
const dargs = require('dargs') | ||
const execFile = require('child_process').execFile | ||
const { Readable, Transform } = require('stream') | ||
const { execFile } = require('child_process') | ||
const split = require('split2') | ||
const { Readable, Transform } = require('stream') | ||
@@ -13,2 +11,3 @@ const DELIMITER = '------------------------ >8 ------------------------' | ||
execOpts.cwd = execOpts.cwd || process.cwd() | ||
return execOpts | ||
@@ -22,18 +21,19 @@ } | ||
gitOpts.to = gitOpts.to || 'HEAD' | ||
return gitOpts | ||
} | ||
function getGitArgs (gitOpts) { | ||
async function getGitArgs (gitOpts) { | ||
const { default: dargs } = await import('dargs') | ||
const gitFormat = `--format=${gitOpts.format || ''}%n${DELIMITER}` | ||
const gitFromTo = [gitOpts.from, gitOpts.to].filter(Boolean).join('..') | ||
const gitArgs = ['log', gitFormat, gitFromTo] | ||
.concat(dargs(gitOpts, { | ||
excludes: ['debug', 'from', 'to', 'format', 'path'] | ||
excludes: ['debug', 'from', 'to', 'format', 'path', 'ignore'] | ||
})) | ||
// allow commits to focus on a single directory | ||
// allow commits to focus on specific directories. | ||
// this is useful for monorepos. | ||
if (gitOpts.path) { | ||
gitArgs.push('--', gitOpts.path) | ||
gitArgs.push('--', ...Array.isArray(gitOpts.path) ? gitOpts.path : [gitOpts.path]) | ||
} | ||
@@ -46,55 +46,65 @@ | ||
const readable = new Readable() | ||
readable._read = function () {} | ||
readable._read = () => {} | ||
const gitOpts = normalizeGitOpts(rawGitOpts) | ||
const execOpts = normalizeExecOpts(rawExecOpts) | ||
const args = getGitArgs(gitOpts) | ||
let isError = false | ||
if (gitOpts.debug) { | ||
gitOpts.debug('Your git-log command is:\ngit ' + args.join(' ')) | ||
} | ||
getGitArgs(gitOpts).then((args) => { | ||
if (gitOpts.debug) { | ||
gitOpts.debug('Your git-log command is:\ngit ' + args.join(' ')) | ||
} | ||
let isError = false | ||
const ignoreRegex = typeof gitOpts.ignore === 'string' | ||
? new RegExp(gitOpts.ignore) | ||
: gitOpts.ignore | ||
const shouldNotIgnore = ignoreRegex | ||
? chunk => !ignoreRegex.test(chunk.toString()) | ||
: () => true | ||
const child = execFile('git', args, { | ||
cwd: execOpts.cwd, | ||
maxBuffer: Infinity | ||
}) | ||
const child = execFile('git', args, { | ||
cwd: execOpts.cwd, | ||
maxBuffer: Infinity | ||
}) | ||
child.stdout | ||
.pipe(split(DELIMITER + '\n')) | ||
.pipe( | ||
new Transform({ | ||
transform (chunk, enc, cb) { | ||
readable.push(chunk) | ||
isError = false | ||
child.stdout | ||
.pipe(split(DELIMITER + '\n')) | ||
.pipe( | ||
new Transform({ | ||
transform (chunk, enc, cb) { | ||
isError = false | ||
setImmediate(() => { | ||
if (shouldNotIgnore(chunk)) { | ||
readable.push(chunk) | ||
} | ||
cb() | ||
}) | ||
}, | ||
flush (cb) { | ||
setImmediate(() => { | ||
if (!isError) { | ||
readable.push(null) | ||
readable.emit('close') | ||
} | ||
cb() | ||
}, | ||
flush (cb) { | ||
setImmediate(function () { | ||
if (!isError) { | ||
readable.push(null) | ||
readable.emit('close') | ||
} | ||
cb() | ||
}) | ||
} | ||
}) | ||
) | ||
cb() | ||
}) | ||
} | ||
}) | ||
) | ||
child.stderr | ||
.pipe( | ||
new Transform({ | ||
objectMode: true, | ||
highWaterMark: 16, | ||
transform (chunk) { | ||
isError = true | ||
readable.emit('error', new Error(chunk)) | ||
readable.emit('close') | ||
} | ||
}) | ||
) | ||
}) | ||
child.stderr | ||
.pipe( | ||
new Transform({ | ||
objectMode: true, | ||
highWaterMark: 16, | ||
transform (chunk) { | ||
isError = true | ||
readable.emit('error', new Error(chunk)) | ||
readable.emit('close') | ||
} | ||
}) | ||
) | ||
return readable | ||
@@ -101,0 +111,0 @@ } |
{ | ||
"name": "git-raw-commits", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Get raw git commits out of your repository using git-log(1)", | ||
@@ -20,7 +20,7 @@ "bugs": { | ||
"engines": { | ||
"node": ">=14" | ||
"node": ">=16" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
"cli.mjs" | ||
], | ||
@@ -37,12 +37,9 @@ "keywords": [ | ||
"dependencies": { | ||
"dargs": "^7.0.0", | ||
"meow": "^8.1.2", | ||
"split2": "^3.2.2" | ||
"dargs": "^8.0.0", | ||
"meow": "^12.0.1", | ||
"split2": "^4.0.0" | ||
}, | ||
"bin": { | ||
"git-raw-commits": "cli.js" | ||
}, | ||
"scripts": { | ||
"test-windows": "mocha --timeout 30000" | ||
"git-raw-commits": "cli.mjs" | ||
} | ||
} |
@@ -62,5 +62,5 @@ # [![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] | ||
Type: `string` | ||
Type: `string` or `array` | ||
Filter commits to the path provided. | ||
Filter commits to the path(s) provided. | ||
@@ -67,0 +67,0 @@ ##### execOpts |
7859
108
+ Addeddargs@8.1.0(transitive)
+ Addedmeow@12.1.1(transitive)
+ Addedsplit2@4.2.0(transitive)
- Removed@babel/code-frame@7.24.7(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/highlight@7.24.7(transitive)
- Removed@types/minimist@1.2.5(transitive)
- Removed@types/normalize-package-data@2.4.4(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedarrify@1.0.1(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedcamelcase-keys@6.2.2(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddargs@7.0.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddecamelize-keys@1.1.1(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedhard-rejection@2.1.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.94.1.0(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.13.1(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjson-parse-even-better-errors@2.3.1(transitive)
- Removedkind-of@6.0.3(transitive)
- Removedlines-and-columns@1.2.4(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedlru-cache@6.0.0(transitive)
- Removedmap-obj@1.0.14.3.0(transitive)
- Removedmeow@8.1.2(transitive)
- Removedmin-indent@1.0.1(transitive)
- Removedminimist-options@4.1.0(transitive)
- Removednormalize-package-data@2.5.03.0.3(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedparse-json@5.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpicocolors@1.0.1(transitive)
- Removedquick-lru@4.0.1(transitive)
- Removedread-pkg@5.2.0(transitive)
- Removedread-pkg-up@7.0.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedredent@3.0.0(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@5.7.27.6.2(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.18(transitive)
- Removedsplit2@3.2.2(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-indent@3.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@3.0.1(transitive)
- Removedtype-fest@0.18.10.6.00.8.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedyallist@4.0.0(transitive)
- Removedyargs-parser@20.2.9(transitive)
Updateddargs@^8.0.0
Updatedmeow@^12.0.1
Updatedsplit2@^4.0.0