From: Mads Andreasen <mads@andreasen.cc>
To: bitbake-devel@lists.openembedded.org
Cc: Mads Andreasen <github@andreasen.cc>
Subject: [PATCH] fetch2/npm: Use npm pack to download node modules instead of wget
Date: Sun, 7 Jul 2019 09:19:44 +0200 [thread overview]
Message-ID: <20190707071944.5653-1-github@andreasen.cc> (raw)
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
Signed-off-by: Mads Andreasen <mads@andreasen.cc>
---
lib/bb/fetch2/npm.py | 45 ++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
index 4427b1bb..6c4d397f 100644
--- a/lib/bb/fetch2/npm.py
+++ b/lib/bb/fetch2/npm.py
@@ -101,11 +101,19 @@ class Npm(FetchMethod):
return False
return True
- def _runwget(self, ud, d, command, quiet):
- logger.debug(2, "Fetching %s using command '%s'" % (ud.url, command))
- bb.fetch2.check_network_access(d, command, ud.url)
+ def _runpack(self, ud, d, pkgfullname: str, quiet=False) -> str:
+ """
+ Runs npm pack on a full package name.
+ Returns the filename of the downloaded package
+ """
+ bb.fetch2.check_network_access(d, pkgfullname, ud.registry)
dldir = d.getVar("DL_DIR")
- runfetchcmd(command, d, quiet, workdir=dldir)
+ dldir = os.path.join(dldir, ud.prefixdir)
+
+ command = f"npm pack {pkgfullname} --registry {ud.registry}"
+ logger.debug(2, "Fetching {pkgfullname} using command '{command}' in {dldir}")
+ filename = runfetchcmd(command, d, quiet, workdir=dldir)
+ return filename.rstrip()
def _unpackdep(self, ud, pkg, data, destdir, dldir, d):
file = data[pkg]['tgz']
@@ -163,6 +171,9 @@ class Npm(FetchMethod):
pkgfullname = pkg
if version != '*' and not '/' in version:
pkgfullname += "@'%s'" % version
+ if pkgfullname in fetchedlist:
+ return
+
logger.debug(2, "Calling getdeps on %s" % pkg)
fetchcmd = "npm view %s --json --registry %s" % (pkgfullname, ud.registry)
output = runfetchcmd(fetchcmd, d, True)
@@ -182,15 +193,10 @@ class Npm(FetchMethod):
if (not blacklist and 'linux' not in pkg_os) or '!linux' in pkg_os:
logger.debug(2, "Skipping %s since it's incompatible with Linux" % pkg)
return
- #logger.debug(2, "Output URL is %s - %s - %s" % (ud.basepath, ud.basename, ud.localfile))
- outputurl = pdata['dist']['tarball']
+ filename = self._runpack(ud, d, pkgfullname)
data[pkg] = {}
- data[pkg]['tgz'] = os.path.basename(outputurl)
- if outputurl in fetchedlist:
- return
-
- self._runwget(ud, d, "%s --directory-prefix=%s %s" % (self.basecmd, ud.prefixdir, outputurl), False)
- fetchedlist.append(outputurl)
+ data[pkg]['tgz'] = filename
+ fetchedlist.append(pkgfullname)
dependencies = pdata.get('dependencies', {})
optionalDependencies = pdata.get('optionalDependencies', {})
@@ -217,17 +223,12 @@ class Npm(FetchMethod):
if obj == pkg:
self._getshrinkeddependencies(obj, data['dependencies'][obj], data['dependencies'][obj]['version'], d, ud, lockdown, manifest, False)
return
- outputurl = "invalid"
- if ('resolved' not in data) or (not data['resolved'].startswith('http://') and not data['resolved'].startswith('https://')):
- # will be the case for ${PN}
- fetchcmd = "npm view %s@%s dist.tarball --registry %s" % (pkg, version, ud.registry)
- logger.debug(2, "Found this matching URL: %s" % str(fetchcmd))
- outputurl = runfetchcmd(fetchcmd, d, True)
- else:
- outputurl = data['resolved']
- self._runwget(ud, d, "%s --directory-prefix=%s %s" % (self.basecmd, ud.prefixdir, outputurl), False)
+
+ pkgnameWithVersion = f"{pkg}@{version}"
+ logger.debug(2, f"Get dependencies for {pkgnameWithVersion}")
+ filename = self._runpack(ud, d, pkgnameWithVersion)
manifest[pkg] = {}
- manifest[pkg]['tgz'] = os.path.basename(outputurl).rstrip()
+ manifest[pkg]['tgz'] = filename
manifest[pkg]['deps'] = {}
if pkg in lockdown:
--
2.17.1
next reply other threads:[~2019-07-07 7:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-07 7:19 Mads Andreasen [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-07-07 11:35 [PATCH] fetch2/npm: Use npm pack to download node modules instead of wget Mads Andreasen
2019-07-25 19:05 Mads Andreasen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190707071944.5653-1-github@andreasen.cc \
--to=mads@andreasen.cc \
--cc=bitbake-devel@lists.openembedded.org \
--cc=github@andreasen.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.