Merge pull request #128119 from Simspace/yarn2nix-preserve-resolutions

yarn2nix: preserve top-level package.json resolutions field in workspace
This commit is contained in:
Silvan Mosberger 2022-03-24 05:00:51 +01:00 committed by GitHub
commit c7b52869d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -74,6 +74,7 @@ in rec {
preBuild ? "", preBuild ? "",
postBuild ? "", postBuild ? "",
workspaceDependencies ? [], # List of yarn packages workspaceDependencies ? [], # List of yarn packages
packageResolutions ? {},
}: }:
let let
extraNativeBuildInputs = extraNativeBuildInputs =
@ -98,7 +99,7 @@ in rec {
workspaceJSON = pkgs.writeText workspaceJSON = pkgs.writeText
"${name}-workspace-package.json" "${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" workspaceDependencyLinks = lib.concatMapStringsSep "\n"
(dep: '' (dep: ''
@ -176,6 +177,8 @@ in rec {
packageGlobs = if lib.isList package.workspaces then package.workspaces else package.workspaces.packages; packageGlobs = if lib.isList package.workspaces then package.workspaces else package.workspaces.packages;
packageResolutions = package.resolutions or {};
globElemToRegex = lib.replaceStrings ["*"] [".*"]; globElemToRegex = lib.replaceStrings ["*"] [".*"];
# PathGlob -> [PathGlobElem] # PathGlob -> [PathGlobElem]
@ -223,7 +226,7 @@ in rec {
inherit name; inherit name;
value = mkYarnPackage ( value = mkYarnPackage (
builtins.removeAttrs attrs ["packageOverrides"] builtins.removeAttrs attrs ["packageOverrides"]
// { inherit src packageJSON yarnLock workspaceDependencies; } // { inherit src packageJSON yarnLock packageResolutions workspaceDependencies; }
// lib.attrByPath [name] {} packageOverrides // lib.attrByPath [name] {} packageOverrides
); );
}) })
@ -245,6 +248,7 @@ in rec {
extraBuildInputs ? [], extraBuildInputs ? [],
publishBinsFor ? null, publishBinsFor ? null,
workspaceDependencies ? [], # List of yarnPackages workspaceDependencies ? [], # List of yarnPackages
packageResolutions ? {},
... ...
}@attrs: }@attrs:
let let
@ -264,7 +268,7 @@ in rec {
preBuild = yarnPreBuild; preBuild = yarnPreBuild;
postBuild = yarnPostBuild; postBuild = yarnPostBuild;
workspaceDependencies = workspaceDependenciesTransitive; workspaceDependencies = workspaceDependenciesTransitive;
inherit packageJSON pname version yarnLock offlineCache yarnFlags pkgConfig; inherit packageJSON pname version yarnLock offlineCache yarnFlags pkgConfig packageResolutions;
}; };
publishBinsFor_ = unlessNull publishBinsFor [pname]; publishBinsFor_ = unlessNull publishBinsFor [pname];
@ -298,7 +302,7 @@ in rec {
'') '')
workspaceDependenciesTransitive; workspaceDependenciesTransitive;
in stdenv.mkDerivation (builtins.removeAttrs attrs ["yarnNix" "pkgConfig" "workspaceDependencies"] // { in stdenv.mkDerivation (builtins.removeAttrs attrs ["yarnNix" "pkgConfig" "workspaceDependencies" "packageResolutions"] // {
inherit src pname; inherit src pname;
name = baseName; name = baseName;