diff-lockfiles 1.1.0 → 1.2.1

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.2.1 - 2025-09-25
4
+
5
+ - Add markdown to --help output
6
+
7
+ ## 1.2.0 - 2025-09-25
8
+
9
+ - Added markdown as a table format
10
+
3
11
  ## 1.1.0 - 2024-06-28
4
12
 
5
13
  - Added --shallow to only handle direct dependencies (GH #31) (Jussi Kosunen)
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
 
@@ -35,7 +40,7 @@ Options:
35
40
 
36
41
  ### `--format=table` (default)
37
42
 
38
- ```texst
43
+ ```text
39
44
  $ diff-lockfiles HEAD~1 HEAD
40
45
  ╔═══════════════════════════════════════════════════════════════════╤═════════════╤═════════════╗
41
46
  ║ package-lock.json │ │ ║
@@ -423,6 +428,67 @@ node_modules/resolve 1.22.2 -> 1.22.4
423
428
  node_modules/@jest/reporters/node_modules/istanbul-lib-instrument added
424
429
  ```
425
430
 
431
+ ### `--format=markdown`
432
+
433
+ ```shell
434
+ $ diff-lockfiles --format markdown HEAD~1 HEAD
435
+ ```
436
+
437
+ | package | old version | new version |
438
+ | --- | --- | --- |
439
+ | node_modules/@jest/console | 29.6.2 | 29.6.3 |
440
+ | node_modules/@jest/core | 29.6.2 | 29.6.3 |
441
+ | node_modules/@jest/environment | 29.6.2 | 29.6.3 |
442
+ | node_modules/@jest/expect | 29.6.2 | 29.6.3 |
443
+ | node_modules/@jest/expect-utils | 29.6.2 | 29.6.3 |
444
+ | node_modules/@jest/fake-timers | 29.6.2 | 29.6.3 |
445
+ | node_modules/@jest/globals | 29.6.2 | 29.6.3 |
446
+ | node_modules/@jest/reporters | 29.6.2 | 29.6.3 |
447
+ | node_modules/@jest/schemas | 29.6.0 | 29.6.3 |
448
+ | node_modules/@jest/source-map | 29.6.0 | 29.6.3 |
449
+ | node_modules/@jest/test-result | 29.6.2 | 29.6.3 |
450
+ | node_modules/@jest/test-sequencer | 29.6.2 | 29.6.3 |
451
+ | node_modules/@jest/transform | 29.6.2 | 29.6.3 |
452
+ | node_modules/@jest/types | 29.6.1 | 29.6.3 |
453
+ | node_modules/@types/babel__core | 7.20.0 | 7.20.1 |
454
+ | node_modules/@types/babel__traverse | 7.18.2 | 7.20.1 |
455
+ | node_modules/babel-jest | 29.6.2 | 29.6.3 |
456
+ | node_modules/babel-plugin-jest-hoist | 29.5.0 | 29.6.3 |
457
+ | node_modules/babel-preset-jest | 29.5.0 | 29.6.3 |
458
+ | node_modules/dedent | 1.3.0 | 1.5.1 |
459
+ | node_modules/diff-sequences | 29.4.3 | 29.6.3 |
460
+ | node_modules/expect | 29.6.2 | 29.6.3 |
461
+ | node_modules/fsevents | 2.3.2 | 2.3.3 |
462
+ | node_modules/is-core-module | 2.12.1 | 2.13.0 |
463
+ | node_modules/jest | 29.6.2 | 29.6.3 |
464
+ | node_modules/jest-changed-files | 29.5.0 | 29.6.3 |
465
+ | node_modules/jest-circus | 29.6.2 | 29.6.3 |
466
+ | node_modules/jest-cli | 29.6.2 | 29.6.3 |
467
+ | node_modules/jest-config | 29.6.2 | 29.6.3 |
468
+ | node_modules/jest-diff | 29.6.2 | 29.6.3 |
469
+ | node_modules/jest-docblock | 29.4.3 | 29.6.3 |
470
+ | node_modules/jest-each | 29.6.2 | 29.6.3 |
471
+ | node_modules/jest-environment-node | 29.6.2 | 29.6.3 |
472
+ | node_modules/jest-get-type | 29.4.3 | 29.6.3 |
473
+ | node_modules/jest-haste-map | 29.6.2 | 29.6.3 |
474
+ | node_modules/jest-leak-detector | 29.6.2 | 29.6.3 |
475
+ | node_modules/jest-matcher-utils | 29.6.2 | 29.6.3 |
476
+ | node_modules/jest-message-util | 29.6.2 | 29.6.3 |
477
+ | node_modules/jest-mock | 29.6.2 | 29.6.3 |
478
+ | node_modules/jest-regex-util | 29.4.3 | 29.6.3 |
479
+ | node_modules/jest-resolve | 29.6.2 | 29.6.3 |
480
+ | node_modules/jest-resolve-dependencies | 29.6.2 | 29.6.3 |
481
+ | node_modules/jest-runner | 29.6.2 | 29.6.3 |
482
+ | node_modules/jest-runtime | 29.6.2 | 29.6.3 |
483
+ | node_modules/jest-snapshot | 29.6.2 | 29.6.3 |
484
+ | node_modules/jest-util | 29.6.2 | 29.6.3 |
485
+ | node_modules/jest-validate | 29.6.2 | 29.6.3 |
486
+ | node_modules/jest-watcher | 29.6.2 | 29.6.3 |
487
+ | node_modules/jest-worker | 29.6.2 | 29.6.3 |
488
+ | node_modules/pretty-format | 29.6.2 | 29.6.3 |
489
+ | node_modules/resolve | 1.22.2 | 1.22.4 |
490
+ | node_modules/@jest/reporters/node_modules/istanbul-lib-instrument | | 6.0.0 |
491
+
426
492
  ## Testing
427
493
 
428
494
  ```bash
@@ -33,7 +33,7 @@ cli
33
33
  .description('diff all changed package-lock.json files in repo')
34
34
  .version(version)
35
35
  .arguments('<from> <to>')
36
- .option('-f, --format <format>', 'changes the output format (table|json|text)', 'table')
36
+ .option('-f, --format <format>', 'changes the output format (table|json|markdown|text)', 'table')
37
37
  .option('-m, --max-buffer', 'maximum read buffer size', 1024 * 10000)
38
38
  .option('-c, --color', 'colorizes certain output formats', false)
39
39
  .option('-s, --shallow', 'only include direct dependencies of the project', false)
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.1.0",
3
+ "version": "1.2.1",
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": "^12.0.0",
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": "^29.6.2"
30
+ "jest": "^30.0.0"
30
31
  }
31
32
  }