MCPcopy Create free account
hub / github.com/adobe/react-spectrum / readPackageVersion

Function readPackageVersion

packages/dev/mcp/shared/src/utils.ts:8–20  ·  view source on GitHub ↗
(entryUrl: string)

Source from the content-addressed store, hash-verified

6// Both the npm-published layout (dist/<lib>/src/index.js) and the .mcpb bundle
7// layout (server/<lib>/src/index.js) place package.json three levels up.
8export function readPackageVersion(entryUrl: string): string {
9 const entryDir = dirname(fileURLToPath(entryUrl));
10 const pkgPath = join(entryDir, '..', '..', '..', 'package.json');
11 try {
12 const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
13 if (typeof pkg.version === 'string' && pkg.version.length > 0) {
14 return pkg.version;
15 }
16 } catch {
17 // fall through
18 }
19 return '0.0.0';
20}
21
22export function errorToString(err: unknown): string {
23 if (err && typeof err === 'object' && 'stack' in err && typeof (err as any).stack === 'string') {

Callers 2

index.tsFile · 0.85
index.tsFile · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected