Skip to content

Commit 7aef2ba

Browse files
committed
chore: bump to node@23 + remove ts-specific instructions
1 parent 0042b30 commit 7aef2ba

File tree

15 files changed

+150
-169
lines changed

15 files changed

+150
-169
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18
1+
v23

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"name": "Simon Renoult",
77
"email": "contact@simonrenoult.me"
88
},
9+
"engines": {
10+
"node": "23"
11+
},
912
"main": "dist/src/lib",
1013
"types": "dist/src/lib/types.d.ts",
1114
"bin": {
@@ -55,7 +58,6 @@
5558
"@types/debug": "^4.1.7",
5659
"@types/micromatch": "^4.0.2",
5760
"@types/mocha": "^10.0.0",
58-
"@types/node": "^18.11.9",
5961
"@typescript-eslint/eslint-plugin": "^5.42.1",
6062
"@typescript-eslint/parser": "^5.42.1",
6163
"chai": "^4.3.7",

src/io/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { existsSync } from "node:fs";
33

44
import Cli from "./cli";
55
import { Options } from "../lib/types";
6-
import Output from "./output";
6+
import * as Output from "./output";
77
import Statistics from "../lib";
88

99
export default async function main(): Promise<void> {

src/io/output.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@ import * as Table from "cli-table3";
22
import { IStatistic } from "../lib/statistics/statistic";
33
import { Options } from "../lib/types";
44

5-
import { buildDebugger, withDuration } from "../utils";
6-
7-
const internal = { debug: buildDebugger("output") };
8-
9-
export default {
10-
render: (...args: any[]): void => withDuration(render, args, internal.debug),
11-
};
12-
13-
function render(statistics: IStatistic[], options: Options): void {
5+
export function render(statistics: IStatistic[], options: Options): void {
146
let stdout;
157
switch (options.format) {
168
case "table":

src/lib/churn/churn.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import { Path } from "../types";
2-
31
export default class Churn {
4-
private path: Path;
5-
private changes: number;
2+
#changes: number;
63

7-
constructor(path: Path) {
8-
this.path = path;
9-
this.changes = 0;
4+
constructor() {
5+
this.#changes = 0;
106
}
117

12-
public increment(): this {
13-
this.changes += 1;
8+
increment(): this {
9+
this.#changes += 1;
1410
return this;
1511
}
1612

17-
public getValue(): number {
18-
return this.changes;
13+
getValue(): number {
14+
return this.#changes;
1915
}
2016
}

src/lib/churn/churns.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
import { History } from "../githistory/githistory";
22

3-
import { Options, Path } from "../types";
3+
import { Path } from "../types";
44
import Churn from "./churn";
55

6-
// FIXME: add commits
7-
86
export default class Churns {
9-
private readonly churnByPath: Map<Path, Churn>;
10-
private readonly options: Options;
11-
12-
public static from(history: History, options: Options) {
13-
return new Churns(history, options);
14-
}
7+
#churnByPath: Map<Path, Churn>;
158

16-
private constructor(history: History, options: Options) {
17-
this.options = options;
18-
this.churnByPath = this.computeChurnsPerFiles(history);
9+
static from(history: History) {
10+
return new Churns(history);
1911
}
2012

21-
public get files(): Path[] {
22-
return [...this.churnByPath.keys()];
13+
constructor(history: History) {
14+
this.#churnByPath = this.#computeChurnsPerFiles(history);
2315
}
2416

25-
public getByPath(path: Path): Churn {
26-
const churn = this.churnByPath.get(path);
17+
getByPath(path: Path): Churn {
18+
const churn = this.#churnByPath.get(path);
2719
if (!churn) {
2820
throw new Error("churn not found for path: " + path);
2921
}
3022
return churn;
3123
}
3224

33-
private computeChurnsPerFiles(history: History): Map<Path, Churn> {
25+
#computeChurnsPerFiles(history: History): Map<Path, Churn> {
3426
return history.reduce((map: Map<Path, Churn>, path) => {
3527
if (map.has(path)) {
3628
const actualChurn = map.get(path);
@@ -40,7 +32,7 @@ export default class Churns {
4032
throw new Error("A churn should have existed for path: " + path);
4133
}
4234
} else {
43-
const churn = new Churn(path).increment();
35+
const churn = new Churn().increment();
4436
map.set(path, churn);
4537
}
4638
return map;

src/lib/complexity/complexities.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import Complexity from "./complexity";
55
const internal = { debug: buildDebugger("complexity") };
66

77
export default class Complexities {
8-
private readonly complexityByPath: Map<Path, Complexity>;
8+
#complexityByPath: Map<Path, Complexity>;
99

10-
public static async computeFor(
10+
static async computeFor(
1111
paths: Path[],
1212
options: Options
1313
): Promise<Complexities> {
@@ -19,17 +19,17 @@ export default class Complexities {
1919
return new Complexities(complexities);
2020
}
2121

22-
public getByPath(path: Path): Complexity {
23-
const complexity = this.complexityByPath.get(path);
24-
if (!complexity) throw new Error("Complexity not found for path: " + path);
25-
return complexity;
22+
constructor(complexities: Complexity[]) {
23+
this.#complexityByPath = this.#computeComplexitiesPerPath(complexities);
2624
}
2725

28-
private constructor(complexities: Complexity[]) {
29-
this.complexityByPath = this.computeComplexitiesPerPath(complexities);
26+
getByPath(path: Path): Complexity {
27+
const complexity = this.#complexityByPath.get(path);
28+
if (!complexity) throw new Error("Complexity not found for #path: " + path);
29+
return complexity;
3030
}
3131

32-
private computeComplexitiesPerPath(complexities: Complexity[]) {
32+
#computeComplexitiesPerPath(complexities: Complexity[]) {
3333
return complexities.reduce((map, complexity) => {
3434
map.set(complexity.path, complexity);
3535
return map;

src/lib/complexity/complexity.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
import { resolve } from "node:path";
12
import { Options, Path } from "../types";
23
import computeSloc from "./strategies/sloc";
34
import { calculate as calculateCyclomatic } from "./strategies/cyclomatic";
45
import { calculate as calculateHalstead } from "./strategies/halstead";
5-
import { resolve } from "node:path";
66
import { UnsupportedExtension } from "../../utils";
77

8-
// FIXME: add modules
9-
108
export default class Complexity {
11-
public static async compute(path: Path, options: Options) {
12-
const complexity = await Complexity.computeComplexity(path, options);
9+
path: Path;
10+
complexity: number;
11+
12+
static async compute(path: Path, options: Options) {
13+
const complexity = await Complexity.#computeComplexity(path, options);
1314
return new Complexity(path, complexity);
1415
}
1516

16-
private constructor(
17-
public readonly path: Path,
18-
public readonly complexity: number
19-
) {}
17+
constructor(path: Path, complexity: number) {
18+
this.complexity = complexity;
19+
this.path = path;
20+
}
2021

21-
private static async computeComplexity(
22+
static async #computeComplexity(
2223
path: Path,
2324
options: Options
2425
): Promise<number> {

src/lib/githistory/githistory.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
import * as micromatch from "micromatch";
21
import { execSync } from "node:child_process";
32
import { existsSync } from "node:fs";
43
import { resolve } from "node:path";
4+
import * as micromatch from "micromatch";
55

66
import { Options, Path } from "../types";
77

88
export type History = Path[];
99

1010
export default class GitHistory {
11-
private options: Options;
12-
13-
public readonly history: History;
14-
public readonly files: Path[];
15-
16-
public static build(options: Options) {
17-
return new GitHistory(options);
18-
}
11+
#options: Options;
12+
history: History;
13+
files: Path[];
1914

20-
private constructor(options: Options) {
21-
this.options = options;
15+
constructor(options: Options) {
16+
this.#options = options;
2217

23-
this.history = this.buildHistory();
24-
this.files = this.listFiles();
18+
this.history = this.#buildHistory();
19+
this.files = this.#listFiles();
2520
}
2621

27-
private buildGitLogCommand(): string {
22+
#buildGitLogCommand(): string {
2823
const isWindows = process.platform === "win32";
2924

3025
return [
3126
"git",
32-
`-C ${this.options.directory}`,
27+
`-C ${this.#options.directory}`,
3328
`log`,
3429
`--follow`,
3530

3631
// Windows CMD handle quotes differently than linux, this is why we should put empty string as said in:
3732
// https://github.com/git-for-windows/git/issues/3131
3833
`--format=${isWindows ? "" : "''"}`,
3934
`--name-only`,
40-
this.options.since ? `--since="${this.options.since}"` : "",
41-
this.options.until ? `--until="${this.options.until}"` : "",
35+
this.#options.since ? `--since="${this.#options.since}"` : "",
36+
this.#options.until ? `--until="${this.#options.until}"` : "",
4237

4338
// Windows CMD handle quotes differently
4439
isWindows ? "*" : "'*'",
@@ -47,42 +42,42 @@ export default class GitHistory {
4742
.join(" ");
4843
}
4944

50-
private buildHistory(): Path[] {
51-
const gitLogCommand = this.buildGitLogCommand();
52-
const stdout = this.executeGitLogCommand(gitLogCommand);
45+
#buildHistory(): Path[] {
46+
const gitLogCommand = this.#buildGitLogCommand();
47+
const stdout = this.#executeGitLogCommand(gitLogCommand);
5348
return stdout
5449
.split("\n")
5550
.filter((line) => {
5651
if (line.trim().length === 0) {
5752
return false;
5853
}
59-
if (!this.pathStillExists(line)) {
54+
if (!this.#pathStillExists(line)) {
6055
return false;
6156
}
62-
if (!this.filterMatches(line)) {
57+
if (!this.#filterMatches(line)) {
6358
return false;
6459
}
6560
return true;
6661
})
6762
.sort();
6863
}
6964

70-
private executeGitLogCommand(gitLogCommand: string): string {
71-
const maxBuffer = this.options.maxBuffer ?? 32_000_000;
65+
#executeGitLogCommand(gitLogCommand: string): string {
66+
const maxBuffer = this.#options.maxBuffer ?? 32_000_000;
7267
return execSync(gitLogCommand, { encoding: "utf8", maxBuffer });
7368
}
7469

75-
private listFiles(): string[] {
70+
#listFiles(): string[] {
7671
return [...new Set(this.history)];
7772
}
7873

79-
private pathStillExists(fileName: string) {
80-
return existsSync(resolve(this.options.directory, fileName));
74+
#pathStillExists(fileName: string) {
75+
return existsSync(resolve(this.#options.directory, fileName));
8176
}
8277

83-
private filterMatches(file: string) {
84-
if (this.options.filter && this.options.filter.length) {
85-
return this.options.filter.every((f) => micromatch.isMatch(file, f));
78+
#filterMatches(file: string) {
79+
if (this.#options.filter && this.#options.filter.length) {
80+
return this.#options.filter.every((f) => micromatch.isMatch(file, f));
8681
}
8782
return true;
8883
}

src/lib/statistics/statistic.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,21 @@ export interface IStatistic {
1010
}
1111

1212
export default class Statistic {
13-
public readonly path: Path;
14-
public readonly churn: number;
15-
public readonly complexity: number;
16-
public readonly score: number;
17-
18-
readonly directories: string[];
19-
20-
static build(path: Path, churn: number, complexity: number): Statistic {
21-
return new Statistic(path, churn, complexity);
22-
}
13+
path: Path;
14+
churn: number;
15+
complexity: number;
16+
score: number;
17+
directories: string[];
2318

24-
private constructor(path: Path, churn: number, complexity: number) {
19+
constructor(path: Path, churn: number, complexity: number) {
2520
this.path = path;
2621
this.churn = churn;
2722
this.complexity = complexity;
28-
this.directories = this.findDirectoriesForFile(path);
23+
this.directories = this.#findDirectoriesForFile(path);
2924
this.score = this.churn * this.complexity;
3025
}
3126

32-
private findDirectoriesForFile(path: string): string[] {
27+
#findDirectoriesForFile(path: string): string[] {
3328
const directories: string[] = [];
3429
const pathChunks = NodePath.parse(path).dir.split(NodePath.sep);
3530
pathChunks.forEach((chunk) => {
@@ -42,7 +37,7 @@ export default class Statistic {
4237
return directories.filter((d) => d.length > 0);
4338
}
4439

45-
public toState(): IStatistic {
40+
toState(): IStatistic {
4641
return {
4742
path: this.path,
4843
churn: this.churn,

0 commit comments

Comments
 (0)