summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/npm.py
diff options
context:
space:
mode:
authorMads Andreasen <mads@andreasen.cc>2019-07-25 21:05:33 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-07-27 22:46:09 +0100
commitbebeed310bfea80eea3e25481ae246fdc9052eb6 (patch)
treefb7a4e5868055d3f8edb5c1c6ccb3b2859735ed9 /bitbake/lib/bb/fetch2/npm.py
parentd7a026d43461a04a974d9431b26a4d121764f47e (diff)
downloadpoky-bebeed310bfea80eea3e25481ae246fdc9052eb6.tar.gz
bitbake: fetch2/npm: Use npm pack to download node modules instead of wget
Using npm pack to download the main node module and its dependencies allow for the use of private npm modules and access to them via .npmrc (Bitbake rev: e5eda3871893e4eadeb311aeb997e183675598f4) Signed-off-by: Mads Andreasen <mads@andreasen.cc> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/npm.py')
-rw-r--r--bitbake/lib/bb/fetch2/npm.py45
1 files changed, 23 insertions, 22 deletions
diff --git a/bitbake/lib/bb/fetch2/npm.py b/bitbake/lib/bb/fetch2/npm.py
index 4427b1bb87..9700e61029 100644
--- a/bitbake/lib/bb/fetch2/npm.py
+++ b/bitbake/lib/bb/fetch2/npm.py
@@ -101,11 +101,19 @@ class Npm(FetchMethod):
101 return False 101 return False
102 return True 102 return True
103 103
104 def _runwget(self, ud, d, command, quiet): 104 def _runpack(self, ud, d, pkgfullname: str, quiet=False) -> str:
105 logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command)) 105 """
106 bb.fetch2.check_network_access(d, command, ud.url) 106 Runs npm pack on a full package name.
107 Returns the filename of the downloaded package
108 """
109 bb.fetch2.check_network_access(d, pkgfullname, ud.registry)
107 dldir = d.getVar("DL_DIR") 110 dldir = d.getVar("DL_DIR")
108 runfetchcmd(command, d, quiet, workdir=dldir) 111 dldir = os.path.join(dldir, ud.prefixdir)
112
113 command = "npm pack {} --registry {}".format(pkgfullname, ud.registry)
114 logger.debug(2, "Fetching {} using command '{}' in {}".format(pkgfullname, command, dldir))
115 filename = runfetchcmd(command, d, quiet, workdir=dldir)
116 return filename.rstrip()
109 117
110 def _unpackdep(self, ud, pkg, data, destdir, dldir, d): 118 def _unpackdep(self, ud, pkg, data, destdir, dldir, d):
111 file = data[pkg]['tgz'] 119 file = data[pkg]['tgz']
@@ -163,6 +171,9 @@ class Npm(FetchMethod):
163 pkgfullname = pkg 171 pkgfullname = pkg
164 if version != '*' and not '/' in version: 172 if version != '*' and not '/' in version:
165 pkgfullname += "@'%s'" % version 173 pkgfullname += "@'%s'" % version
174 if pkgfullname in fetchedlist:
175 return
176
166 logger.debug(2, "Calling getdeps on %s" % pkg) 177 logger.debug(2, "Calling getdeps on %s" % pkg)
167 fetchcmd = "npm view %s --json --registry %s" % (pkgfullname, ud.registry) 178 fetchcmd = "npm view %s --json --registry %s" % (pkgfullname, ud.registry)
168 output = runfetchcmd(fetchcmd, d, True) 179 output = runfetchcmd(fetchcmd, d, True)
@@ -182,15 +193,10 @@ class Npm(FetchMethod):
182 if (not blacklist and 'linux' not in pkg_os) or '!linux' in pkg_os: 193 if (not blacklist and 'linux' not in pkg_os) or '!linux' in pkg_os:
183 logger.debug(2, "Skipping %s since it's incompatible with Linux" % pkg) 194 logger.debug(2, "Skipping %s since it's incompatible with Linux" % pkg)
184 return 195 return
185 #logger.debug(2, "Output URL is %s - %s - %s" % (ud.basepath, ud.basename, ud.localfile)) 196 filename = self._runpack(ud, d, pkgfullname)
186 outputurl = pdata['dist']['tarball']
187 data[pkg] = {} 197 data[pkg] = {}
188 data[pkg]['tgz'] = os.path.basename(outputurl) 198 data[pkg]['tgz'] = filename
189 if outputurl in fetchedlist: 199 fetchedlist.append(pkgfullname)
190 return
191
192 self._runwget(ud, d, "%s --directory-prefix=%s %s" % (self.basecmd, ud.prefixdir, outputurl), False)
193 fetchedlist.append(outputurl)
194 200
195 dependencies = pdata.get('dependencies', {}) 201 dependencies = pdata.get('dependencies', {})
196 optionalDependencies = pdata.get('optionalDependencies', {}) 202 optionalDependencies = pdata.get('optionalDependencies', {})
@@ -217,17 +223,12 @@ class Npm(FetchMethod):
217 if obj == pkg: 223 if obj == pkg:
218 self._getshrinkeddependencies(obj, data['dependencies'][obj], data['dependencies'][obj]['version'], d, ud, lockdown, manifest, False) 224 self._getshrinkeddependencies(obj, data['dependencies'][obj], data['dependencies'][obj]['version'], d, ud, lockdown, manifest, False)
219 return 225 return
220 outputurl = "invalid" 226
221 if ('resolved' not in data) or (not data['resolved'].startswith('http://') and not data['resolved'].startswith('https://')): 227 pkgnameWithVersion = "{}@{}".format(pkg, version)
222 # will be the case for ${PN} 228 logger.debug(2, "Get dependencies for {}".format(pkgnameWithVersion))
223 fetchcmd = "npm view %s@%s dist.tarball --registry %s" % (pkg, version, ud.registry) 229 filename = self._runpack(ud, d, pkgnameWithVersion)
224 logger.debug(2, "Found this matching URL: %s" % str(fetchcmd))
225 outputurl = runfetchcmd(fetchcmd, d, True)
226 else:
227 outputurl = data['resolved']
228 self._runwget(ud, d, "%s --directory-prefix=%s %s" % (self.basecmd, ud.prefixdir, outputurl), False)
229 manifest[pkg] = {} 230 manifest[pkg] = {}
230 manifest[pkg]['tgz'] = os.path.basename(outputurl).rstrip() 231 manifest[pkg]['tgz'] = filename
231 manifest[pkg]['deps'] = {} 232 manifest[pkg]['deps'] = {}
232 233
233 if pkg in lockdown: 234 if pkg in lockdown: