diff-lockfiles 1.1.0 → 1.2.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/CHANGELOG.md +4 -0
- package/README.md +7 -2
- package/lib/index.js +44 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -7,12 +7,17 @@ operates on Git commit ranges rather than on files.
|
|
|
7
7
|
|
|
8
8
|
## Example
|
|
9
9
|
|
|
10
|
+
Install `diff-lockfiles` globally:
|
|
11
|
+
|
|
10
12
|
```sh
|
|
11
|
-
npm install diff-lockfiles
|
|
12
|
-
diff-lockfiles --color origin/main dependabot/branch
|
|
13
|
+
npm install -g diff-lockfiles
|
|
13
14
|
```
|
|
14
15
|
|
|
16
|
+
Try it out:
|
|
17
|
+
|
|
15
18
|
```ssh
|
|
19
|
+
diff-lockfiles --color origin/main dependabot/branch
|
|
20
|
+
|
|
16
21
|
diff-lockfiles --color HEAD~1 HEAD
|
|
17
22
|
```
|
|
18
23
|
|
package/lib/index.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import semver from 'semver';
|
|
4
4
|
import { table } from 'table';
|
|
5
|
+
import { markdownTable } from 'markdown-table';
|
|
5
6
|
|
|
6
7
|
export function diff(oldLock, newLock, shallow) {
|
|
7
8
|
const changes = {};
|
|
8
|
-
|
|
9
|
+
|
|
9
10
|
function filterPackages(packages) {
|
|
10
11
|
let entries = Object.entries(packages);
|
|
11
12
|
if (shallow) {
|
|
@@ -114,6 +115,45 @@ function printTable(changes, options) {
|
|
|
114
115
|
/* eslint-disable no-console */
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
function printMarkdown(changes, options) {
|
|
119
|
+
/* eslint-disable no-console */
|
|
120
|
+
|
|
121
|
+
// Helper function to format version changes with markdown emphasis
|
|
122
|
+
function formatVersionChange(oldVersion, newVersion) {
|
|
123
|
+
if (!oldVersion) return `**${newVersion}** (added)`;
|
|
124
|
+
if (!newVersion) return `~~${oldVersion}~~ (removed)`;
|
|
125
|
+
|
|
126
|
+
if (semver.valid(oldVersion) && semver.valid(newVersion)) {
|
|
127
|
+
if (semver.lt(oldVersion, newVersion)) {
|
|
128
|
+
return `${oldVersion} → **${newVersion}**`;
|
|
129
|
+
} else if (semver.gt(oldVersion, newVersion)) {
|
|
130
|
+
return `**${oldVersion}** → ${newVersion}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return `${oldVersion} → ${newVersion}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const tableData = [
|
|
138
|
+
['Package', 'Old Version', 'New Version', 'Change'],
|
|
139
|
+
...Object.entries(changes).map(([name, [oldVersion, newVersion]]) => [
|
|
140
|
+
name,
|
|
141
|
+
oldVersion || '—',
|
|
142
|
+
newVersion || '—',
|
|
143
|
+
formatVersionChange(oldVersion, newVersion)
|
|
144
|
+
])
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
// Add title if provided
|
|
148
|
+
if (options.title && options.title !== '') {
|
|
149
|
+
console.log(`## ${options.title}\n`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
console.log(markdownTable(tableData));
|
|
153
|
+
|
|
154
|
+
/* eslint-enable no-console */
|
|
155
|
+
}
|
|
156
|
+
|
|
117
157
|
export function print(changes, options) {
|
|
118
158
|
switch (options.format) {
|
|
119
159
|
case 'json':
|
|
@@ -122,6 +162,9 @@ export function print(changes, options) {
|
|
|
122
162
|
case 'table':
|
|
123
163
|
printTable(changes, options);
|
|
124
164
|
break;
|
|
165
|
+
case 'markdown':
|
|
166
|
+
printMarkdown(changes, options);
|
|
167
|
+
break;
|
|
125
168
|
case 'text':
|
|
126
169
|
default:
|
|
127
170
|
printText(changes, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diff-lockfiles",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "a diff for package-lock.json files",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"chalk": "^5.3.0",
|
|
23
|
-
"commander": "^
|
|
23
|
+
"commander": "^14.0.0",
|
|
24
|
+
"markdown-table": "^3.0.4",
|
|
24
25
|
"semver": "^7.5.4",
|
|
25
26
|
"table": "^6.8.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"eslint": "^9.0.0",
|
|
29
|
-
"jest": "^
|
|
30
|
+
"jest": "^30.0.0"
|
|
30
31
|
}
|
|
31
32
|
}
|