jsr-exports-lint
Version:
JSR exports field lint for bundlers
56 lines (54 loc) • 1.19 kB
JavaScript
import { t as lint } from "./lint-ChuUrGpT.js";
import fs from "node:fs";
//#region src/unbuild.ts
/**
* An entry for unbuild hooks
*
* @example
* ```js
* import { lintJsrExports } from 'jsr-exports-lint/unbuild'
* ```
*
* @module
*/
/**
* @author kazuya kawaguchi (a.k.a. @kazupon)
* @license MIT
*/
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 };