@@ -449,7 +449,9 @@ class RecipetoolCreateTests(RecipetoolBase):
checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme'
checkvars['LICENSE'] = 'BSD-3-Clause AND ISC AND MIT AND Unknown'
urls = []
- urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}')
+ urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}'
+ ';sha512sum=f2dd7d88cb9a129fbb97eb87a8b5103bab24f783420fd7587f8000a355a12bf7'
+ '83f1263230afc588123958b73e36bb241f63eaf08119aac5aa2a870bc4de9223')
urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json')
checkvars['SRC_URI'] = set(urls)
checkvars['S'] = '${WORKDIR}/npm'
@@ -413,6 +413,18 @@ def is_package(url):
return True
return False
+def get_npm_checksum(registry, package, version):
+ """Get the checksum of an npm package from the registry.
+
+ The npm fetcher needs a checksum before the download. When a new recipe
+ is created, the registry is the only source of this checksum.
+ """
+ import urllib.request
+ from bb.fetch.npm import npm_integrity
+ url = "https://%s/%s/%s" % (registry.strip("/"), package, version)
+ with urllib.request.urlopen(url, timeout=60) as response:
+ return npm_integrity(json.load(response)["dist"]["integrity"])
+
def create_recipe(args):
import bb.process
import tempfile
@@ -523,6 +535,15 @@ def create_recipe(args):
# Assume 'master' branch if not set
if scheme in ['git', 'gitsm'] and 'branch' not in params and 'nobranch' not in params:
params['branch'] = 'master'
+ npm_checksum = {}
+ if scheme == 'npm' and not any(p in params for p in bb.fetch.npm.CHECKSUM_PARMS):
+ try:
+ checksum_name, checksum = get_npm_checksum(network + path, params.get('package', ''), params.get('version', ''))
+ except Exception as e:
+ logger.error('Unable to get the checksum of %s from the registry: %s' % (srcuri, e))
+ sys.exit(1)
+ npm_checksum[checksum_name] = checksum
+ params.update(npm_checksum)
fetchuri = bb.fetch.encodeurl((scheme, network, path, user, passwd, params))
tmpparent = tinfoil.config_data.getVar('BASE_WORKDIR')
@@ -587,6 +608,7 @@ def create_recipe(args):
# Since we might have a value in srcbranch, we need to
# recontruct the srcuri to include 'branch' in params.
scheme, network, path, user, passwd, params = bb.fetch.decodeurl(srcuri)
+ params.update(npm_checksum)
if scheme in ['git', 'gitsm']:
params['branch'] = srcbranch or 'master'