mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-12 14:14:36 +03:00
php: handle dev dependencies (+ noDev flag)
This commit is contained in:
parent
8e7af28ff0
commit
a133520a08
@ -109,6 +109,7 @@ in {
|
|||||||
*/
|
*/
|
||||||
tree,
|
tree,
|
||||||
# arguments defined in `extraArgs` (see below) specified by user
|
# arguments defined in `extraArgs` (see below) specified by user
|
||||||
|
noDev,
|
||||||
...
|
...
|
||||||
} @ args: let
|
} @ args: let
|
||||||
# get the root source and project source
|
# get the root source and project source
|
||||||
@ -122,23 +123,37 @@ in {
|
|||||||
inherit (callPackageDream ../../utils.nix {}) satisfiesSemver;
|
inherit (callPackageDream ../../utils.nix {}) satisfiesSemver;
|
||||||
|
|
||||||
# all the pinned packages
|
# all the pinned packages
|
||||||
packages = composerLock.packages;
|
packages =
|
||||||
|
composerLock.packages
|
||||||
|
++ (
|
||||||
|
if noDev
|
||||||
|
then []
|
||||||
|
else composerLock."packages-dev"
|
||||||
|
);
|
||||||
|
|
||||||
# toplevel php semver
|
# toplevel php semver
|
||||||
phpSemver = composerJson.require."php";
|
phpSemver = composerJson.require."php";
|
||||||
# all the php extensions
|
# all the php extensions
|
||||||
phpExtensions = let
|
phpExtensions = let
|
||||||
all = map (pkg: l.attrsets.attrNames (pkg.require or {})) packages;
|
all = map (pkg: l.attrsets.attrNames (getRequire pkg)) packages;
|
||||||
flat = l.lists.flatten all;
|
flat = l.lists.flatten all;
|
||||||
extensions = l.filter (l.strings.hasPrefix "ext-") flat;
|
extensions = l.filter (l.strings.hasPrefix "ext-") flat;
|
||||||
in
|
in
|
||||||
l.lists.unique extensions;
|
l.lists.unique extensions;
|
||||||
|
|
||||||
# get the requierements without php version pin & without php extensions
|
# get require (and require-dev)
|
||||||
cleanRequire = requires:
|
getRequire = pkg:
|
||||||
|
(
|
||||||
|
if noDev
|
||||||
|
then []
|
||||||
|
else (pkg."require-dev" or {})
|
||||||
|
)
|
||||||
|
// (pkg.require or {});
|
||||||
|
# strip php version & php extensions
|
||||||
|
cleanRequire = deps:
|
||||||
l.filterAttrs
|
l.filterAttrs
|
||||||
(name: _: (name != "php") && !(l.strings.hasPrefix "ext-" name))
|
(name: _: (name != "php") && !(l.strings.hasPrefix "ext-" name))
|
||||||
requires;
|
deps;
|
||||||
|
|
||||||
# resolve semvers into exact versions
|
# resolve semvers into exact versions
|
||||||
pinRequires = dep: let
|
pinRequires = dep: let
|
||||||
@ -148,12 +163,16 @@ in {
|
|||||||
(l.filter (dep: dep.name == name)
|
(l.filter (dep: dep.name == name)
|
||||||
packages)))
|
packages)))
|
||||||
.version;
|
.version;
|
||||||
pinnedRequires =
|
pinAttr = attr:
|
||||||
if "require" ? dep
|
if attr ? dep
|
||||||
then l.mapAttrs pin dep.require
|
then l.mapAttrs pin dep."${attr}"
|
||||||
else {};
|
else {};
|
||||||
in
|
in
|
||||||
dep // {require = pinnedRequires;};
|
dep
|
||||||
|
// {
|
||||||
|
require = pinAttr "require";
|
||||||
|
"require-dev" = pinAttr "require-dev";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
dlib.simpleTranslate2.translate
|
dlib.simpleTranslate2.translate
|
||||||
({objectsByKey, ...}: rec {
|
({objectsByKey, ...}: rec {
|
||||||
@ -201,6 +220,7 @@ in {
|
|||||||
path = projectSource;
|
path = projectSource;
|
||||||
};
|
};
|
||||||
require = (pinRequires composerJson).require;
|
require = (pinRequires composerJson).require;
|
||||||
|
"require-dev" = (pinRequires composerJson)."require-dev";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -222,7 +242,7 @@ in {
|
|||||||
dependencies = rawObj: finalObj:
|
dependencies = rawObj: finalObj:
|
||||||
l.attrsets.mapAttrsToList
|
l.attrsets.mapAttrsToList
|
||||||
(name: version: {inherit name version;})
|
(name: version: {inherit name version;})
|
||||||
(cleanRequire rawObj.require);
|
(cleanRequire (getRequire rawObj));
|
||||||
|
|
||||||
sourceSpec = rawObj: finalObj:
|
sourceSpec = rawObj: finalObj:
|
||||||
if rawObj.source.type == "path"
|
if rawObj.source.type == "path"
|
||||||
@ -248,21 +268,6 @@ in {
|
|||||||
the dream-lock.
|
the dream-lock.
|
||||||
*/
|
*/
|
||||||
extraObjects = [
|
extraObjects = [
|
||||||
# {
|
|
||||||
# name = "foo2";
|
|
||||||
# version = "1.0";
|
|
||||||
# dependencies = [
|
|
||||||
# {
|
|
||||||
# name = "bar2";
|
|
||||||
# version = "1.1";
|
|
||||||
# }
|
|
||||||
# ];
|
|
||||||
# sourceSpec = {
|
|
||||||
# type = "git";
|
|
||||||
# url = "https://...";
|
|
||||||
# rev = "...";
|
|
||||||
# };
|
|
||||||
# }
|
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -274,5 +279,9 @@ in {
|
|||||||
# String arguments contain a default value and examples. Flags do not.
|
# String arguments contain a default value and examples. Flags do not.
|
||||||
# Flags are false by default.
|
# Flags are false by default.
|
||||||
extraArgs = {
|
extraArgs = {
|
||||||
|
noDev = {
|
||||||
|
description = "Exclude development dependencies";
|
||||||
|
type = "flag";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user