@aklinker1/check 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3 -4
- package/dist/index.js +1 -1
- package/dist/{src-B6y5RIK9.js → src-35ZaX6Fv.js} +39 -34
- package/package.json +2 -6
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { i as ALL_TOOLS, t as check } from "./src-
|
|
2
|
-
import { isCI } from "ci-info";
|
|
1
|
+
import { a as isCi, i as ALL_TOOLS, t as check } from "./src-35ZaX6Fv.js";
|
|
3
2
|
|
|
4
3
|
//#region package.json
|
|
5
|
-
var version = "2.3.
|
|
4
|
+
var version = "2.3.1";
|
|
6
5
|
|
|
7
6
|
//#endregion
|
|
8
7
|
//#region src/cli.ts
|
|
@@ -28,7 +27,7 @@ if (boolArg("-h") || boolArg("--help")) {
|
|
|
28
27
|
process.exit(0);
|
|
29
28
|
}
|
|
30
29
|
await check({
|
|
31
|
-
fix: boolArg("-f") ?? boolArg("--fix") ?? !
|
|
30
|
+
fix: boolArg("-f") ?? boolArg("--fix") ?? !isCi,
|
|
32
31
|
debug: boolArg("-d") ?? boolArg("--debug") ?? false,
|
|
33
32
|
root: args.find((arg) => !arg.startsWith("-")) ?? "."
|
|
34
33
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { isCI } from "ci-info";
|
|
2
1
|
import { readFile } from "node:fs/promises";
|
|
3
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
4
3
|
import readline from "node:readline";
|
|
5
4
|
import { spawn } from "node:child_process";
|
|
6
5
|
|
|
7
6
|
//#region src/utils.ts
|
|
7
|
+
const env = process.env;
|
|
8
|
+
const isCi = Boolean(env.CI || env.JENKINS_URL);
|
|
9
|
+
const isDebug = env.DEBUG === "true" || env.DEBUG === "1";
|
|
8
10
|
function exec(cmd, opts) {
|
|
9
11
|
return new Promise((resolve$1, reject) => {
|
|
10
12
|
const child = spawn(cmd, {
|
|
@@ -31,12 +33,12 @@ function exec(cmd, opts) {
|
|
|
31
33
|
});
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
async function execAndParse(cmd, cwd, parser) {
|
|
35
|
-
const res = await exec(cmd, { cwd });
|
|
36
|
+
async function execAndParse(cmd, cwd$1, parser) {
|
|
37
|
+
const res = await exec(cmd, { cwd: cwd$1 });
|
|
36
38
|
if (res.exitCode == null) throw Error("Exit code was null");
|
|
37
|
-
if (isDebug
|
|
39
|
+
if (isDebug) console.debug({
|
|
38
40
|
cmd,
|
|
39
|
-
cwd,
|
|
41
|
+
cwd: cwd$1,
|
|
40
42
|
...res
|
|
41
43
|
});
|
|
42
44
|
return parser({
|
|
@@ -45,9 +47,6 @@ async function execAndParse(cmd, cwd, parser) {
|
|
|
45
47
|
stdout: res.stdout
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
function isDebug() {
|
|
49
|
-
return process.env.DEBUG === "true" || process.env.DEBUG === "1";
|
|
50
|
-
}
|
|
51
50
|
const bold = (str) => `\x1b[1m${str}\x1b[0m`;
|
|
52
51
|
const dim = (str) => `\x1b[2m${str}\x1b[0m`;
|
|
53
52
|
const red = (str) => `\x1b[31m${str}\x1b[0m`;
|
|
@@ -60,7 +59,7 @@ function humanMs(ms) {
|
|
|
60
59
|
return `${minutes > 0 ? `${minutes}m ` : ""}${seconds}s`;
|
|
61
60
|
}
|
|
62
61
|
function debug(message) {
|
|
63
|
-
if (isDebug
|
|
62
|
+
if (isDebug) console.debug(dim("⚙ " + message));
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
//#endregion
|
|
@@ -157,9 +156,11 @@ const eslint = ({ root }) => {
|
|
|
157
156
|
fix: () => execAndParse(fixCmd, root, parseOutput$6)
|
|
158
157
|
};
|
|
159
158
|
};
|
|
159
|
+
const NEWLINE_REGEX$5 = /\r?\n/;
|
|
160
|
+
const LINT_REGEX$1 = /^(?<file>.*?): line (?<line>[0-9]+), col (?<column>[0-9]+), (?<kind>\S+) - (?<message>.*?) \((?<rule>\S*?)\)$/;
|
|
160
161
|
const parseOutput$6 = ({ stdout, stderr }) => {
|
|
161
|
-
return `${stdout}\n${stderr}`.split(
|
|
162
|
-
const groups =
|
|
162
|
+
return `${stdout}\n${stderr}`.split(NEWLINE_REGEX$5).reduce((acc, line) => {
|
|
163
|
+
const groups = LINT_REGEX$1.exec(line)?.groups;
|
|
163
164
|
if (groups) acc.push({
|
|
164
165
|
file: groups.file,
|
|
165
166
|
kind: groups.kind === "Warning" ? "warning" : "error",
|
|
@@ -213,7 +214,7 @@ const oxfmt = ({ root }) => {
|
|
|
213
214
|
fix: () => execAndParse(fixCmd, root, parseOutput$4)
|
|
214
215
|
};
|
|
215
216
|
};
|
|
216
|
-
const NEWLINE_REGEX = /\r?\n/;
|
|
217
|
+
const NEWLINE_REGEX$4 = /\r?\n/;
|
|
217
218
|
const SYNTAX_ERROR_REGEX = /^\s*?[×✕]\s+(?<message>.+?)\r?\n\s+╭─\[(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]+)\]/;
|
|
218
219
|
const parseOutput$4 = ({ stdout, stderr }) => {
|
|
219
220
|
const problems = [];
|
|
@@ -226,7 +227,7 @@ const parseOutput$4 = ({ stdout, stderr }) => {
|
|
|
226
227
|
column: parseInt(groups.column, 10)
|
|
227
228
|
}
|
|
228
229
|
});
|
|
229
|
-
for (const line of stdout.trim().split(NEWLINE_REGEX)) {
|
|
230
|
+
for (const line of stdout.trim().split(NEWLINE_REGEX$4)) {
|
|
230
231
|
if (!line || line.includes(" ")) continue;
|
|
231
232
|
problems.push({
|
|
232
233
|
file: line.trim(),
|
|
@@ -249,9 +250,11 @@ const oxlint = ({ root }) => {
|
|
|
249
250
|
fix: () => execAndParse(fixCmd, root, parseOutput$3)
|
|
250
251
|
};
|
|
251
252
|
};
|
|
253
|
+
const NEWLINE_REGEX$3 = /\r?\n/;
|
|
254
|
+
const LINT_REGEX = /^(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]+):\s?(?<message>.*?)\s?\[(?<kind>Warning|Error)\/?(?<rule>.*?)\]\s?$/;
|
|
252
255
|
const parseOutput$3 = ({ stdout }) => {
|
|
253
|
-
|
|
254
|
-
const groups =
|
|
256
|
+
return stdout.split(NEWLINE_REGEX$3).reduce((acc, line) => {
|
|
257
|
+
const groups = LINT_REGEX.exec(line)?.groups;
|
|
255
258
|
if (groups) acc.push({
|
|
256
259
|
file: groups.file,
|
|
257
260
|
kind: groups.kind === "Error" ? "error" : "warning",
|
|
@@ -264,11 +267,6 @@ const parseOutput$3 = ({ stdout }) => {
|
|
|
264
267
|
});
|
|
265
268
|
return acc;
|
|
266
269
|
}, []);
|
|
267
|
-
return stdout.trim().split(/\r?\n/).map((line) => line.trim()).filter((line) => !!line && !line.includes(" ")).map((line) => ({
|
|
268
|
-
file: line.trim(),
|
|
269
|
-
kind: "warning",
|
|
270
|
-
message: "Not formatted."
|
|
271
|
-
}));
|
|
272
270
|
};
|
|
273
271
|
|
|
274
272
|
//#endregion
|
|
@@ -283,9 +281,11 @@ const prettier = ({ root }) => {
|
|
|
283
281
|
fix: () => execAndParse(fixCmd, root, parseOutput$2)
|
|
284
282
|
};
|
|
285
283
|
};
|
|
284
|
+
const NEWLINE_REGEX$2 = /\r?\n/;
|
|
285
|
+
const ERROR_REGEX$2 = /^\[(?<kind>.+?)\]\s?(?<file>.+?):\s?(?<message>.*?)\s?\((?<line>[0-9]+):(?<column>[0-9]+)\)$/;
|
|
286
286
|
const parseOutput$2 = ({ stdout, stderr }) => {
|
|
287
|
-
if (stderr.trim()) return stderr.split(
|
|
288
|
-
const groups =
|
|
287
|
+
if (stderr.trim()) return stderr.split(NEWLINE_REGEX$2).reduce((acc, line) => {
|
|
288
|
+
const groups = ERROR_REGEX$2.exec(line)?.groups;
|
|
289
289
|
if (groups) acc.push({
|
|
290
290
|
file: groups.file,
|
|
291
291
|
kind: groups.kind === "error" ? "error" : "warning",
|
|
@@ -297,7 +297,7 @@ const parseOutput$2 = ({ stdout, stderr }) => {
|
|
|
297
297
|
});
|
|
298
298
|
return acc;
|
|
299
299
|
}, []);
|
|
300
|
-
return stdout.trim().split(
|
|
300
|
+
return stdout.trim().split(NEWLINE_REGEX$2).map((line) => line.trim()).filter((line) => !!line && !line.includes(" ")).map((line) => ({
|
|
301
301
|
file: line.trim(),
|
|
302
302
|
kind: "warning",
|
|
303
303
|
message: "Not formatted."
|
|
@@ -314,14 +314,16 @@ const publint = ({ root }) => {
|
|
|
314
314
|
check: () => execAndParse(cmd, root, parseOutput$1)
|
|
315
315
|
};
|
|
316
316
|
};
|
|
317
|
+
const NEWLINE_REGEX$1 = /\r?\n/;
|
|
318
|
+
const ERROR_REGEX$1 = /^[0-9]+\.\s?(?<message>.*)$/;
|
|
317
319
|
const parseOutput$1 = ({ stdout }) => {
|
|
318
320
|
let kind = "warning";
|
|
319
|
-
return stdout.split(
|
|
321
|
+
return stdout.split(NEWLINE_REGEX$1).reduce((acc, line) => {
|
|
320
322
|
if (line.includes("Errors:")) {
|
|
321
323
|
kind = "error";
|
|
322
324
|
return acc;
|
|
323
325
|
}
|
|
324
|
-
const groups =
|
|
326
|
+
const groups = ERROR_REGEX$1.exec(line)?.groups;
|
|
325
327
|
if (groups == null) return acc;
|
|
326
328
|
acc.push({
|
|
327
329
|
kind,
|
|
@@ -361,9 +363,11 @@ const typescript = async ({ root, packageJson }) => {
|
|
|
361
363
|
check: async () => execAndParse(mod.cmd, root, parseOutput)
|
|
362
364
|
};
|
|
363
365
|
};
|
|
366
|
+
const NEWLINE_REGEX = /\r?\n/;
|
|
367
|
+
const ERROR_REGEX = /^(?<file>\S+?)\((?<line>[0-9]+),(?<column>[0-9]+)\): \w+? (?<rule>TS[0-9]+): (?<message>.*)$/;
|
|
364
368
|
const parseOutput = ({ stdout }) => {
|
|
365
|
-
return stdout.split(
|
|
366
|
-
const groups =
|
|
369
|
+
return stdout.split(NEWLINE_REGEX).reduce((acc, line) => {
|
|
370
|
+
const groups = ERROR_REGEX.exec(line)?.groups;
|
|
367
371
|
if (groups) acc.push({
|
|
368
372
|
file: groups.file,
|
|
369
373
|
kind: "error",
|
|
@@ -392,8 +396,9 @@ const ALL_TOOLS = [
|
|
|
392
396
|
|
|
393
397
|
//#endregion
|
|
394
398
|
//#region src/index.ts
|
|
399
|
+
const cwd = process.cwd();
|
|
395
400
|
async function check(options = {}) {
|
|
396
|
-
const { debug: debug$1, fix = !
|
|
401
|
+
const { debug: debug$1, fix = !isCi, root = cwd } = options;
|
|
397
402
|
const packageJson = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
398
403
|
if (debug$1) process.env.DEBUG = "true";
|
|
399
404
|
console.log();
|
|
@@ -409,7 +414,7 @@ async function check(options = {}) {
|
|
|
409
414
|
packageJson
|
|
410
415
|
});
|
|
411
416
|
if (tools.length === 0) {
|
|
412
|
-
if (isDebug
|
|
417
|
+
if (isDebug) console.log("No tools detected!");
|
|
413
418
|
else console.log("No tools detected! Run with --debug for more info");
|
|
414
419
|
console.log();
|
|
415
420
|
process.exit(1);
|
|
@@ -418,7 +423,7 @@ async function check(options = {}) {
|
|
|
418
423
|
const startTime = performance.now();
|
|
419
424
|
const problems$1 = await (fix ? tool.fix ?? tool.check : tool.check)();
|
|
420
425
|
problems$1.forEach((problem) => {
|
|
421
|
-
problem.file = resolve(root
|
|
426
|
+
problem.file = resolve(root, problem.file);
|
|
422
427
|
});
|
|
423
428
|
const duration = humanMs(performance.now() - startTime);
|
|
424
429
|
const title = `${tool.name} ${dim(`(${duration})`)}`;
|
|
@@ -446,7 +451,7 @@ async function check(options = {}) {
|
|
|
446
451
|
}, /* @__PURE__ */ new Map());
|
|
447
452
|
console.log([...groupedProblems.values()].map(renderProblemGroup).join("\n"));
|
|
448
453
|
const files = Object.entries(problems.reduce((acc, problem) => {
|
|
449
|
-
const file = "." + sep + relative(
|
|
454
|
+
const file = "." + sep + relative(root, problem.file);
|
|
450
455
|
acc[file] ??= 0;
|
|
451
456
|
acc[file]++;
|
|
452
457
|
return acc;
|
|
@@ -468,7 +473,7 @@ async function findInstalledTools(opts) {
|
|
|
468
473
|
isInstalled: !!opts.packageJson.devDependencies?.[tool.packageName]
|
|
469
474
|
};
|
|
470
475
|
}));
|
|
471
|
-
if (isDebug
|
|
476
|
+
if (isDebug) {
|
|
472
477
|
const getTools = (isInstalled) => status.filter((item) => item.isInstalled === isInstalled).map((item) => item.tool.name).join(", ");
|
|
473
478
|
debug(`Installed: ${getTools(true) || "(none)"}`);
|
|
474
479
|
debug(`Skipping: ${getTools(false) || "(none)"} `);
|
|
@@ -481,7 +486,7 @@ function plural(count, singular, plural$1) {
|
|
|
481
486
|
function renderProblemGroup(problems) {
|
|
482
487
|
const renderedProblems = problems.map(renderProblem);
|
|
483
488
|
const problem = problems[0];
|
|
484
|
-
const path = relative(
|
|
489
|
+
const path = relative(cwd, problem.file);
|
|
485
490
|
const link = dim(`→ .${sep}${problem.location ? `${path}:${problem.location.line}:${problem.location.column}` : path}`);
|
|
486
491
|
return `${renderedProblems.join("\n")}\n ${link}`;
|
|
487
492
|
}
|
|
@@ -492,4 +497,4 @@ function renderProblem(problem) {
|
|
|
492
497
|
}
|
|
493
498
|
|
|
494
499
|
//#endregion
|
|
495
|
-
export { ALL_TOOLS as i, renderProblem as n, renderProblemGroup as r, check as t };
|
|
500
|
+
export { isCi as a, ALL_TOOLS as i, renderProblem as n, renderProblemGroup as r, check as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aklinker1/check",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"check",
|
|
6
6
|
"eslint",
|
|
@@ -39,11 +39,7 @@
|
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsdown src/index.ts src/cli.ts",
|
|
41
41
|
"check": "bun src/cli.ts",
|
|
42
|
-
"prepack": "bun run build"
|
|
43
|
-
"prepublish": "bun run build"
|
|
44
|
-
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"ci-info": "*"
|
|
42
|
+
"prepack": "bun run build"
|
|
47
43
|
},
|
|
48
44
|
"devDependencies": {
|
|
49
45
|
"@types/bun": "latest",
|