🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@antongolub/lockfile

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antongolub/lockfile

Read, write, and convert npm (v1, v2) and yarn (classic and berry) lockfiles in any directions with reasonable losses.

latest
Source
npmnpm
Version
0.0.0-snapshot.0
Version published
Maintainers
1
Created
Source

lockfile

Read, write, and convert npm (v1, v2) and yarn (classic and berry) lockfiles in any directions with reasonable losses.

Motivation

Every package manager brings its own philosophy of how to describe, store and control projects dependencies. This is awesome for developers, but literally becomes a pain in *** *** headache for isec, devops and release engineers. This lib is a naive attempt to build a pm-independent, generic, extensible and reliable deps representation.

The package manifest contains its own deps requirements, the lockfile defines the deps resolution snapshot*, so both of them are required to build a dependency graph. We can convert this data into a normalized representation for further analysis and processing (for example, to fix vulnerabilities). And then, if necessary, convert back to the original format.

Status

⚠️ Initial draft. Alpha-version

Getting started

Install

yarn add @antongolub/lockfile

Usage

import { parse, format } from '@antongolub/lockfile'

const parsed = parse({
  lockfile: './yarn.lock',
  workspaces: {'': './package.json', 'foo': './packages/foo/package.json'},
})

// output
{
  entries: {
    '@babel/code-frame@7.10.4': {
      name: '@babel/code-frame',
      version: '7.10.4',
      scope: 'prod/dev/peer/opt',
      integrities: {
        sha512: 'hashsum',
        sha256: '...',
        sha1: '...',
        md5: '...'
      },
      reference: {
        sourceType: 'npm/git/file/workspace'
        source: 'uri://remote/address',
        linkType: 'hard/soft',
        link: '<root>path/to/package'
      },
      dependencies: {
        '@babel/highlight': '^7.10.4'
      }
    },
    ...
  },
  meta: {
    lockfile: {
      type: 'yarn',
      version: '5', // metadata format version
    },
    packageJson: {...},
    workspaces: {
      patterns: ['./packages/*'],
      packages: {
        '@qiwi/pijma-core': '<root>/packages/core/package.json'
      }
    }
  },
}

const data = format({
  ...parsed,
  lockfileType: 'yarn-2'
})
// output
`
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
  version: 5
  cacheKey: 8

"@babel/code-frame@npm:7.10.4":
  version: 7.10.4
  resolution: "@babel/code-frame@npm:7.10.4"
...
`

Lockfile (meta) versions

Package managerMeta formatSupported
npm <71x
npm >=72
yarn 1 (classic)1x
yarn 35, 6x
yarn 46, 7

Caveats

  • Only npm links are supported for now
  • npm1: optional: true label is not supported by lockfile formatter

Inspired by

  • synp
  • snyk-nodejs-lockfile-parser

License

MIT

Keywords

lock

FAQs

Package last updated on 15 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts