diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-30 09:49:04 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-30 09:50:43 +0100 |
commit | 9941b480a0e2a8b57f2ed069cd583f2784394a2b (patch) | |
tree | f80db88ee2a290921c443ddb060c0fc214d05d83 /lib/bb/fetch2/npmsw.py | |
parent | b2e1be67d2acca27451bed59874bc1c2a7ec44a6 (diff) | |
download | bitbake-contrib-9941b480a0e2a8b57f2ed069cd583f2784394a2b.tar.gz |
fetch2/npmsw: Support old and new shrinkwrap formats
"fetch2/npmsw: Add support for the new format of the shrinkwrap file"
added support for the new format shrinkwrap files but this regressed
our tests which still use the old format.
Similar to how npm handles this, support both for now until we can
migrate our tests.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/fetch2/npmsw.py')
-rw-r--r-- | lib/bb/fetch2/npmsw.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/bb/fetch2/npmsw.py b/lib/bb/fetch2/npmsw.py index d89be10ca..971ccc905 100644 --- a/lib/bb/fetch2/npmsw.py +++ b/lib/bb/fetch2/npmsw.py @@ -43,15 +43,32 @@ def foreach_dependencies(shrinkwrap, callback=None, dev=False): params = the package parameters (dictionary) destdir = the destination of the package (string) """ - packages = shrinkwrap.get("packages", {}) - - for package in packages: - if package != "": - name = package.split('node_modules/')[-1] - package_infos = packages.get(package, {}) - if dev == False and package_infos.get("dev", False): - continue - callback(name, package_infos, package) + # For handling old style dependencies entries in shinkwrap files + def _walk_deps(deps, deptree): + for name in deps: + subtree = [*deptree, name] + _walk_deps(deps[name].get("dependencies", {}), subtree) + if callback is not None: + if deps[name].get("dev", False) and not dev: + continue + elif deps[name].get("bundled", False): + continue + destsubdirs = [os.path.join("node_modules", dep) for dep in subtree] + destsuffix = os.path.join(*destsubdirs) + callback(name, deps[name], destsuffix) + + # packages entry means new style shrinkwrap file, else use dependencies + packages = shrinkwrap.get("packages", None) + if packages is not None: + for package in packages: + if package != "": + name = package.split('node_modules/')[-1] + package_infos = packages.get(package, {}) + if dev == False and package_infos.get("dev", False): + continue + callback(name, package_infos, package) + else: + _walk_deps(shrinkwrap.get("dependencies", {}), []) class NpmShrinkWrap(FetchMethod): """Class to fetch all package from a shrinkwrap file""" |