mindscreen/yarnlock

A package for parsing and interpreting yarn.lock files

Package info

github.com/mindscreen/yarnlock

pkg:composer/mindscreen/yarnlock

Statistics

Installs: 170 568

Dependents: 4

Suggesters: 0

Stars: 4

Open Issues: 4

v1.1.1 2024-10-25 12:18 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 1444dd5b50a4e66a85ef40127f13f0a2692e0b0f

  • Matthias Klatte <matthias.klatte.woop@mindscreen.de>

This package is auto-updated.

Last update: 2026-06-28 01:32:09 UTC


README

👁 CircleCI
👁 codecov

A php-package for parsing and evaluating the yarn.lock format.

Basic Usage

<?php
use Mindscreen\YarnLock;

$yarnLock = YarnLock::fromString(file_get_contents('yarn.lock'));

$allPackages = $yarnLock->getPackages();
$hasBabelCore = $yarnLock->hasPackage('babel-core', '^6.0.0');
$babelCorePackages = $yarnLock->getPackagesByName('babel-core');
$babelCoreDependencies = $babelCorePackages[0]->getDependencies();

Package Depth

If you maybe don't just want all packages but only the direct dependencies plus one level of indirection, you have to go a little extra mile:

<?php
use Mindscreen\YarnLock;
// read the dependencies from the package.json file
$packageDependencies = (json_decode(file_get_contents('package.json')))->dependencies;
// get these packages from the yarn lock-file
$rootDependencies = array_map(function($packageName, $packageVersion) use ($yarnLock) {
 return $yarnLock->getPackage($packageName, $packageVersion);
}, array_keys($packageDependencies), array_values($packageDependencies));
// some of our dependencies might be used by other dependencies deeper down the tree so
// they wouldn't appear in the top levels, if we wouldn't explicitly set them there.
$yarnLock->calculateDepth($rootDependencies);

// get the first two levels; the second argument is the exclusive upper limit
$yarnLock->getPackagesByDepth(0, 2);