Skip to content

Commit

Permalink
nodejs-oe-cache: backport fix for ENOTCACHED issues
Browse files Browse the repository at this point in the history
https://lists.openembedded.org/g/openembedded-devel/message/110246
https://lists.openembedded.org/g/openembedded-devel/message/110244

temporarily until it's merged in meta-oe/master and backported to
scarthgap

Signed-off-by: Martin Jansa <martin.jansa@gmail.com>
  • Loading branch information
shr-project committed May 3, 2024
1 parent 600f40a commit 2936d12
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://lists.openembedded.org/g/openembedded-devel/message/110246
# https://lists.openembedded.org/g/openembedded-devel/message/110244
FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:"
77 changes: 77 additions & 0 deletions meta-luneos/recipes-devtools/nodejs/nodejs-oe-cache/oe-npm-cache
Original file line number Diff line number Diff line change
@@ -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/json',
},
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}).`);
})

0 comments on commit 2936d12

Please sign in to comment.