diff-lockfiles 1.0.3 → 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 +4 -0
- package/README.md +1 -0
- package/bin/diff-lockfiles.js +2 -1
- package/lib/index.js +16 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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
|
@@ -36,13 +36,14 @@ cli
|
|
|
36
36
|
.option('-f, --format <format>', 'changes the output format (table|json|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
|
+
.option('-s, --shallow', 'only include direct dependencies of the project', false)
|
|
39
40
|
.action((from, to, options) => {
|
|
40
41
|
lockFiles(from, to).then((v) => {
|
|
41
42
|
for (let filename of v) {
|
|
42
43
|
const a = lockFileString(options.maxBuffer, from, filename).then((s) => { return JSON.parse(s); });
|
|
43
44
|
const b = lockFileString(options.maxBuffer, to, filename).then((s) => { return JSON.parse(s); });
|
|
44
45
|
Promise.all([a, b]).then((values) => {
|
|
45
|
-
const changes = diff(values[0], values[1]);
|
|
46
|
+
const changes = diff(values[0], values[1], options.shallow);
|
|
46
47
|
print(changes, {
|
|
47
48
|
color: options.color,
|
|
48
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];
|