What is @pnpm/lockfile-file?
@pnpm/lockfile-file is a utility package for handling lockfiles in the pnpm package manager. It provides functionalities to read, write, and manipulate lockfiles, which are essential for ensuring consistent and reproducible builds in a pnpm-managed project.
What are @pnpm/lockfile-file's main functionalities?
Read Lockfile
This feature allows you to read the wanted lockfile from a specified directory. The `readWantedLockfile` function reads the lockfile and returns its contents, which can be used for further processing or analysis.
const { readWantedLockfile } = require('@pnpm/lockfile-file');
const lockfile = readWantedLockfile('/path/to/project', { ignoreIncompatible: false });
console.log(lockfile);
Write Lockfile
This feature allows you to write a lockfile to a specified directory. The `writeWantedLockfile` function takes the directory path and the lockfile content as arguments and writes the lockfile to the specified location.
const { writeWantedLockfile } = require('@pnpm/lockfile-file');
const lockfile = { /* lockfile content */ };
writeWantedLockfile('/path/to/project', lockfile);
console.log('Lockfile written successfully');
Update Lockfile
This feature allows you to update an existing lockfile with new information. The `updateLockfile` function takes the current lockfile content and the updates as arguments and returns the updated lockfile.
const { updateLockfile } = require('@pnpm/lockfile-file');
const lockfile = { /* existing lockfile content */ };
const updatedLockfile = updateLockfile(lockfile, { /* updates */ });
console.log(updatedLockfile);
Other packages similar to @pnpm/lockfile-file
lockfile
The `lockfile` package is a generic library for reading and writing lockfiles. It is not specific to any package manager and can be used for various purposes. Compared to @pnpm/lockfile-file, it offers more general functionalities but lacks pnpm-specific features.
yarnlockfile
The `yarnlockfile` package is a utility for parsing and stringifying Yarn lockfiles. It is specific to the Yarn package manager and provides functionalities similar to @pnpm/lockfile-file but for Yarn. It does not support pnpm lockfiles.
npm-lockfile
The `npm-lockfile` package is a utility for working with npm lockfiles. It provides functionalities to read, write, and manipulate npm lockfiles. While it offers similar features to @pnpm/lockfile-file, it is tailored for npm and does not support pnpm lockfiles.
@pnpm/lockfile-file
Read/write pnpm-lock.yaml files
Reads and writes the wanted (pnpm-lock.yaml
) and current (node_modules/.pnpm-lock.yaml
) lockfile files of pnpm.
Lockfile files are the state files of the node_modules
installed via pnpm. They are like
the package-lock.json
of npm or the yarn.lock
of Yarn.
Install
pnpm add @pnpm/lockfile-file
API
readWantedLockfile(pkgPath, opts) => Promise<Lockfile>
Reads the pnpm-lock.yaml
file from the root of the package.
Arguments
pkgPath
- Path - the path to the projectopts.ignoreIncompatible
- Boolean - false
by default. If true
, throws an error
if the lockfile file format is not compatible with the current library.
readCurrentLockfile(virtualStoreDir, opts) => Promise<Lockfile>
Reads the lockfile file from <virtualStoreDir>/lock.yaml
.
existsWantedLockfile(pkgPath) => Promise<Boolean>
Returns true
if a pnpm-lock.yaml
exists in the root of the package.
writeLockfiles(opts) => Promise<void>
Writes the wanted/current lockfile files. When they are empty, removes them.
Arguments
opts.wantedLockfile
opts.wantedLockfileDir
opts.currentLockfile
opts.currentLockfileDir
[opts.forceSharedFormat]
writeWantedLockfile(pkgPath, wantedLockfile) => Promise<void>
Writes the wanted lockfile file only. Sometimes it is needed just to update the wanted lockfile
without touching node_modules
.
writeCurrentLockfile(virtualStoreDir, currentLockfile) => Promise<void>
Writes the current lockfile file only.
License
MIT