summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@sigma-chemnitz.de>2022-05-19 12:05:56 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-09-12 08:41:48 +0100
commitb53aff215effa6fdb02d3ac90d6ea654bd43e0eb (patch)
treee1f3448a04dfc27373b348089655d611c1e4c244 /meta/classes
parentbf1987dbe543683e6a136e6818b293939595bb01 (diff)
downloadpoky-b53aff215effa6fdb02d3ac90d6ea654bd43e0eb.tar.gz
npm: use npm_registry to cache package
With nodejs 16, the simple 'npm cache add' approach does not work anymore because its fetcher implementation downloads also meta information from the registry. We have to generate these information and add them to the cache. There is no direct support in 'npm' for task so we have to implement it manually. This implementation consists of a openembedded python module (in oe-core) and a nodejs version specific helper (in oe-meta). (From OE-Core rev: bfce90b1260d07f01a8dc2998c9e63ca36d4ebbe) Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 019b9c341d539939098962c228c1fd5c99331312) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/npm.bbclass15
1 files changed, 9 insertions, 6 deletions
diff --git a/meta/classes/npm.bbclass b/meta/classes/npm.bbclass
index 11c80a738e..8379c7b988 100644
--- a/meta/classes/npm.bbclass
+++ b/meta/classes/npm.bbclass
@@ -19,7 +19,7 @@
19 19
20inherit python3native 20inherit python3native
21 21
22DEPENDS:prepend = "nodejs-native " 22DEPENDS:prepend = "nodejs-native nodejs-oe-cache-native "
23RDEPENDS:${PN}:append:class-target = " nodejs" 23RDEPENDS:${PN}:append:class-target = " nodejs"
24 24
25EXTRA_OENPM = "" 25EXTRA_OENPM = ""
@@ -46,6 +46,7 @@ NPM_ARCH ?= "${@npm_target_arch_map(d.getVar("TARGET_ARCH"))}"
46NPM_PACKAGE = "${WORKDIR}/npm-package" 46NPM_PACKAGE = "${WORKDIR}/npm-package"
47NPM_CACHE = "${WORKDIR}/npm-cache" 47NPM_CACHE = "${WORKDIR}/npm-cache"
48NPM_BUILD = "${WORKDIR}/npm-build" 48NPM_BUILD = "${WORKDIR}/npm-build"
49NPM_REGISTRY = "${WORKDIR}/npm-registry"
49 50
50def npm_global_configs(d): 51def npm_global_configs(d):
51 """Get the npm global configuration""" 52 """Get the npm global configuration"""
@@ -109,16 +110,18 @@ python npm_do_configure() {
109 from bb.fetch2.npm import npm_unpack 110 from bb.fetch2.npm import npm_unpack
110 from bb.fetch2.npmsw import foreach_dependencies 111 from bb.fetch2.npmsw import foreach_dependencies
111 from bb.progress import OutOfProgressHandler 112 from bb.progress import OutOfProgressHandler
113 from oe.npm_registry import NpmRegistry
112 114
113 bb.utils.remove(d.getVar("NPM_CACHE"), recurse=True) 115 bb.utils.remove(d.getVar("NPM_CACHE"), recurse=True)
114 bb.utils.remove(d.getVar("NPM_PACKAGE"), recurse=True) 116 bb.utils.remove(d.getVar("NPM_PACKAGE"), recurse=True)
115 117
116 env = NpmEnvironment(d, configs=npm_global_configs(d)) 118 env = NpmEnvironment(d, configs=npm_global_configs(d))
119 registry = NpmRegistry(d.getVar('NPM_REGISTRY'), d.getVar('NPM_CACHE'))
117 120
118 def _npm_cache_add(tarball): 121 def _npm_cache_add(tarball, pkg):
119 """Run 'npm cache add' for a specified tarball""" 122 """Add tarball to local registry and register it in the
120 cmd = "npm cache add %s" % shlex.quote(tarball) 123 cache"""
121 env.run(cmd) 124 registry.add_pkg(tarball, pkg)
122 125
123 def _npm_integrity(tarball): 126 def _npm_integrity(tarball):
124 """Return the npm integrity of a specified tarball""" 127 """Return the npm integrity of a specified tarball"""
@@ -182,7 +185,7 @@ python npm_do_configure() {
182 # Add the dependency to the npm cache 185 # Add the dependency to the npm cache
183 destdir = os.path.join(d.getVar("S"), destsuffix) 186 destdir = os.path.join(d.getVar("S"), destsuffix)
184 (tarball, pkg) = npm_pack(env, destdir, tmpdir) 187 (tarball, pkg) = npm_pack(env, destdir, tmpdir)
185 _npm_cache_add(tarball) 188 _npm_cache_add(tarball, pkg)
186 # Add its signature to the cached shrinkwrap 189 # Add its signature to the cached shrinkwrap
187 dep = _npmsw_dependency_dict(cached_shrinkwrap, deptree) 190 dep = _npmsw_dependency_dict(cached_shrinkwrap, deptree)
188 dep["version"] = pkg['version'] 191 dep["version"] = pkg['version']