summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>2025-01-07 10:17:54 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-01-08 11:34:04 +0000
commiteb0c87fa4c3cc85ecb907f42559fbe9afb25aae7 (patch)
tree569e01f1eb4177721f5de65a40dc3fc3c591b0f9
parentc691d4d53f7e4c448e02b9b2c182d8503eb5e067 (diff)
downloadpoky-eb0c87fa4c3cc85ecb907f42559fbe9afb25aae7.tar.gz
bitbake: fetch2: npmsw: remove old lockfile format support
Remove support for the old lockfile format. The old lockfile format is required by npm 6 / Node.js 14 which is out of maintenance [2]. [1] https://docs.npmjs.com/cli/v6/configuring-npm/package-lock-json [2] https://nodejs.org/en/about/previous-releases (Bitbake rev: 7824e19483d9b60a259d6e3a4c7068fade94f2bf) Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/fetch2/npmsw.py97
1 files changed, 36 insertions, 61 deletions
diff --git a/bitbake/lib/bb/fetch2/npmsw.py b/bitbake/lib/bb/fetch2/npmsw.py
index 558c9a2b07..2f9599ee9e 100644
--- a/bitbake/lib/bb/fetch2/npmsw.py
+++ b/bitbake/lib/bb/fetch2/npmsw.py
@@ -37,40 +37,26 @@ def foreach_dependencies(shrinkwrap, callback=None, dev=False):
37 """ 37 """
38 Run a callback for each dependencies of a shrinkwrap file. 38 Run a callback for each dependencies of a shrinkwrap file.
39 The callback is using the format: 39 The callback is using the format:
40 callback(name, params, deptree) 40 callback(name, data, location)
41 with: 41 with:
42 name = the package name (string) 42 name = the package name (string)
43 params = the package parameters (dictionary) 43 data = the package data (dictionary)
44 destdir = the destination of the package (string) 44 location = the location of the package (string)
45 """ 45 """
46 # For handling old style dependencies entries in shinkwrap files 46 packages = shrinkwrap.get("packages")
47 def _walk_deps(deps, deptree): 47 if not packages:
48 for name in deps: 48 raise FetchError("Invalid shrinkwrap file format")
49 subtree = [*deptree, name] 49
50 _walk_deps(deps[name].get("dependencies", {}), subtree) 50 for location, data in packages.items():
51 if callback is not None: 51 # Skip empty main and local link target packages
52 if deps[name].get("dev", False) and not dev: 52 if not location.startswith('node_modules/'):
53 continue 53 continue
54 elif deps[name].get("bundled", False): 54 elif not dev and data.get("dev", False):
55 continue 55 continue
56 destsubdirs = [os.path.join("node_modules", dep) for dep in subtree] 56 elif data.get("inBundle", False):
57 destsuffix = os.path.join(*destsubdirs) 57 continue
58 callback(name, deps[name], destsuffix) 58 name = location.split('node_modules/')[-1]
59 59 callback(name, data, location)
60 # packages entry means new style shrinkwrap file, else use dependencies
61 packages = shrinkwrap.get("packages", None)
62 if packages is not None:
63 for package in packages:
64 if package != "":
65 name = package.split('node_modules/')[-1]
66 package_infos = packages.get(package, {})
67 if dev == False and package_infos.get("dev", False):
68 continue
69 elif package_infos.get("inBundle", False):
70 continue
71 callback(name, package_infos, package)
72 else:
73 _walk_deps(shrinkwrap.get("dependencies", {}), [])
74 60
75class NpmShrinkWrap(FetchMethod): 61class NpmShrinkWrap(FetchMethod):
76 """Class to fetch all package from a shrinkwrap file""" 62 """Class to fetch all package from a shrinkwrap file"""
@@ -97,12 +83,18 @@ class NpmShrinkWrap(FetchMethod):
97 extrapaths = [] 83 extrapaths = []
98 unpack = True 84 unpack = True
99 85
100 integrity = params.get("integrity", None) 86 integrity = params.get("integrity")
101 resolved = params.get("resolved", None) 87 resolved = params.get("resolved")
102 version = params.get("version", resolved) 88 version = params.get("version")
89 link = params.get("link", False)
90
91 # Handle link sources
92 if link:
93 localpath = resolved
94 unpack = False
103 95
104 # Handle registry sources 96 # Handle registry sources
105 if is_semver(version) and integrity: 97 elif version and is_semver(version) and integrity:
106 # Handle duplicate dependencies without url 98 # Handle duplicate dependencies without url
107 if not resolved: 99 if not resolved:
108 return 100 return
@@ -130,10 +122,10 @@ class NpmShrinkWrap(FetchMethod):
130 extrapaths.append(resolvefile) 122 extrapaths.append(resolvefile)
131 123
132 # Handle http tarball sources 124 # Handle http tarball sources
133 elif version.startswith("http") and integrity: 125 elif resolved.startswith("http") and integrity:
134 localfile = npm_localfile(os.path.basename(version)) 126 localfile = npm_localfile(os.path.basename(resolved))
135 127
136 uri = URI(version) 128 uri = URI(resolved)
137 uri.params["downloadfilename"] = localfile 129 uri.params["downloadfilename"] = localfile
138 130
139 checksum_name, checksum_expected = npm_integrity(integrity) 131 checksum_name, checksum_expected = npm_integrity(integrity)
@@ -143,28 +135,12 @@ class NpmShrinkWrap(FetchMethod):
143 135
144 localpath = os.path.join(d.getVar("DL_DIR"), localfile) 136 localpath = os.path.join(d.getVar("DL_DIR"), localfile)
145 137
146 # Handle local tarball and link sources 138 # Handle local tarball sources
147 elif version.startswith("file"): 139 elif resolved.startswith("file"):
148 localpath = version[5:] 140 localpath = resolved[5:]
149 if not version.endswith(".tgz"):
150 unpack = False
151 141
152 # Handle git sources 142 # Handle git sources
153 elif version.startswith(("git", "bitbucket","gist")) or ( 143 elif resolved.startswith("git"):
154 not version.endswith((".tgz", ".tar", ".tar.gz"))
155 and not version.startswith((".", "@", "/"))
156 and "/" in version
157 ):
158 if version.startswith("github:"):
159 version = "git+https://github.com/" + version[len("github:"):]
160 elif version.startswith("gist:"):
161 version = "git+https://gist.github.com/" + version[len("gist:"):]
162 elif version.startswith("bitbucket:"):
163 version = "git+https://bitbucket.org/" + version[len("bitbucket:"):]
164 elif version.startswith("gitlab:"):
165 version = "git+https://gitlab.com/" + version[len("gitlab:"):]
166 elif not version.startswith(("git+","git:")):
167 version = "git+https://github.com/" + version
168 regex = re.compile(r""" 144 regex = re.compile(r"""
169 ^ 145 ^
170 git\+ 146 git\+
@@ -176,10 +152,9 @@ class NpmShrinkWrap(FetchMethod):
176 $ 152 $
177 """, re.VERBOSE) 153 """, re.VERBOSE)
178 154
179 match = regex.match(version) 155 match = regex.match(resolved)
180
181 if not match: 156 if not match:
182 raise ParameterError("Invalid git url: %s" % version, ud.url) 157 raise ParameterError("Invalid git url: %s" % resolved, ud.url)
183 158
184 groups = match.groupdict() 159 groups = match.groupdict()
185 160