ex_yarn v0.4.1 ExYarn View Source

ExYarn is a small library for parsing Yarn lockfiles in Elixir. Only the version 1 of Yarn lockfiles is currently supported.

The library allows you to parse either to a plain Elixir map, or to a utility type, ExYarn.Lockfile, which makes manipulating the parsed dependencies a little easier.

Note on performance

This library was built in part as a learning exercise and therefore does not necessarily apply the best possible practices and tools when it comes to code quality and performance. If performance is important to you, I recommend using Dorgan's library (hex.pm, Github), which uses NimbleParsec for better performance.

Example

Parsing to a map

iex> input = ~s(
...># yarn lockfile v1
...>"@babel/code-frame@7.8.3":
...>  version "7.10.4"
...>  resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
...>  integrity sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==
...>  dependencies:
...>    "@babel/highlight" "^7.10.4"
...>)
...> ExYarn.parse(input)
{
  :ok,
  {
    %{
      "@babel/code-frame@7.8.3" => %{
        "version" => "7.10.4",
        "resolved" => "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a",
        "integrity" => "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==",
        "dependencies" => %{"@babel/highlight" => "^7.10.4"}
      }
    },
    [" yarn lockfile v1"]
  }
}

Parsing to a ExYarn.Lockfile

iex> input = ~s(
...># yarn lockfile v1
...>"@babel/code-frame@7.8.3":
...>  version "7.10.4"
...>  resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
...>  integrity sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==
...>  dependencies:
...>    "@babel/highlight" "^7.10.4"
...>)
...>ExYarn.parse_to_lockfile(input)
{
  :ok,
  %ExYarn.Lockfile{
    version: 1,
    dependencies: [
      %ExYarn.Dependency{
        name: "@babel/code-frame@7.8.3",
        version: "7.10.4",
        resolved: "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a",
        integrity: "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==",
        dependencies: [
          {"@babel/highlight", "^7.10.4"}
        ],
        optional_dependencies: []
      }
    ],
    comments: [" yarn lockfile v1"]}}

Link to this section Summary

Functions

Takes the lockfile's content as input and returns the parsed map

Same as ExYarn.parse/1 but raises errors instead of returning them

Takes the lockfile's content as input and returns a parsed ExYarn.Lockfile

Same as ExYarn.parse_to_lockfile/1 but raises errors instead of returning them

Link to this section Functions

Specs

parse(binary()) :: {:error, Exception.t()} | {:ok, {map(), [binary()]}}

Takes the lockfile's content as input and returns the parsed map

Link to this function

parse!(lockfile_content)

View Source

Specs

parse!(binary()) :: {map(), [binary()]}

Same as ExYarn.parse/1 but raises errors instead of returning them

Link to this function

parse_to_lockfile(lockfile_content)

View Source

Specs

parse_to_lockfile(binary()) ::
  {:error, binary() | Exception.t()} | {:ok, ExYarn.Lockfile.t()}

Takes the lockfile's content as input and returns a parsed ExYarn.Lockfile

Link to this function

parse_to_lockfile!(lockfile_content)

View Source

Specs

parse_to_lockfile!(binary()) :: ExYarn.Lockfile.t()

Same as ExYarn.parse_to_lockfile/1 but raises errors instead of returning them