summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@sigma-chemnitz.de>2022-09-13 17:34:28 +0200
committerArmin Kuster <akuster808@gmail.com>2022-09-15 08:17:25 -0400
commit035d9c61e81b32cb62706cfdbfae08b1bac7ae88 (patch)
tree4e70bf2015b046e2b7711a21cdb3e3bc0cd12c41
parent8f96c05f6d82fde052f2cb1652c13922814accb0 (diff)
downloadmeta-openembedded-035d9c61e81b32cb62706cfdbfae08b1bac7ae88.tar.gz
nodejs-oe-cache-native: initial checkin
This implements an 'npm cache add' like functionality but allows to specify the key of the data and sets metadata which are required to find the data. It is used to cache information as done during 'npm install'. Keyformat and metadata are nodejs version specific. Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> Signed-off-by: Khem Raj <raj.khem@gmail.com>
-rwxr-xr-xmeta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache77
-rw-r--r--meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb21
2 files changed, 98 insertions, 0 deletions
diff --git a/meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache b/meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache
new file mode 100755
index 0000000000..f596207648
--- /dev/null
+++ b/meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache
@@ -0,0 +1,77 @@
1#!/usr/bin/env node
2
3/// Usage: oe-npm-cache <cache-dir> <type> <key> <file-name>
4/// <type> ... meta - metainformation about package
5/// tgz - tarball
6
7const process = require("node:process");
8
9module.paths.unshift("@@libdir@@/node_modules/npm/node_modules");
10
11const cacache = require('cacache')
12const fs = require('fs')
13
14// argv[0] is 'node', argv[1] is this script
15const cache_dir = process.argv[2]
16const type = process.argv[3]
17const key = process.argv[4]
18const file = process.argv[5]
19
20const data = fs.readFileSync(file)
21
22// metadata content is highly nodejs dependent; when cache entries are not
23// found, place debug statements in 'make-fetch-happen/lib/cache/policy.js'
24// (CachePolicy::satisfies())
25const xlate = {
26 'meta': {
27 'key_prefix': 'make-fetch-happen:request-cache:',
28 'metadata': function() {
29 return {
30 time: Date.now(),
31 url: key,
32 reqHeaders: {
33 'accept': 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
34 },
35 resHeaders: {
36 "content-type": "application/json",
37 "status": 200,
38 },
39 options: {
40 compress: true,
41 }
42 };
43 },
44 },
45
46 'tgz': {
47 'key_prefix': 'make-fetch-happen:request-cache:',
48 'metadata': function() {
49 return {
50 time: Date.now(),
51 url: key,
52 reqHeaders: {
53 'accept': '*/*',
54 },
55 resHeaders: {
56 "content-type": "application/octet-stream",
57 "status": 200,
58 },
59 options: {
60 compress: true,
61 },
62 };
63 },
64 },
65};
66
67const info = xlate[type];
68let opts = {}
69
70if (info.metadata) {
71 opts['metadata'] = info.metadata();
72}
73
74cacache.put(cache_dir, info.key_prefix + key, data, opts)
75 .then(integrity => {
76 console.log(`Saved content of ${key} (${file}).`);
77})
diff --git a/meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb b/meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb
new file mode 100644
index 0000000000..a61dd5018f
--- /dev/null
+++ b/meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb
@@ -0,0 +1,21 @@
1DESCRIPTION = "OE helper for manipulating npm cache"
2LICENSE = "Apache-2.0"
3LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
4
5SRC_URI = "\
6 file://oe-npm-cache \
7"
8
9inherit native
10
11B = "${WORKDIR}/build"
12
13do_configure() {
14 sed -e 's!@@libdir@@!${libdir}!g' < '${WORKDIR}/oe-npm-cache' > '${B}/oe-npm-cache'
15}
16
17do_install() {
18 install -D -p -m 0755 ${B}/oe-npm-cache ${D}${bindir}/oe-npm-cache
19}
20
21RDEPENDS:${PN} = "nodejs-native"