summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Crowe <mac@mcrowe.com>2025-04-08 14:41:18 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-04-10 11:05:34 +0100
commitf762d4537c6ef968e3ec9dc695dea8568a413071 (patch)
treea7955cf67bb65542ca9a37b13ae6270c3c497f64
parent916205dac9c2261fd5c4d76ac73f139fbfd03bdd (diff)
downloadpoky-f762d4537c6ef968e3ec9dc695dea8568a413071.tar.gz
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 <mac@mcrowe.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/npm.bbclass3
1 files changed, 3 insertions, 0 deletions
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() {
154 has_shrinkwrap_file = False 154 has_shrinkwrap_file = False
155 155
156 if has_shrinkwrap_file: 156 if has_shrinkwrap_file:
157 if int(orig_shrinkwrap.get("lockfileVersion", 0)) < 2:
158 bb.fatal("%s: lockfileVersion version 2 or later is required" % orig_shrinkwrap_file)
159
157 cached_shrinkwrap = copy.deepcopy(orig_shrinkwrap) 160 cached_shrinkwrap = copy.deepcopy(orig_shrinkwrap)
158 for package in orig_shrinkwrap["packages"]: 161 for package in orig_shrinkwrap["packages"]:
159 if package != "": 162 if package != "":