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

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
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
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
gjaldon
As the title states, EctoEnum has just been updated after some time of hardly any activity in the repo. Here’s the latest release: https:...
New

Other popular topics Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

Sub Categories:

We're in Beta

About us Mission Statement