From 9b1c5870e55ca80ca523cfa2617c2affc54e00aa Mon Sep 17 00:00:00 2001 From: Las Date: Sat, 25 Jan 2025 12:52:47 +0000 Subject: [PATCH] nodejs-package-lock-v3: Skip extraneous entries The motivation was pagedjs-cli, which has the following lock file: https://github.com/pagedjs/pagedjs-cli/blob/d682e19ee5d14bfe07ad1726540e2423ede75a05/package-lock.json#L39 The explanation in https://docs.npmjs.com/cli/v7/commands/npm-prune/ is: > Extraneous packages are those present in the node_modules folder that > are not listed as any package's dependency list. > [..] > In normal operation, extraneous modules are pruned automatically, > so you'll only need this command with the --production flag. > However, in the real world, operation is not always "normal". > When crashes or mistakes happen, this command can help clean up any resulting garbage. Arguably it's the upstream package-lock.json that's broken, but OTOH, detecting this as an error in dream2nix would take as much code as just ignoring it, and just ignoring it is probably OK 99% of the time. At the very least it's more helpful than the previous error you would get, which is an error when it tries to access `entry.version`. --- .../dream2nix/nodejs-package-lock-v3/default.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/dream2nix/nodejs-package-lock-v3/default.nix b/modules/dream2nix/nodejs-package-lock-v3/default.nix index 73186e87f9..a5be1697a2 100644 --- a/modules/dream2nix/nodejs-package-lock-v3/default.nix +++ b/modules/dream2nix/nodejs-package-lock-v3/default.nix @@ -59,6 +59,8 @@ }; }; } + else if entry ? extraneous && entry.extraneous + then { extraneous = true; } else let source = parseSource entry; version = @@ -83,10 +85,13 @@ parse = lock: builtins.foldl' (acc: entry: - acc - // { - ${entry.name} = acc.${entry.name} or {} // entry.value; - }) + if entry ? extraneous && entry.extraneous + then acc + else + acc + // { + ${entry.name} = acc.${entry.name} or {} // entry.value; + }) {} # [{name=; value=;} ...] (l.mapAttrsToList (parseEntry lock) lock.packages);