UNPKG

jsr-exports-lint

Version:
42 lines (40 loc) 979 B
import { lint } from "./lint-B6ddNLyQ.js"; import fs from "node:fs"; //#region src/unbuild.ts const EXTENSIONS = [ ".ts", ".js", ".mts", ".mjs", ".cts", ".cjs", ".tsx", ".jsx" ]; /** * Lint `exports` field of JSR manifest file for unbuild hooks * @param jsrPath The path to the `jsr.json` file. * @returns A unbuild hook */ function lintJsrExports(jsrPath) { return async (ctx) => { await lint({ jsrPath, entries: normalizeEntries(ctx), cwd: ctx.options.rootDir, silent: false }); }; } function normalizeEntries(ctx) { const ctxEntries = ctx.options.entries.filter((entry) => entry.builder === "rollup" && entry.name); const entries = Object.create(null); for (const entry of ctxEntries) { const ext = EXTENSIONS.find((ext$1) => fs.existsSync(`${entry.input}${ext$1}`)); if (!ext) throw new Error(`No entry found for ${entry.input}`); entries[entry.name] = `${entry.input}${ext}`; } return entries; } //#endregion export { lintJsrExports };