From f762d4537c6ef968e3ec9dc695dea8568a413071 Mon Sep 17 00:00:00 2001 From: Mike Crowe Date: Tue, 8 Apr 2025 14:41:18 +0100 Subject: [PATCH] classes-recipe: npm: Complain immediately if npm-shrinkwrap.json is too old Rather than emitting: Exception: KeyError: 'packages' and a stack trace, let's fail immediately if lockfileVersion implies that the npm-shrinkwrap.json file isn't compatible. The documentation[1] doesn't make it clear which lockfileVersions are guaranteed to contain "packages". I have lockfileVersion 1 files without. Running npm 7.5.2 generates npm-shrinkwrap.json files with lockfileVersion 2 and "packages", so I've set the minimum to be 2. [1] https://docs.npmjs.com/cli/v7/configuring-npm/package-lock-json (From OE-Core rev: 4d3cbd11bc9cc0bf5a8571ecd3ce6e5e5c6ef6eb) Signed-off-by: Mike Crowe Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- meta/classes-recipe/npm.bbclass | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meta/classes-recipe/npm.bbclass b/meta/classes-recipe/npm.bbclass index a73ff29be8..344e8b4bec 100644 --- a/meta/classes-recipe/npm.bbclass +++ b/meta/classes-recipe/npm.bbclass @@ -154,6 +154,9 @@ python npm_do_configure() { has_shrinkwrap_file = False if has_shrinkwrap_file: + if int(orig_shrinkwrap.get("lockfileVersion", 0)) < 2: + bb.fatal("%s: lockfileVersion version 2 or later is required" % orig_shrinkwrap_file) + cached_shrinkwrap = copy.deepcopy(orig_shrinkwrap) for package in orig_shrinkwrap["packages"]: if package != "":