This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
rewriteDescriptors
aameen-tulip edited this page Dec 6, 2022
·
3 revisions
-
lib.libpkginfo.rewriteDescriptors
Replace
package.json
style dependency descriptors ("^1.0.0"
) with new values either by overriding or transforming them.Takes an attrset of package names assigned to either strings or functions. For strings, override existing descriptors in package.json, for functions apply them to the existing value to produce a new descriptor.
- Prototype
rewriteDescriptors = { pjs # data to modify , resolve # override values/functions , depFields ? ["dependencies"] # attrsets to be modified }: <FUNCTION>;
- Example
{ lib }: let # Our phony `package.json' data data = { name = "test-pkg"; version = "0.0.1"; dependencies.foo = "^1.0.0"; dependencies.bar = "~1.0.0"; dependencies.baz = "github:fake/repo"; devDependencies.foo = "^1.0.0"; }; # Our transfmormation rules. xform = { foo = "2.0.0"; # set `foo' to "2.0.0" # strip off any modifiers: "^1.0.0" -> "1.0.0" bar = d: let m = builtins.match "[~=^]([0-9.]+)" d; in if m == null then d else builtins.head m; # Set to a store path ( in this case a dummy one ) baz = "/nix/store/XXXXXXX-repo.tgz"; # Quux never appears in our data, but so this does nothing here. # It covers us for other inputs that might contain it though. quux = "4.0.0"; }; in { # Call the routine expr = lib.libpkginfo.rewriteDescriptors { pjs = data; resolves = xform; depFields = ["dependencies"]; }; # What we expect the output to be. expected = { name = "test-pkg"; version = "0.0.1"; dependencies.foo = "2.0.0"; dependencies.bar = "1.0.0"; dependencies.baz = "/nix/store/XXXXXXX-repo.tgz"; # Unmodified because `depFields' does not ask for # `devDependencies' to be changed. devDependencies.foo = "^1.0.0"; }; }
- Prototype