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

Function getPackageVersion

packages/dev/s2-docs/src/CodeBlock.tsx:393–407  ·  view source on GitHub ↗
(pkg: string)

Source from the content-addressed store, hash-verified

391
392let packageVersionCache = new Map<string, string>();
393function getPackageVersion(pkg: string) {
394 let version = packageVersionCache.get(pkg);
395 if (version) {
396 return version;
397 }
398
399 let p = findPackageJSON(pkg, __filename);
400 if (p) {
401 let json = JSON.parse(fs.readFileSync(p, 'utf8'));
402 packageVersionCache.set(pkg, json.version);
403 return json.version;
404 } else {
405 throw new Error('Could not find package.json for ' + pkg);
406 }
407}
408
409function resolveUrl(specifier: string, file: string) {
410 let relative = path.relative(path.resolve('pages'), path.dirname(file)).split(/[/\\]/);

Callers 1

parseFileFunction · 0.85

Calls 2

parseMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected