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-06-28 12:55:26 +0100
commitccfa4132f9a9a1fab8c3bffdc1fa316a98ab795a (patch)
tree84d4a1d4cff436c1d07e87fe4164e6b5d53b7158 /meta/classes
parent6ca69f66ba70c829956746cf290e39b16a950731 (diff)
downloadpoky-ccfa4132f9a9a1fab8c3bffdc1fa316a98ab795a.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: 019b9c341d539939098962c228c1fd5c99331312) Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> 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 3ab67769e1..deea53c9ec 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"""
@@ -112,16 +113,18 @@ python npm_do_configure() {
112 from bb.fetch2.npm import npm_unpack 113 from bb.fetch2.npm import npm_unpack
113 from bb.fetch2.npmsw import foreach_dependencies 114 from bb.fetch2.npmsw import foreach_dependencies
114 from bb.progress import OutOfProgressHandler 115 from bb.progress import OutOfProgressHandler
116 from oe.npm_registry import NpmRegistry
115 117
116 bb.utils.remove(d.getVar("NPM_CACHE"), recurse=True) 118 bb.utils.remove(d.getVar("NPM_CACHE"), recurse=True)
117 bb.utils.remove(d.getVar("NPM_PACKAGE"), recurse=True) 119 bb.utils.remove(d.getVar("NPM_PACKAGE"), recurse=True)
118 120
119 env = NpmEnvironment(d, configs=npm_global_configs(d)) 121 env = NpmEnvironment(d, configs=npm_global_configs(d))
122 registry = NpmRegistry(d.getVar('NPM_REGISTRY'), d.getVar('NPM_CACHE'))
120 123
121 def _npm_cache_add(tarball): 124 def _npm_cache_add(tarball, pkg):
122 """Run 'npm cache add' for a specified tarball""" 125 """Add tarball to local registry and register it in the
123 cmd = "npm cache add %s" % shlex.quote(tarball) 126 cache"""
124 env.run(cmd) 127 registry.add_pkg(tarball, pkg)
125 128
126 def _npm_integrity(tarball): 129 def _npm_integrity(tarball):
127 """Return the npm integrity of a specified tarball""" 130 """Return the npm integrity of a specified tarball"""
@@ -185,7 +188,7 @@ python npm_do_configure() {
185 # Add the dependency to the npm cache 188 # Add the dependency to the npm cache
186 destdir = os.path.join(d.getVar("S"), destsuffix) 189 destdir = os.path.join(d.getVar("S"), destsuffix)
187 (tarball, pkg) = npm_pack(env, destdir, tmpdir) 190 (tarball, pkg) = npm_pack(env, destdir, tmpdir)
188 _npm_cache_add(tarball) 191 _npm_cache_add(tarball, pkg)
189 # Add its signature to the cached shrinkwrap 192 # Add its signature to the cached shrinkwrap
190 dep = _npmsw_dependency_dict(cached_shrinkwrap, deptree) 193 dep = _npmsw_dependency_dict(cached_shrinkwrap, deptree)
191 dep["version"] = pkg['version'] 194 dep["version"] = pkg['version']