Skip to content

Commit

Permalink
fix(plugin-js-packages): skip package labels until semver is integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlacenka committed Apr 25, 2024
1 parent 4b2a2df commit aa90d68
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
14 changes: 10 additions & 4 deletions packages/plugin-js-packages/src/lib/runner/outdated/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ export function outdatedResultToAuditOutput(
const relevantDependencies: OutdatedResult = result.filter(
dep => dep.type === dependencyGroupToLong[depGroup],
);
const outdatedDependencies = relevantDependencies.filter(
dep => dep.current !== dep.latest,
);
// TODO use semver logic to compare versions
const outdatedDependencies = relevantDependencies
.filter(dep => dep.current !== dep.latest)
.filter(
dep =>
dep.current.split('-')[0]?.toString() !==
dep.latest.split('-')[0]?.toString(),
);

const outdatedStats = outdatedDependencies.reduce(
(acc, dep) => {
Expand Down Expand Up @@ -114,7 +119,8 @@ export function getOutdatedLevel(
}

export function splitPackageVersion(fullVersion: string): PackageVersion {
const [major, minor, patch] = fullVersion.split('.').map(Number);
const semanticVersion = String(fullVersion.split('-')[0]);
const [major, minor, patch] = semanticVersion.split('.').map(Number);

if (major == null || minor == null || patch == null) {
throw new Error(`Invalid version description ${fullVersion}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('outdatedResultToAuditOutput', () => {
{
name: 'nx',
current: '15.8.1',
latest: '17.0.0',
latest: '17.0.0-stable',
type: 'dependencies',
},
{
Expand Down Expand Up @@ -169,6 +169,34 @@ describe('outdatedResultToAuditOutput', () => {
displayValue: 'all dependencies are up to date',
});
});

it('should skip identical semantic versions with different label', () => {
expect(
outdatedResultToAuditOutput(
[
{
name: 'cypress',
current: '13.7.0-alpha',
latest: '13.7.0-beta',
type: 'devDependencies',
},
{
name: 'nx',
current: '17.0.0-12',
latest: '17.0.0-15',
type: 'devDependencies',
},
],
'npm',
'dev',
),
).toEqual<AuditOutput>({
slug: 'npm-outdated-dev',
score: 1,
value: 0,
displayValue: 'all dependencies are up to date',
});
});
});

describe('calculateOutdatedScore', () => {
Expand Down

0 comments on commit aa90d68

Please sign in to comment.