summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/npmsw.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch2/npmsw.py')
-rw-r--r--bitbake/lib/bb/fetch2/npmsw.py98
1 files changed, 38 insertions, 60 deletions
diff --git a/bitbake/lib/bb/fetch2/npmsw.py b/bitbake/lib/bb/fetch2/npmsw.py
index ff5f8dc755..2f9599ee9e 100644
--- a/bitbake/lib/bb/fetch2/npmsw.py
+++ b/bitbake/lib/bb/fetch2/npmsw.py
@@ -37,38 +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 callback(name, package_infos, package)
70 else:
71 _walk_deps(shrinkwrap.get("dependencies", {}), [])
72 60
73class NpmShrinkWrap(FetchMethod): 61class NpmShrinkWrap(FetchMethod):
74 """Class to fetch all package from a shrinkwrap file""" 62 """Class to fetch all package from a shrinkwrap file"""
@@ -95,12 +83,18 @@ class NpmShrinkWrap(FetchMethod):
95 extrapaths = [] 83 extrapaths = []
96 unpack = True 84 unpack = True
97 85
98 integrity = params.get("integrity", None) 86 integrity = params.get("integrity")
99 resolved = params.get("resolved", None) 87 resolved = params.get("resolved")
100 version = params.get("version", None) 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
101 95
102 # Handle registry sources 96 # Handle registry sources
103 if is_semver(version) and integrity: 97 elif version and is_semver(version) and integrity:
104 # Handle duplicate dependencies without url 98 # Handle duplicate dependencies without url
105 if not resolved: 99 if not resolved:
106 return 100 return
@@ -128,10 +122,10 @@ class NpmShrinkWrap(FetchMethod):
128 extrapaths.append(resolvefile) 122 extrapaths.append(resolvefile)
129 123
130 # Handle http tarball sources 124 # Handle http tarball sources
131 elif version.startswith("http") and integrity: 125 elif resolved.startswith("http") and integrity:
132 localfile = npm_localfile(os.path.basename(version)) 126 localfile = npm_localfile(os.path.basename(resolved))
133 127
134 uri = URI(version) 128 uri = URI(resolved)
135 uri.params["downloadfilename"] = localfile 129 uri.params["downloadfilename"] = localfile
136 130
137 checksum_name, checksum_expected = npm_integrity(integrity) 131 checksum_name, checksum_expected = npm_integrity(integrity)
@@ -141,28 +135,12 @@ class NpmShrinkWrap(FetchMethod):
141 135
142 localpath = os.path.join(d.getVar("DL_DIR"), localfile) 136 localpath = os.path.join(d.getVar("DL_DIR"), localfile)
143 137
144 # Handle local tarball and link sources 138 # Handle local tarball sources
145 elif version.startswith("file"): 139 elif resolved.startswith("file"):
146 localpath = version[5:] 140 localpath = resolved[5:]
147 if not version.endswith(".tgz"):
148 unpack = False
149 141
150 # Handle git sources 142 # Handle git sources
151 elif version.startswith(("git", "bitbucket","gist")) or ( 143 elif resolved.startswith("git"):
152 not version.endswith((".tgz", ".tar", ".tar.gz"))
153 and not version.startswith((".", "@", "/"))
154 and "/" in version
155 ):
156 if version.startswith("github:"):
157 version = "git+https://github.com/" + version[len("github:"):]
158 elif version.startswith("gist:"):
159 version = "git+https://gist.github.com/" + version[len("gist:"):]
160 elif version.startswith("bitbucket:"):
161 version = "git+https://bitbucket.org/" + version[len("bitbucket:"):]
162 elif version.startswith("gitlab:"):
163 version = "git+https://gitlab.com/" + version[len("gitlab:"):]
164 elif not version.startswith(("git+","git:")):
165 version = "git+https://github.com/" + version
166 regex = re.compile(r""" 144 regex = re.compile(r"""
167 ^ 145 ^
168 git\+ 146 git\+
@@ -174,16 +152,16 @@ class NpmShrinkWrap(FetchMethod):
174 $ 152 $
175 """, re.VERBOSE) 153 """, re.VERBOSE)
176 154
177 match = regex.match(version) 155 match = regex.match(resolved)
178
179 if not match: 156 if not match:
180 raise ParameterError("Invalid git url: %s" % version, ud.url) 157 raise ParameterError("Invalid git url: %s" % resolved, ud.url)
181 158
182 groups = match.groupdict() 159 groups = match.groupdict()
183 160
184 uri = URI("git://" + str(groups["url"])) 161 uri = URI("git://" + str(groups["url"]))
185 uri.params["protocol"] = str(groups["protocol"]) 162 uri.params["protocol"] = str(groups["protocol"])
186 uri.params["rev"] = str(groups["rev"]) 163 uri.params["rev"] = str(groups["rev"])
164 uri.params["nobranch"] = "1"
187 uri.params["destsuffix"] = destsuffix 165 uri.params["destsuffix"] = destsuffix
188 166
189 url = str(uri) 167 url = str(uri)
@@ -268,7 +246,7 @@ class NpmShrinkWrap(FetchMethod):
268 246
269 def unpack(self, ud, rootdir, d): 247 def unpack(self, ud, rootdir, d):
270 """Unpack the downloaded dependencies""" 248 """Unpack the downloaded dependencies"""
271 destdir = d.getVar("S") 249 destdir = rootdir
272 destsuffix = ud.parm.get("destsuffix") 250 destsuffix = ud.parm.get("destsuffix")
273 if destsuffix: 251 if destsuffix:
274 destdir = os.path.join(rootdir, destsuffix) 252 destdir = os.path.join(rootdir, destsuffix)