|
9 | 9 |
|
10 | 10 | sanitizeLockfile = lock: |
11 | 11 | # Every project MUST have a name |
12 | | - assert lock ? name; |
13 | | - # Every project MUST have a version |
14 | | - assert lock ? version; |
15 | | - # This lockfile module only supports lockfileVersion 2 and 3 |
16 | | - assert !lock ? lockfileVersion || lock.lockfileVersion >= 2; |
17 | | - # The Lockfile must contain a 'packages' attribute. |
18 | | - assert lock ? packages; |
19 | | - lock; |
| 12 | + if ! lock ? name |
| 13 | + then throw "Invalid lockfile: Every project MUST have a name" |
| 14 | + else |
| 15 | + # Every project MUST have a version |
| 16 | + if ! lock ? version |
| 17 | + then throw "Invalid lockfile: Every project MUST have a version" |
| 18 | + else |
| 19 | + # This lockfile module only supports lockfileVersion 2 and 3 |
| 20 | + if ! lock ? lockfileVersion || lock.lockfileVersion <= 1 |
| 21 | + then throw "This lockfile module only supports lockfileVersion 2 and 3" |
| 22 | + else |
| 23 | + # The Lockfile must contain a 'packages' attribute. |
| 24 | + if ! lock ? packages |
| 25 | + then throw "Invalid lockfile: The Lockfile must contain 'packages' attribute." |
| 26 | + else lock; |
20 | 27 |
|
21 | 28 | findEntry = |
22 | 29 | # = "attrs" |
|
34 | 41 | else if currentPath == "" |
35 | 42 | then throw "${search} not found in package-lock.json." |
36 | 43 | else findEntry packageLock (stripPath currentPath) search; |
37 | | - |
38 | | - # Returns the names of all "bundledDependencies". |
39 | | - # People depend on different types and different names. Unfortunatly those fields are not part of the offical npm documentation. |
40 | | - # Which may also be the reason for the mess. |
41 | | - # |
42 | | - # TODO: define unit tests. |
43 | | - # Adopted from https://github.com/aakropotkin/floco/blob/708c4ffa0c05033c29fe6886a238cb20c3ba3fb4/modules/plock/implementation.nix#L139 |
44 | | - # |
45 | | - # getBundledDependencies :: Pent -> {} |
46 | | - getBundledDependencies = pent: let |
47 | | - # b :: bool | [] |
48 | | - b = pent.bundledDependencies or pent.bundleDependencies or []; |
49 | | - in |
50 | | - # The following asserts is the XOR logic. |
51 | | - # "bundle" and "bundled" dependencies are both valid but invalid if both or none keys exist |
52 | | - assert ( pent ? bundledDependencies ) -> |
53 | | - ( ! ( pent ? bundleDependencies ) ); |
54 | | - assert ( pent ? bundleDependencies ) -> |
55 | | - ( ! ( pent ? bundledDependencies ) ); |
56 | | - if b == [] then {} else |
57 | | - if builtins.isList b then { bundledDependencies = b; } else |
58 | | - if ! b then {} else { |
59 | | - # b :: true |
60 | | - bundledDependencies = builtins.attrNames ( |
61 | | - ( pent.dependencies or {} ) // ( pent.requires or {} ) |
62 | | - ); |
63 | | - }; |
64 | 44 | in { |
65 | | - inherit findEntry stripPath getBundledDependencies sanitizeLockfile; |
| 45 | + inherit findEntry stripPath sanitizeLockfile; |
66 | 46 | } |
0 commit comments