mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-23 17:20:31 +03:00
yarn.lock: initial translator
This commit is contained in:
parent
8f4632ab5e
commit
daa71d3e53
@ -12,8 +12,6 @@
|
|||||||
{
|
{
|
||||||
inputDirectories,
|
inputDirectories,
|
||||||
inputFiles,
|
inputFiles,
|
||||||
|
|
||||||
dev,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
@ -23,19 +21,63 @@
|
|||||||
else
|
else
|
||||||
lib.elemAt inputFiles 0;
|
lib.elemAt inputFiles 0;
|
||||||
parser = import ./parser.nix { inherit lib; inherit (externals) nix-parsec;};
|
parser = import ./parser.nix { inherit lib; inherit (externals) nix-parsec;};
|
||||||
parsedLock = parser.parseLock yarnLock;
|
parsedLock = lib.foldAttrs (n: a: n // a) {} (parser.parseLock yarnLock).value;
|
||||||
# TODO: parse input files
|
nameFromLockName = lockName:
|
||||||
|
let
|
||||||
|
version = lib.last (lib.splitString "@" lockName);
|
||||||
|
in
|
||||||
|
lib.removeSuffix "@${version}" lockName;
|
||||||
|
sources = lib.mapAttrs' (dependencyName: dependencyAttrs:
|
||||||
|
let
|
||||||
|
name = nameFromLockName dependencyName;
|
||||||
|
in
|
||||||
|
lib.nameValuePair ("${name}#${dependencyAttrs.version}") (
|
||||||
|
if ! lib.hasInfix "@github:" dependencyName then
|
||||||
|
{
|
||||||
|
version = dependencyAttrs.version;
|
||||||
|
hash = dependencyAttrs.integrity;
|
||||||
|
url = dependencyAttrs.resolved;
|
||||||
|
type = "fetchurl";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
let
|
||||||
|
gitUrlInfos = lib.splitString "/" dependencyAttrs.resolved;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
type = "github";
|
||||||
|
rev = lib.elemAt gitUrlInfos 6;
|
||||||
|
owner = lib.elemAt gitUrlInfos 3;
|
||||||
|
repo = lib.elemAt gitUrlInfos 4;
|
||||||
|
}
|
||||||
|
)) parsedLock;
|
||||||
|
dependencyGraph = lib.mapAttrs' (dependencyName: dependencyAttrs:
|
||||||
|
let
|
||||||
|
name = nameFromLockName dependencyName;
|
||||||
|
dependencies = dependencyAttrs.dependencies or [] ++ dependencyAttrs.optionalDependencies or [];
|
||||||
|
graph = lib.forEach dependencies (dependency:
|
||||||
|
builtins.head (
|
||||||
|
lib.mapAttrsToList (name: value:
|
||||||
|
let
|
||||||
|
yarnName = "${name}@${value}";
|
||||||
|
version = parsedLock."${yarnName}".version;
|
||||||
|
in
|
||||||
|
"${name}#${version}"
|
||||||
|
) dependency
|
||||||
|
)
|
||||||
|
);
|
||||||
|
in
|
||||||
|
lib.nameValuePair ("${name}#${dependencyAttrs.version}") graph) parsedLock;
|
||||||
in
|
in
|
||||||
# TODO: produce dream lock like in /specifications/dream-lock-example.json
|
# TODO: produce dream lock like in /specifications/dream-lock-example.json
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
sources = true;
|
inherit sources;
|
||||||
|
|
||||||
generic = {
|
generic = {
|
||||||
buildSystem = "nodejs";
|
buildSystem = "nodejs";
|
||||||
producedBy = translatorName;
|
producedBy = translatorName;
|
||||||
mainPackage = "test";
|
mainPackage = "test";
|
||||||
dependencyGraph = true;
|
inherit dependencyGraph;
|
||||||
sourcesCombinedHash = null;
|
sourcesCombinedHash = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,12 +99,12 @@
|
|||||||
inputFiles,
|
inputFiles,
|
||||||
}@args:
|
}@args:
|
||||||
{
|
{
|
||||||
inputDirectories = [];
|
inputDirectories = lib.filter
|
||||||
# TODO: insert regex here that matches valid input file names
|
(utils.containsMatchingFile [ ''.*yarn\.lock'' ''.*package.json'' ])
|
||||||
# examples:
|
args.inputDirectories;
|
||||||
# - ".*(requirements).*\\.txt"
|
|
||||||
# - ".*(package-lock\\.json)"
|
inputFiles =
|
||||||
inputFiles = lib.filter (f: builtins.match "# TODO: your regex" f != null) args.inputFiles;
|
lib.filter (f: builtins.match ''.*yarn\.lock'' f != null) args.inputFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -73,25 +115,10 @@
|
|||||||
# String arguments contain a default value and examples. Flags do not.
|
# String arguments contain a default value and examples. Flags do not.
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
|
|
||||||
# Example: string option
|
# optionalDependencies = {
|
||||||
# This will be exposed by the translate CLI command as --arg_the-answer
|
# description = "Whether to include optional dependencies";
|
||||||
the-answer = {
|
# type = "flag";
|
||||||
default = "42";
|
# };
|
||||||
description = "The Answer to the Ultimate Question of Life";
|
|
||||||
examples = [
|
|
||||||
"0"
|
|
||||||
"1234"
|
|
||||||
];
|
|
||||||
type = "argument";
|
|
||||||
};
|
|
||||||
|
|
||||||
# Example: boolean option
|
|
||||||
# This will be exposed by the translate CLI command as --flag_example-flag
|
|
||||||
# The default value of boolean flags is always false
|
|
||||||
flat-earth = {
|
|
||||||
description = "Is the earth flat";
|
|
||||||
type = "flag";
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user