dependency-change-report 1.0.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/README.md +127 -0
- package/cli.mjs +92 -0
- package/lib/generate-html.mjs +967 -0
- package/lib/generate-text.mjs +411 -0
- package/lib/index.mjs +1424 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Dependency Change Report
|
|
2
|
+
|
|
3
|
+
A tool to analyze dependency changes between different versions of a Node.js project and generate detailed reports with changelogs.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Compare dependencies between two versions of a repository
|
|
8
|
+
- Identify added, upgraded, removed, and modified dependencies
|
|
9
|
+
- Generate changelogs for upgraded dependencies by analyzing commit history
|
|
10
|
+
- Detect namespace changes in dependencies (e.g., from `package` to `@org/package`)
|
|
11
|
+
- Create HTML reports with detailed information
|
|
12
|
+
- Track and report errors during changelog generation
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### Using npx (Recommended)
|
|
17
|
+
|
|
18
|
+
No installation required! Run directly with npx:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx dependency-change-report <github-repo> <older-version> <newer-version> [working-dir]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Global Installation (Alternative)
|
|
25
|
+
|
|
26
|
+
For frequent use, you can install globally:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install -g dependency-change-report
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then run with:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
dependency-change-report <github-repo> <older-version> <newer-version> [working-dir]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Command Line Interface
|
|
41
|
+
|
|
42
|
+
Generate a dependency report:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Using npx (recommended)
|
|
46
|
+
npx dependency-change-report <github-repo> <older-version> <newer-version> [working-dir]
|
|
47
|
+
|
|
48
|
+
# If installed globally
|
|
49
|
+
dependency-change-report <github-repo> <older-version> <newer-version> [working-dir]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The tool automatically generates three report formats:
|
|
53
|
+
- `report.json` - Raw data in JSON format
|
|
54
|
+
- `report.html` - Web-friendly HTML report
|
|
55
|
+
- `report.txt` - Slack-friendly text report
|
|
56
|
+
|
|
57
|
+
### Examples
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Generate a report comparing v1.0.0 and v2.0.0 of a repository
|
|
61
|
+
npx dependency-change-report git@github.com:user/repo.git v1.0.0 v2.0.0
|
|
62
|
+
|
|
63
|
+
# Generate a report with a specific working directory
|
|
64
|
+
npx dependency-change-report git@github.com:user/repo.git v1.0.0 v2.0.0 /tmp/analysis
|
|
65
|
+
|
|
66
|
+
# Filter nested dependencies by namespace (e.g., @holepunch)
|
|
67
|
+
npx dependency-change-report git@github.com:user/repo.git v1.0.0 v2.0.0 . @holepunch
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Programmatic Usage
|
|
71
|
+
|
|
72
|
+
You can also use the tool programmatically in your own Node.js projects:
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
import { analyzeDependencyChanges } from 'dependency-change-report';
|
|
76
|
+
import { generateHtmlReport } from 'dependency-change-report/lib/generate-html.mjs';
|
|
77
|
+
import { generateTextReport } from 'dependency-change-report/lib/generate-text.mjs';
|
|
78
|
+
|
|
79
|
+
// Generate a dependency report
|
|
80
|
+
const report = await analyzeDependencyChanges(
|
|
81
|
+
'git@github.com:user/repo.git',
|
|
82
|
+
'v1.0.0',
|
|
83
|
+
'v2.0.0'
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Generate an HTML report from a JSON report
|
|
87
|
+
await generateHtmlReport('./path/to/report.json', './path/to/output.html');
|
|
88
|
+
|
|
89
|
+
// Generate a text report from a JSON report
|
|
90
|
+
await generateTextReport('./path/to/report.json', './path/to/output.txt');
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Report Structure
|
|
94
|
+
|
|
95
|
+
The generated JSON report includes:
|
|
96
|
+
|
|
97
|
+
- Repository information
|
|
98
|
+
- Version comparison details
|
|
99
|
+
- Lists of added, upgraded, removed, and modified dependencies
|
|
100
|
+
- Changelogs with commit history for upgraded dependencies
|
|
101
|
+
- Error information for dependencies that couldn't be analyzed
|
|
102
|
+
|
|
103
|
+
The HTML report provides a user-friendly visualization of this data, including:
|
|
104
|
+
|
|
105
|
+
- Summary statistics
|
|
106
|
+
- Detailed tables of dependency changes
|
|
107
|
+
- Commit history for upgraded dependencies
|
|
108
|
+
- Error information
|
|
109
|
+
|
|
110
|
+
## How It Works
|
|
111
|
+
|
|
112
|
+
1. Clones the repository at both the older and newer versions
|
|
113
|
+
2. Installs dependencies for both versions
|
|
114
|
+
3. Compares the dependency trees to identify changes
|
|
115
|
+
4. For each upgraded dependency, clones its repository and analyzes commit history
|
|
116
|
+
5. Generates a JSON report with all the collected information
|
|
117
|
+
6. Optionally converts the JSON report to an HTML report
|
|
118
|
+
|
|
119
|
+
## Requirements
|
|
120
|
+
|
|
121
|
+
- Node.js 14 or higher
|
|
122
|
+
- Git
|
|
123
|
+
- npm
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
ISC
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { analyzeDependencyChanges } from './lib/index.mjs';
|
|
4
|
+
import { generateHtmlReport } from './lib/generate-html.mjs';
|
|
5
|
+
import { generateTextReport } from './lib/generate-text.mjs';
|
|
6
|
+
import { dirname, join, basename } from 'path';
|
|
7
|
+
|
|
8
|
+
// CLI interface
|
|
9
|
+
const main = async () => {
|
|
10
|
+
try {
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
|
|
13
|
+
if (args.length < 3) {
|
|
14
|
+
console.error('Usage: dependency-change-report <github-repo> <older-version> <newer-version> [working-dir] [namespace]');
|
|
15
|
+
console.error(' <older-version> and <newer-version> can be any git reference (tag, branch, commit)');
|
|
16
|
+
console.error(' [namespace] is optional - if provided, only second-level dependencies within this namespace will be analyzed (e.g., @holepunch)');
|
|
17
|
+
console.error('');
|
|
18
|
+
console.error('This command generates three files:');
|
|
19
|
+
console.error(' - report.json (raw data)');
|
|
20
|
+
console.error(' - report.html (web-friendly report)');
|
|
21
|
+
console.error(' - report.txt (Slack-friendly text report)');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [repoUrl, olderVersion, newerVersion, workingDir, namespace] = args;
|
|
26
|
+
|
|
27
|
+
console.log(`Analyzing dependency changes for ${repoUrl} between older version (${olderVersion}) and newer version (${newerVersion})`);
|
|
28
|
+
if (namespace) {
|
|
29
|
+
console.log(`Filtering second-level dependencies to only include those in namespace: ${namespace}`);
|
|
30
|
+
}
|
|
31
|
+
const report = await analyzeDependencyChanges(repoUrl, olderVersion, newerVersion, workingDir, namespace);
|
|
32
|
+
|
|
33
|
+
console.log('\nSummary:');
|
|
34
|
+
console.log(`Added dependencies: ${report.changes.added.length}`);
|
|
35
|
+
console.log(`Upgraded dependencies: ${report.changes.upgraded.length}`);
|
|
36
|
+
console.log(`Removed dependencies: ${report.changes.removed.length}`);
|
|
37
|
+
console.log(`Modified dependencies (namespace changes): ${report.changes.modified ? report.changes.modified.length : 0}`);
|
|
38
|
+
|
|
39
|
+
// Display nested dependency information if available
|
|
40
|
+
if (report.changes.nested) {
|
|
41
|
+
console.log('\nNested Dependencies:');
|
|
42
|
+
console.log(`Added nested dependencies: ${report.changes.nested.added.length}`);
|
|
43
|
+
console.log(`Upgraded nested dependencies: ${report.changes.nested.upgraded.length}`);
|
|
44
|
+
console.log(`Removed nested dependencies: ${report.changes.nested.removed.length}`);
|
|
45
|
+
|
|
46
|
+
if (namespace) {
|
|
47
|
+
console.log(`\nNote: Nested dependencies filtered by namespace: ${namespace}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const changelogCount = Object.keys(report.changelogs).length;
|
|
52
|
+
const errorCount = Object.keys(report.errors).length;
|
|
53
|
+
console.log(`Generated changelogs for ${changelogCount} upgraded dependencies`);
|
|
54
|
+
console.log(`Encountered errors with ${errorCount} dependencies`);
|
|
55
|
+
|
|
56
|
+
// Generate HTML and text reports
|
|
57
|
+
console.log('\nGenerating additional report formats...');
|
|
58
|
+
|
|
59
|
+
// Use the actual report directory path from the report
|
|
60
|
+
const reportJsonPath = report.reportPath;
|
|
61
|
+
const reportDir = dirname(reportJsonPath);
|
|
62
|
+
|
|
63
|
+
// Generate HTML report
|
|
64
|
+
const htmlPath = join(reportDir, 'report.html');
|
|
65
|
+
await generateHtmlReport(reportJsonPath, htmlPath);
|
|
66
|
+
|
|
67
|
+
// Generate text report
|
|
68
|
+
const textPath = join(reportDir, 'report.txt');
|
|
69
|
+
await generateTextReport(reportJsonPath, textPath);
|
|
70
|
+
|
|
71
|
+
console.log('\nAll reports generated successfully!');
|
|
72
|
+
console.log(`📄 JSON: ${reportJsonPath}`);
|
|
73
|
+
console.log(`🌐 HTML: ${htmlPath}`);
|
|
74
|
+
console.log(`📝 Text: ${textPath}`);
|
|
75
|
+
|
|
76
|
+
// Display repository information for added dependencies
|
|
77
|
+
if (report.changes.added.length > 0) {
|
|
78
|
+
console.log('\nAdded dependencies with repositories:');
|
|
79
|
+
report.changes.added.forEach(dep => {
|
|
80
|
+
if (dep.repository) {
|
|
81
|
+
console.log(`- ${dep.name}: ${dep.repository}`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error(`Error: ${error.message}`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Run the main function
|
|
92
|
+
main();
|