# lockparse

> A lightweight lockfile parser.

Latest version **0.5.2** (published 2026-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install lockparse
pnpm add lockparse
yarn add lockparse
bun add lockparse
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.2 |
| Published | 2026-05-13 |
| First published | 2025-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 25 |
| Author | James Garbutt |
| Maintainers | 43081j |
| Keywords | lockfile, lock, parse, pnpm, npm, yarn |

## Links

- npm: https://www.npmjs.com/package/lockparse
- Repository: https://github.com/43081j/lockparse
- Homepage: https://github.com/43081j/lockparse#readme
- Issues: https://github.com/43081j/lockparse/issues
- npm.io page: https://npm.io/package/lockparse

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.5.2 (latest) — 2026-05-13
- 0.0.1-pre.0 (next) — 2025-10-07
- 0.5.0 — 2025-10-25
- 0.4.0 — 2025-10-25
- 0.3.0 — 2025-10-14
- 0.2.2 — 2025-10-08
- 0.2.1 — 2025-10-07
- 0.2.0 — 2025-10-07

## README

# 🔒 lockparse

> A tiny, zero-dependency lockfile parser for npm, Yarn, pnpm, and Bun.

## Installation

```bash
npm install lockparse
```

## Usage

```ts
import { parse } from 'lockparse';
import { readFile } from 'node:fs/promises';

const lockfileContent = await readFile('./package-lock.json', 'utf-8');
const packageJson = JSON.parse(await readFile('./package.json', 'utf-8'));
const lockfile = await parse(lockfileContent, 'npm', packageJson);

console.log(lockfile.root);
```

## API

### `parse(input, typeOrFileName, packageJson?)`

Parses a lockfile and returns a structured representation of the dependency tree.

#### Parameters

- **`input`** (`string`): The lockfile content as a string
- **`typeOrFileName`** (`string`): The lockfile type or filename. Supported values:
  - `'npm'` or `'package-lock.json'` - npm lockfile
  - `'yarn'` or `'yarn.lock'` - Yarn lockfile
  - `'pnpm'` or `'pnpm-lock.yaml'` - pnpm lockfile
  - `'bun'` or `'bun.lock'` - Bun lockfile
- **`packageJson`** (`PackageJsonLike`, optional): The package.json object (optional but recommended for better accuracy)

#### Returns

`Promise<ParsedLockFile>` - A promise that resolves to an object with:

- **`type`** (`LockFileType`): The detected lockfile type
- **`packages`** (`ParsedDependency[]`): A flat array of all packages in the lockfile
- **`root`** (`ParsedDependency`): The root dependency node representing the project's dependency tree

#### Note: Yarn parsing

When parsing Yarn lockfiles, the `packageJson` parameter is highly recommended. Without it, the root node will not contain any dependencies as the Yarn lock file does not include this information. All packages will however still be contained in the `packages` array.

## License

MIT

---
_Source: https://npm.io/package/lockparse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
