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.
npm install pkg-typesVerified import paths — ran on the pinned version, not inferred.
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`.
Migrate your project to use ES module `import` syntax. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions for files importing `pkg-types`.
Update parsing logic to account for both `string[]` and `object` types for the `workspaces` field when reading `PackageJson` data.
When explicit behavior is needed, specify the full file path to functions like `readPackage` instead of relying solely on directory-based discovery. Alternatively, manage your project's configuration files to avoid ambiguity.
Familiarize yourself with the `findWorkspaceDir` detection order documented in the README. If the default strategy is not suitable, consider using more specific file resolution functions like `findPackage` with custom `filenames` options.
Replace `const { ... } = require('pkg-types')` with `import { ... } from 'pkg-types'`. Ensure your Node.js environment or build setup correctly handles ES modules.Verify that a valid package configuration file exists in the target directory or any parent directories. Ensure the provided path is correct and accessible. Handle the potential error in your application logic.
Confirm that a lock file generated by a package manager (npm, yarn, pnpm, bun, deno) exists in your project. Check the starting path provided to `resolveLockFile` to ensure it's correct.
No dependency data recorded yet.