mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 06:21:30 +03:00
fix(nodejs-package-lock-v3): handle multiple versions & auto load packageLock
This commit is contained in:
parent
1202352107
commit
d7a037e723
@ -5,6 +5,8 @@
|
||||
...
|
||||
}: let
|
||||
l = lib // builtins;
|
||||
cfg = config.nodejs-package-lock-v3;
|
||||
|
||||
inherit (config.deps) fetchurl;
|
||||
|
||||
nodejsLockUtils = import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;};
|
||||
@ -68,11 +70,18 @@
|
||||
};
|
||||
};
|
||||
|
||||
parse = lock: (l.mapAttrs' (parseEntry lock) lock.packages);
|
||||
parse = lock:
|
||||
builtins.foldl'
|
||||
(acc: entry:
|
||||
acc
|
||||
// {
|
||||
${entry.name} = acc.${entry.name} or {} // entry.value;
|
||||
})
|
||||
{}
|
||||
# [{name=; value=;} ...]
|
||||
(l.mapAttrsToList (parseEntry lock) lock.packages);
|
||||
|
||||
pdefs = parse config.nodejs-package-lock-v3.packageLock;
|
||||
# cfg = config.nodejs-package-lock-v3;
|
||||
# config.packageLock
|
||||
in {
|
||||
imports = [
|
||||
./interface.nix
|
||||
@ -88,4 +97,7 @@ in {
|
||||
};
|
||||
|
||||
nodejs-package-lock-v3.pdefs = pdefs;
|
||||
nodejs-package-lock-v3.packageLock =
|
||||
lib.mkDefault
|
||||
(builtins.fromJSON (builtins.readFile cfg.packageLockFile));
|
||||
}
|
||||
|
@ -2,21 +2,6 @@
|
||||
# meta? :: {
|
||||
# }
|
||||
# }
|
||||
# // Every package has one entry
|
||||
# pdef.${name}.${version} :: {
|
||||
# // all dependency entries of that package.
|
||||
# // each dependency is guaranteed to have its own entry in 'pdef'
|
||||
# // A package without dependencies has `dependencies = {}` (So dependencies has a constant type)
|
||||
# dependencies = {
|
||||
# ${name} = {
|
||||
# dev :: boolean;
|
||||
# version :: string;
|
||||
# }
|
||||
# } | {}
|
||||
# // Pointing to the source of the package.
|
||||
# // in most cases this is a tarball (tar.gz) which needs to be unpacked by e.g. unpackPhase
|
||||
# source :: Derivation | Path
|
||||
# }
|
||||
{
|
||||
config,
|
||||
options,
|
||||
@ -81,7 +66,6 @@ in {
|
||||
description = ''
|
||||
The package-lock.json file to use.
|
||||
'';
|
||||
default = cfg.source + "/package-lock.json";
|
||||
};
|
||||
packageLock = {
|
||||
type = t.attrs;
|
||||
@ -93,7 +77,7 @@ in {
|
||||
# // each dependency is guaranteed to have its own entry in 'pdef'
|
||||
# // A package without dependencies has `dependencies = {}` (So dependencies has a constant type)
|
||||
# dependencies = {
|
||||
# ${name}.${version} = {
|
||||
# ${name} = {
|
||||
# dev = boolean;
|
||||
# version :: string;
|
||||
# }
|
||||
|
@ -280,6 +280,23 @@ in {
|
||||
};
|
||||
};
|
||||
|
||||
test_multiple_versions = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLockFile = ./multiple-versions-lock.json;
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = lib.attrNames config.nodejs-package-lock-v3.pdefs.strip-ansi;
|
||||
expected = [
|
||||
"3.0.1"
|
||||
"4.0.0"
|
||||
"6.0.0"
|
||||
];
|
||||
};
|
||||
|
||||
# TODO: some infinite recursion occurs when accessing pdef.{name}.{version}.source
|
||||
# test_nodejs_parse_lockfile = let
|
||||
# evaled = eval {
|
||||
|
@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "cowsay",
|
||||
"version": "1.5.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/chalk/node_modules/strip-ansi": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
|
||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/cliui/node_modules/strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
|
||||
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
|
||||
"dependencies": {
|
||||
"ansi-regex": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi/node_modules/strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/yargs/node_modules/strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user