Skip to content

Commit

Permalink
fix: types typo
Browse files Browse the repository at this point in the history
  • Loading branch information
narol1024 committed Jun 3, 2024
1 parent e1f0fea commit b1ef1f3
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The results are similar to the following:
"name": "react",
"in": 195657,
"out": 1,
"instable": 0.000005110958918112216,
"instability": 0.000005110958918112216,
"label": "Stable"
}
]
Expand Down
12 changes: 6 additions & 6 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Array [
Object {
"fanIn": 10000,
"fanOut": 1,
"instability": 0.00009999000099990002,
"label": "Stable",
"name": "react",
"stability": 0.00009999000099990002,
},
]
`;
Expand All @@ -17,35 +17,35 @@ Array [
Object {
"fanIn": 1,
"fanOut": 0,
"instable": 0,
"instability": 0,
"label": "Stable",
"name": "a",
},
Object {
"fanIn": 1,
"fanOut": 1,
"instable": 0.5,
"instability": 0.5,
"label": "Normal",
"name": "b",
},
Object {
"fanIn": 1,
"fanOut": 2,
"instable": 0.6666666666666666,
"instability": 0.6666666666666666,
"label": "Flexible",
"name": "c",
},
Object {
"fanIn": 1,
"fanOut": 3,
"instable": 0.75,
"instability": 0.75,
"label": "Flexible",
"name": "d",
},
Object {
"fanIn": 1,
"fanOut": 4,
"instable": 0.8,
"instability": 0.8,
"label": "Instable",
"name": "e",
},
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('CLI tool Tests', () => {
name: 'react',
fanIn: 10000,
fanOut: 1,
stability: 0.00009999000099990002,
instability: 0.00009999000099990002,
label: 'Stable',
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { analyze } from '../index';
const program = new Command();

async function bootstrap(argv = process.argv) {
program.name('sdp-analyzer').description('A cli tool for analyzing package stability').version(VERSION);
program.name('sdp-analyzer').description('A cli tool for analyzing package instability').version(VERSION);
program
.command('analyze')
.argument('<string>', 'the local package path or a npm package name')
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SDP expressions:
// Stability = Fan-out / (Fan-in + Fan-out)
// Instability = Fan-out / (Fan-in + Fan-out)
export function evaluate(fanOut: number, fanIn: number) {
if (fanOut === 0 && fanIn === 0) {
return 0;
Expand Down
12 changes: 6 additions & 6 deletions src/platforms/npm-package/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Array [
Object {
"fanIn": 10000,
"fanOut": 0,
"instability": 0,
"label": "Stable",
"name": "lodash",
"stability": 0,
},
]
`;
Expand All @@ -17,16 +17,16 @@ Array [
Object {
"fanIn": 10000,
"fanOut": 1,
"instability": 0.00009999000099990002,
"label": "Stable",
"name": "react",
"stability": 0.00009999000099990002,
},
Object {
"fanIn": 10000,
"fanOut": 5,
"instability": 0.0004997501249375312,
"label": "Stable",
"name": "vue",
"stability": 0.0004997501249375312,
},
]
`;
Expand All @@ -36,16 +36,16 @@ Array [
Object {
"fanIn": 10000,
"fanOut": 1,
"instability": 0.00009999000099990002,
"label": "Stable",
"name": "react",
"stability": 0.00009999000099990002,
},
Object {
"fanIn": 10000,
"fanOut": 5,
"instability": 0.0004997501249375312,
"label": "Stable",
"name": "vue",
"stability": 0.0004997501249375312,
},
]
`;
Expand All @@ -55,9 +55,9 @@ Array [
Object {
"fanIn": 10000,
"fanOut": 1,
"instability": 0.00009999000099990002,
"label": "Stable",
"name": "react",
"stability": 0.00009999000099990002,
},
]
`;
10 changes: 5 additions & 5 deletions src/platforms/npm-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { exec } from 'child_process';
import nodeFetch from 'node-fetch';
import { promisify } from 'util';
import { load as cheerioLoad } from 'cheerio';
import type { Dep, NpmDependency } from '../../types';
import type { SDPResults, NpmDependency } from '../../types';
import { evaluate } from '../../core';
import { getStablityLabel } from '../../utils/label';

Expand Down Expand Up @@ -101,7 +101,7 @@ export async function countNpmPackageDependants(packageName: string, version: st
}

// To analyze one or multiple packages on the npm repository, like react, vue, express, etc.
export async function analyze(packageNames: string): Promise<Dep[]> {
export async function analyze(packageNames: string): Promise<SDPResults[]> {
try {
const normalizedPackageNames = packageNames.split(',');
const depsPromises = normalizedPackageNames.map(async packageName => {
Expand All @@ -114,13 +114,13 @@ export async function analyze(packageNames: string): Promise<Dep[]> {
countNpmPackageDependants(packageName, version),
]);
const fanOut = dependencies.length;
const stability = fanOut === 0 ? 0 : evaluate(fanOut, dependants);
const instability = fanOut === 0 ? 0 : evaluate(fanOut, dependants);
return {
name: packageName,
fanIn: dependants,
fanOut,
stability,
label: getStablityLabel(stability),
instability,
label: getStablityLabel(instability),
};
});

Expand Down
10 changes: 5 additions & 5 deletions src/platforms/workspaces/yarn/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ Array [
Object {
"fanIn": 1,
"fanOut": 0,
"instable": 0,
"instability": 0,
"label": "Stable",
"name": "a",
},
Object {
"fanIn": 1,
"fanOut": 1,
"instable": 0.5,
"instability": 0.5,
"label": "Normal",
"name": "b",
},
Object {
"fanIn": 1,
"fanOut": 2,
"instable": 0.6666666666666666,
"instability": 0.6666666666666666,
"label": "Flexible",
"name": "c",
},
Object {
"fanIn": 1,
"fanOut": 3,
"instable": 0.75,
"instability": 0.75,
"label": "Flexible",
"name": "d",
},
Object {
"fanIn": 1,
"fanOut": 4,
"instable": 0.8,
"instability": 0.8,
"label": "Instable",
"name": "e",
},
Expand Down
9 changes: 5 additions & 4 deletions src/platforms/workspaces/yarn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fg from 'fast-glob';
import jsonfile from 'jsonfile';
import { evaluate } from '../../../core';
import { getStablityLabel } from '../../../utils/label';
import { SDPResults } from '../../../types';

// To read the dependencies of a package using workspaces.
export function readWorkspacesDependencies(packagePath: string) {
Expand Down Expand Up @@ -34,7 +35,7 @@ export function readWorkspacesDependencies(packagePath: string) {
}

// To analyze workspaces using Yarn package manager, such as ./my-yarn-workspaces-project
export async function analyze(packagePath: string) {
export async function analyze(packagePath: string): Promise<SDPResults[]> {
try {
const dependencyMap = readWorkspacesDependencies(packagePath);
if (dependencyMap.length === 0) {
Expand All @@ -53,11 +54,11 @@ export async function analyze(packagePath: string) {
});
return Promise.resolve(
deps.map(dep => {
const stablility = evaluate(dep.fanOut, dep.fanIn);
const instability = evaluate(dep.fanOut, dep.fanIn);
return {
...dep,
instable: stablility,
label: getStablityLabel(stablility),
instability,
label: getStablityLabel(instability),
};
}),
);
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface Dep {
export interface SDPResults {
name: string;
fanIn: number;
fanOut: number;
stability: number;
instability: number;
label: string;
}
export interface NpmDependency {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/label.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// The label is determined based on the value of stability
export function getStablityLabel(stablility: number) {
if (stablility < 0.2) {
// The label is determined based on the value of instability
export function getStablityLabel(instability: number) {
if (instability < 0.2) {
return 'Stable';
} else if (stablility < 0.6) {
} else if (instability < 0.6) {
return 'Normal';
} else if (stablility < 0.8) {
} else if (instability < 0.8) {
return 'Flexible';
} else {
return 'Instable';
Expand Down

0 comments on commit b1ef1f3

Please sign in to comment.