@aklinker1/check 1.2.0 → 1.3.0
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.mjs +5 -0
- package/dist/index.mjs +13 -10
- package/dist/tools/eslint.d.ts +2 -2
- package/dist/tools/eslint.mjs +19 -15
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/prettier.d.ts +2 -2
- package/dist/tools/prettier.mjs +11 -8
- package/dist/tools/publint.d.ts +2 -2
- package/dist/tools/publint.mjs +10 -5
- package/dist/tools/typescript.d.ts +2 -2
- package/dist/tools/typescript.mjs +16 -12
- package/dist/types.d.ts +8 -3
- package/dist/utils.d.ts +2 -2
- package/dist/utils.mjs +8 -13
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -5,12 +5,17 @@ import { createTaskList } from "./tasklist/index.mjs";
|
|
|
5
5
|
import { relative, resolve, sep } from "node:path";
|
|
6
6
|
import { isCI } from "ci-info";
|
|
7
7
|
export async function check(options = {}) {
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
debug: debug2,
|
|
10
|
+
fix = !isCI,
|
|
11
|
+
root = process.cwd(),
|
|
12
|
+
binDir = "node_modules/.bin"
|
|
13
|
+
} = options;
|
|
9
14
|
if (debug2) {
|
|
10
15
|
process.env.DEBUG = "true";
|
|
11
16
|
}
|
|
12
17
|
console.log();
|
|
13
|
-
const tools = await findInstalledTools(root);
|
|
18
|
+
const tools = await findInstalledTools({ root, binDir });
|
|
14
19
|
if (tools.length === 0) {
|
|
15
20
|
console.log("No tools detected! Run with --debug for more info");
|
|
16
21
|
console.log();
|
|
@@ -21,7 +26,7 @@ export async function check(options = {}) {
|
|
|
21
26
|
async ({ input: tool, fail, succeed, warn }) => {
|
|
22
27
|
const startTime = performance.now();
|
|
23
28
|
const fn = fix ? tool.fix ?? tool.check : tool.check;
|
|
24
|
-
const problems2 = await fn(
|
|
29
|
+
const problems2 = await fn();
|
|
25
30
|
problems2.forEach((problem) => {
|
|
26
31
|
problem.file = resolve(root ?? process.cwd(), problem.file);
|
|
27
32
|
});
|
|
@@ -80,13 +85,11 @@ export async function check(options = {}) {
|
|
|
80
85
|
console.log();
|
|
81
86
|
process.exit(problems.length);
|
|
82
87
|
}
|
|
83
|
-
async function findInstalledTools(
|
|
84
|
-
const status = await p(ALL_TOOLS).map(async (
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
isInstalled: await t.isInstalled(root)
|
|
89
|
-
};
|
|
88
|
+
async function findInstalledTools(opts) {
|
|
89
|
+
const status = await p(ALL_TOOLS).map(async (def) => {
|
|
90
|
+
const tool = await def(opts);
|
|
91
|
+
const isInstalled = await tool.isInstalled();
|
|
92
|
+
return { tool, isInstalled };
|
|
90
93
|
}).promise;
|
|
91
94
|
if (isDebug()) {
|
|
92
95
|
const getTools = (isInstalled) => status.filter((item) => item.isInstalled === isInstalled).map((item) => item.tool.name).join(", ");
|
package/dist/tools/eslint.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { OutputParser,
|
|
2
|
-
export declare const eslint:
|
|
1
|
+
import type { OutputParser, ToolDefinition } from "../types";
|
|
2
|
+
export declare const eslint: ToolDefinition;
|
|
3
3
|
export declare const parseOuptut: OutputParser;
|
package/dist/tools/eslint.mjs
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { isBinInstalled, execAndParse } from "../utils.mjs";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
export const eslint = ({ binDir, root }) => {
|
|
4
|
+
const bin = resolve(root, binDir, "eslint");
|
|
5
|
+
const checkArgs = [
|
|
6
|
+
".",
|
|
7
|
+
"--ext",
|
|
8
|
+
".js,.ts,.jsx,.tsx,.mjs,.mts,.cjs,.cts,.vue",
|
|
9
|
+
"--format",
|
|
10
|
+
"compact",
|
|
11
|
+
"--max-warnings",
|
|
12
|
+
"0"
|
|
13
|
+
];
|
|
14
|
+
const fixArgs = [...checkArgs, "--fix"];
|
|
15
|
+
return {
|
|
16
|
+
name: "ESLint",
|
|
17
|
+
isInstalled: () => isBinInstalled(bin),
|
|
18
|
+
check: () => execAndParse(bin, checkArgs, root, parseOuptut),
|
|
19
|
+
fix: () => execAndParse(bin, fixArgs, root, parseOuptut)
|
|
20
|
+
};
|
|
17
21
|
};
|
|
18
22
|
export const parseOuptut = ({ stdout, stderr }) => {
|
|
19
23
|
return `${stdout}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ALL_TOOLS:
|
|
1
|
+
export declare const ALL_TOOLS: import("..").ToolDefinition[];
|
package/dist/tools/prettier.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const prettier:
|
|
1
|
+
import type { OutputParser, ToolDefinition } from "../types";
|
|
2
|
+
export declare const prettier: ToolDefinition;
|
|
3
3
|
export declare const parseOuptut: OutputParser;
|
package/dist/tools/prettier.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { execAndParse, isBinInstalled } from "../utils.mjs";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
export const prettier = ({ binDir, root }) => {
|
|
4
|
+
const bin = resolve(root, binDir, "prettier");
|
|
5
|
+
const checkArgs = [".", "--list-different"];
|
|
6
|
+
const fixArgs = [".", "-w"];
|
|
7
|
+
return {
|
|
8
|
+
name: "Prettier",
|
|
9
|
+
isInstalled: () => isBinInstalled(bin),
|
|
10
|
+
check: () => execAndParse(bin, checkArgs, root, parseOuptut),
|
|
11
|
+
fix: () => execAndParse(bin, fixArgs, root, parseOuptut)
|
|
12
|
+
};
|
|
10
13
|
};
|
|
11
14
|
export const parseOuptut = ({ stdout, stderr }) => {
|
|
12
15
|
if (stderr.trim()) {
|
package/dist/tools/publint.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { OutputParser,
|
|
2
|
-
export declare const publint:
|
|
1
|
+
import type { OutputParser, ToolDefinition } from "../types";
|
|
2
|
+
export declare const publint: ToolDefinition;
|
|
3
3
|
export declare const parseOuptut: OutputParser;
|
package/dist/tools/publint.mjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { isBinInstalled, execAndParse } from "../utils.mjs";
|
|
2
|
-
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
const bin = "publint";
|
|
3
4
|
const args = [];
|
|
4
|
-
export const publint = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const publint = ({ binDir, root }) => {
|
|
6
|
+
const bin2 = resolve(root, binDir, "publint");
|
|
7
|
+
const args2 = [];
|
|
8
|
+
return {
|
|
9
|
+
name: "Publint",
|
|
10
|
+
isInstalled: () => isBinInstalled(bin2),
|
|
11
|
+
check: () => execAndParse(bin2, args2, root, parseOuptut)
|
|
12
|
+
};
|
|
8
13
|
};
|
|
9
14
|
export const parseOuptut = ({ stdout }) => {
|
|
10
15
|
let kind = "warning";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const typescript:
|
|
1
|
+
import type { OutputParser, ToolDefinition } from "../types";
|
|
2
|
+
export declare const typescript: ToolDefinition;
|
|
3
3
|
export declare const parseOuptut: OutputParser;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import { debug, execAndParse, isBinInstalled } from "../utils.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
export const typescript = async ({
|
|
4
|
+
root,
|
|
5
|
+
binDir
|
|
6
|
+
}) => {
|
|
7
|
+
const tsc = {
|
|
8
|
+
bin: resolve(root, binDir, "tsc"),
|
|
9
|
+
args: ["--noEmit", "--pretty", "false"]
|
|
10
|
+
};
|
|
11
|
+
const vueTsc = {
|
|
12
|
+
bin: resolve(root, binDir, "vue-tsc"),
|
|
13
|
+
args: ["--noEmit", "--pretty", "false"]
|
|
14
|
+
};
|
|
15
|
+
const isVueTsc = await isBinInstalled(vueTsc.bin);
|
|
12
16
|
debug("TypeScript: Is vue-tsc installed? " + isVueTsc);
|
|
13
17
|
const cmd = isVueTsc ? vueTsc : tsc;
|
|
14
18
|
const name = isVueTsc ? "TypeScript (Vue)" : "Typescript";
|
|
15
19
|
return {
|
|
16
20
|
name,
|
|
17
21
|
// Always check if tsc is installed
|
|
18
|
-
isInstalled: (
|
|
22
|
+
isInstalled: () => isBinInstalled(tsc.bin),
|
|
19
23
|
// Execute the other TSC binary if necessary
|
|
20
|
-
check: async (
|
|
24
|
+
check: async () => execAndParse(cmd.bin, cmd.args, root, parseOuptut)
|
|
21
25
|
};
|
|
22
26
|
};
|
|
23
27
|
export const parseOuptut = ({ stdout }) => {
|
package/dist/types.d.ts
CHANGED
|
@@ -13,7 +13,12 @@ export interface CheckOptions {
|
|
|
13
13
|
* Set to true to enable debug logs.
|
|
14
14
|
*/
|
|
15
15
|
debug?: boolean;
|
|
16
|
+
binDir?: string;
|
|
16
17
|
}
|
|
18
|
+
export type ToolDefinition = (opts: {
|
|
19
|
+
root: string;
|
|
20
|
+
binDir: string;
|
|
21
|
+
}) => Promise<Tool> | Tool;
|
|
17
22
|
export interface Tool {
|
|
18
23
|
/**
|
|
19
24
|
* Name of tool shown in the console output.
|
|
@@ -22,15 +27,15 @@ export interface Tool {
|
|
|
22
27
|
/**
|
|
23
28
|
* Check if the tool is installed.
|
|
24
29
|
*/
|
|
25
|
-
isInstalled: (
|
|
30
|
+
isInstalled: () => Promise<boolean>;
|
|
26
31
|
/**
|
|
27
32
|
* Run the tool, only checking for problems.
|
|
28
33
|
*/
|
|
29
|
-
check: (
|
|
34
|
+
check: () => Promise<Problem[]>;
|
|
30
35
|
/**
|
|
31
36
|
* Run the tool, but fix problems if possible. If the tool doesn't support fixing problems, `check` will be called instead.
|
|
32
37
|
*/
|
|
33
|
-
fix?: (
|
|
38
|
+
fix?: () => Promise<Problem[]>;
|
|
34
39
|
}
|
|
35
40
|
export interface Problem {
|
|
36
41
|
location?: CodeLocation;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OutputParser, Problem } from "./types";
|
|
2
|
-
export declare function isBinInstalled(bin: string
|
|
3
|
-
export declare function execAndParse(
|
|
2
|
+
export declare function isBinInstalled(bin: string): Promise<boolean>;
|
|
3
|
+
export declare function execAndParse(bin: string, args: string[], cwd: string, parser: OutputParser): Promise<Problem[]>;
|
|
4
4
|
export declare function isDebug(): boolean;
|
|
5
5
|
export declare const bold: (str: string) => string;
|
|
6
6
|
export declare const dim: (str: string) => string;
|
package/dist/utils.mjs
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { stat } from "fs/promises";
|
|
3
|
-
|
|
4
|
-
function resolveRoot(root, ...path) {
|
|
5
|
-
return root != null ? resolve(root, ...path) : resolve(...path);
|
|
6
|
-
}
|
|
7
|
-
export async function isBinInstalled(bin, root) {
|
|
3
|
+
export async function isBinInstalled(bin) {
|
|
8
4
|
try {
|
|
9
|
-
const binPath = resolveRoot(root, bin);
|
|
10
5
|
if (isDebug())
|
|
11
|
-
debug(`Checking if binary exists: ${
|
|
12
|
-
await stat(
|
|
6
|
+
debug(`Checking if binary exists: ${bin}`);
|
|
7
|
+
await stat(bin);
|
|
13
8
|
return true;
|
|
14
9
|
} catch (err) {
|
|
15
10
|
return false;
|
|
16
11
|
}
|
|
17
12
|
}
|
|
18
13
|
function exec(cmd, args, opts) {
|
|
19
|
-
return new Promise((
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
20
15
|
const child = spawn(cmd, args, { ...opts, shell: true });
|
|
21
16
|
let stderr = "";
|
|
22
17
|
let stdout = "";
|
|
@@ -30,16 +25,16 @@ function exec(cmd, args, opts) {
|
|
|
30
25
|
reject(error);
|
|
31
26
|
});
|
|
32
27
|
child.on("close", (exitCode) => {
|
|
33
|
-
|
|
28
|
+
resolve({ stderr, stdout, exitCode });
|
|
34
29
|
});
|
|
35
30
|
});
|
|
36
31
|
}
|
|
37
|
-
export async function execAndParse(
|
|
38
|
-
const res = await exec(
|
|
32
|
+
export async function execAndParse(bin, args, cwd, parser) {
|
|
33
|
+
const res = await exec(bin, args, { cwd });
|
|
39
34
|
if (res.exitCode == null)
|
|
40
35
|
throw Error("Exit code was null");
|
|
41
36
|
if (isDebug())
|
|
42
|
-
console.debug({ bin, args,
|
|
37
|
+
console.debug({ bin, args, cwd, ...res });
|
|
43
38
|
return parser({
|
|
44
39
|
code: res.exitCode,
|
|
45
40
|
stderr: res.stderr,
|