mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-27 14:51:15 +03:00
nodejsLockUtils: fix computing parent path for workspace packages
This commit is contained in:
parent
64fbb0f415
commit
3fd4c14d36
@ -1,11 +1,15 @@
|
|||||||
{lib, ...}: let
|
{lib, ...}: let
|
||||||
# path = node_modules/@org/lib/node_modules/bar
|
# path = node_modules/@org/lib/node_modules/bar
|
||||||
stripPath = path: let
|
parentPath = path: let
|
||||||
split = lib.splitString "node_modules/" path; # = [ "@org/lib" "bar" ]
|
# noPackages = lib.removePrefix "packages/" path;
|
||||||
suffix = "node_modules/${lib.last split}"; # = "node_modules/bar"
|
packages = lib.splitString "node_modules/" path; # = [ "@org/lib" "bar" ]
|
||||||
nextPath = lib.removeSuffix suffix path; # = "node_modules/@org/lib/node_modules/bar";
|
nextPath = lib.concatStringsSep "node_modules/" (lib.init packages);
|
||||||
in
|
in
|
||||||
lib.removeSuffix "/" nextPath;
|
lib.removeSuffix "/" (
|
||||||
|
if path == nextPath
|
||||||
|
then ""
|
||||||
|
else nextPath
|
||||||
|
);
|
||||||
|
|
||||||
findEntry =
|
findEntry =
|
||||||
# = "attrs"
|
# = "attrs"
|
||||||
@ -22,7 +26,8 @@
|
|||||||
searchPath
|
searchPath
|
||||||
else if currentPath == ""
|
else if currentPath == ""
|
||||||
then throw "${search} not found in package-lock.json."
|
then throw "${search} not found in package-lock.json."
|
||||||
else findEntry packageLock (stripPath currentPath) search;
|
# if the package cannot be found as a sub-dependency, check the parent
|
||||||
|
else findEntry packageLock (parentPath currentPath) search;
|
||||||
in {
|
in {
|
||||||
inherit findEntry stripPath;
|
inherit findEntry parentPath;
|
||||||
}
|
}
|
||||||
|
@ -4,35 +4,32 @@
|
|||||||
nodejsLockUtils ? import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;},
|
nodejsLockUtils ? import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;},
|
||||||
}: {
|
}: {
|
||||||
# test the path strip function
|
# test the path strip function
|
||||||
test_nodejsLockUtils_stripPath_simple = let
|
test_nodejsLockUtils_parentPath_simple = {
|
||||||
nextPath = nodejsLockUtils.stripPath "node_modules/@org/lib/node_modules/bar";
|
expr = nodejsLockUtils.parentPath "node_modules/@org/lib/node_modules/bar";
|
||||||
in {
|
|
||||||
expr = nextPath;
|
|
||||||
expected = "node_modules/@org/lib";
|
expected = "node_modules/@org/lib";
|
||||||
};
|
};
|
||||||
|
|
||||||
test_nodejsLockUtils_stripPath_root = let
|
test_nodejsLockUtils_parentPath_root = {
|
||||||
nextPath = nodejsLockUtils.stripPath "node_modules/bar";
|
expr = nodejsLockUtils.parentPath "node_modules/bar";
|
||||||
in {
|
|
||||||
expr = nextPath;
|
|
||||||
# The root
|
# The root
|
||||||
expected = "";
|
expected = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
test_nodejsLockUtils_stripPath_empty = let
|
test_nodejsLockUtils_parentPath_empty = {
|
||||||
nextPath = nodejsLockUtils.stripPath "";
|
expr = nodejsLockUtils.parentPath "";
|
||||||
in {
|
|
||||||
expr = nextPath;
|
|
||||||
expected = "";
|
expected = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
test_nodejsLockUtils_stripPath_complex = let
|
test_nodejsLockUtils_parentPath_complex = {
|
||||||
nextPath = nodejsLockUtils.stripPath "node_modules/@org/lib/node_modules/bar/node_modules/foo";
|
expr = nodejsLockUtils.parentPath "node_modules/@org/lib/node_modules/bar/node_modules/foo";
|
||||||
in {
|
|
||||||
expr = nextPath;
|
|
||||||
expected = "node_modules/@org/lib/node_modules/bar";
|
expected = "node_modules/@org/lib/node_modules/bar";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test_nodejsLockUtils_parentPath_local_package = {
|
||||||
|
expr = nodejsLockUtils.parentPath "packages/foo";
|
||||||
|
expected = "";
|
||||||
|
};
|
||||||
|
|
||||||
# test the resolve function
|
# test the resolve function
|
||||||
test_nodejsLockUtils_findEntry_argparse = let
|
test_nodejsLockUtils_findEntry_argparse = let
|
||||||
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
|
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
|
||||||
|
Loading…
Reference in New Issue
Block a user