MCPcopy Create free account
hub / github.com/effect-app/libs / readPackageMetadata

Function readPackageMetadata

repos/effect/packages/tools/jsdocs/src/Jsdocs.ts:521–568  ·  view source on GitHub ↗
(root: string)

Source from the content-addressed store, hash-verified

519 *
520 * @category constructors
521 * @since 4.0.0
522 */
523export function createJSDocFileMatcher(options: {
524 readonly cwd: string
525 readonly include?: ReadonlyArray<string>
526 readonly exclude?: ReadonlyArray<string>
527}): (filename: string) => boolean {
528 const include = options.include?.map(globToRegExp)
529 const exclude = options.exclude?.map(globToRegExp)
530 return (filename) => {
531 const normalizedFilename = normalizePathName(filename)
532 const relativeFilename = normalizePathName(path.relative(options.cwd, filename))
533 const matches = (regexp: RegExp) => regexp.test(normalizedFilename) || regexp.test(relativeFilename)
534 if (include !== undefined && !include.some(matches)) {
535 return false
536 }
537 if (exclude !== undefined && exclude.some(matches)) {
538 return false
539 }
540 return true
541 }
542}
543
544function isRecord(value: unknown): value is Record<string, unknown> {
545 return typeof value === "object" && value !== null && !Array.isArray(value)
546}
547
548function findPackageRoot(filename: string): string | undefined {
549 let directory = path.dirname(path.resolve(filename))
550 while (true) {
551 const packageJsonPath = path.join(directory, "package.json")
552 if (fs.existsSync(packageJsonPath)) {
553 return directory
554 }
555 const parent = path.dirname(directory)
556 if (parent === directory) {
557 return undefined
558 }
559 directory = parent
560 }
561}
562
563function readPackageMetadata(root: string): Result<PackageMetadata, string> {
564 const normalizedRoot = path.resolve(root)
565 const cached = packageMetadataCache.get(normalizedRoot)
566 if (cached !== undefined) {
567 return cached
568 }
569 const packageJsonPath = path.join(normalizedRoot, "package.json")
570 let parsed: unknown
571 try {

Callers 1

resolveJSDocImportsFunction · 0.85

Calls 6

joinMethod · 0.80
parseMethod · 0.80
isRecordFunction · 0.70
getMethod · 0.65
setMethod · 0.65
StringInterface · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…