-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nodejs-oe-cache: backport fix for ENOTCACHED issues
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
1 parent
600f40a
commit 2936d12
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
meta-luneos/recipes-devtools/nodejs/nodejs-oe-cache-native_%.bbappend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
77
meta-luneos/recipes-devtools/nodejs/nodejs-oe-cache/oe-npm-cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}).`); | ||
}) |