mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 06:21:30 +03:00
init: package-lock.json V3 parser
This commit is contained in:
parent
00b2b09551
commit
44f946d814
28
lib/internal/nodejsLockUtils.nix
Normal file
28
lib/internal/nodejsLockUtils.nix
Normal file
@ -0,0 +1,28 @@
|
||||
{lib, ...}: let
|
||||
# path = node_modules/@org/lib/node_modules/bar
|
||||
stripPath = path: let
|
||||
split = lib.splitString "node_modules/" path; # = [ "@org/lib" "bar" ]
|
||||
suffix = "node_modules/${lib.last split}"; # = "node_modules/bar"
|
||||
nextPath = lib.removeSuffix suffix path; # = "node_modules/@org/lib/node_modules/bar";
|
||||
in
|
||||
lib.removeSuffix "/" nextPath;
|
||||
|
||||
findEntry =
|
||||
# = "attrs"
|
||||
packageLock:
|
||||
# = "my-package/node_modules/@foo/bar"
|
||||
currentPath:
|
||||
# = "kitty"
|
||||
search: let
|
||||
searchPath = lib.removePrefix "/" "${currentPath}/node_modules/${search}"; # = "my-package/node_modules/@foo/bar/node_modules/kitty"
|
||||
in
|
||||
if packageLock.packages ? ${searchPath}
|
||||
then
|
||||
# attribute found in plock
|
||||
searchPath
|
||||
else if currentPath == ""
|
||||
then throw "${search} not found in package-lock.json."
|
||||
else findEntry packageLock (stripPath currentPath) search;
|
||||
in {
|
||||
inherit findEntry stripPath;
|
||||
}
|
91
modules/dream2nix/nodejs-package-lock-v3/default.nix
Normal file
91
modules/dream2nix/nodejs-package-lock-v3/default.nix
Normal file
@ -0,0 +1,91 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
dream2nix,
|
||||
...
|
||||
}: let
|
||||
l = lib // builtins;
|
||||
inherit (config.deps) fetchurl;
|
||||
|
||||
nodejsLockUtils = import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;};
|
||||
|
||||
isLink = plent: plent ? link && plent.link;
|
||||
|
||||
parseSource = plent:
|
||||
if isLink plent
|
||||
then
|
||||
# entry is local file
|
||||
(builtins.dirOf config.nodejs-package-lock-v3.packageLockFile) + "/${plent.resolved}"
|
||||
else
|
||||
fetchurl {
|
||||
url = plent.resolved;
|
||||
hash = plent.integrity;
|
||||
};
|
||||
|
||||
getDependencies = lock: path: plent:
|
||||
l.mapAttrs (name: _descriptor: {
|
||||
dev = plent.dev or false;
|
||||
version = let
|
||||
# Need this util as dependencies no explizitly locked version
|
||||
# This findEntry is needed to find the exact locked version
|
||||
packageIdent = nodejsLockUtils.findEntry lock path name;
|
||||
in
|
||||
# Read version from package-lock entry for the resolved package
|
||||
lock.packages.${packageIdent}.version;
|
||||
})
|
||||
(plent.dependencies or {} // plent.devDependencies or {} // plent.optionalDependencies or {});
|
||||
|
||||
# Takes one entry of "package" from package-lock.json
|
||||
parseEntry = lock: path: entry:
|
||||
if path == ""
|
||||
then {
|
||||
# Root level package
|
||||
name = entry.name;
|
||||
value = {
|
||||
${entry.version} = {
|
||||
dependencies = getDependencies lock path entry;
|
||||
};
|
||||
};
|
||||
}
|
||||
else let
|
||||
source = parseSource entry;
|
||||
version =
|
||||
if isLink entry
|
||||
then let
|
||||
pjs = l.fromJSON (l.readFile (source + "/package.json"));
|
||||
in
|
||||
pjs.version
|
||||
else entry.version;
|
||||
in
|
||||
# Every other package
|
||||
{
|
||||
name = l.last (builtins.split "node_modules/" path);
|
||||
value = {
|
||||
${version} = {
|
||||
dependencies = getDependencies lock path entry;
|
||||
inherit source;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
parse = lock: (l.mapAttrs' (parseEntry lock) lock.packages);
|
||||
|
||||
pdefs = parse config.nodejs-package-lock-v3.packageLock;
|
||||
# cfg = config.nodejs-package-lock-v3;
|
||||
# config.packageLock
|
||||
in {
|
||||
imports = [
|
||||
./interface.nix
|
||||
dream2nix.modules.dream2nix.core
|
||||
];
|
||||
|
||||
# declare external dependencies
|
||||
deps = {nixpkgs, ...}: {
|
||||
inherit
|
||||
(nixpkgs)
|
||||
fetchurl
|
||||
;
|
||||
};
|
||||
|
||||
nodejs-package-lock-v3.pdefs = pdefs;
|
||||
}
|
146
modules/dream2nix/nodejs-package-lock-v3/interface.nix
Normal file
146
modules/dream2nix/nodejs-package-lock-v3/interface.nix
Normal file
@ -0,0 +1,146 @@
|
||||
# subsystemAttrs :: {
|
||||
# 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,
|
||||
lib,
|
||||
dream2nix,
|
||||
specialArgs,
|
||||
...
|
||||
}: let
|
||||
l = lib // builtins;
|
||||
t = l.types;
|
||||
cfg = config.nodejs-package-lock-v3;
|
||||
|
||||
derivationType = t.oneOf [t.str t.path t.package];
|
||||
|
||||
# A stricteer submodule type that prevents derivations from being
|
||||
# detected as modules by accident. (derivations are attrs as well as modules)
|
||||
drvPart = let
|
||||
type = t.submoduleWith {
|
||||
modules = [dream2nix.modules.dream2nix.core];
|
||||
inherit specialArgs;
|
||||
};
|
||||
in
|
||||
type
|
||||
// {
|
||||
# Ensure that derivations are never detected as modules by accident.
|
||||
check = val: type.check val && (val.type or null != "derivation");
|
||||
};
|
||||
|
||||
drvPartOrPackage = t.either derivationType drvPart;
|
||||
|
||||
optPackage = l.mkOption {
|
||||
type = drvPartOrPackage;
|
||||
apply = drv: drv.public or drv;
|
||||
# default = null;
|
||||
};
|
||||
|
||||
# {
|
||||
# dev = boolean;
|
||||
# version :: string;
|
||||
# }
|
||||
depEntryType = t.submodule {
|
||||
options.dev = l.mkOption {
|
||||
type = t.bool;
|
||||
# default = false;
|
||||
};
|
||||
options.version = l.mkOption {
|
||||
type = t.str;
|
||||
};
|
||||
};
|
||||
|
||||
# dependencies = {
|
||||
# ${name} = {
|
||||
# dev = boolean;
|
||||
# version :: string;
|
||||
# }
|
||||
# }
|
||||
dependenciesType = t.attrsOf depEntryType;
|
||||
in {
|
||||
options.nodejs-package-lock-v3 = l.mapAttrs (_: l.mkOption) {
|
||||
packageLockFile = {
|
||||
type = t.nullOr t.path;
|
||||
description = ''
|
||||
The package-lock.json file to use.
|
||||
'';
|
||||
default = cfg.source + "/package-lock.json";
|
||||
};
|
||||
packageLock = {
|
||||
type = t.attrs;
|
||||
description = "The content of the package-lock.json";
|
||||
};
|
||||
|
||||
# pdefs.${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}.${version} = {
|
||||
# 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
|
||||
# }
|
||||
pdefs = {
|
||||
type = t.attrsOf (t.attrsOf (t.submodule {
|
||||
options.dependencies = l.mkOption {
|
||||
type = dependenciesType;
|
||||
};
|
||||
options.source = optPackage;
|
||||
}));
|
||||
};
|
||||
|
||||
# packageJsonFile = {
|
||||
# type = t.path;
|
||||
# description = ''
|
||||
# The package.json file to use.
|
||||
# '';
|
||||
# default = cfg.source + "/package.json";
|
||||
# };
|
||||
# packageJson = {
|
||||
# type = t.attrs;
|
||||
# description = "The content of the package.json";
|
||||
# };
|
||||
# source = {
|
||||
# type = t.either t.path t.package;
|
||||
# description = "Source of the package";
|
||||
# default = config.mkDerivation.src;
|
||||
# };
|
||||
# withDevDependencies = {
|
||||
# type = t.bool;
|
||||
# default = true;
|
||||
# description = ''
|
||||
# Whether to include development dependencies.
|
||||
# Usually it's a bad idea to disable this, as development dependencies can contain important build time dependencies.
|
||||
# '';
|
||||
# };
|
||||
# workspaces = {
|
||||
# type = t.listOf t.str;
|
||||
# description = ''
|
||||
# Workspaces to include.
|
||||
# Defaults to the ones defined in package.json.
|
||||
# '';
|
||||
# };
|
||||
};
|
||||
}
|
300
tests/nix-unit/test_nodejs_lock_v3/default.nix
Normal file
300
tests/nix-unit/test_nodejs_lock_v3/default.nix
Normal file
@ -0,0 +1,300 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
lib ? import <nixpkgs/lib>,
|
||||
dream2nix ? (import (../../../modules + "/flake.nix")).outputs {},
|
||||
}: let
|
||||
eval = module:
|
||||
lib.evalModules {
|
||||
modules = [module];
|
||||
specialArgs = {
|
||||
inherit dream2nix;
|
||||
packageSets = {
|
||||
nixpkgs = pkgs;
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
# test if dependencies are ignored successfully in pip.rootDependencies
|
||||
test_nodejs_parse_root_lock = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLock = lib.mkForce {
|
||||
# Example content of lockfile
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"lockfileVersion" = 3;
|
||||
"requires" = true;
|
||||
"packages" = {
|
||||
"" = {
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"license" = "ISC";
|
||||
"dependencies" = {
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
# This needs to be set by the user / we can set this automatically later
|
||||
nodejs-package-lock-v3.pdefs."minimal"."1.0.0".source = "";
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.nodejs-package-lock-v3.pdefs;
|
||||
expected = {
|
||||
"minimal"."1.0.0" = {
|
||||
dependencies = {};
|
||||
source = "";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# test if dependencies are ignored successfully in pip.rootDependencies
|
||||
test_nodejs_fetch_dep = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLock = lib.mkForce {
|
||||
# Example content of lockfile
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"lockfileVersion" = 3;
|
||||
"requires" = true;
|
||||
"packages" = {
|
||||
"node_modules/async" = {
|
||||
"version" = "0.2.10";
|
||||
"resolved" = "https://registry.npmjs.org/async/-/async-0.2.10.tgz";
|
||||
"integrity" = "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==";
|
||||
};
|
||||
# "node_modules/@org/async" = {
|
||||
# "version" = "0.2.10";
|
||||
# "resolved" = "https://registry.npmjs.org/async/-/async-0.2.10.tgz";
|
||||
# "integrity" = "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==";
|
||||
# };
|
||||
};
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.nodejs-package-lock-v3.pdefs."async"."0.2.10".source.type;
|
||||
expected = "derivation";
|
||||
};
|
||||
|
||||
# test if dependencies are ignored successfully in pip.rootDependencies
|
||||
test_nodejs_file_dep = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLockFile = ./package-lock.json;
|
||||
nodejs-package-lock-v3.packageLock = lib.mkForce {
|
||||
# Example content of lockfile
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"lockfileVersion" = 3;
|
||||
"requires" = true;
|
||||
"packages" = {
|
||||
"node_modules/@org/lib" = {
|
||||
"resolved" = "./lib";
|
||||
"link" = true;
|
||||
};
|
||||
"node_modules/@org/async" = {
|
||||
"version" = "0.2.10";
|
||||
"resolved" = "https://registry.npmjs.org/async/-/async-0.2.10.tgz";
|
||||
"integrity" = "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.nodejs-package-lock-v3.pdefs."@org/lib"."1.0.0".source;
|
||||
expected = ./. + "/lib";
|
||||
};
|
||||
|
||||
# test if dependencies are ignored successfully in pip.rootDependencies
|
||||
test_nodejs_resolve_single_dependency = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLockFile = ./package-lock.json;
|
||||
nodejs-package-lock-v3.packageLock = lib.mkForce {
|
||||
# Example content of lockfile
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"lockfileVersion" = 3;
|
||||
"requires" = true;
|
||||
"packages" = {
|
||||
"" = {
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"license" = "ISC";
|
||||
"dependencies" = {
|
||||
"@org/async" = "^0.2.0";
|
||||
};
|
||||
};
|
||||
"node_modules/@org/async" = {
|
||||
"version" = "0.2.10";
|
||||
"resolved" = "https://registry.npmjs.org/async/-/async-0.2.10.tgz";
|
||||
"integrity" = "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.nodejs-package-lock-v3.pdefs."minimal"."1.0.0".dependencies;
|
||||
expected = {
|
||||
"@org/async" = {
|
||||
dev = false;
|
||||
version = "0.2.10";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test_nodejs_resolve_nested_dependency = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLockFile = ./package-lock.json;
|
||||
nodejs-package-lock-v3.packageLock = lib.mkForce {
|
||||
# Example content of lockfile
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"lockfileVersion" = 3;
|
||||
"requires" = true;
|
||||
"packages" = {
|
||||
"node_modules/foo" = {
|
||||
"version" = "1.0.0";
|
||||
"dependencies" = {
|
||||
"@org/async" = "^0.2.10";
|
||||
};
|
||||
};
|
||||
# expect to resolve this
|
||||
"node_modules/foo/node_modules/@org/async" = {
|
||||
"version" = "0.2.10";
|
||||
"resolved" = "https://registry.npmjs.org/async/-/async-0.2.10.tgz";
|
||||
"integrity" = "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==";
|
||||
};
|
||||
# expect to NOT resolve this
|
||||
"node_modules/@org/async" = {
|
||||
"version" = "1.0.0";
|
||||
"resolved" = "https://registry.npmjs.org/async/-/async-0.2.10.tgz";
|
||||
"integrity" = "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.nodejs-package-lock-v3.pdefs."foo"."1.0.0".dependencies;
|
||||
expected = {
|
||||
"@org/async" = {
|
||||
dev = false;
|
||||
version = "0.2.10";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test_nodejs_resolve_hoisted_dependency = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLockFile = ./package-lock.json;
|
||||
nodejs-package-lock-v3.packageLock = lib.mkForce {
|
||||
# Example content of lockfile
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"lockfileVersion" = 3;
|
||||
"packages" = {
|
||||
"node_modules/foo" = {
|
||||
"version" = "1.0.0";
|
||||
"dependencies" = {
|
||||
"@org/async" = "^0.2.10";
|
||||
};
|
||||
};
|
||||
# expect to NOT resolve this
|
||||
"node_modules/other/node_modules/@org/async" = {
|
||||
"version" = "1.0.0";
|
||||
};
|
||||
# expect to resolve this
|
||||
"node_modules/@org/async" = {
|
||||
"version" = "0.2.10";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.nodejs-package-lock-v3.pdefs."foo"."1.0.0".dependencies;
|
||||
expected = {
|
||||
"@org/async" = {
|
||||
dev = false;
|
||||
version = "0.2.10";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test_nodejs_resolve_dev_dependency = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
];
|
||||
nodejs-package-lock-v3.packageLockFile = ./package-lock.json;
|
||||
nodejs-package-lock-v3.packageLock = lib.mkForce {
|
||||
# Example content of lockfile
|
||||
"name" = "minimal";
|
||||
"version" = "1.0.0";
|
||||
"lockfileVersion" = 3;
|
||||
"packages" = {
|
||||
"node_modules/foo" = {
|
||||
"version" = "1.0.0";
|
||||
"devDependencies" = {
|
||||
"@org/async" = "^0.2.10";
|
||||
};
|
||||
};
|
||||
# expect to NOT resolve this
|
||||
"node_modules/other/node_modules/@org/async" = {
|
||||
"version" = "1.0.0";
|
||||
};
|
||||
# expect to resolve this
|
||||
"node_modules/@org/async" = {
|
||||
"version" = "0.2.10";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.nodejs-package-lock-v3.pdefs."foo"."1.0.0".dependencies;
|
||||
expected = {
|
||||
"@org/async" = {
|
||||
dev = false;
|
||||
version = "0.2.10";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# TODO: some infinite recursion occurs when accessing pdef.{name}.{version}.source
|
||||
# test_nodejs_parse_lockfile = let
|
||||
# evaled = eval {
|
||||
# imports = [
|
||||
# dream2nix.modules.dream2nix.nodejs-package-lock-v3
|
||||
# ];
|
||||
# nodejs-package-lock-v3.packageLockFile = ./package-lock.json;
|
||||
# nodejs-package-lock-v3.packageLock = lib.mkForce (builtins.fromJSON (builtins.readFile ./package-lock.json));
|
||||
# # set the root package source
|
||||
# nodejs-package-lock-v3.pdefs."minimal"."1.0.0".source = "";
|
||||
# };
|
||||
# config = evaled.config;
|
||||
# in {
|
||||
# expr = config.nodejs-package-lock-v3.pdefs."argparse"."0.1.16";
|
||||
# expected = {
|
||||
# };
|
||||
# };
|
||||
}
|
12
tests/nix-unit/test_nodejs_lock_v3/lib/package.json
Normal file
12
tests/nix-unit/test_nodejs_lock_v3/lib/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "lib",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
101
tests/nix-unit/test_nodejs_lock_v3/package-lock.json
generated
Normal file
101
tests/nix-unit/test_nodejs_lock_v3/package-lock.json
generated
Normal file
@ -0,0 +1,101 @@
|
||||
{
|
||||
"name": "minimal",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "minimal",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"kitten": "^0.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"bla": "foo"
|
||||
}
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "0.1.16",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz",
|
||||
"integrity": "sha512-LjmC2dNpdn2L4UzyoaIr11ELYoLn37ZFy9zObrQFHsSuOepeUEMKnM8w5KL4Tnrp2gy88rRuQt6Ky8Bjml+Baw==",
|
||||
"dependencies": {
|
||||
"underscore": "~1.7.0",
|
||||
"underscore.string": "~2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/async": {
|
||||
"version": "0.2.10",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
|
||||
"integrity": "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ=="
|
||||
},
|
||||
"node_modules/esprima": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz",
|
||||
"integrity": "sha512-rp5dMKN8zEs9dfi9g0X1ClLmV//WRyk/R15mppFNICIFRG5P92VP7Z04p8pk++gABo9W2tY+kHyu6P1mEHgmTA==",
|
||||
"bin": {
|
||||
"esparse": "bin/esparse.js",
|
||||
"esvalidate": "bin/esvalidate.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-2.1.3.tgz",
|
||||
"integrity": "sha512-2ElQ5tUBsI5GIjddfYGdudelD5+9JM9FfJXlrn+Mj3k72t4XrqBr3vf3+1sky0WKC3dSVhF0ZqIUpX9QFBmmfQ==",
|
||||
"dependencies": {
|
||||
"argparse": "~ 0.1.11",
|
||||
"esprima": "~ 1.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"js-yaml": "bin/js-yaml.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/kitten": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/kitten/-/kitten-0.0.2.tgz",
|
||||
"integrity": "sha512-OAxjUlTdnuVacqvwmjfz40qqVv4zc7Y8/l2p0FEpNKnEXdn4DlKaxPQRGyU1VdvORAIAaQqcBP5O33S5WhCeIQ==",
|
||||
"dependencies": {
|
||||
"async": "0.2.x",
|
||||
"js-yaml": "2.1.x",
|
||||
"lodash": "1.3.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.x"
|
||||
}
|
||||
},
|
||||
"node_modules/@org/nested/node_modules/kitten": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/kitten/-/kitten-0.0.2.tgz",
|
||||
"integrity": "sha512-OAxjUlTdnuVacqvwmjfz40qqVv4zc7Y8/l2p0FEpNKnEXdn4DlKaxPQRGyU1VdvORAIAaQqcBP5O33S5WhCeIQ==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-1.3.1.tgz",
|
||||
"integrity": "sha512-F7AB8u+6d00CCgnbjWzq9fFLpzOMCgq6mPjOW4+8+dYbrnc0obRrC+IHctzfZ1KKTQxX0xo/punrlpOWcf4gpw==",
|
||||
"engines": [
|
||||
"node",
|
||||
"rhino"
|
||||
]
|
||||
},
|
||||
"node_modules/underscore": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
|
||||
"integrity": "sha512-cp0oQQyZhUM1kpJDLdGO1jPZHgS/MpzoWYfe9+CM2h/QGDZlqwT2T3YGukuBdaNJ/CAPoeyAZRRHz8JFo176vA=="
|
||||
},
|
||||
"node_modules/underscore.string": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.4.0.tgz",
|
||||
"integrity": "sha512-yxkabuCaIBnzfIvX3kBxQqCs0ar/bfJwDnFEHJUm/ZrRVhT3IItdRF5cZjARLzEnyQYtIUhsZ2LG2j3HidFOFQ==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
tests/nix-unit/test_nodejs_lockutils/default.nix
Normal file
77
tests/nix-unit/test_nodejs_lockutils/default.nix
Normal file
@ -0,0 +1,77 @@
|
||||
{
|
||||
# pkgs ? import <nixpkgs> {},
|
||||
lib ? import <nixpkgs/lib>,
|
||||
nodejsLockUtils ? import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;},
|
||||
}: {
|
||||
# test the path strip function
|
||||
test_nodejsLockUtils_stripPath_simple = let
|
||||
nextPath = nodejsLockUtils.stripPath "node_modules/@org/lib/node_modules/bar";
|
||||
in {
|
||||
expr = nextPath;
|
||||
expected = "node_modules/@org/lib";
|
||||
};
|
||||
|
||||
test_nodejsLockUtils_stripPath_root = let
|
||||
nextPath = nodejsLockUtils.stripPath "node_modules/bar";
|
||||
in {
|
||||
expr = nextPath;
|
||||
# The root
|
||||
expected = "";
|
||||
};
|
||||
|
||||
test_nodejsLockUtils_stripPath_empty = let
|
||||
nextPath = nodejsLockUtils.stripPath "";
|
||||
in {
|
||||
expr = nextPath;
|
||||
expected = "";
|
||||
};
|
||||
|
||||
test_nodejsLockUtils_stripPath_complex = let
|
||||
nextPath = nodejsLockUtils.stripPath "node_modules/@org/lib/node_modules/bar/node_modules/foo";
|
||||
in {
|
||||
expr = nextPath;
|
||||
expected = "node_modules/@org/lib/node_modules/bar";
|
||||
};
|
||||
|
||||
# test the resolve function
|
||||
test_nodejsLockUtils_findEntry_argparse = let
|
||||
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
|
||||
path = nodejsLockUtils.findEntry plock "" "argparse";
|
||||
in {
|
||||
expr = path;
|
||||
expected = "node_modules/argparse";
|
||||
};
|
||||
|
||||
test_nodejsLockUtils_findEntry_notFound = let
|
||||
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
|
||||
path = builtins.tryEval (nodejsLockUtils.findEntry plock "" "foo");
|
||||
in {
|
||||
expr = path;
|
||||
expected = {
|
||||
success = false;
|
||||
value = false;
|
||||
};
|
||||
};
|
||||
|
||||
test_nodejsLockUtils_findEntry_deepNested_kitten = let
|
||||
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
|
||||
path =
|
||||
nodejsLockUtils.findEntry plock
|
||||
"node_modules/@org/nested/node_modules/foo"
|
||||
"kitten";
|
||||
in {
|
||||
expr = path;
|
||||
expected = "node_modules/@org/nested/node_modules/kitten";
|
||||
};
|
||||
|
||||
test_nodejsLockUtils_findEntry_hoisted = let
|
||||
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
|
||||
path =
|
||||
nodejsLockUtils.findEntry plock
|
||||
"node_modules/argparse"
|
||||
"underscore";
|
||||
in {
|
||||
expr = path;
|
||||
expected = "node_modules/underscore";
|
||||
};
|
||||
}
|
101
tests/nix-unit/test_nodejs_lockutils/package-lock.json
generated
Normal file
101
tests/nix-unit/test_nodejs_lockutils/package-lock.json
generated
Normal file
@ -0,0 +1,101 @@
|
||||
{
|
||||
"name": "minimal",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "minimal",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"kitten": "^0.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"bla": "foo"
|
||||
}
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "0.1.16",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz",
|
||||
"integrity": "sha512-LjmC2dNpdn2L4UzyoaIr11ELYoLn37ZFy9zObrQFHsSuOepeUEMKnM8w5KL4Tnrp2gy88rRuQt6Ky8Bjml+Baw==",
|
||||
"dependencies": {
|
||||
"underscore": "~1.7.0",
|
||||
"underscore.string": "~2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/async": {
|
||||
"version": "0.2.10",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
|
||||
"integrity": "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ=="
|
||||
},
|
||||
"node_modules/esprima": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.0.4.tgz",
|
||||
"integrity": "sha512-rp5dMKN8zEs9dfi9g0X1ClLmV//WRyk/R15mppFNICIFRG5P92VP7Z04p8pk++gABo9W2tY+kHyu6P1mEHgmTA==",
|
||||
"bin": {
|
||||
"esparse": "bin/esparse.js",
|
||||
"esvalidate": "bin/esvalidate.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-2.1.3.tgz",
|
||||
"integrity": "sha512-2ElQ5tUBsI5GIjddfYGdudelD5+9JM9FfJXlrn+Mj3k72t4XrqBr3vf3+1sky0WKC3dSVhF0ZqIUpX9QFBmmfQ==",
|
||||
"dependencies": {
|
||||
"argparse": "~ 0.1.11",
|
||||
"esprima": "~ 1.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"js-yaml": "bin/js-yaml.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/kitten": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/kitten/-/kitten-0.0.2.tgz",
|
||||
"integrity": "sha512-OAxjUlTdnuVacqvwmjfz40qqVv4zc7Y8/l2p0FEpNKnEXdn4DlKaxPQRGyU1VdvORAIAaQqcBP5O33S5WhCeIQ==",
|
||||
"dependencies": {
|
||||
"async": "0.2.x",
|
||||
"js-yaml": "2.1.x",
|
||||
"lodash": "1.3.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.8.x"
|
||||
}
|
||||
},
|
||||
"node_modules/@org/nested/node_modules/kitten": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/kitten/-/kitten-0.0.2.tgz",
|
||||
"integrity": "sha512-OAxjUlTdnuVacqvwmjfz40qqVv4zc7Y8/l2p0FEpNKnEXdn4DlKaxPQRGyU1VdvORAIAaQqcBP5O33S5WhCeIQ==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-1.3.1.tgz",
|
||||
"integrity": "sha512-F7AB8u+6d00CCgnbjWzq9fFLpzOMCgq6mPjOW4+8+dYbrnc0obRrC+IHctzfZ1KKTQxX0xo/punrlpOWcf4gpw==",
|
||||
"engines": [
|
||||
"node",
|
||||
"rhino"
|
||||
]
|
||||
},
|
||||
"node_modules/underscore": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
|
||||
"integrity": "sha512-cp0oQQyZhUM1kpJDLdGO1jPZHgS/MpzoWYfe9+CM2h/QGDZlqwT2T3YGukuBdaNJ/CAPoeyAZRRHz8JFo176vA=="
|
||||
},
|
||||
"node_modules/underscore.string": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.4.0.tgz",
|
||||
"integrity": "sha512-yxkabuCaIBnzfIvX3kBxQqCs0ar/bfJwDnFEHJUm/ZrRVhT3IItdRF5cZjARLzEnyQYtIUhsZ2LG2j3HidFOFQ==",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user