From 9801e6e53dc321e860c822f7f3c370e76d218a42 Mon Sep 17 00:00:00 2001 From: Richard Wallace Date: Wed, 5 Jan 2022 13:09:34 -0700 Subject: [PATCH] yarn2nix: preserve top-level package.json resolutions field in workspace The `package.json` produced when building node_modules for a workspace ignores the `resolutions` from the project `package.json`. This results in dependencies being resolved in a way that conflicts with the `yarn.lock` file. To fix this, we need to preserve the `resolutions`. --- .../tools/yarn2nix-moretea/yarn2nix/default.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix index b0bf715e66e..01b9e44623a 100644 --- a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix +++ b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix @@ -74,6 +74,7 @@ in rec { preBuild ? "", postBuild ? "", workspaceDependencies ? [], # List of yarn packages + packageResolutions ? {}, }: let extraBuildInputs = (lib.flatten (builtins.map (key: @@ -93,7 +94,7 @@ in rec { workspaceJSON = pkgs.writeText "${name}-workspace-package.json" - (builtins.toJSON { private = true; workspaces = ["deps/**"]; }); # scoped packages need second splat + (builtins.toJSON { private = true; workspaces = ["deps/**"]; resolutions = packageResolutions; }); # scoped packages need second splat workspaceDependencyLinks = lib.concatMapStringsSep "\n" (dep: '' @@ -170,6 +171,8 @@ in rec { packageGlobs = package.workspaces; + packageResolutions = package.resolutions or {}; + globElemToRegex = lib.replaceStrings ["*"] [".*"]; # PathGlob -> [PathGlobElem] @@ -217,7 +220,7 @@ in rec { inherit name; value = mkYarnPackage ( builtins.removeAttrs attrs ["packageOverrides"] - // { inherit src packageJSON yarnLock workspaceDependencies; } + // { inherit src packageJSON yarnLock packageResolutions workspaceDependencies; } // lib.attrByPath [name] {} packageOverrides ); }) @@ -239,6 +242,7 @@ in rec { extraBuildInputs ? [], publishBinsFor ? null, workspaceDependencies ? [], # List of yarnPackages + packageResolutions ? {}, ... }@attrs: let @@ -258,7 +262,7 @@ in rec { preBuild = yarnPreBuild; postBuild = yarnPostBuild; workspaceDependencies = workspaceDependenciesTransitive; - inherit packageJSON pname version yarnLock offlineCache yarnFlags pkgConfig; + inherit packageJSON pname version yarnLock offlineCache yarnFlags pkgConfig packageResolutions; }; publishBinsFor_ = unlessNull publishBinsFor [pname]; @@ -292,7 +296,7 @@ in rec { '') workspaceDependenciesTransitive; - in stdenv.mkDerivation (builtins.removeAttrs attrs ["yarnNix" "pkgConfig" "workspaceDependencies"] // { + in stdenv.mkDerivation (builtins.removeAttrs attrs ["yarnNix" "pkgConfig" "workspaceDependencies" "packageResolutions"] // { inherit src pname; name = baseName;