diff --git a/README.md b/README.md index 9e23dd9..c50a5b3 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ > [!WARNING] > I have not actually published this to NPM yet. +https://github.com/aklinker1/check/assets/10101283/c8089e5c-e25f-4f59-8897-d2a6f97a3139 + ```sh pnpm i @aklinker1/check pnpm check pnpm check --fix ``` -https://github.com/aklinker1/check/assets/10101283/c8089e5c-e25f-4f59-8897-d2a6f97a3139 - -To enable TS, ESLint, or Prettier, just install the package: +To enable checks for any of the following modules, just install them: ```sh -pnpm i -D typescript eslint prettier +pnpm i -D typescript eslint prettier publint ``` ## Contributing diff --git a/bun.lockb b/bun.lockb index 60e1ba4..8049d2f 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 592761e..24d56b7 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@types/bun": "latest", + "publint": "^0.2.7", "unbuild": "latest" }, "peerDependencies": { diff --git a/src/tools/index.ts b/src/tools/index.ts index f53fe33..3a772e2 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -2,5 +2,6 @@ import type { Tool } from "../types"; import { eslint } from "./eslint"; import { prettier } from "./prettier"; import { typescript } from "./typescript"; +import { publint } from "./publint"; -export const ALL_TOOLS: Tool[] = [prettier, typescript, eslint]; +export const ALL_TOOLS: Tool[] = [publint, prettier, typescript, eslint]; diff --git a/src/tools/publint.test.ts b/src/tools/publint.test.ts new file mode 100644 index 0000000..116de81 --- /dev/null +++ b/src/tools/publint.test.ts @@ -0,0 +1,40 @@ +import { describe, it, expect } from "bun:test"; +import { parseOuptut } from "./publint"; + +describe("Publint", () => { + it("should properly parse output", async () => { + const stdout = `@aklinker1/check lint results: +Suggestions: +1. Consider being better lolz. +Warnings: +1. pkg.exports["."].import types is not exported. Consider adding pkg.exports["."].import.types: "./dist/index.d.ts" to be compatible with TypeScript's "moduleResolution": "bundler" compiler option. +Errors: +1. pkg.module is ./dist/index.cjs but the file does not exist. +`; + const stderr = ""; + const code = 1; + + expect(parseOuptut({ code, stdout, stderr })).toEqual({ + type: "error", + problems: [ + { + file: "package.json", + message: "Consider being better lolz.", + kind: "warning", + }, + { + file: "package.json", + message: + 'pkg.exports["."].import types is not exported. Consider adding pkg.exports["."].import.types: "./dist/index.d.ts" to be compatible with TypeScript\'s "moduleResolution": "bundler" compiler option.', + kind: "warning", + }, + { + file: "package.json", + message: + "pkg.module is ./dist/index.cjs but the file does not exist.", + kind: "error", + }, + ], + }); + }); +}); diff --git a/src/tools/publint.ts b/src/tools/publint.ts new file mode 100644 index 0000000..436f882 --- /dev/null +++ b/src/tools/publint.ts @@ -0,0 +1,38 @@ +import type { OutputParser, Problem, ProblemKind, Tool } from "../types"; +import { isBinInstalled, execAndParse } from "../utils"; + +const bin = "node_modules/.bin/publint"; +const args: string[] = []; + +export const publint: Tool = { + name: "Publint", + isInstalled: (root) => isBinInstalled(bin, root), + check: (root) => execAndParse(root, bin, args, parseOuptut), +}; + +export const parseOuptut: OutputParser = ({ code, stdout, stderr }) => { + if (code === 0) return { type: "success" }; + + let kind: ProblemKind = "warning"; + const problems = stdout.split(/\r?\n/).reduce((acc, line) => { + if (line.includes("Errors:")) { + kind = "error"; + return acc; + } + const match = /^[0-9]+\.\s?(.*)$/.exec(line); + if (match == null) return acc; + + acc.push({ + kind, + message: match[1], + file: "package.json", + }); + + return acc; + }, []); + + return { + type: kind, + problems, + }; +};