Skip to content

Commit 5f473e8

Browse files
authored
Merge pull request #15 from UniquePanda/develop
Merge release 0.2.0 into main
2 parents 271adbc + 2635572 commit 5f473e8

11 files changed

Lines changed: 1111 additions & 48 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
# Change Log
22

3+
## 0.2.0
4+
### Added
5+
* Added NpmRunner class and npm-update-diff exectuable (#1)
6+
* Added running of npm update and creation of diff of dependency trees from before and after update (#4)
7+
* Make executable run provided command instead of always running npm update (#12)
8+
* Rename project from `npm-update-diff` to `npm-run-diff` to `npm-with-diff` (#7, #9) :facepalm: :smile:
9+
310
## Unreleased

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# npm-update-diff
2-
An npm package that will show which packages changed after a run of "npm update".
1+
# npm-with-diff
2+
Use this instead of 'npm' to get a readable diff of the dependency trees from before and after the execution of the npm command.

bin/npm-with-diff.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#! /usr/bin/env node
2+
3+
const NpmWithDiff = require('../lib/NpmWithDiff').NpmWithDiff;
4+
5+
const argumentsWithValue = ['--searchedTreeDepth'];
6+
7+
let isDebug = false;
8+
let forceExecution = false;
9+
let excludeDevPackagesFromDiff = false;
10+
let searchedTreeDepthForDiff = 10;
11+
let command = '';
12+
13+
async function main() {
14+
const arguments = process.argv.slice(2); // First two arguments are execPath and path of JS file.
15+
16+
let internalArguments = []; // Arguments that are used for this script.
17+
let npmArguments = []; // Arguments that are passed to npm.
18+
19+
let isReadingInternalArguments = true;
20+
arguments.forEach((argument) => {
21+
if (isReadingInternalArguments) {
22+
if (argument === '--') { // "--" marks the end of internal arguments.
23+
isReadingInternalArguments = false;
24+
return;
25+
}
26+
27+
internalArguments.push(argument);
28+
} else {
29+
npmArguments.push(argument);
30+
}
31+
});
32+
33+
// If no arguments were added for npm and no "--" was added to the arguments, assume that only npm arguments were
34+
// provided. This is a little "hack" around the double dash convention, but probably reflects most use cases better.
35+
if (isReadingInternalArguments) {
36+
npmArguments = internalArguments.slice();
37+
internalArguments = [];
38+
}
39+
40+
// If first npm argument doesn't start with a dash, assume it's an npm command.
41+
if (npmArguments.length > 0 && !npmArguments[0].startsWith('-')) {
42+
command = npmArguments.shift(); // All other npm arguments are treated as arguments for the command.
43+
}
44+
45+
for (const internalArgument of internalArguments) {
46+
const splitArgument = internalArgument.split('=');
47+
const argument = splitArgument[0];
48+
let value = null;
49+
50+
if (splitArgument.length > 1) {
51+
splitArgument.shift();
52+
value = splitArgument.join('');
53+
54+
if (!argumentsWithValue.includes(argument)) {
55+
console.error('Argument "' + argument + '" cannot be provided with a value.');
56+
return;
57+
}
58+
59+
if (value === '') {
60+
console.error('Please provide a value for argument "' + argument + '".');
61+
return;
62+
}
63+
}
64+
65+
switch (argument) {
66+
case '--dev-only-debug':
67+
isDebug = true;
68+
break;
69+
case '--force':
70+
case '-f':
71+
forceExecution = true;
72+
break;
73+
case '--exclude-dev':
74+
excludeDevPackagesFromDiff = true;
75+
break;
76+
case '--searchedTreeDepth':
77+
searchedTreeDepthForDiff = value;
78+
break;
79+
default:
80+
console.error('Unknown argument: "' + argument + '".');
81+
return;
82+
}
83+
}
84+
85+
86+
await (new NpmWithDiff(isDebug).runCommandWithDiff(
87+
command,
88+
npmArguments,
89+
searchedTreeDepthForDiff,
90+
excludeDevPackagesFromDiff,
91+
forceExecution
92+
));
93+
}
94+
95+
main();

package-lock.json

Lines changed: 33 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
{
2-
"name": "npm-update-diff",
3-
"version": "0.1.0",
4-
"description": "Shows which packages changed after a run of \"npm update\".",
5-
"main": "index.js",
2+
"name": "npm-with-diff",
3+
"version": "0.2.0",
4+
"description": "Use this instead of 'npm' to get a readable diff of the dependency trees from before and after the execution of the npm command.",
5+
"author": "Marcel Wendler (https://github.com/UniquePanda)",
6+
"license": "MIT",
7+
"main": "lib/index.js",
8+
"types": "lib/index.d.js",
9+
"bin": {
10+
"npm-with-diff": "./bin/npm-with-diff.js"
11+
},
612
"scripts": {
713
"test": "jest --config jest.config.json",
814
"build": "tsc"
915
},
16+
"files": [
17+
"lib/**/*"
18+
],
1019
"repository": {
1120
"type": "git",
12-
"url": "git+https://github.com/UniquePanda/npm-update-diff.git"
21+
"url": "git+https://github.com/UniquePanda/npm-with-diff.git"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/UniquePanda/npm-with-diff/issues"
1325
},
26+
"homepage": "https://github.com/UniquePanda/npm-with-diff#readme",
1427
"keywords": [
1528
"npm",
29+
"command",
30+
"run",
1631
"update",
32+
"install",
33+
"dependency",
34+
"dependencies",
1735
"diff",
1836
"difference",
1937
"package"
2038
],
21-
"author": "Marcel Wendler (https://github.com/UniquePanda)",
22-
"license": "MIT",
23-
"bugs": {
24-
"url": "https://github.com/UniquePanda/npm-update-diff/issues"
25-
},
26-
"homepage": "https://github.com/UniquePanda/npm-update-diff#readme",
27-
"files": [
28-
"lib/**/*"
29-
],
3039
"devDependencies": {
31-
"@types/jest": "^29.2.5",
40+
"@types/jest": "^29.2.6",
3241
"@types/node": "^18.11.18",
3342
"jest": "^29.3.1",
3443
"ts-jest": "^29.0.5",

src/Interfaces.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export interface NpmPackageList {
2+
version: string,
3+
name: string,
4+
dependencies: Map<string, NpmPackageListEntry>,
5+
}
6+
7+
export interface NpmPackageListEntry {
8+
version: string,
9+
resolved: string,
10+
overridden: boolean,
11+
dependencies?: Map<string, NpmPackageListEntry>,
12+
}
13+
14+
export interface PackageListDiff {
15+
packageName: string,
16+
parentPackagesNames: Array<string>,
17+
directDependenciesCount: number,
18+
wasAdded: boolean,
19+
wasRemoved: boolean,
20+
previousVersion: string|null,
21+
newVersion: string|null,
22+
}

0 commit comments

Comments
 (0)