ci: package publish ready
This commit is contained in:
41
scripts/check-package.mjs
Normal file
41
scripts/check-package.mjs
Normal file
@@ -0,0 +1,41 @@
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
|
||||
const requiredFiles = [
|
||||
"README.md",
|
||||
"dist/index.js",
|
||||
"dist/index.d.ts",
|
||||
];
|
||||
|
||||
const missingFiles = requiredFiles.filter((path) => !existsSync(path));
|
||||
|
||||
if (missingFiles.length > 0) {
|
||||
console.error(`Missing package artifact(s): ${missingFiles.join(", ")}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const packageJson = JSON.parse(readFileSync("package.json", "utf8"));
|
||||
|
||||
const expectedFields = {
|
||||
main: "dist/index.js",
|
||||
module: "dist/index.js",
|
||||
types: "dist/index.d.ts",
|
||||
};
|
||||
|
||||
for (const [field, expected] of Object.entries(expectedFields)) {
|
||||
if (packageJson[field] !== expected) {
|
||||
console.error(`package.json ${field} must be ${expected}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (packageJson.exports?.["."]?.types !== "./dist/index.d.ts") {
|
||||
console.error("package.json exports[\".\"].types must point to ./dist/index.d.ts");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (packageJson.exports?.["."]?.import !== "./dist/index.js") {
|
||||
console.error("package.json exports[\".\"].import must point to ./dist/index.js");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("Package metadata and artifacts are publish-ready.");
|
||||
Reference in New Issue
Block a user