@aklinker1/check 1.4.4 → 2.0.0-alpha.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/README.md CHANGED
@@ -23,9 +23,6 @@ This project is built using [`bun`](https://bun.sh). Demo project uses PNPM.
23
23
  ```sh
24
24
  # Setup
25
25
  bun i
26
- pushd demo
27
- pnpm i
28
- popd
29
26
 
30
27
  # Build NPM package
31
28
  bun run build
@@ -33,7 +30,6 @@ bun run build
33
30
  # Run checks
34
31
  bun check --help
35
32
  bun check
36
- bun check demo
37
33
  ```
38
34
 
39
35
  ### Adding Tools
package/dist/index.mjs CHANGED
@@ -11,22 +11,23 @@ import {
11
11
  yellow
12
12
  } from "./utils.mjs";
13
13
  import { createTaskList } from "./tasklist/index.mjs";
14
- import { relative, resolve, sep } from "node:path";
14
+ import { relative, resolve, sep, join } from "node:path";
15
15
  import { isCI } from "ci-info";
16
+ import { readFile } from "node:fs/promises";
16
17
  export async function check(options = {}) {
17
- const {
18
- debug,
19
- fix = !isCI,
20
- root = process.cwd(),
21
- binDir = "node_modules/.bin"
22
- } = options;
18
+ const { debug, fix = !isCI, root = process.cwd() } = options;
19
+ const packageJson = JSON.parse(
20
+ await readFile(join(root, "package.json"), "utf8")
21
+ );
23
22
  if (debug) {
24
23
  process.env.DEBUG = "true";
25
24
  }
26
25
  console.log();
27
26
  debugLog("Options:" + JSON.stringify(options));
28
- debugLog("Resolved options:" + JSON.stringify({ debug, fix, root, binDir }));
29
- const tools = await findInstalledTools({ root, binDir });
27
+ debugLog(
28
+ "Resolved options:" + JSON.stringify({ debug, fix, root, packageJson })
29
+ );
30
+ const tools = await findInstalledTools({ root, packageJson });
30
31
  if (tools.length === 0) {
31
32
  if (isDebug()) {
32
33
  console.log("No tools detected!");
@@ -103,7 +104,7 @@ export async function check(options = {}) {
103
104
  async function findInstalledTools(opts) {
104
105
  const status = await p(ALL_TOOLS).map(async (def) => {
105
106
  const tool = await def(opts);
106
- const isInstalled = await tool.isInstalled();
107
+ const isInstalled = !!opts.packageJson.devDependencies?.[tool.packageName];
107
108
  return { tool, isInstalled };
108
109
  }).promise;
109
110
  if (isDebug()) {
@@ -1,3 +1,3 @@
1
1
  import type { OutputParser, ToolDefinition } from "../types";
2
2
  export declare const eslint: ToolDefinition;
3
- export declare const parseOuptut: OutputParser;
3
+ export declare const parseOutput: OutputParser;
@@ -1,7 +1,6 @@
1
- import { isBinInstalled, execAndParse } from "../utils.mjs";
2
- import { resolve } from "node:path";
3
- export const eslint = ({ binDir, root }) => {
4
- const bin = resolve(root, binDir, "eslint");
1
+ import { execAndParse } from "../utils.mjs";
2
+ export const eslint = ({ root }) => {
3
+ const bin = "eslint";
5
4
  const checkArgs = [
6
5
  ".",
7
6
  "--ext",
@@ -14,12 +13,12 @@ export const eslint = ({ binDir, root }) => {
14
13
  const fixArgs = [...checkArgs, "--fix"];
15
14
  return {
16
15
  name: "ESLint",
17
- isInstalled: () => isBinInstalled(bin),
18
- check: () => execAndParse(bin, checkArgs, root, parseOuptut),
19
- fix: () => execAndParse(bin, fixArgs, root, parseOuptut)
16
+ packageName: "eslint",
17
+ check: () => execAndParse(bin, checkArgs, root, parseOutput),
18
+ fix: () => execAndParse(bin, fixArgs, root, parseOutput)
20
19
  };
21
20
  };
22
- export const parseOuptut = ({ stdout, stderr }) => {
21
+ export const parseOutput = ({ stdout, stderr }) => {
23
22
  return `${stdout}
24
23
  ${stderr}`.split(/\r?\n/).reduce((acc, line) => {
25
24
  const groups = /^(?<file>.*?): line (?<line>[0-9]+), col (?<column>[0-9]+), (?<kind>\S+) - (?<message>.*?) \((?<rule>\S*?)\)$/.exec(
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "bun:test";
2
- import { parseOuptut } from "./eslint.mjs";
2
+ import { parseOutput } from "./eslint.mjs";
3
3
  describe("ESLint", () => {
4
4
  it("should properly parse output", async () => {
5
5
  const stdout = `/path/to/check/demo/test.ts: line 1, col 7, Warning - 'test' is assigned a value but never used. (@typescript-eslint/no-unused-vars)
@@ -9,7 +9,7 @@ describe("ESLint", () => {
9
9
  `;
10
10
  const stderr = "";
11
11
  const code = 1;
12
- expect(parseOuptut({ code, stdout, stderr })).toEqual([
12
+ expect(parseOutput({ code, stdout, stderr })).toEqual([
13
13
  {
14
14
  file: "/path/to/check/demo/test.ts",
15
15
  message: "'test' is assigned a value but never used.",
@@ -1,3 +1,3 @@
1
1
  import type { OutputParser, ToolDefinition } from "../types";
2
2
  export declare const oxlint: ToolDefinition;
3
- export declare const parseOuptut: OutputParser;
3
+ export declare const parseOutput: OutputParser;
@@ -1,10 +1,10 @@
1
- import { execAndParse, isBinInstalled } from "../utils.mjs";
2
- import { resolve } from "node:path";
3
- export const oxlint = ({ binDir, root }) => {
4
- const bin = resolve(root, binDir, "oxlint");
1
+ import { execAndParse } from "../utils.mjs";
2
+ export const oxlint = ({ root }) => {
3
+ const bin = "oxlint";
5
4
  const checkArgs = [
6
5
  "--format=unix",
7
6
  "--deny-warnings",
7
+ "--ignore-path=.oxlintignore",
8
8
  "--ignore-pattern='**/dist/**'",
9
9
  "--ignore-pattern='**/node_modules/**'",
10
10
  "--ignore-pattern='**/.output/**'",
@@ -13,12 +13,12 @@ export const oxlint = ({ binDir, root }) => {
13
13
  const fixArgs = [...checkArgs, "--fix"];
14
14
  return {
15
15
  name: "Oxlint",
16
- isInstalled: () => isBinInstalled(bin),
17
- check: () => execAndParse(bin, checkArgs, root, parseOuptut),
18
- fix: () => execAndParse(bin, fixArgs, root, parseOuptut)
16
+ packageName: "oxlint",
17
+ check: () => execAndParse(bin, checkArgs, root, parseOutput),
18
+ fix: () => execAndParse(bin, fixArgs, root, parseOutput)
19
19
  };
20
20
  };
21
- export const parseOuptut = ({ stdout, stderr }) => {
21
+ export const parseOutput = ({ stdout }) => {
22
22
  if (stdout.trim()) {
23
23
  return stdout.split(/\r?\n/).reduce((acc, line) => {
24
24
  const groups = /^(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]+):\s?(?<message>.*?)\s?\[(?<kind>Warning|Error)\/?(?<rule>.*?)\]\s?$/.exec(
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "bun:test";
2
- import { parseOuptut } from "./oxlint.mjs";
2
+ import { parseOutput } from "./oxlint.mjs";
3
3
  describe("Oxlint", () => {
4
4
  it("should properly parse output", async () => {
5
5
  const stdout = `
@@ -12,7 +12,7 @@ test.ts:8:7: Missing initializer in const declaration [Error]
12
12
  `;
13
13
  const stderr = "";
14
14
  const code = 1;
15
- expect(parseOuptut({ code, stdout, stderr })).toEqual([
15
+ expect(parseOutput({ code, stdout, stderr })).toEqual([
16
16
  {
17
17
  file: "test.ts",
18
18
  message: "Variable 'test' is declared but never used.",
@@ -1,3 +1,3 @@
1
1
  import type { OutputParser, ToolDefinition } from "../types";
2
2
  export declare const prettier: ToolDefinition;
3
- export declare const parseOuptut: OutputParser;
3
+ export declare const parseOutput: OutputParser;
@@ -1,17 +1,16 @@
1
- import { execAndParse, isBinInstalled } from "../utils.mjs";
2
- import { resolve } from "node:path";
3
- export const prettier = ({ binDir, root }) => {
4
- const bin = resolve(root, binDir, "prettier");
1
+ import { execAndParse } from "../utils.mjs";
2
+ export const prettier = ({ root }) => {
3
+ const bin = "prettier";
5
4
  const checkArgs = [".", "--list-different"];
6
5
  const fixArgs = [".", "-w"];
7
6
  return {
8
7
  name: "Prettier",
9
- isInstalled: () => isBinInstalled(bin),
10
- check: () => execAndParse(bin, checkArgs, root, parseOuptut),
11
- fix: () => execAndParse(bin, fixArgs, root, parseOuptut)
8
+ packageName: "prettier",
9
+ check: () => execAndParse(bin, checkArgs, root, parseOutput),
10
+ fix: () => execAndParse(bin, fixArgs, root, parseOutput)
12
11
  };
13
12
  };
14
- export const parseOuptut = ({ stdout, stderr }) => {
13
+ export const parseOutput = ({ stdout, stderr }) => {
15
14
  if (stderr.trim()) {
16
15
  return stderr.split(/\r?\n/).reduce((acc, line) => {
17
16
  const groups = /^\[(?<kind>.+?)\]\s?(?<file>.+?):\s?(?<message>.*?)\s?\((?<line>[0-9]+):(?<column>[0-9]+)\)$/.exec(
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "bun:test";
2
- import { parseOuptut } from "./prettier.mjs";
2
+ import { parseOutput } from "./prettier.mjs";
3
3
  describe("Prettier", () => {
4
4
  it("should properly parse output", async () => {
5
5
  const stdout = `target/.rustc_info.json
@@ -7,7 +7,7 @@ describe("Prettier", () => {
7
7
  `;
8
8
  const stderr = "";
9
9
  const code = 1;
10
- expect(parseOuptut({ code, stdout, stderr })).toEqual([
10
+ expect(parseOutput({ code, stdout, stderr })).toEqual([
11
11
  {
12
12
  file: "target/.rustc_info.json",
13
13
  message: "Not formatted.",
@@ -24,7 +24,7 @@ describe("Prettier", () => {
24
24
  const stdout = "";
25
25
  const stderr = "";
26
26
  const code = 1;
27
- expect(parseOuptut({ code, stdout, stderr })).toEqual([]);
27
+ expect(parseOutput({ code, stdout, stderr })).toEqual([]);
28
28
  });
29
29
  it("should return an error when a syntax error is reported", async () => {
30
30
  const stderr = `[error] src/components/CommitDiff.ts: SyntaxError: Declaration or statement expected. (15:1)
@@ -45,7 +45,7 @@ describe("Prettier", () => {
45
45
  .github/workflows/validate.yml 4ms
46
46
  .prettierrc.yml 0ms`;
47
47
  const code = 1;
48
- expect(parseOuptut({ code, stdout, stderr })).toEqual([
48
+ expect(parseOutput({ code, stdout, stderr })).toEqual([
49
49
  {
50
50
  file: "src/components/CommitDiff.ts",
51
51
  message: "SyntaxError: Declaration or statement expected.",
@@ -73,6 +73,6 @@ describe("Prettier", () => {
73
73
  .github/workflows/validate.yml 4ms
74
74
  .prettierrc.yml 0ms`;
75
75
  const code = 0;
76
- expect(parseOuptut({ code, stdout, stderr })).toEqual([]);
76
+ expect(parseOutput({ code, stdout, stderr })).toEqual([]);
77
77
  });
78
78
  });
@@ -1,3 +1,3 @@
1
1
  import type { OutputParser, ToolDefinition } from "../types";
2
2
  export declare const publint: ToolDefinition;
3
- export declare const parseOuptut: OutputParser;
3
+ export declare const parseOutput: OutputParser;
@@ -1,17 +1,14 @@
1
- import { isBinInstalled, execAndParse } from "../utils.mjs";
2
- import { resolve } from "node:path";
3
- const bin = "publint";
4
- const args = [];
5
- export const publint = ({ binDir, root }) => {
6
- const bin2 = resolve(root, binDir, "publint");
7
- const args2 = [];
1
+ import { execAndParse } from "../utils.mjs";
2
+ export const publint = ({ root }) => {
3
+ const bin = "publint";
4
+ const args = [];
8
5
  return {
9
6
  name: "Publint",
10
- isInstalled: () => isBinInstalled(bin2),
11
- check: () => execAndParse(bin2, args2, root, parseOuptut)
7
+ packageName: "publint",
8
+ check: () => execAndParse(bin, args, root, parseOutput)
12
9
  };
13
10
  };
14
- export const parseOuptut = ({ stdout }) => {
11
+ export const parseOutput = ({ stdout }) => {
15
12
  let kind = "warning";
16
13
  return stdout.split(/\r?\n/).reduce((acc, line) => {
17
14
  if (line.includes("Errors:")) {
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "bun:test";
2
- import { parseOuptut } from "./publint.mjs";
2
+ import { parseOutput } from "./publint.mjs";
3
3
  describe("Publint", () => {
4
4
  it("should properly parse output", async () => {
5
5
  const stdout = `@aklinker1/check lint results:
@@ -12,7 +12,7 @@ Errors:
12
12
  `;
13
13
  const stderr = "";
14
14
  const code = 1;
15
- expect(parseOuptut({ code, stdout, stderr })).toEqual([
15
+ expect(parseOutput({ code, stdout, stderr })).toEqual([
16
16
  {
17
17
  file: "package.json",
18
18
  message: "Consider being better lolz.",
@@ -1,3 +1,3 @@
1
1
  import type { OutputParser, ToolDefinition } from "../types";
2
2
  export declare const typescript: ToolDefinition;
3
- export declare const parseOuptut: OutputParser;
3
+ export declare const parseOutput: OutputParser;
@@ -1,30 +1,31 @@
1
- import { debug, execAndParse, isBinInstalled } from "../utils.mjs";
2
- import { resolve } from "node:path";
1
+ import { debug, execAndParse } from "../utils.mjs";
3
2
  export const typescript = async ({
4
3
  root,
5
- binDir
4
+ packageJson
6
5
  }) => {
7
6
  const tsc = {
8
- bin: resolve(root, binDir, "tsc"),
7
+ name: "TypeScript",
8
+ bin: "tsc",
9
+ packageName: "typescript",
9
10
  args: ["--noEmit", "--pretty", "false"]
10
11
  };
11
12
  const vueTsc = {
12
- bin: resolve(root, binDir, "vue-tsc"),
13
+ name: "TypeScript (Vue)",
14
+ bin: "vue-tsc",
15
+ packageName: "vue-tsc",
13
16
  args: ["--noEmit", "--pretty", "false"]
14
17
  };
15
- const isVueTsc = await isBinInstalled(vueTsc.bin);
18
+ const isVueTsc = packageJson.devDependencies?.["vue-tsc"] !== void 0;
16
19
  debug("TypeScript: Is vue-tsc installed? " + isVueTsc);
17
20
  const cmd = isVueTsc ? vueTsc : tsc;
18
- const name = isVueTsc ? "TypeScript (Vue)" : "Typescript";
19
21
  return {
20
- name,
21
- // Always check if tsc is installed
22
- isInstalled: () => isBinInstalled(tsc.bin),
22
+ name: cmd.name,
23
+ packageName: cmd.packageName,
23
24
  // Execute the other TSC binary if necessary
24
- check: async () => execAndParse(cmd.bin, cmd.args, root, parseOuptut)
25
+ check: async () => execAndParse(cmd.bin, cmd.args, root, parseOutput)
25
26
  };
26
27
  };
27
- export const parseOuptut = ({ stdout }) => {
28
+ export const parseOutput = ({ stdout }) => {
28
29
  return stdout.split(/\r?\n/).reduce((acc, line) => {
29
30
  const groups = /^(?<file>\S+?)\((?<line>[0-9]+),(?<column>[0-9]+)\): \w+? (?<rule>TS[0-9]+): (?<message>.*)$/.exec(
30
31
  line
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "bun:test";
2
- import { parseOuptut } from "./typescript.mjs";
2
+ import { parseOutput } from "./typescript.mjs";
3
3
  describe("TypeScript", () => {
4
4
  it("should properly parse output", async () => {
5
5
  const stdout = `test.ts(1,19): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
@@ -7,7 +7,7 @@ test.ts(5,24): error TS7006: Parameter 'a' implicitly has an 'any' type.
7
7
  `;
8
8
  const stderr = "";
9
9
  const code = 1;
10
- expect(parseOuptut({ code, stdout, stderr })).toEqual([
10
+ expect(parseOutput({ code, stdout, stderr })).toEqual([
11
11
  {
12
12
  file: "test.ts",
13
13
  message: "A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.",
@@ -35,7 +35,7 @@ test.ts(5,24): error TS7006: Parameter 'a' implicitly has an 'any' type.
35
35
  Property 'value' is missing in type '{ vale: string; }' but required in type 'Omit<{ readonly value: string; "onUpdate:value"?: ((newValue: string) => any) | undefined; } & VNodeProps & AllowedComponentProps & ComponentCustomProps & Readonly<...> & { ...; }, never>'.`;
36
36
  const stderr = "";
37
37
  const code = 1;
38
- expect(parseOuptut({ code, stdout, stderr })).toEqual([
38
+ expect(parseOutput({ code, stdout, stderr })).toEqual([
39
39
  {
40
40
  file: "src/components/CustomListsPref.vue",
41
41
  message: `Argument of type '{ vale: string; }' is not assignable to parameter of type 'Partial<{}> & Omit<{ readonly value: string; "onUpdate:value"?: ((newValue: string) => any) | undefined; } & VNodeProps & AllowedComponentProps & ComponentCustomProps & Readonly<...> & { ...; }, never> & Record<...>'.`,
package/dist/types.d.ts CHANGED
@@ -13,11 +13,10 @@ export interface CheckOptions {
13
13
  * Set to true to enable debug logs.
14
14
  */
15
15
  debug?: boolean;
16
- binDir?: string;
17
16
  }
18
17
  export type ToolDefinition = (opts: {
19
18
  root: string;
20
- binDir: string;
19
+ packageJson: any;
21
20
  }) => Promise<Tool> | Tool;
22
21
  export interface Tool {
23
22
  /**
@@ -25,9 +24,9 @@ export interface Tool {
25
24
  */
26
25
  name: string;
27
26
  /**
28
- * Check if the tool is installed.
27
+ * The name of the package in your `package.json`. If present, this tool will be ran.
29
28
  */
30
- isInstalled: () => Promise<boolean>;
29
+ packageName: string;
31
30
  /**
32
31
  * Run the tool, only checking for problems.
33
32
  */
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { OutputParser, Problem } from "./types";
2
- export declare function isBinInstalled(bin: string): Promise<boolean>;
3
2
  export declare function execAndParse(bin: string, args: string[], cwd: string, parser: OutputParser): Promise<Problem[]>;
4
3
  export declare function isDebug(): boolean;
5
4
  export declare const bold: (str: string) => string;
package/dist/utils.mjs CHANGED
@@ -1,15 +1,4 @@
1
1
  import { spawn } from "node:child_process";
2
- import { stat } from "fs/promises";
3
- export async function isBinInstalled(bin) {
4
- try {
5
- if (isDebug())
6
- debug(`Checking if binary exists: ${bin}`);
7
- await stat(bin);
8
- return true;
9
- } catch (err) {
10
- return false;
11
- }
12
- }
13
2
  function exec(cmd, args, opts) {
14
3
  return new Promise((resolve, reject) => {
15
4
  const child = spawn(cmd, args, { ...opts, shell: true });
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@aklinker1/check",
3
- "version": "1.4.4",
3
+ "version": "2.0.0-alpha.1",
4
+ "packageManager": "bun@1.2.11",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "https://github.com/aklinker1/check"
@@ -34,6 +35,12 @@
34
35
  "bin": {
35
36
  "check": "bin/check.mjs"
36
37
  },
38
+ "scripts": {
39
+ "build": "bunx --bun unbuild",
40
+ "check": "bun src/cli.ts",
41
+ "prepack": "bun run build",
42
+ "prepublish": "bun run build"
43
+ },
37
44
  "dependencies": {
38
45
  "@antfu/utils": "^0.7.7",
39
46
  "citty": "^0.1.6",
@@ -42,11 +49,9 @@
42
49
  "devDependencies": {
43
50
  "@types/bun": "latest",
44
51
  "publint": "^0.2.7",
52
+ "typescript": "^5.0.0",
45
53
  "unbuild": "latest"
46
54
  },
47
- "peerDependencies": {
48
- "typescript": "^5.0.0"
49
- },
50
55
  "unbuild": {
51
56
  "entries": [
52
57
  {
@@ -61,10 +66,5 @@
61
66
  "excludeAuthors": [
62
67
  "aaronklinker1@gmail.com"
63
68
  ]
64
- },
65
- "scripts": {
66
- "build": "bunx --bun unbuild",
67
- "check": "bun src/cli.ts",
68
- "prepublish": "bun run build"
69
69
  }
70
- }
70
+ }
package/bin/check.mjs DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import "../dist/cli.mjs";