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`.
This commit is contained in:
parent
2f8299f321
commit
9801e6e53d
1 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue