libnpmdiff 6.0.9 → 6.1.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/lib/format-diff.js +30 -8
- package/package.json +4 -5
package/lib/format-diff.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
const EOL = '\n'
|
|
2
|
-
|
|
3
|
-
const colorizeDiff = require('@npmcli/disparity-colors')
|
|
4
1
|
const jsDiff = require('diff')
|
|
5
2
|
|
|
6
3
|
const shouldPrintPatch = require('./should-print-patch.js')
|
|
7
4
|
|
|
5
|
+
const colors = {
|
|
6
|
+
// red
|
|
7
|
+
removed: { open: '\x1B[31m', close: '\x1B[39m' },
|
|
8
|
+
// green
|
|
9
|
+
added: { open: '\x1B[32m', close: '\x1B[39m' },
|
|
10
|
+
// blue
|
|
11
|
+
header: { open: '\x1B[34m', close: '\x1B[39m' },
|
|
12
|
+
// cyan
|
|
13
|
+
section: { open: '\x1B[36m', close: '\x1B[39m' },
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const color = (colorStr, colorId) => {
|
|
17
|
+
const { open, close } = colors[colorId]
|
|
18
|
+
// avoid highlighting the "\n" (would highlight till the end of the line)
|
|
19
|
+
return colorStr.replace(/[^\n\r]+/g, open + '$&' + close)
|
|
20
|
+
}
|
|
21
|
+
|
|
8
22
|
const formatDiff = ({ files, opts = {}, refs, versions }) => {
|
|
9
23
|
let res = ''
|
|
10
24
|
const srcPrefix = opts.diffNoPrefix ? '' : opts.diffSrcPrefix || 'a/'
|
|
@@ -35,7 +49,7 @@ const formatDiff = ({ files, opts = {}, refs, versions }) => {
|
|
|
35
49
|
}
|
|
36
50
|
|
|
37
51
|
if (opts.diffNameOnly) {
|
|
38
|
-
res += `${filename}
|
|
52
|
+
res += `${filename}\n`
|
|
39
53
|
continue
|
|
40
54
|
}
|
|
41
55
|
|
|
@@ -43,7 +57,7 @@ const formatDiff = ({ files, opts = {}, refs, versions }) => {
|
|
|
43
57
|
let headerLength = 0
|
|
44
58
|
const header = str => {
|
|
45
59
|
headerLength++
|
|
46
|
-
patch += `${str}
|
|
60
|
+
patch += `${str}\n`
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
// manually build a git diff-compatible header
|
|
@@ -85,9 +99,17 @@ const formatDiff = ({ files, opts = {}, refs, versions }) => {
|
|
|
85
99
|
header(`+++ ${names.b}`)
|
|
86
100
|
}
|
|
87
101
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
if (opts.color) {
|
|
103
|
+
// this RegExp will include all the `\n` chars into the lines, easier to join
|
|
104
|
+
const lines = patch.split(/^/m)
|
|
105
|
+
res += color(lines.slice(0, headerLength).join(''), 'header')
|
|
106
|
+
res += lines.slice(headerLength).join('')
|
|
107
|
+
.replace(/^-.*/gm, color('$&', 'removed'))
|
|
108
|
+
.replace(/^\+.*/gm, color('$&', 'added'))
|
|
109
|
+
.replace(/^@@.+@@/gm, color('$&', 'section'))
|
|
110
|
+
} else {
|
|
111
|
+
res += patch
|
|
112
|
+
}
|
|
91
113
|
}
|
|
92
114
|
|
|
93
115
|
return res.trim()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libnpmdiff",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "The registry diff",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,13 +47,12 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@npmcli/arborist": "^7.2.1",
|
|
50
|
-
"@npmcli/
|
|
51
|
-
"@npmcli/installed-package-contents": "^2.0.2",
|
|
50
|
+
"@npmcli/installed-package-contents": "^2.1.0",
|
|
52
51
|
"binary-extensions": "^2.3.0",
|
|
53
52
|
"diff": "^5.1.0",
|
|
54
53
|
"minimatch": "^9.0.4",
|
|
55
|
-
"npm-package-arg": "^11.0.
|
|
56
|
-
"pacote": "^
|
|
54
|
+
"npm-package-arg": "^11.0.2",
|
|
55
|
+
"pacote": "^18.0.1",
|
|
57
56
|
"tar": "^6.2.1"
|
|
58
57
|
},
|
|
59
58
|
"templateOSS": {
|