From 77571a847f4c6c744a2541b493b2b7e9751a13ce Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Tue, 21 Nov 2023 17:49:05 -0500 Subject: [PATCH] prefetch-npm-deps: use default value when lockfile has no deps --- .../node/fetch-npm-deps/src/parse/lock.rs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pkgs/build-support/node/fetch-npm-deps/src/parse/lock.rs b/pkgs/build-support/node/fetch-npm-deps/src/parse/lock.rs index f7273d6a7888..e3580cfca0d3 100644 --- a/pkgs/build-support/node/fetch-npm-deps/src/parse/lock.rs +++ b/pkgs/build-support/node/fetch-npm-deps/src/parse/lock.rs @@ -18,23 +18,20 @@ pub(super) fn packages(content: &str) -> anyhow::Result> { 1 => { let initial_url = get_initial_url()?; - lockfile - .dependencies - .map(|p| to_new_packages(p, &initial_url)) - .transpose()? + to_new_packages(lockfile.dependencies.unwrap_or_default(), &initial_url)? } - 2 | 3 => lockfile.packages.map(|pkgs| { - pkgs.into_iter() - .filter(|(n, p)| !n.is_empty() && matches!(p.resolved, Some(UrlOrString::Url(_)))) - .map(|(n, p)| Package { name: Some(n), ..p }) - .collect() - }), + 2 | 3 => lockfile + .packages + .unwrap_or_default() + .into_iter() + .filter(|(n, p)| !n.is_empty() && matches!(p.resolved, Some(UrlOrString::Url(_)))) + .map(|(n, p)| Package { name: Some(n), ..p }) + .collect(), _ => bail!( "We don't support lockfile version {}, please file an issue.", lockfile.version ), - } - .expect("lockfile should have packages"); + }; packages.par_sort_by(|x, y| { x.resolved