Skip to content

Commit e3b453f

Browse files
further refactors
1 parent 7617d5f commit e3b453f

File tree

11 files changed

+98
-159
lines changed

11 files changed

+98
-159
lines changed

src/core/dependency-checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { PatchPulseConfig, shouldSkipPackage } from '../services/config';
44
import { getLatestVersion } from '../services/npm';
55
import { type DependencyInfo } from '../types';
66
import { ProgressSpinner } from '../ui/progress';
7-
import { getUpdateType, isVersionOutdated } from '../ui/version';
7+
import { getUpdateType } from '../utils/getUpdateType';
8+
import { isVersionOutdated } from '../utils/isVersionOutdated';
89

910
export async function checkDependencyVersions(
1011
dependencies: Record<string, string> | undefined,
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/ui/tests/summary.test.ts renamed to src/ui/display/__tests__/summary.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2-
import { type DependencyInfo } from '../../types';
3-
import { displaySummary } from '../display/summary';
2+
import { type DependencyInfo } from '../../../types';
3+
import { displaySummary } from '../summary';
44

55
describe('displaySummary', () => {
66
let consoleSpy: ReturnType<typeof vi.spyOn>;

src/ui/tests/display.test.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/ui/version.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/utils/getUpdateType.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import chalk from 'chalk';
2+
import { parseVersion } from './parseVersion';
3+
4+
/**
5+
* Determines the type of update required based on the current and latest versions
6+
* @param current - The current version string
7+
* @param latest - The latest version string
8+
* @returns The type of update required ('patch', 'minor', or 'major')
9+
*/
10+
export function getUpdateType(
11+
current: string,
12+
latest: string
13+
): 'patch' | 'minor' | 'major' {
14+
try {
15+
const currentVersion = parseVersion(current);
16+
const latestVersion = parseVersion(latest);
17+
18+
if (latestVersion.major > currentVersion.major) {
19+
return 'major';
20+
}
21+
if (latestVersion.minor > currentVersion.minor) {
22+
return 'minor';
23+
}
24+
if (latestVersion.patch > currentVersion.patch) {
25+
return 'patch';
26+
}
27+
return 'patch';
28+
} catch (error) {
29+
// Handle invalid version formats gracefully
30+
console.warn(chalk.yellow(`⚠️ Invalid version format: ${error}`));
31+
return 'patch'; // Default fallback
32+
}
33+
}

src/utils/isVersionOutdated.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import chalk from 'chalk';
2+
import { parseVersion } from './parseVersion';
3+
4+
/**
5+
* Checks if the current version is outdated compared to the latest version
6+
* @param current - The current version string
7+
* @param latest - The latest version string
8+
* @returns True if the current version is outdated, false otherwise
9+
*/
10+
export function isVersionOutdated(current: string, latest: string): boolean {
11+
try {
12+
const currentVersion = parseVersion(current);
13+
const latestVersion = parseVersion(latest);
14+
15+
// Compare major versions first
16+
if (latestVersion.major > currentVersion.major) {
17+
return true;
18+
}
19+
if (latestVersion.major < currentVersion.major) {
20+
return false;
21+
}
22+
23+
// If major versions are equal, compare minor versions
24+
if (latestVersion.minor > currentVersion.minor) {
25+
return true;
26+
}
27+
if (latestVersion.minor < currentVersion.minor) {
28+
return false;
29+
}
30+
31+
// If minor versions are equal, compare patch versions
32+
return latestVersion.patch > currentVersion.patch;
33+
} catch (error) {
34+
// Handle invalid version formats gracefully
35+
console.warn(chalk.yellow(`⚠️ Invalid version format: ${error}`));
36+
return false; // Default to not outdated if we can't parse
37+
}
38+
}

0 commit comments

Comments
 (0)