dorgan

dorgan

YarnParser - A parser for Yarn lockfiles

Someone in the Elixir’s Discord guild needed a parser for yarn lock files, and I wanted to try and learn parser combinators, so I wrote a yarn lock files parser

hex.pm
Documentation
GitHub repo

Example usage:

iex> input = 
  """
  # Some comment
  # yarn lockfile v1
  key1, key2:
    val1 true
    subkey1:
      val2 123
  """

iex> {:ok, parsed} = YarnParser.decode(input)
iex> parsed
{:ok,
  %{
    "comments" => ["# Some comment", "# yarn lockfile v1"],
    "key1" => %{
      "val1" => true,
      "subkey1" => %{
        "val2" => 123
      }
    },
    "key2" => %{
      "val1" => true,
      "subkey1" => %{
        "val2" => 123
      }
    }
  }
}

iex> YarnParser.get_version(parsed)
1

It currently doesn’t handle merge conflicts like the original parser and I need to improve error messages(mostly regarding invalid indentation).

Most Liked

kitplummer

kitplummer

I’m pretty sure I know who it was that was looking to parse a yarn.lock file. :smiley: I’ve been building some tooling to support analysis of dependencies in different language ecosystems as part of a research project. I asked a student to look into it - as both an exercise in understanding the “lock” model, as well as digging into parsers and behaviours in Elixir. We’ve been using the YarnParser, which works great.

axelson

axelson

Scenic Core Team

It could also be used to generate a bill of materials like the one used in SBoM - Mix task to generate a Software Bill-of-Materials (SBoM)

dorgan

dorgan

Version 0.4.0 was published

It turns out Yarn 2 now uses YAML instead of their own format, so now YarnParser uses YamlElixir to parse newer lockfiles. Version detection is automatic.

There was also a change in the API, the decode function returns a YarnLock struct that holds lockfile metadata and dependencies. It should be easier to get the lockfile’s version and other stuff now.

dorgan

dorgan

I published version 0.3.0, it renames YarnParser.parse to YarnParser.decode and adds encoding functionality:

%{
  "prop1" => "val1",
  "block1" => %{
    "prop2" => true
  },
  "prop3" => 123
} |> YarnParser.encode()
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1

block1:
  prop2 true

prop1 val1
prop3 123

Where Next?

Popular in Libraries Top

Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 13801 100
New
marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
zoltanszogyenyi
Hey everyone :wave: Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-source U...
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
bryanjos
Hi, I just published version 0.23.0 of Elixirscript. Most of the changes are around JavaScript interop now that Elixirscript uses the ...
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Sub Categories:

We're in Beta

About us Mission Statement