{"library":"pkg-types","title":"Package and TypeScript Configuration Utilities","description":"pkg-types is a utility library providing Node.js functions and comprehensive TypeScript definitions for common project configuration files, including `package.json`, `tsconfig.json`, and various lock files (e.g., `yarn.lock`, `pnpm-lock.yaml`, `bun.lockb`, `deno.lock`). The current stable version is 2.3.0. The package has an active development cycle, with frequent releases bringing enhancements and bug fixes. A key differentiator is its automatic format detection for `package.json` (supporting `.json`, `.json5`, `.yaml`) and robust utilities for finding and reading workspace configurations across different package managers and monorepo tools like Lerna, Turborepo, and Rush. It streamlines the process of programmatically interacting with project metadata, making it ideal for tooling development.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pkg-types"],"cli":null},"imports":["import { readPackage } from 'pkg-types'","import type { PackageJson } from 'pkg-types'","import { readTSConfig } from 'pkg-types'","import { findWorkspaceDir } from 'pkg-types'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { readPackage, findPackage, readTSConfig, findWorkspaceDir } from 'pkg-types';\nimport path from 'node:path';\n\nasync function getProjectConfig() {\n  try {\n    // Find the nearest package.json, package.json5, or package.yaml\n    const packageFile = await findPackage(process.cwd());\n    if (packageFile) {\n      console.log(`Found package file: ${packageFile}`);\n\n      // Read the package configuration, automatically detecting format\n      const pkg = await readPackage(path.dirname(packageFile));\n      console.log('Project Name:', pkg.name);\n      console.log('Project Version:', pkg.version);\n    } else {\n      console.log('No package file found in current directory or ancestors.');\n    }\n\n    // Read the nearest tsconfig.json\n    const tsconfigPath = await findPackage(process.cwd(), { filenames: ['tsconfig.json'] });\n    if (tsconfigPath) {\n      const tsconfig = await readTSConfig(path.dirname(tsconfigPath));\n      console.log('TSConfig Compiler Options:', tsconfig?.compilerOptions);\n    } else {\n      console.log('No tsconfig.json found.');\n    }\n\n    // Find the workspace root directory\n    const workspaceRoot = await findWorkspaceDir(process.cwd());\n    if (workspaceRoot) {\n      console.log('Detected workspace root:', workspaceRoot);\n    } else {\n      console.log('No workspace root detected.');\n    }\n\n  } catch (error) {\n    console.error('Failed to read project configuration:', (error as Error).message);\n  }\n}\n\ngetProjectConfig();","lang":"typescript","description":"Demonstrates how to find and read project `package.json` and `tsconfig.json` files, and detect the workspace root directory using various utilities from `pkg-types`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}