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 ? "",
postBuild ? "",
workspaceDependencies ? [], # List of yarn packages
packageResolutions ? {},
}:
let
extraNativeBuildInputs =
@ -98,7 +99,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: ''
@ -176,6 +177,8 @@ in rec {
packageGlobs = if lib.isList package.workspaces then package.workspaces else package.workspaces.packages;
packageResolutions = package.resolutions or {};
globElemToRegex = lib.replaceStrings ["*"] [".*"];
# PathGlob -> [PathGlobElem]
@ -223,7 +226,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
);
})
@ -245,6 +248,7 @@ in rec {
extraBuildInputs ? [],
publishBinsFor ? null,
workspaceDependencies ? [], # List of yarnPackages
packageResolutions ? {},
...
}@attrs:
let
@ -264,7 +268,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];
@ -298,7 +302,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;