Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 27x 27x 9x 9x 9x 9x 9x 27x 18x 9x 9x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 4x 3x 7x 7x 1x 1x 1x 1x 1x 1x 1537x 1537x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1537x 1537x 1x 1x 1x 1x 1x 1x 1x 653x 653x 1x 1x 1x 1x 1x 1x 1x 674x 674x 1x 1x 1x 1x 1x 1x 1x 210x 210x 1x 1x 1x 1x 1x 1x 1x 1x 17x 17x 17x 17x 1x 1x 17x | "use strict";
/**
* Version information for oag-mcp and the tools it pins.
*
* @module util/version
*/
import fs from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";
const require = createRequire(import.meta.url);
/**
* Exact OpenAPI Generator versions that oag-mcp is tested against. SDKs
* generated by any other version are rejected unless
* --allow-untested-oag-version is given. Add versions here (with a fixture
* and tests) to support more than one.
*/
export const SUPPORTED_OAG_VERSIONS = ["7.26.0"] as const;
/** The only OpenAPI Generator target supported by this release. */
export const SUPPORTED_GENERATOR = "typescript-fetch";
/** Deno versions accepted by the executor, as a semver range. */
export const DENO_VERSION_RANGE = ">=2.5.0 <3.0.0";
let cachedPackage:
{ name: string; version: string; author?: string } | undefined;
/**
* Locate the oag-mcp package root by walking up from this module.
*
* @return {String} absolute directory containing oag-mcp's package.json
*/
export function packageRoot(): string {
let dir = path.dirname(fileURLToPath(import.meta.url));
for (let i = 0; i < 5; i++) {
const candidate = path.join(dir, "package.json");
if (fs.existsSync(candidate)) {
const pkg = JSON.parse(fs.readFileSync(candidate, "utf8"));
if (pkg.name === "oag-mcp") {
return dir;
}
}
dir = path.dirname(dir);
}
throw new Error("Unable to locate the oag-mcp package root");
}
/**
* The name in a package.json person field: npm's "Name <email> (url)" form,
* or an object with a name.
*
* @param {String|Object} [author] - the field's value
* @return {String} the name, or undefined when there is none
*/
export function authorName(author: unknown): string | undefined {
const name =
typeof author === "string"
? author.replace(/\s*[<(].*$/, "").trim()
: (author as { name?: unknown } | undefined)?.name;
return typeof name === "string" && name ? name : undefined;
}
/**
* Read (once) oag-mcp's own package.json.
*
* @private
*/
function _package(): { name: string; version: string; author?: string } {
if (!cachedPackage) {
const pkg = JSON.parse(
fs.readFileSync(path.join(packageRoot(), "package.json"), "utf8"),
);
cachedPackage = {
name: pkg.name as string,
version: pkg.version as string,
author: authorName(pkg.author),
};
}
return cachedPackage;
}
/**
* Read the oag-mcp package name from package.json.
*
* @return {String} package name
*/
export function oagMcpName(): string {
return _package().name;
}
/**
* Read the oag-mcp version from package.json.
*
* @return {String} version string
*/
export function oagMcpVersion(): string {
return _package().version;
}
/**
* Read the oag-mcp author's name from package.json.
*
* @return {String} author name, or undefined when not set
*/
export function oagMcpAuthor(): string | undefined {
return _package().author;
}
/**
* Read the installed version of a dependency.
*
* @param {String} name - package name
* @return {String} version, or "unknown"
*/
export function dependencyVersion(name: string): string {
try {
const pkgPath = require.resolve(`${name}/package.json`);
return JSON.parse(fs.readFileSync(pkgPath, "utf8")).version;
} catch {
return "unknown";
}
}
|