Skip to contentSkip to conversation

nodejs-oe-cache-native: initial checkin

meta-oe Martin Jansa 3 participants 4 messages Sep 13, 2022 – Sep 15, 2022

lore
Share & tools
lore
#0 lore raw

From: Enrico Scholz <[email protected]>

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.

---
 .../nodejs/nodejs-oe-cache-16.14/oe-npm-cache | 77 +++++++++++++++++++
 .../nodejs/nodejs-oe-cache-native_16.14.bb    | 21 +++++
 2 files changed, 98 insertions(+)
 create mode 100755 meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache
 create mode 100644 meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +77 -0
new file mode 100755
index 0000000000..f596207648
@@ -0,0 +1,77 @@
+#!/usr/bin/env node
+
+/// Usage: oe-npm-cache <cache-dir> <type> <key> <file-name>
+///    <type> ... meta - metainformation about package
+///               tgz  - tarball
+
+const process = require("node:process");
+
+module.paths.unshift("@@libdir@@/node_modules/npm/node_modules");
+
+const cacache = require('cacache')
+const fs = require('fs')
+
+// argv[0] is 'node', argv[1] is this script
+const cache_dir = process.argv[2]
+const type      = process.argv[3]
+const key       = process.argv[4]
+const file      = process.argv[5]
+
+const data = fs.readFileSync(file)
+
+// metadata content is highly nodejs dependent; when cache entries are not
+// found, place debug statements in 'make-fetch-happen/lib/cache/policy.js'
+// (CachePolicy::satisfies())
+const xlate = {
+    'meta': {
+	'key_prefix': 'make-fetch-happen:request-cache:',
+	'metadata': function() {
+	    return {
+		time: Date.now(),
+		url:  key,
+		reqHeaders: {
+		    'accept': 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
+		},
+		resHeaders: {
+		    "content-type": "application/json",
+		    "status": 200,
+		},
+		options: {
+		    compress: true,
+		}
+	    };
+	},
+    },
+
+    'tgz': {
+	'key_prefix': 'make-fetch-happen:request-cache:',
+	'metadata': function() {
+	    return {
+		time: Date.now(),
+		url:  key,
+		reqHeaders: {
+		    'accept': '*/*',
+		},
+		resHeaders: {
+		    "content-type": "application/octet-stream",
+		    "status": 200,
+		},
+		options: {
+		    compress: true,
+		},
+	    };
+	},
+    },
+};
+
+const info = xlate[type];
+let opts = {}
+
+if (info.metadata) {
+    opts['metadata'] = info.metadata();
+}
+
+cacache.put(cache_dir, info.key_prefix + key, data, opts)
+    .then(integrity => {
+	console.log(`Saved content of ${key} (${file}).`);
+})
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb new file +21 -0
new file mode 100644
index 0000000000..a61dd5018f
@@ -0,0 +1,21 @@
+DESCRIPTION = "OE helper for manipulating npm cache"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+SRC_URI = "\
+    file://oe-npm-cache \
+"
+
+inherit native
+
+B = "${WORKDIR}/build"
+
+do_configure() {
+    sed -e 's!@@libdir@@!${libdir}!g' < '${WORKDIR}/oe-npm-cache' > '${B}/oe-npm-cache'
+}
+
+do_install() {
+    install -D -p -m 0755 ${B}/oe-npm-cache ${D}${bindir}/oe-npm-cache
+}
+
+RDEPENDS:${PN} = "nodejs-native"
Signature · 1 line
2.37.3
#1 lore raw
Quoted 9 lines · Martin Jansa

From: Enrico Scholz <[email protected]>

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.

Isn't this adding a new recipe to a Stable branch?

- armin

Quoted 129 lines
---
  .../nodejs/nodejs-oe-cache-16.14/oe-npm-cache | 77 +++++++++++++++++++
  .../nodejs/nodejs-oe-cache-native_16.14.bb    | 21 +++++
  2 files changed, 98 insertions(+)

create mode 100755 meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache create mode 100644 meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +77 -0
new file mode 100755
index 0000000000..f596207648
@@ -0,0 +1,77 @@
+#!/usr/bin/env node
+
+/// Usage: oe-npm-cache <cache-dir> <type> <key> <file-name>
+///    <type> ... meta - metainformation about package
+///               tgz  - tarball
+
+const process = require("node:process");
+
+module.paths.unshift("@@libdir@@/node_modules/npm/node_modules");
+
+const cacache = require('cacache')
+const fs = require('fs')
+
+// argv[0] is 'node', argv[1] is this script
+const cache_dir = process.argv[2]
+const type      = process.argv[3]
+const key       = process.argv[4]
+const file      = process.argv[5]
+
+const data = fs.readFileSync(file)
+
+// metadata content is highly nodejs dependent; when cache entries are not
+// found, place debug statements in 'make-fetch-happen/lib/cache/policy.js'
+// (CachePolicy::satisfies())
+const xlate = {
+    'meta': {
+	'key_prefix': 'make-fetch-happen:request-cache:',
+	'metadata': function() {
+	    return {
+		time: Date.now(),
+		url:  key,
+		reqHeaders: {
+		    'accept': 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
+		},
+		resHeaders: {
+		    "content-type": "application/json",
+		    "status": 200,
+		},
+		options: {
+		    compress: true,
+		}
+	    };
+	},
+    },
+
+    'tgz': {
+	'key_prefix': 'make-fetch-happen:request-cache:',
+	'metadata': function() {
+	    return {
+		time: Date.now(),
+		url:  key,
+		reqHeaders: {
+		    'accept': '*/*',
+		},
+		resHeaders: {
+		    "content-type": "application/octet-stream",
+		    "status": 200,
+		},
+		options: {
+		    compress: true,
+		},
+	    };
+	},
+    },
+};
+
+const info = xlate[type];
+let opts = {}
+
+if (info.metadata) {
+    opts['metadata'] = info.metadata();
+}
+
+cacache.put(cache_dir, info.key_prefix + key, data, opts)
+    .then(integrity => {
+	console.log(`Saved content of ${key} (${file}).`);
+})
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb new file +21 -1
new file mode 100644
index 0000000000..a61dd5018f
@@ -0,0 +1,21 @@
+DESCRIPTION = "OE helper for manipulating npm cache"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+SRC_URI = "\
+    file://oe-npm-cache \
+"
+
+inherit native
+
+B = "${WORKDIR}/build"
+
+do_configure() {
+    sed -e 's!@@libdir@@!${libdir}!g' < '${WORKDIR}/oe-npm-cache' > '${B}/oe-npm-cache'
+}
+
+do_install() {
+    install -D -p -m 0755 ${B}/oe-npm-cache ${D}${bindir}/oe-npm-cache
+}
+
+RDEPENDS:${PN} = "nodejs-native"
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#98787): https://lists.openembedded.org/g/openembedded-devel/message/98787
Mute This Topic: https://lists.openembedded.org/mt/93657958/3616698
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

oe-core kirkstone already added the dependency on it, so I guess it justifies the exception

Quoted 160 lines · On Wed, Sep 14, 2022 at 10:19 PM akuster808 <[email protected]> wrote:
Quoted 9 lines · Martin Jansa

From: Enrico Scholz <[email protected]>

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.

Isn't this adding a new recipe to a Stable branch?

- armin

Quoted 8 lines
---
  .../nodejs/nodejs-oe-cache-16.14/oe-npm-cache | 77 +++++++++++++++++++
  .../nodejs/nodejs-oe-cache-native_16.14.bb    | 21 +++++
  2 files changed, 98 insertions(+)

create mode 100755

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache

Quoted 1 line

create mode 100644 meta-oe/recipes-devtools/nodejs/

nodejs-oe-cache-native_16.14.bb

Quoted 2 lines

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

Quoted 17 lines

new file mode 100755
index 0000000000..f596207648

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +12 -0
@@ -0,0 +1,77 @@
+#!/usr/bin/env node
+
+/// Usage: oe-npm-cache <cache-dir> <type> <key> <file-name>
+///    <type> ... meta - metainformation about package
+///               tgz  - tarball
+
+const process = require("node:process");
+
+module.paths.unshift("@@libdir@@/node_modules/npm/node_modules");
+
+const cacache = require('cacache')
+const fs = require('fs')

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache line 22

Quoted 10 lines
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +10 -0
+
+// argv[0] is 'node', argv[1] is this script
+const cache_dir = process.argv[2]
+const type      = process.argv[3]
+const key       = process.argv[4]
+const file      = process.argv[5]
+
+const data = fs.readFileSync(file)
+
+// metadata content is highly nodejs dependent; when cache entries are

not

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache line 23

Quoted 1 line
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +1 -0
+// found, place debug statements in

'make-fetch-happen/lib/cache/policy.js'

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache

Quoted 10 lines
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +10 -0
+// (CachePolicy::satisfies())
+const xlate = {
+    'meta': {
+     'key_prefix': 'make-fetch-happen:request-cache:',
+     'metadata': function() {
+         return {
+             time: Date.now(),
+             url:  key,
+             reqHeaders: {
+                 'accept': 'application/vnd.npm.install-v1+json; q=1.0,

application/json; q=0.8, */*',

Review

Quoted 45 lines
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +44 -0
+             },
+             resHeaders: {
+                 "content-type": "application/json",
+                 "status": 200,
+             },
+             options: {
+                 compress: true,
+             }
+         };
+     },
+    },
+
+    'tgz': {
+     'key_prefix': 'make-fetch-happen:request-cache:',
+     'metadata': function() {
+         return {
+             time: Date.now(),
+             url:  key,
+             reqHeaders: {
+                 'accept': '*/*',
+             },
+             resHeaders: {
+                 "content-type": "application/octet-stream",
+                 "status": 200,
+             },
+             options: {
+                 compress: true,
+             },
+         };
+     },
+    },
+};
+
+const info = xlate[type];
+let opts = {}
+
+if (info.metadata) {
+    opts['metadata'] = info.metadata();
+}
+
+cacache.put(cache_dir, info.key_prefix + key, data, opts)
+    .then(integrity => {
+     console.log(`Saved content of ${key} (${file}).`);
+})
(quoted diff) +0 -0

nodejs-oe-cache-native_16.14.bb b/meta-oe/recipes-devtools/nodejs/ nodejs-oe-cache-native_16.14.bb

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb line 3

Quoted 8 lines

new file mode 100644
index 0000000000..a61dd5018f

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb new file +3 -0
@@ -0,0 +1,21 @@
+DESCRIPTION = "OE helper for manipulating npm cache"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM =

"file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb

Quoted 11 lines
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb new file +11 -0
+
+SRC_URI = "\
+    file://oe-npm-cache \
+"
+
+inherit native
+
+B = "${WORKDIR}/build"
+
+do_configure() {
+    sed -e 's!@@libdir@@!${libdir}!g' < '${WORKDIR}/oe-npm-cache' >

'${B}/oe-npm-cache'

Quoted 11 lines
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb new file +7 -1
+}
+
+do_install() {
+    install -D -p -m 0755 ${B}/oe-npm-cache ${D}${bindir}/oe-npm-cache
+}
+
+RDEPENDS:${PN} = "nodejs-native"
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group. View/Reply Online (#98787):

https://lists.openembedded.org/g/openembedded-devel/message/98787

Quoted 3 lines

Mute This Topic: https://lists.openembedded.org/mt/93657958/3616698
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [

[email protected]]

Quoted 2 lines

-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw
Quoted 3 lines · Martin Jansa

oe-core kirkstone already added the dependency on it, so I guess it justifies the exception

agreed

Quoted 148 lines · On Wed, Sep 14, 2022 at 10:19 PM akuster808 <[email protected]> wrote:
Quoted 147 lines · Martin Jansa
Quoted 9 lines

From: Enrico Scholz <[email protected]>

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.

Isn't this adding a new recipe to a Stable branch?

- armin

Quoted 129 lines
---
  .../nodejs/nodejs-oe-cache-16.14/oe-npm-cache | 77 +++++++++++++++++++
  .../nodejs/nodejs-oe-cache-native_16.14.bb    | 21 +++++
  2 files changed, 98 insertions(+)

create mode 100755 meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache create mode 100644 meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb

meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-16.14/oe-npm-cache new file +77 -0
new file mode 100755
index 0000000000..f596207648
@@ -0,0 +1,77 @@
+#!/usr/bin/env node
+
+/// Usage: oe-npm-cache <cache-dir> <type> <key> <file-name>
+///    <type> ... meta - metainformation about package
+///               tgz  - tarball
+
+const process = require("node:process");
+
+module.paths.unshift("@@libdir@@/node_modules/npm/node_modules");
+
+const cacache = require('cacache')
+const fs = require('fs')
+
+// argv[0] is 'node', argv[1] is this script
+const cache_dir = process.argv[2]
+const type      = process.argv[3]
+const key       = process.argv[4]
+const file      = process.argv[5]
+
+const data = fs.readFileSync(file)
+
+// metadata content is highly nodejs dependent; when cache entries are not
+// found, place debug statements in 'make-fetch-happen/lib/cache/policy.js'
+// (CachePolicy::satisfies())
+const xlate = {
+    'meta': {
+     'key_prefix': 'make-fetch-happen:request-cache:',
+     'metadata': function() {
+         return {
+             time: Date.now(),
+             url:  key,
+             reqHeaders: {
+                 'accept': 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
+             },
+             resHeaders: {
+                 "content-type": "application/json",
+                 "status": 200,
+             },
+             options: {
+                 compress: true,
+             }
+         };
+     },
+    },
+
+    'tgz': {
+     'key_prefix': 'make-fetch-happen:request-cache:',
+     'metadata': function() {
+         return {
+             time: Date.now(),
+             url:  key,
+             reqHeaders: {
+                 'accept': '*/*',
+             },
+             resHeaders: {
+                 "content-type": "application/octet-stream",
+                 "status": 200,
+             },
+             options: {
+                 compress: true,
+             },
+         };
+     },
+    },
+};
+
+const info = xlate[type];
+let opts = {}
+
+if (info.metadata) {
+    opts['metadata'] = info.metadata();
+}
+
+cacache.put(cache_dir, info.key_prefix + key, data, opts)
+    .then(integrity => {
+     console.log(`Saved content of ${key} (${file}).`);
+})
meta-oe/recipes-devtools/nodejs/nodejs-oe-cache-native_16.14.bb new file +21 -1
new file mode 100644
index 0000000000..a61dd5018f
@@ -0,0 +1,21 @@
+DESCRIPTION = "OE helper for manipulating npm cache"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+SRC_URI = "\
+    file://oe-npm-cache \
+"
+
+inherit native
+
+B = "${WORKDIR}/build"
+
+do_configure() {
+    sed -e 's!@@libdir@@!${libdir}!g' < '${WORKDIR}/oe-npm-cache' > '${B}/oe-npm-cache'
+}
+
+do_install() {
+    install -D -p -m 0755 ${B}/oe-npm-cache ${D}${bindir}/oe-npm-cache
+}
+
+RDEPENDS:${PN} = "nodejs-native"
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#98787): https://lists.openembedded.org/g/openembedded-devel/message/98787
Mute This Topic: https://lists.openembedded.org/mt/93657958/3616698
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-