UNPKG

alinea

Version:
47 lines (45 loc) 1.45 kB
import { compareVersions } from "../../chunks/chunk-5RKITIG5.js"; import "../../chunks/chunk-NZLE2WMY.js"; // src/cli/util/EnsureLibs.ts import fs from "node:fs"; import { createRequire } from "node:module"; import path from "node:path"; import { outcome } from "alinea/core/Outcome"; import { reportFatal } from "./Report.js"; var require2 = createRequire(import.meta.url); function ensureLibs(libs) { function fail(message) { reportFatal(message); process.exit(1); } function ensurePackage(pkg, minVersion) { const [location] = outcome(() => require2.resolve(pkg)); if (!location) throw fail( `We could not find the ${pkg} package. It's required for the alinea dashboard. You can install it with: npm i ${pkg}` ); const dir = path.dirname(location); const [meta] = outcome( () => fs.readFileSync(path.join(dir, "package.json"), "utf8") ); if (!meta) throw fail(`Could not retrieve ${pkg}'s package.json file`); const { version } = JSON.parse(meta); const pkgVersionWorks = compareVersions.compare(version, minVersion, ">="); if (!pkgVersionWorks) throw fail( `${pkg} version ${version} is not supported, at least ${minVersion} is required ` ); } for (const [pkg, minVersion] of Object.entries(libs)) { ensurePackage(pkg, minVersion); } ensurePackage("react", "18.0.0"); ensurePackage("react-dom", "18.0.0"); } export { ensureLibs };