Files
lodestar/scripts/assert_exports.mjs
Nazar Hussain c0aa75280c fix: contract eth_call bug and made some improvements (#5785)
* Fix some regressions for prover

* Fix package export assertion for nested conditional exports

* Improve the exports for the package

* Fix the http agent for https

* Fix e2e tests
2023-07-24 12:54:25 -04:00

50 lines
1.5 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
// ESM modules now reference build files on (package.json).exports
// This script ensure that the referenced files exist
const pkgsDirpath = path.resolve("./packages");
function getExportPaths(pkgDirPath, pkgExports) {
// {
// "exports": "./lib/index.js",
// }
if (typeof pkgExports === "string") {
return [pkgExports];
}
// {
// "exports": {
// ".": {
// "import": "./lib/index.js"
// },
// }
const exportPaths = [];
for (const [exportPath, nestedExportObj] of Object.entries(pkgExports)) {
if (typeof nestedExportObj === "object") {
exportPaths.push(...getExportPaths(pkgDirPath, nestedExportObj));
} else if (typeof nestedExportObj === "string") {
exportPaths.push(nestedExportObj);
}
}
return exportPaths;
}
for (const pkgDirname of fs.readdirSync(pkgsDirpath)) {
const pkgDirpath = path.join(pkgsDirpath, pkgDirname);
const packageJSONPath = path.join(pkgDirpath, "package.json");
if (!fs.existsSync(packageJSONPath)) {
throw Error(`No package.json found in ${pkgDirpath}`);
}
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf8"));
const exportPaths = getExportPaths(pkgDirpath, packageJSON.exports);
const missingExportPaths = exportPaths.filter((exportPath) => !fs.existsSync(path.join(pkgDirpath, exportPath)));
if (missingExportPaths.length > 0) {
throw Error(`export paths file(s) not found\n${missingExportPaths.join("\n")}`);
}
}