Skip to content

Commit

Permalink
fix: remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Nov 19, 2019
1 parent 815c65a commit 6a9f403
Showing 1 changed file with 1 addition and 61 deletions.
62 changes: 1 addition & 61 deletions src/detectors/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { PackageManagement, PracticeEvaluationResult } from '../model';
import { intersection, keys } from 'lodash';
import * as nodePath from 'path';
import { coerce, valid } from 'semver';
import { PackageVersion } from '../inspectors/IPackageInspector';
import { PracticeContext } from '../contexts/practice/PracticeContext';
import ncu from 'npm-check-updates';
import { PackageManagement } from '../model';

export const fileExtensionRegExp = (extensions: string[]): RegExp => {
const regExpString = `.*\\.(${extensions.join('|').replace('.', '\\.')})$`;
Expand Down Expand Up @@ -60,59 +56,3 @@ export const hasOneOfPackages = (packages: string[], packageManagement?: Package
}
return false;
};

export const semverToPackageVersion = (semverString: string): PackageVersion | undefined => {
const coerced = coerce(semverString);
if (coerced) {
const version = valid(coerced);
if (version) {
const splitted = version.split('.');
return {
value: semverString,
major: splitted[0],
minor: splitted[1],
patch: splitted[2],
};
}
}
return undefined;
};

export const evaluateBySemverLevel = async (ctx: PracticeContext, semverVersion: SemverVersion) => {
if (ctx.fileInspector === undefined || ctx.packageInspector === undefined) {
return PracticeEvaluationResult.unknown;
}

const pkgs = ctx.packageInspector.packages;
const fakePkgJson: { dependencies: { [key: string]: string } } = { dependencies: {} };

pkgs &&
pkgs.forEach((p) => {
fakePkgJson.dependencies[p.name] = p.requestedVersion.value;
});

const result = await ncu.run({
packageData: JSON.stringify(fakePkgJson),
});

for (const property in result) {
const parsedVersion = semverToPackageVersion(result[property]);
if (parsedVersion) {
for (const pkg of ctx.packageInspector.packages!) {
if (pkg.name === property) {
if (parsedVersion[semverVersion] > pkg.lockfileVersion[semverVersion]) {
return PracticeEvaluationResult.notPracticing;
}
}
}
}
}

return PracticeEvaluationResult.practicing;
};

export enum SemverVersion {
major = 'major',
minor = 'minor',
patch = 'patch',
}

0 comments on commit 6a9f403

Please sign in to comment.