everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
35 lines (33 loc) • 1.86 kB
JavaScript
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
let node_fs = require("node:fs");
let node_path = require("node:path");
//#region src/cli/framework-version.ts
function stripVersionPrefix(version) {
return version.replace(/^[\^~>=]+/, "");
}
function readRootCatalogVersion(projectDir, packageName) {
const pkgPath = (0, node_path.join)(projectDir, "package.json");
if (!(0, node_fs.existsSync)(pkgPath)) return void 0;
const version = JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf-8")).workspaces?.catalog?.[packageName];
return version ? stripVersionPrefix(version) : void 0;
}
function readNodeModulesVersion(projectDir, packageName) {
const pkgPath = (0, node_path.join)(projectDir, "node_modules", packageName, "package.json");
if (!(0, node_fs.existsSync)(pkgPath)) return void 0;
return JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf-8")).version;
}
function readInstalledFrameworkVersion(projectDir, packageName) {
const pkgPath = (0, node_path.join)(projectDir, "package.json");
if (!(0, node_fs.existsSync)(pkgPath)) return void 0;
const pkg = JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf-8"));
const deps = pkg.dependencies ?? {};
const devDeps = pkg.devDependencies ?? {};
const version = deps[packageName] || devDeps[packageName];
if (!version) return readRootCatalogVersion(projectDir, packageName) ?? readNodeModulesVersion(projectDir, packageName);
if (version.startsWith("catalog:")) return readRootCatalogVersion(projectDir, packageName) ?? readNodeModulesVersion(projectDir, packageName);
if (version.startsWith("workspace:") || version.startsWith("file:")) return readNodeModulesVersion(projectDir, packageName);
return stripVersionPrefix(version);
}
//#endregion
exports.readInstalledFrameworkVersion = readInstalledFrameworkVersion;
//# sourceMappingURL=framework-version.cjs.map