Skip to content

Commit

Permalink
Attempt to resolve some issues with scoped and circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
notgne2 committed Dec 12, 2019
1 parent 6c7f91c commit 21e7f56
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ in {

# These attrs have already been created in pre-processing
# Cyclic dependencies has deterministic ordering so they will end up with the exact same attributes
name = lib.concatStringsSep "-" (builtins.map (attr: pnpmlock.packages."${attr}".name) pkgInfo.constituents);
name = builtins.substring 0 207 (lib.concatStringsSep "-" (builtins.map (attr: pnpmlock.packages."${attr}".name) pkgInfo.constituents));
version = if !hasCycle then pkgInfo.version else "cyclic";
pname = lib.concatStringsSep "-" (builtins.map (attr: pnpmlock.packages."${attr}".pname) pkgInfo.constituents);

Expand Down
7 changes: 4 additions & 3 deletions derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ in {
sourceRoot = ".";
postUnpack = ''
mkdir -p node_modules
mv pnpm2nix-source-*/* node_modules/
cp -R pnpm2nix-source-*/* node_modules/
rm -r pnpm2nix-source-*
'';

Expand All @@ -77,9 +77,10 @@ in {
if test ! -L "$module"; then
# Check for nested directories (npm calls this scopes)
if test "$(echo "$module" | grep -o '@')" = '@'; then
outdir=$(dirname node_modules/${dep.pname})
scope=$(echo "${dep.pname}" | cut -d/ -f 1)
outdir=node_modules/$scope
mkdir -p "$outdir"
ln -s "$module" $outdir/$(basename "$module")
ln -sf "$module" "$outdir"
else
ln -s "$module" node_modules/$(basename "$module")
fi
Expand Down
6 changes: 3 additions & 3 deletions pnpmlock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ let
#
# The list is sorted to provide the exact same ordering no matter
# where the cycle was entered
cycleConstituents = lib.lists.sort (a: b: a < b) (if hasCycle then
cycleConstituents = lib.unique (lib.lists.sort (a: b: a < b) (if hasCycle then
(lib.lists.sublist cycleIndex (lib.lists.length visitStack) visitStack)
else [ pkgAttr ]);
else [ pkgAttr ]));

# Modify the accumulator with constituents
#
Expand All @@ -228,7 +228,7 @@ let
dependencies = lib.filter (depAttr: !(lib.elem depAttr cycleConstituents)) constituentDeps;
in {
"${attrName}" = (constituent // {
constituents = cycleConstituents;
constituents = lib.unique ((if builtins.hasAttr "constituents" constituent then constituent.constituents else []) ++ cycleConstituents);
inherit dependencies;
});
}))) acc cycleConstituents;
Expand Down

0 comments on commit 21e7f56

Please sign in to comment.