at master 927 B view raw
1# This overlay implements mocking of the lib.path.splitRoot function 2# It pretends that the last component named "mock-root" is the root: 3# 4# splitRoot /foo/mock-root/bar/mock-root/baz 5# => { 6# root = /foo/mock-root/bar/mock-root; 7# subpath = "./baz"; 8# } 9self: super: { 10 path = super.path // { 11 splitRoot = 12 path: 13 let 14 parts = super.path.splitRoot path; 15 components = self.path.subpath.components parts.subpath; 16 count = self.length components; 17 rootIndex = 18 count 19 - self.lists.findFirstIndex (component: component == "mock-root") (self.length components) ( 20 self.reverseList components 21 ); 22 root = self.path.append parts.root (self.path.subpath.join (self.take rootIndex components)); 23 subpath = self.path.subpath.join (self.drop rootIndex components); 24 in 25 { 26 inherit root subpath; 27 }; 28 }; 29}