dependency-change-report 1.4.5 → 1.4.7
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/cli.mjs +37 -2
- package/lib/core/analyzer.mjs +26 -6
- package/lib/generate-html.mjs +2 -1
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { dirname, join, basename } from 'path';
|
|
|
9
9
|
import { command, flag, arg, summary, rest } from 'paparam'
|
|
10
10
|
import envPaths from 'env-paths';
|
|
11
11
|
import { executeCommand } from './lib/utils/command-executor.mjs';
|
|
12
|
+
import { mkdir } from 'fs/promises';
|
|
12
13
|
|
|
13
14
|
const compare = command(
|
|
14
15
|
'compare',
|
|
@@ -49,6 +50,14 @@ const compare = command(
|
|
|
49
50
|
outputDir = workingDir; // Default to working directory
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
// Ensure output directory exists
|
|
54
|
+
try {
|
|
55
|
+
await mkdir(outputDir, { recursive: true });
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(`Failed to create output directory ${outputDir}: ${error.message}`);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
console.log(`Analyzing dependency changes for ${repoUrl} between older version (${olderVersion}) and newer version (${newerVersion})`);
|
|
53
62
|
|
|
54
63
|
const report = await analyzeDependencyChanges(repoUrl, olderVersion, newerVersion, workingDir, null, compare.flags.ignoreDev);
|
|
@@ -81,9 +90,18 @@ const compare = command(
|
|
|
81
90
|
let baseFilename = 'report';
|
|
82
91
|
if (isGitHubActions) {
|
|
83
92
|
const eventName = process.env.GITHUB_EVENT_NAME;
|
|
84
|
-
|
|
93
|
+
let prNumber = process.env.GITHUB_PR_NUMBER;
|
|
85
94
|
const sha = process.env.GITHUB_SHA?.substring(0, 7);
|
|
86
95
|
|
|
96
|
+
// Extract PR number from GITHUB_REF_NAME if not in GITHUB_PR_NUMBER
|
|
97
|
+
if (!prNumber && process.env.GITHUB_REF_NAME) {
|
|
98
|
+
const refName = process.env.GITHUB_REF_NAME;
|
|
99
|
+
const prMatch = refName.match(/^(\d+)\/merge$/);
|
|
100
|
+
if (prMatch) {
|
|
101
|
+
prNumber = prMatch[1];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
87
105
|
if (eventName === 'pull_request' && prNumber) {
|
|
88
106
|
baseFilename = `dependency-report-PR-${prNumber}`;
|
|
89
107
|
} else if (sha) {
|
|
@@ -206,6 +224,14 @@ const auto = command(
|
|
|
206
224
|
outputDir = workingDir; // Default to working directory
|
|
207
225
|
}
|
|
208
226
|
|
|
227
|
+
// Ensure output directory exists
|
|
228
|
+
try {
|
|
229
|
+
await mkdir(outputDir, { recursive: true });
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error(`Failed to create output directory ${outputDir}: ${error.message}`);
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
|
|
209
235
|
console.log(`Auto-detecting versions for ${repoUrl}...`);
|
|
210
236
|
|
|
211
237
|
// Detect versions automatically
|
|
@@ -243,9 +269,18 @@ const auto = command(
|
|
|
243
269
|
let baseFilename = 'report';
|
|
244
270
|
if (isGitHubActions) {
|
|
245
271
|
const eventName = process.env.GITHUB_EVENT_NAME;
|
|
246
|
-
|
|
272
|
+
let prNumber = process.env.GITHUB_PR_NUMBER;
|
|
247
273
|
const sha = process.env.GITHUB_SHA?.substring(0, 7);
|
|
248
274
|
|
|
275
|
+
// Extract PR number from GITHUB_REF_NAME if not in GITHUB_PR_NUMBER
|
|
276
|
+
if (!prNumber && process.env.GITHUB_REF_NAME) {
|
|
277
|
+
const refName = process.env.GITHUB_REF_NAME;
|
|
278
|
+
const prMatch = refName.match(/^(\d+)\/merge$/);
|
|
279
|
+
if (prMatch) {
|
|
280
|
+
prNumber = prMatch[1];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
249
284
|
if (eventName === 'pull_request' && prNumber) {
|
|
250
285
|
baseFilename = `dependency-report-PR-${prNumber}`;
|
|
251
286
|
} else if (sha) {
|
package/lib/core/analyzer.mjs
CHANGED
|
@@ -589,10 +589,20 @@ export const analyzeDependencyChanges = async (repoUrl, olderVersion, newerVersi
|
|
|
589
589
|
const currentBranchName = currentBranch.trim();
|
|
590
590
|
|
|
591
591
|
if (currentBranchName !== olderVersion) {
|
|
592
|
-
|
|
592
|
+
try {
|
|
593
|
+
await executeCommand('git', ['worktree', 'remove', olderVersionDir], process.cwd(), time_1min, 'cleanup older worktree', false);
|
|
594
|
+
} catch (removeError) {
|
|
595
|
+
// If normal remove fails, try with --force
|
|
596
|
+
await executeCommand('git', ['worktree', 'remove', '--force', olderVersionDir], process.cwd(), time_1min, 'force cleanup older worktree', false);
|
|
597
|
+
}
|
|
593
598
|
}
|
|
594
599
|
if (currentBranchName !== newerVersion) {
|
|
595
|
-
|
|
600
|
+
try {
|
|
601
|
+
await executeCommand('git', ['worktree', 'remove', newerVersionDir], process.cwd(), time_1min, 'cleanup newer worktree', false);
|
|
602
|
+
} catch (removeError) {
|
|
603
|
+
// If normal remove fails, try with --force
|
|
604
|
+
await executeCommand('git', ['worktree', 'remove', '--force', newerVersionDir], process.cwd(), time_1min, 'force cleanup newer worktree', false);
|
|
605
|
+
}
|
|
596
606
|
}
|
|
597
607
|
} catch (cleanupError) {
|
|
598
608
|
console.warn(`⚠️ Failed to clean up worktrees: ${cleanupError.message}`);
|
|
@@ -614,15 +624,25 @@ export const analyzeDependencyChanges = async (repoUrl, olderVersion, newerVersi
|
|
|
614
624
|
if (currentBranchName !== olderVersion) {
|
|
615
625
|
try {
|
|
616
626
|
await executeCommand('git', ['worktree', 'remove', olderVersionDir], process.cwd(), time_1min, 'cleanup older worktree', false);
|
|
617
|
-
} catch (
|
|
618
|
-
|
|
627
|
+
} catch (removeError) {
|
|
628
|
+
try {
|
|
629
|
+
// If normal remove fails, try with --force
|
|
630
|
+
await executeCommand('git', ['worktree', 'remove', '--force', olderVersionDir], process.cwd(), time_1min, 'force cleanup older worktree', false);
|
|
631
|
+
} catch (cleanupError) {
|
|
632
|
+
// Ignore cleanup errors
|
|
633
|
+
}
|
|
619
634
|
}
|
|
620
635
|
}
|
|
621
636
|
if (currentBranchName !== newerVersion) {
|
|
622
637
|
try {
|
|
623
638
|
await executeCommand('git', ['worktree', 'remove', newerVersionDir], process.cwd(), time_1min, 'cleanup newer worktree', false);
|
|
624
|
-
} catch (
|
|
625
|
-
|
|
639
|
+
} catch (removeError) {
|
|
640
|
+
try {
|
|
641
|
+
// If normal remove fails, try with --force
|
|
642
|
+
await executeCommand('git', ['worktree', 'remove', '--force', newerVersionDir], process.cwd(), time_1min, 'force cleanup newer worktree', false);
|
|
643
|
+
} catch (cleanupError) {
|
|
644
|
+
// Ignore cleanup errors
|
|
645
|
+
}
|
|
626
646
|
}
|
|
627
647
|
}
|
|
628
648
|
} catch (cleanupError) {
|
package/lib/generate-html.mjs
CHANGED
|
@@ -21,9 +21,10 @@ const generateHtmlReport = async (jsonPath, outputPath = null) => {
|
|
|
21
21
|
|
|
22
22
|
// If no output path specified, create one with a specific naming format
|
|
23
23
|
if (!outputPath) {
|
|
24
|
+
const jsonDir = dirname(jsonPath);
|
|
24
25
|
const packageName = reportJson.repository.split('/').pop().replace('.git', '');
|
|
25
26
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
26
|
-
outputPath = `dependency-report-${packageName}-${reportJson.olderVersion}-${reportJson.newerVersion}-${timestamp}.html
|
|
27
|
+
outputPath = join(jsonDir, `dependency-report-${packageName}-${reportJson.olderVersion}-${reportJson.newerVersion}-${timestamp}.html`);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
// Generate HTML content
|