2021-01-28 17:38:39 -05:00
|
|
|
const { basename, extname } = require('path')
|
|
|
|
|
|
|
|
const binaryExtensions = require('binary-extensions')
|
|
|
|
|
|
|
|
// we should try to print patches as long as the
|
|
|
|
// extension is not identified as binary files
|
|
|
|
const shouldPrintPatch = (path, opts = {}) => {
|
2021-11-18 20:58:02 +00:00
|
|
|
if (opts.diffText) {
|
2021-01-28 17:38:39 -05:00
|
|
|
return true
|
2021-11-18 20:58:02 +00:00
|
|
|
}
|
2021-01-28 17:38:39 -05:00
|
|
|
|
|
|
|
const filename = basename(path)
|
|
|
|
const extension = (
|
|
|
|
filename.startsWith('.')
|
|
|
|
? filename
|
|
|
|
: extname(filename)
|
2022-04-14 21:57:02 +00:00
|
|
|
).slice(1)
|
2021-01-28 17:38:39 -05:00
|
|
|
|
|
|
|
return !binaryExtensions.includes(extension)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = shouldPrintPatch
|