What is @types/yarnpkg__lockfile?
@types/yarnpkg__lockfile provides TypeScript type definitions for the yarnpkg/lockfile package, which is used to parse and stringify Yarn lockfiles. This package allows developers to work with Yarn lockfiles in a type-safe manner, ensuring that the data structures and methods used are correctly typed.
What are @types/yarnpkg__lockfile's main functionalities?
Parse Yarn Lockfile
This feature allows you to parse a Yarn lockfile into a JavaScript object. The `parse` function reads the contents of a `yarn.lock` file and converts it into a JSON object that can be easily manipulated.
const { parse } = require('@yarnpkg/lockfile');
const fs = require('fs');
const file = fs.readFileSync('./yarn.lock', 'utf8');
const json = parse(file);
console.log(json);
Stringify Yarn Lockfile
This feature allows you to convert a JavaScript object back into a Yarn lockfile format. The `stringify` function takes a JSON object representing the lockfile and converts it into a string that can be written to a `yarn.lock` file.
const { stringify } = require('@yarnpkg/lockfile');
const json = {
'package-a@^1.0.0': {
version: '1.0.1',
resolved: 'https://registry.yarnpkg.com/package-a/-/package-a-1.0.1.tgz',
integrity: 'sha512-...',
dependencies: {
'package-b': '^2.0.0'
}
}
};
const lockfile = stringify(json);
console.log(lockfile);
Other packages similar to @types/yarnpkg__lockfile
npm-lockfile
The `npm-lockfile` package is designed specifically for working with npm lockfiles. It provides methods to parse and manipulate npm's `package-lock.json` files. While it serves a similar purpose, it is tailored for npm rather than Yarn.
Installation
npm install --save @types/yarnpkg__lockfile
Summary
This package contains type definitions for @yarnpkg/lockfile (https://github.com/yarnpkg/yarn/tree/master/packages/lockfile).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/yarnpkg__lockfile.
export interface Dependency {
[packageName: string]: string;
}
export interface FirstLevelDependency {
version: string;
resolved?: string | undefined;
dependencies?: Dependency | undefined;
}
export interface LockFileObject {
[packageName: string]: FirstLevelDependency;
}
export function parse(
file: string,
fileLoc?: string,
): {
type: "success" | "merge" | "conflict";
object: LockFileObject;
};
export function stringify(
json: any,
noHeader?: boolean,
enableVersions?: boolean,
): string;
Additional Details
- Last updated: Tue, 07 Nov 2023 15:11:36 GMT
- Dependencies: none
Credits
These definitions were written by Eric Wang.