Skip to content

Commit bd5bac5

Browse files
committed
refactors
1 parent 13e673d commit bd5bac5

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

index.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {join, dirname, basename, resolve} from "node:path";
44
import {lstatSync, readFileSync, truncateSync, writeFileSync, accessSync, type Stats} from "node:fs";
55
import {stripVTControlCharacters, styleText, parseArgs, type ParseArgsOptionsConfig} from "node:util";
66
import {execFileSync} from "node:child_process";
7-
import {availableParallelism, cpus, EOL} from "node:os";
87
import pMap from "p-map";
98
import pkg from "./package.json" with {type: "json"};
109
import {parse, coerce, diff, gt, gte, lt, neq, valid, validRange} from "semver";
@@ -80,11 +79,6 @@ type FindNewVersionOpts = {
8079
semvers: Set<string>,
8180
};
8281

83-
const numCores = availableParallelism?.() ?? cpus().length ?? 4;
84-
if (versions?.uv && numCores > 4) {
85-
env.UV_THREADPOOL_SIZE = String(numCores);
86-
}
87-
8882
// regexes for url dependencies. does only github and only hash or exact semver
8983
// https://regex101.com/r/gCZzfK/2
9084
const stripRe = /^.*?:\/\/(.*?@)?(github\.com[:/])/i;
@@ -198,7 +192,7 @@ const enabledModes = parseMixedArg(args.modes) as Set<string> || new Set(["npm",
198192
const githubApiUrl = typeof args.githubapi === "string" ? normalizeUrl(args.githubapi) : "https://api.github.com";
199193
const pypiApiUrl = typeof args.pypiapi === "string" ? normalizeUrl(args.pypiapi) : "https://pypi.org";
200194

201-
const stripV = (str: string): string => str.replace(/^v/, "");
195+
const stripv = (str: string): string => str.replace(/^v/, "");
202196

203197
function matchesAny(str: string, set: Set<RegExp> | boolean): boolean {
204198
for (const re of (set instanceof Set ? set : [])) {
@@ -369,7 +363,7 @@ function getGoUpgrades(deps: DepsByMode, projectDir: string) {
369363
const stdout = execFileSync("go", [
370364
"list", "-u", "-mod=readonly", "-json", "-m", ...Object.keys(deps.go).map(key => key.split(sep)[1]),
371365
], {stdio: "pipe", encoding: "utf8", cwd: projectDir});
372-
const json = `[${stdout.replaceAll(`${EOL}}`, `${EOL}},`)}]`.replaceAll(`},${EOL}]`, `}${EOL}]`);
366+
const json = `[${stdout.replaceAll(/\r?\n\}/g, "},")}]`.replaceAll(/\},\r?\n\]/g, "}]");
373367

374368
const ret: Array<PackageInfo> = [];
375369
for (const {Main, Indirect, Version, Update, Path, Time} of JSON.parse(json) as Array<GoListInfo>) {
@@ -566,11 +560,8 @@ function textTable(rows: Array<Array<string>>, hsep = " "): string {
566560
return ret;
567561
}
568562

569-
function shortenGoName(moduleName: string): string {
570-
if (/\/v[0-9]$/.test(moduleName)) {
571-
moduleName = dirname(moduleName);
572-
}
573-
return moduleName;
563+
function shortenGoModule(module: string): string {
564+
return /\/v[0-9]$/.test(module) ? dirname(module) : module;
574565
}
575566

576567
function formatDeps(deps: DepsByMode): string {
@@ -584,7 +575,7 @@ function formatDeps(deps: DepsByMode): string {
584575
if (seen.has(id)) continue;
585576
seen.add(id);
586577
arr.push([
587-
mode === "go" ? shortenGoName(name) : name,
578+
mode === "go" ? shortenGoModule(name) : name,
588579
highlightDiff(data.old, data.new, red),
589580
highlightDiff(data.new, data.old, green),
590581
data.age || "",
@@ -822,24 +813,24 @@ async function getTags(user: string, repo: string): Promise<Array<string>> {
822813
}
823814

824815
function selectTag(tags: Array<string>, oldRef: string, useGreatest: boolean): string | null {
825-
const oldRefBare = stripV(oldRef);
816+
const oldRefBare = stripv(oldRef);
826817
if (!valid(oldRefBare)) return null;
827818

828819
if (!useGreatest) {
829820
const lastTag = tags.at(-1);
830821
if (!lastTag) return null;
831-
const lastTagBare = stripV(lastTag);
822+
const lastTagBare = stripv(lastTag);
832823
if (!valid(lastTagBare)) return null;
833824

834825
if (neq(oldRefBare, lastTagBare)) {
835826
return lastTag;
836827
}
837828
} else {
838829
let greatestTag = oldRef;
839-
let greatestTagBare = stripV(oldRef);
830+
let greatestTagBare = stripv(oldRef);
840831

841832
for (const tag of tags) {
842-
const tagBare = stripV(tag);
833+
const tagBare = stripv(tag);
843834
if (!valid(tagBare)) continue;
844835
if (!greatestTag || gt(tagBare, greatestTagBare)) {
845836
greatestTag = tag;
@@ -1266,7 +1257,7 @@ async function main(): Promise<void> {
12661257
} else if (mode === "pypi") {
12671258
deps[mode][key].info = getInfoUrl(data as any, registry, data.info.name);
12681259
} else if (mode === "go") {
1269-
deps[mode][key].info = `https://${shortenGoName(name)}`;
1260+
deps[mode][key].info = `https://${shortenGoModule(name)}`;
12701261
}
12711262

12721263
if (date) {

0 commit comments

Comments
 (0)