diff-lockfiles 1.0.2 → 1.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/CHANGELOG.md +9 -0
- package/README.md +1 -0
- package/bin/diff-lockfiles.js +5 -8
- package/lib/index.js +16 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 1.1.0 - 2024-06-28
|
|
4
|
+
|
|
5
|
+
- Added --shallow to only handle direct dependencies (GH #31) (Jussi Kosunen)
|
|
6
|
+
|
|
7
|
+
## 1.0.3 - 2024-06-06
|
|
8
|
+
|
|
9
|
+
- Only diff files whose string *ends* with package-lock.json (GH #24 Tim
|
|
10
|
+
Vergenz)
|
|
11
|
+
|
|
3
12
|
## 1.0.2 - 2023-09-07
|
|
4
13
|
|
|
5
14
|
- Default to table layout rather than text
|
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ Options:
|
|
|
29
29
|
-f, --format <format> changes the output format (default: "table")
|
|
30
30
|
-m, --max-buffer maximum read buffer size
|
|
31
31
|
-c, --color colorizes certain output formats (default: false)
|
|
32
|
+
-s, --shallow only include direct dependencies of the project (default: false)
|
|
32
33
|
-h, --help display help for command
|
|
33
34
|
```
|
|
34
35
|
|
package/bin/diff-lockfiles.js
CHANGED
|
@@ -8,19 +8,15 @@ import { diff, print } from '../lib/index.js';
|
|
|
8
8
|
const execPromise = promisify(exec);
|
|
9
9
|
const version = '1.0.2';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
const output = await execPromise(`git diff ${a} ${b} --name-only | grep package-lock.json`);
|
|
11
|
+
async function lockFiles(a, b) {
|
|
12
|
+
const output = await execPromise(`git diff ${a} ${b} --name-only | grep 'package-lock.json$'`);
|
|
13
13
|
const lines = output.stdout;
|
|
14
14
|
const list = lines.trim().split(/\r\n|\r|\n/);
|
|
15
15
|
|
|
16
|
-
if (output.stderr.trim !== '') {
|
|
17
|
-
// console.error(output.stderr.trim);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
16
|
return list;
|
|
21
17
|
};
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
async function lockFileString(maxBuffer, branch, filename) {
|
|
24
20
|
const output = await execPromise(`git show ${branch}:${filename}`, { maxBuffer: maxBuffer });
|
|
25
21
|
const lines = output.stdout.trim();
|
|
26
22
|
|
|
@@ -40,13 +36,14 @@ cli
|
|
|
40
36
|
.option('-f, --format <format>', 'changes the output format (table|json|text)', 'table')
|
|
41
37
|
.option('-m, --max-buffer', 'maximum read buffer size', 1024 * 10000)
|
|
42
38
|
.option('-c, --color', 'colorizes certain output formats', false)
|
|
39
|
+
.option('-s, --shallow', 'only include direct dependencies of the project', false)
|
|
43
40
|
.action((from, to, options) => {
|
|
44
41
|
lockFiles(from, to).then((v) => {
|
|
45
42
|
for (let filename of v) {
|
|
46
43
|
const a = lockFileString(options.maxBuffer, from, filename).then((s) => { return JSON.parse(s); });
|
|
47
44
|
const b = lockFileString(options.maxBuffer, to, filename).then((s) => { return JSON.parse(s); });
|
|
48
45
|
Promise.all([a, b]).then((values) => {
|
|
49
|
-
const changes = diff(values[0], values[1]);
|
|
46
|
+
const changes = diff(values[0], values[1], options.shallow);
|
|
50
47
|
print(changes, {
|
|
51
48
|
color: options.color,
|
|
52
49
|
format: options.format,
|
package/lib/index.js
CHANGED
|
@@ -3,14 +3,27 @@ import chalk from 'chalk';
|
|
|
3
3
|
import semver from 'semver';
|
|
4
4
|
import { table } from 'table';
|
|
5
5
|
|
|
6
|
-
export function diff(oldLock, newLock) {
|
|
6
|
+
export function diff(oldLock, newLock, shallow) {
|
|
7
7
|
const changes = {};
|
|
8
|
+
|
|
9
|
+
function filterPackages(packages) {
|
|
10
|
+
let entries = Object.entries(packages);
|
|
11
|
+
if (shallow) {
|
|
12
|
+
const selfPackage = packages[''];
|
|
13
|
+
const directDeps = new Set(
|
|
14
|
+
['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']
|
|
15
|
+
.flatMap(key => Object.keys(selfPackage[key] ?? {}))
|
|
16
|
+
.map(pkg => `node_modules/${pkg}`));
|
|
17
|
+
entries = entries.filter(([name]) => directDeps.has(name) || name === ''); // include self for compatibility
|
|
18
|
+
}
|
|
19
|
+
return entries;
|
|
20
|
+
}
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
filterPackages(oldLock.packages).forEach(([name, { version }]) => {
|
|
10
23
|
changes[name] = [version, null];
|
|
11
24
|
});
|
|
12
25
|
|
|
13
|
-
|
|
26
|
+
filterPackages(newLock.packages).forEach(([name, { version }]) => {
|
|
14
27
|
if (changes[name] && changes[name][0]) {
|
|
15
28
|
if (semver.eq(changes[name][0], version)) {
|
|
16
29
|
delete changes[name];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diff-lockfiles",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "a diff for package-lock.json files",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"chalk": "^5.3.0",
|
|
23
|
-
"commander": "^
|
|
23
|
+
"commander": "^12.0.0",
|
|
24
24
|
"semver": "^7.5.4",
|
|
25
25
|
"table": "^6.8.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"eslint": "^
|
|
28
|
+
"eslint": "^9.0.0",
|
|
29
29
|
"jest": "^29.6.2"
|
|
30
30
|
}
|
|
31
31
|
}
|